summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/gallery/controllers/movies.php2
-rw-r--r--modules/gallery/controllers/photos.php2
-rw-r--r--modules/gallery/libraries/ORM_MPTT.php8
-rw-r--r--modules/gallery/models/item.php16
-rw-r--r--modules/kohana23_compat/libraries/MY_Database_Builder.php31
5 files changed, 46 insertions, 13 deletions
diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php
index 7ceeefdf..157c388f 100644
--- a/modules/gallery/controllers/movies.php
+++ b/modules/gallery/controllers/movies.php
@@ -21,7 +21,7 @@ class Movies_Controller extends Items_Controller {
public function _show($movie) {
access::required("view", $movie);
- $where = array("type != " => "album");
+ $where = array(array("type", "!=", "album"));
$position = $movie->parent()->get_position($movie, $where);
if ($position > 1) {
list ($previous_item, $ignore, $next_item) =
diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php
index 0d7daac4..478447b1 100644
--- a/modules/gallery/controllers/photos.php
+++ b/modules/gallery/controllers/photos.php
@@ -21,7 +21,7 @@ class Photos_Controller extends Items_Controller {
public function _show($photo) {
access::required("view", $photo);
- $where = array("type != " => "album");
+ $where = array(array("type", "!=", "album"));
$position = $photo->parent()->get_position($photo, $where);
if ($position > 1) {
list ($previous_item, $ignore, $next_item) =
diff --git a/modules/gallery/libraries/ORM_MPTT.php b/modules/gallery/libraries/ORM_MPTT.php
index 01b2d7b7..90b9d38a 100644
--- a/modules/gallery/libraries/ORM_MPTT.php
+++ b/modules/gallery/libraries/ORM_MPTT.php
@@ -152,7 +152,7 @@ class ORM_MPTT_Core extends ORM {
*/
function children($limit=null, $offset=0, $where=null, $order_by=array("id" => "ASC")) {
if ($where) {
- $this->where($where);
+ $this->merge_where($where);
}
return $this
@@ -170,7 +170,7 @@ class ORM_MPTT_Core extends ORM {
*/
function children_count($where=null) {
if ($where) {
- $this->where($where);
+ $this->merge_where($where);
}
return $this
@@ -189,7 +189,7 @@ class ORM_MPTT_Core extends ORM {
*/
function descendants($limit=null, $offset=0, $where=null, $order_by=array("id" => "ASC")) {
if ($where) {
- $this->where($where);
+ $this->merge_where($where);
}
return $this
@@ -207,7 +207,7 @@ class ORM_MPTT_Core extends ORM {
*/
function descendants_count($where=null) {
if ($where) {
- $this->where($where);
+ $this->merge_where($where);
}
return $this
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index c8d25cc5..acc4e96f 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -428,14 +428,14 @@ class Item_Model extends ORM_MPTT {
} else {
$comp = "<";
}
- $db = Database::instance();
+ $db = db::build();
// If the comparison column has NULLs in it, we can't use comparators on it and will have to
// deal with it the hard way.
$count = $db->from("items")
->where("parent_id", "=", $this->id)
->where($this->sort_column, "=", NULL)
- ->where($where)
+ ->merge_where($where)
->count_records();
if (empty($count)) {
@@ -445,7 +445,7 @@ class Item_Model extends ORM_MPTT {
$position = $db->from("items")
->where("parent_id", "=", $this->id)
->where($sort_column, $comp, $child->$sort_column)
- ->where($where)
+ ->merge_where($where)
->count_records();
// We stopped short of our target value in the sort (notice that we're using a < comparator
@@ -456,12 +456,14 @@ class Item_Model extends ORM_MPTT {
//
// Fix this by doing a 2nd query where we iterate over the equivalent columns and add them to
// our base value.
- foreach ($db->from("items")
+ foreach ($db
+ ->select("id")
+ ->from("items")
->where("parent_id", "=", $this->id)
->where($sort_column, "=", $child->$sort_column)
- ->where($where)
+ ->merge_where($where)
->order_by(array("id" => "ASC"))
- ->get() as $row) {
+ ->execute() as $row) {
$position++;
if ($row->id == $child->id) {
break;
@@ -485,7 +487,7 @@ class Item_Model extends ORM_MPTT {
foreach ($db->select("id")
->from("items")
->where("parent_id", "=", $this->id)
- ->where($where)
+ ->merge_where($where)
->order_by($order_by)
->get() as $row) {
$position++;
diff --git a/modules/kohana23_compat/libraries/MY_Database_Builder.php b/modules/kohana23_compat/libraries/MY_Database_Builder.php
new file mode 100644
index 00000000..974f9c6d
--- /dev/null
+++ b/modules/kohana23_compat/libraries/MY_Database_Builder.php
@@ -0,0 +1,31 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2009 Bharat Mediratta
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+class Database_Builder extends Database_Builder_Core {
+ /**
+ * Merge in a series of where clause tuples and call where() on each one.
+ * @chainable
+ */
+ public function merge_where($tuples) {
+ foreach ($tuples as $tuple) {
+ $this->where($tuple[0], $tuple[1], $tuple[2]);
+ }
+ return $this;
+ }
+} \ No newline at end of file