summaryrefslogtreecommitdiff
path: root/protected/modules/cms/controllers/SitecontentController.php
blob: 72dde78adb68ee816146d967fee8b8e645635ede (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php

Yii::import('application.modules.cms.models.Sitecontent');
class SitecontentController extends Controller
{
	public $defaultAction='admin';
	private $_model;

	public function beforeAction($action)
	{
		$this->layout = Yii::app()->controller->module->layout;
		return true;
	}
	public function accessRules()
	{
		return array(
				array('deny',
						'actions'=>array('*'),
						'users'=>array('*'),
				),
				array('allow',
						'actions'=>array('*'),
						'roles'=>array('admin'),
				)
		);
	}
	public function actionSearch() 
	{
		$q = new CDbCriteria();
		$q->addSearchCondition('content',$_POST['search']);
		$results = Sitecontent::model()->findAll($q);
		$q = new CDbCriteria();
		$q->addSearchCondition('beschreibung',$_POST['search']);
		$results = Verein::model()->findAll($q);

		$this->render('results', array(
					'results' => $results,
					'search' => $_POST['search']));
	}
	
	public static function getContent($id) {
		if($model = Sitecontent::model()->findByPk($id)) {
			return $model->content;
		}
	}

	public function filters()
	{
		return array('accessControl');
	}

	public function actionView()
	{
		$model = $this->loadContent();

		$this->breadcrumbs = array($model->title);
		if($model->depth == 1) {
			$this->menu = CMS::getMenuPoints($model->id);
		} elseif ($model->depth == 2){
			$this->menu = CMS::getMenuPoints($model->oparent->id);
		}
		$this->render('view', array(
					'sitecontent' => $model,
					));
	}

	public function actionCreate()
	{
		$model=new Sitecontent;

		$this->performAjaxValidation($model);

		if(isset($_POST['Sitecontent']))
		{
			$model->attributes=$_POST['Sitecontent'];
			$model->createtime = time();
			$model->updatetime = time();

			if(isset(Yii::app()->user->id))
					$model->authorid = Yii::app()->user->id;

			if($model->save())
				$this->redirect(array('admin'));
		}

		if(isset($_GET['position']))
			$model->position = $_GET['position'];

		$this->render('create',array(
			'model'=>$model,
		));
	}

	public function actionUpdate()
	{
		$model=$this->loadContent();

		$this->performAjaxValidation($model);

		if(isset($_POST['Sitecontent']))
		{
			$model->attributes=$_POST['Sitecontent'];
			$model->updatetime = time();
			if($model->save())
				$this->redirect(array('admin'));
		}

		$this->render('update',array(
			'model'=>$model,
		));
	}

	public function actionDelete()
	{
		if(Yii::app()->request->isPostRequest)
		{
			$this->loadContent()->delete();

			if(!isset($_POST['ajax']))
				$this->redirect(array('index'));
		}
		else
			throw new CHttpException(400,Yii::t('App','Invalid request. Please do not repeat this request again.'));
	}

	public function actionIndex()
	{
		$dataProvider=new CActiveDataProvider('Sitecontent');
		$this->render('index',array(
			'dataProvider'=>$dataProvider,
		));
	}

	public function actionAdmin()
	{
		$model=new Sitecontent('search');
		if(isset($_GET['Sitecontent']))
			$model->attributes=$_GET['Sitecontent'];

		$this->render('admin',array(
			'model'=>$model,
		));
	}

	public function loadContent()
	{
		if($this->_model===null)
		{
			if(isset($_GET['id']) && is_array(@$_GET['id']))
				$this->_model = Sitecontent::model()->find('id = :id and language = :language',  array(
							':id' => $_GET['id']['id'],
							':language' => $_GET['id']['language'],
							));
			if(isset($_GET['id']) && !is_array($_GET['id'])) 
				$this->_model = Sitecontent::model()->find('id = :id',  array(
							':id' => $_GET['id'],
							));

			if($this->_model === null)
				$this->_model = Sitecontent::model()->find("title_url = :page", array(
							':page' => $_GET['page']));
			if($this->_model===null)
				throw new CHttpException(404,Yii::t('App','We are sorry. The requested page does not exist.'));
		}
		return $this->_model;
	}

	protected function performAjaxValidation($model)
	{
		if(isset($_POST['ajax']) && $_POST['ajax']==='sitecontent-form')
		{
			echo CActiveForm::validate($model);
			Yii::app()->end();
		}
	}
}