summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2009-03-09 13:30:22 +0000
committerTim Almdal <tnalmdal@shaw.ca>2009-03-09 13:30:22 +0000
commitc0375db79f47b4e4e0b1c261929389c6d3995edc (patch)
tree7c8c5fd3b02cb12fb12361d738f591faea08adac /core
parentcaa0a6d47fb5ed3faa0c321c10c86c5b6f3d7db8 (diff)
Restructure the sort order to maintain the sort column and sort order
as two separate columns in the item table.
Diffstat (limited to 'core')
-rw-r--r--core/controllers/albums.php16
-rw-r--r--core/helpers/album.php19
-rw-r--r--core/helpers/core_installer.php1
3 files changed, 13 insertions, 23 deletions
diff --git a/core/controllers/albums.php b/core/controllers/albums.php
index 96a6f401..2a55ecac 100644
--- a/core/controllers/albums.php
+++ b/core/controllers/albums.php
@@ -50,13 +50,11 @@ class Albums_Controller extends Items_Controller {
url::redirect("albums/$album->id?page=$max_pages");
}
- $sort_order = $album->sort_column;
- $sort_order = !empty($sort_order) ? unserialize($sort_order) : $sort_order;
-
$template = new Theme_View("page.html", "album");
$template->set_global("page_size", $page_size);
$template->set_global("item", $album);
- $template->set_global("children", $album->viewable()->children($page_size, $offset, $sort_order));
+ $template->set_global("children", $album->viewable()->children($page_size, $offset,
+ array($album->sort_column => $album->sort_order)));
$template->set_global("children_count", $children_count);
$template->set_global("parents", $album->parents());
$template->content = new View("album.html");
@@ -156,13 +154,9 @@ class Albums_Controller extends Items_Controller {
$orig = clone $album;
$album->title = $form->edit_album->title->value;
$album->description = $form->edit_album->description->value;
- $sort_column = $form->edit_album->sort_order->column->value;
- if (!empty($sort_column)) {
- $album->sort_column = serialize(array($sort_column =>
- $form->edit_album->sort_order->direction->value));
- } else {
- $album->sort_column = null;
- }
+ $album->sort_column = $form->edit_album->sort_order->column->value;
+ $album->sort_order = $form->edit_album->sort_order->direction->value;
+
$album->save();
module::event("item_updated", $orig, $album);
diff --git a/core/helpers/album.php b/core/helpers/album.php
index 72008cd5..ecb8b5ff 100644
--- a/core/helpers/album.php
+++ b/core/helpers/album.php
@@ -46,6 +46,8 @@ class album_Core {
$album->thumb_dirty = 1;
$album->resize_dirty = 1;
$album->rand_key = ((float)mt_rand()) / (float)mt_getrandmax();
+ $album->sort_column = "id";
+ $album->sort_order = "ASC";
while (ORM::factory("item")
->where("parent_id", $parent->id)
@@ -85,31 +87,24 @@ class album_Core {
}
$group->input("title")->label(t("Title"))->value($parent->title);
$group->textarea("description")->label(t("Description"))->value($parent->description);
+
$sort_order = $group->group("sort_order", array("id" => "gAlbumSortOrder"))
->label(t("Sort Order"));
- $sort_column = $parent->sort_column;
- if (!empty($sort_column)) {
- $sort_column = unserialize($sort_column);
- $columns = array_keys($sort_column);
- $sort_direction = $sort_column[$columns[0]];
- $sort_column = $columns[0];
- } else {
- list ($sort_column, $sort_direction) = array("", "ASC");
- }
+
$sort_order->dropdown("column", array("id" => "gAlbumSortColumn"))
->label(t("Sort by"))
- ->options(array("" => t("select a column"),
+ ->options(array("id" => t("select a column"),
"created" => t("Creation Date"),
"title" => t("Title"),
"updated" => t("Updated Date"),
"view_count" => t("Number of views"),
"rand_key" => t("Random")))
- ->selected($sort_column);
+ ->selected($parent->sort_column);
$sort_order->dropdown("direction", array("id" => "gAlbumSortDirection"))
->label(t("Order"))
->options(array("ASC" => t("Ascending"),
"DESC" => t("Descending")))
- ->selected($sort_direction);
+ ->selected($parent->sort_order);
$group->hidden("type")->value("album");
$group->submit("")->value(t("Modify"));
$form->add_rules_from(ORM::factory("item"));
diff --git a/core/helpers/core_installer.php b/core/helpers/core_installer.php
index bee06181..706ff548 100644
--- a/core/helpers/core_installer.php
+++ b/core/helpers/core_installer.php
@@ -79,6 +79,7 @@ class core_installer {
`width` int(9) default NULL,
`rand_key` float default NULL,
`sort_column` varchar(64) default NULL,
+ `sort_order` char(4) default 'ASC',
PRIMARY KEY (`id`),
KEY `parent_id` (`parent_id`),
KEY `type` (`type`),