array('create', 'createAngebot', 'index', 'delete', 'update', 'view'), 'users'=>array('@'), ), array('deny', // deny all users 'users'=>array('*'), ), ); } /** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new AngebotVerein(); $model->published = true; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['AngebotVerein'])) { $model->attributes = $_POST['AngebotVerein']; $model->verein_id = Yii::app()->user->vereinId; if($model->save()) { $this->redirect(array('index')); } else { if (0 < $model->angebot_id) { $model->angebot = Angebot::model()->findByPk($model->angebot_id); } } } $this->render('create',array( 'model'=>$model, 'angebote'=>$this->loadAllAngeboteForAutoComplete(), 'einheiten'=>(null != $model->angebot) ? $model->angebot->kategorie->einheiten : '' )); } public function actionIndex() { $model = new AngebotVerein('search'); $model->unsetAttributes(); // clear any default values if (isset($_GET['AngebotVerein'])) { $model->attributes = $_GET['AngebotVerein']; } $model->verein_id = Yii::app()->user->vereinId; $this->render('index',array( 'model'=>$model, )); } /** * Deletes a particular model. * If deletion is successful, the browser will be redirected to the 'admin' page. * @param integer $id the ID of the model to be deleted */ public function actionDelete($id) { if(Yii::app()->request->isPostRequest) { // we only allow deletion via POST request $model = $this->loadModel($id); if ($model->verein_id != Yii::app()->user->vereinId) { throw new CHttpException(401,'Illegal Access! Delete your own data!'); } else { $model->delete(); } // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if(!isset($_GET['ajax'])) $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin')); } else throw new CHttpException(400,'Invalid request. Please do not repeat this request again.'); } public function actionUpdate($id) { $model = $this->loadModel($id); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['AngebotVerein'])){ $model->attributes = $_POST['AngebotVerein']; if ($model->verein_id != Yii::app()->user->vereinId) { $model->verein_id = Yii::app()->user->vereinId; } if ($model->save()) { $this->redirect(array('index')); } } $this->render('update',array( 'model'=>$model, 'angebote'=>$this->loadAllAngeboteForAutoComplete(), 'einheiten'=>$model->angebot->kategorie->einheiten )); } public function actionCreateAngebot() { $model = new Angebot(); $model->published = true; if (Yii::app()->request->isAjaxRequest) { if (isset($_POST['angebot_name'])) { $model->name = $_POST['angebot_name']; } else if (isset($_POST['Angebot'])) { $model->attributes = $_POST['Angebot']; if ($model->save()) { echo CJSON::encode(array( 'status'=>'success', 'div'=>"Angebot erfolgreich erstellt", 'label'=>$model->name, 'value'=>$model->id, 'einheiten'=>$model->kategorie->einheiten )); exit; } } else { throw new CHttpException(400); } $kategorien = Kategorie::model()->findAll(array("condition"=>"published=1")); echo CJSON::encode(array( 'status'=>'failure', 'div'=>$this->renderPartial('_angebot_form', array('model'=>$model, 'kategorien'=>$kategorien), true))); } else { throw new CHttpException(400); } } /** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ protected function loadModel($id) { $model = AngebotVerein::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; } private function loadAllAngeboteForAutoComplete() { $angebot = Angebot::model()->findAll(); $angebote = array(); foreach ($angebot as $a) { $an = array(); $an["label"] = $a->name; $an["value"] = $a->id; $an["einheiten"] = $a->kategorie->einheiten; array_push($angebote, $an); } return $angebote; } // Uncomment the following methods and override them if needed /* public function filters() { // return the filter configuration for this controller, e.g.: return array( 'inlineFilterName', array( 'class'=>'path.to.FilterClass', 'propertyName'=>'propertyValue', ), ); } public function actions() { // return external action classes, e.g.: return array( 'action1'=>'path.to.ActionClass', 'action2'=>array( 'class'=>'path.to.AnotherActionClass', 'propertyName'=>'propertyValue', ), ); } */ }