1 <?php
2
3 4 5
6 7 8 9 10
11 Yii::setPathOfAlias('P3MetaTreeWidget', dirname(__FILE__));
12
13 class P3MetaTreeWidget extends CWidget {
14
15 public $model = null;
16 public $rootNodeId = null;
17 public $view = 'tree';
18 public $routes = array(
19 'updateContent' => null,
20 'updateMetaData' => null,
21 'viewContent' => null,
22 'viewMetaData' => null,
23 );
24 public $cssClass = "p3-meta-tree-widget";
25
26 function init() {
27
28 }
29
30 function run() {
31 $criteria = new CDbCriteria;
32
33 if ($this->rootNodeId === null) {
34 $criteria->condition = "treeParent_id IS :id";
35 } else {
36 $criteria->condition = "treeParent_id = :id";
37 }
38 $criteria->params = array(':id' => $this->rootNodeId);
39 $model = new $this->model;
40 $firstLevelNodes = $model::model()->findAll($criteria);
41
42 $this->renderTree($firstLevelNodes);
43 }
44
45 private function renderTree($models) {
46 echo "<div class='{$this->cssClass}'>";
47 echo "<ul>";
48 foreach ($models AS $model) {
49 echo "<li>";
50 $this->render($this->view, array('model' => $model));
51 $this->renderTree($model->getChildren());
52 echo "</li>";
53 }
54 echo "</ul>";
55 echo "</div>";
56 }
57
58 }
59
60 ?>
61