PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 7.0.19
Admin Columns v7.0.19
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 / ColumnSize / UserStorage.php
codepress-admin-columns / classes / ColumnSize Last commit date
ListStorage.php 1 month ago UserStorage.php 1 month ago
UserStorage.php
114 lines
1 <?php
2
3 namespace AC\ColumnSize;
4
5 use AC\Preferences\Preference;
6 use AC\Preferences\SiteFactory;
7 use AC\Type\ColumnId;
8 use AC\Type\ColumnWidth;
9 use AC\Type\ListScreenId;
10
11 class UserStorage
12 {
13
14 private const OPTION_UNIT = 'unit';
15 private const OPTION_VALUE = 'value';
16
17 private SiteFactory $storage_factory;
18
19 public function __construct(SiteFactory $storage_factory)
20 {
21 $this->storage_factory = $storage_factory;
22 }
23
24 private function create_storage(): Preference
25 {
26 return $this->storage_factory->create('column_widths');
27 }
28
29 public function save(ListScreenId $list_id, ColumnId $column_name, ColumnWidth $column_width): void
30 {
31 $widths = $this->create_storage()->find((string)$list_id) ?: [];
32
33 $widths[(string)$column_name] = [
34 self::OPTION_UNIT => $column_width->get_unit(),
35 self::OPTION_VALUE => $column_width->get_value(),
36 ];
37
38 $this->create_storage()->save(
39 (string)$list_id,
40 $widths
41 );
42 }
43
44 public function exists(ListScreenId $list_id): bool
45 {
46 return null !== $this->create_storage()->find((string)$list_id);
47 }
48
49 public function get(ListScreenId $list_id, ColumnId $column_id): ?ColumnWidth
50 {
51 $widths = $this->create_storage()->find((string)$list_id);
52
53 $name = (string)$column_id;
54
55 if ( ! isset($widths[$name])) {
56 return null;
57 }
58
59 return new ColumnWidth(
60 $widths[$name][self::OPTION_UNIT],
61 $widths[$name][self::OPTION_VALUE]
62 );
63 }
64
65 /**
66 * @param ListScreenId $list_id
67 *
68 * @return ColumnWidth[]
69 */
70 public function get_all(ListScreenId $list_id): array
71 {
72 $widths = $this->create_storage()->find((string)$list_id);
73
74 if ( ! $widths) {
75 return [];
76 }
77
78 $column_widths = [];
79
80 foreach ($widths as $column_name => $width) {
81 $column_widths[$column_name] = new ColumnWidth(
82 $width[self::OPTION_UNIT],
83 $width[self::OPTION_VALUE]
84 );
85 }
86
87 return $column_widths;
88 }
89
90 public function delete(ListScreenId $list_id, string $column_name): void
91 {
92 $widths = $this->create_storage()->find(
93 (string)$list_id
94 );
95
96 if ( ! $widths) {
97 return;
98 }
99
100 unset($widths[$column_name]);
101
102 $widths
103 ? $this->create_storage()->save((string)$list_id, $widths)
104 : $this->delete_by_list_id($list_id);
105 }
106
107 public function delete_by_list_id(ListScreenId $list_id): void
108 {
109 $this->create_storage()->delete(
110 (string)$list_id
111 );
112 }
113
114 }