PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 7.0.13
Admin Columns v7.0.13
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 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
OriginalColumnsRepository.php
142 lines
1 <?php
2
3 namespace AC\Storage\Repository;
4
5 use AC\Storage\Option;
6 use AC\Type\OriginalColumn;
7 use AC\Type\OriginalColumns;
8 use AC\Type\TableId;
9 use Exception;
10
11 final class OriginalColumnsRepository
12 {
13
14 private function storage(TableId $id): Option
15 {
16 return new Option(
17 sprintf('_ac_columns_default_%s', $id)
18 );
19 }
20
21 public function update(TableId $id, OriginalColumns $columns): void
22 {
23 $data = [];
24
25 foreach ($columns as $column) {
26 $args = [
27 'label' => $column->get_label(),
28 ];
29
30 if ($column->is_sortable()) {
31 $args['sortable'] = true;
32 }
33
34 $data[$column->get_name()] = $args;
35 }
36
37 $this->storage($id)->save($data);
38 }
39
40 public function exists(TableId $id): bool
41 {
42 return false !== $this->get_cached($id);
43 }
44
45 public function delete(TableId $id): void
46 {
47 $this
48 ->storage($id)
49 ->delete();
50 }
51
52 public function find(TableId $id, string $type): ?OriginalColumn
53 {
54 $data = $this->get_cached($id);
55
56 if ( ! $data) {
57 return null;
58 }
59
60 $column_data = $data[$type] ?? null;
61
62 return $column_data && is_array($column_data)
63 ? $this->create_column($type, $column_data)
64 : null;
65 }
66
67 public function find_all_cached(TableId $id): OriginalColumns
68 {
69 $columns = [];
70
71 $data = $this->get_cached($id);
72
73 if ($data) {
74 foreach ($data as $type => $column_data) {
75 if ('cb' === $type) {
76 continue;
77 }
78
79 $column = $this->create_column($type, $column_data);
80
81 if ( ! $column) {
82 continue;
83 }
84
85 $columns[] = $column;
86 }
87 }
88
89 return new OriginalColumns($columns);
90 }
91
92 private function get_cached(TableId $id)
93 {
94 static $cached_storage;
95
96 if ( ! isset($cached_storage[(string)$id])) {
97 $cached_storage[(string)$id] = $this->storage($id)->get();
98 }
99
100 return $cached_storage[(string)$id];
101 }
102
103 public function find_all(TableId $id): OriginalColumns
104 {
105 $columns = [];
106
107 foreach ($this->get($id) as $type => $data) {
108 if ('cb' === $type) {
109 continue;
110 }
111
112 $column = $this->create_column($type, $data);
113
114 if ( ! $column) {
115 continue;
116 }
117
118 $columns[] = $column;
119 }
120
121 return new OriginalColumns($columns);
122 }
123
124 private function create_column(string $type, array $data): ?OriginalColumn
125 {
126 try {
127 return new OriginalColumn(
128 $type,
129 (string)($data['label'] ?? ''),
130 (bool)($data['sortable'] ?? false)
131 );
132 } catch (Exception $e) {
133 return null;
134 }
135 }
136
137 private function get(TableId $id): array
138 {
139 return $this->storage($id)->get() ?: [];
140 }
141
142 }