diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-04-05 16:57:51 +0000 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-04-05 16:57:51 +0000 |
commit | f1eec57221f9bca047ff8d422ade1e26df0fa233 (patch) | |
tree | 8d271693657c7383be277742caaeaa9a81ccde9d | |
parent | 15fc9b9399ede22879c5f5a6ff95d058986d0278 (diff) |
Add a weight column to the items model. Change the album ordering to
use this as the default instead of id. This prepares the way for
manual reordering in the organize functionality.
-rw-r--r-- | core/helpers/album.php | 4 | ||||
-rw-r--r-- | core/helpers/core_installer.php | 3 | ||||
-rw-r--r-- | core/helpers/movie.php | 2 | ||||
-rw-r--r-- | core/helpers/photo.php | 2 | ||||
-rw-r--r-- | core/models/item.php | 5 | ||||
-rw-r--r-- | core/tests/Albums_Controller_Test.php | 2 | ||||
-rw-r--r-- | core/tests/ORM_MPTT_Test.php | 6 | ||||
-rw-r--r-- | installer/install.sql | 5 | ||||
-rw-r--r-- | modules/user/views/admin_users.html.php | 3 |
9 files changed, 20 insertions, 12 deletions
diff --git a/core/helpers/album.php b/core/helpers/album.php index ecb8b5ff..db816470 100644 --- a/core/helpers/album.php +++ b/core/helpers/album.php @@ -46,7 +46,7 @@ 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_column = "weight"; $album->sort_order = "ASC"; while (ORM::factory("item") @@ -93,7 +93,7 @@ class album_Core { $sort_order->dropdown("column", array("id" => "gAlbumSortColumn")) ->label(t("Sort by")) - ->options(array("id" => t("select a column"), + ->options(array("weight" => t("Default"), "created" => t("Creation Date"), "title" => t("Title"), "updated" => t("Updated Date"), diff --git a/core/helpers/core_installer.php b/core/helpers/core_installer.php index ef1afa19..7bdcd376 100644 --- a/core/helpers/core_installer.php +++ b/core/helpers/core_installer.php @@ -76,6 +76,7 @@ class core_installer { `rand_key` float default NULL, `sort_column` varchar(64) default NULL, `sort_order` char(4) default 'ASC', + `weight` int(9) NOT NULL default 0, PRIMARY KEY (`id`), KEY `parent_id` (`parent_id`), KEY `type` (`type`), @@ -201,7 +202,7 @@ class core_installer { $root->level = 1; $root->thumb_dirty = 1; $root->resize_dirty = 1; - $root->sort_column = "id"; + $root->sort_column = "weight"; $root->sort_order = "ASC"; $root->save(); access::add_item($root); diff --git a/core/helpers/movie.php b/core/helpers/movie.php index 59258dd9..658bc185 100644 --- a/core/helpers/movie.php +++ b/core/helpers/movie.php @@ -63,7 +63,7 @@ class movie_Core { $movie->mime_type = strtolower($pi["extension"]) == "mp4" ? "video/mp4" : "video/x-flv"; $movie->thumb_dirty = 1; $movie->resize_dirty = 1; - $movie->sort_column = "id"; + $movie->sort_column = "weight"; $movie->rand_key = ((float)mt_rand()) / (float)mt_getrandmax(); // Randomize the name if there's a conflict diff --git a/core/helpers/photo.php b/core/helpers/photo.php index 72e43419..a3f88ecb 100644 --- a/core/helpers/photo.php +++ b/core/helpers/photo.php @@ -63,7 +63,7 @@ class photo_Core { $photo->mime_type = empty($image_info['mime']) ? "application/unknown" : $image_info['mime']; $photo->thumb_dirty = 1; $photo->resize_dirty = 1; - $photo->sort_column = "id"; + $photo->sort_column = "weight"; $photo->rand_key = ((float)mt_rand()) / (float)mt_getrandmax(); // Randomize the name if there's a conflict diff --git a/core/models/item.php b/core/models/item.php index 528752e8..b28f71fe 100644 --- a/core/models/item.php +++ b/core/models/item.php @@ -295,6 +295,11 @@ class Item_Model extends ORM_MPTT { $this->updated = time(); if (!$this->loaded) { $this->created = $this->updated; + // let albums have a weight of zero so they come first + if (!$this->is_album()) { + $r = ORM::factory("item")->select("MAX(weight) as max_weight")->find(); + $this->weight = $r->max_weight + 1; + } } } return parent::save(); diff --git a/core/tests/Albums_Controller_Test.php b/core/tests/Albums_Controller_Test.php index b43ae01b..747b7427 100644 --- a/core/tests/Albums_Controller_Test.php +++ b/core/tests/Albums_Controller_Test.php @@ -31,7 +31,7 @@ class Albums_Controller_Test extends Unit_Test_Case { $_POST["name"] = "new name"; $_POST["title"] = "new title"; $_POST["description"] = "new description"; - $_POST["column"] = "id"; + $_POST["column"] = "weight"; $_POST["direction"] = "ASC"; $_POST["csrf"] = access::csrf_token(); $_POST["_method"] = "put"; diff --git a/core/tests/ORM_MPTT_Test.php b/core/tests/ORM_MPTT_Test.php index 2aeea58c..f443862b 100644 --- a/core/tests/ORM_MPTT_Test.php +++ b/core/tests/ORM_MPTT_Test.php @@ -29,7 +29,7 @@ class ORM_MPTT_Test extends Unit_Test_Case { $album = ORM::factory("item"); $album->type = "album"; $album->rand_key = ((float)mt_rand()) / (float)mt_getrandmax(); - $album->sort_column = "id"; + $album->sort_column = "weight"; $album->sort_order = "ASC"; $album->add_to_parent($root); @@ -155,7 +155,7 @@ class ORM_MPTT_Test extends Unit_Test_Case { $parent = ORM::factory("item"); $parent->type = "album"; $parent->rand_key = ((float)mt_rand()) / (float)mt_getrandmax(); - $parent->sort_column = "id"; + $parent->sort_column = "weight"; $parent->sort_order = "ASC"; $parent->add_to_parent($root); @@ -166,7 +166,7 @@ class ORM_MPTT_Test extends Unit_Test_Case { $album1 = ORM::factory("item"); $album1->type = "album"; $album1->rand_key = ((float)mt_rand()) / (float)mt_getrandmax(); - $album1->sort_column = "id"; + $album1->sort_column = "weight"; $album1->sort_order = "ASC"; $album1->add_to_parent($parent); diff --git a/installer/install.sql b/installer/install.sql index 9b1b40f3..a55aa8be 100644 --- a/installer/install.sql +++ b/installer/install.sql @@ -139,6 +139,7 @@ CREATE TABLE {items} ( `rand_key` float default NULL, `sort_column` varchar(64) default NULL, `sort_order` char(4) default 'ASC', + `weight` int(9) NOT NULL default '0', `view_1` tinyint(2) NOT NULL default '0', `view_2` tinyint(2) NOT NULL default '0', PRIMARY KEY (`id`), @@ -147,7 +148,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,UNIX_TIMESTAMP(),'',NULL,1,1,1,NULL,NULL,NULL,0,NULL,NULL,1,2,NULL,NULL,1,'Gallery','album',UNIX_TIMESTAMP(),0,NULL,NULL,'id','ASC',1,1); +INSERT INTO {items} VALUES (NULL,UNIX_TIMESTAMP(),'',NULL,1,1,1,NULL,NULL,NULL,0,NULL,NULL,1,2,NULL,NULL,1,'Gallery','album',UNIX_TIMESTAMP(),0,NULL,NULL,'weight','ASC',0,1,1); DROP TABLE IF EXISTS {items_tags}; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; @@ -325,4 +326,4 @@ CREATE TABLE {vars} ( UNIQUE KEY `module_name` (`module_name`,`name`) ) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; -INSERT INTO {vars} VALUES (1,'core','active_site_theme','default'),(2,'core','active_admin_theme','admin_default'),(3,'core','page_size','9'),(4,'core','thumb_size','200'),(5,'core','resize_size','640'),(6,'core','default_locale','en_US'),(7,'core','graphics_toolkit','imagemagick'),(8,'core','graphics_toolkit_path','/usr/bin'),(9,'core','blocks_dashboard_sidebar','a:4:{i:1804289383;a:2:{i:0;s:4:\"core\";i:1;s:11:\"block_adder\";}i:846930886;a:2:{i:0;s:4:\"core\";i:1;s:5:\"stats\";}i:1681692777;a:2:{i:0;s:4:\"core\";i:1;s:13:\"platform_info\";}i:1714636915;a:2:{i:0;s:4:\"core\";i:1;s:12:\"project_news\";}}'),(10,'core','blocks_dashboard_center','a:4:{i:1957747793;a:2:{i:0;s:4:\"core\";i:1;s:7:\"welcome\";}i:424238335;a:2:{i:0;s:4:\"core\";i:1;s:12:\"photo_stream\";}i:719885386;a:2:{i:0;s:4:\"core\";i:1;s:11:\"log_entries\";}i:1649760492;a:2:{i:0;s:7:\"comment\";i:1;s:15:\"recent_comments\";}}'),(11,'core','version','3.0 Alpha 3'),(12,'comment','spam_caught','0'); +INSERT INTO {vars} VALUES (1,'core','active_site_theme','default'),(2,'core','active_admin_theme','admin_default'),(3,'core','page_size','9'),(4,'core','thumb_size','200'),(5,'core','resize_size','640'),(6,'core','default_locale','en_US'),(7,'core','graphics_toolkit','imagemagick'),(8,'core','graphics_toolkit_path','/usr/bin'),(9,'core','blocks_dashboard_sidebar','a:4:{i:1804289383;a:2:{i:0;s:4:\"core\";i:1;s:11:\"block_adder\";}i:846930886;a:2:{i:0;s:4:\"core\";i:1;s:5:\"stats\";}i:1681692777;a:2:{i:0;s:4:\"core\";i:1;s:13:\"platform_info\";}i:1714636915;a:2:{i:0;s:4:\"core\";i:1;s:12:\"project_news\";}}'),(10,'core','blocks_dashboard_center','a:4:{i:1957747793;a:2:{i:0;s:4:\"core\";i:1;s:7:\"welcome\";}i:424238335;a:2:{i:0;s:4:\"core\";i:1;s:12:\"photo_stream\";}i:719885386;a:2:{i:0;s:4:\"core\";i:1;s:11:\"log_entries\";}i:1649760492;a:2:{i:0;s:7:\"comment\";i:1;s:15:\"recent_comments\";}}'),(11,'core','version','3.0 pre-beta svn'),(12,'comment','spam_caught','0'); diff --git a/modules/user/views/admin_users.html.php b/modules/user/views/admin_users.html.php index 67dd297d..05a1138e 100644 --- a/modules/user/views/admin_users.html.php +++ b/modules/user/views/admin_users.html.php @@ -83,8 +83,9 @@ </td> <td class="gActions"> <a href="<?= url::site("admin/users/edit_user_form/$user->id") ?>" + open_text="<?= t("close") ?>" class="gPanelLink gButtonLink ui-state-default ui-corner-all ui-icon-left"> - <span class="ui-icon ui-icon-pencil"></span><?= t("edit") ?></a> + <span class="ui-icon ui-icon-pencil"></span><span class="gButtonText"><?= t("edit") ?></span></a> <? if (user::active()->id != $user->id && !$user->guest): ?> <a href="<?= url::site("admin/users/delete_user_form/$user->id") ?>" class="gDialogLink gButtonLink ui-state-default ui-corner-all ui-icon-left"> |