Skip to content

Commit

Permalink
Manager namespaced
Browse files Browse the repository at this point in the history
  • Loading branch information
dergel committed Sep 7, 2024
1 parent 1a08f4b commit eb275d9
Show file tree
Hide file tree
Showing 41 changed files with 556 additions and 392 deletions.
25 changes: 19 additions & 6 deletions boot.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Yakamara\YForm\Manager\Dataset;
use Yakamara\YForm\Manager\Table\Table;
use Yakamara\YForm\Rest\Rest;
use Yakamara\YForm\YForm;

Expand All @@ -17,6 +19,17 @@ class_alias('Yakamara\YForm\List\Tools', 'rex_yform_list_tools');
class_alias('Yakamara\YForm\RexVar\Data', 'rex_var_yform_data');
class_alias('Yakamara\YForm\RexVar\TableData', 'rex_var_yform_data');
class_alias('Yakamara\YForm\Email\Template', 'rex_yform_email_template');
class_alias('Yakamara\YForm\Manager\Table\Table', 'rex_yform_manager_table');
class_alias('Yakamara\YForm\Manager\Table\Authorization', 'rex_yform_manager_table_authorization');
class_alias('Yakamara\YForm\Manager\Table\Api', 'rex_yform_manager_table_api');
class_alias('Yakamara\YForm\Manager\Table\Perm\Edit', 'rex_yform_manager_table_perm_edit');
class_alias('Yakamara\YForm\Manager\Table\Perm\View', 'rex_yform_manager_table_perm_view');
class_alias('Yakamara\YForm\Manager\Collection', 'rex_yform_manager_collection');
class_alias('Yakamara\YForm\Manager\Dataset', 'rex_yform_manager_dataset');
class_alias('Yakamara\YForm\Manager\Field', 'rex_yform_manager_field');
class_alias('Yakamara\YForm\Manager\Manager', 'rex_yform_manager_manager');
class_alias('Yakamara\YForm\Manager\Query', 'rex_yform_manager_query');
class_alias('Yakamara\YForm\Manager\Search', 'rex_yform_manager_search');

YForm::addTemplatePath(rex_path::addon('yform', 'ytemplates'));

Expand Down Expand Up @@ -93,8 +106,8 @@ class_alias('Yakamara\YForm\Email\Template', 'rex_yform_email_template');

// Manager

rex_complex_perm::register('yform_manager_table_edit', 'rex_yform_manager_table_perm_edit');
rex_complex_perm::register('yform_manager_table_view', 'rex_yform_manager_table_perm_view');
rex_complex_perm::register('yform_manager_table_edit', 'Yakamara\YForm\Manager\Table\Perm\Edit');
rex_complex_perm::register('yform_manager_table_view', 'Yakamara\YForm\Manager\Table\Perm\View');

if (rex::isBackend() && rex::getUser()) {
rex_extension::register('PACKAGES_INCLUDED', function () {
Expand All @@ -120,7 +133,7 @@ class_alias('Yakamara\YForm\Email\Template', 'rex_yform_email_template');
}

try {
$tables = rex_yform_manager_table::getAll();
$tables = Table::getAll();
} catch (Exception $e) {
$tables = [];
}
Expand Down Expand Up @@ -173,19 +186,19 @@ class_alias('Yakamara\YForm\Email\Template', 'rex_yform_email_template');
return;
}

$table = rex_yform_manager_table::get($ep->getParam('table'));
$table = Table::get($ep->getParam('table'));
if (!$table) {
return;
}

$dataset = $ep->getParam('form')->getParam('manager_dataset');
if (!$dataset) {
$dataset = rex_yform_manager_dataset::getRaw($ep->getParam('id'), $table->getTableName());
$dataset = Dataset::getRaw($ep->getParam('id'), $table->getTableName());
}
$dataset->invalidateData();

if ($table->hasHistory() && $dataset->isHistoryEnabled()) {
$action = 'insert' === $ep->getParam('action') ? rex_yform_manager_dataset::ACTION_CREATE : rex_yform_manager_dataset::ACTION_UPDATE;
$action = 'insert' === $ep->getParam('action') ? Dataset::ACTION_CREATE : Dataset::ACTION_UPDATE;
$dataset->makeSnapshot($action);
}
});
10 changes: 5 additions & 5 deletions docs/04_yorm.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ dump($items);
Es stehen folgende Klassen zur Verfügung:

- `rex_yform_manager_dataset`
- `rex_yform_manager_collection`
- `rex_yform_manager_query`
- `Yakamara\YForm\Manager\Collection`
- `Yakamara\YForm\Manager\Dataset`
- `Yakamara\YForm\Manager\Query`

<a name="klasse-erstellen"></a>

