diff options
Diffstat (limited to 'protected/modules/cms/models')
| -rw-r--r-- | protected/modules/cms/models/Cms.php | 72 | ||||
| -rw-r--r-- | protected/modules/cms/models/Sitecontent.php | 82 |
2 files changed, 154 insertions, 0 deletions
diff --git a/protected/modules/cms/models/Cms.php b/protected/modules/cms/models/Cms.php new file mode 100644 index 0000000..691ca0c --- /dev/null +++ b/protected/modules/cms/models/Cms.php @@ -0,0 +1,72 @@ +<?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 && Cms::module()->strict404raising) + throw new CHttpException(404); + 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) { + + 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(array('label'=>$child->title, 'url'=>array('/cms/sitecontent/view', 'page'=>$child->title_url))); + } + } + return $tmp; + } +} diff --git a/protected/modules/cms/models/Sitecontent.php b/protected/modules/cms/models/Sitecontent.php new file mode 100644 index 0000000..a15029f --- /dev/null +++ b/protected/modules/cms/models/Sitecontent.php @@ -0,0 +1,82 @@ +<?php + +class Sitecontent extends CActiveRecord +{ + public static function model($className=__CLASS__) + { + return parent::model($className); + } + + public function primaryKey() { + return array('id', 'language'); + } + + public function beforeValidate() { + if(Yii::app()->controller->module->enableHtmlPurifier) { + $purifier = new CHtmlPurifier(); + $this->content = $purifier->purify($this->content); + } + return parent::beforeValidate(); + } + + public function tableName() + { + return 'sitecontent'; + } + + public function rules() + { + return array( + array('id, position, title, language', 'required'), + array('parent, position, createtime, updatetime', 'numerical', 'integerOnly'=>true), + array('title, keywords, description', 'length', 'max'=>255), + array('content, title_url, title_browser', 'safe'), + array('id, position, title, keywords, description, content, authorid, createtime, updatetime, language', 'safe', 'on'=>'search'), + ); + } + + public function relations() + { + return array( + 'parent' => array(self::BELONGS_TO, 'Sitecontent', 'parent'), + 'childs' => array(self::HAS_MANY, 'Sitecontent', 'parent'), + ); + } + + public function attributeLabels() + { + return array( + 'id' => '#', + 'parent' => Yii::t('CmsModule.cms', 'Parent'), + 'position' => Yii::t('CmsModule.cms', 'Position'), + 'title' => Yii::t('CmsModule.cms', 'Title'), + 'title_url' => Yii::t('CmsModule.cms', 'URL title'), + 'title_browser' => Yii::t('CmsModule.cms', 'Browser title'), + 'content' => Yii::t('CmsModule.cms', 'Content'), + 'authorid' => Yii::t('CmsModule.cms', 'Authorid'), + 'createtime' => Yii::t('CmsModule.cms', 'Createtime'), + 'updatetime' => Yii::t('CmsModule.cms', 'Updatetime'), + 'language' => Yii::t('CmsModule.cms', 'Language'), + ); + } + + public function search() + { + $criteria=new CDbCriteria; + + $criteria->compare('id',$this->id); + $criteria->compare('position',$this->position); + $criteria->compare('language',$this->language); + $criteria->compare('title',$this->title,true); + $criteria->compare('keywords',$this->keywords,true); + $criteria->compare('description',$this->description,true); + $criteria->compare('content',$this->content,true); + $criteria->compare('authorid',$this->authorid); + $criteria->compare('createtime',$this->createtime); + $criteria->compare('updatetime',$this->updatetime); + + return new CActiveDataProvider('Sitecontent', array( + 'criteria'=>$criteria, + )); + } +} |
