summaryrefslogtreecommitdiff
path: root/protected/modules/cms/models
diff options
context:
space:
mode:
authorPatrick Seeger <pseeger@ccwn.org>2012-06-25 23:31:16 +0200
committerPatrick Seeger <pseeger@ccwn.org>2012-06-25 23:31:16 +0200
commitd58f7cf02dc0c5ce2df2f0db00361fe673074be8 (patch)
treede5b7064e43255a471de4cb469a7db71bce3d328 /protected/modules/cms/models
parent82f5b7dc1890c03ebec349225e76ea0b22ec6c1d (diff)
Änderungen das alles tut, editor, cms
Diffstat (limited to 'protected/modules/cms/models')
-rw-r--r--protected/modules/cms/models/Cms.php77
-rw-r--r--protected/modules/cms/models/Sitecontent.php92
2 files changed, 169 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..e07ad4e
--- /dev/null
+++ b/protected/modules/cms/models/Cms.php
@@ -0,0 +1,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;
+ }
+}
diff --git a/protected/modules/cms/models/Sitecontent.php b/protected/modules/cms/models/Sitecontent.php
new file mode 100644
index 0000000..17e6f0f
--- /dev/null
+++ b/protected/modules/cms/models/Sitecontent.php
@@ -0,0 +1,92 @@
+<?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('position, title, language, depth', 'required'),
+ array('parent, depth, position, createtime, updatetime', 'numerical', 'integerOnly'=>true),
+ array('title, keywords, description', 'length', 'max'=>255),
+ array('content, title_url, title_browser', 'safe'),
+ array('title, keywords, description, content, language', 'safe', 'on'=>'search'),
+ );
+ }
+
+ public function relations()
+ {
+ return array(
+ 'oparent' => 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'),
+ 'depth' => Yii::t('CmsModule.cms', 'Depth'),
+ );
+ }
+
+ 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);
+ //$criteria->compare('depth',$this->depth);
+
+ return new CActiveDataProvider('Sitecontent', array(
+ 'criteria'=>$criteria,
+ ));
+ }
+
+ public function beforeSave() {
+ if ($this->parent > 0){
+ $this->depth = $this->oparent->depth + 1;
+
+ }
+ return parent::beforeSave();
+ }
+}