From 9340afb2229f62368b178a360930794dd31721cd Mon Sep 17 00:00:00 2001 From: aB0t Date: Fri, 2 Jun 2023 04:48:07 +0200 Subject: [PATCH] update 2023-06-02 04:47:47 --- README.md | 5 +- .../code.php | 2 +- .../code.power | 2 +- .../code.php | 7 +- .../code.power | 4 +- .../settings.json | 2 +- .../README.md | 68 ------ .../code.php | 198 +-------------- .../code.power | 194 +-------------- .../settings.json | 2 +- .../README.md | 2 +- .../code.php | 5 +- .../code.power | 2 +- .../settings.json | 4 +- .../README.md | 98 ++++++++ .../code.php | 225 ++++++++++++++++++ .../code.power | 199 ++++++++++++++++ .../settings.json | 20 ++ super-powers.json | 13 +- 19 files changed, 575 insertions(+), 477 deletions(-) create mode 100644 src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/README.md create mode 100644 src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/code.php create mode 100644 src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/code.power create mode 100644 src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/settings.json diff --git a/README.md b/README.md index e4727b3..68b227f 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ This repository contains an index (see below) of all the approved powers within - **Namespace**: [VDM\Joomla\Abstraction](#vdm-joomla-abstraction) - **abstract class BaseConfig** | [Details](src/ffbd4e1f-a342-4080-ab7d-1de3741bf319) | [Code](src/ffbd4e1f-a342-4080-ab7d-1de3741bf319/code.php) | [Settings](src/ffbd4e1f-a342-4080-ab7d-1de3741bf319/settings.json) | Super__ffbd4e1f_a342_4080_ab7d_1de3741bf319__Power + - **abstract class BaseTable** | [Details](src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6) | [Code](src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/code.php) | [Settings](src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/settings.json) | Super__e0f6ddbe_2a35_4537_942c_faff2ebd04f6__Power - **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) | Super__6cbef8f8_4813_48e3_b05a_65e1aea95171__Power - **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) | Super__584747d1_3a86_453d_b7a3_a2219de8d777__Power - **Namespace**: [VDM\Joomla\Componentbuilder](#vdm-joomla-componentbuilder) @@ -41,6 +42,7 @@ This repository contains an index (see below) of all the approved powers within - **final class Update** | [Details](src/cce56585-58b0-4f72-a92c-e2635ea52d83) | [Code](src/cce56585-58b0-4f72-a92c-e2635ea52d83/code.php) | [Settings](src/cce56585-58b0-4f72-a92c-e2635ea52d83/settings.json) | Super__cce56585_58b0_4f72_a92c_e2635ea52d83__Power - **Namespace**: [VDM\Joomla\Interfaces](#vdm-joomla-interfaces) + - **interface FactoryInterface** | [Details](src/caf33c5d-858c-4f9a-894f-ab302ec5445a) | [Code](src/caf33c5d-858c-4f9a-894f-ab302ec5445a/code.php) | [Settings](src/caf33c5d-858c-4f9a-894f-ab302ec5445a/settings.json) | Super__caf33c5d_858c_4f9a_894f_ab302ec5445a__Power - **interface InsertInterface** | [Details](src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48) | [Code](src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/code.php) | [Settings](src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/settings.json) | Super__ad12ca1c_d3ce_4e7f_88c5_c6c92bdedc48__Power - **interface LoadInterface** | [Details](src/2ad31f74-f579-499d-b98b-c4f54fd615dd) | [Code](src/2ad31f74-f579-499d-b98b-c4f54fd615dd/code.php) | [Settings](src/2ad31f74-f579-499d-b98b-c4f54fd615dd/settings.json) | Super__2ad31f74_f579_499d_b98b_c4f54fd615dd__Power - **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) | Super__8aef58c1_3f70_4bd4_b9e4_3f29fcd41cff__Power @@ -61,9 +63,6 @@ This repository contains an index (see below) of all the approved powers within - **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) | Super__b84e947d_2a13_44f7_ac0f_3902ae55ae0c__Power - **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) | Super__44a3367c_f9e4_406b_b396_0f452bde0f03__Power - **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) | Super__c6bbc3ee_58e7_4463_adba_5c5ae839ee36__Power -- **Namespace**: [VDM\Joomla\Componentbuilder\Interfaces](#vdm-joomla-componentbuilder-interfaces) - - - **interface FactoryInterface** | [Details](src/caf33c5d-858c-4f9a-894f-ab302ec5445a) | [Code](src/caf33c5d-858c-4f9a-894f-ab302ec5445a/code.php) | [Settings](src/caf33c5d-858c-4f9a-894f-ab302ec5445a/settings.json) | Super__caf33c5d_858c_4f9a_894f_ab302ec5445a__Power - **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) | Super__cddcac51_9a46_47c4_ba59_105c70453bd6__Power diff --git a/src/06f8eada-d59b-441c-b287-0aea1793da5a/code.php b/src/06f8eada-d59b-441c-b287-0aea1793da5a/code.php index d52b6b5..5141ca2 100644 --- a/src/06f8eada-d59b-441c-b287-0aea1793da5a/code.php +++ b/src/06f8eada-d59b-441c-b287-0aea1793da5a/code.php @@ -186,7 +186,7 @@ final class Load extends Database implements LoadInterface if (isset($tables['a'])) { // get the query - $query = $this->query($select, $tables, $where, $order); + $query = $this->query($select, $tables, $where, $order, $limit); // Load the items $this->db->setQuery($query); diff --git a/src/06f8eada-d59b-441c-b287-0aea1793da5a/code.power b/src/06f8eada-d59b-441c-b287-0aea1793da5a/code.power index 965b225..8a3110b 100644 --- a/src/06f8eada-d59b-441c-b287-0aea1793da5a/code.power +++ b/src/06f8eada-d59b-441c-b287-0aea1793da5a/code.power @@ -160,7 +160,7 @@ if (isset($tables['a'])) { // get the query - $query = $this->query($select, $tables, $where, $order); + $query = $this->query($select, $tables, $where, $order, $limit); // Load the items $this->db->setQuery($query); diff --git a/src/584747d1-3a86-453d-b7a3-a2219de8d777/code.php b/src/584747d1-3a86-453d-b7a3-a2219de8d777/code.php index 7727200..9785bf3 100644 --- a/src/584747d1-3a86-453d-b7a3-a2219de8d777/code.php +++ b/src/584747d1-3a86-453d-b7a3-a2219de8d777/code.php @@ -18,7 +18,7 @@ use VDM\Joomla\Interfaces\Tableinterface as Table; /** - * Our base Model + * Base Model * * @since 3.2.0 */ @@ -114,7 +114,7 @@ abstract class Model } } - // all items must have more than one field or its empty (1 = id or guid) + // all items must have more than one field or its empty (1 = key) if ($field_number > 1) { return $item_bucket; @@ -341,7 +341,6 @@ abstract class Model * @return string * @since 3.2.0 */ - abstract protected function getTable(): string; - + 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 index 8f93d7b..4cb2eb3 100644 --- a/src/584747d1-3a86-453d-b7a3-a2219de8d777/code.power +++ b/src/584747d1-3a86-453d-b7a3-a2219de8d777/code.power @@ -88,7 +88,7 @@ } } - // all items must have more than one field or its empty (1 = id or guid) + // all items must have more than one field or its empty (1 = key) if ($field_number > 1) { return $item_bucket; @@ -315,4 +315,4 @@ * @return string * @since 3.2.0 */ - abstract protected function getTable(): string; + abstract protected function getTable(): string; \ No newline at end of file diff --git a/src/584747d1-3a86-453d-b7a3-a2219de8d777/settings.json b/src/584747d1-3a86-453d-b7a3-a2219de8d777/settings.json index 26adf2b..39f7427 100644 --- a/src/584747d1-3a86-453d-b7a3-a2219de8d777/settings.json +++ b/src/584747d1-3a86-453d-b7a3-a2219de8d777/settings.json @@ -24,7 +24,7 @@ } }, "namespace": "VDM\\Joomla\\Abstraction.Model", - "description": "Our base Model\r\n\r\n@since 3.2.0", + "description": "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": "" diff --git a/src/bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8/README.md b/src/bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8/README.md index 1d391b4..3ed0cf4 100644 --- a/src/bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8/README.md +++ b/src/bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8/README.md @@ -11,75 +11,7 @@ ```uml @startuml class Table #Gold { - + get(string $table, ?string $field = null, ...) : mixed - + title(string $table) : ?array - + titleName(string $table) : string - + tables() : array - + exist(string $table, ?string $field = null) : bool - + fields(string $table, bool $default = false) : ?array - # addDefault(array $fields) : array } - -note right of Table::get - Get any value from a item/field/column of an area/view/table -Example: $this->get('table_name', 'field_name', 'value_key'); -Get an item/field/column of an area/view/table -Example: $this->get('table_name', 'field_name'); -Get all items/fields/columns of an area/view/table -Example: $this->get('table_name'); -Get all areas/views/tables with all their item/field/column details -Example: $this->get('All'); - - since: 3.2.0 - return: mixed - - arguments: - string $table - ?string $field = null - ?string $key = null -end note - -note right of Table::title - Get title field from an area/view/table - - since: 3.2.0 - return: ?array -end note - -note right of Table::titleName - Get title field name - - since: 3.2.0 - return: string -end note - -note right of Table::tables - Get all tables - - since: 3.2.0 - return: array -end note - -note right of Table::exist - Check if a table (and field) exist - - since: 3.2.0 - return: bool -end note - -note right of Table::fields - Get all fields of an area/view/table - - since: 3.2.0 - return: ?array -end note - -note right of Table::addDefault - Add the default fields - - since: 3.2.0 - return: array -end note @enduml ``` diff --git a/src/bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8/code.php b/src/bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8/code.php index ea4e1c0..325c758 100644 --- a/src/bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8/code.php +++ b/src/bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8/code.php @@ -13,6 +13,7 @@ namespace VDM\Joomla\Componentbuilder; use VDM\Joomla\Interfaces\Tableinterface; +use VDM\Joomla\Abstraction\BaseTable; /** @@ -20,7 +21,7 @@ use VDM\Joomla\Interfaces\Tableinterface; * * @since 3.2.0 */ -class Table implements Tableinterface +class Table extends BaseTable implements Tableinterface { /** * All areas/views/tables with their field details @@ -5543,199 +5544,6 @@ class Table implements Tableinterface 'tab_name' => 'Basic', ], ], - ]; - - /** - * Get any value from a item/field/column of an area/view/table - * Example: $this->get('table_name', 'field_name', 'value_key'); - * Get an item/field/column of an area/view/table - * Example: $this->get('table_name', 'field_name'); - * Get all items/fields/columns of an area/view/table - * Example: $this->get('table_name'); - * Get all areas/views/tables with all their item/field/column details - * Example: $this->get('All'); - * - * @param string $table The table - * @param string|null $field The field - * @param string|null $key The value key - * - * @return mixed - * @since 3.2.0 - */ - public function get(string $table, ?string $field = null, ?string $key = null) - { - // return the item/field/column of an area/view/table - if (is_string($field) && is_string($key)) - { - // return the value of a item/field/column of an area/view/table - if (isset($this->tables[$table][$field][$key])) - { - return $this->tables[$table][$field][$key]; - } - return null; - } - // return the item/field/column of an area/view/table - elseif (is_string($field)) - { - if (isset($this->tables[$table][$field])) - { - return $this->tables[$table][$field]; - } - return null; - } - // return an area/view/table - elseif ($table !== 'All') - { - if (isset($this->tables[$table])) - { - return $this->tables[$table]; - } - return null; - } - - // return all - return $this->tables; - } - - /** - * Get title field from an area/view/table - * - * @param string $table The area - * - * @return ?array - * @since 3.2.0 - */ - public function title(string $table): ?array - { - // return the title item/field/column of an area/view/table - if (($table = $this->get($table)) !== null) - { - foreach ($table as $item) - { - if ($item['title']) - { - return $item; - } - } - } - - // none found - return null; - } - - /** - * Get title field name - * - * @param string $table The area - * - * @return string - * @since 3.2.0 - */ - public function titleName(string $table): string - { - // return the title name of an area/view/table - if (($field = $this->title($table)) !== null) - { - return $field['name']; - } - - // none found default to ID - return 'id'; - } - - /** - * Get all tables - * - * @return array - * @since 3.2.0 - */ - public function tables(): array - { - // return all areas/views/tables - return array_keys($this->tables); - } - - /** - * Check if a table (and field) exist - * - * @param string $table The area - * @param string|null $field The area - * - * @return bool - * @since 3.2.0 - */ - public function exist(string $table, ?string $field = null): bool - { - if (isset($this->tables[$table])) - { - // if we have a field - if (is_string($field)) - { - if (isset($this->tables[$table][$field])) - { - return true; - } - } - else - { - return true; - } - } - - return false; - } - - /** - * Get all fields of an area/view/table - * - * @param string $table The area - * @param bool $default Add the default fields - * - * @return array|null On success an array of fields - * @since 3.2.0 - */ - public function fields(string $table, bool $default = false): ?array - { - // return all fields of an area/view/table - if (($table = $this->get($table)) !== null) - { - if ($default) - { - return $this->addDefault(array_keys($table)); - } - else - { - return array_keys($table); - } - } - - // none found - return null; - } - - /** - * Add the default fields - * - * @param array $fields The table dynamic fields - * - * @return array Fields (with defaults added) - * @since 3.2.0 - */ - protected function addDefault(array $fields): array - { - // add default fields - array_unshift($fields, 'id'); - $fields[] = 'ordering'; - $fields[] = 'published'; - $fields[] = 'modified_by'; - $fields[] = 'modified'; - $fields[] = 'created_by'; - $fields[] = 'created'; - $fields[] = 'hits'; - $fields[] = 'version'; - - return $fields; - } - + ]; } diff --git a/src/bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8/code.power b/src/bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8/code.power index 7abc6aa..ff82257 100644 --- a/src/bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8/code.power +++ b/src/bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8/code.power @@ -4,196 +4,4 @@ * @var array * @since 3.2.0 **/ - protected array $tables = ###ALL_COMPONENT_FIELDS###; - - /** - * Get any value from a item/field/column of an area/view/table - * Example: $this->get('table_name', 'field_name', 'value_key'); - * Get an item/field/column of an area/view/table - * Example: $this->get('table_name', 'field_name'); - * Get all items/fields/columns of an area/view/table - * Example: $this->get('table_name'); - * Get all areas/views/tables with all their item/field/column details - * Example: $this->get('All'); - * - * @param string $table The table - * @param string|null $field The field - * @param string|null $key The value key - * - * @return mixed - * @since 3.2.0 - */ - public function get(string $table, ?string $field = null, ?string $key = null) - { - // return the item/field/column of an area/view/table - if (is_string($field) && is_string($key)) - { - // return the value of a item/field/column of an area/view/table - if (isset($this->tables[$table][$field][$key])) - { - return $this->tables[$table][$field][$key]; - } - return null; - } - // return the item/field/column of an area/view/table - elseif (is_string($field)) - { - if (isset($this->tables[$table][$field])) - { - return $this->tables[$table][$field]; - } - return null; - } - // return an area/view/table - elseif ($table !== 'All') - { - if (isset($this->tables[$table])) - { - return $this->tables[$table]; - } - return null; - } - - // return all - return $this->tables; - } - - /** - * Get title field from an area/view/table - * - * @param string $table The area - * - * @return ?array - * @since 3.2.0 - */ - public function title(string $table): ?array - { - // return the title item/field/column of an area/view/table - if (($table = $this->get($table)) !== null) - { - foreach ($table as $item) - { - if ($item['title']) - { - return $item; - } - } - } - - // none found - return null; - } - - /** - * Get title field name - * - * @param string $table The area - * - * @return string - * @since 3.2.0 - */ - public function titleName(string $table): string - { - // return the title name of an area/view/table - if (($field = $this->title($table)) !== null) - { - return $field['name']; - } - - // none found default to ID - return 'id'; - } - - /** - * Get all tables - * - * @return array - * @since 3.2.0 - */ - public function tables(): array - { - // return all areas/views/tables - return array_keys($this->tables); - } - - /** - * Check if a table (and field) exist - * - * @param string $table The area - * @param string|null $field The area - * - * @return bool - * @since 3.2.0 - */ - public function exist(string $table, ?string $field = null): bool - { - if (isset($this->tables[$table])) - { - // if we have a field - if (is_string($field)) - { - if (isset($this->tables[$table][$field])) - { - return true; - } - } - else - { - return true; - } - } - - return false; - } - - /** - * Get all fields of an area/view/table - * - * @param string $table The area - * @param bool $default Add the default fields - * - * @return array|null On success an array of fields - * @since 3.2.0 - */ - public function fields(string $table, bool $default = false): ?array - { - // return all fields of an area/view/table - if (($table = $this->get($table)) !== null) - { - if ($default) - { - return $this->addDefault(array_keys($table)); - } - else - { - return array_keys($table); - } - } - - // none found - return null; - } - - /** - * Add the default fields - * - * @param array $fields The table dynamic fields - * - * @return array Fields (with defaults added) - * @since 3.2.0 - */ - protected function addDefault(array $fields): array - { - // add default fields - array_unshift($fields, 'id'); - $fields[] = 'ordering'; - $fields[] = 'published'; - $fields[] = 'modified_by'; - $fields[] = 'modified'; - $fields[] = 'created_by'; - $fields[] = 'created'; - $fields[] = 'hits'; - $fields[] = 'version'; - - return $fields; - } + protected array $tables = ###ALL_COMPONENT_FIELDS###; \ No newline at end of file diff --git a/src/bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8/settings.json b/src/bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8/settings.json index dbfe8bd..6541f3b 100644 --- a/src/bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8/settings.json +++ b/src/bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8/settings.json @@ -1,7 +1,7 @@ { "add_head": "0", "add_licensing_template": "2", - "extends": "0", + "extends": "e0f6ddbe-2a35-4537-942c-faff2ebd04f6", "guid": "bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8", "implements": [ "2da6d6c4-eb29-4d69-8bc2-36d96e916adf" diff --git a/src/caf33c5d-858c-4f9a-894f-ab302ec5445a/README.md b/src/caf33c5d-858c-4f9a-894f-ab302ec5445a/README.md index eeb3a5f..230dfb3 100644 --- a/src/caf33c5d-858c-4f9a-894f-ab302ec5445a/README.md +++ b/src/caf33c5d-858c-4f9a-894f-ab302ec5445a/README.md @@ -7,7 +7,7 @@ ╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ ``` # interface FactoryInterface (Details) -> namespace: **VDM\Joomla\Componentbuilder\Interfaces** +> namespace: **VDM\Joomla\Interfaces** ```uml @startuml interface FactoryInterface #Lavender { diff --git a/src/caf33c5d-858c-4f9a-894f-ab302ec5445a/code.php b/src/caf33c5d-858c-4f9a-894f-ab302ec5445a/code.php index aff5406..0dd2e4c 100644 --- a/src/caf33c5d-858c-4f9a-894f-ab302ec5445a/code.php +++ b/src/caf33c5d-858c-4f9a-894f-ab302ec5445a/code.php @@ -9,7 +9,7 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ -namespace VDM\Joomla\Componentbuilder\Interfaces; +namespace VDM\Joomla\Interfaces; use Joomla\DI\Container; @@ -36,7 +36,6 @@ interface FactoryInterface * @return Container * @since 3.2.0 */ - public static function getContainer(): Container; - + public static function getContainer(): Container; } diff --git a/src/caf33c5d-858c-4f9a-894f-ab302ec5445a/code.power b/src/caf33c5d-858c-4f9a-894f-ab302ec5445a/code.power index 5a394fe..2b6ce65 100644 --- a/src/caf33c5d-858c-4f9a-894f-ab302ec5445a/code.power +++ b/src/caf33c5d-858c-4f9a-894f-ab302ec5445a/code.power @@ -14,4 +14,4 @@ * @return Container * @since 3.2.0 */ - public static function getContainer(): Container; + public static function getContainer(): Container; \ No newline at end of file diff --git a/src/caf33c5d-858c-4f9a-894f-ab302ec5445a/settings.json b/src/caf33c5d-858c-4f9a-894f-ab302ec5445a/settings.json index d1a52a8..d062262 100644 --- a/src/caf33c5d-858c-4f9a-894f-ab302ec5445a/settings.json +++ b/src/caf33c5d-858c-4f9a-894f-ab302ec5445a/settings.json @@ -7,10 +7,10 @@ "load_selection": null, "name": "FactoryInterface", "power_version": "1.0.0", - "system_name": "JCB.Interfaces.FactoryInterface", + "system_name": "VDM.Interfaces.FactoryInterface", "type": "interface", "use_selection": null, - "namespace": "VDM\\Joomla\\Componentbuilder.Interfaces.FactoryInterface", + "namespace": "VDM\\Joomla\\Interfaces.FactoryInterface", "description": "The Container Factory Interface", "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\\DI\\Container;", diff --git a/src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/README.md b/src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/README.md new file mode 100644 index 0000000..b97b282 --- /dev/null +++ b/src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/README.md @@ -0,0 +1,98 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# abstract class BaseTable (Details) +> namespace: **VDM\Joomla\Abstraction** +```uml +@startuml +abstract BaseTable #Orange { + # array $tables + + get(string $table, ?string $field = null, ...) : mixed + + title(string $table) : ?array + + titleName(string $table) : string + + tables() : array + + exist(string $table, ?string $field = null) : bool + + fields(string $table, bool $default = false) : ?array + # addDefault(array $fields) : array +} + +note right of BaseTable::get + Get any value from a item/field/column of an area/view/table +Example: $this->get('table_name', 'field_name', 'value_key'); +Get an item/field/column of an area/view/table +Example: $this->get('table_name', 'field_name'); +Get all items/fields/columns of an area/view/table +Example: $this->get('table_name'); +Get all areas/views/tables with all their item/field/column details +Example: $this->get('All'); + + since: 3.2.0 + return: mixed + + arguments: + string $table + ?string $field = null + ?string $key = null +end note + +note right of BaseTable::title + Get title field from an area/view/table + + since: 3.2.0 + return: ?array +end note + +note right of BaseTable::titleName + Get title field name + + since: 3.2.0 + return: string +end note + +note right of BaseTable::tables + Get all tables + + since: 3.2.0 + return: array +end note + +note right of BaseTable::exist + Check if a table (and field) exist + + since: 3.2.0 + return: bool +end note + +note right of BaseTable::fields + Get all fields of an area/view/table + + since: 3.2.0 + return: ?array +end note + +note right of BaseTable::addDefault + Add the default fields + + 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/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/code.php b/src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/code.php new file mode 100644 index 0000000..f9a2df7 --- /dev/null +++ b/src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/code.php @@ -0,0 +1,225 @@ + + * @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\Abstraction; + + +use VDM\Joomla\Interfaces\Tableinterface; + + +/** + * Base Table + * + * @since 3.2.0 + */ +abstract class BaseTable implements Tableinterface +{ + /** + * All areas/views/tables with their field details + * + * @var array + * @since 3.2.0 + **/ + protected array $tables; + + /** + * Get any value from a item/field/column of an area/view/table + * Example: $this->get('table_name', 'field_name', 'value_key'); + * Get an item/field/column of an area/view/table + * Example: $this->get('table_name', 'field_name'); + * Get all items/fields/columns of an area/view/table + * Example: $this->get('table_name'); + * Get all areas/views/tables with all their item/field/column details + * Example: $this->get('All'); + * + * @param string $table The table + * @param string|null $field The field + * @param string|null $key The value key + * + * @return mixed + * @since 3.2.0 + */ + public function get(string $table, ?string $field = null, ?string $key = null) + { + // return the item/field/column of an area/view/table + if (is_string($field) && is_string($key)) + { + // return the value of a item/field/column of an area/view/table + if (isset($this->tables[$table][$field][$key])) + { + return $this->tables[$table][$field][$key]; + } + return null; + } + // return the item/field/column of an area/view/table + elseif (is_string($field)) + { + if (isset($this->tables[$table][$field])) + { + return $this->tables[$table][$field]; + } + return null; + } + // return an area/view/table + elseif ($table !== 'All') + { + if (isset($this->tables[$table])) + { + return $this->tables[$table]; + } + return null; + } + + // return all + return $this->tables; + } + + /** + * Get title field from an area/view/table + * + * @param string $table The area + * + * @return ?array + * @since 3.2.0 + */ + public function title(string $table): ?array + { + // return the title item/field/column of an area/view/table + if (($table = $this->get($table)) !== null) + { + foreach ($table as $item) + { + if ($item['title']) + { + return $item; + } + } + } + + // none found + return null; + } + + /** + * Get title field name + * + * @param string $table The area + * + * @return string + * @since 3.2.0 + */ + public function titleName(string $table): string + { + // return the title name of an area/view/table + if (($field = $this->title($table)) !== null) + { + return $field['name']; + } + + // none found default to ID + return 'id'; + } + + /** + * Get all tables + * + * @return array + * @since 3.2.0 + */ + public function tables(): array + { + // return all areas/views/tables + return array_keys($this->tables); + } + + /** + * Check if a table (and field) exist + * + * @param string $table The area + * @param string|null $field The area + * + * @return bool + * @since 3.2.0 + */ + public function exist(string $table, ?string $field = null): bool + { + if (isset($this->tables[$table])) + { + // if we have a field + if (is_string($field)) + { + if (isset($this->tables[$table][$field])) + { + return true; + } + } + else + { + return true; + } + } + + return false; + } + + /** + * Get all fields of an area/view/table + * + * @param string $table The area + * @param bool $default Add the default fields + * + * @return array|null On success an array of fields + * @since 3.2.0 + */ + public function fields(string $table, bool $default = false): ?array + { + // return all fields of an area/view/table + if (($table = $this->get($table)) !== null) + { + if ($default) + { + return $this->addDefault(array_keys($table)); + } + else + { + return array_keys($table); + } + } + + // none found + return null; + } + + /** + * Add the default fields + * + * @param array $fields The table dynamic fields + * + * @return array Fields (with defaults added) + * @since 3.2.0 + */ + protected function addDefault(array $fields): array + { + // add default fields + array_unshift($fields, 'id'); + $fields[] = 'ordering'; + $fields[] = 'published'; + $fields[] = 'modified_by'; + $fields[] = 'modified'; + $fields[] = 'created_by'; + $fields[] = 'created'; + $fields[] = 'hits'; + $fields[] = 'version'; + + return $fields; + } +} + diff --git a/src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/code.power b/src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/code.power new file mode 100644 index 0000000..64dc19c --- /dev/null +++ b/src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/code.power @@ -0,0 +1,199 @@ + /** + * All areas/views/tables with their field details + * + * @var array + * @since 3.2.0 + **/ + protected array $tables; + + /** + * Get any value from a item/field/column of an area/view/table + * Example: $this->get('table_name', 'field_name', 'value_key'); + * Get an item/field/column of an area/view/table + * Example: $this->get('table_name', 'field_name'); + * Get all items/fields/columns of an area/view/table + * Example: $this->get('table_name'); + * Get all areas/views/tables with all their item/field/column details + * Example: $this->get('All'); + * + * @param string $table The table + * @param string|null $field The field + * @param string|null $key The value key + * + * @return mixed + * @since 3.2.0 + */ + public function get(string $table, ?string $field = null, ?string $key = null) + { + // return the item/field/column of an area/view/table + if (is_string($field) && is_string($key)) + { + // return the value of a item/field/column of an area/view/table + if (isset($this->tables[$table][$field][$key])) + { + return $this->tables[$table][$field][$key]; + } + return null; + } + // return the item/field/column of an area/view/table + elseif (is_string($field)) + { + if (isset($this->tables[$table][$field])) + { + return $this->tables[$table][$field]; + } + return null; + } + // return an area/view/table + elseif ($table !== 'All') + { + if (isset($this->tables[$table])) + { + return $this->tables[$table]; + } + return null; + } + + // return all + return $this->tables; + } + + /** + * Get title field from an area/view/table + * + * @param string $table The area + * + * @return ?array + * @since 3.2.0 + */ + public function title(string $table): ?array + { + // return the title item/field/column of an area/view/table + if (($table = $this->get($table)) !== null) + { + foreach ($table as $item) + { + if ($item['title']) + { + return $item; + } + } + } + + // none found + return null; + } + + /** + * Get title field name + * + * @param string $table The area + * + * @return string + * @since 3.2.0 + */ + public function titleName(string $table): string + { + // return the title name of an area/view/table + if (($field = $this->title($table)) !== null) + { + return $field['name']; + } + + // none found default to ID + return 'id'; + } + + /** + * Get all tables + * + * @return array + * @since 3.2.0 + */ + public function tables(): array + { + // return all areas/views/tables + return array_keys($this->tables); + } + + /** + * Check if a table (and field) exist + * + * @param string $table The area + * @param string|null $field The area + * + * @return bool + * @since 3.2.0 + */ + public function exist(string $table, ?string $field = null): bool + { + if (isset($this->tables[$table])) + { + // if we have a field + if (is_string($field)) + { + if (isset($this->tables[$table][$field])) + { + return true; + } + } + else + { + return true; + } + } + + return false; + } + + /** + * Get all fields of an area/view/table + * + * @param string $table The area + * @param bool $default Add the default fields + * + * @return array|null On success an array of fields + * @since 3.2.0 + */ + public function fields(string $table, bool $default = false): ?array + { + // return all fields of an area/view/table + if (($table = $this->get($table)) !== null) + { + if ($default) + { + return $this->addDefault(array_keys($table)); + } + else + { + return array_keys($table); + } + } + + // none found + return null; + } + + /** + * Add the default fields + * + * @param array $fields The table dynamic fields + * + * @return array Fields (with defaults added) + * @since 3.2.0 + */ + protected function addDefault(array $fields): array + { + // add default fields + array_unshift($fields, 'id'); + $fields[] = 'ordering'; + $fields[] = 'published'; + $fields[] = 'modified_by'; + $fields[] = 'modified'; + $fields[] = 'created_by'; + $fields[] = 'created'; + $fields[] = 'hits'; + $fields[] = 'version'; + + return $fields; + } \ No newline at end of file diff --git a/src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/settings.json b/src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/settings.json new file mode 100644 index 0000000..61b51ac --- /dev/null +++ b/src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/settings.json @@ -0,0 +1,20 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "e0f6ddbe-2a35-4537-942c-faff2ebd04f6", + "implements": [ + "2da6d6c4-eb29-4d69-8bc2-36d96e916adf" + ], + "load_selection": null, + "name": "BaseTable", + "power_version": "1.0.0", + "system_name": "VDM.Abstraction.BaseTable", + "type": "abstract class", + "use_selection": null, + "namespace": "VDM\\Joomla\\Abstraction.BaseTable", + "description": "Base Table\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": "" +} \ No newline at end of file diff --git a/super-powers.json b/super-powers.json index 746b958..31feb16 100644 --- a/super-powers.json +++ b/super-powers.json @@ -299,7 +299,7 @@ "caf33c5d-858c-4f9a-894f-ab302ec5445a": { "name": "FactoryInterface", "type": "interface", - "namespace": "VDM\\Joomla\\Componentbuilder\\Interfaces", + "namespace": "VDM\\Joomla\\Interfaces", "code": "src\/caf33c5d-858c-4f9a-894f-ab302ec5445a\/code.php", "power": "src\/caf33c5d-858c-4f9a-894f-ab302ec5445a\/code.power", "settings": "src\/caf33c5d-858c-4f9a-894f-ab302ec5445a\/settings.json", @@ -351,6 +351,17 @@ "spk": "Super__db87c339_5bb6_4291_a7ef_2c48ea1b06bc__Power", "guid": "db87c339-5bb6-4291-a7ef-2c48ea1b06bc" }, + "e0f6ddbe-2a35-4537-942c-faff2ebd04f6": { + "name": "BaseTable", + "type": "abstract class", + "namespace": "VDM\\Joomla\\Abstraction", + "code": "src\/e0f6ddbe-2a35-4537-942c-faff2ebd04f6\/code.php", + "power": "src\/e0f6ddbe-2a35-4537-942c-faff2ebd04f6\/code.power", + "settings": "src\/e0f6ddbe-2a35-4537-942c-faff2ebd04f6\/settings.json", + "path": "src\/e0f6ddbe-2a35-4537-942c-faff2ebd04f6", + "spk": "Super__e0f6ddbe_2a35_4537_942c_faff2ebd04f6__Power", + "guid": "e0f6ddbe-2a35-4537-942c-faff2ebd04f6" + }, "ffbd4e1f-a342-4080-ab7d-1de3741bf319": { "name": "BaseConfig", "type": "abstract class",