Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Model::getUserActions() to be called only on model #947

Merged
merged 7 commits into from
Dec 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 6 additions & 33 deletions src/Field/SqlExpressionField.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,24 @@ class SqlExpressionField extends Field
init as private _init;
}

/**
* Used expression.
*
* @var \Closure|string|Expressionable
*/
/** @var \Closure|string|Expressionable Used expression. */
public $expr;

/**
* Expressions are always read_only.
*
* @var bool
*/
/** @var bool Expressions are always read_only. */
public $read_only = true;

/**
* Specifies how to aggregate this.
*
* @var string
*/
/** @var string Specifies how to aggregate this. */
public $aggregate;

/**
* Aggregation by concatenation.
*
* @var string
*/
/** @var string Aggregation by concatenation. */
public $concat;

/**
* When defining as aggregate, this will point to relation object.
*
* @var Reference\HasMany|null
*/
/** @var Reference\HasMany|null When defining as aggregate, this will point to relation object. */
public $aggregate_relation;

/**
* Specifies which field to use.
*
* @var string
*/
/** @var string Specifies which field to use. */
public $field;

/**
* Initialization.
*/
protected function init(): void
{
$this->_init();
Expand Down
54 changes: 10 additions & 44 deletions src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
use Mvorisek\Atk4\Hintable\Data\HintableModelTrait;

/**
* Data model class.
*
* @property int $id @Atk4\Field(visibility="protected_set") Contains ID of the current record.
* If the value is null then the record is considered to be new.
* @property Field[]|Reference[] $elements
Expand Down Expand Up @@ -99,36 +97,22 @@ class Model implements \IteratorAggregate

// {{{ Properties of the class

/**
* @var static|null not-null if and only if this instance is an entity
*/
/** @var static|null not-null if and only if this instance is an entity */
private $_model;

/**
* @var mixed once set, loading a different ID will result in an error
*/
/** @var mixed once set, loading a different ID will result in an error */
private $_entityId;

/** @var array<string, true> */
private static $_modelOnlyProperties;

/**
* The class used by addField() method.
*
* @var string|array
*/
/** @var string|array The class used by addField() method. */
public $_default_seed_addField = [Field::class];

/**
* The class used by addExpression() method.
*
* @var string|array
*/
/** @var string|array The class used by addExpression() method. */
public $_default_seed_addExpression = [CallbackField::class];

/**
* @var array<string, Field>
*/
/** @var array<string, Field> */
protected $fields = [];

/**
Expand All @@ -140,16 +124,10 @@ class Model implements \IteratorAggregate
*/
public $table;

/**
* Use alias for $table.
*
* @var string|null
*/
/** @var string|null */
public $table_alias;

/**
* @var Persistence|Persistence\Sql|null
*/
/** @var Persistence|Persistence\Sql|null */
public $persistence;

/**
Expand All @@ -163,25 +141,13 @@ class Model implements \IteratorAggregate
/** @var Model\Scope\RootScope */
private $scope;

/**
* Array of limit set.
*
* @var array
*/
/** @var array Array of limit set. */
public $limit = [];

/**
* Array of set order by.
*
* @var array
*/
/** @var array Array of set order by. */
public $order = [];

/**
* Array of WITH cursors set.
*
* @var array
*/
/** @var array Array of WITH cursors set. */
public $with = [];

/**
Expand Down
24 changes: 4 additions & 20 deletions src/Model/FieldPropertiesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,10 @@

trait FieldPropertiesTrait
{
/**
* Field type. Name of type registered in \Doctrine\DBAL\Types\Type.
*
* @var string|null
*/
/** @var string|null Field type. Name of type registered in \Doctrine\DBAL\Types\Type. */
public $type;

/**
* For several types enum can provide list of available options. ['blue', 'red'].
*
* @var array|null
*/
/** @var array|null For several types enum can provide list of available options. ['blue', 'red']. */
public $enum;

/**
Expand All @@ -36,11 +28,7 @@ trait FieldPropertiesTrait
*/
protected $referenceLink;

/**
* Actual field name.
*
* @var string|null
*/
/** @var string|null Actual field name. */
public $actual;

/**
Expand All @@ -51,11 +39,7 @@ trait FieldPropertiesTrait
*/
public $system = false;

/**
* Default value of field.
*
* @var mixed
*/
/** @var mixed Default value of field. */
public $default;

/**
Expand Down
27 changes: 4 additions & 23 deletions src/Model/Join.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ class Join
*/
protected $kind;

/**
* Is our join weak? Weak join will stop you from touching foreign table.
*
* @var bool
*/
/** @var bool Is our join weak? Weak join will stop you from touching foreign table. */
protected $weak = false;

/**
Expand Down Expand Up @@ -107,11 +103,7 @@ class Join
*/
protected $foreign_field;

/**
* A short symbolic name that will be used as an alias for the joined table.
*
* @var string
*/
/** @var string A short symbolic name that will be used as an alias for the joined table. */
public $foreign_alias;

/**
Expand All @@ -122,18 +114,10 @@ class Join
*/
protected $prefix = '';

/**
* ID indexed by spl_object_id(entity) used by a joined table.
*
* @var mixed
*/
/** @var mixed ID indexed by spl_object_id(entity) used by a joined table. */
protected $idByOid;

/**
* Data indexed by spl_object_id(entity) which is populated here as the save/insert progresses.
*
* @var array<int, array<string, mixed>>
*/
/** @var array<int, array<string, mixed>> Data indexed by spl_object_id(entity) which is populated here as the save/insert progresses. */
private $saveBufferByOid = [];

public function __construct(string $foreign_table = null)
Expand Down Expand Up @@ -206,9 +190,6 @@ public function getDesiredName(): string
return '#join_' . $this->foreign_table;
}

