Media.php
1.11 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
<?php
namespace ACA\ACF\Search\Comparison\Repeater;
use AC;
use ACA\ACF\Search\Comparison;
use ACP;
use ACP\Search\Comparison\SearchableValues;
use ACP\Search\Operators;
class Media extends Comparison\Repeater
implements SearchableValues {
/**
* @var string
*/
private $mime_type;
public function __construct( $meta_type, $parent_key, $sub_key, $mime_type = null ) {
$this->mime_type = $mime_type;
$operators = new Operators( [
Operators::EQ,
] );
parent::__construct( $meta_type, $parent_key, $sub_key, $operators );
}
protected function get_search_entities( $s, $paged ) {
return new ACP\Helper\Select\Entities\Post( [
's' => $s,
'paged' => $paged,
'post_type' => 'attachment',
'post_mime_type' => $this->mime_type,
'orderby' => 'date',
'order' => 'DESC',
] );
}
public function get_values( $s, $paged ) {
$entities = $this->get_search_entities( $s, $paged );
return new AC\Helper\Select\Options\Paginated(
$entities,
new ACP\Helper\Select\Group\MimeType( new ACP\Helper\Select\Formatter\PostTitle( $entities ) )
);
}
}