4
0

update 2023-06-04 21:30:50

This commit is contained in:
Robot 2023-06-04 21:30:50 +02:00
parent f9959e0696
commit a03abafafd
Signed by: Robot
GPG Key ID: 14DECD44E7E1BB95
12 changed files with 281 additions and 125 deletions

View File

@ -17,6 +17,7 @@ class Upsert << (F,LightGreen) >> #Green {
# validateBefore(mixed $value, ?string $field = null, ...) : bool
# validateAfter(mixed $value, ?string $field = null, ...) : bool
# getTable() : string
+ modelDistributionHistory(mixed $value) : mixed
}
note right of Upsert::__construct
@ -68,6 +69,13 @@ note right of Upsert::getTable
since: 2.0.1
return: string
end note
note right of Upsert::modelDistributionHistory
Model Translation History
since: 2.0.1
return: mixed
end note
@enduml
```

View File

@ -73,6 +73,12 @@ final class Upsert extends Model implements ModelInterface
// check if this is a valid table
if (($store = $this->table->get($table, $field, 'store')) !== null)
{
// Model Translation History
if ($table === 'translation' && $field === 'distribution_history')
{
$value = $this->modelDistributionHistory($value);
}
// open the value based on the store method
switch($store)
{
@ -136,6 +142,30 @@ final class Upsert extends Model implements ModelInterface
protected function getTable(): string
{
return $this->config->table_name;
}
/**
* Model Translation History
*
* @param mixed $value The value to model
*
* @return mixed
* @since 2.0.1
*/
public function modelDistributionHistory($value)
{
if (ObjectHelper::check($value))
{
$n = 0;
$bucket = [];
foreach ($value as $version => $description)
{
$bucket["distribution_history$n"] = ['version' => $version, 'description' => $description];
$n++;
}
return $bucket;
}
return '';
}
}

View File

@ -43,6 +43,12 @@
// check if this is a valid table
if (($store = $this->table->get($table, $field, 'store')) !== null)
{
// Model Translation History
if ($table === 'translation' && $field === 'distribution_history')
{
$value = $this->modelDistributionHistory($value);
}
// open the value based on the store method
switch($store)
{
@ -106,4 +112,28 @@
protected function getTable(): string
{
return $this->config->table_name;
}
/**
* Model Translation History
*
* @param mixed $value The value to model
*
* @return mixed
* @since 2.0.1
*/
public function modelDistributionHistory($value)
{
if (ObjectHelper::check($value))
{
$n = 0;
$bucket = [];
foreach ($value as $version => $description)
{
$bucket["distribution_history$n"] = ['version' => $version, 'description' => $description];
$n++;
}
return $bucket;
}
return '';
}

View File

@ -15,10 +15,10 @@ class Insert << (F,LightGreen) >> #Green {
# Database $database
+ __construct(Model $model, Database $database)
+ value(mixed $value, string $field, ...) : bool
+ row(array $item) : bool
+ rows(?array $items) : bool
+ item(object $item) : bool
+ items(?array $items) : bool
+ row(array $item, string $table) : bool
+ rows(?array $items, string $table) : bool
+ item(object $item, string $table) : bool
+ items(?array $items, string $table) : bool
}
note right of Insert::__construct
@ -29,7 +29,7 @@ end note
note right of Insert::value
Insert a value to a given table
Example: $this->value(Value, 'value_key', 'GUID');
Example: $this->value(Value, 'value_key', 'table_name');
since: 2.0.1
return: bool
@ -37,13 +37,12 @@ Example: $this->value(Value, 'value_key', 'GUID');
arguments:
mixed $value
string $field
string $keyValue
string $key = 'guid'
string $table
end note
note right of Insert::row
Insert single row with multiple values to a given table
Example: $this->item(Array);
Example: $this->item(Array, 'table_name');
since: 2.0.1
return: bool
@ -51,7 +50,7 @@ end note
note right of Insert::rows
Insert multiple rows to a given table
Example: $this->items(Array);
Example: $this->items(Array, 'table_name');
since: 2.0.1
return: bool
@ -59,7 +58,7 @@ end note
note right of Insert::item
Insert single item with multiple values to a given table
Example: $this->item(Object);
Example: $this->item(Object, 'table_name');
since: 2.0.1
return: bool
@ -67,7 +66,7 @@ end note
note right of Insert::items
Insert multiple items to a given table
Example: $this->items(Array);
Example: $this->items(Array, 'table_name');
since: 2.0.1
return: bool

View File

@ -55,103 +55,105 @@ final class Insert
/**
* Insert a value to a given table
* Example: $this->value(Value, 'value_key', 'GUID');
* Example: $this->value(Value, 'value_key', 'table_name');
*
* @param mixed $value The field value
* @param string $field The field key
* @param string $keyValue The key value
* @param string $key The key name
* @param mixed $value The field value
* @param string $field The field key
* @param string $table Target table
*
* @return bool
* @since 2.0.1
*/
public function value($value, string $field, string $keyValue, string $key = 'guid'): bool
public function value($value, string $field, string $table): bool
{
// build the array
$item = [];
$item[$key] = $keyValue;
$item[$field] = $value;
// Insert the column of this table
return $this->row($item);
return $this->row($item, $table);
}
/**
* Insert single row with multiple values to a given table
* Example: $this->item(Array);
* Example: $this->item(Array, 'table_name');
*
* @param array $item The item to save
* @param string $table Target table
*
* @return bool
* @since 2.0.1
*/
public function row(array $item): bool
public function row(array $item, string $table): bool
{
// check if object could be modelled
if (($item = $this->model->row($item, 'power')) !== null)
if (($item = $this->model->row($item, $table)) !== null)
{
// Insert the column of this table
return $this->database->row($item, 'power');
return $this->database->row($item, $table);
}
return false;
}
/**
* Insert multiple rows to a given table
* Example: $this->items(Array);
* Example: $this->items(Array, 'table_name');
*
* @param array|null $items The items updated in database (array of arrays)
* @param string $table Target table
*
* @return bool
* @since 2.0.1
*/
public function rows(?array $items): bool
public function rows(?array $items, string $table): bool
{
// check if object could be modelled
if (($items = $this->model->rows($items, 'power')) !== null)
if (($items = $this->model->rows($items, $table)) !== null)
{
// Insert the column of this table
return $this->database->rows($items, 'power');
return $this->database->rows($items, $table);
}
return false;
}
/**
* Insert single item with multiple values to a given table
* Example: $this->item(Object);
* Example: $this->item(Object, 'table_name');
*
* @param object $item The item to save
* @param string $table Target table
*
* @return bool
* @since 2.0.1
*/
public function item(object $item): bool
public function item(object $item, string $table): bool
{
// check if object could be modelled
if (($item = $this->model->item($item, 'power')) !== null)
if (($item = $this->model->item($item, $table)) !== null)
{
// Insert the column of this table
return $this->database->item($item, 'power');
// Insert the column of this table.
return $this->database->item($item, $table);
}
return false;
}
/**
* Insert multiple items to a given table
* Example: $this->items(Array);
* Example: $this->items(Array, 'table_name');
*
* @param array|null $items The items updated in database (array of objects)
* @param string $table Target table
*
* @return bool
* @since 2.0.1
*/
public function items(?array $items): bool
public function items(?array $items, string $table): bool
{
// check if object could be modelled
if (($items = $this->model->items($items, 'power')) !== null)
if (($items = $this->model->items($items, $table)) !== null)
{
// Update the column of this table using guid as the primary key.
return $this->database->items($items, 'power');
// Insert the column of this table.
return $this->database->items($items, $table);
}
return false;
}

View File

@ -30,103 +30,105 @@
/**
* Insert a value to a given table
* Example: $this->value(Value, 'value_key', 'GUID');
* Example: $this->value(Value, 'value_key', 'table_name');
*
* @param mixed $value The field value
* @param string $field The field key
* @param string $keyValue The key value
* @param string $key The key name
* @param mixed $value The field value
* @param string $field The field key
* @param string $table Target table
*
* @return bool
* @since 2.0.1
*/
public function value($value, string $field, string $keyValue, string $key = 'guid'): bool
public function value($value, string $field, string $table): bool
{
// build the array
$item = [];
$item[$key] = $keyValue;
$item[$field] = $value;
// Insert the column of this table
return $this->row($item);
return $this->row($item, $table);
}
/**
* Insert single row with multiple values to a given table
* Example: $this->item(Array);
* Example: $this->item(Array, 'table_name');
*
* @param array $item The item to save
* @param string $table Target table
*
* @return bool
* @since 2.0.1
*/
public function row(array $item): bool
public function row(array $item, string $table): bool
{
// check if object could be modelled
if (($item = $this->model->row($item, 'power')) !== null)
if (($item = $this->model->row($item, $table)) !== null)
{
// Insert the column of this table
return $this->database->row($item, 'power');
return $this->database->row($item, $table);
}
return false;
}
/**
* Insert multiple rows to a given table
* Example: $this->items(Array);
* Example: $this->items(Array, 'table_name');
*
* @param array|null $items The items updated in database (array of arrays)
* @param string $table Target table
*
* @return bool
* @since 2.0.1
*/
public function rows(?array $items): bool
public function rows(?array $items, string $table): bool
{
// check if object could be modelled
if (($items = $this->model->rows($items, 'power')) !== null)
if (($items = $this->model->rows($items, $table)) !== null)
{
// Insert the column of this table
return $this->database->rows($items, 'power');
return $this->database->rows($items, $table);
}
return false;
}
/**
* Insert single item with multiple values to a given table
* Example: $this->item(Object);
* Example: $this->item(Object, 'table_name');
*
* @param object $item The item to save
* @param string $table Target table
*
* @return bool
* @since 2.0.1
*/
public function item(object $item): bool
public function item(object $item, string $table): bool
{
// check if object could be modelled
if (($item = $this->model->item($item, 'power')) !== null)
if (($item = $this->model->item($item, $table)) !== null)
{
// Insert the column of this table
return $this->database->item($item, 'power');
// Insert the column of this table.
return $this->database->item($item, $table);
}
return false;
}
/**
* Insert multiple items to a given table
* Example: $this->items(Array);
* Example: $this->items(Array, 'table_name');
*
* @param array|null $items The items updated in database (array of objects)
* @param string $table Target table
*
* @return bool
* @since 2.0.1
*/
public function items(?array $items): bool
public function items(?array $items, string $table): bool
{
// check if object could be modelled
if (($items = $this->model->items($items, 'power')) !== null)
if (($items = $this->model->items($items, $table)) !== null)
{
// Update the column of this table using guid as the primary key.
return $this->database->items($items, 'power');
// Insert the column of this table.
return $this->database->items($items, $table);
}
return false;
}

View File

@ -17,6 +17,7 @@ class Load << (F,LightGreen) >> #Green {
# validateBefore(mixed $value, ?string $field = null, ...) : bool
# validateAfter(mixed $value, ?string $field = null, ...) : bool
# getTable() : string
+ modelDistributionHistory(mixed $value) : mixed
}
note right of Load::__construct
@ -68,6 +69,13 @@ note right of Load::getTable
since: 2.0.1
return: string
end note
note right of Load::modelDistributionHistory
Model Distribution History
since: 2.0.1
return: mixed
end note
@enduml
```