/**
* Initialization.
*/
protected function init(): void
{
$this->_init();
Expand Down
6 changes: 1 addition & 5 deletions src/Model/JoinLinkTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@

trait JoinLinkTrait
{
/**
* The short name of the join link.
*
* @var string|null
*/
/** @var string|null The short name of the join link. */
protected $joinName;

public function hasJoin(): bool
Expand Down
6 changes: 1 addition & 5 deletions src/Model/JoinsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
*/
trait JoinsTrait
{
/**
* The class used by join() method.
*
* @var array
*/
/** @var array The class used by join() method. */
public $_default_seed_join = [Join::class];

/**
Expand Down
30 changes: 5 additions & 25 deletions src/Model/ReferencesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,19 @@
*/
trait ReferencesTrait
{
/**
* The seed used by addRef() method.
*
* @var array
*/
/** @var array The seed used by addRef() method. */
public $_default_seed_addRef = [Reference::class];

/**
* The seed used by hasOne() method.
*
* @var array
*/
/** @var array The seed used by hasOne() method. */
public $_default_seed_hasOne = [Reference\HasOne::class];

/**
* The seed used by hasMany() method.
*
* @var array
*/
/** @var array The seed used by hasMany() method. */
public $_default_seed_hasMany = [Reference\HasMany::class];

/**
* The seed used by containsOne() method.
*
* @var array
*/
/** @var array The seed used by containsOne() method. */
public $_default_seed_containsOne = [Reference\ContainsOne::class];

/**
* The seed used by containsMany() method.
*
* @var array
*/
/** @var array The seed used by containsMany() method. */
public $_default_seed_containsMany = [Reference\ContainsMany::class];

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Model/Scope/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ class Condition extends AbstractScope
public const OPERATOR_REGEXP = 'REGEXP';
public const OPERATOR_NOT_REGEXP = 'NOT REGEXP';

/**
* @var array<string, array<string, string>>
*/
/** @var array<string, array<string, string>> */
protected static $operators = [
self::OPERATOR_EQUALS => [
'negate' => self::OPERATOR_DOESNOT_EQUAL,
Expand Down
16 changes: 3 additions & 13 deletions src/Model/UserActionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,10 @@

trait UserActionsTrait
{
/**
* Default class for addUserAction().
*
* @var string|array
*/
/** @var string|array Default class for addUserAction(). */
public $_default_seed_action = [UserAction::class];

/**
* @var array<string, UserAction> Collection of user actions - using key as action system name
*/
/** @var array<string, UserAction> Collection of user actions - using key as action system name */
protected $userActions = [];

/**
Expand Down Expand Up @@ -79,11 +73,7 @@ private function addUserActionFromModel(string $name, UserAction $action): void
*/
public function getUserActions(string $appliesTo = null): array
{
if ($this->isEntity()) {
foreach (array_diff_key($this->getModel()->getUserActions($appliesTo), $this->userActions) as $name => $action) {
$this->addUserActionFromModel($name, $action);
}
}
$this->assertIsModel();

return array_filter($this->userActions, function ($action) use ($appliesTo) {
return !$action->system && ($appliesTo === null || $action->appliesTo === $appliesTo);
Expand Down
Loading