summaryrefslogtreecommitdiff
path: root/protected/modules/cms/models/Cms.php
blob: e07ad4e1398f0c69337a7d7ae3d79cfda3d88e94 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php

Yii::import('application.modules.cms.models.*');
Yii::import('application.modules.cms.controllers.*');

class Cms {
	public function module() {
		return Yii::app()->getModule('cms');

	}
	public static function t($string, $params = array())
	{
		Yii::import('application.modules.cms.CmsModule');
		return Yii::t('CmsModule.cms', $string, $params);
	}

	public static function render($id = null, $return = false, $lang = null) {
		if($lang === null)
			$lang = Yii::app()->language;

		$column = 'id';
		if(!is_numeric($id))
			$column = 'title_url';

		if($id) {
			$sitecontent = Sitecontent::model()->find(
					$column . ' = :id and language = :lang', array(
						':id' => $id,
						':lang' => $lang));

			// If the sitecontent is not available in the requested language,
			// try to fallback to the first natural found sitecontent in the db
			if(!$sitecontent)
				$sitecontent = Sitecontent::model()->find(
						$column .' = :id', array(
							':id' => $id));

			if(!$sitecontent && Yii::app()->getModule('cms')->strict404raising)
				throw new CHttpException(404);
			else if (!$sitecontent) {
				$sitecontent = new Sitecontent();
				$sitecontent->content = "";
			}
			else if($return)
				return $sitecontent->content;
			else
				echo $sitecontent->content;	
		}
	}

	public static function renderMenuPoints($id) {
		if(is_numeric($id))
			$sitecontent = Sitecontent::model()->findByAttributes(array('id'=> $id));
		$childs = $sitecontent->childs;
		if($childs)  {
			foreach($sitecontent->childs as $child) {
				printf('<li>%s</li>',
						CHtml::link($child->title, array(
								'/cms/sitecontent/view', 'page' => $child->title_url) ));
			}
		}
	}
	public static function getMenuPoints($id) {
		$tmp=array();
		if(is_numeric($id))
			$sitecontent = Sitecontent::model()->findByAttributes(array('id'=> $id));
		$childs = $sitecontent->childs;
		if($childs)  {

			foreach($sitecontent->childs as $child) {
				Yii::trace("Lala","Debug");
				$tmp = array_merge($tmp,array(array('label'=>$child->title, 'url'=>array('/cms/sitecontent/view', 'page'=>$child->title_url))));
			}
		}
		return $tmp;
	}
}