Expand Down Expand Up @@ -519,7 +519,7 @@ Beispiel für resetSelect()
// resetSelect() ermöglicht es im Anschluss per select nur die Felder des Datensatzes zu erhalten, die man wirklich benötigt.

```php
$dataset = rex_yform_manager_query::get('rex_yf_example')
$dataset = Yakamara\YForm\Manager\Query::get('rex_yf_example')
->resetSelect()
->select('id')
->select('title')
Expand Down Expand Up @@ -682,7 +682,7 @@ Nachteil: Man kann keine anderen Operatoren als = verwenden.
Mit `whereNested` in der Callback-Notation arbeiten:

```
$query->whereNested(function (rex_yform_manager_query $query) {
$query->whereNested(function (Yakamara\YForm\Manager\Query $query) {
$query
->where('foo', 1)
->where('bar', 2)
Expand Down
2 changes: 1 addition & 1 deletion fragments/yform/manager/page/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/** @var rex_yform_manager $manager */
$manager = $this->getVar('this');

/** @var rex_yform_manager_table $table */
/** @var \Yakamara\YForm\Manager\Table\Table $table */
$table = $this->getVar('table');
$detailForm = $this->getVar('detailForm');
$historyPage = $this->getVar('historyPage');
Expand Down
2 changes: 1 addition & 1 deletion fragments/yform/manager/page/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static function ($params) {
}
} else {
[$table_name, $field_name] = explode('.', $params['params']['opener_field']);
$table = rex_yform_manager_table::get($table_name);
$table = \Yakamara\YForm\Manager\Table\Table::get($table_name);
if ($table) {
$fields = $table->getValueFields(['name' => $field_name]);
if (isset($fields[$field_name])) {
Expand Down
21 changes: 10 additions & 11 deletions lib/List/List.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
use rex_url;
use rex_url_provider_interface;
use rex_view;
use rex_yform_manager_dataset;
use rex_yform_manager_query;
use Yakamara\YForm\Manager\Dataset;
use Yakamara\YForm\Manager\Query;

use function count;
use function in_array;
Expand All @@ -32,9 +32,9 @@ class YList implements rex_url_provider_interface
public const LIST_OPT_SORT_DIRECTION = 1;
public const LIST_OPT_SORT = 0;

/** @var rex_yform_manager_query */
/** @var Query */
private $query;
/** @var rex_yform_manager_dataset */
/** @var Dataset */
private $currentItem;
/** @var bool */
/** @phpstan-ignore-next-line */
Expand Down Expand Up @@ -99,12 +99,12 @@ class YList implements rex_url_provider_interface
/**
* Erstellt ein rex_list Objekt.
*
* @param rex_yform_manager_query $query YForm Query Objekt
* @param Query $query YForm Query Objekt
* @param int $rowsPerPage Anzahl der Elemente pro Zeile
* @param string|null $listName Name der Liste
* @param bool $debug
*/
protected function __construct(rex_yform_manager_query $query, int $rowsPerPage = 30, $listName = null, $debug = false)
protected function __construct(Query $query, int $rowsPerPage = 30, $listName = null, $debug = false)
{
// --------- Validation
if (!$listName) {
Expand Down Expand Up @@ -190,7 +190,7 @@ protected function __construct(rex_yform_manager_query $query, int $rowsPerPage
}

/**
* @param rex_yform_manager_query $query
* @param Query $query
* @param int $rowsPerPage
* @param string|null $listName
* @param bool $debug
Expand All @@ -212,19 +212,18 @@ public function init()
}

// ---------------------- setters/getters

/**
* @return rex_yform_manager_query
* @return Query
*/
public function getQuery()
{
return $this->query;
}

/**
* @return rex_yform_manager_query
* @return Query
*/
public function setQuery(rex_yform_manager_query $query)
public function setQuery(Query $query)
{
$this->query = $query;
return $this->query;
Expand Down
2 changes: 1 addition & 1 deletion lib/RexVar/TableData.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function getOutput()
return self::quote('[table param not defined]');
}

$table = rex_yform_manager_table::get($tableName);
$table = \Yakamara\YForm\Manager\Table\Table::get($tableName);
if (!$table) {
return self::quote('[table not in YForm?]');
}
Expand Down
61 changes: 39 additions & 22 deletions lib/manager/collection.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
<?php

/**
* @template T of rex_yform_manager_dataset
* @template T of \Yakamara\YForm\Manager\Dataset
* @extends SplFixedArray<T>
*
* @method rex_yform_manager_dataset offsetGet($offset)
* @method \Yakamara\YForm\Manager\Dataset offsetGet($offset)
* @method list<T> toArray()
*/
class rex_yform_manager_collection extends \SplFixedArray

namespace Yakamara\YForm\Manager;

use Closure;
use InvalidArgumentException;
use rex_i18n;
use rex_yform_base_abstract;
use rex_yform_value_abstract;
use SplFixedArray;
use Yakamara\YForm\Manager\Table\Table;
use Yakamara\YForm\YForm;

use function array_slice;
use function call_user_func;
use function count;
use function is_string;

class Collection extends SplFixedArray
{
/** @var bool */
private static $debug = false;
Expand All @@ -16,7 +33,7 @@ class rex_yform_manager_collection extends \SplFixedArray
private $table;

/**
* @param T[] $data
* @param array<T> $data
*/
final public function __construct(string $table, array $data = [])
{
Expand All @@ -31,13 +48,13 @@ public function getTableName(): string
return $this->table;
}

public function getTable(): rex_yform_manager_table
public function getTable(): Table
{
return rex_yform_manager_table::require($this->table);
return Table::require($this->table);
}

/**
* @param T[] $data
* @param array<T> $data
* @return $this
*/
public function setData(array $data): self
Expand All @@ -64,17 +81,17 @@ public function isEmpty(): bool
}

/**
* @return null|T
* @return T|null
*/
public function first(): ?rex_yform_manager_dataset
public function first(): ?Dataset
{
return $this->count() ? $this[0] : null;
}

/**
* @return null|T
* @return T|null
*/
public function last(): ?rex_yform_manager_dataset
public function last(): ?Dataset
{
return $this->count() ? $this[$this->count() - 1] : null;
}
Expand Down Expand Up @@ -162,7 +179,7 @@ public function chunk(int $size): array
}

/**
* @return T[]
* @return array<T>
*/
public function toKeyIndex(string $key = 'id'): array
{
Expand All @@ -185,7 +202,7 @@ public function toKeyValue(string $key, string $value): array
}

/**
* @param string|string[] $keys
* @param string|array<string> $keys
*/
public function groupBy($keys, ?string $value = null): array
{
Expand All @@ -195,7 +212,7 @@ public function groupBy($keys, ?string $value = null): array
$keys = array_reverse($keys);
}

$setValue = static function (&$array, array $keys, rex_yform_manager_dataset $dataset) use (&$setValue, $value) {
$setValue = static function (&$array, array $keys, Dataset $dataset) use (&$setValue, $value) {
if (!$keys) {
$array[] = $value ? $dataset->getValue($value) : $dataset;
return;
Expand All @@ -221,12 +238,12 @@ public function groupBy($keys, ?string $value = null): array
/**
* @param string|Closure $value Field name or callback
* @param string $separator Separator between elements
* @param null|string $and Optional separator between last two elements
* @param string|null $and Optional separator between last two elements
*/
public function implode($value, string $separator, ?string $and = null): string
{
if (!$value instanceof Closure) {
$value = static function (rex_yform_manager_dataset $dataset) use ($value) {
$value = static function (Dataset $dataset) use ($value) {
return $dataset->getValue($value);
};
}
Expand Down Expand Up @@ -307,7 +324,7 @@ public function setValue(string $key, $value): self
}

/**
* @return self A new collection containing all datasets related to this collection by $key relation
* @return Collection A new collection containing all datasets related to this collection by $key relation
*/
public function populateRelation(string $key)
{
Expand All @@ -321,7 +338,7 @@ public function populateRelation(string $key)
return new self($relation['table']);
}

$query = rex_yform_manager_dataset::query($relation['table']);
$query = Dataset::query($relation['table']);

if (0 == $relation['type'] || 2 == $relation['type']) {
$query->where('id', $this->getValues($key));
Expand Down Expand Up @@ -428,9 +445,9 @@ public function delete(): bool
return $success;
}

public function getForm(): \Yakamara\YForm\YForm
public function getForm(): YForm
{
$yform = new \Yakamara\YForm\YForm();
$yform = new YForm();
$yform->setDebug(self::$debug);
$yform->objparams['form_name'] = 'yform-manager-multi-edit';
$yform->objparams['form_class'] .= ' yform-manager-multi-edit';
Expand Down Expand Up @@ -529,9 +546,9 @@ public function getForm(): \Yakamara\YForm\YForm
}

/**
* @param null|callable(\Yakamara\YForm\YForm):void $afterFieldsExecuted
* @param callable(\Yakamara\YForm\YForm):void|null $afterFieldsExecuted
*/
public function executeForm(\Yakamara\YForm\YForm $yform, ?callable $afterFieldsExecuted = null): string
public function executeForm(YForm $yform, ?callable $afterFieldsExecuted = null): string
{
$yform->executeFields();

Expand Down
Loading

0 comments on commit eb275d9

Please sign in to comment.