Album first
mbuild
![]()
Joined: 2012-10-09
Posts: 4 |
![]() |
Help me, please. How to organize items with "Albums fist" functions, as it was in Gallery2. |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
You have to manually do that in G3. So if the feature is that important stay with G2. Dave |
|
mbuild
![]()
Joined: 2012-10-09
Posts: 4 |
![]() |
Thank you, Dave. |
|
llryo
Joined: 2010-06-20
Posts: 12 |
![]() |
I just tried it and successfully did it by modify the database record. Someone could probably create a module for this. To make it more permanent, you can modify the file below. ../modules/gallery/helpers/album.php BEFORE: /** * Return a structured set of all the possible sort orders. */ static function get_sort_order_options() { return array("weight" => t("Manual"), "captured" => t("Date captured"), "created" => t("Date uploaded"), "title" => t("Title"), "name" => t("File name"), "updated" => t("Date modified"), "view_count" => t("Number of views"), "rand_key" => t("Random")); } AFTER: /** * Return a structured set of all the possible sort orders. */ static function get_sort_order_options() { return array("`type ASC, `weight" => t("Manual"), "`type ASC, `captured" => t("Date captured"), "`type ASC, `created" => t("Date uploaded"), "`type ASC, `title" => t("Title"), "`type ASC, `name" => t("File name"), "`type ASC, `updated" => t("Date modified"), "`type ASC, `view_count" => t("Number of views"), "`type ASC, `rand_key" => t("Random")); } |
|
llryo
Joined: 2010-06-20
Posts: 12 |
![]() |
The above code did work too well testing... scrap that idea and it's too intrusive. Here is a less intrusive way. The filter is added dynamically. ../modules/gallery/models/item.php lines added: $order_by = array_merge(array("type" => "ASC"), $order_by); BEFORE: /** * Return all of the children of this album. Unless you specify a specific sort order, the * results will be ordered by this album's sort order. * * @chainable * @param integer SQL limit * @param integer SQL offset * @param array additional where clauses * @param array order_by * @return array ORM */ function children($limit=null, $offset=null, $where=array(), $order_by=null) { if (empty($order_by)) { $order_by = array($this->sort_column => $this->sort_order); // Use id as a tie breaker if ($this->sort_column != "id") { $order_by["id"] = "ASC"; } } return parent::children($limit, $offset, $where, $order_by); } /** * Return the children of this album, and all of it's sub-albums. Unless you specify a specific * sort order, the results will be ordered by this album's sort order. Note that this * album's sort order is imposed on all sub-albums, regardless of their sort order. * * @chainable * @param integer SQL limit * @param integer SQL offset * @param array additional where clauses * @return object ORM_Iterator */ function descendants($limit=null, $offset=null, $where=array(), $order_by=null) { if (empty($order_by)) { $order_by = array($this->sort_column => $this->sort_order); // Use id as a tie breaker if ($this->sort_column != "id") { $order_by["id"] = "ASC"; } } return parent::descendants($limit, $offset, $where, $order_by); } AFTER: /** * Return all of the children of this album. Unless you specify a specific sort order, the * results will be ordered by this album's sort order. * * @chainable * @param integer SQL limit * @param integer SQL offset * @param array additional where clauses * @param array order_by * @return array ORM */ function children($limit=null, $offset=null, $where=array(), $order_by=null) { if (empty($order_by)) { $order_by = array($this->sort_column => $this->sort_order); // Use id as a tie breaker if ($this->sort_column != "id") { $order_by["id"] = "ASC"; } $order_by = array_merge(array("type" => "ASC"), $order_by); } return parent::children($limit, $offset, $where, $order_by); } /** * Return the children of this album, and all of it's sub-albums. Unless you specify a specific * sort order, the results will be ordered by this album's sort order. Note that this * album's sort order is imposed on all sub-albums, regardless of their sort order. * * @chainable * @param integer SQL limit * @param integer SQL offset * @param array additional where clauses * @return object ORM_Iterator */ function descendants($limit=null, $offset=null, $where=array(), $order_by=null) { if (empty($order_by)) { $order_by = array($this->sort_column => $this->sort_order); // Use id as a tie breaker if ($this->sort_column != "id") { $order_by["id"] = "ASC"; } $order_by = array_merge(array("type" => "ASC"), $order_by); } return parent::descendants($limit, $offset, $where, $order_by); } |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
Thanks for the contribution! Quote:
Someone could probably create a module for this. Why not take a crack at this yourself? Dave |
|
llryo
Joined: 2010-06-20
Posts: 12 |
![]() |
I don't quite like the solution. It sorts all the types alphabetically. In essence, "albums", "movies", then "photos" first, then the secondary sort will be the user configured sort. I would love to have more control honestly. If there are no movies, this solutions works fine. I have an idea to make it complete user configurable but can't seem to get it quite working. Any help will be appreciated. I'm not great at PHP and don't know an easy way to debug. The values for 1,2,3 can be replaced with an admin page to determine sort order. ../system/libraries/Database_Builder.php /** * Compiles the builder object into a SQL query * * @return string Compiled query */ protected function compile() { ... if ( ! empty($this->order_by)) { $sql .= "\nORDER BY "; //$sql .= "\n CASE `type` WHEN 'album' THEN 1 WHEN 'movie' THEN 2 WHEN 'photo' THEN 3 ELSE 9 END , "; //$sql .= "\n CASE `type` WHEN 'album' THEN name ELSE null END , "; $sql .= $this->compile_order_by(); } ... } |
|
tempg
Joined: 2005-12-17
Posts: 1857 |
![]() |
@llryo: I've seen others request this before. It may not be 100% the way you want it, but it could be of great use to others the way it is, pending your additions to it. (You can update the module later if you add new features, etc.) |
|