PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 7.0.13
Admin Columns v7.0.13
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 / Response / JsonListScreenSettingsFactory.php
codepress-admin-columns / classes / Response Last commit date
Json.php 5 months ago JsonColumnFactory.php 5 months ago JsonListScreenSettingsFactory.php 5 months ago
JsonListScreenSettingsFactory.php
209 lines
1 <?php
2
3 declare(strict_types=1);
4
5 namespace AC\Response;
6
7 use AC;
8 use AC\Admin\Banner\BannerContextResolver;
9 use AC\ListScreen;
10 use AC\Setting\Encoder;
11 use AC\Storage\EncoderFactory;
12 use AC\Type\StartingPrice;
13 use AC\Type\Url\Preview;
14 use AC\Type\Url\Site;
15 use AC\Type\Url\UtmTags;
16
17 class JsonListScreenSettingsFactory
18 {
19
20 private EncoderFactory $encoder_factory;
21
22 private AC\ColumnTypeRepository $type_repository;
23
24 private AC\ColumnGroups $column_groups;
25
26 private BannerContextResolver $banner_context_resolver;
27
28 public function __construct(
29 EncoderFactory $encoder_factory,
30 AC\ColumnTypeRepository $type_repository,
31 AC\ColumnGroups $column_groups,
32 BannerContextResolver $banner_context_resolver
33 ) {
34 $this->encoder_factory = $encoder_factory;
35 $this->type_repository = $type_repository;
36 $this->column_groups = $column_groups;
37 $this->banner_context_resolver = $banner_context_resolver;
38 }
39
40 public function create(ListScreen $list_screen, bool $is_stored = true, bool $is_template = false): Json
41 {
42 $encoder = $this->encoder_factory
43 ->create()
44 ->set_list_screen($list_screen);
45
46 $table_screen = $list_screen->get_table_screen();
47
48 $context = $this->banner_context_resolver->resolve($table_screen);
49
50 return (new Json())->set_parameters([
51 'read_only' => $list_screen->is_read_only(),
52 'table_url' => $is_template
53 ? (string)new Preview($list_screen->get_table_url(), 'columns')
54 : (string)$list_screen->get_table_url(),
55 'settings' => $encoder->encode(),
56 'column_types' => $this->get_column_types($table_screen),
57 'column_settings' => $this->encode_column_settings($list_screen->get_columns()),
58 'is_stored' => $is_stored,
59 'is_template' => $is_template,
60 'labels' => [
61 'singular' => $table_screen->get_labels()->get_singular(),
62 'plural' => $table_screen->get_labels()->get_plural(),
63 ],
64 'pro_banner' => $context
65 ? $context->get_arguments($table_screen)
66 : $this->get_default_banner_arguments($table_screen),
67 ]);
68 }
69
70 private function get_column_types(AC\TableScreen $table_screen): array
71 {
72 $column_types = [];
73
74 $original_types = $this->get_original_types($table_screen);
75
76 foreach ($this->type_repository->find_all($table_screen) as $column) {
77 $group = $this->column_groups->find($column->get_group());
78 $label = $this->get_clean_label($column);
79
80 $column_type = [
81 'label' => $label,
82 'value' => $column->get_type(),
83 'group' => $group ? $group->get_label() : __('Default', 'codepress-admin-columns'),
84 'group_key' => $column->get_group(),
85 'original' => in_array($column->get_type(), $original_types, true),
86 'searchable_label' => $label,
87 ];
88
89 if ('custom' !== $column->get_group()) {
90 $column_type['searchable_label'] .= ' ' . $column_type['group'];
91 }
92
93 $description = $column->get_description();
94 if ($description !== null) {
95 $column_type['description'] = $description;
96 }
97
98 $column_types[] = $column_type;
99 }
100
101 usort($column_types, function ($a, $b) {
102 // ignore original columns
103 if ($a['original'] || $b['original']) {
104 return 0;
105 }
106
107 return strcasecmp($a['label'], $b['label']);
108 });
109
110 return $column_types;
111 }
112
113 private function get_original_types(AC\TableScreen $table_screen): array
114 {
115 $types = [];
116 foreach ($this->type_repository->find_all_by_original($table_screen) as $column) {
117 $types[] = $column->get_type();
118 }
119
120 return $types;
121 }
122
123 private function get_clean_label(AC\Column $column): string
124 {
125 $label = $column->get_label();
126
127 if (strip_tags($label) === '') {
128 $label = ucfirst(str_replace('_', ' ', $column->get_type()));
129 }
130
131 return strip_tags($label);
132 }
133
134 private function encode_column_settings(AC\ColumnIterator $columns): array
135 {
136 $settings = [];
137
138 foreach ($columns as $column) {
139 $settings[(string)$column->get_id()] = (new Encoder($column->get_settings()))->encode();
140 }
141
142 return $settings;
143 }
144
145 private function get_default_banner_arguments(AC\TableScreen $table_screen): array
146 {
147 $upgrade_url = new UtmTags(Site::create_admin_columns_pro(), 'banner');
148
149 $plural = $table_screen->get_labels()->get_plural();
150 $singular = $table_screen->get_labels()->get_singular();
151
152 if (mb_strlen($plural) > 30) {
153 $plural = __('content', 'codepress-admin-columns');
154 $singular = __('item', 'codepress-admin-columns');
155 }
156
157 $plural_lower = mb_strtolower($plural);
158 $singular_lower = mb_strtolower($singular);
159
160 return [
161 'title' => sprintf(
162 __('Manage your %s faster', 'codepress-admin-columns'),
163 $plural_lower
164 ),
165 'description' => sprintf(
166 __('Turn your %1$s overview into a workspace for sorting, editing, filtering, and exporting - without opening a single %2$s.', 'codepress-admin-columns'),
167 $plural_lower,
168 $singular_lower
169 ),
170 'upgrade_cta' => sprintf(__('Manage your %s faster', 'codepress-admin-columns'), $plural_lower),
171 'upgrade_cta_price' => sprintf(
172 '%s · %s',
173 sprintf(
174 /* translators: %s: price (e.g. $79) */
175 __('from %s/year', 'codepress-admin-columns'),
176 StartingPrice::get()
177 ),
178 __('all features included', 'codepress-admin-columns')
179 ),
180 'features' => [
181 [
182 'url' => $upgrade_url->with_content('usp-editing')->get_url(),
183 'label' => __('Inline edit directly in the table', 'codepress-admin-columns'),
184 ],
185 [
186 'url' => $upgrade_url->with_content('usp-sorting')->get_url(),
187 'label' => __('Sort and filter on any column', 'codepress-admin-columns'),
188 ],
189 [
190 'url' => $upgrade_url->with_content('usp-bulk-edit')->get_url(),
191 'label' => sprintf(
192 __('Bulk edit hundreds of %s at once', 'codepress-admin-columns'),
193 $plural_lower
194 ),
195 ],
196 [
197 'url' => $upgrade_url->with_content('usp-export')->get_url(),
198 'label' => __('Export table data to CSV', 'codepress-admin-columns'),
199 ],
200 [
201 'url' => $upgrade_url->with_content('usp-column-sets')->get_url(),
202 'label' => __('Multiple views per screen', 'codepress-admin-columns'),
203 ],
204 ],
205 'promo_url' => $upgrade_url->get_url(),
206 ];
207 }
208
209 }