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
ListScreenOrder.php
43 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AC\Storage\Repository; |
| 4 | |
| 5 | use AC\Type\ListScreenId; |
| 6 | use AC\Type\TableId; |
| 7 | |
| 8 | class ListScreenOrder |
| 9 | { |
| 10 | |
| 11 | private const KEY = 'ac_list_screens_order'; |
| 12 | |
| 13 | public function get(TableId $key): array |
| 14 | { |
| 15 | $orders = $this->get_data(); |
| 16 | |
| 17 | return $orders[(string)$key] ?? []; |
| 18 | } |
| 19 | |
| 20 | public function set(TableId $key, array $list_screen_ids): void |
| 21 | { |
| 22 | $data = $this->get_data(); |
| 23 | |
| 24 | $data[(string)$key] = $list_screen_ids; |
| 25 | |
| 26 | update_option(self::KEY, $data, false); |
| 27 | } |
| 28 | |
| 29 | public function add(TableId $key, ListScreenId $id): void |
| 30 | { |
| 31 | $ids = $this->get($key); |
| 32 | |
| 33 | array_unshift($ids, (string)$id); |
| 34 | |
| 35 | $this->set($key, $ids); |
| 36 | } |
| 37 | |
| 38 | private function get_data(): array |
| 39 | { |
| 40 | return get_option(self::KEY, []) ?: []; |
| 41 | } |
| 42 | |
| 43 | } |