summaryrefslogtreecommitdiff
path: root/protected/controllers/MyAngebotController.php
diff options
context:
space:
mode:
Diffstat (limited to 'protected/controllers/MyAngebotController.php')
-rw-r--r--protected/controllers/MyAngebotController.php128
1 files changed, 121 insertions, 7 deletions
diff --git a/protected/controllers/MyAngebotController.php b/protected/controllers/MyAngebotController.php
index c53da98..b85846e 100644
--- a/protected/controllers/MyAngebotController.php
+++ b/protected/controllers/MyAngebotController.php
@@ -2,12 +2,16 @@
class MyAngebotController extends Controller
{
+ /**
+ * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
+ * using two-column layout. See 'protected/views/layouts/column2.php'.
+ */
+ public $layout = '//layouts/column2';
/**
* @return array action filters
*/
- public function filters()
- {
+ public function filters() {
return array(
'accessControl', // perform access control for CRUD operations
);
@@ -18,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
@@ -30,8 +33,38 @@ class MyAngebotController extends Controller
),
);
}
- public function actionIndex()
- {
+
+ /**
+ * 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'])) {
@@ -44,6 +77,87 @@ class MyAngebotController extends Controller
));
}
+ 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()