View File

@ -80,6 +80,12 @@ final class Load extends Model implements ModelInterface
$value = json_decode($value);
break;
}
// Model Distribution History
if ($table === 'translation' && $field === 'distribution_history')
{
$value = $this->modelDistributionHistory($value);
}
}
return $value;
@ -136,6 +142,19 @@ final class Load extends Model implements ModelInterface
protected function getTable(): string
{
return $this->config->table_name;
}
/**
* Model Distribution History
*
* @param mixed $value The value to model
*
* @return mixed
* @since 2.0.1
*/
public function modelDistributionHistory($value)
{
return $value;
}
}

View File

@ -50,6 +50,12 @@
$value = json_decode($value);
break;
}
// Model Distribution History
if ($table === 'translation' && $field === 'distribution_history')
{
$value = $this->modelDistributionHistory($value);
}
}
return $value;
@ -106,4 +112,17 @@
protected function getTable(): string
{
return $this->config->table_name;
}
/**
* Model Distribution History
*
* @param mixed $value The value to model
*
* @return mixed
* @since 2.0.1
*/
public function modelDistributionHistory($value)
{
return $value;
}

View File

@ -15,10 +15,10 @@ class Update << (F,LightGreen) >> #Green {
# Database $database
+ __construct(Model $model, Database $database)
+ value(mixed $value, string $field, ...) : bool
+ row(array $item) : bool
+ rows(?array $items) : bool
+ item(object $item) : bool
+ items(?array $items) : bool
+ row(array $item, string $key, ...) : bool
+ rows(?array $items, string $key, ...) : bool
+ item(object $item, string $key, ...) : bool
+ items(?array $items, string $key, ...) : bool
}
note right of Update::__construct
@ -29,7 +29,7 @@ end note
note right of Update::value
Update a value to a given table
Example: $this->value(Value, 'value_key', 'GUID');
Example: $this->value(Value, 'value_key', 'id', 'table_name');
since: 2.0.1
return: bool
@ -38,39 +38,60 @@ Example: $this->value(Value, 'value_key', 'GUID');
mixed $value
string $field
string $keyValue
string $key = 'guid'
string $key
string $table
end note
note right of Update::row
Update single row with multiple values to a given table
Example: $this->item(Array);
Example: $this->item(Array, 'id', 'table_name');
since: 2.0.1
return: bool
arguments:
array $item
string $key
string $table
end note
note right of Update::rows
Update multiple rows to a given table
Example: $this->items(Array);
Example: $this->items(Array, 'id', 'table_name');
since: 2.0.1
return: bool
arguments:
?array $items
string $key
string $table
end note
note right of Update::item
Update single item with multiple values to a given table
Example: $this->item(Object);
Example: $this->item(Object, 'id', 'table_name');
since: 2.0.1
return: bool
arguments:
object $item
string $key
string $table
end note
note right of Update::items
Update multiple items to a given table
Example: $this->items(Array);
Example: $this->items(Array, 'id', 'table_name');
since: 2.0.1
return: bool
arguments:
?array $items
string $key
string $table
end note
@enduml

