summaryrefslogtreecommitdiff
path: root/modules/gallery
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2009-11-26 21:14:54 -0800
committerBharat Mediratta <bharat@menalto.com>2009-11-26 21:14:54 -0800
commit96b00d6cfe437e376d5547a10aa8d1cf7def8c13 (patch)
tree355f3df10c86f595e1373a53a0746b877b27489b /modules/gallery
parentb9a0e0963746420d82ad3107135aa7a9256825be (diff)
Convert some more Database::instance() calls to db::build() form.
Diffstat (limited to 'modules/gallery')
-rw-r--r--modules/gallery/helpers/item.php4
-rw-r--r--modules/gallery/libraries/ORM_MPTT.php90
-rw-r--r--modules/gallery/models/item.php6
3 files changed, 63 insertions, 37 deletions
diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php
index 7496d368..c3126435 100644
--- a/modules/gallery/helpers/item.php
+++ b/modules/gallery/helpers/item.php
@@ -140,10 +140,10 @@ class item_Core {
// Guard against an empty result when we create the first item. It's unfortunate that we
// have to check this every time.
// @todo: figure out a better way to bootstrap the weight.
- $result = Database::instance()
+ $result = db::build()
->select("weight")->from("items")
->order_by("weight", "desc")->limit(1)
- ->get()->current();
+ ->execute()->current();
return ($result ? $result->weight : 0) + 1;
}
diff --git a/modules/gallery/libraries/ORM_MPTT.php b/modules/gallery/libraries/ORM_MPTT.php
index a67f05be..0ec0a848 100644
--- a/modules/gallery/libraries/ORM_MPTT.php
+++ b/modules/gallery/libraries/ORM_MPTT.php
@@ -51,10 +51,16 @@ class ORM_MPTT_Core extends ORM {
try {
// Make a hole in the parent for this new item
- $this->db->query(
- "UPDATE {{$this->table_name}} SET `left_ptr` = `left_ptr` + 2 WHERE `left_ptr` >= {$parent->right_ptr}");
- $this->db->query(
- "UPDATE {{$this->table_name}} SET `right_ptr` = `right_ptr` + 2 WHERE `right_ptr` >= {$parent->right_ptr}");
+ $this->db_builder
+ ->update($this->table_name)
+ ->set("left_ptr", new Database_Expression("`left_ptr` + 2"))
+ ->where("left_ptr", ">=", $parent->right_ptr)
+ ->execute();
+ $this->db_builder
+ ->update($this->table_name)
+ ->set("right_ptr", new Database_Expression("`right_ptr` + 2"))
+ ->where("right_ptr", ">=", $parent->right_ptr)
+ ->execute();
$parent->right_ptr += 2;
// Insert this item into the hole
@@ -92,10 +98,16 @@ class ORM_MPTT_Core extends ORM {
$this->lock();
try {
- $this->db->query(
- "UPDATE {{$this->table_name}} SET `left_ptr` = `left_ptr` - 2 WHERE `left_ptr` > {$this->right_ptr}");
- $this->db->query(
- "UPDATE {{$this->table_name}} SET `right_ptr` = `right_ptr` - 2 WHERE `right_ptr` > {$this->right_ptr}");
+ $this->db_builder
+ ->update($this->table_name)
+ ->set("left_ptr", new Database_Expression("`left_ptr` - 2"))
+ ->where("left_ptr", ">", $this->right_ptr)
+ ->execute();
+ $this->db_builder
+ ->update($this->table_name)
+ ->set("right_ptr", new Database_Expression("`right_ptr` - 2"))
+ ->where("right_ptr", ">", $this->right_ptr)
+ ->execute();
} catch (Exception $e) {
$this->unlock();
throw $e;
@@ -239,23 +251,32 @@ class ORM_MPTT_Core extends ORM {
try {
if ($level_delta) {
// Update the levels for the to-be-moved items
- $this->db->query(
- "UPDATE {{$this->table_name}} SET `level` = `level` + $level_delta" .
- " WHERE `left_ptr` >= $original_left_ptr AND `right_ptr` <= $original_right_ptr");
+ $this->db_builder
+ ->update($this->table_name)
+ ->set("level", new Database_Expression("`level` + $level_delta"))
+ ->where("left_ptr", ">=", $original_left_ptr)
+ ->where("right_ptr", "<=", $original_right_ptr)
+ ->execute();
}
// Make a hole in the target for the move
- $target->db->query(
- "UPDATE {{$this->table_name}} SET `left_ptr` = `left_ptr` + $size_of_hole" .
- " WHERE `left_ptr` >= $target_right_ptr");
- $target->db->query(
- "UPDATE {{$this->table_name}} SET `right_ptr` = `right_ptr` + $size_of_hole" .
- " WHERE `right_ptr` >= $target_right_ptr");
+ $target->db_builder
+ ->update($this->table_name)
+ ->set("left_ptr", new Database_Expression("`left_ptr` + $size_of_hole"))
+ ->where("left_ptr", ">=", $target_right_ptr)
+ ->execute();
+ $target->db_builder
+ ->update($this->table_name)
+ ->set("right_ptr", new Database_Expression("`right_ptr` + $size_of_hole"))
+ ->where("right_ptr", ">=", $target_right_ptr)
+ ->execute();
// Change the parent.
- $this->db->query(
- "UPDATE {{$this->table_name}} SET `parent_id` = {$target->id}" .
- " WHERE `id` = {$this->id}");
+ $this->db_builder
+ ->update($this->table_name)
+ ->set("parent_id", $target->id)
+ ->where("id", "=", $this->id)
+ ->execute();
// If the source is to the right of the target then we just adjusted its left_ptr and right_ptr above.
$left_ptr = $original_left_ptr;
@@ -266,20 +287,25 @@ class ORM_MPTT_Core extends ORM {
}
$new_offset = $target->right_ptr - $left_ptr;
- $this->db->query(
- "UPDATE {{$this->table_name}}" .
- " SET `left_ptr` = `left_ptr` + $new_offset," .
- " `right_ptr` = `right_ptr` + $new_offset" .
- " WHERE `left_ptr` >= $left_ptr" .
- " AND `right_ptr` <= $right_ptr");
+ $this->db_builder
+ ->update($this->table_name)
+ ->set("left_ptr", new Database_Expression("`left_ptr` + $new_offset"))
+ ->set("right_ptr", new Database_Expression("`right_ptr` + $new_offset"))
+ ->where("left_ptr", ">=", $left_ptr)
+ ->where("right_ptr", "<=", $right_ptr)
+ ->execute();
// Close the hole in the source's parent after the move
- $this->db->query(
- "UPDATE {{$this->table_name}} SET `left_ptr` = `left_ptr` - $size_of_hole" .
- " WHERE `left_ptr` > $right_ptr");
- $this->db->query(
- "UPDATE {{$this->table_name}} SET `right_ptr` = `right_ptr` - $size_of_hole" .
- " WHERE `right_ptr` > $right_ptr");
+ $this->db_builder
+ ->update($this->table_name)
+ ->set("left_ptr", new Database_Expression("`left_ptr` - $size_of_hole"))
+ ->where("left_ptr", ">", $right_ptr)
+ ->execute();
+ $this->db_builder
+ ->update($this->table_name)
+ ->set("right_ptr", new Database_Expression("`right_ptr` - $size_of_hole"))
+ ->where("right_ptr", ">", $right_ptr)
+ ->execute();
} catch (Exception $e) {
$this->unlock();
throw $e;
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index 16c57dbc..8a42cc1e 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -285,14 +285,14 @@ class Item_Model extends ORM_MPTT {
private function _build_relative_caches() {
$names = array();
$slugs = array();
- foreach (Database::instance()
+ foreach (db::build()
->select(array("name", "slug"))
->from("items")
->where("left_ptr", "<=", $this->left_ptr)
->where("right_ptr", ">=", $this->right_ptr)
->where("id", "<>", 1)
->order_by("left_ptr", "ASC")
- ->get() as $row) {
+ ->execute() as $row) {
// Don't encode the names segment
$names[] = rawurlencode($row->name);
$slugs[] = rawurlencode($row->slug);
@@ -489,7 +489,7 @@ class Item_Model extends ORM_MPTT {
->where("parent_id", "=", $this->id)
->merge_where($where)
->order_by($order_by)
- ->get() as $row) {
+ ->execute() as $row) {
$position++;
if ($row->id == $child->id) {
break;