TableListScreenSetter.php
1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
namespace AC\Controller;
use AC\Asset\Location\Absolute;
use AC\ColumnSize;
use AC\ListScreenRepository\Storage;
use AC\ListScreenTypes;
use AC\PermissionChecker;
use AC\Registerable;
use AC\Request;
use AC\Table;
use AC\Type\ListScreenId;
use WP_Screen;
class TableListScreenSetter implements Registerable {
/**
* @var Storage
*/
private $storage;
/**
* @var PermissionChecker
*/
private $permission_checker;
/**
* @var Absolute
*/
private $location;
/**
* @var Table\LayoutPreference
*/
private $preference;
public function __construct( Storage $storage, PermissionChecker $permission_checker, Absolute $location, Table\LayoutPreference $preference ) {
$this->storage = $storage;
$this->permission_checker = $permission_checker;
$this->location = $location;
$this->preference = $preference;
}
public function register() {
add_action( 'current_screen', [ $this, 'handle' ] );
}
public function handle( WP_Screen $wp_screen ) {
$request = new Request();
$request->add_middleware( new Middleware\ListScreenTable( $this->storage, $wp_screen, $this->preference ) );
$list_key = $request->get( 'list_key' );
if ( ! $list_key ) {
return;
}
$list_id = $request->get( 'list_id' );
$list_screen = ListScreenId::is_valid_id( $list_id )
? $this->storage->find( new ListScreenId( $list_id ) )
: null;
if ( ! $list_screen || ! $this->permission_checker->is_valid( $list_screen ) ) {
$list_screen = ListScreenTypes::instance()->get_list_screen_by_key( $list_key );
}
if ( ! $list_screen ) {
return;
}
if ( $list_screen->has_id() ) {
$this->preference->set( $list_screen->get_key(), $list_screen->get_id()->get_id() );
}
$table_screen = new Table\Screen(
$this->location,
$list_screen,
new ColumnSize\ListStorage( $this->storage ),
new ColumnSize\UserStorage( new ColumnSize\UserPreference( get_current_user_id() ) )
);
$table_screen->register();
do_action( 'ac/table', $table_screen );
}
}