View File

@ -55,17 +55,18 @@ final class Update
/**
* Update a value to a given table
* Example: $this->value(Value, 'value_key', 'GUID');
* Example: $this->value(Value, 'value_key', 'id', 'table_name');
*
* @param mixed $value The field value
* @param string $field The field key
* @param string $keyValue The key value
* @param string $key The key name
* @param string $table Target table
*
* @return bool
* @since 2.0.1
*/
public function value($value, string $field, string $keyValue, string $key = 'guid'): bool
public function value($value, string $field, string $keyValue, string $key, string $table): bool
{
// build the array
$item = [];
@ -73,85 +74,93 @@ final class Update
$item[$field] = $value;
// Update the column of this table using guid as the primary key.
return $this->row($item);
return $this->row($item, $key, $table);
}
/**
* Update single row with multiple values to a given table
* Example: $this->item(Array);
* Example: $this->item(Array, 'id', 'table_name');
*
* @param array $item The item to save
* @param array $item The item to save
* @param string $key The key name
* @param string $table Target table
*
* @return bool
* @since 2.0.1
*/
public function row(array $item): bool
public function row(array $item, string $key, string $table): bool
{
// check if object could be modelled
if (($item = $this->model->row($item, 'power')) !== null)
if (($item = $this->model->row($item, $table)) !== null)
{
// Update the column of this table using guid as the primary key.
return $this->database->row($item, 'guid', 'power');
// Update the column of this table using $key as the primary key.
return $this->database->row($item, $key, $table);
}
return false;
}
/**
* Update multiple rows to a given table
* Example: $this->items(Array);
* Example: $this->items(Array, 'id', 'table_name');
*
* @param array|null $items The items updated in database (array of arrays)
* @param array|null $items The items updated in database (array of arrays)
* @param string $key The key name
* @param string $table Target table
*
* @return bool
* @since 2.0.1
*/
public function rows(?array $items): bool
public function rows(?array $items, string $key, string $table): bool
{
// check if object could be modelled
if (($items = $this->model->rows($items, 'power')) !== null)
if (($items = $this->model->rows($items, $table)) !== null)
{
// Update the column of this table using guid as the primary key.
return $this->database->rows($items, 'guid', 'power');
// Update the column of this table using $key as the primary key.
return $this->database->rows($items, $key, $table);
}
return false;
}
/**
* Update single item with multiple values to a given table
* Example: $this->item(Object);
* Example: $this->item(Object, 'id', 'table_name');
*
* @param object $item The item to save
* @param string $key The key name
* @param string $table Target table
*
* @return bool
* @since 2.0.1
*/
public function item(object $item): bool
public function item(object $item, string $key, string $table): bool
{
// check if object could be modelled
if (($item = $this->model->item($item, 'power')) !== null)
if (($item = $this->model->item($item, $table)) !== null)
{
// Update the column of this table using guid as the primary key.
return $this->database->item($item, 'guid', 'power');
// Update the column of this table using $key as the primary key.
return $this->database->item($item, $key, $table);
}
return false;
}
/**
* Update multiple items to a given table
* Example: $this->items(Array);
* Example: $this->items(Array, 'id', 'table_name');
*
* @param array|null $items The items updated in database (array of objects)
* @param array|null $items The items updated in database (array of objects)
* @param string $key The key name
* @param string $table Target table
*
* @return bool
* @since 2.0.1
*/
public function items(?array $items): bool
public function items(?array $items, string $key, string $table): bool
{
// check if object could be modelled
if (($items = $this->model->items($items, 'power')) !== null)
if (($items = $this->model->items($items, $table)) !== null)
{
// Update the column of this table using guid as the primary key.
return $this->database->items($items, 'guid', 'power');
// Update the column of this table using $key as the primary key.
return $this->database->items($items, $key, $table);
}
return false;
}

