From c0375db79f47b4e4e0b1c261929389c6d3995edc Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Mon, 9 Mar 2009 13:30:22 +0000 Subject: Restructure the sort order to maintain the sort column and sort order as two separate columns in the item table. --- core/helpers/album.php | 19 +++++++------------ core/helpers/core_installer.php | 1 + 2 files changed, 8 insertions(+), 12 deletions(-) (limited to 'core/helpers') 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`), -- cgit v1.2.3