dropdown.php
1.8 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
<?php
/**
* A dropdown above a list table in wp-admin
*/
abstract class P2P_Dropdown {
protected $ctype;
protected $title;
function __construct( $directed, $title ) {
$this->ctype = $directed;
$this->title = $title;
}
function show_dropdown() {
echo $this->render_dropdown();
}
protected function render_dropdown() {
$direction = $this->ctype->flip_direction()->get_direction();
$labels = $this->ctype->get( 'current', 'labels' );
if ( isset( $labels->dropdown_title ) ) {
$title = $labels->dropdown_title;
} elseif ( isset( $labels->column_title ) ) {
$title = $labels->column_title;
} else {
$title = $this->title;
}
return scbForms::input(
array(
'type' => 'select',
'name' => array( 'p2p', $this->ctype->name, $direction ),
'choices' => self::get_choices( $this->ctype ),
'text' => $title,
),
array_map( 'sanitize_text_field', $_GET )
);
}
protected static function get_qv() {
if ( ! isset( $_GET['p2p'] ) ) {
return array();
}
$args = array();
$tmp = reset( sanitize_text_field( $_GET['p2p'] ) );
$args['connected_type'] = key( sanitize_text_field( $_GET['p2p'] ) );
// list( $args['connected_direction'], $args['connected_items'] ) = each( $tmp );
foreach ($tmp as $key => $value) {
$args['connected_direction'] = $key;
$args['connected_items'] = $value;
break;
}
if ( ! $args['connected_items'] ) {
return array();
}
return $args;
}
protected static function get_choices( $directed ) {
$extra_qv = array(
'p2p:per_page' => -1,
'p2p:context' => 'admin_dropdown',
);
$connected = $directed->get_connected( 'any', $extra_qv, 'abstract' );
$options = array();
foreach ( $connected->items as $item ) {
$options[ $item->get_id() ] = $item->get_title();
}
return $options;
}
}