summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/helpers/album.php4
-rw-r--r--core/helpers/core_installer.php3
-rw-r--r--core/helpers/movie.php2
-rw-r--r--core/helpers/photo.php2
-rw-r--r--core/models/item.php5
-rw-r--r--core/tests/Albums_Controller_Test.php2
-rw-r--r--core/tests/ORM_MPTT_Test.php6
7 files changed, 15 insertions, 9 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);