-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathScreenController.php
89 lines (69 loc) · 2.02 KB
/
ScreenController.php
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
89
<?php
namespace AC;
use AC\ColumnRepository\Sort\ManualOrder;
use AC\ListScreen\ManageValue;
class ScreenController implements Registerable
{
/**
* @var ListScreen
*/
private $list_screen;
/**
* @var array
*/
private $headings = [];
/**
* @var DefaultColumnsRepository
*/
private $default_columns;
public function __construct(ListScreen $list_screen)
{
$this->list_screen = $list_screen;
$this->default_columns = new DefaultColumnsRepository();
}
public function register(): void
{
// Headings
add_filter($this->list_screen->get_heading_hookname(), [$this, 'add_headings'], 200);
// Values
if ($this->list_screen instanceof ManageValue) {
$this->list_screen->manage_value()->register();
}
do_action('ac/table/list_screen', $this->list_screen);
}
/**
* @param $columns
*
* @return array
* @since 2.0
*/
public function add_headings($columns)
{
if (empty($columns)) {
return $columns;
}
if ( ! wp_doing_ajax()) {
$this->default_columns->update($this->list_screen->get_key(), $columns);
}
// Run once
if ($this->headings) {
return $this->headings;
}
// Nothing stored. Show default columns on screen.
if ( ! $this->list_screen->get_settings()) {
return $columns;
}
// Add mandatory checkbox
if (isset($columns['cb'])) {
$this->headings['cb'] = $columns['cb'];
}
$column_repository = new ColumnRepository($this->list_screen);
$args = [
ColumnRepository::ARG_SORT => new ManualOrder($this->list_screen->get_id()),
];
foreach ($column_repository->find_all($args) as $column) {
$this->headings[$column->get_name()] = $column->get_custom_label();
}
return apply_filters('ac/headings', $this->headings, $this->list_screen);
}
}