diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-03-08 16:29:01 +0000 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-03-08 16:29:01 +0000 |
commit | 39954ad0b77800b3d4935430794adf18c2625148 (patch) | |
tree | a9016b38fa2b1ed0e9a20276457f2011a4a70f27 | |
parent | bf6c814e81a00d6aec3cacdecd3b93b90cf73a3e (diff) |
Implement Sortable albums. Current sort fields include (Creation
Date, Update Date, Random Key, Title, Mime Type, Item Type & Number of views)
-rw-r--r-- | core/controllers/albums.php | 14 | ||||
-rw-r--r-- | core/helpers/album.php | 23 | ||||
-rw-r--r-- | core/helpers/core_installer.php | 1 | ||||
-rw-r--r-- | core/libraries/ORM_MPTT.php | 12 | ||||
-rw-r--r-- | installer/install.sql | 3 |
5 files changed, 47 insertions, 6 deletions
diff --git a/core/controllers/albums.php b/core/controllers/albums.php index 4ceb323d..ea5fc860 100644 --- a/core/controllers/albums.php +++ b/core/controllers/albums.php @@ -50,10 +50,16 @@ class Albums_Controller extends Items_Controller { url::redirect("albums/$album->id?page=$max_pages"); } + $sort_order = $album->sort_column; + if (!empty($sort_order)) { + list ($sort_column, $sort_direction) = explode(" ", $sort_order); + $sort_order = array($sort_column => $sort_direction); + } + $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)); + $template->set_global("children", $album->viewable()->children($page_size, $offset, $sort_order)); $template->set_global("children_count", $children_count); $template->set_global("parents", $album->parents()); $template->content = new View("album.html"); @@ -153,6 +159,12 @@ 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 = $sort_column . " " . $form->edit_album->sort_order->direction->value; + } else { + $album->sort_column = null; + } $album->save(); module::event("item_updated", $orig, $album); diff --git a/core/helpers/album.php b/core/helpers/album.php index c75095be..d93840c1 100644 --- a/core/helpers/album.php +++ b/core/helpers/album.php @@ -85,6 +85,29 @@ 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")); + if (empty($parent->sort_order)) { + list ($sort_column, $sort_direction) = explode(" ", $parent->sort_column); + } 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"), + "created" => t("Creation Date"), + "mime_type" => t("Mime Type"), + "title" => t("Title"), + "type" => t("Type"), + "updated" => t("Updated Date"), + "view_count" => t("Number of views"), + "rand_key" => t("Random"))) + ->selected($sort_column); + $sort_order->dropdown("direction", array("id" => "gAlbumSortDirection")) + ->label(t("Order")) + ->options(array("ASC" => t("Ascending"), + "DESC" => t("Descending"))) + ->selected($sort_direction); $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 83c6907a..3a1013e0 100644 --- a/core/helpers/core_installer.php +++ b/core/helpers/core_installer.php @@ -78,6 +78,7 @@ class core_installer { `view_count` int(9) default 0, `width` int(9) default NULL, `rand_key` float default NULL, + `sort_column` varchar(255) default NULL, PRIMARY KEY (`id`), KEY `parent_id` (`parent_id`), KEY `type` (`type`), diff --git a/core/libraries/ORM_MPTT.php b/core/libraries/ORM_MPTT.php index 7e89bf6f..6b493e88 100644 --- a/core/libraries/ORM_MPTT.php +++ b/core/libraries/ORM_MPTT.php @@ -142,10 +142,14 @@ class ORM_MPTT_Core extends ORM { * @param integer SQL offset * @return array ORM */ - function children($limit=null, $offset=0) { - return $this->where("parent_id", $this->id) - ->orderby("id", "ASC") - ->find_all($limit, $offset); + function children($limit=null, $offset=0, $orderby=null) { + $this->where("parent_id", $this->id); + if (empty($orderby)) { + $this->orderby("id", "ASC"); + } else { + $this->orderby($orderby); + } + return $this->find_all($limit, $offset); } /** diff --git a/installer/install.sql b/installer/install.sql index c280a99b..a3ae66ef 100644 --- a/installer/install.sql +++ b/installer/install.sql @@ -139,13 +139,14 @@ CREATE TABLE {items} ( `view_1` tinyint(2) NOT NULL default '0', `view_2` tinyint(2) NOT NULL default '0', `rand_key` float default NULL, + `sort_column` varchar(255) default NULL, PRIMARY KEY (`id`), KEY `parent_id` (`parent_id`), KEY `type` (`type`), KEY `random` (`rand_key` DESC) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; -INSERT INTO {items} VALUES (NULL,1234232381,'Welcome to your Gallery3',NULL,1,1,1,NULL,NULL,2,0,NULL,NULL,1,2,NULL,NULL,1,'Gallery','album',1234232381,0,NULL,1,1,NULL); +INSERT INTO {items} VALUES (NULL,1234232381,'Welcome to your Gallery3',NULL,1,1,1,NULL,NULL,2,0,NULL,NULL,1,2,NULL,NULL,1,'Gallery','album',1234232381,0,NULL,1,1,NULL,NULL); DROP TABLE IF EXISTS `items_tags`; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; |