diff options
Diffstat (limited to 'protected/controllers/MyAngebotController.php')
| -rw-r--r-- | protected/controllers/MyAngebotController.php | 106 |
1 files changed, 67 insertions, 39 deletions
diff --git a/protected/controllers/MyAngebotController.php b/protected/controllers/MyAngebotController.php index 02d9929..0072e61 100644 --- a/protected/controllers/MyAngebotController.php +++ b/protected/controllers/MyAngebotController.php @@ -11,8 +11,7 @@ class MyAngebotController extends Controller /** * @return array action filters */ - public function filters() - { + public function filters() { return array( 'accessControl', // perform access control for CRUD operations ); @@ -23,11 +22,10 @@ class MyAngebotController extends Controller * This method is used by the 'accessControl' filter. * @return array access control rules */ - public function accessRules() - { + public function accessRules() { return array( array('allow', // // allow authenticated user - 'actions'=>array('create', 'index', 'delete', 'update', 'view'), + 'actions'=>array('create', 'createAngebot', 'index', 'delete', 'update', 'view'), 'users'=>array('@'), ), array('deny', // deny all users @@ -40,39 +38,33 @@ class MyAngebotController extends Controller * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ - public function actionCreate() - { - $model=new AngebotVerein; + 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'])) - { + if (isset($_POST['AngebotVerein'])) { $model->attributes = $_POST['AngebotVerein']; $model->verein_id = Yii::app()->user->vereinId; - if($model->save()) + if($model->save()) { $this->redirect(array('index')); + } else { + if (0 < $model->angebot_id) { + $model->angebot = Angebot::model()->findByPk($model->angebot_id); + } } - - $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);
} $this->render('create',array( 'model'=>$model, - 'angebote'=>$angebote, - 'einheiten'=>'' + 'angebote'=>$this->loadAllAngeboteForAutoComplete(), + 'einheiten'=>(null != $model->angebot) ? $model->angebot->kategorie->einheiten : '' )); } - public function actionIndex() - { + + public function actionIndex() { $model = new AngebotVerein('search'); $model->unsetAttributes(); // clear any default values if (isset($_GET['AngebotVerein'])) { @@ -91,41 +83,77 @@ class MyAngebotController extends Controller // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); - if(isset($_POST['AngebotVerein'])) - { + if (isset($_POST['AngebotVerein'])){ $model->attributes = $_POST['AngebotVerein']; - if($model->save()) + if ($model->verein_id != Yii::app()->user->vereinId) { + $model->verein_id = Yii::app()->user->vereinId; + } + if ($model->save()) { $this->redirect(array('index')); } - $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); } + $this->render('update',array( 'model'=>$model, - 'angebote'=>$angebote, + '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'])) {
+ $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; + } + } + + $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 */ - public function loadModel($id) - { + protected function loadModel($id) { $model = AngebotVerein::model()->findByPk($id); - if($model===null) + 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() |
