Skip to content

Commit

Permalink
Add the not: filter to do basic negation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
brendo committed Oct 30, 2010
1 parent 6aee2a0 commit afaa656
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions fields/field.selectbox_link.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ public function buildDSRetrivalSQL($data, &$joins, &$where, $andOperation=false)
}
}
else {
$negation = false;
if(preg_match('/^not:/', $data[0])) {
$data[0] = preg_replace('/^not:/', null, $data[0]);
$negation = true;
}

foreach($data as $key => &$value) {
// for now, I assume string values are the only possible handles.
// of course, this is not entirely true, but I find it good enough.
Expand Down Expand Up @@ -448,15 +454,18 @@ public function buildDSRetrivalSQL($data, &$joins, &$where, $andOperation=false)
}
}

if($andOperation):
if($andOperation) {
$condition = ($negation) ? '!=' : '=';
foreach($data as $key => $bit){
$joins .= " LEFT JOIN `tbl_entries_data_$field_id` AS `t$field_id$key` ON (`e`.`id` = `t$field_id$key`.entry_id) ";
$where .= " AND `t$field_id$key`.relation_id = '$bit' ";
$where .= " AND `t$field_id$key`.relation_id $condition '$bit' ";
}
else:
}
else {
$condition = ($negation) ? 'NOT IN' : 'IN';
$joins .= " LEFT JOIN `tbl_entries_data_$field_id` AS `t$field_id` ON (`e`.`id` = `t$field_id`.entry_id) ";
$where .= " AND `t$field_id`.relation_id IN ('".@implode("', '", $data)."') ";
endif;
$where .= " AND `t$field_id`.relation_id $condition ('".implode("', '", $data)."') ";
}

}

Expand Down

0 comments on commit afaa656

Please sign in to comment.