Author.php
1.17 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
<?php
namespace ACP\Search\Comparison\Post;
use AC;
use ACP\Helper\Select;
use ACP\Helper\Select\Formatter;
use ACP\Helper\Select\Group;
use ACP\Search\Comparison\SearchableValues;
use ACP\Search\Operators;
class Author extends PostField
implements SearchableValues {
/**
* @var string
*/
private $post_type;
public function __construct( $post_type ) {
$operators = new Operators( [
Operators::EQ,
Operators::CURRENT_USER,
] );
$this->post_type = $post_type;
parent::__construct( $operators );
}
protected function get_field() {
return 'post_author';
}
/**
* @param string $post_type
*
* @return int[]
*/
private function get_author_ids( $post_type ) {
global $wpdb;
return $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = %s;", $post_type ) );
}
public function get_values( $search, $paged ) {
$entities = new Select\Entities\User( [
'search' => $search,
'paged' => $paged,
'include' => $this->get_author_ids( $this->post_type ),
] );
return new AC\Helper\Select\Options\Paginated(
$entities,
new Group\UserRole(
new Formatter\UserName( $entities )
)
);
}
}