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 / Request / Middleware / TableScreenAdmin.php
codepress-admin-columns / classes / Request / Middleware Last commit date
ListScreenAdmin.php 3 months ago ListScreenTable.php 3 months ago TableScreenAdmin.php 3 months ago
TableScreenAdmin.php
88 lines
1 <?php
2
3 namespace AC\Request\Middleware;
4
5 use AC\Admin\Preference;
6 use AC\Middleware;
7 use AC\Request;
8 use AC\Table\TableScreenCollection;
9 use AC\TableScreen;
10 use AC\Type\TableId;
11 use Exception;
12
13 class TableScreenAdmin implements Middleware
14 {
15
16 private Preference\EditorPreference $preference;
17
18 private TableScreenCollection $table_screens;
19
20 public function __construct(
21 Preference\EditorPreference $preference,
22 TableScreenCollection $table_screens
23 ) {
24 $this->preference = $preference;
25 $this->table_screens = $table_screens;
26 }
27
28 private function get_table_screen_by_id(TableId $table_id): ?TableScreen
29 {
30 foreach ($this->table_screens as $table_screen) {
31 if ($table_screen->get_id()->equals($table_id)) {
32 return $table_screen;
33 }
34 }
35
36 return null;
37 }
38
39 private function get_requested_table_screen(Request $request): ?TableScreen
40 {
41 try {
42 $key = new TableId((string)$request->get('list_screen'));
43 } catch (Exception $e) {
44 return null;
45 }
46
47 return $this->get_table_screen_by_id($key);
48 }
49
50 private function get_last_visited_table_screen(): ?TableScreen
51 {
52 $table_id = $this->preference->get_table_id();
53
54 return $table_id ?
55 $this->get_table_screen_by_id($table_id)
56 : null;
57 }
58
59 private function get_first_visit_table_screen(): ?TableScreen
60 {
61 $table_screen = $this->get_table_screen_by_id(new TableId('post'));
62
63 return $table_screen ?: $this->table_screens->offsetGet($this->table_screens->count() - 1);
64 }
65
66 private function get_table_screen(Request $request): ?TableScreen
67 {
68 $table_screen = $this->get_requested_table_screen($request);
69
70 if ( ! $table_screen) {
71 $table_screen = $this->get_last_visited_table_screen();
72 }
73
74 if ( ! $table_screen) {
75 $table_screen = $this->get_first_visit_table_screen();
76 }
77
78 return $table_screen;
79 }
80
81 public function handle(Request $request): void
82 {
83 $request->get_parameters()->merge([
84 'table_screen' => $this->get_table_screen($request),
85 ]);
86 }
87
88 }