PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 7.1.4
Admin Columns v7.1.4
7.1.4 7.0.19 2.3.5 2.4 2.4.1 2.4.10 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.6.1 2.5.6.2 2.5.6.3 2.5.6.4 3.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.7 3.1 3.1.1 3.1.10 3.1.2 3.1.3 3.1.5 3.2.3 3.2.7 3.3.1 3.4.1 3.4.6 3.4.8 4.0.1 4.0.3 4.1.6 4.2.2 4.2.5 4.3 4.3.2 4.4.1 4.4.4 4.4.5 4.5.5 4.6.1 4.7.18 4.7.19 4.7.20 4.7.7 7.0.13 7.0.14 7.0.16 trunk 1.0 1.1 1.1.3 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.5.1 1.4.6 1.4.6.1 1.4.6.2 1.4.6.3 1.4.6.4 1.4.7 1.4.8 1.4.9 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.1.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.5.1 2.2.6 2.2.6.1 2.2.6.2 2.2.6.3 2.2.6.4 2.2.7 2.2.8 2.2.8.1 2.2.9 2.3.1 2.3.2 2.3.3
codepress-admin-columns / classes / Storage / Repository / OriginalColumnsRepository.php
codepress-admin-columns / classes / Storage / Repository Last commit date
EditButton.php 2 days ago EditorFavorites.php 2 days ago EditorMenuStatus.php 2 days ago IntegrationStatus.php 2 days ago ListColumnOrder.php 2 days ago ListScreenOrder.php 2 days ago OriginalColumnsRepository.php 2 days ago TableListOrder.php 2 days ago UserColumnOrder.php 2 days ago
OriginalColumnsRepository.php
144 lines
1 <?php
2
3 declare(strict_types=1);
4
5 namespace AC\Storage\Repository;
6
7 use AC\Storage\Option;
8 use AC\Type\OriginalColumn;
9 use AC\Type\OriginalColumns;
10 use AC\Type\TableId;
11 use Exception;
12
13 final class OriginalColumnsRepository
14 {
15 private function storage(TableId $id): Option
16 {
17 return new Option(
18 sprintf('_ac_columns_default_%s', $id)
19 );
20 }
21
22 public function update(TableId $id, OriginalColumns $columns): void
23 {
24 $data = [];
25
26 foreach ($columns as $column) {
27 $args = [
28 'label' => $column->get_label(),
29 ];
30
31 if ($column->is_sortable()) {
32 $args['sortable'] = true;
33 }
34
35 $data[$column->get_name()] = $args;
36 }
37
38 $this->storage($id)->save($data);
39 }
40
41 public function exists(TableId $id): bool
42 {
43 return false !== $this->get_cached($id);
44 }
45
46 public function delete(TableId $id): void
47 {
48 $this
49 ->storage($id)
50 ->delete();
51 }
52
53 public function find(TableId $id, string $type): ?OriginalColumn
54 {
55 $data = $this->get_cached($id);
56
57 if (! $data) {
58 return null;
59 }
60
61 $column_data = $data[$type] ?? null;
62
63 return $column_data && is_array($column_data)
64 ? $this->create_column($type, $column_data)
65 : null;
66 }
67
68 public function find_all_cached(TableId $id): OriginalColumns
69 {
70 $columns = [];
71
72 $data = $this->get_cached($id);
73
74 if ($data) {
75 foreach ($data as $type => $column_data) {
76 if ('cb' === $type) {
77 continue;
78 }
79
80 $column = $this->create_column($type, $column_data);
81
82 if (! $column) {
83 continue;
84 }
85
86 $columns[] = $column;
87 }
88 }
89
90 return new OriginalColumns($columns);
91 }
92
93 private function get_cached(TableId $id)
94 {
95 static $cached_storage;
96
97 if (! isset($cached_storage[(string)$id])) {
98 $cached_storage[(string)$id] = $this->storage($id)->get();
99 }
100
101 return $cached_storage[(string)$id];
102 }
103
104 public function find_all(TableId $id): OriginalColumns
105 {
106 $columns = [];
107
108 foreach ($this->get($id) as $type => $data) {
109 if ('cb' === $type) {
110 continue;
111 }
112
113 $column = $this->create_column($type, $data);
114
115 if (! $column) {
116 continue;
117 }
118
119 $columns[] = $column;
120 }
121
122 return new OriginalColumns($columns);
123 }
124
125 private function create_column(string $type, array $data): ?OriginalColumn
126 {
127 try {
128 return new OriginalColumn(
129 $type,
130 (string)($data['label'] ?? ''),
131 (bool)($data['sortable'] ?? false)
132 );
133 } catch (Exception $e) {
134 return null;
135 }
136 }
137
138 private function get(TableId $id): array
139 {
140 return $this->storage($id)->get() ?: [];
141 }
142
143 }
144