In.php
1.1 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
<?php
namespace ACP\Search\Helper\Sql\Comparison;
use ACP\Search\Helper\Sql\Comparison;
use ACP\Search\Value;
use LogicException;
class In extends Comparison
implements Negatable {
/**
* @param string $column
* @param Value $value
*/
public function __construct( $column, Value $value ) {
$operator = 'IN';
if ( $this->is_negated() ) {
$operator = 'NOT ' . $operator;
}
parent::__construct( $column, $operator, $value );
}
public function get_statement() {
return $this->column . ' ' . $this->operator . ' (?)';
}
public function is_negated() {
return false;
}
public function bind_value( Value $value ) {
if ( ! is_array( $value->get_value() ) ) {
throw new LogicException( 'Value can only be an array.' );
}
$type = $value->get_type();
$values = $value->get_value();
foreach ( $values as $new_value ) {
parent::bind_value( new Value( $new_value, $type ) );
}
return $this;
}
public function prepare() {
$this->statement = str_replace( '?', implode( ', ', array_fill( 0, count( $this->values ), '?' ) ), $this->statement );
return parent::prepare();
}
}