mirror of
https://github.com/Pathduck/gallery3.git
synced 2026-04-26 07:29:15 -04:00
Change ORM_MPTT::add_to_parent() to take an ORM instead of an id so
that it's consistent with ORM_MPTT::move_to()
This commit is contained in:
@@ -47,7 +47,12 @@ class album_Core {
|
||||
$album->name = "{$name}-" . rand();
|
||||
}
|
||||
|
||||
$album = $album->add_to_parent($parent_id);
|
||||
$parent = ORM::factory("item", $parent_id);
|
||||
if (!$parent->loaded) {
|
||||
throw new Exception("@todo INVALID_PARENT_ID");
|
||||
}
|
||||
|
||||
$album = $album->add_to_parent($parent);
|
||||
mkdir($album->file_path());
|
||||
$thumbnail_dir = dirname($album->thumbnail_path());
|
||||
if (!file_exists($thumbnail_dir)) {
|
||||
|
||||
@@ -69,7 +69,12 @@ class photo_Core {
|
||||
}
|
||||
|
||||
// This saves the photo
|
||||
$photo->add_to_parent($parent_id);
|
||||
$parent = ORM::factory("item", $parent_id);
|
||||
if (!$parent->loaded) {
|
||||
throw new Exception("@todo INVALID_PARENT_ID");
|
||||
}
|
||||
|
||||
$photo->add_to_parent($parent);
|
||||
copy($filename, $photo->file_path());
|
||||
|
||||
// @todo: parameterize these dimensions
|
||||
@@ -84,7 +89,7 @@ class photo_Core {
|
||||
}
|
||||
|
||||
static function get_add_form($parent) {
|
||||
$form = new Forge("albums/{$parent->id}", "", "post",
|
||||
$form = new Forge("albums/{$parent->id}", "", "post",
|
||||
array("id" => "gAddPhotoForm", "enctype" => "multipart/form-data"));
|
||||
$group = $form->group(sprintf(_("Add Photo to %s"), $parent->title));
|
||||
$group->input("name")->label(true);
|
||||
|
||||
@@ -52,12 +52,11 @@ class ORM_MPTT_Core extends ORM {
|
||||
* @param integer $parent_id the id of the parent node
|
||||
* @return ORM
|
||||
*/
|
||||
function add_to_parent($parent_id) {
|
||||
function add_to_parent($parent) {
|
||||
$this->lock();
|
||||
|
||||
try {
|
||||
// Make a hole in the parent for this new item
|
||||
$parent = ORM::factory($this->model_name, $parent_id);
|
||||
$this->db->query(
|
||||
"UPDATE `{$this->table_name}` SET `left` = `left` + 2 WHERE `left` >= {$parent->right}");
|
||||
$this->db->query(
|
||||
|
||||
@@ -50,7 +50,8 @@ class Access_Helper_Test extends Unit_Test_Case {
|
||||
}
|
||||
|
||||
public function adding_and_removing_items_adds_ands_removes_rows_test() {
|
||||
$item = ORM::factory("item")->add_to_parent(1);
|
||||
$root = ORM::factory("item", 1);
|
||||
$item = ORM::factory("item")->add_to_parent($root);
|
||||
|
||||
// Simulate an event
|
||||
access::add_item($item);
|
||||
@@ -70,7 +71,8 @@ class Access_Helper_Test extends Unit_Test_Case {
|
||||
}
|
||||
|
||||
public function can_allow_deny_and_reset_intent_test() {
|
||||
$item = ORM::factory("item")->add_to_parent(1);
|
||||
$root = ORM::factory("item", 1);
|
||||
$item = ORM::factory("item")->add_to_parent($root);
|
||||
access::add_item($item);
|
||||
$intent = ORM::factory("access_intent")->where("item_id", $item->id)->find();
|
||||
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
*/
|
||||
class ORM_MPTT_Test extends Unit_Test_Case {
|
||||
public function add_to_parent_test() {
|
||||
$album = ORM::factory("item")->add_to_parent(1);
|
||||
$root = ORM::factory("item", 1);
|
||||
$album = ORM::factory("item")->add_to_parent($root);
|
||||
|
||||
$this->assert_equal($album->parent()->right - 2, $album->left);
|
||||
$this->assert_equal($album->parent()->right - 1, $album->right);
|
||||
@@ -28,11 +29,12 @@ class ORM_MPTT_Test extends Unit_Test_Case {
|
||||
}
|
||||
|
||||
public function add_hierarchy_test() {
|
||||
$album1 = ORM::factory("item")->add_to_parent(1);
|
||||
$album1_1 = ORM::factory("item")->add_to_parent($album1->id);
|
||||
$album1_2 = ORM::factory("item")->add_to_parent($album1->id);
|
||||
$album1_1_1 = ORM::factory("item")->add_to_parent($album1_1->id);
|
||||
$album1_1_2 = ORM::factory("item")->add_to_parent($album1_1->id);
|
||||
$root = ORM::factory("item", 1);
|
||||
$album1 = ORM::factory("item")->add_to_parent($root);
|
||||
$album1_1 = ORM::factory("item")->add_to_parent($album1);
|
||||
$album1_2 = ORM::factory("item")->add_to_parent($album1);
|
||||
$album1_1_1 = ORM::factory("item")->add_to_parent($album1_1);
|
||||
$album1_1_2 = ORM::factory("item")->add_to_parent($album1_1);
|
||||
|
||||
$album1->reload();
|
||||
$this->assert_equal(9, $album1->right - $album1->left);
|
||||
@@ -42,11 +44,12 @@ class ORM_MPTT_Test extends Unit_Test_Case {
|
||||
}
|
||||
|
||||
public function delete_hierarchy_test() {
|
||||
$album1 = ORM::factory("item")->add_to_parent(1);
|
||||
$album1_1 = ORM::factory("item")->add_to_parent($album1->id);
|
||||
$album1_2 = ORM::factory("item")->add_to_parent($album1->id);
|
||||
$album1_1_1 = ORM::factory("item")->add_to_parent($album1_1->id);
|
||||
$album1_1_2 = ORM::factory("item")->add_to_parent($album1_1->id);
|
||||
$root = ORM::factory("item", 1);
|
||||
$album1 = ORM::factory("item")->add_to_parent($root);
|
||||
$album1_1 = ORM::factory("item")->add_to_parent($album1);
|
||||
$album1_2 = ORM::factory("item")->add_to_parent($album1);
|
||||
$album1_1_1 = ORM::factory("item")->add_to_parent($album1_1);
|
||||
$album1_1_2 = ORM::factory("item")->add_to_parent($album1_1);
|
||||
|
||||
$album1_1->delete();
|
||||
$album1->reload();
|
||||
@@ -83,15 +86,17 @@ class ORM_MPTT_Test extends Unit_Test_Case {
|
||||
}
|
||||
|
||||
public function parent_test() {
|
||||
$album = ORM::factory("item")->add_to_parent(1);
|
||||
$root = ORM::factory("item", 1);
|
||||
$album = ORM::factory("item")->add_to_parent($root);
|
||||
|
||||
$parent = ORM::factory("item", 1);
|
||||
$this->assert_equal($parent->id, $album->parent()->id);
|
||||
}
|
||||
|
||||
public function parents_test() {
|
||||
$outer = ORM::factory("item")->add_to_parent(1);
|
||||
$inner = ORM::factory("item")->add_to_parent($outer->id);
|
||||
$root = ORM::factory("item", 1);
|
||||
$outer = ORM::factory("item")->add_to_parent($root);
|
||||
$inner = ORM::factory("item")->add_to_parent($outer);
|
||||
|
||||
$parent_ids = array();
|
||||
foreach ($inner->parents() as $parent) {
|
||||
@@ -101,9 +106,10 @@ class ORM_MPTT_Test extends Unit_Test_Case {
|
||||
}
|
||||
|
||||
public function children_test() {
|
||||
$outer = ORM::factory("item")->add_to_parent(1);
|
||||
$inner1 = ORM::factory("item")->add_to_parent($outer->id);
|
||||
$inner2 = ORM::factory("item")->add_to_parent($outer->id);
|
||||
$root = ORM::factory("item", 1);
|
||||
$outer = ORM::factory("item")->add_to_parent($root);
|
||||
$inner1 = ORM::factory("item")->add_to_parent($outer);
|
||||
$inner2 = ORM::factory("item")->add_to_parent($outer);
|
||||
|
||||
$child_ids = array();
|
||||
foreach ($outer->children() as $child) {
|
||||
@@ -113,37 +119,41 @@ class ORM_MPTT_Test extends Unit_Test_Case {
|
||||
}
|
||||
|
||||
public function children_limit_test() {
|
||||
$outer = ORM::factory("item")->add_to_parent(1);
|
||||
$inner1 = ORM::factory("item")->add_to_parent($outer->id);
|
||||
$inner2 = ORM::factory("item")->add_to_parent($outer->id);
|
||||
$root = ORM::factory("item", 1);
|
||||
$outer = ORM::factory("item")->add_to_parent($root);
|
||||
$inner1 = ORM::factory("item")->add_to_parent($outer);
|
||||
$inner2 = ORM::factory("item")->add_to_parent($outer);
|
||||
|
||||
$this->assert_equal(array($inner2->id => null), $outer->children(1, 1)->select_list('id'));
|
||||
}
|
||||
|
||||
public function children_count_test() {
|
||||
$outer = ORM::factory("item")->add_to_parent(1);
|
||||
$inner1 = ORM::factory("item")->add_to_parent($outer->id);
|
||||
$inner2 = ORM::factory("item")->add_to_parent($outer->id);
|
||||
$root = ORM::factory("item", 1);
|
||||
$outer = ORM::factory("item")->add_to_parent($root);
|
||||
$inner1 = ORM::factory("item")->add_to_parent($outer);
|
||||
$inner2 = ORM::factory("item")->add_to_parent($outer);
|
||||
|
||||
$this->assert_equal(2, $outer->children_count());
|
||||
}
|
||||
|
||||
public function descendant_test() {
|
||||
$root = ORM::factory("item", 1);
|
||||
|
||||
$parent = ORM::factory("item");
|
||||
$parent->type = "album";
|
||||
$parent->add_to_parent(1);
|
||||
$parent->add_to_parent($root);
|
||||
|
||||
$photo = ORM::factory("item");
|
||||
$photo->type = "photo";
|
||||
$photo->add_to_parent($parent->id);
|
||||
$photo->add_to_parent($parent);
|
||||
|
||||
$album1 = ORM::factory("item");
|
||||
$album1->type = "album";
|
||||
$album1->add_to_parent($parent->id);
|
||||
$album1->add_to_parent($parent);
|
||||
|
||||
$photo1 = ORM::factory("item");
|
||||
$photo1->type = "photo";
|
||||
$photo1->add_to_parent($album1->id);
|
||||
$photo1->add_to_parent($album1);
|
||||
|
||||
$parent->reload();
|
||||
|
||||
@@ -153,31 +163,35 @@ class ORM_MPTT_Test extends Unit_Test_Case {
|
||||
}
|
||||
|
||||
public function descendant_limit_test() {
|
||||
$parent = ORM::factory("item")->add_to_parent(1);
|
||||
$album1 = ORM::factory("item")->add_to_parent($parent->id);
|
||||
$album2 = ORM::factory("item")->add_to_parent($parent->id);
|
||||
$album3 = ORM::factory("item")->add_to_parent($parent->id);
|
||||
$root = ORM::factory("item", 1);
|
||||
|
||||
$parent = ORM::factory("item")->add_to_parent($root);
|
||||
$album1 = ORM::factory("item")->add_to_parent($parent);
|
||||
$album2 = ORM::factory("item")->add_to_parent($parent);
|
||||
$album3 = ORM::factory("item")->add_to_parent($parent);
|
||||
|
||||
$parent->reload();
|
||||
$this->assert_equal(2, $parent->descendants(2)->count());
|
||||
}
|
||||
|
||||
public function descendant_count_test() {
|
||||
$root = ORM::factory("item", 1);
|
||||
|
||||
$parent = ORM::factory("item");
|
||||
$parent->type = "album";
|
||||
$parent->add_to_parent(1);
|
||||
$parent->add_to_parent($root);
|
||||
|
||||
$photo = ORM::factory("item");
|
||||
$photo->type = "photo";
|
||||
$photo->add_to_parent($parent->id);
|
||||
$photo->add_to_parent($parent);
|
||||
|
||||
$album1 = ORM::factory("item");
|
||||
$album1->type = "album";
|
||||
$album1->add_to_parent($parent->id);
|
||||
$album1->add_to_parent($parent);
|
||||
|
||||
$photo1 = ORM::factory("item");
|
||||
$photo1->type = "photo";
|
||||
$photo1->add_to_parent($album1->id);
|
||||
$photo1->add_to_parent($album1);
|
||||
|
||||
$parent->reload();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user