Skip to content

Commit 31b1e45

Browse files
Implemented support for NOT IN
1 parent 3f958da commit 31b1e45

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/Skeleton/Pager/Sql/Condition.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,17 @@ public function get_comparison() {
9393
*/
9494
public function __toString() {
9595
$db = Database::get();
96-
if ($this->comparison == 'IN') {
96+
if ($this->comparison == 'IN' || $this->comparison == 'NOT IN') {
97+
$not = '';
98+
if ($this->comparison == 'NOT IN') {
99+
$not = 'NOT ';
100+
}
97101
if (!is_array($this->value)) {
98-
throw new \Exception('Error in condition: the IN value specified for ' . $this->local_field . ' must be an array');
102+
throw new \Exception('Error in condition: the ' . $not . 'IN value specified for ' . $this->local_field . ' must be an array');
99103
}
100104

101105
if (empty($this->value) === true) {
102-
return $db->quote_identifier($this->local_field) . ' IN (NULL)';
106+
return $db->quote_identifier($this->local_field) . ' ' . $not . 'IN (NULL)';
103107
}
104108

105109
/**
@@ -120,10 +124,10 @@ public function __toString() {
120124
$condition = '( ';
121125
if (count($non_null) > 0 ) {
122126
$list = implode(', ', $db->quote($non_null));
123-
$condition .= $db->quote_identifier($this->local_field) . ' IN (' . $list . ')';
127+
$condition .= $db->quote_identifier($this->local_field) . ' ' . $not . 'IN (' . $list . ')';
124128
}
125129
if (count($null) > 0) {
126-
$condition .= ' OR ' . $db->quote_identifier($this->local_field) . ' IS NULL )';
130+
$condition .= ' OR ' . $db->quote_identifier($this->local_field) . ' IS ' . $not . 'NULL )';
127131
}
128132
$condition .= ') ';
129133

0 commit comments

Comments
 (0)