diff --git a/README.md b/README.md index 96c9a2f..e75d301 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,35 @@ This repository contains an index (see below) of all the approved powers within - **abstract class MathHelper** | [Details](src/152c8793-8b75-4715-996a-257b9f65451c) | [Code](src/152c8793-8b75-4715-996a-257b9f65451c/code.php) | [Settings](src/152c8793-8b75-4715-996a-257b9f65451c/settings.json) | [152c8793-8b75-4715-996a-257b9f65451c](src/152c8793-8b75-4715-996a-257b9f65451c) - **abstract class ObjectHelper** | [Details](src/91004529-94a9-4590-b842-e7c6b624ecf5) | [Code](src/91004529-94a9-4590-b842-e7c6b624ecf5/code.php) | [Settings](src/91004529-94a9-4590-b842-e7c6b624ecf5/settings.json) | [91004529-94a9-4590-b842-e7c6b624ecf5](src/91004529-94a9-4590-b842-e7c6b624ecf5) - **abstract class StringHelper** | [Details](src/1f28cb53-60d9-4db1-b517-3c7dc6b429ef) | [Code](src/1f28cb53-60d9-4db1-b517-3c7dc6b429ef/code.php) | [Settings](src/1f28cb53-60d9-4db1-b517-3c7dc6b429ef/settings.json) | [1f28cb53-60d9-4db1-b517-3c7dc6b429ef](src/1f28cb53-60d9-4db1-b517-3c7dc6b429ef) +- **Namespace**: [VDM\Joomla\Componentbuilder\Abstraction](#vdm-joomla-componentbuilder-abstraction) + + - **abstract class BaseConfig** | [Details](src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36) | [Code](src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/code.php) | [Settings](src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/settings.json) | [9769f3b2-17bf-4f20-b54b-3a4ebe572b36](src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36) + - **abstract class BaseRegistry** | [Details](src/b84e947d-2a13-44f7-ac0f-3902ae55ae0c) | [Code](src/b84e947d-2a13-44f7-ac0f-3902ae55ae0c/code.php) | [Settings](src/b84e947d-2a13-44f7-ac0f-3902ae55ae0c/settings.json) | [b84e947d-2a13-44f7-ac0f-3902ae55ae0c](src/b84e947d-2a13-44f7-ac0f-3902ae55ae0c) + - **abstract class Database** | [Details](src/6cbef8f8-4813-48e3-b05a-65e1aea95171) | [Code](src/6cbef8f8-4813-48e3-b05a-65e1aea95171/code.php) | [Settings](src/6cbef8f8-4813-48e3-b05a-65e1aea95171/settings.json) | [6cbef8f8-4813-48e3-b05a-65e1aea95171](src/6cbef8f8-4813-48e3-b05a-65e1aea95171) + - **abstract class Mapper** | [Details](src/44a3367c-f9e4-406b-b396-0f452bde0f03) | [Code](src/44a3367c-f9e4-406b-b396-0f452bde0f03/code.php) | [Settings](src/44a3367c-f9e4-406b-b396-0f452bde0f03/settings.json) | [44a3367c-f9e4-406b-b396-0f452bde0f03](src/44a3367c-f9e4-406b-b396-0f452bde0f03) + - **abstract class MapperSingle** | [Details](src/c6bbc3ee-58e7-4463-adba-5c5ae839ee36) | [Code](src/c6bbc3ee-58e7-4463-adba-5c5ae839ee36/code.php) | [Settings](src/c6bbc3ee-58e7-4463-adba-5c5ae839ee36/settings.json) | [c6bbc3ee-58e7-4463-adba-5c5ae839ee36](src/c6bbc3ee-58e7-4463-adba-5c5ae839ee36) + - **abstract class Model** | [Details](src/584747d1-3a86-453d-b7a3-a2219de8d777) | [Code](src/584747d1-3a86-453d-b7a3-a2219de8d777/code.php) | [Settings](src/584747d1-3a86-453d-b7a3-a2219de8d777/settings.json) | [584747d1-3a86-453d-b7a3-a2219de8d777](src/584747d1-3a86-453d-b7a3-a2219de8d777) +- **Namespace**: [VDM\Joomla\Componentbuilder\Database](#vdm-joomla-componentbuilder-database) + + - **final class Insert** | [Details](src/524eb8f6-38d4-47dc-92ad-98b94e099ac0) | [Code](src/524eb8f6-38d4-47dc-92ad-98b94e099ac0/code.php) | [Settings](src/524eb8f6-38d4-47dc-92ad-98b94e099ac0/settings.json) | [524eb8f6-38d4-47dc-92ad-98b94e099ac0](src/524eb8f6-38d4-47dc-92ad-98b94e099ac0) + - **final class Load** | [Details](src/06f8eada-d59b-441c-b287-0aea1793da5a) | [Code](src/06f8eada-d59b-441c-b287-0aea1793da5a/code.php) | [Settings](src/06f8eada-d59b-441c-b287-0aea1793da5a/settings.json) | [06f8eada-d59b-441c-b287-0aea1793da5a](src/06f8eada-d59b-441c-b287-0aea1793da5a) +- **Namespace**: [VDM\Joomla\Componentbuilder\Interfaces](#vdm-joomla-componentbuilder-interfaces) + + - **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) +- **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) + - **abstract class FormHelper** | [Details](src/1198aecf-84c6-45d2-aea8-d531aa4afdfa) | [Code](src/1198aecf-84c6-45d2-aea8-d531aa4afdfa/code.php) | [Settings](src/1198aecf-84c6-45d2-aea8-d531aa4afdfa/settings.json) | [1198aecf-84c6-45d2-aea8-d531aa4afdfa](src/1198aecf-84c6-45d2-aea8-d531aa4afdfa) - **Namespace**: [VDM\Joomla\Utilities\Component](#vdm-joomla-utilities-component) - **abstract class Helper** | [Details](src/640b5352-fb09-425f-a26e-cd44eda03f15) | [Code](src/640b5352-fb09-425f-a26e-cd44eda03f15/code.php) | [Settings](src/640b5352-fb09-425f-a26e-cd44eda03f15/settings.json) | [640b5352-fb09-425f-a26e-cd44eda03f15](src/640b5352-fb09-425f-a26e-cd44eda03f15) +- **Namespace**: [VDM\Joomla\Utilities\String](#vdm-joomla-utilities-string) + + - **abstract class ClassfunctionHelper** | [Details](src/30c5b4c2-f75f-4d15-869a-f8bfedd87358) | [Code](src/30c5b4c2-f75f-4d15-869a-f8bfedd87358/code.php) | [Settings](src/30c5b4c2-f75f-4d15-869a-f8bfedd87358/settings.json) | [30c5b4c2-f75f-4d15-869a-f8bfedd87358](src/30c5b4c2-f75f-4d15-869a-f8bfedd87358) + - **abstract class FieldHelper** | [Details](src/9ef0eb24-aae4-4f5a-99af-d724db44808f) | [Code](src/9ef0eb24-aae4-4f5a-99af-d724db44808f/code.php) | [Settings](src/9ef0eb24-aae4-4f5a-99af-d724db44808f/settings.json) | [9ef0eb24-aae4-4f5a-99af-d724db44808f](src/9ef0eb24-aae4-4f5a-99af-d724db44808f) + - **abstract class NamespaceHelper** | [Details](src/ce8cf834-6bac-44fb-941c-861f7e046cc0) | [Code](src/ce8cf834-6bac-44fb-941c-861f7e046cc0/code.php) | [Settings](src/ce8cf834-6bac-44fb-941c-861f7e046cc0/settings.json) | [ce8cf834-6bac-44fb-941c-861f7e046cc0](src/ce8cf834-6bac-44fb-941c-861f7e046cc0) + - **abstract class PluginHelper** | [Details](src/3cf76fbf-fd95-4a33-878e-7aff6d36b7f6) | [Code](src/3cf76fbf-fd95-4a33-878e-7aff6d36b7f6/code.php) | [Settings](src/3cf76fbf-fd95-4a33-878e-7aff6d36b7f6/settings.json) | [3cf76fbf-fd95-4a33-878e-7aff6d36b7f6](src/3cf76fbf-fd95-4a33-878e-7aff6d36b7f6) + - **abstract class TypeHelper** | [Details](src/a8935cbe-7701-40dc-bfd5-675f2d600954) | [Code](src/a8935cbe-7701-40dc-bfd5-675f2d600954/code.php) | [Settings](src/a8935cbe-7701-40dc-bfd5-675f2d600954/settings.json) | [a8935cbe-7701-40dc-bfd5-675f2d600954](src/a8935cbe-7701-40dc-bfd5-675f2d600954) # Class Diagrams @@ -161,6 +187,190 @@ namespace VDM\Joomla\Utilities #DarkCyan { } +@enduml +``` + +## VDM Joomla Componentbuilder Abstraction +> namespace VDM\Joomla\Componentbuilder\Abstraction +```uml +@startuml + +namespace VDM\Joomla\Componentbuilder\Abstraction #Olive { + + + abstract BaseConfig #Orange { + # Input $input + # JoomlaRegistry $params + + __construct() + + __set() + + __get() + + get() : mixed + + appendArray() : mixed + } + + abstract BaseRegistry #Orange { + + _() : ?\ArrayIterator + + appendArray() : mixed + + isArray() : bool + + isString() : bool + + isNumeric() : bool + } + + abstract Database #Orange { + # \JDatabaseDriver $db + # string $table + + __construct() + # quote() : mixed + # getTable() : string + } + + abstract Mapper #Orange { + + array $active + + isActive() : bool + + set() : void + + get() : mixed + + exist() : bool + + add() : void + + remove() : void + # {abstract} key() : string + + isActive_() : bool + + set_() : void + + get_() : mixed + + exist_() : bool + + add_() : void + + remove_() : void + # {abstract} firstKey() : string + # {abstract} secondKey() : string + } + + abstract MapperSingle #Orange { + + array $active + + isActive() : bool + + set() : void + + get() : mixed + + exist() : bool + + add() : void + + remove() : void + # {abstract} key() : string + } + + abstract Model #Orange { + # array $last + # Table $table + + __construct() + + {abstract} value() : mixed + + item() : ?object + + items() : ?array + + row() : ?array + + rows() : ?array + + last() : ?int + # getTableFields() : ?array + # {abstract} validateBefore() : bool + # {abstract} validateAfter() : bool + # {abstract} getTable() : string + } +} + + +@enduml +``` + +## VDM Joomla Componentbuilder Database +> namespace VDM\Joomla\Componentbuilder\Database +```uml +@startuml + +namespace VDM\Joomla\Componentbuilder\Database #Olive { + + + class Insert << (F,LightGreen) >> #Green { + # bool $defaults + + defaults() : void + + rows() : bool + + items() : bool + + row() : bool + + item() : bool + # getArrayColumns() : array + # getObjectsColumns() : array + # insert() : bool + } + + class Load << (F,LightGreen) >> #Green { + + rows() : ?array + + items() : ?array + + row() : ?array + + item() : ?object + + value() : mixed + # many() : bool + # one() : bool + # query() : ?object + } +} + + +@enduml +``` + +## VDM Joomla Componentbuilder Interfaces +> namespace VDM\Joomla\Componentbuilder\Interfaces +```uml +@startuml + +namespace VDM\Joomla\Componentbuilder\Interfaces #Olive { + + + interface ModelInterface #Lavender { + + value() : mixed + + item() : ?object + + items() : ?array + + row() : ?array + + rows() : ?array + + last() : ?int + } +} + + +@enduml +``` + +## VDM Joomla Componentbuilder Utilities +> namespace VDM\Joomla\Componentbuilder\Utilities +```uml +@startuml + +namespace VDM\Joomla\Componentbuilder\Utilities #Olive { + + + abstract FilterHelper #Orange { + + {static} extensions() : string + + {static} names() : ?array + + {static} linked() : ?array + + {static} namespaces() : ?array + + {static} namegroup() : ?array + + {static} translation() : ?array + + {static} translations() : ?array + + {static} languages() : ?array + + {static} paths() : ?array + - {static} joomla_component_admin_views() : ?array + - {static} joomla_component_custom_admin_views() : ?array + - {static} joomla_component_site_views() : ?array + - {static} joomla_component() : ?array + - {static} joomla_module() : ?array + - {static} joomla_plugin() : ?array + - {static} admin_view() : ?array + } + + abstract FormHelper #Orange { + + {static} xml() : ?\SimpleXMLElement + + {static} append() : void + + {static} comment() : void + + {static} attributes() : void + + {static} options() : void + + {static} field() : ?FormField + } +} + + @enduml ``` @@ -183,6 +393,44 @@ namespace VDM\Joomla\Utilities\Component #Olive { } +@enduml +``` + +## VDM Joomla Utilities String +> namespace VDM\Joomla\Utilities\String +```uml +@startuml + +namespace VDM\Joomla\Utilities\String #Olive { + + + abstract ClassfunctionHelper #Orange { + + {static} safe() : string + } + + abstract FieldHelper #Orange { + # static $builder + + {static} safe() + } + + abstract NamespaceHelper #Orange { + + {static} safe() : string + } + + abstract PluginHelper #Orange { + + {static} safeFolderName() : string + + {static} safeClassName() : string + + {static} safeInstallClassName() : string + + {static} safeLangPrefix() : string + } + + abstract TypeHelper #Orange { + # static $builder + + {static} safe() + } +} + + @enduml ``` diff --git a/src/06f8eada-d59b-441c-b287-0aea1793da5a/README.md b/src/06f8eada-d59b-441c-b287-0aea1793da5a/README.md new file mode 100644 index 0000000..76c35b0 --- /dev/null +++ b/src/06f8eada-d59b-441c-b287-0aea1793da5a/README.md @@ -0,0 +1,145 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# final class Load (Details) +> namespace: **VDM\Joomla\Componentbuilder\Database** +```uml +@startuml +class Load << (F,LightGreen) >> #Green { + + rows(array $select, array $tables, ...) : ?array + + items(array $select, array $tables, ...) : ?array + + row(array $select, array $tables, ...) : ?array + + item(array $select, array $tables, ...) : ?object + + value(array $select, array $tables, ...) : mixed + # many(array $select, array $tables, ...) : bool + # one(array $select, array $tables, ...) : bool + # query(array $select, array $tables, ...) : ?object +} + +note right of Load::rows + Load data rows as an array of associated arrays + + since: 3.2.0 + return: ?array + + arguments: + array $select + array $tables + ?array $where = null + ?array $order = null + ?int $limit = null +end note + +note left of Load::items + Load data rows as an array of objects + + since: 3.2.0 + return: ?array + + arguments: + array $select + array $tables + ?array $where = null + ?array $order = null + ?int $limit = null +end note + +note right of Load::row + Load data row as an associated array + + since: 3.2.0 + return: ?array + + arguments: + array $select + array $tables + ?array $where = null + ?array $order = null +end note + +note left of Load::item + Load data row as an object + + since: 3.2.0 + return: ?object + + arguments: + array $select + array $tables + ?array $where = null + ?array $order = null +end note + +note right of Load::value + Load one value from a row + + since: 3.2.0 + return: mixed + + arguments: + array $select + array $tables + ?array $where = null + ?array $order = null +end note + +note left of Load::many + Load many + + since: 3.2.0 + return: bool + + arguments: + array $select + array $tables + ?array $where = null + ?array $order = null + ?int $limit = null +end note + +note right of Load::one + Load one + + since: 3.2.0 + return: bool + + arguments: + array $select + array $tables + ?array $where = null + ?array $order = null +end note + +note left of Load::query + Get the query object + + since: 3.2.0 + return: ?object + + arguments: + array $select + array $tables + ?array $where = null + ?array $order = null + ?int $limit = null +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/06f8eada-d59b-441c-b287-0aea1793da5a/code.php b/src/06f8eada-d59b-441c-b287-0aea1793da5a/code.php new file mode 100644 index 0000000..8d91af9 --- /dev/null +++ b/src/06f8eada-d59b-441c-b287-0aea1793da5a/code.php @@ -0,0 +1,381 @@ + + * @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\Database; + + +use VDM\Joomla\Utilities\ArrayHelper; +use VDM\Joomla\Componentbuilder\Interfaces\LoadInterface; +use VDM\Joomla\Componentbuilder\Abstraction\Database; + + +/** + * Database Load + * + * @since 3.2.0 + */ +final class Load extends Database implements LoadInterface +{ + /** + * Load data rows as an array of associated arrays + * + * @param array $select Array of selection keys + * @param array $tables Array of tables to search + * @param array|null $where Array of where key=>value match exist + * @param array|null $order Array of how to order the data + * @param int|null $limit Limit the number of values returned + * + * @return array|null + * @since 3.2.0 + **/ + public function rows(array $select, array $tables, ?array $where = null, + ?array $order = null, ?int $limit = null): ?array + { + // set key if found + $key = ''; + if (isset($select['key'])) + { + if (is_string($select['key'])) + { + $key = $select['key']; + } + unset($select['key']); + } + + // check if we can get many rows + if ($this->many($select, $tables, $where, $order, $limit)) + { + // return associated arrays from the table records + return $this->db->loadAssocList($key); + } + + // data does not exist + return null; + } + + /** + * Load data rows as an array of objects + * + * @param array $select Array of selection keys + * @param array $tables Array of tables to search + * @param array|null $where Array of where key=>value match exist + * @param array|null $order Array of how to order the data + * @param int|null $limit Limit the number of values returned + * + * @return array|null + * @since 3.2.0 + **/ + public function items(array $select, array $tables, ?array $where = null, + ?array $order = null, ?int $limit = null): ?array + { + // set key if found + $key = ''; + if (isset($select['key'])) + { + if (is_string($select['key'])) + { + $key = $select['key']; + } + unset($select['key']); + } + + // check if we can get many rows + if ($this->many($select, $tables, $where, $order, $limit)) + { + // return associated arrays from the table records + return $this->db->loadObjectList($key); + } + + // data does not exist + return null; + } + + /** + * Load data row as an associated array + * + * @param array $select Array of selection keys + * @param array $tables Array of tables to search + * @param array|null $where Array of where key=>value match exist + * @param array|null $order Array of how to order the data + * + * @return array|null + * @since 3.2.0 + **/ + public function row(array $select, array $tables, ?array $where = null, ?array $order = null): ?array + { + // check if we can get one row + if ($this->one($select, $tables, $where, $order)) + { + return $this->db->loadAssoc(); + } + + // data does not exist + return null; + } + + /** + * Load data row as an object + * + * @param array $select Array of selection keys + * @param array $tables Array of tables to search + * @param array|null $where Array of where key=>value match exist + * @param array|null $order Array of how to order the data + * + * @return object|null + * @since 3.2.0 + **/ + public function item(array $select, array $tables, ?array $where = null, ?array $order = null): ?object + { + // check if we can get one row + if ($this->one($select, $tables, $where, $order)) + { + return $this->db->loadObject(); + } + + // data does not exist + return null; + } + + /** + * Load one value from a row + * + * @param array $select Array of selection keys + * @param array $tables Array of tables to search + * @param array|null $where Array of where key=>value match exist + * @param array|null $order Array of how to order the data + * + * @return mixed + * @since 3.2.0 + **/ + public function value(array $select, array $tables, ?array $where = null, ?array $order = null) + { + // check if we can get one value + if ($this->one($select, $tables, $where, $order)) + { + return $this->db->loadResult(); + } + + // data does not exist + return null; + } + + /** + * Load many + * + * @param array $select Array of selection keys + * @param array $tables Array of tables to search + * @param array|null $where Array of where key=>value match exist + * @param array|null $order Array of how to order the data + * @param int|null $limit Limit the number of values returned + * + * @return bool + * @since 3.2.0 + **/ + protected function many(array $select, array $tables, ?array $where = null, + ?array $order = null, ?int $limit = null): bool + { + // only do check if we have the table set + if (isset($tables['a'])) + { + // get the query + $query = $this->query($select, $tables, $where, $order); + + // Load the items + $this->db->setQuery($query); + $this->db->execute(); + + // check if we have values + if ($this->db->getNumRows()) + { + return true; + } + } + + // data does not exist + return false; + } + + /** + * Load one + * + * @param array $select Array of selection keys + * @param array $tables Array of tables to search + * @param array|null $where Array of where key=>value match exist + * @param array|null $order Array of how to order the data + * + * @return bool + * @since 3.2.0 + **/ + protected function one(array $select, array $tables, ?array $where = null, ?array $order = null): bool + { + // only do check if we have the table set + if (isset($tables['a'])) + { + // get the query + $query = $this->query($select, $tables, $where, $order); + + // Load the item + $this->db->setQuery($query, 0, 1); + $this->db->execute(); + + // check if we have values + if ($this->db->getNumRows()) + { + return true; + } + } + + // data does not exist + return false; + } + + /** + * Get the query object + * + * @param array $select Array of selection keys + * @param array $tables Array of tables to search + * @param array|null $where Array of where key=>value match exist + * @param array|null $order Array of how to order the data + * @param int|null $limit Limit the number of values returned + * + * @return object|null The query object (DatabaseQuery) + * @since 3.2.0 + **/ + protected function query(array $select, array $tables, ?array $where = null, + ?array $order = null, ?int $limit = null): ?object + { + $query = $this->db->getQuery(true); + + // check if we have an all selection set + if (isset($select['all'])) + { + // all selection example array: ['all' => ['a.*', 'b.*']] + if (ArrayHelper::check($select['all'])) + { + foreach ($select['all'] as $select_all) + { + // set target selection + $query->select( + $select_all + ); + } + } + // all selection example string: ['all' =>'a.*'] + elseif (is_string($select['all'])) + { + // set target selection + $query->select( + $select['all'] + ); + } + unset($select['all']); + } + + // load the table where join + if (ArrayHelper::check($select)) + { + // set target selection + $query->select( + $this->db->quoteName( + array_keys($select), + array_values($select) + ) + ); + } + + // set main table + $query->from($this->db->quoteName($this->getTable($tables['a']), 'a')); + + // remove main table + unset($tables['a']); + + // load the table where join + if (ArrayHelper::check($tables)) + { + foreach ($tables as $as => $table) + { + $query->join( + 'LEFT', $this->db->quoteName( + $this->getTable($table['name']), $as + ) . ' ON (' . $this->db->quoteName($table['join_on']) + . ' = ' . $this->db->quoteName($table['as_on']) . ')' + ); + } + } + + // load the table where getters + if (ArrayHelper::check($where)) + { + foreach ($where as $key => $value) + { + if (ArrayHelper::check($value)) + { + if (isset($value['value']) && isset($value['operator'])) + { + if (ArrayHelper::check($value['value'])) + { + // add the where by array + $query->where($this->db->quoteName($key) . ' ' . + $value['operator'] . ' (' . + implode(',', + array_map( + fn($val) => $this->quote($val), + $value['value'] + ) + ) + . ')' + ); + } + else + { + // add the where + $query->where($this->db->quoteName($key) . ' ' . + $value['operator'] . ' ' . $this->quote($value['value'])); + } + } + else + { + // we should through an exception + // for security we just return nothing for now + return null; + } + } + else + { + // add the where + $query->where($this->db->quoteName($key) . + ' = ' . $this->quote($value)); + } + } + } + + // load the row ordering + if (ArrayHelper::check($order)) + { + foreach ($order as $key => $direction) + { + // add the ordering + $query->order($this->db->quoteName($key) . + ' ' . $direction); + } + } + + // only return a limited number + if (is_numeric($limit)) + { + $query->setLimit($limit); + } + + return $query; + } + +} + diff --git a/src/06f8eada-d59b-441c-b287-0aea1793da5a/code.power b/src/06f8eada-d59b-441c-b287-0aea1793da5a/code.power new file mode 100644 index 0000000..965b225 --- /dev/null +++ b/src/06f8eada-d59b-441c-b287-0aea1793da5a/code.power @@ -0,0 +1,352 @@ + /** + * Load data rows as an array of associated arrays + * + * @param array $select Array of selection keys + * @param array $tables Array of tables to search + * @param array|null $where Array of where key=>value match exist + * @param array|null $order Array of how to order the data + * @param int|null $limit Limit the number of values returned + * + * @return array|null + * @since 3.2.0 + **/ + public function rows(array $select, array $tables, ?array $where = null, + ?array $order = null, ?int $limit = null): ?array + { + // set key if found + $key = ''; + if (isset($select['key'])) + { + if (is_string($select['key'])) + { + $key = $select['key']; + } + unset($select['key']); + } + + // check if we can get many rows + if ($this->many($select, $tables, $where, $order, $limit)) + { + // return associated arrays from the table records + return $this->db->loadAssocList($key); + } + + // data does not exist + return null; + } + + /** + * Load data rows as an array of objects + * + * @param array $select Array of selection keys + * @param array $tables Array of tables to search + * @param array|null $where Array of where key=>value match exist + * @param array|null $order Array of how to order the data + * @param int|null $limit Limit the number of values returned + * + * @return array|null + * @since 3.2.0 + **/ + public function items(array $select, array $tables, ?array $where = null, + ?array $order = null, ?int $limit = null): ?array + { + // set key if found + $key = ''; + if (isset($select['key'])) + { + if (is_string($select['key'])) + { + $key = $select['key']; + } + unset($select['key']); + } + + // check if we can get many rows + if ($this->many($select, $tables, $where, $order, $limit)) + { + // return associated arrays from the table records + return $this->db->loadObjectList($key); + } + + // data does not exist + return null; + } + + /** + * Load data row as an associated array + * + * @param array $select Array of selection keys + * @param array $tables Array of tables to search + * @param array|null $where Array of where key=>value match exist + * @param array|null $order Array of how to order the data + * + * @return array|null + * @since 3.2.0 + **/ + public function row(array $select, array $tables, ?array $where = null, ?array $order = null): ?array + { + // check if we can get one row + if ($this->one($select, $tables, $where, $order)) + { + return $this->db->loadAssoc(); + } + + // data does not exist + return null; + } + + /** + * Load data row as an object + * + * @param array $select Array of selection keys + * @param array $tables Array of tables to search + * @param array|null $where Array of where key=>value match exist + * @param array|null $order Array of how to order the data + * + * @return object|null + * @since 3.2.0 + **/ + public function item(array $select, array $tables, ?array $where = null, ?array $order = null): ?object + { + // check if we can get one row + if ($this->one($select, $tables, $where, $order)) + { + return $this->db->loadObject(); + } + + // data does not exist + return null; + } + + /** + * Load one value from a row + * + * @param array $select Array of selection keys + * @param array $tables Array of tables to search + * @param array|null $where Array of where key=>value match exist + * @param array|null $order Array of how to order the data + * + * @return mixed + * @since 3.2.0 + **/ + public function value(array $select, array $tables, ?array $where = null, ?array $order = null) + { + // check if we can get one value + if ($this->one($select, $tables, $where, $order)) + { + return $this->db->loadResult(); + } + + // data does not exist + return null; + } + + /** + * Load many + * + * @param array $select Array of selection keys + * @param array $tables Array of tables to search + * @param array|null $where Array of where key=>value match exist + * @param array|null $order Array of how to order the data + * @param int|null $limit Limit the number of values returned + * + * @return bool + * @since 3.2.0 + **/ + protected function many(array $select, array $tables, ?array $where = null, + ?array $order = null, ?int $limit = null): bool + { + // only do check if we have the table set + if (isset($tables['a'])) + { + // get the query + $query = $this->query($select, $tables, $where, $order); + + // Load the items + $this->db->setQuery($query); + $this->db->execute(); + + // check if we have values + if ($this->db->getNumRows()) + { + return true; + } + } + + // data does not exist + return false; + } + + /** + * Load one + * + * @param array $select Array of selection keys + * @param array $tables Array of tables to search + * @param array|null $where Array of where key=>value match exist + * @param array|null $order Array of how to order the data + * + * @return bool + * @since 3.2.0 + **/ + protected function one(array $select, array $tables, ?array $where = null, ?array $order = null): bool + { + // only do check if we have the table set + if (isset($tables['a'])) + { + // get the query + $query = $this->query($select, $tables, $where, $order); + + // Load the item + $this->db->setQuery($query, 0, 1); + $this->db->execute(); + + // check if we have values + if ($this->db->getNumRows()) + { + return true; + } + } + + // data does not exist + return false; + } + + /** + * Get the query object + * + * @param array $select Array of selection keys + * @param array $tables Array of tables to search + * @param array|null $where Array of where key=>value match exist + * @param array|null $order Array of how to order the data + * @param int|null $limit Limit the number of values returned + * + * @return object|null The query object (DatabaseQuery) + * @since 3.2.0 + **/ + protected function query(array $select, array $tables, ?array $where = null, + ?array $order = null, ?int $limit = null): ?object + { + $query = $this->db->getQuery(true); + + // check if we have an all selection set + if (isset($select['all'])) + { + // all selection example array: ['all' => ['a.*', 'b.*']] + if (ArrayHelper::check($select['all'])) + { + foreach ($select['all'] as $select_all) + { + // set target selection + $query->select( + $select_all + ); + } + } + // all selection example string: ['all' =>'a.*'] + elseif (is_string($select['all'])) + { + // set target selection + $query->select( + $select['all'] + ); + } + unset($select['all']); + } + + // load the table where join + if (ArrayHelper::check($select)) + { + // set target selection + $query->select( + $this->db->quoteName( + array_keys($select), + array_values($select) + ) + ); + } + + // set main table + $query->from($this->db->quoteName($this->getTable($tables['a']), 'a')); + + // remove main table + unset($tables['a']); + + // load the table where join + if (ArrayHelper::check($tables)) + { + foreach ($tables as $as => $table) + { + $query->join( + 'LEFT', $this->db->quoteName( + $this->getTable($table['name']), $as + ) . ' ON (' . $this->db->quoteName($table['join_on']) + . ' = ' . $this->db->quoteName($table['as_on']) . ')' + ); + } + } + + // load the table where getters + if (ArrayHelper::check($where)) + { + foreach ($where as $key => $value) + { + if (ArrayHelper::check($value)) + { + if (isset($value['value']) && isset($value['operator'])) + { + if (ArrayHelper::check($value['value'])) + { + // add the where by array + $query->where($this->db->quoteName($key) . ' ' . + $value['operator'] . ' (' . + implode(',', + array_map( + fn($val) => $this->quote($val), + $value['value'] + ) + ) + . ')' + ); + } + else + { + // add the where + $query->where($this->db->quoteName($key) . ' ' . + $value['operator'] . ' ' . $this->quote($value['value'])); + } + } + else + { + // we should through an exception + // for security we just return nothing for now + return null; + } + } + else + { + // add the where + $query->where($this->db->quoteName($key) . + ' = ' . $this->quote($value)); + } + } + } + + // load the row ordering + if (ArrayHelper::check($order)) + { + foreach ($order as $key => $direction) + { + // add the ordering + $query->order($this->db->quoteName($key) . + ' ' . $direction); + } + } + + // only return a limited number + if (is_numeric($limit)) + { + $query->setLimit($limit); + } + + return $query; + } diff --git a/src/06f8eada-d59b-441c-b287-0aea1793da5a/settings.json b/src/06f8eada-d59b-441c-b287-0aea1793da5a/settings.json new file mode 100644 index 0000000..6a47f8f --- /dev/null +++ b/src/06f8eada-d59b-441c-b287-0aea1793da5a/settings.json @@ -0,0 +1,25 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "6cbef8f8-4813-48e3-b05a-65e1aea95171", + "guid": "06f8eada-d59b-441c-b287-0aea1793da5a", + "implements": [ + "2ad31f74-f579-499d-b98b-c4f54fd615dd" + ], + "load_selection": null, + "name": "Load", + "power_version": "1.0.0", + "system_name": "JCB.Database.Load", + "type": "final class", + "use_selection": { + "use_selection0": { + "use": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Database.Load", + "description": "Database Load\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/0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a/code.power b/src/0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a/code.power new file mode 100644 index 0000000..efbf012 --- /dev/null +++ b/src/0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a/code.power @@ -0,0 +1,83 @@ + /** + * Check if have an array with a length + * + * @input array The array to check + * + * @returns int|false number of items in array on success + * + * @since 3.2.0 + */ + public static function check($array, $removeEmptyString = false) + { + if (is_array($array) && ($nr = count((array) $array)) > 0) + { + // also make sure the empty strings are removed + if ($removeEmptyString) + { + $array = array_filter($array); + + if ($array === []) + { + return false; + } + + return count($array); + } + + return $nr; + } + + return false; + } + + /** + * Merge an array of array's + * + * @input array The arrays you would like to merge + * + * @returns array|null merged array on success + * + * @since 3.0.9 + */ + public static function merge($arrays): ?array + { + if(self::check($arrays)) + { + $merged = []; + foreach ($arrays as $array) + { + if (self::check($array)) + { + $merged = array_merge($merged, $array); + } + } + return $merged; + } + return null; + } + + /** + * Check if arrays intersect + * + * @input array The first array + * @input array The second array + * + * @returns bool true if intersect else false + * + * @since 3.1.1 + */ + public static function intersect($a_array, $b_array): bool + { + // flip the second array + $b_array = array_flip($b_array); + + // loop the first array + foreach ($a_array as $v) + { + if (isset($b_array[$v])) + { + return true; + } + } + return false; + } diff --git a/src/0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a/settings.json b/src/0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a/settings.json index fb447d1..7305c7c 100644 --- a/src/0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a/settings.json +++ b/src/0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a/settings.json @@ -1,10 +1,9 @@ { "add_head": "0", + "add_licensing_template": "2", "extends": "0", - "extends_custom": "", "guid": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a", "implements": null, - "implements_custom": "", "load_selection": null, "name": "ArrayHelper", "power_version": "1.0.0", @@ -12,5 +11,8 @@ "type": "abstract class", "use_selection": null, "namespace": "VDM\\Joomla\\Utilities.ArrayHelper", - "description": "Some array tricks helper\r\n\r\n@since 3.0.9" + "description": "Some array tricks helper\r\n\r\n@since 3.0.9", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 3rd September, 2020\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/1198aecf-84c6-45d2-aea8-d531aa4afdfa/README.md b/src/1198aecf-84c6-45d2-aea8-d531aa4afdfa/README.md new file mode 100644 index 0000000..6df4784 --- /dev/null +++ b/src/1198aecf-84c6-45d2-aea8-d531aa4afdfa/README.md @@ -0,0 +1,84 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# abstract class FormHelper (Details) +> namespace: **VDM\Joomla\Componentbuilder\Utilities** +```uml +@startuml +abstract FormHelper #Orange { + + {static} xml(array $attributes, ?array $options = null) : ?\SimpleXMLElement + + {static} append(\SimpleXMLElement $xml, mixed $node) : void + + {static} comment(\SimpleXMLElement $xml, string $comment) : void + + {static} attributes(\SimpleXMLElement $xml, array $attributes = []) : void + + {static} options(\SimpleXMLElement $xml, array $options = []) : void + + {static} field(array $attributes, string $default = '', ...) : ?FormField +} + +note right of FormHelper::xml + get the field xml + + since: 3.2.0 + return: ?\SimpleXMLElement +end note + +note right of FormHelper::append + xmlAppend +or a stdClass object containing a comment attribute to be injected +before the XML node and a fieldXML attribute containing a SimpleXMLElement + + since: 3.2.0 + return: void +end note + +note right of FormHelper::comment + xmlComment + + since: 3.2.0 + return: void +end note + +note right of FormHelper::attributes + xmlAddAttributes + + since: 3.2.0 + return: void +end note + +note right of FormHelper::options + xmlAddOptions + + since: 3.2.0 + return: void +end note + +note right of FormHelper::field + get the field object + + since: 3.2.0 + return: ?FormField + + arguments: + array $attributes + string $default = '' + ?array $options = null +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/1198aecf-84c6-45d2-aea8-d531aa4afdfa/code.php b/src/1198aecf-84c6-45d2-aea8-d531aa4afdfa/code.php new file mode 100644 index 0000000..6fff729 --- /dev/null +++ b/src/1198aecf-84c6-45d2-aea8-d531aa4afdfa/code.php @@ -0,0 +1,189 @@ + + * @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\Utilities; + + +use Joomla\CMS\Form\FormHelper as JoomlaFormHelper; +use Joomla\CMS\Form\FormField; +use VDM\Joomla\Utilities\ArrayHelper; + + +/** + * Form Helper + * + * @since 3.2.0 + */ +abstract class FormHelper +{ + /** + * get the field xml + * + * @param array $attributes The array of attributes + * @param array $options The options to apply to the XML element + * + * @return \SimpleXMLElement|null + * @since 3.2.0 + */ + public static function xml(array $attributes, ?array $options = null): ?\SimpleXMLElement + { + // make sure we have attributes and a type value + if (ArrayHelper::check($attributes)) + { + // start field xml + $XML = new \SimpleXMLElement(''); + + // load the attributes + self::attributes($XML, $attributes); + + // check if we have options + if (ArrayHelper::check($options)) + { + // load the options + self::options($XML, $options); + } + + // return the field xml + return $XML; + } + + return null; + } + + /** + * xmlAppend + * + * @param \SimpleXMLElement $xml The XML element reference in which to inject a comment + * @param mixed $node A SimpleXMLElement node to append to the XML element reference, + * or a stdClass object containing a comment attribute to be injected + * before the XML node and a fieldXML attribute containing a SimpleXMLElement + * + * @return void + * @since 3.2.0 + */ + public static function append(\SimpleXMLElement &$xml, $node) + { + if (!$node) + { + // element was not returned + return; + } + switch (get_class($node)) + { + case 'stdClass': + if (property_exists($node, 'comment')) + { + self::comment($xml, $node->comment); + } + if (property_exists($node, 'fieldXML')) + { + self::append($xml, $node->fieldXML); + } + break; + case 'SimpleXMLElement': + $domXML = \dom_import_simplexml($xml); + $domNode = \dom_import_simplexml($node); + $domXML->appendChild($domXML->ownerDocument->importNode($domNode, true)); + $xml = \simplexml_import_dom($domXML); + break; + } + } + + /** + * xmlComment + * + * @param \SimpleXMLElement $xml The XML element reference in which to inject a comment + * @param string $comment The comment to inject + * + * @return void + * @since 3.2.0 + */ + public static function comment(\SimpleXMLElement &$xml, string $comment) + { + $domXML = \dom_import_simplexml($xml); + $domComment = new \DOMComment($comment); + $nodeTarget = $domXML->ownerDocument->importNode($domComment, true); + $domXML->appendChild($nodeTarget); + $xml = \simplexml_import_dom($domXML); + } + + /** + * xmlAddAttributes + * + * @param \SimpleXMLElement $xml The XML element reference in which to inject a comment + * @param array $attributes The attributes to apply to the XML element + * + * @return void + * @since 3.2.0 + */ + public static function attributes(\SimpleXMLElement &$xml, array $attributes = []) + { + foreach ($attributes as $key => $value) + { + $xml->addAttribute($key, $value); + } + } + + /** + * xmlAddOptions + * + * @param \SimpleXMLElement $xml The XML element reference in which to inject a comment + * @param array $options The options to apply to the XML element + * + * @return void + * @since 3.2.0 + */ + public static function options(\SimpleXMLElement &$xml, array $options = []) + { + foreach ($options as $key => $value) + { + $addOption = $xml->addChild('option'); + $addOption->addAttribute('value', $key); + $addOption[] = $value; + } + } + + /** + * get the field object + * + * @param array $attributes The array of attributes + * @param string $default The default of the field + * @param array $options The options to apply to the XML element + * + * @return FormField|null + * @since 3.2.0 + */ + public static function field(array $attributes, string $default = '', ?array $options = null): ?FormField + { + // make sure we have attributes and a type value + if (ArrayHelper::check($attributes) && isset($attributes['type'])) + { + // get field type + if (($field = JoomlaFormHelper::loadFieldType($attributes['type'], true)) === false) + { + return null; + } + + // get field xml + $XML = self::xml($attributes, $options); + + // setup the field + $field->setup($XML, $default); + + // return the field object + return $field; + } + + return null; + } + +} + diff --git a/src/1198aecf-84c6-45d2-aea8-d531aa4afdfa/code.power b/src/1198aecf-84c6-45d2-aea8-d531aa4afdfa/code.power new file mode 100644 index 0000000..771d5dd --- /dev/null +++ b/src/1198aecf-84c6-45d2-aea8-d531aa4afdfa/code.power @@ -0,0 +1,160 @@ + /** + * get the field xml + * + * @param array $attributes The array of attributes + * @param array $options The options to apply to the XML element + * + * @return \SimpleXMLElement|null + * @since 3.2.0 + */ + public static function xml(array $attributes, ?array $options = null): ?\SimpleXMLElement + { + // make sure we have attributes and a type value + if (ArrayHelper::check($attributes)) + { + // start field xml + $XML = new \SimpleXMLElement(''); + + // load the attributes + self::attributes($XML, $attributes); + + // check if we have options + if (ArrayHelper::check($options)) + { + // load the options + self::options($XML, $options); + } + + // return the field xml + return $XML; + } + + return null; + } + + /** + * xmlAppend + * + * @param \SimpleXMLElement $xml The XML element reference in which to inject a comment + * @param mixed $node A SimpleXMLElement node to append to the XML element reference, + * or a stdClass object containing a comment attribute to be injected + * before the XML node and a fieldXML attribute containing a SimpleXMLElement + * + * @return void + * @since 3.2.0 + */ + public static function append(\SimpleXMLElement &$xml, $node) + { + if (!$node) + { + // element was not returned + return; + } + switch (get_class($node)) + { + case 'stdClass': + if (property_exists($node, 'comment')) + { + self::comment($xml, $node->comment); + } + if (property_exists($node, 'fieldXML')) + { + self::append($xml, $node->fieldXML); + } + break; + case 'SimpleXMLElement': + $domXML = \dom_import_simplexml($xml); + $domNode = \dom_import_simplexml($node); + $domXML->appendChild($domXML->ownerDocument->importNode($domNode, true)); + $xml = \simplexml_import_dom($domXML); + break; + } + } + + /** + * xmlComment + * + * @param \SimpleXMLElement $xml The XML element reference in which to inject a comment + * @param string $comment The comment to inject + * + * @return void + * @since 3.2.0 + */ + public static function comment(\SimpleXMLElement &$xml, string $comment) + { + $domXML = \dom_import_simplexml($xml); + $domComment = new \DOMComment($comment); + $nodeTarget = $domXML->ownerDocument->importNode($domComment, true); + $domXML->appendChild($nodeTarget); + $xml = \simplexml_import_dom($domXML); + } + + /** + * xmlAddAttributes + * + * @param \SimpleXMLElement $xml The XML element reference in which to inject a comment + * @param array $attributes The attributes to apply to the XML element + * + * @return void + * @since 3.2.0 + */ + public static function attributes(\SimpleXMLElement &$xml, array $attributes = []) + { + foreach ($attributes as $key => $value) + { + $xml->addAttribute($key, $value); + } + } + + /** + * xmlAddOptions + * + * @param \SimpleXMLElement $xml The XML element reference in which to inject a comment + * @param array $options The options to apply to the XML element + * + * @return void + * @since 3.2.0 + */ + public static function options(\SimpleXMLElement &$xml, array $options = []) + { + foreach ($options as $key => $value) + { + $addOption = $xml->addChild('option'); + $addOption->addAttribute('value', $key); + $addOption[] = $value; + } + } + + /** + * get the field object + * + * @param array $attributes The array of attributes + * @param string $default The default of the field + * @param array $options The options to apply to the XML element + * + * @return FormField|null + * @since 3.2.0 + */ + public static function field(array $attributes, string $default = '', ?array $options = null): ?FormField + { + // make sure we have attributes and a type value + if (ArrayHelper::check($attributes) && isset($attributes['type'])) + { + // get field type + if (($field = JoomlaFormHelper::loadFieldType($attributes['type'], true)) === false) + { + return null; + } + + // get field xml + $XML = self::xml($attributes, $options); + + // setup the field + $field->setup($XML, $default); + + // return the field object + return $field; + } + + return null; + } diff --git a/src/1198aecf-84c6-45d2-aea8-d531aa4afdfa/settings.json b/src/1198aecf-84c6-45d2-aea8-d531aa4afdfa/settings.json new file mode 100644 index 0000000..8951a67 --- /dev/null +++ b/src/1198aecf-84c6-45d2-aea8-d531aa4afdfa/settings.json @@ -0,0 +1,23 @@ +{ + "add_head": "1", + "add_licensing_template": "2", + "extends": "0", + "guid": "1198aecf-84c6-45d2-aea8-d531aa4afdfa", + "implements": null, + "load_selection": null, + "name": "FormHelper", + "power_version": "1.0.0", + "system_name": "JCB.Utilities.FormHelper", + "type": "abstract class", + "use_selection": { + "use_selection0": { + "use": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Utilities.FormHelper", + "description": "Form Helper\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": "use Joomla\\CMS\\Form\\FormHelper as JoomlaFormHelper;\r\nuse Joomla\\CMS\\Form\\FormField;", + "composer": "" +} \ No newline at end of file diff --git a/src/152c8793-8b75-4715-996a-257b9f65451c/code.power b/src/152c8793-8b75-4715-996a-257b9f65451c/code.power new file mode 100644 index 0000000..68c8863 --- /dev/null +++ b/src/152c8793-8b75-4715-996a-257b9f65451c/code.power @@ -0,0 +1,79 @@ + /** + * bc math wrapper (very basic not for accounting) + * + * @param string $type The type bc math + * @param int $val1 The first value + * @param int $val2 The second value + * @param int $scale The scale value + * + * @return int + * + * @since 3.0.9 + */ + public static function bc($type, $val1, $val2, $scale = 0) + { + // build function name + $function = 'bc' . $type; + // use the bcmath function if available + if (function_exists($function)) + { + return $function($val1, $val2, $scale); + } + // if function does not exist we use +-*/ operators (fallback - not ideal) + switch ($type) + { + // Multiply two numbers + case 'mul': + return (string) round($val1 * $val2, $scale); + break; + // Divide of two numbers + case 'div': + return (string) round($val1 / $val2, $scale); + break; + // Adding two numbers + case 'add': + return (string) round($val1 + $val2, $scale); + break; + // Subtract one number from the other + case 'sub': + return (string) round($val1 - $val2, $scale); + break; + // Raise an arbitrary precision number to another + case 'pow': + return (string) round(pow($val1, $val2), $scale); + break; + // Compare two arbitrary precision numbers + case 'comp': + return (round($val1,2) == round($val2,2)); + break; + } + return false; + } + + /** + * Basic sum of an array with more precision + * + * @param array $array The values to sum + * @param int $scale The scale value + * + * @return float + * + * @since 3.0.9 + */ + public static function sum($array, $scale = 4) + { + // use the bcadd function if available + if (function_exists('bcadd')) + { + // set the start value + $value = 0.0; + // loop the values and run bcadd + foreach($array as $val) + { + $value = bcadd($value, (string) $val, $scale); + } + return $value; + } + // fall back on array sum + return array_sum($array); + } diff --git a/src/152c8793-8b75-4715-996a-257b9f65451c/settings.json b/src/152c8793-8b75-4715-996a-257b9f65451c/settings.json index c149221..e9c4168 100644 --- a/src/152c8793-8b75-4715-996a-257b9f65451c/settings.json +++ b/src/152c8793-8b75-4715-996a-257b9f65451c/settings.json @@ -1,10 +1,9 @@ { "add_head": "0", + "add_licensing_template": "2", "extends": "0", - "extends_custom": "", "guid": "152c8793-8b75-4715-996a-257b9f65451c", "implements": null, - "implements_custom": "", "load_selection": null, "name": "MathHelper", "power_version": "1.0.0", @@ -12,5 +11,8 @@ "type": "abstract class", "use_selection": null, "namespace": "VDM\\Joomla\\Utilities.MathHelper", - "description": "Basic Math Helper\r\n\r\n@since 3.0.9" + "description": "Basic Math Helper\r\n\r\n@since 3.0.9", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 3rd September, 2020\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/1f28cb53-60d9-4db1-b517-3c7dc6b429ef/code.power b/src/1f28cb53-60d9-4db1-b517-3c7dc6b429ef/code.power new file mode 100644 index 0000000..2ec6411 --- /dev/null +++ b/src/1f28cb53-60d9-4db1-b517-3c7dc6b429ef/code.power @@ -0,0 +1,387 @@ + /** + * The Main Active Language + * + * @var string + * + * @since 3.0.9 + */ + public static $langTag; + + /** + * Check if we have a string with a length + * + * @input string $string The string to check + * + * @returns bool true on success + * + * @since 3.0.9 + */ + public static function check($string): bool + { + return is_string($string) && strlen($string) > 0; + } + + /** + * Shorten a string + * + * @input string The you would like to shorten + * + * @returns string on success + * + * @since 3.0.9 + */ + public static function shorten($string, $length = 40, $addTip = true) + { + if (self::check($string)) + { + $initial = strlen((string) $string); + $words = preg_split('/([\s\n\r]+)/', (string) $string, null, PREG_SPLIT_DELIM_CAPTURE); + $words_count = count((array)$words); + + $word_length = 0; + $last_word = 0; + for (; $last_word < $words_count; ++$last_word) + { + $word_length += strlen($words[$last_word]); + if ($word_length > $length) + { + break; + } + } + + $newString = implode(array_slice($words, 0, $last_word)); + $final = strlen($newString); + if ($initial !== $final && $addTip) + { + $title = self::shorten($string, 400 , false); + return '' . trim($newString) . '...'; + } + elseif ($initial !== $final && !$addTip) + { + return trim($newString) . '...'; + } + } + return $string; + } + + /** + * Making strings safe (various ways) + * + * @input string The you would like to make safe + * + * @returns string on success + * + * @since 3.0.9 + */ + public static function safe($string, $type = 'L', $spacer = '_', $replaceNumbers = true, $keepOnlyCharacters = true) + { + if ($replaceNumbers === true) + { + // remove all numbers and replace with English text version (works well only up to millions) + $string = self::numbers($string); + } + // 0nly continue if we have a string + if (self::check($string)) + { + // create file name without the extension that is safe + if ($type === 'filename') + { + // make sure VDM is not in the string + $string = str_replace('VDM', 'vDm', (string) $string); + // Remove anything which isn't a word, whitespace, number + // or any of the following caracters -_() + // If you don't need to handle multi-byte characters + // you can use preg_replace rather than mb_ereg_replace + // Thanks @Łukasz Rysiak! + // $string = mb_ereg_replace("([^\w\s\d\-_\(\)])", '', $string); + $string = preg_replace("([^\w\s\d\-_\(\)])", '', $string); + + // http://stackoverflow.com/a/2021729/1429677 + return preg_replace('/\s+/', ' ', (string) $string); + } + // remove all other characters + $string = trim((string) $string); + $string = preg_replace('/'.$spacer.'+/', ' ', $string); + $string = preg_replace('/\s+/', ' ', $string); + // Transliterate string + $string = self::transliterate($string); + // remove all and keep only characters + if ($keepOnlyCharacters) + { + $string = preg_replace("/[^A-Za-z ]/", '', (string) $string); + } + // keep both numbers and characters + else + { + $string = preg_replace("/[^A-Za-z0-9 ]/", '', (string) $string); + } + // select final adaptations + if ($type === 'L' || $type === 'strtolower') + { + // replace white space with underscore + $string = preg_replace('/\s+/', (string) $spacer, (string) $string); + // default is to return lower + return strtolower($string); + } + elseif ($type === 'W') + { + // return a string with all first letter of each word uppercase(no underscore) + return ucwords(strtolower($string)); + } + elseif ($type === 'w' || $type === 'word') + { + // return a string with all lowercase(no underscore) + return strtolower($string); + } + elseif ($type === 'Ww' || $type === 'Word') + { + // return a string with first letter of the first word uppercase and all the rest lowercase(no underscore) + return ucfirst(strtolower($string)); + } + elseif ($type === 'WW' || $type === 'WORD') + { + // return a string with all the uppercase(no underscore) + return strtoupper($string); + } + elseif ($type === 'U' || $type === 'strtoupper') + { + // replace white space with underscore + $string = preg_replace('/\s+/', (string) $spacer, $string); + // return all upper + return strtoupper($string); + } + elseif ($type === 'F' || $type === 'ucfirst') + { + // replace white space with underscore + $string = preg_replace('/\s+/', (string) $spacer, $string); + // return with first character to upper + return ucfirst(strtolower($string)); + } + elseif ($type === 'cA' || $type === 'cAmel' || $type === 'camelcase') + { + // convert all words to first letter uppercase + $string = ucwords(strtolower($string)); + // remove white space + $string = preg_replace('/\s+/', '', $string); + // now return first letter lowercase + return lcfirst($string); + } + // return string + return $string; + } + // not a string + return ''; + } + + /** + * Convert none English strings to code usable string + * + * @input an string + * + * @returns a string + * + * @since 3.0.9 + */ + public static function transliterate($string) + { + // set tag only once + if (!self::check(self::$langTag)) + { + // get global value + self::$langTag = Helper::getParams()->get('language', 'en-GB'); + } + + // Transliterate on the language requested + $lang = Language::getInstance(self::$langTag); + + return $lang->transliterate($string); + } + + /** + * make sure a string is HTML save + * + * @input an html string + * + * @returns a string + * + * @since 3.0.9 + */ + public static function html($var, $charset = 'UTF-8', $shorten = false, $length = 40, $addTip = true) + { + if (self::check($var)) + { + $filter = new InputFilter(); + $string = $filter->clean( + html_entity_decode( + htmlentities( + (string) $var, + ENT_COMPAT, + $charset + ) + ), + 'HTML' + ); + if ($shorten) + { + return self::shorten($string, $length, $addTip); + } + return $string; + } + else + { + return ''; + } + } + + /** + * Convert all int in a string to an English word string + * + * @input an string with numbers + * + * @returns a string + * + * @since 3.0.9 + */ + public static function numbers($string) + { + // set numbers array + $numbers = []; + $search_replace= []; + + // first get all numbers + preg_match_all('!\d+!', (string) $string, $numbers); + + // check if we have any numbers + if (isset($numbers[0]) && ArrayHelper::check($numbers[0])) + { + foreach ($numbers[0] as $number) + { + $search_replace[$number] = self::number((int)$number); + } + + // now replace numbers in string + $string = str_replace(array_keys($search_replace), array_values($search_replace), (string) $string); + + // check if we missed any, strange if we did. + return self::numbers($string); + } + + // return the string with no numbers remaining. + return $string; + } + + /** + * Convert an integer into an English word string + * Thanks to Tom Nicholson + * + * @input an int + * @returns a string + * + * @since 3.0.9 + */ + public static function number($x) + { + $nwords = array( "zero", "one", "two", "three", "four", "five", "six", "seven", + "eight", "nine", "ten", "eleven", "twelve", "thirteen", + "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", + "nineteen", "twenty", 30 => "thirty", 40 => "forty", + 50 => "fifty", 60 => "sixty", 70 => "seventy", 80 => "eighty", + 90 => "ninety" ); + + if(!is_numeric($x)) + { + $w = $x; + } + elseif(fmod($x, 1) != 0) + { + $w = $x; + } + else + { + if($x < 0) + { + $w = 'minus '; + $x = -$x; + } + else + { + $w = ''; + // ... now $x is a non-negative integer. + } + + if($x < 21) // 0 to 20 + { + $w .= $nwords[$x]; + } + elseif($x < 100) // 21 to 99 + { + $w .= $nwords[10 * floor($x/10)]; + $r = fmod($x, 10); + if($r > 0) + { + $w .= ' ' . $nwords[$r]; + } + } + elseif($x < 1000) // 100 to 999 + { + $w .= $nwords[floor($x/100)] .' hundred'; + $r = fmod($x, 100); + if($r > 0) + { + $w .= ' and '. self::number($r); + } + } + elseif($x < 1000000) // 1000 to 999999 + { + $w .= self::number(floor($x/1000)) .' thousand'; + $r = fmod($x, 1000); + if($r > 0) + { + $w .= ' '; + if($r < 100) + { + $w .= 'and '; + } + $w .= self::number($r); + } + } + else // millions + { + $w .= self::number(floor($x/1000000)) .' million'; + $r = fmod($x, 1000000); + if($r > 0) + { + $w .= ' '; + if($r < 100) + { + $w .= 'and '; + } + $w .= self::number($r); + } + } + } + return $w; + } + + /** + * Random Key + * + * @input int $size The size of the random string + * + * @returns a string + * @since 3.0.9 + */ + public static function random(int $size): string + { + $bag = "abcefghijknopqrstuwxyzABCDDEFGHIJKLLMMNOPQRSTUVVWXYZabcddefghijkllmmnopqrstuvvwxyzABCEFGHIJKNOPQRSTUWXYZ"; + $key = []; + $bagsize = strlen($bag) - 1; + + for ($i = 0; $i < $size; $i++) + { + $get = rand(0, $bagsize); + $key[] = $bag[$get]; + } + + return implode($key); + } diff --git a/src/1f28cb53-60d9-4db1-b517-3c7dc6b429ef/settings.json b/src/1f28cb53-60d9-4db1-b517-3c7dc6b429ef/settings.json index 108aa41..cf66879 100644 --- a/src/1f28cb53-60d9-4db1-b517-3c7dc6b429ef/settings.json +++ b/src/1f28cb53-60d9-4db1-b517-3c7dc6b429ef/settings.json @@ -1,10 +1,9 @@ { "add_head": "1", + "add_licensing_template": "2", "extends": "0", - "extends_custom": "", "guid": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef", "implements": null, - "implements_custom": "", "load_selection": { "load_selection0": { "load": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a" @@ -22,5 +21,7 @@ }, "namespace": "VDM\\Joomla\\Utilities.StringHelper", "description": "Some string tricks\r\n\r\n@since 3.0.9", - "head": "use Joomla\\CMS\\Filter\\InputFilter;\r\nuse Joomla\\CMS\\Language\\Language;" + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 3rd September, 2020\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": "use Joomla\\CMS\\Filter\\InputFilter;\r\nuse Joomla\\CMS\\Language\\Language;", + "composer": "" } \ No newline at end of file diff --git a/src/30c5b4c2-f75f-4d15-869a-f8bfedd87358/README.md b/src/30c5b4c2-f75f-4d15-869a-f8bfedd87358/README.md new file mode 100644 index 0000000..92c14b5 --- /dev/null +++ b/src/30c5b4c2-f75f-4d15-869a-f8bfedd87358/README.md @@ -0,0 +1,37 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# abstract class ClassfunctionHelper (Details) +> namespace: **VDM\Joomla\Utilities\String** +```uml +@startuml +abstract ClassfunctionHelper #Orange { + + {static} safe($name) : string +} + +note right of ClassfunctionHelper::safe + Making class or function name safe + + since: 3.0.9 + return: string +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/30c5b4c2-f75f-4d15-869a-f8bfedd87358/code.php b/src/30c5b4c2-f75f-4d15-869a-f8bfedd87358/code.php new file mode 100644 index 0000000..42d21af --- /dev/null +++ b/src/30c5b4c2-f75f-4d15-869a-f8bfedd87358/code.php @@ -0,0 +1,47 @@ + + * @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\Utilities\String; + + +use VDM\Joomla\Utilities\StringHelper; + + +/** + * Control the naming of a class and function + * + * @since 3.0.9 + */ +abstract class ClassfunctionHelper +{ + /** + * Making class or function name safe + * + * @input string The name you would like to make safe + * + * @returns string on success + * + * @since 3.0.9 + */ + public static function safe($name): string + { + // remove numbers if the first character is a number + if (is_numeric(substr((string) $name, 0, 1))) + { + $name = StringHelper::numbers($name); + } + + // remove all spaces and strange characters + return trim(preg_replace("/[^A-Za-z0-9_-]/", '', (string) $name)); + } + +} + diff --git a/src/30c5b4c2-f75f-4d15-869a-f8bfedd87358/code.power b/src/30c5b4c2-f75f-4d15-869a-f8bfedd87358/code.power new file mode 100644 index 0000000..e3d3764 --- /dev/null +++ b/src/30c5b4c2-f75f-4d15-869a-f8bfedd87358/code.power @@ -0,0 +1,20 @@ + /** + * Making class or function name safe + * + * @input string The name you would like to make safe + * + * @returns string on success + * + * @since 3.0.9 + */ + public static function safe($name): string + { + // remove numbers if the first character is a number + if (is_numeric(substr((string) $name, 0, 1))) + { + $name = StringHelper::numbers($name); + } + + // remove all spaces and strange characters + return trim(preg_replace("/[^A-Za-z0-9_-]/", '', (string) $name)); + } diff --git a/src/30c5b4c2-f75f-4d15-869a-f8bfedd87358/settings.json b/src/30c5b4c2-f75f-4d15-869a-f8bfedd87358/settings.json new file mode 100644 index 0000000..572ee07 --- /dev/null +++ b/src/30c5b4c2-f75f-4d15-869a-f8bfedd87358/settings.json @@ -0,0 +1,23 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "30c5b4c2-f75f-4d15-869a-f8bfedd87358", + "implements": null, + "load_selection": null, + "name": "ClassfunctionHelper", + "power_version": "1.0.0", + "system_name": "String Classfunction Helper", + "type": "abstract class", + "use_selection": { + "use_selection0": { + "use": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Utilities.String.ClassfunctionHelper", + "description": "Control the naming of a class and function\r\n\r\n@since 3.0.9", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 3rd September, 2020\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/3cf76fbf-fd95-4a33-878e-7aff6d36b7f6/README.md b/src/3cf76fbf-fd95-4a33-878e-7aff6d36b7f6/README.md new file mode 100644 index 0000000..624c984 --- /dev/null +++ b/src/3cf76fbf-fd95-4a33-878e-7aff6d36b7f6/README.md @@ -0,0 +1,61 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# abstract class PluginHelper (Details) +> namespace: **VDM\Joomla\Utilities\String** +```uml +@startuml +abstract PluginHelper #Orange { + + {static} safeFolderName(string $codeName, string $group) : string + + {static} safeClassName(string $codeName, string $group) : string + + {static} safeInstallClassName(string $codeName, string $group) : string + + {static} safeLangPrefix(string $codeName, string $group) : string +} + +note right of PluginHelper::safeFolderName + Making plugin folder name safe + + since: 3.0.9 + return: string +end note + +note right of PluginHelper::safeClassName + Making plugin class name safe + + since: 3.0.9 + return: string +end note + +note right of PluginHelper::safeInstallClassName + Making plugin install class name safe + + since: 3.0.9 + return: string +end note + +note right of PluginHelper::safeLangPrefix + Making language prefix safe + + since: 3.0.9 + return: string +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/3cf76fbf-fd95-4a33-878e-7aff6d36b7f6/code.php b/src/3cf76fbf-fd95-4a33-878e-7aff6d36b7f6/code.php new file mode 100644 index 0000000..1b31ffd --- /dev/null +++ b/src/3cf76fbf-fd95-4a33-878e-7aff6d36b7f6/code.php @@ -0,0 +1,115 @@ + + * @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\Utilities\String; + + +/** + * Control the naming of a plugin + * + * @since 3.0.9 + */ +abstract class PluginHelper +{ + /** + * Making plugin folder name safe + * + * @input string $codeName The name + * @input string $group The group name + * + * @returns string on success + * + * @since 3.0.9 + */ + public static function safeFolderName(string $codeName, string $group): string + { + // editors-xtd group plugins must have a class with plgButton structure + if ($group === 'editors-xtd') + { + $group = 'Button'; + } + + return 'plg_' . strtolower($group) . '_' . strtolower( + $codeName + ); + } + + /** + * Making plugin class name safe + * + * @input string $codeName The name + * @input string $group The group name + * + * @returns string on success + * + * @since 3.0.9 + */ + public static function safeClassName(string $codeName, string $group): string + { + // editors-xtd group plugins must have a class with plgButton structure + if ($group === 'editors-xtd') + { + $group = 'Button'; + } + + return 'Plg' . ucfirst($group) . ucfirst( + $codeName + ); + } + + /** + * Making plugin install class name safe + * + * @input string $codeName The name + * @input string $group The group name + * + * @returns string on success + * + * @since 3.0.9 + */ + public static function safeInstallClassName(string $codeName, string $group): string + { + // editors-xtd group plugins must have a class with plgButton structure + if ($group === 'editors-xtd') + { + $group = 'Button'; + } + + return 'plg' . ucfirst($group) . ucfirst( + $codeName + ) . 'InstallerScript'; + } + + /** + * Making language prefix safe + * + * @input string $codeName The name + * @input string $group The group name + * + * @returns string on success + * + * @since 3.0.9 + */ + public static function safeLangPrefix(string $codeName, string $group): string + { + // editors-xtd group plugins must have a class with plgButton structure + if ($group === 'editors-xtd') + { + $group = 'Button'; + } + + return 'PLG_' . strtoupper($group) . '_' . strtoupper( + $codeName + ); + } + +} + diff --git a/src/3cf76fbf-fd95-4a33-878e-7aff6d36b7f6/code.power b/src/3cf76fbf-fd95-4a33-878e-7aff6d36b7f6/code.power new file mode 100644 index 0000000..ec9b01f --- /dev/null +++ b/src/3cf76fbf-fd95-4a33-878e-7aff6d36b7f6/code.power @@ -0,0 +1,91 @@ + /** + * Making plugin folder name safe + * + * @input string $codeName The name + * @input string $group The group name + * + * @returns string on success + * + * @since 3.0.9 + */ + public static function safeFolderName(string $codeName, string $group): string + { + // editors-xtd group plugins must have a class with plgButton structure + if ($group === 'editors-xtd') + { + $group = 'Button'; + } + + return 'plg_' . strtolower($group) . '_' . strtolower( + $codeName + ); + } + + /** + * Making plugin class name safe + * + * @input string $codeName The name + * @input string $group The group name + * + * @returns string on success + * + * @since 3.0.9 + */ + public static function safeClassName(string $codeName, string $group): string + { + // editors-xtd group plugins must have a class with plgButton structure + if ($group === 'editors-xtd') + { + $group = 'Button'; + } + + return 'Plg' . ucfirst($group) . ucfirst( + $codeName + ); + } + + /** + * Making plugin install class name safe + * + * @input string $codeName The name + * @input string $group The group name + * + * @returns string on success + * + * @since 3.0.9 + */ + public static function safeInstallClassName(string $codeName, string $group): string + { + // editors-xtd group plugins must have a class with plgButton structure + if ($group === 'editors-xtd') + { + $group = 'Button'; + } + + return 'plg' . ucfirst($group) . ucfirst( + $codeName + ) . 'InstallerScript'; + } + + /** + * Making language prefix safe + * + * @input string $codeName The name + * @input string $group The group name + * + * @returns string on success + * + * @since 3.0.9 + */ + public static function safeLangPrefix(string $codeName, string $group): string + { + // editors-xtd group plugins must have a class with plgButton structure + if ($group === 'editors-xtd') + { + $group = 'Button'; + } + + return 'PLG_' . strtoupper($group) . '_' . strtoupper( + $codeName + ); + } diff --git a/src/3cf76fbf-fd95-4a33-878e-7aff6d36b7f6/settings.json b/src/3cf76fbf-fd95-4a33-878e-7aff6d36b7f6/settings.json new file mode 100644 index 0000000..c9afb7e --- /dev/null +++ b/src/3cf76fbf-fd95-4a33-878e-7aff6d36b7f6/settings.json @@ -0,0 +1,18 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "3cf76fbf-fd95-4a33-878e-7aff6d36b7f6", + "implements": null, + "load_selection": null, + "name": "PluginHelper", + "power_version": "1.0.0", + "system_name": "String Plugin Helper", + "type": "abstract class", + "use_selection": null, + "namespace": "VDM\\Joomla\\Utilities.String.PluginHelper", + "description": "Control the naming of a plugin\r\n\r\n@since 3.0.9", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 3rd September, 2020\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/44a3367c-f9e4-406b-b396-0f452bde0f03/README.md b/src/44a3367c-f9e4-406b-b396-0f452bde0f03/README.md new file mode 100644 index 0000000..906cd9e --- /dev/null +++ b/src/44a3367c-f9e4-406b-b396-0f452bde0f03/README.md @@ -0,0 +1,160 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# abstract class Mapper (Details) +> namespace: **VDM\Joomla\Componentbuilder\Abstraction** +```uml +@startuml +abstract Mapper #Orange { + + array $active + + isActive() : bool + + set(string $key, mixed $value) : void + + get(string $key) : mixed + + exist(string $key) : bool + + add(string $key, mixed $value) : void + + remove(string $key) : void + # {abstract} key(string $key) : string + + isActive_(string $firstKey = null) : bool + + set_(string $firstKey, string $secondKey, ...) : void + + get_(string $firstKey, ?string $secondKey = null) : mixed + + exist_(string $firstKey, ?string $secondKey = null) : bool + + add_(string $firstKey, string $secondKey, ...) : void + + remove_(string $firstKey, ?string $secondKey = null) : void + # {abstract} firstKey(string $key) : string + # {abstract} secondKey(string $key) : string +} + +note right of Mapper::isActive + Check if any values are set in the active array + + since: 3.2.0 + return: bool +end note + +note left of Mapper::set + Set content + + since: 3.2.0 + return: void +end note + +note right of Mapper::get + Get content + + since: 3.2.0 + return: mixed +end note + +note left of Mapper::exist + Does key exist + + since: 3.2.0 + return: bool +end note + +note right of Mapper::add + Add content + + since: 3.2.0 + return: void +end note + +note left of Mapper::remove + Remove content + + since: 3.2.0 + return: void +end note + +note right of Mapper::key + Model the key + + since: 3.2.0 + return: string +end note + +note left of Mapper::isActive_ + Check if any values are set in the active array. + + since: 3.2.0 + return: bool +end note + +note right of Mapper::set_ + Set dynamic content + + since: 3.2.0 + return: void + + arguments: + string $firstKey + string $secondKey + mixed $value +end note + +note left of Mapper::get_ + Get dynamic content + + since: 3.2.0 + return: mixed +end note + +note right of Mapper::exist_ + Does keys exist + + since: 3.2.0 + return: bool +end note + +note left of Mapper::add_ + Add dynamic content + + since: 3.2.0 + return: void + + arguments: + string $firstKey + string $secondKey + mixed $value +end note + +note right of Mapper::remove_ + Remove dynamic content + + since: 3.2.0 + return: void +end note + +note left of Mapper::firstKey + Model the first key + + since: 3.2.0 + return: string +end note + +note right of Mapper::secondKey + Model the second key + + since: 3.2.0 + return: string +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/44a3367c-f9e4-406b-b396-0f452bde0f03/code.php b/src/44a3367c-f9e4-406b-b396-0f452bde0f03/code.php new file mode 100644 index 0000000..fec5fdc --- /dev/null +++ b/src/44a3367c-f9e4-406b-b396-0f452bde0f03/code.php @@ -0,0 +1,295 @@ + + * @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\Abstraction; + + +use VDM\Joomla\Componentbuilder\Interfaces\Mapperdoubleinterface; +use VDM\Joomla\Componentbuilder\Interfaces\Mappersingleinterface; + + +/** + * Compiler Mapper + * + * @since 3.2.0 + */ +abstract class Mapper implements Mapperdoubleinterface, Mappersingleinterface +{ + + /** + * The Content + * + * @var array + * @since 3.2.0 + **/ + public array $active = []; + + /** + * Check if any values are set in the active array + * + * @return bool Returns true if the active array is not empty, false otherwise + * @since 3.2.0 + */ + public function isActive(): bool + { + return !empty($this->active); + } + + /** + * Set content + * + * @param string $key The main string key + * @param mixed $value The values to set + * + * @return void + * @since 3.2.0 + */ + public function set(string $key, $value) + { + $this->active[$this->key($key)] = $value; + } + + /** + * Get content + * + * @param string $key The main string key + * + * @return mixed + * @since 3.2.0 + */ + public function get(string $key) + { + return $this->active[$this->key($key)] ?? null; + } + + /** + * Does key exist + * + * @param string $key The main string key + * + * @return bool + * @since 3.2.0 + */ + public function exist(string $key): bool + { + if (isset($this->active[$this->key($key)])) + { + return true; + } + return false; + } + + /** + * Add content + * + * @param string $key The main string key + * @param mixed $value The values to set + * + * @return void + * @since 3.2.0 + */ + public function add(string $key, $value) + { + if (isset($this->active[$this->key($key)])) + { + $this->active[$this->key($key)] .= $value; + } + else + { + $this->active[$this->key($key)] = $value; + } + } + + /** + * Remove content + * + * @param string $key The main string key + * + * @return void + * @since 3.2.0 + */ + public function remove(string $key) + { + unset($this->active[$this->key($key)]); + } + + /** + * Model the key + * + * @param string $key The key to model + * + * @return string + * @since 3.2.0 + */ + abstract protected function key(string $key): string; + + /** + * The Dynamic Content + * + * @var array + * @since 3.2.0 + **/ + public array $_active = []; + + /** + * Check if any values are set in the active array. + * + * @param string|null $firstKey Optional. The first key to check for values. + * + * @return bool True if the active array or the specified subarray is not empty, false otherwise. + * @since 3.2.0 + */ + public function isActive_(string $firstKey = null): bool + { + // If a firstKey is provided, check if it has any values. + if (is_string($firstKey)) + { + // Get the first key from the input parameter and check if it exists in the active array. + $firstKey = $this->firstKey($firstKey); + if (isset($this->_active[$firstKey])) + { + return !empty($this->_active[$firstKey]); + } + return false; + } + + // If no firstKey is provided, check if the entire active array has any values. + return !empty($this->_active); + } + + /** + * Set dynamic content + * + * @param string $firstKey The first key + * @param string $secondKey The second key + * @param mixed $value The values to set + * + * @return void + * @since 3.2.0 + */ + public function set_(string $firstKey, string $secondKey, $value) + { + $this->_active[$this->firstKey($firstKey)] + [$this->secondKey($secondKey)] = $value; + } + + /** + * Get dynamic content + * + * @param string $firstKey The first key + * @param string|null $secondKey The second key + * + * @return mixed + * @since 3.2.0 + */ + public function get_(string $firstKey, ?string $secondKey = null) + { + if (is_string($secondKey)) + { + return $this->_active[$this->firstKey($firstKey)] + [$this->secondKey($secondKey)] ?? null; + } + return $this->_active[$this->firstKey($firstKey)] ?? null; + } + + /** + * Does keys exist + * + * @param string $firstKey The first key + * @param string|null $secondKey The second key + * + * @return bool + * @since 3.2.0 + */ + public function exist_(string $firstKey, ?string $secondKey = null): bool + { + if (is_string($secondKey) && isset($this->_active[$this->firstKey($firstKey)]) && + isset($this->_active[$this->firstKey($firstKey)] + [$this->secondKey($secondKey)])) + { + return true; + } + elseif (is_null($secondKey) && isset($this->_active[$this->firstKey($firstKey)])) + { + return true; + } + return false; + } + + /** + * Add dynamic content + * + * @param string $firstKey The first key + * @param string $secondKey The second key + * @param mixed $value The values to set + * + * @return void + * @since 3.2.0 + */ + public function add_(string $firstKey, string $secondKey, $value) + { + if (isset($this->_active[$this->firstKey($firstKey)]) && + isset($this->_active[$this->firstKey($firstKey)] + [$this->secondKey($secondKey)])) + { + $this->_active[$this->firstKey($firstKey)] + [$this->secondKey($secondKey)] .= $value; + } + else + { + $this->_active[$this->firstKey($firstKey)] + [$this->secondKey($secondKey)] = $value; + } + } + + /** + * Remove dynamic content + * + * @param string $firstKey The first key + * @param string|null $secondKey The second key + * + * @return void + * @since 3.2.0 + */ + public function remove_(string $firstKey, ?string $secondKey = null) + { + if (is_string($secondKey)) + { + unset($this->_active[$this->firstKey($firstKey)] + [$this->secondKey($secondKey)]); + } + else + { + unset($this->_active[$this->firstKey($firstKey)]); + } + } + + /** + * Model the first key + * + * @param string $key The first key to model + * + * @return string + * @since 3.2.0 + */ + abstract protected function firstKey(string $key): string; + + /** + * Model the second key + * + * @param string $key The second key to model + * + * @return string + * @since 3.2.0 + */ + abstract protected function secondKey(string $key): string; +} + diff --git a/src/44a3367c-f9e4-406b-b396-0f452bde0f03/code.power b/src/44a3367c-f9e4-406b-b396-0f452bde0f03/code.power new file mode 100644 index 0000000..5c5f647 --- /dev/null +++ b/src/44a3367c-f9e4-406b-b396-0f452bde0f03/code.power @@ -0,0 +1,2 @@ +[CUSTOMCODE=abstractionMapperSingle] +[CUSTOMCODE=abstractionMapperDouble] \ No newline at end of file diff --git a/src/44a3367c-f9e4-406b-b396-0f452bde0f03/settings.json b/src/44a3367c-f9e4-406b-b396-0f452bde0f03/settings.json new file mode 100644 index 0000000..094b04e --- /dev/null +++ b/src/44a3367c-f9e4-406b-b396-0f452bde0f03/settings.json @@ -0,0 +1,21 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "44a3367c-f9e4-406b-b396-0f452bde0f03", + "implements": [ + "fbc58009-fa16-4d49-a0dd-419c3b62d42f", + "78527c29-24ad-4735-ad4c-ec33a4952d9b" + ], + "load_selection": null, + "name": "Mapper", + "power_version": "1.0.0", + "system_name": "JCB.Abstraction.Mapper", + "type": "abstract class", + "use_selection": null, + "namespace": "VDM\\Joomla\\Componentbuilder.Abstraction.Mapper", + "description": "Compiler Mapper\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/4b225c51-d293-48e4-b3f6-5136cf5c3f18/code.power b/src/4b225c51-d293-48e4-b3f6-5136cf5c3f18/code.power new file mode 100644 index 0000000..3053e99 --- /dev/null +++ b/src/4b225c51-d293-48e4-b3f6-5136cf5c3f18/code.power @@ -0,0 +1,77 @@ + /** + * Check if you have a json string + * + * @input string $string The json string to check + * + * @returns bool true on success + * + * @since 3.0.9 + */ + public static function check($string): bool + { + if (StringHelper::check($string)) + { + json_decode((string) $string); + return (json_last_error() === JSON_ERROR_NONE); + } + + return false; + } + + /** + * Convert a json object to a string + * + * @input string $value The json string to convert + * + * @returns a string + * + * @since 3.0.9 + */ + public static function string($value, $separator = ", ", $table = null, $id = 'id', $name = 'name') + { + // do some table foot work + $external = false; + if (is_string($table) && strpos((string) $table, '#__') !== false) + { + $external = true; + $table = str_replace('#__', '', (string) $table); + } + + // check if string is JSON + $result = json_decode((string) $value, true); + if (json_last_error() === JSON_ERROR_NONE) + { + // is JSON + if (ArrayHelper::check($result)) + { + if (StringHelper::check($table)) + { + $names = []; + foreach ($result as $val) + { + if ($external) + { + if ($_name = GetHelper::var(null, $val, $id, $name, '=', $table)) + { + $names[] = $_name; + } + } + else + { + if ($_name = GetHelper::var($table, $val, $id, $name)) + { + $names[] = $_name; + } + } + } + if (ArrayHelper::check($names)) + { + return (string) implode($separator, $names); + } + } + return (string) implode($separator, $result); + } + return (string) json_decode((string) $value); + } + return $value; + } diff --git a/src/4b225c51-d293-48e4-b3f6-5136cf5c3f18/settings.json b/src/4b225c51-d293-48e4-b3f6-5136cf5c3f18/settings.json index 19aed5d..be43cde 100644 --- a/src/4b225c51-d293-48e4-b3f6-5136cf5c3f18/settings.json +++ b/src/4b225c51-d293-48e4-b3f6-5136cf5c3f18/settings.json @@ -1,10 +1,9 @@ { "add_head": "0", + "add_licensing_template": "2", "extends": "0", - "extends_custom": "", "guid": "4b225c51-d293-48e4-b3f6-5136cf5c3f18", "implements": null, - "implements_custom": "", "load_selection": { "load_selection0": { "load": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef" @@ -22,5 +21,8 @@ "type": "abstract class", "use_selection": null, "namespace": "VDM\\Joomla\\Utilities.JsonHelper", - "description": "The json checker\r\n\r\n@since 3.0.9" + "description": "The json checker\r\n\r\n@since 3.0.9", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 3rd September, 2020\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/524eb8f6-38d4-47dc-92ad-98b94e099ac0/README.md b/src/524eb8f6-38d4-47dc-92ad-98b94e099ac0/README.md new file mode 100644 index 0000000..8378f12 --- /dev/null +++ b/src/524eb8f6-38d4-47dc-92ad-98b94e099ac0/README.md @@ -0,0 +1,110 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# final class Insert (Details) +> namespace: **VDM\Joomla\Componentbuilder\Database** +```uml +@startuml +class Insert << (F,LightGreen) >> #Green { + # bool $defaults + + 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 + # getArrayColumns(array $data) : array + # getObjectsColumns(array $data) : array + # insert(array $data, string $table, ...) : bool +} + +note right of Insert::defaults + Switch to prevent/allow defaults from being added. + + since: 3.2.0 + return: void +end note + +note left of Insert::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 Insert::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 left of Insert::row + Insert row to the database + + since: 3.2.0 + return: bool +end note + +note right of Insert::item + Insert item to the database + + since: 3.2.0 + return: bool +end note + +note left of Insert::getArrayColumns + Get columns from data array + + since: 3.2.0 + return: array +end note + +note right of Insert::getObjectsColumns + Get columns from data objects + + since: 3.2.0 + return: array +end note + +note left of Insert::insert + Insert data into the database + + since: 3.2.0 + return: bool + + arguments: + array $data + string $table + array $columns + bool $isArray +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/524eb8f6-38d4-47dc-92ad-98b94e099ac0/code.php b/src/524eb8f6-38d4-47dc-92ad-98b94e099ac0/code.php new file mode 100644 index 0000000..b3c5465 --- /dev/null +++ b/src/524eb8f6-38d4-47dc-92ad-98b94e099ac0/code.php @@ -0,0 +1,291 @@ + + * @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\Database; + + +use Joomla\CMS\Date\Date; +use VDM\Joomla\Utilities\ArrayHelper; +use VDM\Joomla\Componentbuilder\Interfaces\InsertInterface; +use VDM\Joomla\Componentbuilder\Abstraction\Database; + + +/** + * Database Insert Class + * + * @since 3.2.0 + */ +final class Insert extends Database implements InsertInterface +{ + /** + * Switch to set the defaults + * + * @var bool + * @since 1.2.0 + **/ + protected bool $defaults = true; + + /** + * 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) + { + $this->defaults = $trigger; + } + + /** + * 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 + { + if (!ArrayHelper::check($data)) + { + return false; + } + + if ($columns === []) + { + $columns = $this->getArrayColumns($data); + } + + return ($columns === []) ? false : $this->insert($data, $table, $columns, true); + } + + /** + * 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 + { + if (!ArrayHelper::check($data)) + { + return false; + } + + if ($columns === []) + { + $columns = $this->getObjectsColumns($data); + } + + return ($columns === []) ? false : $this->insert($data, $table, $columns, false); + } + + /** + * 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 + { + return $this->rows([$data], $table); + } + + /** + * 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 + { + return $this->items([$data], $table); + } + + /** + * Get columns from data array + * + * @param array $data Data array + * + * @return array + * @since 3.2.0 + **/ + protected function getArrayColumns(array &$data): array + { + $row = array_values($data)[0]; + + if (!ArrayHelper::check($row)) + { + return []; + } + + $columns = array_keys($row); + + return array_combine($columns, $columns); + } + + /** + * Get columns from data objects + * + * @param array $data Data objects + * + * @return array + * @since 3.2.0 + **/ + protected function getObjectsColumns(array &$data): array + { + $row = array_values($data)[0]; + + if (!is_object($row)) + { + return []; + } + + $columns = get_object_vars($row); + + return array_combine(array_keys($columns), array_keys($columns)); + } + + /** + * Insert data into the database + * + * @param array $data Data to store in database + * @param string $table The table where the data is being added + * @param array $columns Data columns for remapping and filtering + * @param bool $isArray Whether the data is an array of arrays or an array of objects + * + * @return bool + * @since 3.2.0 + **/ + protected function insert(array &$data, string $table, array $columns, bool $isArray): bool + { + // get a query object + $query = $this->db->getQuery(true); + + // set the query targets + $query->insert($this->db->quoteName($this->getTable($table)))->columns($this->db->quoteName(array_keys($columns))); + + // set joomla default columns + $add_created = false; + $add_version = false; + $add_published = false; + + // check if we should load the defaults + if ($this->defaults) + { + // get the date + $date = (new Date())->toSql(); + + if (!isset($columns['created'])) + { + $columns['created'] = '_|-v-|_'; + $add_created = true; + } + + if (!isset($columns['version'])) + { + $columns['version'] = '_|-v-|_'; + $add_version = true; + } + + if (!isset($columns['version'])) + { + $columns['published'] = '_|-v-|_'; + $add_published = true; + } + // the _|-v-|_ prevents an empty value from being loaded + } + + // limiting factor on the amount of rows to insert before we reset the query + $limit = 300; + + // set the insert values + foreach ($data as $nr => $value) + { + // check the limit + if ($limit <= 1) + { + // execute and reset the query + $this->db->setQuery($query); + $this->db->execute(); + + // reset limit + $limit = 300; + + // get a query object + $query = $this->db->getQuery(true); + + // set the query targets + $query->insert($this->db->quoteName($this->getTable($table)))->columns($this->db->quoteName(array_keys($columns))); + } + + $row = []; + foreach ($columns as $column => $key) + { + if ('_|-v-|_' !== $key) + { + $row[] = ($isArray && isset($value[$key])) ? $this->quote($value[$key]) + : ((!$isArray && isset($value->{$key})) ? $this->quote($value->{$key}) : ''); + } + } + + // set joomla default columns + if ($add_created) + { + $row[] = $this->db->quote($date); + } + + if ($add_version) + { + $row[] = 1; + } + + if ($add_published) + { + $row[] = 1; + } + + // add to query + $query->values(implode(',', $row)); + + // decrement the limiter + $limit--; + + // clear the data from memory + unset($data[$nr]); + } + + // execute the final query + $this->db->setQuery($query); + $this->db->execute(); + + // always reset the default switch + $this->defaults(); + + return true; + } + +} + diff --git a/src/524eb8f6-38d4-47dc-92ad-98b94e099ac0/code.power b/src/524eb8f6-38d4-47dc-92ad-98b94e099ac0/code.power new file mode 100644 index 0000000..7ad3def --- /dev/null +++ b/src/524eb8f6-38d4-47dc-92ad-98b94e099ac0/code.power @@ -0,0 +1,261 @@ + /** + * Switch to set the defaults + * + * @var bool + * @since 1.2.0 + **/ + protected bool $defaults = true; + + /** + * 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) + { + $this->defaults = $trigger; + } + + /** + * 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 + { + if (!ArrayHelper::check($data)) + { + return false; + } + + if ($columns === []) + { + $columns = $this->getArrayColumns($data); + } + + return ($columns === []) ? false : $this->insert($data, $table, $columns, true); + } + + /** + * 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 + { + if (!ArrayHelper::check($data)) + { + return false; + } + + if ($columns === []) + { + $columns = $this->getObjectsColumns($data); + } + + return ($columns === []) ? false : $this->insert($data, $table, $columns, false); + } + + /** + * 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 + { + return $this->rows([$data], $table); + } + + /** + * 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 + { + return $this->items([$data], $table); + } + + /** + * Get columns from data array + * + * @param array $data Data array + * + * @return array + * @since 3.2.0 + **/ + protected function getArrayColumns(array &$data): array + { + $row = array_values($data)[0]; + + if (!ArrayHelper::check($row)) + { + return []; + } + + $columns = array_keys($row); + + return array_combine($columns, $columns); + } + + /** + * Get columns from data objects + * + * @param array $data Data objects + * + * @return array + * @since 3.2.0 + **/ + protected function getObjectsColumns(array &$data): array + { + $row = array_values($data)[0]; + + if (!is_object($row)) + { + return []; + } + + $columns = get_object_vars($row); + + return array_combine(array_keys($columns), array_keys($columns)); + } + + /** + * Insert data into the database + * + * @param array $data Data to store in database + * @param string $table The table where the data is being added + * @param array $columns Data columns for remapping and filtering + * @param bool $isArray Whether the data is an array of arrays or an array of objects + * + * @return bool + * @since 3.2.0 + **/ + protected function insert(array &$data, string $table, array $columns, bool $isArray): bool + { + // get a query object + $query = $this->db->getQuery(true); + + // set the query targets + $query->insert($this->db->quoteName($this->getTable($table)))->columns($this->db->quoteName(array_keys($columns))); + + // set joomla default columns + $add_created = false; + $add_version = false; + $add_published = false; + + // check if we should load the defaults + if ($this->defaults) + { + // get the date + $date = (new Date())->toSql(); + + if (!isset($columns['created'])) + { + $columns['created'] = '_|-v-|_'; + $add_created = true; + } + + if (!isset($columns['version'])) + { + $columns['version'] = '_|-v-|_'; + $add_version = true; + } + + if (!isset($columns['version'])) + { + $columns['published'] = '_|-v-|_'; + $add_published = true; + } + // the _|-v-|_ prevents an empty value from being loaded + } + + // limiting factor on the amount of rows to insert before we reset the query + $limit = 300; + + // set the insert values + foreach ($data as $nr => $value) + { + // check the limit + if ($limit <= 1) + { + // execute and reset the query + $this->db->setQuery($query); + $this->db->execute(); + + // reset limit + $limit = 300; + + // get a query object + $query = $this->db->getQuery(true); + + // set the query targets + $query->insert($this->db->quoteName($this->getTable($table)))->columns($this->db->quoteName(array_keys($columns))); + } + + $row = []; + foreach ($columns as $column => $key) + { + if ('_|-v-|_' !== $key) + { + $row[] = ($isArray && isset($value[$key])) ? $this->quote($value[$key]) + : ((!$isArray && isset($value->{$key})) ? $this->quote($value->{$key}) : ''); + } + } + + // set joomla default columns + if ($add_created) + { + $row[] = $this->db->quote($date); + } + + if ($add_version) + { + $row[] = 1; + } + + if ($add_published) + { + $row[] = 1; + } + + // add to query + $query->values(implode(',', $row)); + + // decrement the limiter + $limit--; + + // clear the data from memory + unset($data[$nr]); + } + + // execute the final query + $this->db->setQuery($query); + $this->db->execute(); + + // always reset the default switch + $this->defaults(); + + return true; + } diff --git a/src/524eb8f6-38d4-47dc-92ad-98b94e099ac0/settings.json b/src/524eb8f6-38d4-47dc-92ad-98b94e099ac0/settings.json new file mode 100644 index 0000000..141d479 --- /dev/null +++ b/src/524eb8f6-38d4-47dc-92ad-98b94e099ac0/settings.json @@ -0,0 +1,25 @@ +{ + "add_head": "1", + "add_licensing_template": "2", + "extends": "6cbef8f8-4813-48e3-b05a-65e1aea95171", + "guid": "524eb8f6-38d4-47dc-92ad-98b94e099ac0", + "implements": [ + "ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48" + ], + "load_selection": null, + "name": "Insert", + "power_version": "1.0.0", + "system_name": "JCB.Database.Insert", + "type": "final class", + "use_selection": { + "use_selection0": { + "use": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Database.Insert", + "description": "Database Insert Class\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": "use Joomla\\CMS\\Date\\Date;", + "composer": "" +} \ No newline at end of file diff --git a/src/584747d1-3a86-453d-b7a3-a2219de8d777/README.md b/src/584747d1-3a86-453d-b7a3-a2219de8d777/README.md new file mode 100644 index 0000000..9abf656 --- /dev/null +++ b/src/584747d1-3a86-453d-b7a3-a2219de8d777/README.md @@ -0,0 +1,139 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# abstract class Model (Details) +> namespace: **VDM\Joomla\Componentbuilder\Abstraction** +```uml +@startuml +abstract Model #Orange { + # array $last + # Table $table + + __construct(Table $table) + + {abstract} value(mixed $value, string $field, ...) : mixed + + item(object $item, ?string $table = null) : ?object + + items(?array $items = null, ?string $table = null) : ?array + + row(array $item, ?string $table = null) : ?array + + rows(?array $items = null, ?string $table = null) : ?array + + last(?string $table = null) : ?int + # getTableFields(string $table, bool $default = false) : ?array + # {abstract} validateBefore(mixed $value, ?string $field = null, ...) : bool + # {abstract} validateAfter(mixed $value, ?string $field = null, ...) : bool + # {abstract} getTable() : string +} + +note right of Model::__construct + Constructor + + since: 3.2.0 +end note + +note left of Model::value + Model the value +Example: $this->value(value, 'value_key', 'table_name'); + + since: 3.2.0 + return: mixed + + arguments: + mixed $value + string $field + ?string $table = null +end note + +note right of Model::item + Model the values of an item +Example: $this->item(Object, 'table_name'); + + since: 3.2.0 + return: ?object +end note + +note left of Model::items + Model the values of multiple items +Example: $this->items(Array, 'table_name'); + + since: 3.2.0 + return: ?array +end note + +note right of Model::row + Model the values of an row +Example: $this->item(Array, 'table_name'); + + since: 3.2.0 + return: ?array +end note + +note left of Model::rows + Model the values of multiple rows +Example: $this->items(Array, 'table_name'); + + since: 3.2.0 + return: ?array +end note + +note right of Model::last + Get last modeled ID +Example: $this->last('table_name'); + + since: 3.2.0 + return: ?int +end note + +note left of Model::getTableFields + Get the current active table's fields (including defaults) + + since: 3.2.0 + return: ?array +end note + +note right of Model::validateBefore + Validate before the value is modelled (basic, override in child class) + + since: 3.2.0 + return: bool + + arguments: + mixed $value + ?string $field = null + ?string $table = null +end note + +note left of Model::validateAfter + Validate after the value is modelled (basic, override in child class) + + since: 3.2.0 + return: bool + + arguments: + mixed $value + ?string $field = null + ?string $table = null +end note + +note right of Model::getTable + Get the current active table + + since: 3.2.0 + return: string +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/584747d1-3a86-453d-b7a3-a2219de8d777/code.php b/src/584747d1-3a86-453d-b7a3-a2219de8d777/code.php new file mode 100644 index 0000000..82636ba --- /dev/null +++ b/src/584747d1-3a86-453d-b7a3-a2219de8d777/code.php @@ -0,0 +1,347 @@ + + * @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\Abstraction; + + +use VDM\Joomla\Utilities\StringHelper; +use VDM\Joomla\Utilities\ArrayHelper; +use VDM\Joomla\Componentbuilder\Table; + + +/** + * Our base Model + * + * @since 3.2.0 + */ +abstract class Model +{ + /** + * Last ID + * + * @var array + * @since 3.2.0 + */ + protected array $last; + + /** + * Search Table + * + * @var Table + * @since 3.2.0 + */ + protected Table $table; + + /** + * Constructor + * + * @param Table $table The search table object. + * + * @since 3.2.0 + */ + public function __construct(Table $table) + { + $this->table = $table; + } + + /** + * Model the value + * Example: $this->value(value, 'value_key', 'table_name'); + * + * @param mixed $value The value to model + * @param string $field The field key + * @param string|null $table The table + * + * @return mixed + * @since 3.2.0 + */ + abstract public function value($value, string $field, ?string $table = null); + + /** + * Model the values of an item + * Example: $this->item(Object, 'table_name'); + * + * @param object $item The item object + * @param string|null $table The table + * + * @return object|null + * @since 3.2.0 + */ + public function item(object $item, ?string $table = null): ?object + { + // set the table name + if (empty($table)) + { + $table = $this->getTable(); + } + + if (($fields = $this->getTableFields($table, true)) !== null) + { + // field counter + $field_number = 0; + + // check if this is a valid table + $item_bucket = new \stdClass(); + + foreach ($fields as $field) + { + // model a value if it exists + if(isset($item->{$field})) + { + if (!$this->validateBefore($item->{$field}, $field, $table)) + { + continue; + } + + $item->{$field} = $this->value($item->{$field}, $field, $table); + + if (!$this->validateAfter($item->{$field}, $field, $table)) + { + continue; + } + + $item_bucket->{$field} = $item->{$field}; + + $field_number++; + } + } + + // all items must have more than one field or its empty (1 = id or guid) + if ($field_number > 1) + { + return $item_bucket; + } + } + + return null; + } + + /** + * Model the values of multiple items + * Example: $this->items(Array, 'table_name'); + * + * @param array|null $items The array of item objects + * @param string|null $table The table + * + * @return array|null + * @since 3.2.0 + */ + public function items(?array $items = null, ?string $table = null): ?array + { + // check if this is a valid table + if (ArrayHelper::check($items)) + { + // set the table name + if (empty($table)) + { + $table = $this->getTable(); + } + + foreach ($items as $id => &$item) + { + // model the item + if (($item = $this->item($item, $table)) !== null) + { + // add the last ID + $this->last[$table] = $item->id ?? $this->last[$table] ?? null; + } + else + { + unset($items[$id]); + } + } + + if (ArrayHelper::check($items)) + { + return $items; + } + } + + return null; + } + + /** + * Model the values of an row + * Example: $this->item(Array, 'table_name'); + * + * @param array $item The item array + * @param string|null $table The table + * + * @return array|null + * @since 3.2.0 + */ + public function row(array $item, ?string $table = null): ?array + { + // set the table name + if (empty($table)) + { + $table = $this->getTable(); + } + + if (($fields = $this->getTableFields($table, true)) !== null) + { + // field counter + $field_number = 0; + + // check if this is a valid table + $item_bucket = []; + + foreach ($fields as $field) + { + // model a value if it exists + if(isset($item[$field])) + { + if (!$this->validateBefore($item[$field], $field, $table)) + { + continue; + } + + $item[$field] = $this->value($item[$field], $field, $table); + + if (!$this->validateAfter($item[$field], $field, $table)) + { + continue; + } + + $item_bucket[$field] = $item[$field]; + + $field_number++; + } + } + + // all items must have more than one field or its empty (1 = id or guid) + if ($field_number > 1) + { + return $item_bucket; + } + } + + return null; + } + + /** + * Model the values of multiple rows + * Example: $this->items(Array, 'table_name'); + * + * @param array|null $items The array of item array + * @param string|null $table The table + * + * @return array|null + * @since 3.2.0 + */ + public function rows(?array $items = null, ?string $table = null): ?array + { + // check if this is a valid table + if (ArrayHelper::check($items)) + { + // set the table name + if (empty($table)) + { + $table = $this->getTable(); + } + + foreach ($items as $id => &$item) + { + // model the item + if (($item = $this->row($item, $table)) !== null) + { + // add the last ID + $this->last[$table] = $item['id'] ?? $this->last[$table] ?? null; + } + else + { + unset($items[$id]); + } + } + + if (ArrayHelper::check($items)) + { + return $items; + } + } + + return null; + } + + /** + * Get last modeled ID + * Example: $this->last('table_name'); + * + * @param string|null $table The table + * + * @return int|null + * @since 3.2.0 + */ + public function last(?string $table = null): ?int + { + // set the table name + if (empty($table)) + { + $table = $this->getTable(); + } + + // check if this is a valid table + if ($table && isset($this->last[$table])) + { + return $this->last[$table]; + } + + return null; + } + + /** + * Get the current active table's fields (including defaults) + * + * @param string $table The area + * @param bool $default Add the default fields + * + * @return array + * @since 3.2.0 + */ + protected function getTableFields(string $table, bool $default = false): ?array + { + return $this->table->fields($table, $default); + } + + /** + * Validate before the value is modelled (basic, override in child class) + * + * @param mixed $value The field value + * @param string|null $field The field key + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + abstract protected function validateBefore(&$value, ?string $field = null, ?string $table = null): bool; + + /** + * Validate after the value is modelled (basic, override in child class) + * + * @param mixed $value The field value + * @param string|null $field The field key + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + abstract protected function validateAfter(&$value, ?string $field = null, ?string $table = null): bool; + + /** + * Get the current active table + * + * @return string + * @since 3.2.0 + */ + abstract protected function getTable(): string; + +} + diff --git a/src/584747d1-3a86-453d-b7a3-a2219de8d777/code.power b/src/584747d1-3a86-453d-b7a3-a2219de8d777/code.power new file mode 100644 index 0000000..8f93d7b --- /dev/null +++ b/src/584747d1-3a86-453d-b7a3-a2219de8d777/code.power @@ -0,0 +1,318 @@ + /** + * Last ID + * + * @var array + * @since 3.2.0 + */ + protected array $last; + + /** + * Search Table + * + * @var Table + * @since 3.2.0 + */ + protected Table $table; + + /** + * Constructor + * + * @param Table $table The search table object. + * + * @since 3.2.0 + */ + public function __construct(Table $table) + { + $this->table = $table; + } + + /** + * Model the value + * Example: $this->value(value, 'value_key', 'table_name'); + * + * @param mixed $value The value to model + * @param string $field The field key + * @param string|null $table The table + * + * @return mixed + * @since 3.2.0 + */ + abstract public function value($value, string $field, ?string $table = null); + + /** + * Model the values of an item + * Example: $this->item(Object, 'table_name'); + * + * @param object $item The item object + * @param string|null $table The table + * + * @return object|null + * @since 3.2.0 + */ + public function item(object $item, ?string $table = null): ?object + { + // set the table name + if (empty($table)) + { + $table = $this->getTable(); + } + + if (($fields = $this->getTableFields($table, true)) !== null) + { + // field counter + $field_number = 0; + + // check if this is a valid table + $item_bucket = new \stdClass(); + + foreach ($fields as $field) + { + // model a value if it exists + if(isset($item->{$field})) + { + if (!$this->validateBefore($item->{$field}, $field, $table)) + { + continue; + } + + $item->{$field} = $this->value($item->{$field}, $field, $table); + + if (!$this->validateAfter($item->{$field}, $field, $table)) + { + continue; + } + + $item_bucket->{$field} = $item->{$field}; + + $field_number++; + } + } + + // all items must have more than one field or its empty (1 = id or guid) + if ($field_number > 1) + { + return $item_bucket; + } + } + + return null; + } + + /** + * Model the values of multiple items + * Example: $this->items(Array, 'table_name'); + * + * @param array|null $items The array of item objects + * @param string|null $table The table + * + * @return array|null + * @since 3.2.0 + */ + public function items(?array $items = null, ?string $table = null): ?array + { + // check if this is a valid table + if (ArrayHelper::check($items)) + { + // set the table name + if (empty($table)) + { + $table = $this->getTable(); + } + + foreach ($items as $id => &$item) + { + // model the item + if (($item = $this->item($item, $table)) !== null) + { + // add the last ID + $this->last[$table] = $item->id ?? $this->last[$table] ?? null; + } + else + { + unset($items[$id]); + } + } + + if (ArrayHelper::check($items)) + { + return $items; + } + } + + return null; + } + + /** + * Model the values of an row + * Example: $this->item(Array, 'table_name'); + * + * @param array $item The item array + * @param string|null $table The table + * + * @return array|null + * @since 3.2.0 + */ + public function row(array $item, ?string $table = null): ?array + { + // set the table name + if (empty($table)) + { + $table = $this->getTable(); + } + + if (($fields = $this->getTableFields($table, true)) !== null) + { + // field counter + $field_number = 0; + + // check if this is a valid table + $item_bucket = []; + + foreach ($fields as $field) + { + // model a value if it exists + if(isset($item[$field])) + { + if (!$this->validateBefore($item[$field], $field, $table)) + { + continue; + } + + $item[$field] = $this->value($item[$field], $field, $table); + + if (!$this->validateAfter($item[$field], $field, $table)) + { + continue; + } + + $item_bucket[$field] = $item[$field]; + + $field_number++; + } + } + + // all items must have more than one field or its empty (1 = id or guid) + if ($field_number > 1) + { + return $item_bucket; + } + } + + return null; + } + + /** + * Model the values of multiple rows + * Example: $this->items(Array, 'table_name'); + * + * @param array|null $items The array of item array + * @param string|null $table The table + * + * @return array|null + * @since 3.2.0 + */ + public function rows(?array $items = null, ?string $table = null): ?array + { + // check if this is a valid table + if (ArrayHelper::check($items)) + { + // set the table name + if (empty($table)) + { + $table = $this->getTable(); + } + + foreach ($items as $id => &$item) + { + // model the item + if (($item = $this->row($item, $table)) !== null) + { + // add the last ID + $this->last[$table] = $item['id'] ?? $this->last[$table] ?? null; + } + else + { + unset($items[$id]); + } + } + + if (ArrayHelper::check($items)) + { + return $items; + } + } + + return null; + } + + /** + * Get last modeled ID + * Example: $this->last('table_name'); + * + * @param string|null $table The table + * + * @return int|null + * @since 3.2.0 + */ + public function last(?string $table = null): ?int + { + // set the table name + if (empty($table)) + { + $table = $this->getTable(); + } + + // check if this is a valid table + if ($table && isset($this->last[$table])) + { + return $this->last[$table]; + } + + return null; + } + + /** + * Get the current active table's fields (including defaults) + * + * @param string $table The area + * @param bool $default Add the default fields + * + * @return array + * @since 3.2.0 + */ + protected function getTableFields(string $table, bool $default = false): ?array + { + return $this->table->fields($table, $default); + } + + /** + * Validate before the value is modelled (basic, override in child class) + * + * @param mixed $value The field value + * @param string|null $field The field key + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + abstract protected function validateBefore(&$value, ?string $field = null, ?string $table = null): bool; + + /** + * Validate after the value is modelled (basic, override in child class) + * + * @param mixed $value The field value + * @param string|null $field The field key + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + abstract protected function validateAfter(&$value, ?string $field = null, ?string $table = null): bool; + + /** + * Get the current active table + * + * @return string + * @since 3.2.0 + */ + abstract protected function getTable(): string; diff --git a/src/584747d1-3a86-453d-b7a3-a2219de8d777/settings.json b/src/584747d1-3a86-453d-b7a3-a2219de8d777/settings.json new file mode 100644 index 0000000..c663d50 --- /dev/null +++ b/src/584747d1-3a86-453d-b7a3-a2219de8d777/settings.json @@ -0,0 +1,31 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "584747d1-3a86-453d-b7a3-a2219de8d777", + "implements": null, + "load_selection": null, + "name": "Model", + "power_version": "1.0.0", + "system_name": "JCB.Abstraction.Model", + "type": "abstract class", + "use_selection": { + "use_selection0": { + "use": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef", + "as": "default" + }, + "use_selection1": { + "use": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a", + "as": "default" + }, + "use_selection2": { + "use": "bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Abstraction.Model", + "description": "Our base Model\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/640b5352-fb09-425f-a26e-cd44eda03f15/code.power b/src/640b5352-fb09-425f-a26e-cd44eda03f15/code.power new file mode 100644 index 0000000..bddd190 --- /dev/null +++ b/src/640b5352-fb09-425f-a26e-cd44eda03f15/code.power @@ -0,0 +1,160 @@ + /** + * The current option + * + * @var string + * @since 3.0.11 + */ + public static string $option; + + /** + * The component params list cache + * + * @var Registry[] + * @since 3.0.11 + */ + protected static array $params = []; + + /** + * Gets the parameter object for the component + * + * @param string|null $option The option for the component. + * + * @return Registry A Registry object. + * @see Registry + * @since 3.0.11 + */ + public static function getParams(?string $option = null): Registry + { + // check that we have an option + if (empty($option)) + { + $option = self::getOption(); + } + + // get global value + if (!isset(self::$params[$option]) || !self::$params[$option] instanceof Registry) + { + self::$params[$option] = ComponentHelper::getParams($option); + } + + return self::$params[$option]; + } + + /** + * Gets the component option + * + * @param string|null $default The default return value if none is found + * + * @return string|null A component option + * @since 3.0.11 + */ + public static function getOption(string $default = 'empty'): ?string + { + if (empty(self::$option)) + { + // get the option from the url input + self::$option = (new Input)->getString('option', false); + } + + if (self::$option) + { + return self::$option; + } + + return $default; + } + + /** + * Gets the component code name + * + * @param string|null $option The option for the component. + * @param string|null $default The default return value if none is found + * + * @return string|null A component code name + * @since 3.0.11 + */ + public static function getCode(?string $option = null, ?string $default = null): ?string + { + // check that we have an option + if (empty($option)) + { + $option = self::getOption(); + } + // option with com_ + if (is_string($option) && strpos($option, 'com_') === 0) + { + return strtolower(trim(substr($option, 4))); + } + + return $default; + } + + /** + * Gets the component abstract helper class + * + * @param string|null $option The option for the component. + * @param string|null $default The default return value if none is found + * + * @return string|null A component helper name + * + * @since 3.0.11 + */ + public static function get(string $option = null, string $default = null): ?string + { + // check that we have an option + // and get the code name from it + if (($code_name = self::getCode($option, false)) !== false) + { + // we build the helper class name + $helper_name = '\\' . \ucfirst($code_name) . 'Helper'; + // check if class exist + if (class_exists($helper_name)) + { + return $helper_name; + } + } + + return $default; + } + + /** + * Check if the helper class of this component has a method + * + * @param string $method The method name to search for + * @param string|null $option The option for the component. + * + * @return bool true if method exist + * + * @since 3.0.11 + */ + public static function methodExists(string $method, string $option = null): bool + { + // get the helper class + return ($helper = self::get($option, false)) !== false && + method_exists($helper, $method); + } + + /** + * Check if the helper class of this component has a method, and call it with the arguments + * + * @param string $method The method name to search for + * @param array $arguments The arguments for function. + * @param string|null $option The option for the component. + * + * @return mixed return whatever the method returns or null + * @since 3.2.0 + */ + public static function _(string $method, array $arguments = [], ?string $option = null) + { + // get the helper class + if (($helper = self::get($option, false)) !== false && + method_exists($helper, $method)) + { + // we know this is not ideal... + // so we need to move these + // functions to their own classes + return call_user_func_array([$helper, $method], $arguments); + } + + return null; + } diff --git a/src/640b5352-fb09-425f-a26e-cd44eda03f15/settings.json b/src/640b5352-fb09-425f-a26e-cd44eda03f15/settings.json index 27667cc..dd4a05b 100644 --- a/src/640b5352-fb09-425f-a26e-cd44eda03f15/settings.json +++ b/src/640b5352-fb09-425f-a26e-cd44eda03f15/settings.json @@ -1,10 +1,9 @@ { "add_head": "1", + "add_licensing_template": "2", "extends": "0", - "extends_custom": "", "guid": "640b5352-fb09-425f-a26e-cd44eda03f15", "implements": null, - "implements_custom": "", "load_selection": null, "name": "Helper", "power_version": "1.0.0", @@ -13,5 +12,7 @@ "use_selection": null, "namespace": "VDM\\Joomla\\Utilities.Component.Helper", "description": "Some component helper\r\n\r\n@since 3.0.11", - "head": "use Joomla\\Input\\Input;\r\nuse Joomla\\CMS\\Component\\ComponentHelper;\r\nuse Joomla\\Registry\\Registry;" + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 3rd September, 2020\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": "use Joomla\\Input\\Input;\r\nuse Joomla\\CMS\\Component\\ComponentHelper;\r\nuse Joomla\\Registry\\Registry;", + "composer": "" } \ No newline at end of file diff --git a/src/6cbef8f8-4813-48e3-b05a-65e1aea95171/README.md b/src/6cbef8f8-4813-48e3-b05a-65e1aea95171/README.md new file mode 100644 index 0000000..a4b3504 --- /dev/null +++ b/src/6cbef8f8-4813-48e3-b05a-65e1aea95171/README.md @@ -0,0 +1,55 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# abstract class Database (Details) +> namespace: **VDM\Joomla\Componentbuilder\Abstraction** +```uml +@startuml +abstract Database #Orange { + # \JDatabaseDriver $db + # string $table + + __construct(?\JDatabaseDriver $db = null) + # quote(mixed $value) : mixed + # getTable(string $table) : string +} + +note right of Database::__construct + Constructor + + since: 3.2.0 +end note + +note right of Database::quote + Set a value based on data type + + since: 3.2.0 + return: mixed +end note + +note right of Database::getTable + Set a table name, adding the +core component as needed + + since: 3.2.0 + return: string +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/6cbef8f8-4813-48e3-b05a-65e1aea95171/code.php b/src/6cbef8f8-4813-48e3-b05a-65e1aea95171/code.php new file mode 100644 index 0000000..5e14535 --- /dev/null +++ b/src/6cbef8f8-4813-48e3-b05a-65e1aea95171/code.php @@ -0,0 +1,108 @@ + + * @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\Abstraction; + + +use Joomla\CMS\Factory as JoomlaFactory; +use VDM\Joomla\Utilities\Component\Helper; + + +/** + * Database + * + * @since 3.2.0 + */ +abstract class Database +{ + /** + * Database object to query local DB + * + * @var \JDatabaseDriver + * @since 3.2.0 + */ + protected \JDatabaseDriver $db; + + /** + * Core Component Table Name + * + * @var string + * @since 3.2.0 + */ + protected string $table; + + /** + * Constructor + * + * @param \JDatabaseDriver|null $db The database driver + * + * @throws \Exception + * @since 3.2.0 + */ + public function __construct(?\JDatabaseDriver $db = null) + { + $this->db = $db ?: JoomlaFactory::getDbo(); + + // set the component table + $this->table = '#__' . Helper::getCode(); + } + + /** + * Set a value based on data type + * + * @param mixed $value The value to set + * + * @return mixed + * @since 3.2.0 + **/ + protected function quote($value) + { + if (is_numeric($value)) + { + if (filter_var($value, FILTER_VALIDATE_INT)) + { + return (int) $value; + } + elseif (filter_var($value, FILTER_VALIDATE_FLOAT)) + { + return (float) $value; + } + } + elseif (is_bool($value)) + { + return (int) $value; + } + + // default just escape it + return $this->db->quote($value); + } + + /** + * Set a table name, adding the + * core component as needed + * + * @param string $table The table string + * + * @return string + * @since 3.2.0 + **/ + protected function getTable(string $table): string + { + if (strpos($table, '#__') === false) + { + return $this->table . '_' . $table; + } + + return $table; + } + +} + diff --git a/src/6cbef8f8-4813-48e3-b05a-65e1aea95171/code.power b/src/6cbef8f8-4813-48e3-b05a-65e1aea95171/code.power new file mode 100644 index 0000000..f980661 --- /dev/null +++ b/src/6cbef8f8-4813-48e3-b05a-65e1aea95171/code.power @@ -0,0 +1,80 @@ + /** + * Database object to query local DB + * + * @var \JDatabaseDriver + * @since 3.2.0 + */ + protected \JDatabaseDriver $db; + + /** + * Core Component Table Name + * + * @var string + * @since 3.2.0 + */ + protected string $table; + + /** + * Constructor + * + * @param \JDatabaseDriver|null $db The database driver + * + * @throws \Exception + * @since 3.2.0 + */ + public function __construct(?\JDatabaseDriver $db = null) + { + $this->db = $db ?: JoomlaFactory::getDbo(); + + // set the component table + $this->table = '#__' . Helper::getCode(); + } + + /** + * Set a value based on data type + * + * @param mixed $value The value to set + * + * @return mixed + * @since 3.2.0 + **/ + protected function quote($value) + { + if (is_numeric($value)) + { + if (filter_var($value, FILTER_VALIDATE_INT)) + { + return (int) $value; + } + elseif (filter_var($value, FILTER_VALIDATE_FLOAT)) + { + return (float) $value; + } + } + elseif (is_bool($value)) + { + return (int) $value; + } + + // default just escape it + return $this->db->quote($value); + } + + /** + * Set a table name, adding the + * core component as needed + * + * @param string $table The table string + * + * @return string + * @since 3.2.0 + **/ + protected function getTable(string $table): string + { + if (strpos($table, '#__') === false) + { + return $this->table . '_' . $table; + } + + return $table; + } diff --git a/src/6cbef8f8-4813-48e3-b05a-65e1aea95171/settings.json b/src/6cbef8f8-4813-48e3-b05a-65e1aea95171/settings.json new file mode 100644 index 0000000..af3eb44 --- /dev/null +++ b/src/6cbef8f8-4813-48e3-b05a-65e1aea95171/settings.json @@ -0,0 +1,23 @@ +{ + "add_head": "1", + "add_licensing_template": "2", + "extends": "0", + "guid": "6cbef8f8-4813-48e3-b05a-65e1aea95171", + "implements": null, + "load_selection": null, + "name": "Database", + "power_version": "1.0.0", + "system_name": "JCB.Abstraction.Database", + "type": "abstract class", + "use_selection": { + "use_selection0": { + "use": "640b5352-fb09-425f-a26e-cd44eda03f15", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Abstraction.Database", + "description": "Database\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": "use Joomla\\CMS\\Factory as JoomlaFactory;", + "composer": "" +} \ No newline at end of file diff --git a/src/79d765b3-7319-4988-9730-446c7f347020/code.power b/src/79d765b3-7319-4988-9730-446c7f347020/code.power new file mode 100644 index 0000000..7e3623b --- /dev/null +++ b/src/79d765b3-7319-4988-9730-446c7f347020/code.power @@ -0,0 +1,629 @@ + /** + * The Main Active Language + * + * @var string + * + * @since 3.0.9 + */ + public static $langTag; + + /** + * Check if have a string with a length + * + * @input string $string The string to check + * + * @returns bool true on success + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use StringHelper::check($string); + */ + public static function checkString($string): bool + { + return StringHelper::check($string); + } + + /** + * Shorten a string + * + * @input string $string That you would like to shorten + * + * @returns string on success + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use StringHelper::shorten($string, $length, $addTip); + */ + public static function shorten($string, $length = 40, $addTip = true) + { + return StringHelper::shorten($string, $length, $addTip); + } + + /** + * Making strings safe (various ways) + * + * @input string $string That you would like to make safe + * + * @returns string on success + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use StringHelper::safe($string, $type, $spacer, $replaceNumbers, $keepOnlyCharacters); + */ + public static function safeString($string, $type = 'L', $spacer = '_', $replaceNumbers = true, $keepOnlyCharacters = true) + { + // set the local component option + self::setComponentOption(); + + return StringHelper::safe($string, $type, $spacer, $replaceNumbers, $keepOnlyCharacters); + } + + /** + * Making class or function name safe + * + * @input string The name you would like to make safe + * + * @returns string on success + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use ClassfunctionHelper::safe($name); + */ + public static function safeClassFunctionName($name) + { + return ClassfunctionHelper::safe($name); + } + + /** + * Making field names safe + * + * @input string The you would like to make safe + * @input boolean The switch to return an ALL UPPER CASE string + * @input string The string to use in white space + * + * @returns string on success + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use FieldHelper::safe($string, $allcap, $spacer); + */ + public static function safeFieldName($string, $allcap = false, $spacer = '_') + { + // set the local component option + self::setComponentOption(); + + return FieldHelper::safe($string, $allcap, $spacer); + } + + /** + * Making field type name safe + * + * @input string The you would like to make safe + * + * @returns string on success + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use TypeHelper::safe($string); + */ + public static function safeTypeName($string) + { + // set the local component option + self::setComponentOption(); + + return TypeHelper::safe($string); + } + + /** + * Making namespace safe + * + * @input string The you would like to make safe + * + * @returns string on success + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use NamespaceHelper::safe($string); + */ + public static function safeNamespace($string) + { + return NamespaceHelper::safe($string); + } + + /** + * @since 3.0.9 + * + * @deprecated 4.0 - Use StringHelper::transliterate($string); + */ + public static function transliterate($string) + { + // set the local component option + self::setComponentOption(); + + return StringHelper::transliterate($string); + } + + /** + * @since 3.0.9 + * + * @deprecated 4.0 - Use StringHelper::html($var, $charset, $shorten, $length); + */ + public static function htmlEscape($var, $charset = 'UTF-8', $shorten = false, $length = 40) + { + // set the local component option + self::setComponentOption(); + + return StringHelper::html($var, $charset, $shorten, $length); + } + + /** + * @since 3.0.9 + * + * @deprecated 4.0 - Use StringHelper::numbers($string); + */ + public static function replaceNumbers($string) + { + return StringHelper::numbers($string); + } + + /** + * Convert an integer into an English word string + * Thanks to Tom Nicholson + * + * @input int $x an int + * + * @returns string a string + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use StringHelper::number($x); + */ + public static function numberToString($x) + { + return StringHelper::number($x); + } + + /** + * Random Key + * + * @input int $size the length of the string + * + * @returns string a string of random characters + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use StringHelper::random($size); + */ + public static function randomkey($size): string + { + return StringHelper::random($size); + } + + /** + * Check if you have a json string + * + * @input string $string The json string to check + * + * @returns bool true on success + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use JsonHelper::check($string); + */ + public static function checkJson($string): bool + { + return JsonHelper::check($string); + } + + /** + * @since 3.0.9 + * + * @deprecated 4.0 - Use JsonHelper::string($value, $sperator, $table, $id, $name); + */ + public static function jsonToString($value, $sperator = ", ", $table = null, $id = 'id', $name = 'name') + { + return JsonHelper::string($value, $sperator, $table, $id, $name); + } + + /** + * Check if you have an array with a length + * + * @input mixed $array The array to check + * @input bool $removeEmptyString Should we remove empty values + * + * @returns int number of items in array on success + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use ArrayHelper::check($array, $removeEmptyString); + */ + public static function checkArray($array, $removeEmptyString = false): int + { + return ArrayHelper::check($array, $removeEmptyString); + } + + /** + * Merge an array of array's + * + * @input mixed $arrays The arrays you would like to merge + * + * @returns mixed array on success + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use ArrayHelper::merge($arrays); + */ + public static function mergeArrays($arrays) + { + return ArrayHelper::merge($arrays); + } + + /** + * Check if you have an object with a length + * + * @input object $object The object to check + * + * @returns bool true on success + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use ObjectHelper::check($object); + */ + public static function checkObject($object): bool + { + return ObjectHelper::check($object); + } + + /** + * Get a Variable + * + * @param string $table The table from which to get the variable + * @param string $where The value where + * @param string $whereString The target/field string where/name + * @param string $what The return field + * @param string $operator The operator between $whereString/field and $where/value + * @param string $main The component in which the table is found + * + * @return mix string/int/float + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use GetHelper::var($table, $where, $whereString, $what, $operator, $main); + */ + public static function getVar($table, $where = null, $whereString = 'user', $what = 'id', $operator = '=', $main = null) + { + // set the local component option + self::setComponentOption(); + + return GetHelper::var($table, $where, $whereString, $what, $operator, $main); + } + + /** + * Get array of variables + * + * @param string $table The table from which to get the variables + * @param string $where The value where + * @param string $whereString The target/field string where/name + * @param string $what The return field + * @param string $operator The operator between $whereString/field and $where/value + * @param string $main The component in which the table is found + * @param bool $unique The switch to return a unique array + * + * @return array + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use GetHelper::vars($table, $where, $whereString, $what, $operator, $main, $unique); + */ + public static function getVars($table, $where = null, $whereString = 'user', $what = 'id', $operator = 'IN', $main = null, $unique = true) + { + // set the local component option + self::setComponentOption(); + + return GetHelper::vars($table, $where, $whereString, $what, $operator, $main, $unique); + } + + /** + * get all strings between two other strings + * + * @param string $content The content to search + * @param string $start The starting value + * @param string $end The ending value + * + * @return array On success + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use GetHelper::allBetween($content, $start, $end); + */ + public static function getAllBetween($content, $start, $end) + { + return GetHelper::allBetween($content, $start, $end); + } + + /** + * get a string between two other strings + * + * @param string $content The content to search + * @param string $start The starting value + * @param string $end The ending value + * @param string $default The default value if none found + * + * @return string On success / empty string on failure + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use GetHelper::between($content, $start, $end, $default); + */ + public static function getBetween($content, $start, $end, $default = '') + { + return GetHelper::between($content, $start, $end, $default); + } + + /** + * bc math wrapper (very basic not for accounting) + * + * @param string $type The type bc math + * @param int $val1 The first value + * @param int $val2 The second value + * @param int $scale The scale value + * + * @return float|int + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use MathHelper::bc($type, $val1, $val2, $scale); + */ + public static function bcmath($type, $val1, $val2, $scale = 0) + { + return MathHelper::bc($type, $val1, $val2, $scale); + } + + /** + * Basic sum of an array with more precision + * + * @param array $array The values to sum + * @param int $scale The scale value + * + * @return float|int + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use MathHelper::sum($array, $scale); + */ + public static function bcsum($array, $scale = 4) + { + return MathHelper::sum($array, $scale); + } + + /** + * create plugin class name + * + * @input string The group name + * @input string The name + * + * @return string + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use PluginHelper::safe($name, $group); + */ + public static function createPluginClassName($group, $name) + { + return PluginHelper::safeClassName($name, $group); + } + + /** + * Returns a GUIDv4 string + * + * Thanks to Dave Pearson (and other) + * https://www.php.net/manual/en/function.com-create-guid.php#119168 + * + * Uses the best cryptographically secure method + * for all supported platforms with fallback to an older, + * less secure version. + * + * @param bool $trim + * + * @return string + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use GuidHelper::get($trim); + */ + public static function GUID($trim = true) + { + return GuidHelper::get($trim); + } + + /** + * Validate the Globally Unique Identifier ( and check if table already has this identifier) + * + * @param string $guid + * @param string $table + * @param int $id + * @param string|null $component + * + * @return bool + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use GuidHelper::valid($guid, $table, $id, $component); + */ + public static function validGUID($guid, $table = null, $id = 0, $component = null) + { + // set the local component option + self::setComponentOption(); + + return GuidHelper::valid($guid, $table, $id, $component); + } + + /** + * get the ITEM of a GUID by table + * + * @param string $guid + * @param string $table + * @param string/array $what + * @param string|null $component + * + * @return mix + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use GuidHelper::valid($guid, $table, $id, $component); + */ + public static function getGUID($guid, $table, $what = 'a.id', $component = null) + { + // set the local component option + self::setComponentOption(); + + return GuidHelper::item($guid, $table, $what, $component); + } + + /** + * Validate the Globally Unique Identifier + * + * Thanks to Lewie + * https://stackoverflow.com/a/1515456/1429677 + * + * @param string $guid + * + * @return bool + * + * @deprecated 4.0 - Use GuidHelper::validate($guid); + */ + protected static function validateGUID($guid) + { + return GuidHelper::validate($guid); + } + + /** + * The zipper method + * + * @param string $workingDIR The directory where the items must be zipped + * @param string $filepath The path to where the zip file must be placed + * + * @return bool true On success + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use FileHelper::zip($workingDIR, $filepath); + */ + public static function zip($workingDIR, &$filepath) + { + return FileHelper::zip($workingDIR, $filepath); + } + + /** + * get the content of a file + * + * @param string $path The path to the file + * @param string/bool $none The return value if no content was found + * + * @return string On success + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use FileHelper::getContent($path, $none); + */ + public static function getFileContents($path, $none = '') + { + return FileHelper::getContent($path, $none); + } + + /** + * Write a file to the server + * + * @param string $path The path and file name where to safe the data + * @param string $data The data to safe + * + * @return bool true On success + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use FileHelper::write($path, $data); + */ + public static function writeFile($path, $data) + { + return FileHelper::write($path, $data); + } + + /** + * get all the file paths in folder and sub folders + * + * @param string $folder The local path to parse + * @param array $fileTypes The type of files to get + * + * @return void + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use FileHelper::getPaths($folder, $fileTypes , $recurse, $full); + */ + public static function getAllFilePaths($folder, $fileTypes = array('\.php', '\.js', '\.css', '\.less'), $recurse = true, $full = true) + { + return FileHelper::getPaths($folder, $fileTypes , $recurse, $full); + } + + /** + * Get the file path or url + * + * @param string $type The (url/path) type to return + * @param string $target The Params Target name (if set) + * @param string $fileType The kind of filename to generate (if not set no file name is generated) + * @param string $key The key to adjust the filename (if not set ignored) + * @param string $default The default path if not set in Params (fallback path) + * @param bool $createIfNotSet The switch to create the folder if not found + * + * @return string On success the path or url is returned based on the type requested + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use FileHelper::getPath($type, $target, $fileType, $key, $default, $createIfNotSet); + */ + public static function getFilePath($type = 'path', $target = 'filepath', $fileType = null, $key = '', $default = '', $createIfNotSet = true) + { + // set the local component option + self::setComponentOption(); + + return FileHelper::getPath($type, $target, $fileType, $key, $default, $createIfNotSet); + } + + /** + * Check if file exist + * + * @param string $path The url/path to check + * + * @return bool If exist true + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use FileHelper::exists($path); + */ + public static function urlExists($path) + { + return FileHelper::exists($path); + } + + /** + * Set the component option + * + * @param String|null $option The option for the component. + * + * @since 3.0.11 + */ + public static function setComponentOption($option = null) + { + // set the local component option + if (empty($option)) + { + if (empty(Helper::$option) && property_exists(__CLASS__, 'ComponentCodeName')) + { + Helper::$option = 'com_' . self::$ComponentCodeName; + } + } + else + { + Helper::$option = $option; + } + } diff --git a/src/79d765b3-7319-4988-9730-446c7f347020/settings.json b/src/79d765b3-7319-4988-9730-446c7f347020/settings.json index 55476b1..61b9b5c 100644 --- a/src/79d765b3-7319-4988-9730-446c7f347020/settings.json +++ b/src/79d765b3-7319-4988-9730-446c7f347020/settings.json @@ -1,10 +1,9 @@ { "add_head": "0", + "add_licensing_template": "2", "extends": "0", - "extends_custom": "", "guid": "79d765b3-7319-4988-9730-446c7f347020", "implements": null, - "implements_custom": "", "load_selection": null, "name": "Utilities", "power_version": "1.0.0", @@ -69,5 +68,8 @@ } }, "namespace": "VDM\\Joomla\\Utilities", - "description": "Basic shared utilities, a legacy implementation\r\n\r\n@since 3.0.9" + "description": "Basic shared utilities, a legacy implementation\r\n\r\n@since 3.0.9", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 3rd September, 2020\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/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff/README.md b/src/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff/README.md new file mode 100644 index 0000000..b877c6b --- /dev/null +++ b/src/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff/README.md @@ -0,0 +1,88 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# interface ModelInterface (Details) +> namespace: **VDM\Joomla\Componentbuilder\Interfaces** +```uml +@startuml +interface ModelInterface #Lavender { + + value(mixed $value, string $field, ...) : mixed + + item(object $item, ?string $table = null) : ?object + + items(?array $items = null, ?string $table = null) : ?array + + row(array $item, ?string $table = null) : ?array + + rows(?array $items = null, ?string $table = null) : ?array + + last(?string $table = null) : ?int +} + +note right of ModelInterface::value + Model the value +Example: $this->value(value, 'value_key', 'table_name'); + + since: 3.2.0 + return: mixed + + arguments: + mixed $value + string $field + ?string $table = null +end note + +note right of ModelInterface::item + Model the values of an item +Example: $this->item(Object, 'table_name'); + + since: 3.2.0 + return: ?object +end note + +note right of ModelInterface::items + Model the values of multiple items +Example: $this->items(Array, 'table_name'); + + since: 3.2.0 + return: ?array +end note + +note right of ModelInterface::row + Model the values of an row +Example: $this->item(Array, 'table_name'); + + since: 3.2.0 + return: ?array +end note + +note right of ModelInterface::rows + Model the values of multiple rows +Example: $this->items(Array, 'table_name'); + + since: 3.2.0 + return: ?array +end note + +note right of ModelInterface::last + Get last modeled ID +Example: $this->last('table_name'); + + since: 3.2.0 + return: ?int +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff/code.php b/src/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff/code.php new file mode 100644 index 0000000..3792660 --- /dev/null +++ b/src/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff/code.php @@ -0,0 +1,95 @@ + + * @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; + + +/** + * Model Interface + * + * @since 3.2.0 + */ +interface ModelInterface +{ + /** + * Model the value + * Example: $this->value(value, 'value_key', 'table_name'); + * + * @param mixed $value The value to model + * @param string $field The field key + * @param string|null $table The table + * + * @return mixed + * @since 3.2.0 + */ + public function value($value, string $field, ?string $table = null); + + /** + * Model the values of an item + * Example: $this->item(Object, 'table_name'); + * + * @param object $item The item object + * @param string|null $table The table + * + * @return object|null + * @since 3.2.0 + */ + public function item(object $item, ?string $table = null): ?object; + + /** + * Model the values of multiple items + * Example: $this->items(Array, 'table_name'); + * + * @param array|null $items The array of item objects + * @param string|null $table The table + * + * @return array|null + * @since 3.2.0 + */ + public function items(?array $items = null, ?string $table = null): ?array; + + /** + * Model the values of an row + * Example: $this->item(Array, 'table_name'); + * + * @param array $item The item array + * @param string|null $table The table + * + * @return array|null + * @since 3.2.0 + */ + public function row(array $item, ?string $table = null): ?array; + + /** + * Model the values of multiple rows + * Example: $this->items(Array, 'table_name'); + * + * @param array|null $items The array of item array + * @param string|null $table The table + * + * @return array|null + * @since 3.2.0 + */ + public function rows(?array $items = null, ?string $table = null): ?array; + + /** + * Get last modeled ID + * Example: $this->last('table_name'); + * + * @param string|null $table The table + * + * @return int|null + * @since 3.2.0 + */ + public function last(?string $table = null): ?int; + +} + diff --git a/src/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff/code.power b/src/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff/code.power new file mode 100644 index 0000000..7e54ce5 --- /dev/null +++ b/src/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff/code.power @@ -0,0 +1,71 @@ + /** + * Model the value + * Example: $this->value(value, 'value_key', 'table_name'); + * + * @param mixed $value The value to model + * @param string $field The field key + * @param string|null $table The table + * + * @return mixed + * @since 3.2.0 + */ + public function value($value, string $field, ?string $table = null); + + /** + * Model the values of an item + * Example: $this->item(Object, 'table_name'); + * + * @param object $item The item object + * @param string|null $table The table + * + * @return object|null + * @since 3.2.0 + */ + public function item(object $item, ?string $table = null): ?object; + + /** + * Model the values of multiple items + * Example: $this->items(Array, 'table_name'); + * + * @param array|null $items The array of item objects + * @param string|null $table The table + * + * @return array|null + * @since 3.2.0 + */ + public function items(?array $items = null, ?string $table = null): ?array; + + /** + * Model the values of an row + * Example: $this->item(Array, 'table_name'); + * + * @param array $item The item array + * @param string|null $table The table + * + * @return array|null + * @since 3.2.0 + */ + public function row(array $item, ?string $table = null): ?array; + + /** + * Model the values of multiple rows + * Example: $this->items(Array, 'table_name'); + * + * @param array|null $items The array of item array + * @param string|null $table The table + * + * @return array|null + * @since 3.2.0 + */ + public function rows(?array $items = null, ?string $table = null): ?array; + + /** + * Get last modeled ID + * Example: $this->last('table_name'); + * + * @param string|null $table The table + * + * @return int|null + * @since 3.2.0 + */ + public function last(?string $table = null): ?int; diff --git a/src/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff/settings.json b/src/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff/settings.json new file mode 100644 index 0000000..a34f200 --- /dev/null +++ b/src/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff/settings.json @@ -0,0 +1,18 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff", + "implements": null, + "load_selection": null, + "name": "ModelInterface", + "power_version": "1.0.0", + "system_name": "JCB.Interfaces.ModelInterface", + "type": "interface", + "use_selection": null, + "namespace": "VDM\\Joomla\\Componentbuilder.Interfaces.ModelInterface", + "description": "Model 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/91004529-94a9-4590-b842-e7c6b624ecf5/code.power b/src/91004529-94a9-4590-b842-e7c6b624ecf5/code.power new file mode 100644 index 0000000..026df61 --- /dev/null +++ b/src/91004529-94a9-4590-b842-e7c6b624ecf5/code.power @@ -0,0 +1,54 @@ + /** + * Check if have an object with a length + * + * @input object The object to check + * + * @returns bool true on success + * + * @since 3.0.9 + */ + public static function check($object) + { + if (is_object($object)) + { + return count((array) $object) > 0; + } + + return false; + } + + /** + * Compare two objects for equality based on their property values. + * + * Note that this method works only for simple objects that don't + * contain any nested objects or resource references. If you need + * to compare more complex objects, you may need to use a + * more advanced method such as serialization or reflection. + * + * @param object|null $obj1 The first object to compare. + * @param object|null $obj2 The second object to compare. + * + * @return bool True if the objects have the same key-value pairs and false otherwise. + */ + public static function equal(?object $obj1, ?object $obj2): bool + { + // if any is null we return false as that means there is a none object + // we are not comparing null but objects + // but we allow null as some objects while + // not instantiate are still null + if (is_null($obj1) || is_null($obj2)) + { + return false; + } + + // Convert the objects to arrays of their property values using get_object_vars. + $array1 = get_object_vars($obj1); + $array2 = get_object_vars($obj2); + + // Compare the arrays using array_diff_assoc to detect any differences. + $diff1 = array_diff_assoc($array1, $array2); + $diff2 = array_diff_assoc($array2, $array1); + + // If the arrays have the same key-value pairs, they will have no differences, so return true. + return empty($diff1) && empty($diff2); + } diff --git a/src/91004529-94a9-4590-b842-e7c6b624ecf5/settings.json b/src/91004529-94a9-4590-b842-e7c6b624ecf5/settings.json index c47b4ad..36f382c 100644 --- a/src/91004529-94a9-4590-b842-e7c6b624ecf5/settings.json +++ b/src/91004529-94a9-4590-b842-e7c6b624ecf5/settings.json @@ -1,10 +1,9 @@ { "add_head": "0", + "add_licensing_template": "2", "extends": "0", - "extends_custom": "", "guid": "91004529-94a9-4590-b842-e7c6b624ecf5", "implements": null, - "implements_custom": "", "load_selection": null, "name": "ObjectHelper", "power_version": "1.0.0", @@ -12,5 +11,8 @@ "type": "abstract class", "use_selection": null, "namespace": "VDM\\Joomla\\Utilities.ObjectHelper", - "description": "Some object tricks\r\n\r\n@since 3.0.9" + "description": "Some object tricks\r\n\r\n@since 3.0.9", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 3rd September, 2020\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/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/README.md b/src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/README.md new file mode 100644 index 0000000..36b85c4 --- /dev/null +++ b/src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/README.md @@ -0,0 +1,68 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# abstract class BaseConfig (Details) +> namespace: **VDM\Joomla\Componentbuilder\Abstraction** +```uml +@startuml +abstract BaseConfig #Orange { + # Input $input + # JoomlaRegistry $params + + __construct(?Input $input = null, ?JoomlaRegistry $params = null) + + __set(string $key, mixed $value) + + __get(string $key) + + get(string $path, mixed $default = null) : mixed + + appendArray(string $path, mixed $value) : mixed +} + +note right of BaseConfig::__construct + Constructor + + since: 3.2.0 +end note + +note right of BaseConfig::__set + setting any config value + + since: 3.2.0 +end note + +note right of BaseConfig::__get + getting any valid value + + since: 3.2.0 +end note + +note right of BaseConfig::get + Get a config value. + + since: 3.2.0 + return: mixed +end note + +note right of BaseConfig::appendArray + Append value to a path in registry of an array + + since: 3.2.0 + return: mixed +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/code.php b/src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/code.php new file mode 100644 index 0000000..76c01e3 --- /dev/null +++ b/src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/code.php @@ -0,0 +1,149 @@ + + * @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\Abstraction; + + +use Joomla\Registry\Registry as JoomlaRegistry; +use Joomla\CMS\Factory; +use Joomla\Input\Input; +use VDM\Joomla\Utilities\Component\Helper; +use VDM\Joomla\Utilities\String\ClassfunctionHelper; + + +/** + * Config + * + * @since 3.2.0 + */ +abstract class BaseConfig extends JoomlaRegistry +{ + /** + * Hold a JInput object for easier access to the input variables. + * + * @var Input + * @since 3.2.0 + */ + protected Input $input; + + /** + * The Params + * + * @var JoomlaRegistry + * @since 3.2.0 + */ + protected JoomlaRegistry $params; + + /** + * Constructor + * + * @param Input|null $input Input + * @param Registry|null $params The component parameters + * + * @throws \Exception + * @since 3.2.0 + */ + public function __construct(?Input $input = null, ?JoomlaRegistry $params = null) + { + $this->input = $input ?: Factory::getApplication()->input; + $this->params = $params ?: Helper::getParams('com_componentbuilder'); + + // Instantiate the internal data object. + $this->data = new \stdClass(); + } + + /** + * setting any config value + * + * @param string $key The value's key/path name + * @param mixed $value Optional default value, returned if the internal value is null. + * + * @since 3.2.0 + */ + public function __set(string $key, $value) + { + $this->set($key, $value); + } + + /** + * getting any valid value + * + * @param string $key The value's key/path name + * + * @since 3.2.0 + * @throws \InvalidArgumentException If $key is not a valid function name. + */ + public function __get(string $key) + { + // check if it has been set + if (($value = $this->get($key, '__N0T_S3T_Y3T_')) !== '__N0T_S3T_Y3T_') + { + return $value; + } + + throw new \InvalidArgumentException(sprintf('Argument %s could not be found as function or path.', $key)); + } + + /** + * Get a config value. + * + * @param string $path Registry path (e.g. joomla_content_showauthor) + * @param mixed $default Optional default value, returned if the internal value is null. + * + * @return mixed Value of entry or null + * + * @since 3.2.0 + */ + public function get($path, $default = null) + { + // function name with no underscores + $method = 'get' . ucfirst((string) ClassfunctionHelper::safe(str_replace('_', '', $path))); + + // check if it has been set + if (($value = parent::get($path, '__N0T_S3T_Y3T_')) !== '__N0T_S3T_Y3T_') + { + return $value; + } + elseif (method_exists($this, $method)) + { + $value = $this->{$method}($default); + + $this->set($path, $value); + + return $value; + } + + return $default; + } + + /** + * Append value to a path in registry of an array + * + * @param string $path Parent registry Path (e.g. joomla.content.showauthor) + * @param mixed $value Value of entry + * + * @return mixed The value of the that has been set. + * + * @since 3.2.0 + */ + public function appendArray(string $path, $value) + { + // check if it does not exist + if (!$this->exists($path)) + { + $this->set($path, []); + } + + return $this->append($path, $value); + } + +} + diff --git a/src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/code.power b/src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/code.power new file mode 100644 index 0000000..883d562 --- /dev/null +++ b/src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/code.power @@ -0,0 +1,118 @@ + /** + * Hold a JInput object for easier access to the input variables. + * + * @var Input + * @since 3.2.0 + */ + protected Input $input; + + /** + * The Params + * + * @var JoomlaRegistry + * @since 3.2.0 + */ + protected JoomlaRegistry $params; + + /** + * Constructor + * + * @param Input|null $input Input + * @param Registry|null $params The component parameters + * + * @throws \Exception + * @since 3.2.0 + */ + public function __construct(?Input $input = null, ?JoomlaRegistry $params = null) + { + $this->input = $input ?: Factory::getApplication()->input; + $this->params = $params ?: Helper::getParams('com_componentbuilder'); + + // Instantiate the internal data object. + $this->data = new \stdClass(); + } + + /** + * setting any config value + * + * @param string $key The value's key/path name + * @param mixed $value Optional default value, returned if the internal value is null. + * + * @since 3.2.0 + */ + public function __set(string $key, $value) + { + $this->set($key, $value); + } + + /** + * getting any valid value + * + * @param string $key The value's key/path name + * + * @since 3.2.0 + * @throws \InvalidArgumentException If $key is not a valid function name. + */ + public function __get(string $key) + { + // check if it has been set + if (($value = $this->get($key, '__N0T_S3T_Y3T_')) !== '__N0T_S3T_Y3T_') + { + return $value; + } + + throw new \InvalidArgumentException(sprintf('Argument %s could not be found as function or path.', $key)); + } + + /** + * Get a config value. + * + * @param string $path Registry path (e.g. joomla_content_showauthor) + * @param mixed $default Optional default value, returned if the internal value is null. + * + * @return mixed Value of entry or null + * + * @since 3.2.0 + */ + public function get($path, $default = null) + { + // function name with no underscores + $method = 'get' . ucfirst((string) ClassfunctionHelper::safe(str_replace('_', '', $path))); + + // check if it has been set + if (($value = parent::get($path, '__N0T_S3T_Y3T_')) !== '__N0T_S3T_Y3T_') + { + return $value; + } + elseif (method_exists($this, $method)) + { + $value = $this->{$method}($default); + + $this->set($path, $value); + + return $value; + } + + return $default; + } + + /** + * Append value to a path in registry of an array + * + * @param string $path Parent registry Path (e.g. joomla.content.showauthor) + * @param mixed $value Value of entry + * + * @return mixed The value of the that has been set. + * + * @since 3.2.0 + */ + public function appendArray(string $path, $value) + { + // check if it does not exist + if (!$this->exists($path)) + { + $this->set($path, []); + } + + return $this->append($path, $value); + } diff --git a/src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/settings.json b/src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/settings.json new file mode 100644 index 0000000..6d2aa02 --- /dev/null +++ b/src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/settings.json @@ -0,0 +1,28 @@ +{ + "add_head": "1", + "add_licensing_template": "2", + "extends": "-1", + "guid": "9769f3b2-17bf-4f20-b54b-3a4ebe572b36", + "implements": null, + "load_selection": null, + "name": "BaseConfig", + "power_version": "1.0.0", + "system_name": "JCB.Abstraction.BaseConfig", + "type": "abstract class", + "use_selection": { + "use_selection0": { + "use": "640b5352-fb09-425f-a26e-cd44eda03f15", + "as": "default" + }, + "use_selection1": { + "use": "30c5b4c2-f75f-4d15-869a-f8bfedd87358", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Abstraction.BaseConfig", + "description": "Config\r\n\r\n@since 3.2.0", + "extends_custom": "JoomlaRegistry", + "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": "use Joomla\\Registry\\Registry as JoomlaRegistry;\r\nuse Joomla\\CMS\\Factory;\r\nuse Joomla\\Input\\Input;", + "composer": "" +} \ No newline at end of file diff --git a/src/9c513baf-b279-43fd-ae29-a585c8cbc4f0/code.power b/src/9c513baf-b279-43fd-ae29-a585c8cbc4f0/code.power new file mode 100644 index 0000000..938ba00 --- /dev/null +++ b/src/9c513baf-b279-43fd-ae29-a585c8cbc4f0/code.power @@ -0,0 +1,186 @@ + /** + * Returns a GUIDv4 string + * + * Thanks to Dave Pearson (and other) + * https://www.php.net/manual/en/function.com-create-guid.php#119168 + * + * Uses the best cryptographically secure method + * for all supported platforms with fallback to an older, + * less secure version. + * + * @param bool $trim + * + * @return string + * + * @since 3.0.9 + */ + public static function get(bool $trim = true): string + { + // Windows + if (function_exists('com_create_guid')) + { + if ($trim) + { + return trim(com_create_guid(), '{}'); + } + return com_create_guid(); + } + + // set the braces if needed + $lbrace = $trim ? "" : chr(123); // "{" + $rbrace = $trim ? "" : chr(125); // "}" + + // OSX/Linux + if (function_exists('openssl_random_pseudo_bytes')) + { + $data = openssl_random_pseudo_bytes(16); + $data[6] = chr( ord($data[6]) & 0x0f | 0x40); // set version to 0100 + $data[8] = chr( ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10 + return $lbrace . vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4)) . $lbrace; + } + + // Fallback (PHP 4.2+) + mt_srand((double) microtime() * 10000); + $charid = strtolower( md5( uniqid( rand(), true))); + $hyphen = chr(45); // "-" + $guidv4 = $lbrace. + substr($charid, 0, 8). $hyphen. + substr($charid, 8, 4). $hyphen. + substr($charid, 12, 4). $hyphen. + substr($charid, 16, 4). $hyphen. + substr($charid, 20, 12). + $rbrace; + return $guidv4; + } + + /** + * Validate the Globally Unique Identifier ( and check if table already has this identifier) + * + * @param string $guid + * @param string|null $table + * @param int $id + * @param string|null $component + * + * @return bool + * + * @since 3.0.9 + */ + public static function valid($guid, ?string $table = null, int $id = 0, ?string $component = null): bool + { + // check if we have a string + if (self::validate($guid)) + { + // check if table already has this identifier + if (StringHelper::check($table)) + { + // check that we have the component code name + if (!is_string($component)) + { + $component = (string) Helper::getCode(); + } + // Get the database object and a new query object. + $db = Factory::getDbo(); + $query = $db->getQuery(true); + $query->select('COUNT(*)') + ->from('#__' . (string) $component . '_' . (string) $table) + ->where($db->quoteName('guid') . ' = ' . $db->quote($guid)); + + // remove this item from the list + if ($id > 0) + { + $query->where($db->quoteName('id') . ' <> ' . (int) $id); + } + + // Set and query the database. + $db->setQuery($query); + $duplicate = (bool) $db->loadResult(); + + if ($duplicate) + { + return false; + } + } + return true; + } + return false; + } + + /** + * get the item by guid in a table + * + * @param string $guid + * @param string $table + * @param string|array $what + * @param string|null $component + * + * @return mix + * + * @since 3.0.9 + */ + public static function item($guid, $table, $what = 'a.id', ?string $component = null) + { + // check if we have a string + // check if table already has this identifier + if (self::validate($guid) && StringHelper::check($table)) + { + // check that we have the component code name + if (!is_string($component)) + { + $component = (string) Helper::getCode(); + } + // Get the database object and a new query object. + $db = Factory::getDbo(); + $query = $db->getQuery(true); + + if (ArrayHelper::check($what)) + { + $query->select($db->quoteName($what)); + } + else + { + $query->select($what); + } + + $query->from($db->quoteName('#__' . (string) $component . '_' . (string) $table, 'a')) + ->where($db->quoteName('a.guid') . ' = ' . $db->quote($guid)); + + // Set and query the database. + $db->setQuery($query); + $db->execute(); + + if ($db->getNumRows()) + { + if (ArrayHelper::check($what) || $what === 'a.*') + { + return $db->loadObject(); + } + else + { + return $db->loadResult(); + } + } + } + return false; + } + + /** + * Validate the Globally Unique Identifier + * + * Thanks to Lewie + * https://stackoverflow.com/a/1515456/1429677 + * + * @param string $guid + * + * @return bool + * + * @since 3.0.9 + */ + protected static function validate($guid) + { + // check if we have a string + if (StringHelper::check($guid)) + { + return preg_match("/^(\{)?[a-f\d]{8}(-[a-f\d]{4}){4}[a-f\d]{8}(?(1)\})$/i", $guid); + } + return false; + } diff --git a/src/9c513baf-b279-43fd-ae29-a585c8cbc4f0/settings.json b/src/9c513baf-b279-43fd-ae29-a585c8cbc4f0/settings.json index 3fc2dbb..dd5c31b 100644 --- a/src/9c513baf-b279-43fd-ae29-a585c8cbc4f0/settings.json +++ b/src/9c513baf-b279-43fd-ae29-a585c8cbc4f0/settings.json @@ -1,10 +1,9 @@ { "add_head": "1", + "add_licensing_template": "2", "extends": "0", - "extends_custom": "", "guid": "9c513baf-b279-43fd-ae29-a585c8cbc4f0", "implements": null, - "implements_custom": "", "load_selection": { "load_selection0": { "load": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a" @@ -25,5 +24,7 @@ }, "namespace": "VDM\\Joomla\\Utilities.GuidHelper", "description": "Global Unique ID Helper\r\n\r\n@since 3.0.9", - "head": "use Joomla\\CMS\\Factory;" + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 3rd September, 2020\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": "use Joomla\\CMS\\Factory;", + "composer": "" } \ No newline at end of file diff --git a/src/9ef0eb24-aae4-4f5a-99af-d724db44808f/README.md b/src/9ef0eb24-aae4-4f5a-99af-d724db44808f/README.md new file mode 100644 index 0000000..48fa006 --- /dev/null +++ b/src/9ef0eb24-aae4-4f5a-99af-d724db44808f/README.md @@ -0,0 +1,42 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# abstract class FieldHelper (Details) +> namespace: **VDM\Joomla\Utilities\String** +```uml +@startuml +abstract FieldHelper #Orange { + # static $builder + + {static} safe($string, $allcap = false, ...) +} + +note right of FieldHelper::safe + Making field names safe + + since: 3.0.9 + + arguments: + $string + $allcap = false + $spacer = '_' +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/9ef0eb24-aae4-4f5a-99af-d724db44808f/code.php b/src/9ef0eb24-aae4-4f5a-99af-d724db44808f/code.php new file mode 100644 index 0000000..0f687b6 --- /dev/null +++ b/src/9ef0eb24-aae4-4f5a-99af-d724db44808f/code.php @@ -0,0 +1,103 @@ + + * @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\Utilities\String; + + +use Joomla\CMS\Component\ComponentHelper; +use VDM\Joomla\Utilities\StringHelper; +use VDM\Joomla\Utilities\Component\Helper; + + +/** + * Control the naming of a field + * + * @since 3.0.9 + */ +abstract class FieldHelper +{ + /** + * The field builder switch + * + * @since 3.0.9 + */ + protected static $builder = false; + + /** + * Making field names safe + * + * @input string The string you would like to make safe + * @input boolean The switch to return an ALL UPPER CASE string + * @input string The string to use in white space + * + * @returns string on success + * + * @since 3.0.9 + */ + public static function safe($string, $allcap = false, $spacer = '_') + { + // get global value + if (self::$builder === false) + { + self::$builder = Helper::getParams()->get('field_name_builder', 1); + } + + // use the new convention + if (2 == self::$builder) + { + // 0nly continue if we have a string + if (StringHelper::check($string)) + { + // check that the first character is not a number + if (is_numeric(substr((string)$string, 0, 1))) + { + $string = StringHelper::numbers($string); + } + + // remove all other strange characters + $string = trim((string) $string); + $string = preg_replace('/'.$spacer.'+/', ' ', $string); + $string = preg_replace('/\s+/', ' ', $string); + + // Transliterate string + $string = StringHelper::transliterate($string); + + // remove all and keep only characters and numbers + $string = preg_replace("/[^A-Za-z0-9 ]/", '', (string) $string); + + // replace white space with underscore (SAFEST OPTION) + $string = preg_replace('/\s+/', (string) $spacer, $string); + + // return all caps + if ($allcap) + { + return strtoupper($string); + } + + // default is to return lower + return strtolower($string); + } + // not a string + return ''; + } + + // return all caps + if ($allcap) + { + return StringHelper::safe($string, 'U'); + } + + // use the default (original behavior/convention) + return StringHelper::safe($string); + } + +} + diff --git a/src/9ef0eb24-aae4-4f5a-99af-d724db44808f/code.power b/src/9ef0eb24-aae4-4f5a-99af-d724db44808f/code.power new file mode 100644 index 0000000..0b27fc5 --- /dev/null +++ b/src/9ef0eb24-aae4-4f5a-99af-d724db44808f/code.power @@ -0,0 +1,74 @@ + /** + * The field builder switch + * + * @since 3.0.9 + */ + protected static $builder = false; + + /** + * Making field names safe + * + * @input string The string you would like to make safe + * @input boolean The switch to return an ALL UPPER CASE string + * @input string The string to use in white space + * + * @returns string on success + * + * @since 3.0.9 + */ + public static function safe($string, $allcap = false, $spacer = '_') + { + // get global value + if (self::$builder === false) + { + self::$builder = Helper::getParams()->get('field_name_builder', 1); + } + + // use the new convention + if (2 == self::$builder) + { + // 0nly continue if we have a string + if (StringHelper::check($string)) + { + // check that the first character is not a number + if (is_numeric(substr((string)$string, 0, 1))) + { + $string = StringHelper::numbers($string); + } + + // remove all other strange characters + $string = trim((string) $string); + $string = preg_replace('/'.$spacer.'+/', ' ', $string); + $string = preg_replace('/\s+/', ' ', $string); + + // Transliterate string + $string = StringHelper::transliterate($string); + + // remove all and keep only characters and numbers + $string = preg_replace("/[^A-Za-z0-9 ]/", '', (string) $string); + + // replace white space with underscore (SAFEST OPTION) + $string = preg_replace('/\s+/', (string) $spacer, $string); + + // return all caps + if ($allcap) + { + return strtoupper($string); + } + + // default is to return lower + return strtolower($string); + } + // not a string + return ''; + } + + // return all caps + if ($allcap) + { + return StringHelper::safe($string, 'U'); + } + + // use the default (original behavior/convention) + return StringHelper::safe($string); + } diff --git a/src/9ef0eb24-aae4-4f5a-99af-d724db44808f/settings.json b/src/9ef0eb24-aae4-4f5a-99af-d724db44808f/settings.json new file mode 100644 index 0000000..64e832f --- /dev/null +++ b/src/9ef0eb24-aae4-4f5a-99af-d724db44808f/settings.json @@ -0,0 +1,27 @@ +{ + "add_head": "1", + "add_licensing_template": "2", + "extends": "0", + "guid": "9ef0eb24-aae4-4f5a-99af-d724db44808f", + "implements": null, + "load_selection": null, + "name": "FieldHelper", + "power_version": "1.0.0", + "system_name": "String Field Helper", + "type": "abstract class", + "use_selection": { + "use_selection0": { + "use": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef", + "as": "default" + }, + "use_selection1": { + "use": "640b5352-fb09-425f-a26e-cd44eda03f15", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Utilities.String.FieldHelper", + "description": "Control the naming of a field\r\n\r\n@since 3.0.9", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 3rd September, 2020\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": "use Joomla\\CMS\\Component\\ComponentHelper;", + "composer": "" +} \ No newline at end of file diff --git a/src/a223b31e-ea1d-4cdf-92ae-5f9becffaff0/code.power b/src/a223b31e-ea1d-4cdf-92ae-5f9becffaff0/code.power new file mode 100644 index 0000000..c89d1b7 --- /dev/null +++ b/src/a223b31e-ea1d-4cdf-92ae-5f9becffaff0/code.power @@ -0,0 +1,329 @@ + /** + * Trigger error notice only once + * + * @var bool + * + * @since 3.0.9 + */ + protected static $curlError = false; + + /** + * The zipper method + * + * @param string $workingDirectory The directory where the items must be zipped + * @param string $filepath The path to where the zip file must be placed + * + * @return bool true On success + * + * @since 3.0.9 + */ + public static function zip($workingDirectory, &$filepath): bool + { + // store the current joomla working directory + $joomla = getcwd(); + + // we are changing the working directory to the component temp folder + chdir($workingDirectory); + + // the full file path of the zip file + $filepath = Path::clean($filepath); + + // delete an existing zip file (or use an exclusion parameter in Folder::files() + File::delete($filepath); + + // get a list of files in the current directory tree (also the hidden files) + $files = Folder::files('.', '', true, true, array('.svn', 'CVS', '.DS_Store', '__MACOSX'), array('.*~')); + + $zipArray = []; + // setup the zip array + foreach ($files as $file) + { + $tmp = []; + $tmp['name'] = str_replace('./', '', (string) $file); + $tmp['data'] = self::getContent($file); + $tmp['time'] = filemtime($file); + $zipArray[] = $tmp; + } + + // change back to joomla working directory + chdir($joomla); + + // get the zip adapter + $zip = (new Archive())->getAdapter('zip'); + + //create the zip file + return (bool) $zip->create($filepath, $zipArray); + } + + /** + * get the content of a file + * + * @param string $path The path to the file + * @param string/bool $none The return value if no content was found + * + * @return string On success + * + * @since 3.0.9 + */ + public static function getContent($path, $none = '') + { + if (StringHelper::check($path)) + { + // use basic file get content for now + if (($content = @file_get_contents($path)) !== FALSE) + { + return $content; + } + // use curl if available + elseif (function_exists('curl_version')) + { + // start curl + $ch = curl_init(); + // set the options + $options = []; + $options[CURLOPT_URL] = $path; + $options[CURLOPT_USERAGENT] = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12'; + $options[CURLOPT_RETURNTRANSFER] = TRUE; + $options[CURLOPT_SSL_VERIFYPEER] = FALSE; + // load the options + curl_setopt_array($ch, $options); + // get the content + $content = curl_exec($ch); + // close the connection + curl_close($ch); + + // return if found + if (StringHelper::check($content)) + { + return $content; + } + } + elseif (!self::$curlError) + { + // set the notice + Factory::getApplication()->enqueueMessage(Text::_('

Curl Not Found!

Please setup curl on your system, or [[[component]]] will not function correctly!

'), 'Error'); + // load this notice only once + self::$curlError = true; + } + } + return $none; + } + + /** + * Write a file to the server + * + * @param string $path The path and file name where to safe the data + * @param string $data The data to safe + * + * @return bool true On success + * + * @since 3.0.9 + */ + public static function write($path, $data) + { + $klaar = false; + if (StringHelper::check($data)) + { + // open the file + $fh = fopen($path, "w"); + if (!is_resource($fh)) + { + return $klaar; + } + // write to the file + if (fwrite($fh, $data)) + { + // has been done + $klaar = true; + } + // close file. + fclose($fh); + } + return $klaar; + } + + /** + * get all the file paths in folder and sub folders + * + * @param string $folder The local path to parse + * @param array $fileTypes The type of files to get + * + * @return void + * + * @since 3.0.9 + */ + public static function getPaths($folder, $fileTypes = array('\.php', '\.js', '\.css', '\.less'), $recurse = true, $full = true) + { + if (Folder::exists($folder)) + { + // we must first store the current woking directory + $joomla = getcwd(); + // we are changing the working directory to the component path + chdir($folder); + + // make sure we have file type filter + if (ArrayHelper::check($fileTypes)) + { + // get the files + foreach ($fileTypes as $type) + { + // get a list of files in the current directory tree + $files[] = Folder::files('.', $type, $recurse, $full); + } + } + elseif (StringHelper::check($fileTypes)) + { + // get a list of files in the current directory tree + $files[] = Folder::files('.', $fileTypes, $recurse, $full); + } + else + { + // get a list of files in the current directory tree + $files[] = Folder::files('.', '.', $recurse, $full); + } + + // change back to Joomla working directory + chdir($joomla); + + // return array of files + return array_map( fn($file) => str_replace('./', '/', (string) $file), (array) ArrayHelper::merge($files)); + } + return false; + } + + /** + * Get the file path or url + * + * @param string $type The (url/path) type to return + * @param string $target The Params Target name (if set) + * @param string $fileType The kind of filename to generate (if not set no file name is generated) + * @param string $key The key to adjust the filename (if not set ignored) + * @param string $default The default path if not set in Params (fallback path) + * @param bool $createIfNotSet The switch to create the folder if not found + * + * @return string On success the path or url is returned based on the type requested + * + * @since 3.0.9 + */ + public static function getPath($type = 'path', $target = 'filepath', $fileType = null, $key = '', $default = '', $createIfNotSet = true) + { + // make sure to always have a string/path + if(!StringHelper::check($default)) + { + $default = JPATH_SITE . '/images/'; + } + + // get the global settings + $filePath = Helper::getParams()->get($target, $default); + + // check the file path (revert to default only of not a hidden file path) + if ('hiddenfilepath' !== $target && strpos((string) $filePath, (string) JPATH_SITE) === false) + { + $filePath = $default; + } + + // create the folder if it does not exist + if ($createIfNotSet && !Folder::exists($filePath)) + { + Folder::create($filePath); + } + + // setup the file name + $fileName = ''; + + // Get basic key + $basickey = 'Th!s_iS_n0t_sAfe_buT_b3tter_then_n0thiug'; + // get the component helper + $helper = Helper::get(); + // check if method exist in helper class + if ($helper && Helper::methodExists('getCryptKey')) + { + $basickey = $helper::getCryptKey('basic', $basickey); + } + + // check the key + if (!StringHelper::check($key)) + { + $key = 'vDm'; + } + + // set the file name + if (StringHelper::check($fileType)) + { + // set the name + $fileName = trim( md5($type . $target . $basickey . $key) . '.' . trim($fileType, '.')); + } + else + { + $fileName = trim( md5($type . $target . $basickey . $key)) . '.txt'; + } + + // return the url + if ('url' === $type) + { + if (\strpos((string) $filePath, (string) JPATH_SITE) !== false) + { + $filePath = trim( str_replace( JPATH_SITE, '', (string) $filePath), '/'); + + return Uri::root() . $filePath . '/' . $fileName; + } + + // since the path is behind the root folder of the site, return only the root url (may be used to build the link) + return Uri::root(); + } + + // sanitize the path + return '/' . trim((string) $filePath, '/' ) . '/' . $fileName; + } + + /** + * Check if file exist + * + * @param string $path The url/path to check + * + * @return bool If exist true + * + * @since 3.0.9 + */ + public static function exists($path) + { + $exists = false; + // if this is a local path + if (strpos($path, 'http:') === false && strpos($path, 'https:') === false) + { + if (file_exists($path)) + { + $exists = true; + } + } + // check if we can use curl + elseif (function_exists('curl_version')) + { + // initiate curl + $ch = curl_init($path); + // CURLOPT_NOBODY (do not return body) + curl_setopt($ch, CURLOPT_NOBODY, true); + // make call + $result = curl_exec($ch); + // check return value + if ($result !== false) + { + // get the http CODE + $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + if ($statusCode !== 404) + { + $exists = true; + } + } + // close the connection + curl_close($ch); + } + elseif ($headers = @get_headers($path)) + { + if(isset($headers[0]) && is_string($headers[0]) && strpos($headers[0],'404') === false) + { + $exists = true; + } + } + return $exists; + } diff --git a/src/a223b31e-ea1d-4cdf-92ae-5f9becffaff0/settings.json b/src/a223b31e-ea1d-4cdf-92ae-5f9becffaff0/settings.json index 436a97d..792b263 100644 --- a/src/a223b31e-ea1d-4cdf-92ae-5f9becffaff0/settings.json +++ b/src/a223b31e-ea1d-4cdf-92ae-5f9becffaff0/settings.json @@ -1,10 +1,9 @@ { "add_head": "1", + "add_licensing_template": "2", "extends": "0", - "extends_custom": "", "guid": "a223b31e-ea1d-4cdf-92ae-5f9becffaff0", "implements": null, - "implements_custom": "", "load_selection": { "load_selection0": { "load": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a" @@ -28,5 +27,7 @@ }, "namespace": "VDM\\Joomla\\Utilities.FileHelper", "description": "File helper\r\n\r\n@since 3.0.9", - "head": "use Joomla\\CMS\\Uri\\Uri;\r\nuse Joomla\\CMS\\Factory;\r\nuse Joomla\\CMS\\Language\\Text;\r\nuse Joomla\\CMS\\Filesystem\\Path;\r\nuse Joomla\\CMS\\Filesystem\\File;\r\nuse Joomla\\CMS\\Filesystem\\Folder;\r\nuse Joomla\\Archive\\Archive;" + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 3rd September, 2020\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": "use Joomla\\CMS\\Uri\\Uri;\r\nuse Joomla\\CMS\\Factory;\r\nuse Joomla\\CMS\\Language\\Text;\r\nuse Joomla\\CMS\\Filesystem\\Path;\r\nuse Joomla\\CMS\\Filesystem\\File;\r\nuse Joomla\\CMS\\Filesystem\\Folder;\r\nuse Joomla\\Archive\\Archive;", + "composer": "" } \ No newline at end of file diff --git a/src/a8935cbe-7701-40dc-bfd5-675f2d600954/README.md b/src/a8935cbe-7701-40dc-bfd5-675f2d600954/README.md new file mode 100644 index 0000000..c5244ed --- /dev/null +++ b/src/a8935cbe-7701-40dc-bfd5-675f2d600954/README.md @@ -0,0 +1,37 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# abstract class TypeHelper (Details) +> namespace: **VDM\Joomla\Utilities\String** +```uml +@startuml +abstract TypeHelper #Orange { + # static $builder + + {static} safe(String $string, String $option = null) +} + +note right of TypeHelper::safe + Making field type name safe + + since: 3.0.9 +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/a8935cbe-7701-40dc-bfd5-675f2d600954/code.php b/src/a8935cbe-7701-40dc-bfd5-675f2d600954/code.php new file mode 100644 index 0000000..bd6f1a2 --- /dev/null +++ b/src/a8935cbe-7701-40dc-bfd5-675f2d600954/code.php @@ -0,0 +1,82 @@ + + * @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\Utilities\String; + + +use Joomla\CMS\Component\ComponentHelper; +use VDM\Joomla\Utilities\StringHelper; +use VDM\Joomla\Utilities\Component\Helper; + + +/** + * Control the naming of a field type + * + * @since 3.0.9 + */ +abstract class TypeHelper +{ + /** + * The field builder switch + * + * @since 3.0.9 + */ + protected static $builder = false; + + /** + * Making field type name safe + * + * @param String $string The you would like to make safe + * @param String $option The option for the component. + * + * @returns string on success + * + * @since 3.0.9 + */ + public static function safe($string, $option = null) + { + // get global value + if (self::$builder === false) + { + self::$builder = Helper::getParams($option)->get('type_name_builder', 1); + } + + // use the new convention + if (2 == self::$builder) + { + // 0nly continue if we have a string + if (StringHelper::check($string)) + { + // check that the first character is not a number + if (is_numeric(substr($string, 0, 1))) + { + $string = StringHelper::numbers($string); + } + + // Transliterate string + $string = StringHelper::transliterate($string); + + // remove all and keep only characters and numbers and point (TODO just one point) + $string = trim(preg_replace("/[^A-Za-z0-9\.]/", '', (string) $string)); + + // best is to return lower (for all string equality in compiler) + return strtolower($string); + } + // not a string + return ''; + } + + // use the default (original behaviour/convention) + return StringHelper::safe($string); + } + +} + diff --git a/src/a8935cbe-7701-40dc-bfd5-675f2d600954/code.power b/src/a8935cbe-7701-40dc-bfd5-675f2d600954/code.power new file mode 100644 index 0000000..e3de478 --- /dev/null +++ b/src/a8935cbe-7701-40dc-bfd5-675f2d600954/code.power @@ -0,0 +1,53 @@ + /** + * The field builder switch + * + * @since 3.0.9 + */ + protected static $builder = false; + + /** + * Making field type name safe + * + * @param String $string The you would like to make safe + * @param String $option The option for the component. + * + * @returns string on success + * + * @since 3.0.9 + */ + public static function safe($string, $option = null) + { + // get global value + if (self::$builder === false) + { + self::$builder = Helper::getParams($option)->get('type_name_builder', 1); + } + + // use the new convention + if (2 == self::$builder) + { + // 0nly continue if we have a string + if (StringHelper::check($string)) + { + // check that the first character is not a number + if (is_numeric(substr($string, 0, 1))) + { + $string = StringHelper::numbers($string); + } + + // Transliterate string + $string = StringHelper::transliterate($string); + + // remove all and keep only characters and numbers and point (TODO just one point) + $string = trim(preg_replace("/[^A-Za-z0-9\.]/", '', (string) $string)); + + // best is to return lower (for all string equality in compiler) + return strtolower($string); + } + // not a string + return ''; + } + + // use the default (original behaviour/convention) + return StringHelper::safe($string); + } diff --git a/src/a8935cbe-7701-40dc-bfd5-675f2d600954/settings.json b/src/a8935cbe-7701-40dc-bfd5-675f2d600954/settings.json new file mode 100644 index 0000000..457d8f2 --- /dev/null +++ b/src/a8935cbe-7701-40dc-bfd5-675f2d600954/settings.json @@ -0,0 +1,27 @@ +{ + "add_head": "1", + "add_licensing_template": "2", + "extends": "0", + "guid": "a8935cbe-7701-40dc-bfd5-675f2d600954", + "implements": null, + "load_selection": null, + "name": "TypeHelper", + "power_version": "1.0.0", + "system_name": "String Type Helper", + "type": "abstract class", + "use_selection": { + "use_selection0": { + "use": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef", + "as": "default" + }, + "use_selection1": { + "use": "640b5352-fb09-425f-a26e-cd44eda03f15", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Utilities.String.TypeHelper", + "description": "Control the naming of a field type\r\n\r\n@since 3.0.9", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 3rd September, 2020\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": "use Joomla\\CMS\\Component\\ComponentHelper;", + "composer": "" +} \ No newline at end of file diff --git a/src/b84e947d-2a13-44f7-ac0f-3902ae55ae0c/README.md b/src/b84e947d-2a13-44f7-ac0f-3902ae55ae0c/README.md new file mode 100644 index 0000000..9f75bdf --- /dev/null +++ b/src/b84e947d-2a13-44f7-ac0f-3902ae55ae0c/README.md @@ -0,0 +1,69 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# abstract class BaseRegistry (Details) +> namespace: **VDM\Joomla\Componentbuilder\Abstraction** +```uml +@startuml +abstract BaseRegistry #Orange { + + _(string $path) : ?\ArrayIterator + + appendArray(string $path, mixed $value) : mixed + + isArray(string $path) : bool + + isString(string $path) : bool + + isNumeric(string $path) : bool +} + +note right of BaseRegistry::_ + Method to iterate over any part of the registry + + since: 3.4.0 + return: ?\ArrayIterator +end note + +note right of BaseRegistry::appendArray + Append value to a path in registry of an array + + since: 3.2.0 + return: mixed +end note + +note right of BaseRegistry::isArray + Check if a registry path exists and is an array + + since: 3.2.0 + return: bool +end note + +note right of BaseRegistry::isString + Check if a registry path exists and is a string + + since: 3.2.0 + return: bool +end note + +note right of BaseRegistry::isNumeric + Check if a registry path exists and is numeric + + 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/b84e947d-2a13-44f7-ac0f-3902ae55ae0c/code.php b/src/b84e947d-2a13-44f7-ac0f-3902ae55ae0c/code.php new file mode 100644 index 0000000..bfec409 --- /dev/null +++ b/src/b84e947d-2a13-44f7-ac0f-3902ae55ae0c/code.php @@ -0,0 +1,150 @@ + + * @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\Abstraction; + + +use Joomla\Registry\Registry as JoomlaRegistry; + + +/** + * Registry + * + * So we have full control over this class + * + * @since 3.2.0 + */ +abstract class BaseRegistry extends JoomlaRegistry implements \JsonSerializable, \ArrayAccess, \IteratorAggregate, \Countable +{ + /** + * Method to iterate over any part of the registry + * + * @param string $path Registry path (e.g. joomla.content.showauthor) + * + * @return \ArrayIterator|null This object represented as an ArrayIterator. + * + * @since 3.4.0 + */ + public function _(string $path): ?\ArrayIterator + { + $data = $this->extract($path); + + if ($data === null) + { + return null; + } + + return $data->getIterator(); + } + + /** + * Append value to a path in registry of an array + * + * @param string $path Parent registry Path (e.g. joomla.content.showauthor) + * @param mixed $value Value of entry + * + * @return mixed The value of the that has been set. + * + * @since 3.2.0 + */ + public function appendArray(string $path, $value) + { + // check if it does not exist + if (!$this->exists($path)) + { + $this->set($path, []); + } + + return $this->append($path, $value); + } + + /** + * Check if a registry path exists and is an array + * + * @param string $path Registry path (e.g. joomla.content.showauthor) + * + * @return boolean + * + * @since 3.2.0 + */ + public function isArray(string $path): bool + { + // Return default value if path is empty + if (empty($path)) { + return false; + } + + // get the value + if (($node = $this->get($path)) !== null + && is_array($node) + && $node !== []) + { + return true; + } + + return false; + } + + /** + * Check if a registry path exists and is a string + * + * @param string $path Registry path (e.g. joomla.content.showauthor) + * + * @return boolean + * + * @since 3.2.0 + */ + public function isString(string $path): bool + { + // Return default value if path is empty + if (empty($path)) { + return false; + } + + // get the value + if (($node = $this->get($path)) !== null + && is_string($node) + && strlen((string) $node) > 0) + { + return true; + } + + return false; + } + + /** + * Check if a registry path exists and is numeric + * + * @param string $path Registry path (e.g. joomla.content.showauthor) + * + * @return boolean + * + * @since 3.2.0 + */ + public function isNumeric(string $path): bool + { + // Return default value if path is empty + if (empty($path)) { + return false; + } + + // get the value + if (($node = $this->get($path)) !== null + && is_numeric($node)) + { + return true; + } + + return false; + } + +} + diff --git a/src/b84e947d-2a13-44f7-ac0f-3902ae55ae0c/code.power b/src/b84e947d-2a13-44f7-ac0f-3902ae55ae0c/code.power new file mode 100644 index 0000000..cec5eb4 --- /dev/null +++ b/src/b84e947d-2a13-44f7-ac0f-3902ae55ae0c/code.power @@ -0,0 +1,121 @@ + /** + * Method to iterate over any part of the registry + * + * @param string $path Registry path (e.g. joomla.content.showauthor) + * + * @return \ArrayIterator|null This object represented as an ArrayIterator. + * + * @since 3.4.0 + */ + public function _(string $path): ?\ArrayIterator + { + $data = $this->extract($path); + + if ($data === null) + { + return null; + } + + return $data->getIterator(); + } + + /** + * Append value to a path in registry of an array + * + * @param string $path Parent registry Path (e.g. joomla.content.showauthor) + * @param mixed $value Value of entry + * + * @return mixed The value of the that has been set. + * + * @since 3.2.0 + */ + public function appendArray(string $path, $value) + { + // check if it does not exist + if (!$this->exists($path)) + { + $this->set($path, []); + } + + return $this->append($path, $value); + } + + /** + * Check if a registry path exists and is an array + * + * @param string $path Registry path (e.g. joomla.content.showauthor) + * + * @return boolean + * + * @since 3.2.0 + */ + public function isArray(string $path): bool + { + // Return default value if path is empty + if (empty($path)) { + return false; + } + + // get the value + if (($node = $this->get($path)) !== null + && is_array($node) + && $node !== []) + { + return true; + } + + return false; + } + + /** + * Check if a registry path exists and is a string + * + * @param string $path Registry path (e.g. joomla.content.showauthor) + * + * @return boolean + * + * @since 3.2.0 + */ + public function isString(string $path): bool + { + // Return default value if path is empty + if (empty($path)) { + return false; + } + + // get the value + if (($node = $this->get($path)) !== null + && is_string($node) + && strlen((string) $node) > 0) + { + return true; + } + + return false; + } + + /** + * Check if a registry path exists and is numeric + * + * @param string $path Registry path (e.g. joomla.content.showauthor) + * + * @return boolean + * + * @since 3.2.0 + */ + public function isNumeric(string $path): bool + { + // Return default value if path is empty + if (empty($path)) { + return false; + } + + // get the value + if (($node = $this->get($path)) !== null + && is_numeric($node)) + { + return true; + } + + return false; + } diff --git a/src/b84e947d-2a13-44f7-ac0f-3902ae55ae0c/settings.json b/src/b84e947d-2a13-44f7-ac0f-3902ae55ae0c/settings.json new file mode 100644 index 0000000..2ec0afd --- /dev/null +++ b/src/b84e947d-2a13-44f7-ac0f-3902ae55ae0c/settings.json @@ -0,0 +1,22 @@ +{ + "add_head": "1", + "add_licensing_template": "2", + "extends": "-1", + "guid": "b84e947d-2a13-44f7-ac0f-3902ae55ae0c", + "implements": [ + "-1" + ], + "load_selection": null, + "name": "BaseRegistry", + "power_version": "1.0.0", + "system_name": "JCB.Abstraction.BaseRegistry", + "type": "abstract class", + "use_selection": null, + "namespace": "VDM\\Joomla\\Componentbuilder.Abstraction.BaseRegistry", + "description": "Registry\r\n\r\nSo we have full control over this class\r\n\r\n@since 3.2.0", + "implements_custom": "\\JsonSerializable, \\ArrayAccess, \\IteratorAggregate, \\Countable", + "extends_custom": "JoomlaRegistry", + "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": "use Joomla\\Registry\\Registry as JoomlaRegistry;", + "composer": "" +} \ No newline at end of file diff --git a/src/c6bbc3ee-58e7-4463-adba-5c5ae839ee36/README.md b/src/c6bbc3ee-58e7-4463-adba-5c5ae839ee36/README.md new file mode 100644 index 0000000..fbede77 --- /dev/null +++ b/src/c6bbc3ee-58e7-4463-adba-5c5ae839ee36/README.md @@ -0,0 +1,86 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# abstract class MapperSingle (Details) +> namespace: **VDM\Joomla\Componentbuilder\Abstraction** +```uml +@startuml +abstract MapperSingle #Orange { + + array $active + + isActive() : bool + + set(string $key, mixed $value) : void + + get(string $key) : mixed + + exist(string $key) : bool + + add(string $key, mixed $value) : void + + remove(string $key) : void + # {abstract} key(string $key) : string +} + +note right of MapperSingle::isActive + Check if any values are set in the active array + + since: 3.2.0 + return: bool +end note + +note right of MapperSingle::set + Set content + + since: 3.2.0 + return: void +end note + +note right of MapperSingle::get + Get content + + since: 3.2.0 + return: mixed +end note + +note right of MapperSingle::exist + Does key exist + + since: 3.2.0 + return: bool +end note + +note right of MapperSingle::add + Add content + + since: 3.2.0 + return: void +end note + +note right of MapperSingle::remove + Remove content + + since: 3.2.0 + return: void +end note + +note right of MapperSingle::key + Model the key + + since: 3.2.0 + return: string +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/c6bbc3ee-58e7-4463-adba-5c5ae839ee36/code.php b/src/c6bbc3ee-58e7-4463-adba-5c5ae839ee36/code.php new file mode 100644 index 0000000..988644f --- /dev/null +++ b/src/c6bbc3ee-58e7-4463-adba-5c5ae839ee36/code.php @@ -0,0 +1,133 @@ + + * @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\Abstraction; + + +use VDM\Joomla\Componentbuilder\Interfaces\Mappersingleinterface; + + +/** + * Compiler Mapper Single + * + * @since 3.2.0 + */ +abstract class MapperSingle implements Mappersingleinterface +{ + + /** + * The Content + * + * @var array + * @since 3.2.0 + **/ + public array $active = []; + + /** + * Check if any values are set in the active array + * + * @return bool Returns true if the active array is not empty, false otherwise + * @since 3.2.0 + */ + public function isActive(): bool + { + return !empty($this->active); + } + + /** + * Set content + * + * @param string $key The main string key + * @param mixed $value The values to set + * + * @return void + * @since 3.2.0 + */ + public function set(string $key, $value) + { + $this->active[$this->key($key)] = $value; + } + + /** + * Get content + * + * @param string $key The main string key + * + * @return mixed + * @since 3.2.0 + */ + public function get(string $key) + { + return $this->active[$this->key($key)] ?? null; + } + + /** + * Does key exist + * + * @param string $key The main string key + * + * @return bool + * @since 3.2.0 + */ + public function exist(string $key): bool + { + if (isset($this->active[$this->key($key)])) + { + return true; + } + return false; + } + + /** + * Add content + * + * @param string $key The main string key + * @param mixed $value The values to set + * + * @return void + * @since 3.2.0 + */ + public function add(string $key, $value) + { + if (isset($this->active[$this->key($key)])) + { + $this->active[$this->key($key)] .= $value; + } + else + { + $this->active[$this->key($key)] = $value; + } + } + + /** + * Remove content + * + * @param string $key The main string key + * + * @return void + * @since 3.2.0 + */ + public function remove(string $key) + { + unset($this->active[$this->key($key)]); + } + + /** + * Model the key + * + * @param string $key The key to model + * + * @return string + * @since 3.2.0 + */ + abstract protected function key(string $key): string; +} + diff --git a/src/c6bbc3ee-58e7-4463-adba-5c5ae839ee36/code.power b/src/c6bbc3ee-58e7-4463-adba-5c5ae839ee36/code.power new file mode 100644 index 0000000..918b331 --- /dev/null +++ b/src/c6bbc3ee-58e7-4463-adba-5c5ae839ee36/code.power @@ -0,0 +1 @@ +[CUSTOMCODE=abstractionMapperSingle] \ No newline at end of file diff --git a/src/c6bbc3ee-58e7-4463-adba-5c5ae839ee36/settings.json b/src/c6bbc3ee-58e7-4463-adba-5c5ae839ee36/settings.json new file mode 100644 index 0000000..ef967de --- /dev/null +++ b/src/c6bbc3ee-58e7-4463-adba-5c5ae839ee36/settings.json @@ -0,0 +1,20 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "c6bbc3ee-58e7-4463-adba-5c5ae839ee36", + "implements": [ + "78527c29-24ad-4735-ad4c-ec33a4952d9b" + ], + "load_selection": null, + "name": "MapperSingle", + "power_version": "1.0.0", + "system_name": "JCB.Abstraction.MapperSingle", + "type": "abstract class", + "use_selection": null, + "namespace": "VDM\\Joomla\\Componentbuilder.Abstraction.MapperSingle", + "description": "Compiler Mapper Single\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/cddcac51-9a46-47c4-ba59-105c70453bd6/README.md b/src/cddcac51-9a46-47c4-ba59-105c70453bd6/README.md new file mode 100644 index 0000000..0745f45 --- /dev/null +++ b/src/cddcac51-9a46-47c4-ba59-105c70453bd6/README.md @@ -0,0 +1,157 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# abstract class FilterHelper (Details) +> namespace: **VDM\Joomla\Componentbuilder\Utilities** +```uml +@startuml +abstract FilterHelper #Orange { + + {static} extensions() : string + + {static} names(string $type, ?string $limiter = null) : ?array + + {static} linked(int $id, string $method) : ?array + + {static} namespaces() : ?array + + {static} namegroup(string $namespace) : ?array + + {static} translation(int $extension, string $type) : ?array + + {static} translations($language, $translated = true) : ?array + + {static} languages() : ?array + + {static} paths(string $path) : ?array + - {static} joomla_component_admin_views(int $id) : ?array + - {static} joomla_component_custom_admin_views(int $id) : ?array + - {static} joomla_component_site_views(int $id) : ?array + - {static} joomla_component(int $id) : ?array + - {static} joomla_module(int $id) : ?array + - {static} joomla_plugin(int $id) : ?array + - {static} admin_view(int $id) : ?array +} + +note right of FilterHelper::extensions + get extensions grouped list xml + + since: 3.2.0 + return: string +end note + +note left of FilterHelper::names + Get by type the ids and system names + + since: 3.2.0 + return: ?array +end note + +note right of FilterHelper::linked + get any area linked IDs + + since: 3.2.0 + return: ?array +end note + +note left of FilterHelper::namespaces + get the substrings of the namespace until the last "\" or "." + + since: 3.2.0 + return: ?array +end note + +note right of FilterHelper::namegroup + get get IDs of powers matching namespaces + + since: 3.2.0 + return: ?array +end note + +note left of FilterHelper::translation + get translation extension ids + + since: 3.2.0 + return: ?array +end note + +note right of FilterHelper::translations + get translation ids + + since: 3.2.0 + return: ?array +end note + +note left of FilterHelper::languages + get available languages + + since: 3.2.0 + return: ?array +end note + +note right of FilterHelper::paths + get get IDs of powers link to this path + + since: 3.2.0 + return: ?array +end note + +note left of FilterHelper::joomla_component_admin_views + Get a component admin views IDs + + since: 3.2.0 + return: ?array +end note + +note right of FilterHelper::joomla_component_custom_admin_views + get a component custom admin views IDs + + since: 3.2.0 + return: ?array +end note + +note left of FilterHelper::joomla_component_site_views + get a component site views IDs + + since: 3.2.0 + return: ?array +end note + +note right of FilterHelper::joomla_component + get a component fields IDs + + since: 3.2.0 + return: ?array +end note + +note left of FilterHelper::joomla_module + get a module fields IDs + + since: 3.2.0 + return: ?array +end note + +note right of FilterHelper::joomla_plugin + get a plugin fields IDs + + since: 3.2.0 + return: ?array +end note + +note left of FilterHelper::admin_view + get an admin view fields IDs + + since: 3.2.0 + return: ?array +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/cddcac51-9a46-47c4-ba59-105c70453bd6/code.php b/src/cddcac51-9a46-47c4-ba59-105c70453bd6/code.php new file mode 100644 index 0000000..86dec4d --- /dev/null +++ b/src/cddcac51-9a46-47c4-ba59-105c70453bd6/code.php @@ -0,0 +1,814 @@ + + * @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\Utilities; + + +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; +use VDM\Joomla\Utilities\ArrayHelper; +use VDM\Joomla\Utilities\JsonHelper; +use VDM\Joomla\Utilities\GetHelper; + + +/** + * Filter Helper + * + * @since 3.2.0 + */ +abstract class FilterHelper +{ + /** + * get extensions grouped list xml + * + * @return string The XML string of Extentions + * @since 3.2.0 + */ + public static function extensions(): string + { + // the extension types + $extensions = array( + 'joomla_component' => 'COM_COMPONENTBUILDER_COMPONENT', + 'joomla_module' => 'COM_COMPONENTBUILDER_MODULE', + 'joomla_plugin' => 'COM_COMPONENTBUILDER_PLUGIN' + ); + + // get the extension values + foreach ($extensions as $extension => $label) + { + ${$extension} = self::names($extension); + } + + $xml = new \DOMDocument(); + $xml->formatOutput = true; + + $root = $xml->createElement('field'); + $root->setAttributeNode(new \DOMAttr('name', 'extension')); + $root->setAttributeNode(new \DOMAttr('type', 'groupedlist')); + $root->setAttributeNode(new \DOMAttr('onchange', 'this.form.submit();')); + + $root + ->appendChild($xml->createElement('option', '- ' . Text::_('COM_COMPONENTBUILDER_SELECT_EXTENSION') . ' -')) + ->setAttributeNode(new \DOMAttr('value', '')); + + foreach ($extensions as $extension => $label) + { + $extension_node = $xml->createElement('group'); + $extension_node->setAttributeNode(new \DOMAttr('label', $label)); + if (!ArrayHelper::check(${$extension})) + { + $extension_node + ->appendChild($xml->createElement('option', '- ' . Text::_('COM_COMPONENTBUILDER_NONE') . ' -')) + ->setAttributeNode(new \DOMAttr('disabled', 'true')); + } + else + { + foreach (${$extension} as $id => $element) + { + $extension_node + ->appendChild($xml->createElement('option', $element)) + ->setAttributeNode(new \DOMAttr('value', $extension . '__' . $id)); + } + } + $root->appendChild($extension_node); + } + $xml->appendChild($root); + + return $xml->saveXML(); + } + + /** + * Get by type the ids and system names + * + * @param string $type The table name to get system names for + * @param string|null $limiter The to limit by limiter table + * + * @return array|null The array of system name and IDs + * @since 3.2.0 + */ + public static function names(string $type, ?string $limiter = null): ?array + { + $db = Factory::getDbo(); + $query = $db->getQuery(true); + + $query + ->select($db->quoteName(array('id', 'system_name'))) + ->from($db->quoteName('#__componentbuilder_' . $type)) + ->where($db->quoteName('published') . ' >= 1') + ->order($db->quoteName('modified') . ' desc') + ->order($db->quoteName('created') . ' desc'); + + // check if we have a limiter for admin views + if ($type === 'admin_view' && $limiter) + { + // first get all views + $admin_view_ids = array(); + + // if this is a plugin or a module, then no views + if (strpos($limiter, 'joomla_component') !== false) + { + $component = (int) str_replace('joomla_component__', '', $limiter); + // get the views of this component + if ($add_views = GetHelper::var('component_admin_views', (int) $component, 'joomla_component', 'addadmin_views')) + { + if (JsonHelper::check($add_views)) + { + $add_views = json_decode($add_views, true); + if (ArrayHelper::check($add_views)) + { + foreach($add_views as $add_view) + { + if (isset($add_view['adminview'])) + { + $admin_view_ids[(int) $add_view['adminview']] = (int) $add_view['adminview']; + } + } + } + } + } + } + // now check if we still have admin views + if (ArrayHelper::check($admin_view_ids)) + { + $query->where($db->quoteName('id') . ' IN (' . implode(',', $admin_view_ids) . ')'); + } + else + { + return null; + } + } + + $db->setQuery($query); + $db->execute(); + + if ($db->getNumRows()) + { + return $db->loadAssocList('id', 'system_name'); + } + + return null; + } + + /** + * get any area linked IDs + * + * @param int $id The target ID + * @param string $method The target method + * + * @return array|null The result ids + * @since 3.2.0 + **/ + public static function linked(int $id, string $method): ?array + { + // check if method exist + if (method_exists(__CLASS__, $method)) + { + return self::{$method}($id); + } + + return null; + } + + /** + * get the substrings of the namespace until the last "\" or "." + * + * @return array|null The result substrings + * @since 3.2.0 + **/ + public static function namespaces(): ?array + { + $db = Factory::getDbo(); + $query = $db->getQuery(true); + $query + ->select( + 'DISTINCT REPLACE(SUBSTRING(' + . $db->quoteName('namespace') + . ', 1, LENGTH(' + . $db->quoteName('namespace') + . ') - LEAST(' + . 'IF(LOCATE(' + . $db->quote('\\') + . ', ' . $db->quoteName('namespace') + . ') > 0, LOCATE(' + . $db->quote('\\') + . ', REVERSE(' + . $db->quoteName('namespace') + . ')), 0), ' + . 'IF(LOCATE(' + . $db->quote('.') + . ', ' . $db->quoteName('namespace') + . ') > 0, LOCATE(' + . $db->quote('.') + . ', REVERSE(' + . $db->quoteName('namespace') + . ')), 0))), ".", "\\\") AS trimmed_namespace' + ) + ->from($db->quoteName('#__componentbuilder_power')) + ->where($db->quoteName('published') . ' = 1') + ->order('LENGTH(trimmed_namespace) ASC, trimmed_namespace ASC'); + $db->setQuery($query); + $db->execute(); + + if ($db->getNumRows()) + { + return $db->loadAssocList('trimmed_namespace', 'trimmed_namespace'); + } + + return null; + } + + /** + * get get IDs of powers matching namespaces + * + * @param string $namespace The target namespace + * + * @return array|null The result ids + * @since 3.2.0 + **/ + public static function namegroup(string $namespace): ?array + { + $db = Factory::getDbo(); + $query = $db->getQuery(true); + $query + ->select($db->quoteName(array('id'))) + ->from($db->quoteName('#__componentbuilder_power')) + ->where($db->quoteName('published') . ' = 1'); + + // we get only those that match the owner and repo (smaller set) + $paths = explode('\\', $namespace); + foreach ($paths as $path) + { + $query->where($db->quoteName('namespace') . ' REGEXP ' . $db->quote($path)); + } + + $db->setQuery($query); + $db->execute(); + + if ($db->getNumRows()) + { + return $db->loadColumn(); + } + + return null; + } + + /** + * get translation extension ids + * + * @param int $extension The target ID + * @param string $type The target method + * + * @return array|null The result ids + * @since 3.2.0 + **/ + public static function translation(int $extension, string $type): ?array + { + // only allow these columns (extension types) + $columns = array( + 'joomla_component' => 'components', + 'joomla_module' => 'modules', + 'joomla_plugin' => 'plugins' + ); + + // check if the column name is correct + if (isset($columns[$type])) + { + $column = $columns[$type]; + $db = Factory::getDbo(); + $query = $db->getQuery(true); + $query + ->select($db->quoteName(array('id', $column))) + ->from($db->quoteName('#__componentbuilder_language_translation')) + ->where($db->quoteName($column) . ' != ' . $db->quote('')); + + $db->setQuery($query); + $db->execute(); + + if ($db->getNumRows()) + { + $results = $db->loadAssocList(); + $matches = []; + foreach ($results as $k => $v) + { + $value = json_decode($v[$column], true); + if (in_array($extension, $value)) + { + $matches[$v['id']] = $v['id']; + } + } + + // Checks that we found matches + if (ArrayHelper::check($matches)) + { + return array_values($matches); + } + } + } + + return null; + } + + /** + * get translation ids + * + * @param int $id The target ID + * + * @return array|null The result ids + * @since 3.2.0 + **/ + public static function translations($language, $translated = true): ?array + { + $db = Factory::getDbo(); + $query = $db->getQuery(true); + + $query + ->select($db->quoteName('id')) + ->from($db->quoteName('#__componentbuilder_language_translation')); + + // Build the where condition + if ($translated === true) // Translated + { + if ($language === 'all') + { + if (($languages = self::languages()) !== null) + { + $wheres = []; + foreach ($languages as $k => $v) + { + $wheres[] = $db->quoteName('translation') . ' LIKE ' . $db->quote('%' . $k . '%'); + } + $query->where($wheres); + } + } + else + { + $query->where($db->quoteName('translation') . ' LIKE ' . $db->quote('%' . $language . '%')); + } + } + else // Not translated + { + if ($language === 'none') + { + $query->where( + array( + $db->quoteName('translation') . ' = ' . $db->quote(''), + $db->quoteName('translation') . ' = ' . $db->quote('[]'), + $db->quoteName('translation') . ' = ' . $db->quote('{}') + ), 'OR' + ); + } + else + { + $query->where($db->quoteName('translation') . ' NOT LIKE ' . $db->quote('%' . $language . '%')); + } + } + + $db->setQuery($query); + $db->execute(); + + if ($db->getNumRows()) + { + return array_unique($db->loadColumn()); + } + + return null; + } + + /** + * get available languages + * + * @return array|null The result ids + * @since 3.2.0 + **/ + public static function languages(): ?array + { + $db = Factory::getDbo(); + $query = $db->getQuery(true); + $query + ->select($db->quoteName(array('langtag', 'name'))) + ->from($db->quoteName('#__componentbuilder_language')) + ->where($db->quoteName('published') . ' = 1') + ->order($db->quoteName('name') . ' desc'); + $db->setQuery($query); + $db->execute(); + + if ($db->getNumRows()) + { + return $db->loadAssocList('langtag', 'name'); + } + + return null; + } + + /** + * get get IDs of powers link to this path + * + * @param string $path The target PATH + * + * @return array|null The result ids + * @since 3.2.0 + **/ + public static function paths(string $path): ?array + { + // get all this power ids + $ids = []; + + $db = Factory::getDbo(); + $query = $db->getQuery(true); + $query + ->select($db->quoteName(array('id', 'approved_paths'))) + ->from($db->quoteName('#__componentbuilder_power')) + ->where($db->quoteName('published') . ' = 1'); + + // we get only those that match the owner and repo (smaller set) + if (($pos = strpos($path, '/')) !== false) + { + $owner = substr($path, 0, $pos); + $repo = substr($path, $pos + 1); + $query + ->where($db->quoteName('approved_paths') . ' REGEXP ' . $db->quote($owner)) + ->where($db->quoteName('approved_paths') . ' REGEXP ' . $db->quote($repo)); + } + + $db->setQuery($query); + $db->execute(); + + if ($db->getNumRows()) + { + $result = $db->loadAssocList('id', 'approved_paths'); + foreach ($result as $id => $paths) + { + if (JsonHelper::check($paths)) + { + $paths = json_decode($paths, true); + if (ArrayHelper::check($paths) && in_array($path, $paths, true)) + { + $ids[$id] = $id; + } + } + } + + if (ArrayHelper::check($ids)) + { + return $ids; + } + } + + return null; + } + + /** + * Get a component admin views IDs + * + * @param int $id The target ID + * + * @return array|null The result ids + * @since 3.2.0 + */ + private static function joomla_component_admin_views(int $id): ?array + { + // get all this components views + $admin_view_ids = []; + + // get the views of this component + if ($add_views = GetHelper::var('component_admin_views', (int) $id, 'joomla_component', 'addadmin_views')) + { + if (JsonHelper::check($add_views)) + { + $add_views = json_decode($add_views, true); + if (ArrayHelper::check($add_views)) + { + foreach($add_views as $add_view) + { + if (isset($add_view['adminview'])) + { + $admin_view_ids[(int) $add_view['adminview']] = (int) $add_view['adminview']; + } + } + } + } + } + + // check that we have fields + if (ArrayHelper::check($admin_view_ids)) + { + return array_values($admin_view_ids); + } + + return null; + } + + /** + * get a component custom admin views IDs + * + * @param int $id The target ID + * + * @return array|null The result ids + * @since 3.2.0 + */ + private static function joomla_component_custom_admin_views($id): ?array + { + // get all this components views + $admin_view_ids = []; + + // get the views of this component + if ($add_views = GetHelper::var('component_custom_admin_views', (int) $id, 'joomla_component', 'addcustom_admin_views')) + { + if (JsonHelper::check($add_views)) + { + $add_views = json_decode($add_views, true); + if (ArrayHelper::check($add_views)) + { + foreach($add_views as $add_view) + { + if (isset($add_view['customadminview'])) + { + $admin_view_ids[(int) $add_view['customadminview']] = (int) $add_view['customadminview']; + } + } + } + } + } + + // check that we have fields + if (ArrayHelper::check($admin_view_ids)) + { + return array_values($admin_view_ids); + } + + return null; + } + + /** + * get a component site views IDs + * + * @param int $id The target ID + * + * @return array|null The result ids + * @since 3.2.0 + */ + private static function joomla_component_site_views($id): ?array + { + // get all this components views + $admin_view_ids = []; + + // get the views of this component + if ($add_views = GetHelper::var('component_site_views', (int) $id, 'joomla_component', 'addsite_views')) + { + if (JsonHelper::check($add_views)) + { + $add_views = json_decode($add_views, true); + if (ArrayHelper::check($add_views)) + { + foreach($add_views as $add_view) + { + if (isset($add_view['siteview'])) + { + $admin_view_ids[(int) $add_view['siteview']] = (int) $add_view['siteview']; + } + } + } + } + } + + // check that we have fields + if (ArrayHelper::check($admin_view_ids)) + { + return array_values($admin_view_ids); + } + + return null; + } + + /** + * get a component fields IDs + * + * @param int $id The target ID + * + * @return array|null The result ids + * @since 3.2.0 + */ + private static function joomla_component($id): ?array + { + // we start the field array + $field_ids = []; + + // first get all views + $admin_view_ids = []; + + // get the views of this component + if ($add_views = GetHelper::var('component_admin_views', (int) $id, 'joomla_component', 'addadmin_views')) + { + if (JsonHelper::check($add_views)) + { + $add_views = json_decode($add_views, true); + if (ArrayHelper::check($add_views)) + { + foreach($add_views as $add_view) + { + if (isset($add_view['adminview'])) + { + $admin_view_ids[(int) $add_view['adminview']] = (int) $add_view['adminview']; + } + } + } + } + } + + // check that we have views + if (ArrayHelper::check($admin_view_ids)) + { + foreach ($admin_view_ids as $admin_view) + { + // get all the fields linked to the admin view + if ($add_fields = GetHelper::var('admin_fields', (int) $admin_view, 'admin_view', 'addfields')) + { + if (JsonHelper::check($add_fields)) + { + $add_fields = json_decode($add_fields, true); + if (ArrayHelper::check($add_fields)) + { + foreach($add_fields as $add_field) + { + if (isset($add_field['field'])) + { + $field_ids[(int) $add_field['field']] = (int) $add_field['field']; + } + } + } + } + } + } + } + + // get config values + if ($add_config = GetHelper::var('component_config', (int) $id, 'joomla_component', 'addconfig')) + { + if (JsonHelper::check($add_config)) + { + $add_config = json_decode($add_config, true); + if (ArrayHelper::check($add_config)) + { + foreach($add_config as $add_conf) + { + if (isset($add_conf['field'])) + { + $field_ids[(int) $add_conf['field']] = (int) $add_conf['field']; + } + } + } + } + } + + // check that we have fields + if (ArrayHelper::check($field_ids)) + { + return array_values($field_ids); + } + + return null; + } + + /** + * get a module fields IDs + * + * @param int $id The target ID + * + * @return array|null The result ids + * @since 3.2.0 + */ + private static function joomla_module($id): ?array + { + // we start the field array + $field_ids = []; + + if ($fields = GetHelper::var('joomla_module', (int) $id, 'id', 'fields')) + { + if (JsonHelper::check($fields)) + { + $fields = json_decode($fields, true); + if (ArrayHelper::check($fields)) + { + foreach($fields as $form) + { + if (isset($form['fields']) && ArrayHelper::check($form['fields'])) + { + foreach ($form['fields'] as $field) + { + if (isset($field['field'])) + { + $field_ids[(int) $field['field']] = (int) $field['field']; + } + } + } + } + } + } + } + + // check that we have fields + if (ArrayHelper::check($field_ids)) + { + return array_values($field_ids); + } + + return null; + } + + /** + * get a plugin fields IDs + * + * @param int $id The target ID + * + * @return array|null The result ids + * @since 3.2.0 + */ + private static function joomla_plugin($id): ?array + { + // we start the field array + $field_ids = []; + + if ($fields = GetHelper::var('joomla_plugin', (int) $id, 'id', 'fields')) + { + if (JsonHelper::check($fields)) + { + $fields = json_decode($fields, true); + if (ArrayHelper::check($fields)) + { + foreach($fields as $form) + { + if (isset($form['fields']) && ArrayHelper::check($form['fields'])) + { + foreach ($form['fields'] as $field) + { + if (isset($field['field'])) + { + $field_ids[(int) $field['field']] = (int) $field['field']; + } + } + } + } + } + } + } + + // check that we have fields + if (ArrayHelper::check($field_ids)) + { + return array_values($field_ids); + } + + return null; + } + + /** + * get an admin view fields IDs + * + * @param int $id The target ID + * + * @return array|null The result ids + * @since 3.2.0 + */ + private static function admin_view($id): ?array + { + // we start the field array + $field_ids = []; + + // get all the fields linked to the admin view + if ($add_fields = GetHelper::var('admin_fields', (int) $id, 'admin_view', 'addfields')) + { + if (JsonHelper::check($add_fields)) + { + $add_fields = json_decode($add_fields, true); + if (ArrayHelper::check($add_fields)) + { + foreach($add_fields as $add_field) + { + if (isset($add_field['field'])) + { + $field_ids[(int) $add_field['field']] = (int) $add_field['field']; + } + } + } + } + } + + // check that we have fields + if (ArrayHelper::check($field_ids)) + { + return array_values($field_ids); + } + + return null; + } + +} + diff --git a/src/cddcac51-9a46-47c4-ba59-105c70453bd6/code.power b/src/cddcac51-9a46-47c4-ba59-105c70453bd6/code.power new file mode 100644 index 0000000..7c565d5 --- /dev/null +++ b/src/cddcac51-9a46-47c4-ba59-105c70453bd6/code.power @@ -0,0 +1,783 @@ + /** + * get extensions grouped list xml + * + * @return string The XML string of Extentions + * @since 3.2.0 + */ + public static function extensions(): string + { + // the extension types + $extensions = array( + 'joomla_component' => JustTEXT::_('Component'), + 'joomla_module' => JustTEXT::_('Module'), + 'joomla_plugin' => JustTEXT::_('Plugin') + ); + + // get the extension values + foreach ($extensions as $extension => $label) + { + ${$extension} = self::names($extension); + } + + $xml = new \DOMDocument(); + $xml->formatOutput = true; + + $root = $xml->createElement('field'); + $root->setAttributeNode(new \DOMAttr('name', 'extension')); + $root->setAttributeNode(new \DOMAttr('type', 'groupedlist')); + $root->setAttributeNode(new \DOMAttr('onchange', 'this.form.submit();')); + + $root + ->appendChild($xml->createElement('option', '- ' . Text::_('Select Extension') . ' -')) + ->setAttributeNode(new \DOMAttr('value', '')); + + foreach ($extensions as $extension => $label) + { + $extension_node = $xml->createElement('group'); + $extension_node->setAttributeNode(new \DOMAttr('label', $label)); + if (!ArrayHelper::check(${$extension})) + { + $extension_node + ->appendChild($xml->createElement('option', '- ' . Text::_('None') . ' -')) + ->setAttributeNode(new \DOMAttr('disabled', 'true')); + } + else + { + foreach (${$extension} as $id => $element) + { + $extension_node + ->appendChild($xml->createElement('option', $element)) + ->setAttributeNode(new \DOMAttr('value', $extension . '__' . $id)); + } + } + $root->appendChild($extension_node); + } + $xml->appendChild($root); + + return $xml->saveXML(); + } + + /** + * Get by type the ids and system names + * + * @param string $type The table name to get system names for + * @param string|null $limiter The to limit by limiter table + * + * @return array|null The array of system name and IDs + * @since 3.2.0 + */ + public static function names(string $type, ?string $limiter = null): ?array + { + $db = Factory::getDbo(); + $query = $db->getQuery(true); + + $query + ->select($db->quoteName(array('id', 'system_name'))) + ->from($db->quoteName('#__componentbuilder_' . $type)) + ->where($db->quoteName('published') . ' >= 1') + ->order($db->quoteName('modified') . ' desc') + ->order($db->quoteName('created') . ' desc'); + + // check if we have a limiter for admin views + if ($type === 'admin_view' && $limiter) + { + // first get all views + $admin_view_ids = array(); + + // if this is a plugin or a module, then no views + if (strpos($limiter, 'joomla_component') !== false) + { + $component = (int) str_replace('joomla_component__', '', $limiter); + // get the views of this component + if ($add_views = GetHelper::var('component_admin_views', (int) $component, 'joomla_component', 'addadmin_views')) + { + if (JsonHelper::check($add_views)) + { + $add_views = json_decode($add_views, true); + if (ArrayHelper::check($add_views)) + { + foreach($add_views as $add_view) + { + if (isset($add_view['adminview'])) + { + $admin_view_ids[(int) $add_view['adminview']] = (int) $add_view['adminview']; + } + } + } + } + } + } + // now check if we still have admin views + if (ArrayHelper::check($admin_view_ids)) + { + $query->where($db->quoteName('id') . ' IN (' . implode(',', $admin_view_ids) . ')'); + } + else + { + return null; + } + } + + $db->setQuery($query); + $db->execute(); + + if ($db->getNumRows()) + { + return $db->loadAssocList('id', 'system_name'); + } + + return null; + } + + /** + * get any area linked IDs + * + * @param int $id The target ID + * @param string $method The target method + * + * @return array|null The result ids + * @since 3.2.0 + **/ + public static function linked(int $id, string $method): ?array + { + // check if method exist + if (method_exists(__CLASS__, $method)) + { + return self::{$method}($id); + } + + return null; + } + + /** + * get the substrings of the namespace until the last "\" or "." + * + * @return array|null The result substrings + * @since 3.2.0 + **/ + public static function namespaces(): ?array + { + $db = Factory::getDbo(); + $query = $db->getQuery(true); + $query + ->select( + 'DISTINCT REPLACE(SUBSTRING(' + . $db->quoteName('namespace') + . ', 1, LENGTH(' + . $db->quoteName('namespace') + . ') - LEAST(' + . 'IF(LOCATE(' + . $db->quote('\\') + . ', ' . $db->quoteName('namespace') + . ') > 0, LOCATE(' + . $db->quote('\\') + . ', REVERSE(' + . $db->quoteName('namespace') + . ')), 0), ' + . 'IF(LOCATE(' + . $db->quote('.') + . ', ' . $db->quoteName('namespace') + . ') > 0, LOCATE(' + . $db->quote('.') + . ', REVERSE(' + . $db->quoteName('namespace') + . ')), 0))), ".", "\\\") AS trimmed_namespace' + ) + ->from($db->quoteName('#__componentbuilder_power')) + ->where($db->quoteName('published') . ' = 1') + ->order('LENGTH(trimmed_namespace) ASC, trimmed_namespace ASC'); + $db->setQuery($query); + $db->execute(); + + if ($db->getNumRows()) + { + return $db->loadAssocList('trimmed_namespace', 'trimmed_namespace'); + } + + return null; + } + + /** + * get get IDs of powers matching namespaces + * + * @param string $namespace The target namespace + * + * @return array|null The result ids + * @since 3.2.0 + **/ + public static function namegroup(string $namespace): ?array + { + $db = Factory::getDbo(); + $query = $db->getQuery(true); + $query + ->select($db->quoteName(array('id'))) + ->from($db->quoteName('#__componentbuilder_power')) + ->where($db->quoteName('published') . ' = 1'); + + // we get only those that match the owner and repo (smaller set) + $paths = explode('\\', $namespace); + foreach ($paths as $path) + { + $query->where($db->quoteName('namespace') . ' REGEXP ' . $db->quote($path)); + } + + $db->setQuery($query); + $db->execute(); + + if ($db->getNumRows()) + { + return $db->loadColumn(); + } + + return null; + } + + /** + * get translation extension ids + * + * @param int $extension The target ID + * @param string $type The target method + * + * @return array|null The result ids + * @since 3.2.0 + **/ + public static function translation(int $extension, string $type): ?array + { + // only allow these columns (extension types) + $columns = array( + 'joomla_component' => 'components', + 'joomla_module' => 'modules', + 'joomla_plugin' => 'plugins' + ); + + // check if the column name is correct + if (isset($columns[$type])) + { + $column = $columns[$type]; + $db = Factory::getDbo(); + $query = $db->getQuery(true); + $query + ->select($db->quoteName(array('id', $column))) + ->from($db->quoteName('#__componentbuilder_language_translation')) + ->where($db->quoteName($column) . ' != ' . $db->quote('')); + + $db->setQuery($query); + $db->execute(); + + if ($db->getNumRows()) + { + $results = $db->loadAssocList(); + $matches = []; + foreach ($results as $k => $v) + { + $value = json_decode($v[$column], true); + if (in_array($extension, $value)) + { + $matches[$v['id']] = $v['id']; + } + } + + // Checks that we found matches + if (ArrayHelper::check($matches)) + { + return array_values($matches); + } + } + } + + return null; + } + + /** + * get translation ids + * + * @param int $id The target ID + * + * @return array|null The result ids + * @since 3.2.0 + **/ + public static function translations($language, $translated = true): ?array + { + $db = Factory::getDbo(); + $query = $db->getQuery(true); + + $query + ->select($db->quoteName('id')) + ->from($db->quoteName('#__componentbuilder_language_translation')); + + // Build the where condition + if ($translated === true) // Translated + { + if ($language === 'all') + { + if (($languages = self::languages()) !== null) + { + $wheres = []; + foreach ($languages as $k => $v) + { + $wheres[] = $db->quoteName('translation') . ' LIKE ' . $db->quote('%' . $k . '%'); + } + $query->where($wheres); + } + } + else + { + $query->where($db->quoteName('translation') . ' LIKE ' . $db->quote('%' . $language . '%')); + } + } + else // Not translated + { + if ($language === 'none') + { + $query->where( + array( + $db->quoteName('translation') . ' = ' . $db->quote(''), + $db->quoteName('translation') . ' = ' . $db->quote('[]'), + $db->quoteName('translation') . ' = ' . $db->quote('{}') + ), 'OR' + ); + } + else + { + $query->where($db->quoteName('translation') . ' NOT LIKE ' . $db->quote('%' . $language . '%')); + } + } + + $db->setQuery($query); + $db->execute(); + + if ($db->getNumRows()) + { + return array_unique($db->loadColumn()); + } + + return null; + } + + /** + * get available languages + * + * @return array|null The result ids + * @since 3.2.0 + **/ + public static function languages(): ?array + { + $db = Factory::getDbo(); + $query = $db->getQuery(true); + $query + ->select($db->quoteName(array('langtag', 'name'))) + ->from($db->quoteName('#__componentbuilder_language')) + ->where($db->quoteName('published') . ' = 1') + ->order($db->quoteName('name') . ' desc'); + $db->setQuery($query); + $db->execute(); + + if ($db->getNumRows()) + { + return $db->loadAssocList('langtag', 'name'); + } + + return null; + } + + /** + * get get IDs of powers link to this path + * + * @param string $path The target PATH + * + * @return array|null The result ids + * @since 3.2.0 + **/ + public static function paths(string $path): ?array + { + // get all this power ids + $ids = []; + + $db = Factory::getDbo(); + $query = $db->getQuery(true); + $query + ->select($db->quoteName(array('id', 'approved_paths'))) + ->from($db->quoteName('#__componentbuilder_power')) + ->where($db->quoteName('published') . ' = 1'); + + // we get only those that match the owner and repo (smaller set) + if (($pos = strpos($path, '/')) !== false) + { + $owner = substr($path, 0, $pos); + $repo = substr($path, $pos + 1); + $query + ->where($db->quoteName('approved_paths') . ' REGEXP ' . $db->quote($owner)) + ->where($db->quoteName('approved_paths') . ' REGEXP ' . $db->quote($repo)); + } + + $db->setQuery($query); + $db->execute(); + + if ($db->getNumRows()) + { + $result = $db->loadAssocList('id', 'approved_paths'); + foreach ($result as $id => $paths) + { + if (JsonHelper::check($paths)) + { + $paths = json_decode($paths, true); + if (ArrayHelper::check($paths) && in_array($path, $paths, true)) + { + $ids[$id] = $id; + } + } + } + + if (ArrayHelper::check($ids)) + { + return $ids; + } + } + + return null; + } + + /** + * Get a component admin views IDs + * + * @param int $id The target ID + * + * @return array|null The result ids + * @since 3.2.0 + */ + private static function joomla_component_admin_views(int $id): ?array + { + // get all this components views + $admin_view_ids = []; + + // get the views of this component + if ($add_views = GetHelper::var('component_admin_views', (int) $id, 'joomla_component', 'addadmin_views')) + { + if (JsonHelper::check($add_views)) + { + $add_views = json_decode($add_views, true); + if (ArrayHelper::check($add_views)) + { + foreach($add_views as $add_view) + { + if (isset($add_view['adminview'])) + { + $admin_view_ids[(int) $add_view['adminview']] = (int) $add_view['adminview']; + } + } + } + } + } + + // check that we have fields + if (ArrayHelper::check($admin_view_ids)) + { + return array_values($admin_view_ids); + } + + return null; + } + + /** + * get a component custom admin views IDs + * + * @param int $id The target ID + * + * @return array|null The result ids + * @since 3.2.0 + */ + private static function joomla_component_custom_admin_views($id): ?array + { + // get all this components views + $admin_view_ids = []; + + // get the views of this component + if ($add_views = GetHelper::var('component_custom_admin_views', (int) $id, 'joomla_component', 'addcustom_admin_views')) + { + if (JsonHelper::check($add_views)) + { + $add_views = json_decode($add_views, true); + if (ArrayHelper::check($add_views)) + { + foreach($add_views as $add_view) + { + if (isset($add_view['customadminview'])) + { + $admin_view_ids[(int) $add_view['customadminview']] = (int) $add_view['customadminview']; + } + } + } + } + } + + // check that we have fields + if (ArrayHelper::check($admin_view_ids)) + { + return array_values($admin_view_ids); + } + + return null; + } + + /** + * get a component site views IDs + * + * @param int $id The target ID + * + * @return array|null The result ids + * @since 3.2.0 + */ + private static function joomla_component_site_views($id): ?array + { + // get all this components views + $admin_view_ids = []; + + // get the views of this component + if ($add_views = GetHelper::var('component_site_views', (int) $id, 'joomla_component', 'addsite_views')) + { + if (JsonHelper::check($add_views)) + { + $add_views = json_decode($add_views, true); + if (ArrayHelper::check($add_views)) + { + foreach($add_views as $add_view) + { + if (isset($add_view['siteview'])) + { + $admin_view_ids[(int) $add_view['siteview']] = (int) $add_view['siteview']; + } + } + } + } + } + + // check that we have fields + if (ArrayHelper::check($admin_view_ids)) + { + return array_values($admin_view_ids); + } + + return null; + } + + /** + * get a component fields IDs + * + * @param int $id The target ID + * + * @return array|null The result ids + * @since 3.2.0 + */ + private static function joomla_component($id): ?array + { + // we start the field array + $field_ids = []; + + // first get all views + $admin_view_ids = []; + + // get the views of this component + if ($add_views = GetHelper::var('component_admin_views', (int) $id, 'joomla_component', 'addadmin_views')) + { + if (JsonHelper::check($add_views)) + { + $add_views = json_decode($add_views, true); + if (ArrayHelper::check($add_views)) + { + foreach($add_views as $add_view) + { + if (isset($add_view['adminview'])) + { + $admin_view_ids[(int) $add_view['adminview']] = (int) $add_view['adminview']; + } + } + } + } + } + + // check that we have views + if (ArrayHelper::check($admin_view_ids)) + { + foreach ($admin_view_ids as $admin_view) + { + // get all the fields linked to the admin view + if ($add_fields = GetHelper::var('admin_fields', (int) $admin_view, 'admin_view', 'addfields')) + { + if (JsonHelper::check($add_fields)) + { + $add_fields = json_decode($add_fields, true); + if (ArrayHelper::check($add_fields)) + { + foreach($add_fields as $add_field) + { + if (isset($add_field['field'])) + { + $field_ids[(int) $add_field['field']] = (int) $add_field['field']; + } + } + } + } + } + } + } + + // get config values + if ($add_config = GetHelper::var('component_config', (int) $id, 'joomla_component', 'addconfig')) + { + if (JsonHelper::check($add_config)) + { + $add_config = json_decode($add_config, true); + if (ArrayHelper::check($add_config)) + { + foreach($add_config as $add_conf) + { + if (isset($add_conf['field'])) + { + $field_ids[(int) $add_conf['field']] = (int) $add_conf['field']; + } + } + } + } + } + + // check that we have fields + if (ArrayHelper::check($field_ids)) + { + return array_values($field_ids); + } + + return null; + } + + /** + * get a module fields IDs + * + * @param int $id The target ID + * + * @return array|null The result ids + * @since 3.2.0 + */ + private static function joomla_module($id): ?array + { + // we start the field array + $field_ids = []; + + if ($fields = GetHelper::var('joomla_module', (int) $id, 'id', 'fields')) + { + if (JsonHelper::check($fields)) + { + $fields = json_decode($fields, true); + if (ArrayHelper::check($fields)) + { + foreach($fields as $form) + { + if (isset($form['fields']) && ArrayHelper::check($form['fields'])) + { + foreach ($form['fields'] as $field) + { + if (isset($field['field'])) + { + $field_ids[(int) $field['field']] = (int) $field['field']; + } + } + } + } + } + } + } + + // check that we have fields + if (ArrayHelper::check($field_ids)) + { + return array_values($field_ids); + } + + return null; + } + + /** + * get a plugin fields IDs + * + * @param int $id The target ID + * + * @return array|null The result ids + * @since 3.2.0 + */ + private static function joomla_plugin($id): ?array + { + // we start the field array + $field_ids = []; + + if ($fields = GetHelper::var('joomla_plugin', (int) $id, 'id', 'fields')) + { + if (JsonHelper::check($fields)) + { + $fields = json_decode($fields, true); + if (ArrayHelper::check($fields)) + { + foreach($fields as $form) + { + if (isset($form['fields']) && ArrayHelper::check($form['fields'])) + { + foreach ($form['fields'] as $field) + { + if (isset($field['field'])) + { + $field_ids[(int) $field['field']] = (int) $field['field']; + } + } + } + } + } + } + } + + // check that we have fields + if (ArrayHelper::check($field_ids)) + { + return array_values($field_ids); + } + + return null; + } + + /** + * get an admin view fields IDs + * + * @param int $id The target ID + * + * @return array|null The result ids + * @since 3.2.0 + */ + private static function admin_view($id): ?array + { + // we start the field array + $field_ids = []; + + // get all the fields linked to the admin view + if ($add_fields = GetHelper::var('admin_fields', (int) $id, 'admin_view', 'addfields')) + { + if (JsonHelper::check($add_fields)) + { + $add_fields = json_decode($add_fields, true); + if (ArrayHelper::check($add_fields)) + { + foreach($add_fields as $add_field) + { + if (isset($add_field['field'])) + { + $field_ids[(int) $add_field['field']] = (int) $add_field['field']; + } + } + } + } + } + + // check that we have fields + if (ArrayHelper::check($field_ids)) + { + return array_values($field_ids); + } + + return null; + } diff --git a/src/cddcac51-9a46-47c4-ba59-105c70453bd6/settings.json b/src/cddcac51-9a46-47c4-ba59-105c70453bd6/settings.json new file mode 100644 index 0000000..0366781 --- /dev/null +++ b/src/cddcac51-9a46-47c4-ba59-105c70453bd6/settings.json @@ -0,0 +1,31 @@ +{ + "add_head": "1", + "add_licensing_template": "2", + "extends": "0", + "guid": "cddcac51-9a46-47c4-ba59-105c70453bd6", + "implements": null, + "load_selection": null, + "name": "FilterHelper", + "power_version": "1.0.0", + "system_name": "JCB.Utilities.FilterHelper", + "type": "abstract class", + "use_selection": { + "use_selection0": { + "use": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a", + "as": "default" + }, + "use_selection1": { + "use": "4b225c51-d293-48e4-b3f6-5136cf5c3f18", + "as": "default" + }, + "use_selection2": { + "use": "db87c339-5bb6-4291-a7ef-2c48ea1b06bc", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Utilities.FilterHelper", + "description": "Filter Helper\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": "use Joomla\\CMS\\Factory;\r\nuse Joomla\\CMS\\Language\\Text;", + "composer": "" +} \ No newline at end of file diff --git a/src/ce8cf834-6bac-44fb-941c-861f7e046cc0/README.md b/src/ce8cf834-6bac-44fb-941c-861f7e046cc0/README.md new file mode 100644 index 0000000..214f965 --- /dev/null +++ b/src/ce8cf834-6bac-44fb-941c-861f7e046cc0/README.md @@ -0,0 +1,37 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# abstract class NamespaceHelper (Details) +> namespace: **VDM\Joomla\Utilities\String** +```uml +@startuml +abstract NamespaceHelper #Orange { + + {static} safe(string $string, bool $removeNumbers = true) : string +} + +note right of NamespaceHelper::safe + Making namespace safe + + since: 3.0.9 + return: string +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/ce8cf834-6bac-44fb-941c-861f7e046cc0/code.php b/src/ce8cf834-6bac-44fb-941c-861f7e046cc0/code.php new file mode 100644 index 0000000..3ef176b --- /dev/null +++ b/src/ce8cf834-6bac-44fb-941c-861f7e046cc0/code.php @@ -0,0 +1,71 @@ + + * @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\Utilities\String; + + +use VDM\Joomla\Utilities\StringHelper; + + +/** + * Control the naming of a namespace helper + * + * @since 3.0.9 + */ +abstract class NamespaceHelper +{ + /** + * Making namespace safe + * + * @input string $string The you would like to make safe + * @input bool $removeNumbers The switch to remove numbers + * + * @returns string on success + * + * @since 3.0.9 + */ + public static function safe(string $string, bool $removeNumbers = true): string + { + // 0nly continue if we have a string with length + if (StringHelper::check($string)) + { + // make sure it has not numbers + if ($removeNumbers) + { + $string = StringHelper::numbers($string); + } + + // Transliterate string TODO: look again as this makes it lowercase + // $string = StringHelper::transliterate($string); + + // first remove all [\] backslashes + $string = str_replace('\\', '+', (string) $string); + + // remove all and keep only characters and [\] backslashes inside of the string + if ($removeNumbers) + { + $string = trim( preg_replace("/[^A-Za-z\+]/", '', $string), '+'); + } + else + { + $string = trim( preg_replace("/[^A-Za-z0-9\+]/", '', $string), '+'); + } + + // place the [\] backslashes back + return trim( preg_replace("/\++/", '\\', $string)); + } + + // not a string + return ''; + } + +} + diff --git a/src/ce8cf834-6bac-44fb-941c-861f7e046cc0/code.power b/src/ce8cf834-6bac-44fb-941c-861f7e046cc0/code.power new file mode 100644 index 0000000..df96e04 --- /dev/null +++ b/src/ce8cf834-6bac-44fb-941c-861f7e046cc0/code.power @@ -0,0 +1,44 @@ + /** + * Making namespace safe + * + * @input string $string The you would like to make safe + * @input bool $removeNumbers The switch to remove numbers + * + * @returns string on success + * + * @since 3.0.9 + */ + public static function safe(string $string, bool $removeNumbers = true): string + { + // 0nly continue if we have a string with length + if (StringHelper::check($string)) + { + // make sure it has not numbers + if ($removeNumbers) + { + $string = StringHelper::numbers($string); + } + + // Transliterate string TODO: look again as this makes it lowercase + // $string = StringHelper::transliterate($string); + + // first remove all [\] backslashes + $string = str_replace('\\', '+', (string) $string); + + // remove all and keep only characters and [\] backslashes inside of the string + if ($removeNumbers) + { + $string = trim( preg_replace("/[^A-Za-z\+]/", '', $string), '+'); + } + else + { + $string = trim( preg_replace("/[^A-Za-z0-9\+]/", '', $string), '+'); + } + + // place the [\] backslashes back + return trim( preg_replace("/\++/", '\\', $string)); + } + + // not a string + return ''; + } diff --git a/src/ce8cf834-6bac-44fb-941c-861f7e046cc0/settings.json b/src/ce8cf834-6bac-44fb-941c-861f7e046cc0/settings.json new file mode 100644 index 0000000..c504c3b --- /dev/null +++ b/src/ce8cf834-6bac-44fb-941c-861f7e046cc0/settings.json @@ -0,0 +1,23 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "ce8cf834-6bac-44fb-941c-861f7e046cc0", + "implements": null, + "load_selection": null, + "name": "NamespaceHelper", + "power_version": "1.0.0", + "system_name": "String Namespace Helper", + "type": "abstract class", + "use_selection": { + "use_selection0": { + "use": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Utilities.String.NamespaceHelper", + "description": "Control the naming of a namespace helper\r\n\r\n@since 3.0.9", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 3rd September, 2020\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/db87c339-5bb6-4291-a7ef-2c48ea1b06bc/code.power b/src/db87c339-5bb6-4291-a7ef-2c48ea1b06bc/code.power new file mode 100644 index 0000000..57b70ca --- /dev/null +++ b/src/db87c339-5bb6-4291-a7ef-2c48ea1b06bc/code.power @@ -0,0 +1,225 @@ + /** + * Get a Variable + * + * @param string|null $table The table from which to get the variable + * @param mixed $where The value where + * @param string $whereString The target/field string where/name + * @param string $what The return field + * @param string $operator The operator between $whereString/field and $where/value + * @param string $main The component in which the table is found + * + * @return mixed string/int/float + * @since 3.0.9 + */ + public static function var(?string $table = null, $where = null, + string $whereString = 'user', string $what = 'id', + string $operator = '=', ?string $main = null) + { + if(empty($where)) + { + $where = Factory::getUser()->id; + } + + if(empty($main)) + { + $main = Helper::getCode(); + } + + // Get a db connection. + $db = Factory::getDbo(); + + // Create a new query object. + $query = $db->getQuery(true); + $query->select($db->quoteName(array($what))); + + if (empty($table)) + { + $query->from($db->quoteName('#__' . $main)); + } + else + { + $query->from($db->quoteName('#__' . $main . '_' . $table)); + } + + if (is_numeric($where)) + { + $query->where($db->quoteName($whereString) . ' ' . $operator . ' ' . (int) $where); + } + elseif (is_string($where)) + { + $query->where($db->quoteName($whereString) . ' ' . $operator . ' ' . $db->quote((string)$where)); + } + else + { + return false; + } + + $db->setQuery($query); + $db->execute(); + + if ($db->getNumRows()) + { + return $db->loadResult(); + } + + return false; + } + + /** + * Get array of variables + * + * @param string|null $table The table from which to get the variables + * @param mixed $where The value where + * @param string $whereString The target/field string where/name + * @param string $what The return field + * @param string $operator The operator between $whereString/field and $where/value + * @param string $main The component in which the table is found + * @param bool $unique The switch to return a unique array + * + * @return array|null + * @since 3.0.9 + */ + public static function vars(?string $table = null, $where = null, + string $whereString = 'user', string $what = 'id', string $operator = 'IN', + ?string $main = null, bool $unique = true): ?array + { + if(empty($where)) + { + $where = Factory::getUser()->id; + } + + if(is_null($main)) + { + $main = Helper::getCode(); + } + + if (!ArrayHelper::check($where) && $where > 0) + { + $where = array($where); + } + + if (ArrayHelper::check($where)) + { + // prep main <-- why? well if $main='' is empty then $table can be categories or users + if (StringHelper::check($main)) + { + $main = '_' . ltrim($main, '_'); + } + + // Get a db connection. + $db = Factory::getDbo(); + + // Create a new query object. + $query = $db->getQuery(true); + $query->select($db->quoteName(array($what))); + + if (empty($table)) + { + $query->from($db->quoteName('#__' . $main)); + } + else + { + $query->from($db->quoteName('#_' . $main . '_' . $table)); + } + + // add strings to array search + if ('IN_STRINGS' === $operator || 'NOT IN_STRINGS' === $operator) + { + $query->where($db->quoteName($whereString) . ' ' . str_replace('_STRINGS', '', $operator) . ' ("' . implode('","', $where) . '")'); + } + else + { + $query->where($db->quoteName($whereString) . ' ' . $operator . ' (' . implode(',', $where) . ')'); + } + + $db->setQuery($query); + $db->execute(); + + if ($db->getNumRows()) + { + if ($unique) + { + return array_unique($db->loadColumn()); + } + return $db->loadColumn(); + } + } + + return null; + } + + /** + * get all strings between two other strings + * + * @param string $content The content to search + * @param string $start The starting value + * @param string $end The ending value + * + * @return array|null On success + * @since 3.0.9 + */ + public static function allBetween(string $content, string $start, string $end): ?array + { + // reset bucket + $bucket = []; + for ($i = 0; ; $i++) + { + // search for string + $found = self::between($content, $start, $end); + + if (StringHelper::check($found)) + { + // add to bucket + $bucket[] = $found; + + // build removal string + $remove = $start . $found . $end; + + // remove from content + $content = str_replace($remove, '', $content); + } + else + { + break; + } + + // safety catch + if ($i == 500) + { + break; + } + } + + // only return unique array of values + if (ArrayHelper::check($bucket)) + { + return array_unique($bucket); + } + + return null; + } + + /** + * get a string between two other strings + * + * @param string $content The content to search + * @param string $start The starting value + * @param string $end The ending value + * @param string $default The default value if none found + * + * @return string On success / empty string on failure + * @since 3.0.9 + */ + public static function between(string $content, string $start, string $end, string $default = ''): string + { + $array = explode($start, $content); + if (isset($array[1]) && strpos($array[1], $end) !== false) + { + $array = explode($end, $array[1]); + + // return string found between + return $array[0]; + } + + return $default; + } diff --git a/src/db87c339-5bb6-4291-a7ef-2c48ea1b06bc/settings.json b/src/db87c339-5bb6-4291-a7ef-2c48ea1b06bc/settings.json index 057c64d..0c84f92 100644 --- a/src/db87c339-5bb6-4291-a7ef-2c48ea1b06bc/settings.json +++ b/src/db87c339-5bb6-4291-a7ef-2c48ea1b06bc/settings.json @@ -1,10 +1,9 @@ { "add_head": "1", + "add_licensing_template": "2", "extends": "0", - "extends_custom": "", "guid": "db87c339-5bb6-4291-a7ef-2c48ea1b06bc", "implements": null, - "implements_custom": "", "load_selection": { "load_selection0": { "load": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a" @@ -25,5 +24,7 @@ }, "namespace": "VDM\\Joomla\\Utilities.GetHelper", "description": "Some easy get...\r\n\r\n@since 3.0.9", - "head": "use Joomla\\CMS\\Factory;" + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 3rd September, 2020\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": "use Joomla\\CMS\\Factory;", + "composer": "" } \ No newline at end of file diff --git a/super-powers.json b/super-powers.json index efee3a5..b998d6a 100644 --- a/super-powers.json +++ b/super-powers.json @@ -4,6 +4,7 @@ "type": "abstract class", "namespace": "VDM\\Joomla\\Utilities", "code": "src\/0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a\/code.php", + "power": "src\/0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a\/code.power", "settings": "src\/0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a\/settings.json", "path": "src\/0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a", "guid": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a" @@ -13,6 +14,7 @@ "type": "abstract class", "namespace": "VDM\\Joomla\\Utilities\\Component", "code": "src\/640b5352-fb09-425f-a26e-cd44eda03f15\/code.php", + "power": "src\/640b5352-fb09-425f-a26e-cd44eda03f15\/code.power", "settings": "src\/640b5352-fb09-425f-a26e-cd44eda03f15\/settings.json", "path": "src\/640b5352-fb09-425f-a26e-cd44eda03f15", "guid": "640b5352-fb09-425f-a26e-cd44eda03f15" @@ -22,6 +24,7 @@ "type": "abstract class", "namespace": "VDM\\Joomla\\Utilities", "code": "src\/1f28cb53-60d9-4db1-b517-3c7dc6b429ef\/code.php", + "power": "src\/1f28cb53-60d9-4db1-b517-3c7dc6b429ef\/code.power", "settings": "src\/1f28cb53-60d9-4db1-b517-3c7dc6b429ef\/settings.json", "path": "src\/1f28cb53-60d9-4db1-b517-3c7dc6b429ef", "guid": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef" @@ -31,6 +34,7 @@ "type": "abstract class", "namespace": "VDM\\Joomla\\Utilities", "code": "src\/db87c339-5bb6-4291-a7ef-2c48ea1b06bc\/code.php", + "power": "src\/db87c339-5bb6-4291-a7ef-2c48ea1b06bc\/code.power", "settings": "src\/db87c339-5bb6-4291-a7ef-2c48ea1b06bc\/settings.json", "path": "src\/db87c339-5bb6-4291-a7ef-2c48ea1b06bc", "guid": "db87c339-5bb6-4291-a7ef-2c48ea1b06bc" @@ -40,6 +44,7 @@ "type": "abstract class", "namespace": "VDM\\Joomla\\Utilities", "code": "src\/4b225c51-d293-48e4-b3f6-5136cf5c3f18\/code.php", + "power": "src\/4b225c51-d293-48e4-b3f6-5136cf5c3f18\/code.power", "settings": "src\/4b225c51-d293-48e4-b3f6-5136cf5c3f18\/settings.json", "path": "src\/4b225c51-d293-48e4-b3f6-5136cf5c3f18", "guid": "4b225c51-d293-48e4-b3f6-5136cf5c3f18" @@ -49,6 +54,7 @@ "type": "abstract class", "namespace": "VDM\\Joomla\\Utilities", "code": "src\/91004529-94a9-4590-b842-e7c6b624ecf5\/code.php", + "power": "src\/91004529-94a9-4590-b842-e7c6b624ecf5\/code.power", "settings": "src\/91004529-94a9-4590-b842-e7c6b624ecf5\/settings.json", "path": "src\/91004529-94a9-4590-b842-e7c6b624ecf5", "guid": "91004529-94a9-4590-b842-e7c6b624ecf5" @@ -58,6 +64,7 @@ "type": "abstract class", "namespace": "VDM\\Joomla\\Utilities", "code": "src\/152c8793-8b75-4715-996a-257b9f65451c\/code.php", + "power": "src\/152c8793-8b75-4715-996a-257b9f65451c\/code.power", "settings": "src\/152c8793-8b75-4715-996a-257b9f65451c\/settings.json", "path": "src\/152c8793-8b75-4715-996a-257b9f65451c", "guid": "152c8793-8b75-4715-996a-257b9f65451c" @@ -67,6 +74,7 @@ "type": "abstract class", "namespace": "VDM\\Joomla\\Utilities", "code": "src\/9c513baf-b279-43fd-ae29-a585c8cbc4f0\/code.php", + "power": "src\/9c513baf-b279-43fd-ae29-a585c8cbc4f0\/code.power", "settings": "src\/9c513baf-b279-43fd-ae29-a585c8cbc4f0\/settings.json", "path": "src\/9c513baf-b279-43fd-ae29-a585c8cbc4f0", "guid": "9c513baf-b279-43fd-ae29-a585c8cbc4f0" @@ -76,17 +84,179 @@ "type": "abstract class", "namespace": "VDM\\Joomla\\Utilities", "code": "src\/a223b31e-ea1d-4cdf-92ae-5f9becffaff0\/code.php", + "power": "src\/a223b31e-ea1d-4cdf-92ae-5f9becffaff0\/code.power", "settings": "src\/a223b31e-ea1d-4cdf-92ae-5f9becffaff0\/settings.json", "path": "src\/a223b31e-ea1d-4cdf-92ae-5f9becffaff0", "guid": "a223b31e-ea1d-4cdf-92ae-5f9becffaff0" }, + "9ef0eb24-aae4-4f5a-99af-d724db44808f": { + "name": "FieldHelper", + "type": "abstract class", + "namespace": "VDM\\Joomla\\Utilities\\String", + "code": "src\/9ef0eb24-aae4-4f5a-99af-d724db44808f\/code.php", + "power": "src\/9ef0eb24-aae4-4f5a-99af-d724db44808f\/code.power", + "settings": "src\/9ef0eb24-aae4-4f5a-99af-d724db44808f\/settings.json", + "path": "src\/9ef0eb24-aae4-4f5a-99af-d724db44808f", + "guid": "9ef0eb24-aae4-4f5a-99af-d724db44808f" + }, + "a8935cbe-7701-40dc-bfd5-675f2d600954": { + "name": "TypeHelper", + "type": "abstract class", + "namespace": "VDM\\Joomla\\Utilities\\String", + "code": "src\/a8935cbe-7701-40dc-bfd5-675f2d600954\/code.php", + "power": "src\/a8935cbe-7701-40dc-bfd5-675f2d600954\/code.power", + "settings": "src\/a8935cbe-7701-40dc-bfd5-675f2d600954\/settings.json", + "path": "src\/a8935cbe-7701-40dc-bfd5-675f2d600954", + "guid": "a8935cbe-7701-40dc-bfd5-675f2d600954" + }, + "30c5b4c2-f75f-4d15-869a-f8bfedd87358": { + "name": "ClassfunctionHelper", + "type": "abstract class", + "namespace": "VDM\\Joomla\\Utilities\\String", + "code": "src\/30c5b4c2-f75f-4d15-869a-f8bfedd87358\/code.php", + "power": "src\/30c5b4c2-f75f-4d15-869a-f8bfedd87358\/code.power", + "settings": "src\/30c5b4c2-f75f-4d15-869a-f8bfedd87358\/settings.json", + "path": "src\/30c5b4c2-f75f-4d15-869a-f8bfedd87358", + "guid": "30c5b4c2-f75f-4d15-869a-f8bfedd87358" + }, + "ce8cf834-6bac-44fb-941c-861f7e046cc0": { + "name": "NamespaceHelper", + "type": "abstract class", + "namespace": "VDM\\Joomla\\Utilities\\String", + "code": "src\/ce8cf834-6bac-44fb-941c-861f7e046cc0\/code.php", + "power": "src\/ce8cf834-6bac-44fb-941c-861f7e046cc0\/code.power", + "settings": "src\/ce8cf834-6bac-44fb-941c-861f7e046cc0\/settings.json", + "path": "src\/ce8cf834-6bac-44fb-941c-861f7e046cc0", + "guid": "ce8cf834-6bac-44fb-941c-861f7e046cc0" + }, + "3cf76fbf-fd95-4a33-878e-7aff6d36b7f6": { + "name": "PluginHelper", + "type": "abstract class", + "namespace": "VDM\\Joomla\\Utilities\\String", + "code": "src\/3cf76fbf-fd95-4a33-878e-7aff6d36b7f6\/code.php", + "power": "src\/3cf76fbf-fd95-4a33-878e-7aff6d36b7f6\/code.power", + "settings": "src\/3cf76fbf-fd95-4a33-878e-7aff6d36b7f6\/settings.json", + "path": "src\/3cf76fbf-fd95-4a33-878e-7aff6d36b7f6", + "guid": "3cf76fbf-fd95-4a33-878e-7aff6d36b7f6" + }, "79d765b3-7319-4988-9730-446c7f347020": { "name": "Utilities", "type": "trait", "namespace": "VDM\\Joomla", "code": "src\/79d765b3-7319-4988-9730-446c7f347020\/code.php", + "power": "src\/79d765b3-7319-4988-9730-446c7f347020\/code.power", "settings": "src\/79d765b3-7319-4988-9730-446c7f347020\/settings.json", "path": "src\/79d765b3-7319-4988-9730-446c7f347020", "guid": "79d765b3-7319-4988-9730-446c7f347020" + }, + "6cbef8f8-4813-48e3-b05a-65e1aea95171": { + "name": "Database", + "type": "abstract class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Abstraction", + "code": "src\/6cbef8f8-4813-48e3-b05a-65e1aea95171\/code.php", + "power": "src\/6cbef8f8-4813-48e3-b05a-65e1aea95171\/code.power", + "settings": "src\/6cbef8f8-4813-48e3-b05a-65e1aea95171\/settings.json", + "path": "src\/6cbef8f8-4813-48e3-b05a-65e1aea95171", + "guid": "6cbef8f8-4813-48e3-b05a-65e1aea95171" + }, + "06f8eada-d59b-441c-b287-0aea1793da5a": { + "name": "Load", + "type": "final class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Database", + "code": "src\/06f8eada-d59b-441c-b287-0aea1793da5a\/code.php", + "power": "src\/06f8eada-d59b-441c-b287-0aea1793da5a\/code.power", + "settings": "src\/06f8eada-d59b-441c-b287-0aea1793da5a\/settings.json", + "path": "src\/06f8eada-d59b-441c-b287-0aea1793da5a", + "guid": "06f8eada-d59b-441c-b287-0aea1793da5a" + }, + "524eb8f6-38d4-47dc-92ad-98b94e099ac0": { + "name": "Insert", + "type": "final class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Database", + "code": "src\/524eb8f6-38d4-47dc-92ad-98b94e099ac0\/code.php", + "power": "src\/524eb8f6-38d4-47dc-92ad-98b94e099ac0\/code.power", + "settings": "src\/524eb8f6-38d4-47dc-92ad-98b94e099ac0\/settings.json", + "path": "src\/524eb8f6-38d4-47dc-92ad-98b94e099ac0", + "guid": "524eb8f6-38d4-47dc-92ad-98b94e099ac0" + }, + "9769f3b2-17bf-4f20-b54b-3a4ebe572b36": { + "name": "BaseConfig", + "type": "abstract class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Abstraction", + "code": "src\/9769f3b2-17bf-4f20-b54b-3a4ebe572b36\/code.php", + "power": "src\/9769f3b2-17bf-4f20-b54b-3a4ebe572b36\/code.power", + "settings": "src\/9769f3b2-17bf-4f20-b54b-3a4ebe572b36\/settings.json", + "path": "src\/9769f3b2-17bf-4f20-b54b-3a4ebe572b36", + "guid": "9769f3b2-17bf-4f20-b54b-3a4ebe572b36" + }, + "8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff": { + "name": "ModelInterface", + "type": "interface", + "namespace": "VDM\\Joomla\\Componentbuilder\\Interfaces", + "code": "src\/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff\/code.php", + "power": "src\/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff\/code.power", + "settings": "src\/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff\/settings.json", + "path": "src\/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff", + "guid": "8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff" + }, + "584747d1-3a86-453d-b7a3-a2219de8d777": { + "name": "Model", + "type": "abstract class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Abstraction", + "code": "src\/584747d1-3a86-453d-b7a3-a2219de8d777\/code.php", + "power": "src\/584747d1-3a86-453d-b7a3-a2219de8d777\/code.power", + "settings": "src\/584747d1-3a86-453d-b7a3-a2219de8d777\/settings.json", + "path": "src\/584747d1-3a86-453d-b7a3-a2219de8d777", + "guid": "584747d1-3a86-453d-b7a3-a2219de8d777" + }, + "b84e947d-2a13-44f7-ac0f-3902ae55ae0c": { + "name": "BaseRegistry", + "type": "abstract class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Abstraction", + "code": "src\/b84e947d-2a13-44f7-ac0f-3902ae55ae0c\/code.php", + "power": "src\/b84e947d-2a13-44f7-ac0f-3902ae55ae0c\/code.power", + "settings": "src\/b84e947d-2a13-44f7-ac0f-3902ae55ae0c\/settings.json", + "path": "src\/b84e947d-2a13-44f7-ac0f-3902ae55ae0c", + "guid": "b84e947d-2a13-44f7-ac0f-3902ae55ae0c" + }, + "44a3367c-f9e4-406b-b396-0f452bde0f03": { + "name": "Mapper", + "type": "abstract class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Abstraction", + "code": "src\/44a3367c-f9e4-406b-b396-0f452bde0f03\/code.php", + "power": "src\/44a3367c-f9e4-406b-b396-0f452bde0f03\/code.power", + "settings": "src\/44a3367c-f9e4-406b-b396-0f452bde0f03\/settings.json", + "path": "src\/44a3367c-f9e4-406b-b396-0f452bde0f03", + "guid": "44a3367c-f9e4-406b-b396-0f452bde0f03" + }, + "c6bbc3ee-58e7-4463-adba-5c5ae839ee36": { + "name": "MapperSingle", + "type": "abstract class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Abstraction", + "code": "src\/c6bbc3ee-58e7-4463-adba-5c5ae839ee36\/code.php", + "power": "src\/c6bbc3ee-58e7-4463-adba-5c5ae839ee36\/code.power", + "settings": "src\/c6bbc3ee-58e7-4463-adba-5c5ae839ee36\/settings.json", + "path": "src\/c6bbc3ee-58e7-4463-adba-5c5ae839ee36", + "guid": "c6bbc3ee-58e7-4463-adba-5c5ae839ee36" + }, + "cddcac51-9a46-47c4-ba59-105c70453bd6": { + "name": "FilterHelper", + "type": "abstract class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Utilities", + "code": "src\/cddcac51-9a46-47c4-ba59-105c70453bd6\/code.php", + "power": "src\/cddcac51-9a46-47c4-ba59-105c70453bd6\/code.power", + "settings": "src\/cddcac51-9a46-47c4-ba59-105c70453bd6\/settings.json", + "path": "src\/cddcac51-9a46-47c4-ba59-105c70453bd6", + "guid": "cddcac51-9a46-47c4-ba59-105c70453bd6" + }, + "1198aecf-84c6-45d2-aea8-d531aa4afdfa": { + "name": "FormHelper", + "type": "abstract class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Utilities", + "code": "src\/1198aecf-84c6-45d2-aea8-d531aa4afdfa\/code.php", + "power": "src\/1198aecf-84c6-45d2-aea8-d531aa4afdfa\/code.power", + "settings": "src\/1198aecf-84c6-45d2-aea8-d531aa4afdfa\/settings.json", + "path": "src\/1198aecf-84c6-45d2-aea8-d531aa4afdfa", + "guid": "1198aecf-84c6-45d2-aea8-d531aa4afdfa" } } \ No newline at end of file