1 <?php
2
3 class P3WidgetTranslationController extends Controller
4 {
5
6 public $defaultAction = "admin";
7 public $scenario = "crud";
8
9 public function filters() {
10 return array(
11 'accessControl',
12 );
13 }
14
15 public function accessRules() {
16 return array(
17 array('allow',
18 'actions'=>array('create','ajaxUpdate','update','delete','admin','view'),
19 'roles'=>array('P3widgets.P3WidgetTranslation.*'),
20 ),
21 array('deny',
22 'users'=>array('*'),
23 ),
24 );
25 }
26
27 public function beforeAction($action){
28 parent::beforeAction($action);
29
30 if (!isset($_GET['id']) && isset($_GET['id'])) {
31 $model=P3WidgetTranslation::model()->find('id = :id', array(
32 ':id' => $_GET['id']));
33 if ($model !== null) {
34 $_GET['id'] = $model->id;
35 } else {
36 throw new CHttpException(400);
37 }
38 }
39 if ($this->module !== null) {
40 $this->breadcrumbs[$this->module->Id] = array('/'.$this->module->Id);
41 }
42 return true;
43 }
44
45 public function actionView($id)
46 {
47 $model = $this->loadModel($id);
48 $this->render('view',array('model' => $model,));
49 }
50
51 public function actionCreate()
52 {
53 $model = new P3WidgetTranslation;
54 $model->scenario = $this->scenario;
55
56 $this->performAjaxValidation($model, 'p3-widget-translation-form');
57
58
59 if(isset($_POST['P3WidgetTranslation'])) {
60 $model->attributes = $_POST['P3WidgetTranslation'];
61
62 try {
63 if($model->save()) {
64 if (isset($_GET['returnUrl'])) {
65 $this->redirect($_GET['returnUrl']);
66 } else {
67 $this->redirect(array('view','id'=>$model->id));
68 }
69 }
70 } catch (Exception $e) {
71 $model->addError('id', $e->getMessage());
72 }
73 } elseif(isset($_GET['P3WidgetTranslation'])) {
74 $model->attributes = $_GET['P3WidgetTranslation'];
75 }
76
77 $this->render('create',array( 'model'=>$model));
78 }
79
80
81 public function actionUpdate($id)
82 {
83 $model = $this->loadModel($id);
84 $model->scenario = $this->scenario;
85
86
87 $this->performAjaxValidation($model, 'p3-widget-translation-form');
88
89 if(isset($_POST['P3WidgetTranslation']))
90 {
91 $model->attributes = $_POST['P3WidgetTranslation'];
92
93
94 try {
95 if($model->save()) {
96 if (isset($_GET['returnUrl'])) {
97 $this->redirect($_GET['returnUrl']);
98 } else {
99 $this->redirect(array('view','id'=>$model->id));
100 }
101 }
102 } catch (Exception $e) {
103 $model->addError('id', $e->getMessage());
104 }
105 }
106
107 $this->render('update',array('model'=>$model,));
108 }
109
110 public function actionEditableSaver()
111 {
112 Yii::import('EditableSaver');
113 $es = new EditableSaver('P3WidgetTranslation');
114 $es->update();
115 }
116
117 public function actionDelete($id)
118 {
119 if(Yii::app()->request->isPostRequest)
120 {
121 try {
122 $this->loadModel($id)->delete();
123 } catch (Exception $e) {
124 throw new CHttpException(500,$e->getMessage());
125 }
126
127 if(!isset($_GET['ajax']))
128 {
129 if (isset($_GET['returnUrl'])) {
130 $this->redirect($_GET['returnUrl']);
131 } else {
132 $this->redirect(array('admin'));
133 }
134 }
135 }
136 else
137 throw new CHttpException(400,Yii::t('P3WidgetsModule.crud', 'Invalid request. Please do not repeat this request again.'));
138 }
139
140 public function actionIndex()
141 {
142 $dataProvider=new CActiveDataProvider('P3WidgetTranslation');
143 $this->render('index',array('dataProvider'=>$dataProvider,));
144 }
145
146 public function actionAdmin()
147 {
148 $model=new P3WidgetTranslation('search');
149 $model->unsetAttributes();
150
151 if(isset($_GET['P3WidgetTranslation'])) {
152 $model->attributes = $_GET['P3WidgetTranslation'];
153 }
154
155 $this->render('admin',array('model'=>$model,));
156 }
157
158 public function loadModel($id)
159 {
160 $model=P3WidgetTranslation::model()->findByPk($id);
161 if($model===null)
162 throw new CHttpException(404,Yii::t('P3WidgetsModule.crud', 'The requested page does not exist.'));
163 return $model;
164 }
165
166 protected function performAjaxValidation($model)
167 {
168 if(isset($_POST['ajax']) && $_POST['ajax']==='p3-widget-translation-form')
169 {
170 echo CActiveForm::validate($model);
171 Yii::app()->end();
172 }
173 }
174 }
175