Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
94.12% |
16 / 17 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| FilterGridMetadata | |
100.00% |
16 / 16 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| fromRow | |
100.00% |
15 / 15 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** @license For full copyright and license information, please see the LICENSE.md file. */ |
| 6 | |
| 7 | namespace App\Core\Engine\Domain\Model; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | use App\Core\Engine\Domain\Model\RecordStatus; |
| 12 | |
| 13 | /** |
| 14 | * Filter Grid Metadata Value Object. |
| 15 | * |
| 16 | * Immutable value object representing a module GRID view/filter configuration |
| 17 | * from a_core_filter_grid_records. Defines GRID tabs, icon, scope, and ownership. |
| 18 | * |
| 19 | * @package App\Core\Engine\Domain\Model |
| 20 | */ |
| 21 | final readonly class FilterGridMetadata |
| 22 | { |
| 23 | /** |
| 24 | * FilterGridMetadata constructor. |
| 25 | * |
| 26 | * @param int $id Filter Grid primary key. |
| 27 | * @param int $moduleId FK to a_core_module_records. |
| 28 | * @param string $name Machine-readable name. |
| 29 | * @param string $label Human-readable display label. |
| 30 | * @param string $iconClass Bootstrap icon class. |
| 31 | * @param bool $isDefault Whether this is the default GRID filter. |
| 32 | * @param bool $isSystem Whether this is a non-deletable system filter. |
| 33 | * @param string $scope Access scope ('private' or 'public'). |
| 34 | * @param int $sortOrder Tab display order. |
| 35 | * @param int|null $owner Record owner user ID. |
| 36 | * @param array<int, int> $coOwners Array of co-owner user IDs. |
| 37 | * @param int $recordStatus Special access level (0=None, 1=All Read, 2=All Write, 3=All Delete). |
| 38 | */ |
| 39 | public function __construct( |
| 40 | public int $id, |
| 41 | public int $moduleId, |
| 42 | public string $name, |
| 43 | public string $label, |
| 44 | public string $iconClass = 'bi bi-grid-1x2', |
| 45 | public bool $isDefault = false, |
| 46 | public bool $isSystem = false, |
| 47 | public string $scope = 'public', |
| 48 | public int $sortOrder = 10, |
| 49 | public ?int $owner = null, |
| 50 | public array $coOwners = [], |
| 51 | public int $recordStatus = 0, |
| 52 | ) { |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Creates a FilterGridMetadata instance from a raw database row array. |
| 57 | * |
| 58 | * @param array<string, mixed> $row Raw database row from a_core_filter_grid_records. |
| 59 | * @return self Hydrated FilterGridMetadata value object. |
| 60 | */ |
| 61 | public static function fromRow(array $row): self |
| 62 | { |
| 63 | $coOwners = \App\Shared\Utils\JsonArrayHelper::toIntList($row['co_owners'] ?? []); |
| 64 | |
| 65 | return new self( |
| 66 | id: (int) $row['id'], |
| 67 | moduleId: (int) $row['module_id'], |
| 68 | name: (string) $row['name'], |
| 69 | label: (string) $row['label'], |
| 70 | iconClass: (string) ($row['icon_class'] ?? 'bi bi-grid-1x2'), |
| 71 | isDefault: (bool) ($row['is_default'] ?? false), |
| 72 | isSystem: (bool) ($row['is_system'] ?? false), |
| 73 | scope: (string) ($row['scope'] ?? 'public'), |
| 74 | sortOrder: (int) ($row['sort_order'] ?? 10), |
| 75 | owner: isset($row['owner']) ? (int) $row['owner'] : null, |
| 76 | coOwners: $coOwners, |
| 77 | recordStatus: (int) ($row['record_status'] ?? 0), |
| 78 | ); |
| 79 | } |
| 80 | |
| 81 | use \App\Core\Engine\Domain\Model\Support\FilterAccessPolicyTrait; |
| 82 | } |
| 83 |