View File

@ -30,17 +30,18 @@
/**
* Update a value to a given table
* Example: $this->value(Value, 'value_key', 'GUID');
* Example: $this->value(Value, 'value_key', 'id', 'table_name');
*
* @param mixed $value The field value
* @param string $field The field key
* @param string $keyValue The key value
* @param string $key The key name
* @param string $table Target table
*
* @return bool
* @since 2.0.1
*/
public function value($value, string $field, string $keyValue, string $key = 'guid'): bool
public function value($value, string $field, string $keyValue, string $key, string $table): bool
{
// build the array
$item = [];
@ -48,85 +49,93 @@
$item[$field] = $value;
// Update the column of this table using guid as the primary key.
return $this->row($item);
return $this->row($item, $key, $table);
}
/**
* Update single row with multiple values to a given table
* Example: $this->item(Array);
* Example: $this->item(Array, 'id', 'table_name');
*
* @param array $item The item to save
* @param array $item The item to save
* @param string $key The key name
* @param string $table Target table
*
* @return bool
* @since 2.0.1
*/
public function row(array $item): bool
public function row(array $item, string $key, string $table): bool
{
// check if object could be modelled
if (($item = $this->model->row($item, 'power')) !== null)
if (($item = $this->model->row($item, $table)) !== null)
{
// Update the column of this table using guid as the primary key.
return $this->database->row($item, 'guid', 'power');
// Update the column of this table using $key as the primary key.
return $this->database->row($item, $key, $table);
}
return false;
}
/**
* Update multiple rows to a given table
* Example: $this->items(Array);
* Example: $this->items(Array, 'id', 'table_name');
*
* @param array|null $items The items updated in database (array of arrays)
* @param array|null $items The items updated in database (array of arrays)
* @param string $key The key name
* @param string $table Target table
*
* @return bool
* @since 2.0.1
*/
public function rows(?array $items): bool
public function rows(?array $items, string $key, string $table): bool
{
// check if object could be modelled
if (($items = $this->model->rows($items, 'power')) !== null)
if (($items = $this->model->rows($items, $table)) !== null)
{
// Update the column of this table using guid as the primary key.
return $this->database->rows($items, 'guid', 'power');
// Update the column of this table using $key as the primary key.
return $this->database->rows($items, $key, $table);
}
return false;
}
/**
* Update single item with multiple values to a given table
* Example: $this->item(Object);
* Example: $this->item(Object, 'id', 'table_name');
*
* @param object $item The item to save
* @param string $key The key name
* @param string $table Target table
*
* @return bool
* @since 2.0.1
*/
public function item(object $item): bool
public function item(object $item, string $key, string $table): bool
{
// check if object could be modelled
if (($item = $this->model->item($item, 'power')) !== null)
if (($item = $this->model->item($item, $table)) !== null)
{
// Update the column of this table using guid as the primary key.
return $this->database->item($item, 'guid', 'power');
// Update the column of this table using $key as the primary key.
return $this->database->item($item, $key, $table);
}
return false;
}
/**
* Update multiple items to a given table
* Example: $this->items(Array);
* Example: $this->items(Array, 'id', 'table_name');
*
* @param array|null $items The items updated in database (array of objects)
* @param array|null $items The items updated in database (array of objects)
* @param string $key The key name
* @param string $table Target table
*
* @return bool
* @since 2.0.1
*/
public function items(?array $items): bool
public function items(?array $items, string $key, string $table): bool
{
// check if object could be modelled
if (($items = $this->model->items($items, 'power')) !== null)
if (($items = $this->model->items($items, $table)) !== null)
{
// Update the column of this table using guid as the primary key.
return $this->database->items($items, 'guid', 'power');
// Update the column of this table using $key as the primary key.
return $this->database->items($items, $key, $table);
}
return false;
}