Media.php
1.3 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 ACA\MetaBox\Search\Comparison\Table;
use AC;
use ACP;
class Media extends TableStorage
implements ACP\Search\Comparison\SearchableValues {
use MultiMapTrait;
/**
* @var
*/
private $mime_type;
public function __construct(
$operators,
$table,
$column,
$mime_type = [],
$value_type = null,
ACP\Search\Labels $labels = null
) {
$this->mime_type = $mime_type;
parent::__construct( $operators, $table, $column, $value_type, $labels );
}
public function get_values( $s, $paged ) {
$args = [
's' => $s,
'paged' => $paged,
'post_type' => 'attachment',
'orderby' => 'date',
'order' => 'DESC',
];
if ( $this->mime_type ) {
$args['post_mime_type'] = $this->mime_type;
}
$entities = new ACP\Helper\Select\Entities\Post( $args );
return new AC\Helper\Select\Options\Paginated(
$entities,
new ACP\Helper\Select\Group\MimeType( new ACP\Helper\Select\Formatter\PostTitle( $entities ) )
);
}
protected function get_subquery( $operator, ACP\Search\Value $value ) {
$_operator = $this->map_operator( $operator );
$_value = $this->map_value( $value, $operator );
$where = ACP\Search\Helper\Sql\ComparisonFactory::create( $this->column, $_operator, $_value );
return "SELECT ID FROM {$this->table} WHERE " . $where->prepare();
}
}