summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/gallery/helpers/item.php15
-rw-r--r--modules/gallery/tests/Item_Helper_Test.php18
2 files changed, 19 insertions, 14 deletions
diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php
index dbad59b9..f38d9888 100644
--- a/modules/gallery/helpers/item.php
+++ b/modules/gallery/helpers/item.php
@@ -208,20 +208,25 @@ class item_Core {
return $model;
}
-
+
+ /**
+ * Return an item by path.
+ * @param string $path
+ * @return object item
+ */
static function find_by_path($path) {
- $path = trim($path, '/');
+ $path = trim($path, "/");
// The root path name is NULL, not '', hence this workaround.
if ($path == '') {
- return ORM::factory("item", 1);
+ return ORM::factory("item", item::root());
}
$paths = explode("/", $path);
$count = count($paths);
foreach (ORM::factory("item")
- ->where('name', '=', $paths[$count - 1])
- ->where('level', '=', $count + 1)
+ ->where("name", "=", $paths[$count - 1])
+ ->where("level", "=", $count + 1)
->find_all() as $item) {
if (urldecode($item->relative_path()) == $path) {
return $item;
diff --git a/modules/gallery/tests/Item_Helper_Test.php b/modules/gallery/tests/Item_Helper_Test.php
index 1fced654..4bc64ff0 100644
--- a/modules/gallery/tests/Item_Helper_Test.php
+++ b/modules/gallery/tests/Item_Helper_Test.php
@@ -130,46 +130,46 @@ class Item_Helper_Test extends Gallery_Unit_Test_Case {
$level1 = test::random_album();
$level2 = test::random_album($level1);
$level3 = test::random_photo($level2);
- $level3->name = 'same.jpg';
+ $level3->name = "same.jpg";
$level3->save();
$level2b = test::random_album($level1);
$level3b = test::random_photo($level2b);
- $level3b->name = 'same.jpg';
+ $level3b->name = "same.jpg";
$level3b->save();
// Item in album
$this->assert_same(
- item::find_by_path('/' . $level1->name . '/' . $level2->name . '/' . $level3->name)->id,
+ item::find_by_path("/" . $level1->name . "/" . $level2->name . "/" . $level3->name)->id,
$level3->id);
// Album, ends with a slash
$this->assert_same(
- item::find_by_path($level1->name . '/' . $level2->name . '/')->id,
+ item::find_by_path($level1->name . "/" . $level2->name . "/")->id,
$level2->id);
// Album, ends without a slash
$this->assert_same(
- item::find_by_path('/' . $level1->name . '/' . $level2->name)->id,
+ item::find_by_path("/" . $level1->name . "/" . $level2->name)->id,
$level2->id);
// Return root if '' is passed
$this->assert_same(
- item::find_by_path('')->id,
+ item::find_by_path("")->id,
"1");
// Verify that we don't get confused by the part names
$this->assert_same(
- item::find_by_path($level1->name . '/' . $level2->name . '/' . $level3->name)->id,
+ item::find_by_path($level1->name . "/" . $level2->name . "/" . $level3->name)->id,
$level3->id);
$this->assert_same(
- item::find_by_path($level1->name . '/' . $level2b->name . '/' . $level3b->name)->id,
+ item::find_by_path($level1->name . "/" . $level2b->name . "/" . $level3b->name)->id,
$level3b->id);
// Verify that we don't get false positives
$this->assert_same(
- item::find_by_path('foo/bar/baz'),
+ item::find_by_path("foo/bar/baz"),
false);
}