column.php
1.55 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
<?php
/**
* A column in a list table in wp-admin
*/
abstract class P2P_Column {
protected $ctype;
protected $connected = array();
function __construct( $directed ) {
$this->ctype = $directed;
$this->column_id = sprintf(
'p2p-%s-%s',
$this->ctype->get_direction(),
$this->ctype->name
);
}
function add_column( $columns ) {
$this->prepare_items();
$labels = $this->ctype->get( 'current', 'labels' );
$title = isset( $labels->column_title )
? $labels->column_title
: $this->ctype->get( 'current', 'title' );
return array_splice( $columns, 0, -1 ) + array( $this->column_id => $title ) + $columns;
}
abstract protected function get_items();
protected function prepare_items() {
$items = $this->get_items();
$extra_qv = array(
'p2p:per_page' => -1,
'p2p:context' => 'admin_column',
);
$connected = $this->ctype->get_connected( $items, $extra_qv, 'abstract' );
$this->connected = scb_list_group_by( $connected->items, '_p2p_get_other_id' );
}
function styles() {
?>
<style type="text/css">
.column-<?php echo $this->column_id; ?> ul {
margin-top: 0;
margin-bottom: 0;
}
</style>
<?php
}
abstract function get_admin_link( $item );
protected function render_column( $column, $item_id ) {
if ( $this->column_id != $column ) {
return;
}
if ( ! isset( $this->connected[ $item_id ] ) ) {
return;
}
$out = '<ul>';
foreach ( $this->connected[ $item_id ] as $item ) {
$out .= html( 'li', html_link( $this->get_admin_link( $item ), $item->get_title() ) );
}
$out .= '</ul>';
return $out;
}
}