Change the children and descendants APIs to be more consistent and to

remove Gallery3 concepts from ORM_MPTT.

The following API methods:
  ORM_MPTT::children
  ORM_MPTT::children_count
  ORM_MPTT::descendants
  ORM_MPTT::descendants_count

All now take a $where clause that allow you to pass through additional
field parameters.

old API:
  $album->children(10, 0, "photos")
  $album->children_count("photos")

new API:
  $album->children(10, 0, array("type" => "photos"))
  $album->children_count(array("type" => "photos"))

This gives us a more flexible API and simplifies the code.  While I
was in there, I changed the way we deal with default orderby values so
that we just assign the default value in the function definition,
which allows us to get rid of all conditionals in the implementation
which results in simpler code.
This commit is contained in:
Bharat Mediratta
2009-08-05 10:38:53 -07:00
parent 9f396178ce
commit e8c57290a2
4 changed files with 51 additions and 56 deletions

View File

@@ -177,8 +177,8 @@ class ORM_MPTT_Test extends Unit_Test_Case {
$parent->reload();
$this->assert_equal(3, $parent->descendants()->count());
$this->assert_equal(2, $parent->descendants(null, 0, "photo")->count());
$this->assert_equal(1, $parent->descendants(null, 0, "album")->count());
$this->assert_equal(2, $parent->descendants(null, 0, array("type" => "photo"))->count());
$this->assert_equal(1, $parent->descendants(null, 0, array("type" => "album"))->count());
}
public function descendant_limit_test() {
@@ -215,7 +215,7 @@ class ORM_MPTT_Test extends Unit_Test_Case {
$parent->reload();
$this->assert_equal(3, $parent->descendants_count());
$this->assert_equal(2, $parent->descendants_count("photo"));
$this->assert_equal(1, $parent->descendants_count("album"));
$this->assert_equal(2, $parent->descendants_count(array("type" => "photo")));
$this->assert_equal(1, $parent->descendants_count(array("type" => "album")));
}
}