InlineStyle
2 days ago
ManageHeading
2 days ago
ManageValue
2 days ago
SaveHeading
2 days ago
Service
2 days ago
TableScreenRepository
2 days ago
AdminHeadStyle.php
2 days ago
ManageValueServiceFactory.php
2 days ago
PrimaryColumn.php
2 days ago
PrimaryColumnFactory.php
2 days ago
SaveHeadingFactory.php
2 days ago
Screen.php
2 days ago
ScreenTools.php
2 days ago
TableFormView.php
2 days ago
TablePreference.php
2 days ago
TableScreenCollection.php
2 days ago
TableScreenRepository.php
2 days ago
TableScreenRepository.php
92 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Table; |
| 6 | |
| 7 | use AC\Table\TableScreenRepository\Sort; |
| 8 | use AC\TableIdsFactory; |
| 9 | use AC\TableScreen; |
| 10 | use AC\TableScreenFactory; |
| 11 | use AC\Type\TableId; |
| 12 | use AC\Type\TableIdCollection; |
| 13 | |
| 14 | class TableScreenRepository |
| 15 | { |
| 16 | protected TableIdsFactory $table_ids_factory; |
| 17 | |
| 18 | protected TableScreenFactory $table_screen_factory; |
| 19 | |
| 20 | public function __construct(TableIdsFactory $table_ids_factory, TableScreenFactory $table_screen_factory) |
| 21 | { |
| 22 | $this->table_ids_factory = $table_ids_factory; |
| 23 | $this->table_screen_factory = $table_screen_factory; |
| 24 | } |
| 25 | |
| 26 | public function find(TableId $table_id): ?TableScreen |
| 27 | { |
| 28 | return $this->table_screen_factory->can_create($table_id) |
| 29 | ? $this->table_screen_factory->create($table_id) |
| 30 | : null; |
| 31 | } |
| 32 | |
| 33 | public function find_all_by_ids(TableIdCollection $ids, ?Sort $sort = null): TableScreenCollection |
| 34 | { |
| 35 | $table_screens = new TableScreenCollection(); |
| 36 | |
| 37 | foreach ($ids as $key) { |
| 38 | if ($this->table_screen_factory->can_create($key)) { |
| 39 | $table_screens->add( |
| 40 | $this->table_screen_factory->create($key) |
| 41 | ); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | if ($sort) { |
| 46 | $table_screens = $sort->sort($table_screens); |
| 47 | } |
| 48 | |
| 49 | return $table_screens; |
| 50 | } |
| 51 | |
| 52 | public function find_all(?Sort $sort = null): TableScreenCollection |
| 53 | { |
| 54 | $table_screens = new TableScreenCollection(); |
| 55 | |
| 56 | foreach ($this->table_ids_factory->create() as $id) { |
| 57 | if (! $this->table_screen_factory->can_create($id)) { |
| 58 | continue; |
| 59 | } |
| 60 | |
| 61 | $table_screens->add( |
| 62 | $this->table_screen_factory->create($id) |
| 63 | ); |
| 64 | } |
| 65 | |
| 66 | if ($sort) { |
| 67 | $table_screens = $sort->sort($table_screens); |
| 68 | } |
| 69 | |
| 70 | return $table_screens; |
| 71 | } |
| 72 | |
| 73 | public function find_all_site(): TableScreenCollection |
| 74 | { |
| 75 | return new TableScreenCollection( |
| 76 | array_filter(iterator_to_array($this->find_all()), static function (TableScreen $screen): bool { |
| 77 | return ! $screen->is_network(); |
| 78 | }) |
| 79 | ); |
| 80 | } |
| 81 | |
| 82 | public function find_all_network(): TableScreenCollection |
| 83 | { |
| 84 | return new TableScreenCollection( |
| 85 | array_filter(iterator_to_array($this->find_all()), static function (TableScreen $screen): bool { |
| 86 | return $screen->is_network(); |
| 87 | }) |
| 88 | ); |
| 89 | } |
| 90 | |
| 91 | } |
| 92 |