summaryrefslogtreecommitdiff
path: root/idiorm.php
diff options
context:
space:
mode:
Diffstat (limited to 'idiorm.php')
-rw-r--r--idiorm.php37
1 files changed, 37 insertions, 0 deletions
diff --git a/idiorm.php b/idiorm.php
index ed22d8b..c73bdb8 100644
--- a/idiorm.php
+++ b/idiorm.php
@@ -1213,6 +1213,43 @@
}
/**
+ * Allows adding a WHERE clause that matches any of the conditions
+ * specified in the array. Each element in the associative array will
+ * be a different condition, where the key will be the column name.
+ *
+ * By default, an equal operator will be used against all columns, but
+ * it can be overriden for any or every column using the second parameter.
+ *
+ * Each condition will be ORed together when added to the final query.
+ */
+ public function where_any_is($values, $operator='=') {
+ $data = array();
+ $query = array("((");
+ $first = true;
+ foreach ($values as $item) {
+ if ($first) {
+ $first = false;
+ } else {
+ $query[] = ") OR (";
+ }
+ $firstsub = true;
+ foreach($item as $key => $item) {
+ $op = is_string($operator) ? $operator : (isset($operator[$key]) ? $operator[$key] : '=');
+ if ($firstsub) {
+ $firstsub = false;
+ } else {
+ $query[] = "AND";
+ }
+ $query[] = $this->_quote_identifier($key);
+ $data[] = $item;
+ $query[] = $op . " ?";
+ }
+ }
+ $query[] = "))";
+ return $this->where_raw(join($query, ' '), $data);
+ }
+
+ /**
* Add a WHERE ... LIKE clause to your query.
*/
public function where_like($column_name, $value=null) {