1 <?php
2 3 4 5 6 7 8
9
10 class P3PagesTreeWidget extends CWidget {
11
12 public $rootNode = null;
13
14 function init(){
15 }
16
17 function run(){
18 $criteria = new CDbCriteria;
19
20 if ($this->rootNode === null) {
21 $criteria->condition = "p3PageMeta.treeParent_id IS :id";
22 } else {
23 $criteria->condition = "p3PageMeta.treeParent_id = :id";
24 }
25 $criteria->params = array(':id'=>$this->rootNode);
26 $criteria->with = array('p3PageMeta');
27 $firstLevelNodes = P3Page::model()->findAll($criteria);
28
29 $this->renderTree($firstLevelNodes);
30 }
31
32 private function renderTree($models){
33 echo "<ul>";
34 foreach($models AS $model){
35 echo "<li>";
36 $this->render('tree',array('model'=>$model));
37 $this->renderTree($model->getChildren());
38 echo "</li>";
39 }
40 echo "</ul>";
41 }
42 }
43
44 ?>
45