update 2023-06-02 04:47:47
This commit is contained in:
parent
a857999064
commit
9340afb222
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
@ -342,6 +342,5 @@ abstract class Model
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract protected function getTable(): string;
|
||||
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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 <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/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": ""
|
||||
|
@ -11,76 +11,8 @@
|
||||
```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
|
||||
```
|
||||
|
||||
|
@ -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
|
||||
@ -5544,198 +5545,5 @@ class Table implements Tableinterface
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -5,195 +5,3 @@
|
||||
* @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;
|
||||
}
|
||||
|
@ -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"
|
||||
|
@ -7,7 +7,7 @@
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# interface FactoryInterface (Details)
|
||||
> namespace: **VDM\Joomla\Componentbuilder\Interfaces**
|
||||
> namespace: **VDM\Joomla\Interfaces**
|
||||
```uml
|
||||
@startuml
|
||||
interface FactoryInterface #Lavender {
|
||||
|
@ -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;
|
||||
@ -37,6 +37,5 @@ interface FactoryInterface
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function getContainer(): Container;
|
||||
|
||||
}
|
||||
|
||||
|
@ -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 <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/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;",
|
||||
|
98
src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/README.md
Normal file
98
src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/README.md
Normal file
@ -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)
|
||||
|
225
src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/code.php
Normal file
225
src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/code.php
Normal file
@ -0,0 +1,225 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/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;
|
||||
}
|
||||
}
|
||||
|
199
src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/code.power
Normal file
199
src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/code.power
Normal file
@ -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;
|
||||
}
|
20
src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/settings.json
Normal file
20
src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/settings.json
Normal file
@ -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 <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/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": ""
|
||||
}
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user