summaryrefslogtreecommitdiff
path: root/protected/modules/cms/components/MenuWidget.php
blob: d17f3568996ae5ec4f7d2eab2bc9023d808b5626 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
Yii::import('application.modules.cms.models.Sitecontent');

class MenuWidget extends CWidget
{
	public $point;
	protected $menu;

	public function init()
	{
		if($this->point == 0)
			throw new CException("Please provide a menu to render");

		parent::init();
		$this->menu = Sitecontent::model()->findAll(array(
					'condition' => 'parent = :point',
					'params' => array(':point' => $this->point),
					'order' => 'position',
					)
				);

		$items = array();
		if($this->menu)
			foreach($this->menu as $point) {
					$items[] = array('label' => $point->title,
							'active' => stripos(Yii::app()->request->url, $point->title_url) !== false,
							'url' => array('/site/view', 'page' => $point->title_url));
			}

		$this->widget('zii.widgets.CMenu',array(
					'items'=>$items
					));  
	}

} 
?>