-
Notifications
You must be signed in to change notification settings - Fork 259
Expand file tree
/
Copy pathdropdown.php
More file actions
74 lines (54 loc) · 1.54 KB
/
Copy pathdropdown.php
File metadata and controls
74 lines (54 loc) · 1.54 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
<?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,
), $_GET );
}
protected static function get_qv() {
if ( !isset( $_GET['p2p'] ) )
return array();
$args = array();
$tmp = reset( $_GET['p2p'] );
$args['connected_type'] = key( $_GET['p2p'] );
$args['connected_direction'] = key( $tmp );
$args['connected_items'] = current( $tmp );
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;
}
}