ReplyTo.php
1.2 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
<?php
namespace ACP\Search\Comparison\Comment;
use AC;
use ACP\Helper\Select;
use ACP\Search\Comparison;
use ACP\Search\Operators;
use ACP\Search\Query\Bindings;
use ACP\Search\Value;
class ReplyTo extends Comparison
implements Comparison\SearchableValues {
public function __construct() {
$operators = new Operators( [
Operators::EQ,
] );
parent::__construct( $operators );
}
protected function create_query_bindings( $operator, Value $value ) {
$bindings = new Bindings\Comment();
return $bindings->parent( $value->get_value() );
}
public function get_values( $search, $paged ) {
$args = compact( 'search', 'paged' );
$args['comment__in'] = $this->get_parents();
$entities = new Select\Entities\Comment( $args );
return new AC\Helper\Select\Options\Paginated(
$entities,
new Select\Formatter\CommentSummary( $entities )
);
}
/**
* @return array|false
*/
private function get_parents() {
global $wpdb;
$limit = 5000;
$results = $wpdb->get_col( "
SELECT DISTINCT( comment_parent )
FROM {$wpdb->comments}
WHERE comment_parent != ''
LIMIT {$limit}
" );
if ( ! $results || $limit <= count( $results ) ) {
return false;
}
return $results;
}
}