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 / RequestHandler / Ajax / ListScreenOriginalColumns.php
codepress-admin-columns / classes / RequestHandler / Ajax Last commit date
AdminGeneralOptionsGet.php 3 days ago AdminGeneralOptionsPersist.php 3 days ago CustomFieldKeys.php 3 days ago EditorMenuFavorites.php 3 days ago EditorMenuStatus.php 3 days ago ExtendedValue.php 3 days ago IntegrationToggle.php 3 days ago Integrations.php 3 days ago ListScreenAddColumn.php 3 days ago ListScreenDelete.php 3 days ago ListScreenOriginalColumns.php 3 days ago ListScreenSave.php 3 days ago ListScreenSelectColumn.php 3 days ago ListScreenSettings.php 3 days ago NetworkPostStati.php 3 days ago NumberFormat.php 3 days ago RestoreSettingsRequest.php 3 days ago ScreenOptions.php 3 days ago
ListScreenOriginalColumns.php
101 lines
1 <?php
2
3 declare(strict_types=1);
4
5 namespace AC\RequestHandler\Ajax;
6
7 use AC\Capabilities;
8 use AC\Column;
9 use AC\ColumnCollection;
10 use AC\ColumnTypeRepository;
11 use AC\DefaultColumnHandler;
12 use AC\Nonce;
13 use AC\Request;
14 use AC\RequestAjaxHandler;
15 use AC\Response;
16 use AC\Setting\Encoder;
17 use AC\TableScreenFactory\Aggregate;
18 use AC\Type\TableId;
19
20 class ListScreenOriginalColumns implements RequestAjaxHandler
21 {
22 private Aggregate $table_screen_factory;
23
24 private ColumnTypeRepository $column_type_repository;
25
26 private DefaultColumnHandler $default_column_handler;
27
28 public function __construct(
29 Aggregate $table_screen_factory,
30 ColumnTypeRepository $column_type_repository,
31 DefaultColumnHandler $default_column_handler
32 ) {
33 $this->table_screen_factory = $table_screen_factory;
34 $this->column_type_repository = $column_type_repository;
35 $this->default_column_handler = $default_column_handler;
36 }
37
38 public function handle(): void
39 {
40 if (! current_user_can(Capabilities::MANAGE)) {
41 return;
42 }
43
44 $request = new Request();
45 $response = new Response\Json();
46
47 if (! (new Nonce\Ajax())->verify($request)) {
48 $response->error();
49 }
50
51 $list_key = new TableId($request->get('list_key'));
52
53 if (! $this->table_screen_factory->can_create($list_key)) {
54 $response->error();
55 }
56
57 $table_screen = $this->table_screen_factory->create($list_key);
58
59 $default_columns = $this->default_column_handler->handle(
60 $table_screen,
61 $this->column_type_repository->find_all_original($table_screen)
62 );
63
64 $response->set_parameter('columns', $this->get_columns($default_columns));
65 $response->set_parameter('config', $this->get_config($default_columns));
66 $response->success();
67 }
68
69 private function get_name(Column $column): string
70 {
71 return (string)$column->get_id();
72 }
73
74 private function get_config(ColumnCollection $columns): array
75 {
76 $settings = [];
77
78 foreach ($columns as $column) {
79 $settings[$this->get_name($column)] = (new Encoder($column->get_settings()))->encode();
80 }
81
82 return $settings;
83 }
84
85 private function get_columns(ColumnCollection $columns): array
86 {
87 $abstracts = [];
88
89 foreach ($columns as $column) {
90 $abstracts[] = [
91 'type' => $column->get_type(),
92 'label' => $column->get_label(),
93 'name' => $this->get_name($column),
94 ];
95 }
96
97 return $abstracts;
98 }
99
100 }
101