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