diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-03-09 13:30:22 +0000 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-03-09 13:30:22 +0000 |
commit | c0375db79f47b4e4e0b1c261929389c6d3995edc (patch) | |
tree | 7c8c5fd3b02cb12fb12361d738f591faea08adac | |
parent | caa0a6d47fb5ed3faa0c321c10c86c5b6f3d7db8 (diff) |
Restructure the sort order to maintain the sort column and sort order
as two separate columns in the item table.
-rw-r--r-- | core/controllers/albums.php | 16 | ||||
-rw-r--r-- | core/helpers/album.php | 19 | ||||
-rw-r--r-- | core/helpers/core_installer.php | 1 | ||||
-rw-r--r-- | installer/install.sql | 3 |
4 files changed, 15 insertions, 24 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`), diff --git a/installer/install.sql b/installer/install.sql index 501f8f1d..48434b08 100644 --- a/installer/install.sql +++ b/installer/install.sql @@ -138,6 +138,7 @@ CREATE TABLE {items} ( `width` int(9) default NULL, `rand_key` float default NULL, `sort_column` varchar(64) default NULL, + `sort_order` char(4) default 'ASC', `view_1` tinyint(2) NOT NULL default '0', `view_2` tinyint(2) NOT NULL default '0', PRIMARY KEY (`id`), @@ -146,7 +147,7 @@ CREATE TABLE {items} ( KEY `random` (`rand_key`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; -INSERT INTO {items} VALUES (NULL,1236569573,'',NULL,1,1,1,NULL,NULL,NULL,0,NULL,NULL,1,2,NULL,NULL,1,'Gallery','album',1236569573,0,NULL,NULL,NULL,1,1); +INSERT INTO {items} VALUES (NULL,1236569573,'',NULL,1,1,1,NULL,NULL,NULL,0,NULL,NULL,1,2,NULL,NULL,1,'Gallery','album',1236569573,0,NULL,NULL,'id','ASC',1,1); DROP TABLE IF EXISTS {items_tags}; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; |