public function testChildrenRelationUsesDefaultOrdering() { $category = new Category(); $query = $category->children()->getQuery()->getQuery(); $expected = array('column' => 'lft', 'direction' => 'asc'); $this->assertEquals($expected, $query->orders[0]); }
<?php require_once 'Kijiji.php'; $id = @$_GET['id']; $c = new Category(); $c->id = $id ? $id : 21; $c->load(); //print_r($c->children()); foreach ($c->children() as $cc) { print "<b><a href=listing.php?id={$cc->id}>{$cc->name}</a></b><p>"; foreach ($cc->children() as $cs) { print "<li><a href=listing.php?id={$cs->id}>{$cs->name}</a><br>"; } }
/** * Build tree-like array for the category * Categories that have children can be selected * @static * @param Category $elem the category for which builds array * @param integer $i nesting level * @return string[] */ private static function GetChildrenForTreeArrayLeafCanSelected($elem, $i, $sign = ' ') { $res = array(); $roots = $elem->children()->findAll(array('order'=>'title')); foreach ($roots as $root) { $res[$root->id] = $root->GetStringName($sign); if (!$root->isLeaf()) $res = $res + self::GetChildrenForTreeArrayLeafCanSelected($root, $i + 1, $sign); } return $res; }
/** * Build tree-like array for the category * Categories that have children can be selected * @static * @param Category $elem the category for which builds array * @param integer $i nesting level * @return string[] */ private static function GetChildrenForTreeArrayLeafCanSelected($elem, $i) { $res = array(); $roots = $elem->children()->findAll(); foreach ($roots as $root) { $res[$root->id] = $root->GetStringName(); if (!$root->isLeaf()) { $res = $res + Category::GetChildrenForTreeArrayLeafCanSelected($root, $i + 1); } } return $res; }