summaryrefslogtreecommitdiff
path: root/modules/gallery/helpers
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2009-08-17 23:47:39 +0800
committerTim Almdal <tnalmdal@shaw.ca>2009-08-18 05:21:17 +0800
commit24d7f5df8c8a18b9ac017fb7b4fc92974b5435cc (patch)
treea5cb70054576f47344469c155517c21cff5f4b2d /modules/gallery/helpers
parentafa8cade7fc948b064636d4e9ecfb03e4c2c67d7 (diff)
Refactor the get maximum weight functionality into a method in the item helper, so that we can use it else where (i.e. the new organize module)
Signed-off-by: Tim Almdal <tnalmdal@shaw.ca>
Diffstat (limited to 'modules/gallery/helpers')
-rw-r--r--modules/gallery/helpers/item.php14
1 files changed, 14 insertions, 0 deletions
diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php
index 80c25862..5504dc95 100644
--- a/modules/gallery/helpers/item.php
+++ b/modules/gallery/helpers/item.php
@@ -137,4 +137,18 @@ class item_Core {
$group->submit("")->value(t("Delete"));
return $form;
}
+
+ /**
+ * Get the next weight value
+ */
+ static function get_max_weight() {
+ // 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()
+ ->select("weight")->from("items")
+ ->orderby("weight", "desc")->limit(1)
+ ->get()->current();
+ return ($result ? $result->weight : 0) + 1;
+ }
} \ No newline at end of file