From b33df41337f92e79ef142910e05b6d65f755ca5b Mon Sep 17 00:00:00 2001 From: aB0t Date: Mon, 1 May 2023 14:01:01 +0200 Subject: [PATCH] update 2023-05-01 14:00:54 --- README.md | 17 ++++ .../code.php | 17 +++- .../code.power | 17 +++- .../README.md | 83 +++++++++++++++++++ .../code.php | 73 ++++++++++++++++ .../code.power | 49 +++++++++++ .../settings.json | 18 ++++ .../README.md | 79 ++++++++++++++++++ .../code.php | 79 ++++++++++++++++++ .../code.power | 55 ++++++++++++ .../settings.json | 18 ++++ super-powers.json | 20 +++++ 12 files changed, 519 insertions(+), 6 deletions(-) create mode 100644 src/7179fde6-1e51-4b51-8545-7ca18f74a0f4/README.md create mode 100644 src/7179fde6-1e51-4b51-8545-7ca18f74a0f4/code.php create mode 100644 src/7179fde6-1e51-4b51-8545-7ca18f74a0f4/code.power create mode 100644 src/7179fde6-1e51-4b51-8545-7ca18f74a0f4/settings.json create mode 100644 src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/README.md create mode 100644 src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/code.php create mode 100644 src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/code.power create mode 100644 src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/settings.json diff --git a/README.md b/README.md index 4db43d0..a238409 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,9 @@ This repository contains an index (see below) of all the approved powers within - **final class Update** | [Details](src/cce56585-58b0-4f72-a92c-e2635ea52d83) | [Code](src/cce56585-58b0-4f72-a92c-e2635ea52d83/code.php) | [Settings](src/cce56585-58b0-4f72-a92c-e2635ea52d83/settings.json) | [cce56585-58b0-4f72-a92c-e2635ea52d83](src/cce56585-58b0-4f72-a92c-e2635ea52d83) - **Namespace**: [VDM\Joomla\Componentbuilder\Interfaces](#vdm-joomla-componentbuilder-interfaces) + - **interface InsertInterface** | [Details](src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48) | [Code](src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/code.php) | [Settings](src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/settings.json) | [ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48](src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48) - **interface ModelInterface** | [Details](src/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff) | [Code](src/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff/code.php) | [Settings](src/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff/settings.json) | [8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff](src/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff) + - **interface UpdateInterface** | [Details](src/7179fde6-1e51-4b51-8545-7ca18f74a0f4) | [Code](src/7179fde6-1e51-4b51-8545-7ca18f74a0f4/code.php) | [Settings](src/7179fde6-1e51-4b51-8545-7ca18f74a0f4/settings.json) | [7179fde6-1e51-4b51-8545-7ca18f74a0f4](src/7179fde6-1e51-4b51-8545-7ca18f74a0f4) - **Namespace**: [VDM\Joomla\Componentbuilder\Utilities](#vdm-joomla-componentbuilder-utilities) - **abstract class FilterHelper** | [Details](src/cddcac51-9a46-47c4-ba59-105c70453bd6) | [Code](src/cddcac51-9a46-47c4-ba59-105c70453bd6/code.php) | [Settings](src/cddcac51-9a46-47c4-ba59-105c70453bd6/settings.json) | [cddcac51-9a46-47c4-ba59-105c70453bd6](src/cddcac51-9a46-47c4-ba59-105c70453bd6) @@ -327,6 +329,14 @@ namespace VDM\Joomla\Componentbuilder\Database #Olive { namespace VDM\Joomla\Componentbuilder\Interfaces #Olive { + interface InsertInterface #Lavender { + + defaults() : void + + rows() : bool + + items() : bool + + row() : bool + + item() : bool + } + interface ModelInterface #Lavender { + value() : mixed + item() : ?object @@ -335,6 +345,13 @@ namespace VDM\Joomla\Componentbuilder\Interfaces #Olive { + rows() : ?array + last() : ?int } + + interface UpdateInterface #Lavender { + + rows() : bool + + items() : bool + + row() : bool + + item() : bool + } } diff --git a/src/6cbef8f8-4813-48e3-b05a-65e1aea95171/code.php b/src/6cbef8f8-4813-48e3-b05a-65e1aea95171/code.php index 5e14535..eff3869 100644 --- a/src/6cbef8f8-4813-48e3-b05a-65e1aea95171/code.php +++ b/src/6cbef8f8-4813-48e3-b05a-65e1aea95171/code.php @@ -65,6 +65,11 @@ abstract class Database **/ protected function quote($value) { + if ($value === null) // hmm the null does pose an issue (will keep an eye on this) + { + return 'NULL'; + } + if (is_numeric($value)) { if (filter_var($value, FILTER_VALIDATE_INT)) @@ -76,12 +81,18 @@ abstract class Database return (float) $value; } } - elseif (is_bool($value)) + elseif (is_bool($value)) // not sure if this will work well (but its correct) { - return (int) $value; + return $value ? 'TRUE' : 'FALSE'; } - // default just escape it + // For date and datetime values + if ($value instanceof \DateTime) + { + return $this->db->quote($value->format('Y-m-d H:i:s')); + } + + // For other data types, just escape it return $this->db->quote($value); } diff --git a/src/6cbef8f8-4813-48e3-b05a-65e1aea95171/code.power b/src/6cbef8f8-4813-48e3-b05a-65e1aea95171/code.power index f980661..1ec9969 100644 --- a/src/6cbef8f8-4813-48e3-b05a-65e1aea95171/code.power +++ b/src/6cbef8f8-4813-48e3-b05a-65e1aea95171/code.power @@ -40,6 +40,11 @@ **/ protected function quote($value) { + if ($value === null) // hmm the null does pose an issue (will keep an eye on this) + { + return 'NULL'; + } + if (is_numeric($value)) { if (filter_var($value, FILTER_VALIDATE_INT)) @@ -51,12 +56,18 @@ return (float) $value; } } - elseif (is_bool($value)) + elseif (is_bool($value)) // not sure if this will work well (but its correct) { - return (int) $value; + return $value ? 'TRUE' : 'FALSE'; } - // default just escape it + // For date and datetime values + if ($value instanceof \DateTime) + { + return $this->db->quote($value->format('Y-m-d H:i:s')); + } + + // For other data types, just escape it return $this->db->quote($value); } diff --git a/src/7179fde6-1e51-4b51-8545-7ca18f74a0f4/README.md b/src/7179fde6-1e51-4b51-8545-7ca18f74a0f4/README.md new file mode 100644 index 0000000..0326e39 --- /dev/null +++ b/src/7179fde6-1e51-4b51-8545-7ca18f74a0f4/README.md @@ -0,0 +1,83 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# interface UpdateInterface (Details) +> namespace: **VDM\Joomla\Componentbuilder\Interfaces** +```uml +@startuml +interface UpdateInterface #Lavender { + + rows(array $data, string $key, ...) : bool + + items(array $data, string $key, ...) : bool + + row(array $data, string $key, ...) : bool + + item(object $data, string $key, ...) : bool +} + +note right of UpdateInterface::rows + Update rows in the database (with remapping and filtering columns option) + + since: 3.2.0 + return: bool + + arguments: + array $data + string $key + string $table + array $columns = [] +end note + +note right of UpdateInterface::items + Update items in the database (with remapping and filtering columns option) + + since: 3.2.0 + return: bool + + arguments: + array $data + string $key + string $table + array $columns = [] +end note + +note right of UpdateInterface::row + Update row in the database + + since: 3.2.0 + return: bool + + arguments: + array $data + string $key + string $table +end note + +note right of UpdateInterface::item + Update item in the database + + since: 3.2.0 + return: bool + + arguments: + object $data + string $key + string $table +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/7179fde6-1e51-4b51-8545-7ca18f74a0f4/code.php b/src/7179fde6-1e51-4b51-8545-7ca18f74a0f4/code.php new file mode 100644 index 0000000..3e0cba0 --- /dev/null +++ b/src/7179fde6-1e51-4b51-8545-7ca18f74a0f4/code.php @@ -0,0 +1,73 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Interfaces; + + +/** + * Database Update Interface + * + * @since 3.2.0 + */ +interface UpdateInterface +{ + /** + * Update rows in the database (with remapping and filtering columns option) + * + * @param array $data Dataset to update in database [array of arrays (key => value)] + * @param string $key Dataset key column to use in updating the values in the Database + * @param string $table The table where the data is being updated + * @param array $columns Data columns for remapping and filtering + * + * @return bool + * @since 3.2.0 + **/ + public function rows(array $data, string $key, string $table, array $columns = []): bool; + + /** + * Update items in the database (with remapping and filtering columns option) + * + * @param array $data Data to updated in database (array of objects) + * @param string $key Dataset key column to use in updating the values in the Database + * @param string $table The table where the data is being update + * @param array $columns Data columns for remapping and filtering + * + * @return bool + * @since 3.2.0 + **/ + public function items(array $data, string $key, string $table, array $columns = []): bool; + + /** + * Update row in the database + * + * @param array $data Dataset to update in database (key => value) + * @param string $key Dataset key column to use in updating the values in the Database + * @param string $table The table where the data is being updated + * + * @return bool + * @since 3.2.0 + **/ + public function row(array $data, string $key, string $table): bool; + + /** + * Update item in the database + * + * @param object $data Dataset to update in database (key => value) + * @param string $key Dataset key column to use in updating the values in the Database + * @param string $table The table where the data is being updated + * + * @return bool + * @since 3.2.0 + **/ + public function item(object $data, string $key, string $table): bool; + +} + diff --git a/src/7179fde6-1e51-4b51-8545-7ca18f74a0f4/code.power b/src/7179fde6-1e51-4b51-8545-7ca18f74a0f4/code.power new file mode 100644 index 0000000..abad002 --- /dev/null +++ b/src/7179fde6-1e51-4b51-8545-7ca18f74a0f4/code.power @@ -0,0 +1,49 @@ + /** + * Update rows in the database (with remapping and filtering columns option) + * + * @param array $data Dataset to update in database [array of arrays (key => value)] + * @param string $key Dataset key column to use in updating the values in the Database + * @param string $table The table where the data is being updated + * @param array $columns Data columns for remapping and filtering + * + * @return bool + * @since 3.2.0 + **/ + public function rows(array $data, string $key, string $table, array $columns = []): bool; + + /** + * Update items in the database (with remapping and filtering columns option) + * + * @param array $data Data to updated in database (array of objects) + * @param string $key Dataset key column to use in updating the values in the Database + * @param string $table The table where the data is being update + * @param array $columns Data columns for remapping and filtering + * + * @return bool + * @since 3.2.0 + **/ + public function items(array $data, string $key, string $table, array $columns = []): bool; + + /** + * Update row in the database + * + * @param array $data Dataset to update in database (key => value) + * @param string $key Dataset key column to use in updating the values in the Database + * @param string $table The table where the data is being updated + * + * @return bool + * @since 3.2.0 + **/ + public function row(array $data, string $key, string $table): bool; + + /** + * Update item in the database + * + * @param object $data Dataset to update in database (key => value) + * @param string $key Dataset key column to use in updating the values in the Database + * @param string $table The table where the data is being updated + * + * @return bool + * @since 3.2.0 + **/ + public function item(object $data, string $key, string $table): bool; diff --git a/src/7179fde6-1e51-4b51-8545-7ca18f74a0f4/settings.json b/src/7179fde6-1e51-4b51-8545-7ca18f74a0f4/settings.json new file mode 100644 index 0000000..c20ef53 --- /dev/null +++ b/src/7179fde6-1e51-4b51-8545-7ca18f74a0f4/settings.json @@ -0,0 +1,18 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "7179fde6-1e51-4b51-8545-7ca18f74a0f4", + "implements": null, + "load_selection": null, + "name": "UpdateInterface", + "power_version": "1.0.0", + "system_name": "JCB.Interfaces.UpdateInterface", + "type": "interface", + "use_selection": null, + "namespace": "VDM\\Joomla\\Componentbuilder.Interfaces.UpdateInterface", + "description": "Database Update Interface\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": "" +} \ No newline at end of file diff --git a/src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/README.md b/src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/README.md new file mode 100644 index 0000000..f17b3ba --- /dev/null +++ b/src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/README.md @@ -0,0 +1,79 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# interface InsertInterface (Details) +> namespace: **VDM\Joomla\Componentbuilder\Interfaces** +```uml +@startuml +interface InsertInterface #Lavender { + + defaults(bool $trigger = true) : void + + rows(array $data, string $table, ...) : bool + + items(array $data, string $table, ...) : bool + + row(array $data, string $table) : bool + + item(object $data, string $table) : bool +} + +note right of InsertInterface::defaults + Switch to prevent/allow defaults from being added. + + since: 3.2.0 + return: void +end note + +note right of InsertInterface::rows + Insert rows to the database (with remapping and filtering columns option) + + since: 3.2.0 + return: bool + + arguments: + array $data + string $table + array $columns = [] +end note + +note right of InsertInterface::items + Insert items to the database (with remapping and filtering columns option) + + since: 3.2.0 + return: bool + + arguments: + array $data + string $table + array $columns = [] +end note + +note right of InsertInterface::row + Insert row to the database + + since: 3.2.0 + return: bool +end note + +note right of InsertInterface::item + Insert item to the database + + since: 3.2.0 + return: bool +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/code.php b/src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/code.php new file mode 100644 index 0000000..d00fc58 --- /dev/null +++ b/src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/code.php @@ -0,0 +1,79 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Interfaces; + + +/** + * Database Insert Interface + * + * @since 3.2.0 + */ +interface InsertInterface +{ + /** + * Switch to prevent/allow defaults from being added. + * + * @param bool $trigger toggle the defaults + * + * @return void + * @since 3.2.0 + **/ + public function defaults(bool $trigger = true); + + /** + * Insert rows to the database (with remapping and filtering columns option) + * + * @param array $data Dataset to store in database [array of arrays (key => value)] + * @param string $table The table where the data is being added + * @param array $columns Data columns for remapping and filtering + * + * @return bool + * @since 3.2.0 + **/ + public function rows(array $data, string $table, array $columns = []): bool; + + /** + * Insert items to the database (with remapping and filtering columns option) + * + * @param array $data Data to store in database (array of objects) + * @param string $table The table where the data is being added + * @param array $columns Data columns for remapping and filtering + * + * @return bool + * @since 3.2.0 + **/ + public function items(array $data, string $table, array $columns = []): bool; + + /** + * Insert row to the database + * + * @param array $data Dataset to store in database (key => value) + * @param string $table The table where the data is being added + * + * @return bool + * @since 3.2.0 + **/ + public function row(array $data, string $table): bool; + + /** + * Insert item to the database + * + * @param object $data Dataset to store in database (key => value) + * @param string $table The table where the data is being added + * + * @return bool + * @since 3.2.0 + **/ + public function item(object $data, string $table): bool; + +} + diff --git a/src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/code.power b/src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/code.power new file mode 100644 index 0000000..8d6c7c5 --- /dev/null +++ b/src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/code.power @@ -0,0 +1,55 @@ + /** + * Switch to prevent/allow defaults from being added. + * + * @param bool $trigger toggle the defaults + * + * @return void + * @since 3.2.0 + **/ + public function defaults(bool $trigger = true); + + /** + * Insert rows to the database (with remapping and filtering columns option) + * + * @param array $data Dataset to store in database [array of arrays (key => value)] + * @param string $table The table where the data is being added + * @param array $columns Data columns for remapping and filtering + * + * @return bool + * @since 3.2.0 + **/ + public function rows(array $data, string $table, array $columns = []): bool; + + /** + * Insert items to the database (with remapping and filtering columns option) + * + * @param array $data Data to store in database (array of objects) + * @param string $table The table where the data is being added + * @param array $columns Data columns for remapping and filtering + * + * @return bool + * @since 3.2.0 + **/ + public function items(array $data, string $table, array $columns = []): bool; + + /** + * Insert row to the database + * + * @param array $data Dataset to store in database (key => value) + * @param string $table The table where the data is being added + * + * @return bool + * @since 3.2.0 + **/ + public function row(array $data, string $table): bool; + + /** + * Insert item to the database + * + * @param object $data Dataset to store in database (key => value) + * @param string $table The table where the data is being added + * + * @return bool + * @since 3.2.0 + **/ + public function item(object $data, string $table): bool; diff --git a/src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/settings.json b/src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/settings.json new file mode 100644 index 0000000..b4148c4 --- /dev/null +++ b/src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/settings.json @@ -0,0 +1,18 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48", + "implements": null, + "load_selection": null, + "name": "InsertInterface", + "power_version": "1.0.0", + "system_name": "JCB.Interfaces.InsertInterface", + "type": "interface", + "use_selection": null, + "namespace": "VDM\\Joomla\\Componentbuilder.Interfaces.InsertInterface", + "description": "Database Insert Interface\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": "" +} \ No newline at end of file diff --git a/super-powers.json b/super-powers.json index 95e7e55..fb6db8b 100644 --- a/super-powers.json +++ b/super-powers.json @@ -169,6 +169,16 @@ "path": "src\/06f8eada-d59b-441c-b287-0aea1793da5a", "guid": "06f8eada-d59b-441c-b287-0aea1793da5a" }, + "ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48": { + "name": "InsertInterface", + "type": "interface", + "namespace": "VDM\\Joomla\\Componentbuilder\\Interfaces", + "code": "src\/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48\/code.php", + "power": "src\/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48\/code.power", + "settings": "src\/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48\/settings.json", + "path": "src\/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48", + "guid": "ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48" + }, "524eb8f6-38d4-47dc-92ad-98b94e099ac0": { "name": "Insert", "type": "final class", @@ -209,6 +219,16 @@ "path": "src\/584747d1-3a86-453d-b7a3-a2219de8d777", "guid": "584747d1-3a86-453d-b7a3-a2219de8d777" }, + "7179fde6-1e51-4b51-8545-7ca18f74a0f4": { + "name": "UpdateInterface", + "type": "interface", + "namespace": "VDM\\Joomla\\Componentbuilder\\Interfaces", + "code": "src\/7179fde6-1e51-4b51-8545-7ca18f74a0f4\/code.php", + "power": "src\/7179fde6-1e51-4b51-8545-7ca18f74a0f4\/code.power", + "settings": "src\/7179fde6-1e51-4b51-8545-7ca18f74a0f4\/settings.json", + "path": "src\/7179fde6-1e51-4b51-8545-7ca18f74a0f4", + "guid": "7179fde6-1e51-4b51-8545-7ca18f74a0f4" + }, "cce56585-58b0-4f72-a92c-e2635ea52d83": { "name": "Update", "type": "final class",