summaryrefslogtreecommitdiff
path: root/idiorm.php
diff options
context:
space:
mode:
authorSimon Holywell <[email protected]>2014-05-28 15:22:59 +0100
committerSimon Holywell <[email protected]>2014-05-28 15:22:59 +0100
commitde4a611d5c3676e3b505c4a6812ccc91ec049d61 (patch)
tree9c4523af5600d021cb3c1c6b786fb54ebbd471f5 /idiorm.php
parenta1b30b9a8889110e5e6bbad06efe36ed0454468a (diff)
parent3f86f09173e4acf0443018121207cffb0e4fe6c7 (diff)
Merge pull request #201 from lrlopez/where_any_is
Multiple OR'ed conditions support
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 ae97e01..ff0ff6e 100644
--- a/idiorm.php
+++ b/idiorm.php
@@ -1214,6 +1214,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) {