EditButton.php
1 day ago
EditorFavorites.php
1 day ago
EditorMenuStatus.php
1 day ago
IntegrationStatus.php
1 day ago
ListColumnOrder.php
1 day ago
ListScreenOrder.php
1 day ago
OriginalColumnsRepository.php
1 day ago
TableListOrder.php
1 day ago
UserColumnOrder.php
1 day ago
ListColumnOrder.php
43 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Storage\Repository; |
| 6 | |
| 7 | use AC\ColumnCollection; |
| 8 | use AC\ColumnIterator; |
| 9 | use AC\ColumnRepository\Sort\ColumnNames; |
| 10 | use AC\ListScreenRepository\Storage; |
| 11 | use AC\Type\ListScreenId; |
| 12 | |
| 13 | class ListColumnOrder |
| 14 | { |
| 15 | private Storage $storage; |
| 16 | |
| 17 | public function __construct(Storage $storage) |
| 18 | { |
| 19 | $this->storage = $storage; |
| 20 | } |
| 21 | |
| 22 | public function save(ListScreenId $list_id, array $column_names): void |
| 23 | { |
| 24 | $list_screen = $this->storage->find($list_id); |
| 25 | |
| 26 | if (! $list_screen || $list_screen->is_read_only()) { |
| 27 | return; |
| 28 | } |
| 29 | |
| 30 | $list_screen->set_columns( |
| 31 | $this->modify_columns($list_screen->get_columns(), $column_names) |
| 32 | ); |
| 33 | |
| 34 | $this->storage->save($list_screen); |
| 35 | } |
| 36 | |
| 37 | private function modify_columns(ColumnIterator $columns, array $names): ColumnCollection |
| 38 | { |
| 39 | return (new ColumnNames($names))->sort($columns); |
| 40 | } |
| 41 | |
| 42 | } |
| 43 |