diff options
| author | tzur <tzur@ccwn.org> | 2012-04-15 15:30:09 +0200 |
|---|---|---|
| committer | tzur <tzur@ccwn.org> | 2012-04-15 15:30:09 +0200 |
| commit | 5b2095abddf9d0596a7715879357e8d9a3b786b2 (patch) | |
| tree | 0c2b6fdc1484b697b1a3740582a906fb51c1d64f /protected/controllers | |
Initial version
Diffstat (limited to 'protected/controllers')
| -rw-r--r-- | protected/controllers/KategorieController.php | 163 | ||||
| -rw-r--r-- | protected/controllers/MyvereinController.php | 122 | ||||
| -rw-r--r-- | protected/controllers/SiteController.php | 104 | ||||
| -rw-r--r-- | protected/controllers/UserController.php | 168 | ||||
| -rw-r--r-- | protected/controllers/VereinController.php | 161 |
5 files changed, 718 insertions, 0 deletions
diff --git a/protected/controllers/KategorieController.php b/protected/controllers/KategorieController.php new file mode 100644 index 0000000..ceeaf42 --- /dev/null +++ b/protected/controllers/KategorieController.php @@ -0,0 +1,163 @@ +<?php + +class KategorieController 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'; + + public function init() { + Yii::app()->format->numberFormat = array('decimals'=>1, 'decimalSeparator'=>",", 'thousandSeparator'=>"."); + } + + /** + * @return array action filters + */ + public function filters() + { + return array( + 'accessControl', // perform access control for CRUD operations + ); + } + + /** + * Specifies the access control rules. + * This method is used by the 'accessControl' filter. + * @return array access control rules + */ + public function accessRules() + { + return array( + array('allow', // allow admin user to perform 'admin' and 'delete' actions + 'actions'=>array('index','create','update','delete','view'), + 'users'=>array('admin'), + ), + array('deny', // deny all users + 'users'=>array('*'), + ), + ); + } + + /** + * Displays a particular model. + * @param integer $id the ID of the model to be displayed + */ + public function actionView($id) + { + $this->render('view',array( + 'model'=>$this->loadModel($id), + )); + } + + /** + * Creates a new model. + * If creation is successful, the browser will be redirected to the 'view' page. + */ + public function actionCreate() + { + $model=new Kategorie; + + // Uncomment the following line if AJAX validation is needed + // $this->performAjaxValidation($model); + + if(isset($_POST['Kategorie'])) + { + $model->attributes=$_POST['Kategorie']; + if($model->save()) + $this->redirect(array('view','id'=>$model->id)); + } + + $this->render('create',array( + 'model'=>$model, + )); + } + + /** + * Updates a particular model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id the ID of the model to be updated + */ + public function actionUpdate($id) + { + $model=$this->loadModel($id); + + // Uncomment the following line if AJAX validation is needed + // $this->performAjaxValidation($model); + + if(isset($_POST['Kategorie'])) + { + $model->attributes=$_POST['Kategorie']; + $model->default_menge = str_replace(",", ".", $model->default_menge); + if($model->save()) { + $this->redirect(array('view','id'=>$model->id)); + } + } + + $this->render('update',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 + $this->loadModel($id)->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.'); + } + + /** + * Lists all models. + */ + public function actionIndex() + { + $model=new Kategorie('search'); + $model->unsetAttributes(); // clear any default values + if(isset($_GET['Kategorie'])) + $model->attributes=$_GET['Kategorie']; + + $this->render('index',array( + 'model'=>$model, + )); + } + + /** + * 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) + { + $model=Kategorie::model()->findByPk($id); + if($model===null) + throw new CHttpException(404,'The requested page does not exist.'); + return $model; + } + + /** + * Performs the AJAX validation. + * @param CModel the model to be validated + */ + protected function performAjaxValidation($model) + { + if(isset($_POST['ajax']) && $_POST['ajax']==='kategorie-form') + { + echo CActiveForm::validate($model); + Yii::app()->end(); + } + } +} diff --git a/protected/controllers/MyvereinController.php b/protected/controllers/MyvereinController.php new file mode 100644 index 0000000..cf241fd --- /dev/null +++ b/protected/controllers/MyvereinController.php @@ -0,0 +1,122 @@ +<?php + +class MyvereinController 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() + { + return array( + 'accessControl', // perform access control for CRUD operations + ); + } + + /** + * Specifies the access control rules. + * This method is used by the 'accessControl' filter. + * @return array access control rules + */ + public function accessRules() + { + return array( + array('allow', // allow authenticated user to perform 'create' and 'update' actions + 'actions'=>array('update','index','view'), + 'users'=>array('@'), + ), + array('deny', // deny all users + 'users'=>array('*'), + ), + ); + } + + /** + * Displays a particular model. + * @param integer $id the ID of the model to be displayed + */ + public function actionView() + { + $id = Yii::app()->user->vereinId; + if (!$id && Yii::app()->user->isAdmin) { + $this->redirect(array("/verein/admin")); + } + $this->render('view',array( + 'model'=>$this->loadModel($id), + )); + } + + /** + * Updates a particular model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id the ID of the model to be updated + */ + public function actionUpdate() + { + $id = Yii::app()->user->vereinId; + $model=$this->loadModel($id); + + // Uncomment the following line if AJAX validation is needed + // $this->performAjaxValidation($model); + + if(isset($_POST['Verein'])) + { + $model->attributes = $_POST['Verein']; + $model->uploadedImage = CUploadedFile::getInstance($model, 'uploadedImage'); + if($model->save()) { + if (null !== $model->uploadedImage) { + $suffix = substr($model->uploadedImage->getName(), strrpos($model->uploadedImage->getName(), ".")); + $filename = "images/uploaded/".time()."-".$model->slug.$suffix; + $model->bild = $filename; + $model->uploadedImage->saveAs($filename); + $model->save(); + } + + $this->redirect(array('view','id'=>$model->id)); + } + } + + $this->render('update',array( + 'model'=>$model, + )); + } + + /** + * Lists all models. + */ + public function actionIndex() + { + $this->actionView(); + } + + /** + * 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) + { + $model=Verein::model()->findByPk($id); + if($model===null) + throw new CHttpException(404,'The requested page does not exist.'); + return $model; + } + + /** + * Performs the AJAX validation. + * @param CModel the model to be validated + */ + protected function performAjaxValidation($model) + { + if(isset($_POST['ajax']) && $_POST['ajax']==='verein-form') + { + echo CActiveForm::validate($model); + Yii::app()->end(); + } + } +} diff --git a/protected/controllers/SiteController.php b/protected/controllers/SiteController.php new file mode 100644 index 0000000..961a968 --- /dev/null +++ b/protected/controllers/SiteController.php @@ -0,0 +1,104 @@ +<?php + +class SiteController extends Controller +{ + /** + * Declares class-based actions. + */ + public function actions() + { + return array( + // captcha action renders the CAPTCHA image displayed on the contact page + 'captcha'=>array( + 'class'=>'CCaptchaAction', + 'backColor'=>0xFFFFFF, + ), + // page action renders "static" pages stored under 'protected/views/site/pages' + // They can be accessed via: index.php?r=site/page&view=FileName + 'page'=>array( + 'class'=>'CViewAction', + ), + ); + } + + /** + * This is the default 'index' action that is invoked + * when an action is not explicitly requested by users. + */ + public function actionIndex() + { + if (!Yii::app()->user->isGuest && Yii::app()->user->isAdmin) { + $this->redirect(array("/verein/")); + } + $this->redirect(array("/myverein/")); + } + + /** + * This is the action to handle external exceptions. + */ + public function actionError() + { + if($error=Yii::app()->errorHandler->error) + { + if(Yii::app()->request->isAjaxRequest) + echo $error['message']; + else + $this->render('error', $error); + } + } + + /** + * Displays the contact page + */ + public function actionContact() + { + $model=new ContactForm; + if(isset($_POST['ContactForm'])) + { + $model->attributes=$_POST['ContactForm']; + if($model->validate()) + { + $headers="From: {$model->email}\r\nReply-To: {$model->email}"; + mail(Yii::app()->params['adminEmail'],$model->subject,$model->body,$headers); + Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.'); + $this->refresh(); + } + } + $this->render('contact',array('model'=>$model)); + } + + /** + * Displays the login page + */ + public function actionLogin() + { + $model=new LoginForm; + + // if it is ajax validation request + if(isset($_POST['ajax']) && $_POST['ajax']==='login-form') + { + echo CActiveForm::validate($model); + Yii::app()->end(); + } + + // collect user input data + if(isset($_POST['LoginForm'])) + { + $model->attributes=$_POST['LoginForm']; + // validate user input and redirect to the previous page if valid + if($model->validate() && $model->login()) + $this->redirect(Yii::app()->user->returnUrl); + } + // display the login form + $this->render('login',array('model'=>$model)); + } + + /** + * Logs out the current user and redirect to homepage. + */ + public function actionLogout() + { + Yii::app()->user->logout(); + $this->redirect(Yii::app()->homeUrl); + } +}
\ No newline at end of file diff --git a/protected/controllers/UserController.php b/protected/controllers/UserController.php new file mode 100644 index 0000000..79fc7e8 --- /dev/null +++ b/protected/controllers/UserController.php @@ -0,0 +1,168 @@ +<?php + +class UserController 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() + { + return array( + 'accessControl', // perform access control for CRUD operations + ); + } + + /** + * Specifies the access control rules. + * This method is used by the 'accessControl' filter. + * @return array access control rules + */ + public function accessRules() + { + return array( + array('allow', // allow admin user to perform 'admin' and 'delete' actions + 'actions'=>array('create','update','index','view','admin','delete'), + 'users'=>array('admin'), + ), + array('deny', // deny all users + 'users'=>array('*'), + ), + ); + } + + /** + * Displays a particular model. + * @param integer $id the ID of the model to be displayed + */ + public function actionView($id) + { + $this->render('view',array( + 'model'=>$this->loadModel($id), + )); + } + + /** + * Creates a new model. + * If creation is successful, the browser will be redirected to the 'view' page. + */ + public function actionCreate() + { + $model=new User; + + // Uncomment the following line if AJAX validation is needed + // $this->performAjaxValidation($model); + + if(isset($_POST['User'])) + { + $model->attributes=$_POST['User']; + if($model->save()) + $this->redirect(array('view','id'=>$model->id)); + } + + $this->render('create',array( + 'model'=>$model, + )); + } + + /** + * Updates a particular model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id the ID of the model to be updated + */ + public function actionUpdate($id) + { + $model=$this->loadModel($id); + + // Uncomment the following line if AJAX validation is needed + // $this->performAjaxValidation($model); + + if(isset($_POST['User'])) + { + $model->attributes=$_POST['User']; + if($model->save()) + $this->redirect(array('view','id'=>$model->id)); + } + + $this->render('update',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 + $this->loadModel($id)->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.'); + } + + /** + * Lists all models. + */ + public function actionIndex() + { + $dataProvider=new CActiveDataProvider('User'); + $this->render('index',array( + 'dataProvider'=>$dataProvider, + )); + } + + /** + * Manages all models. + */ + public function actionAdmin() + { + $model=new User('search'); + $model->unsetAttributes(); // clear any default values + if(isset($_GET['User'])) + $model->attributes=$_GET['User']; + + $this->render('admin',array( + 'model'=>$model, + )); + } + + /** + * 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) + { + $model=User::model()->findByPk($id); + if($model===null) + throw new CHttpException(404,'The requested page does not exist.'); + return $model; + } + + /** + * Performs the AJAX validation. + * @param CModel the model to be validated + */ + protected function performAjaxValidation($model) + { + if(isset($_POST['ajax']) && $_POST['ajax']==='user-form') + { + echo CActiveForm::validate($model); + Yii::app()->end(); + } + } +} diff --git a/protected/controllers/VereinController.php b/protected/controllers/VereinController.php new file mode 100644 index 0000000..30c05bc --- /dev/null +++ b/protected/controllers/VereinController.php @@ -0,0 +1,161 @@ +<?php + +class VereinController 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() + { + return array( + 'accessControl', // perform access control for CRUD operations + ); + } + + /** + * Specifies the access control rules. + * This method is used by the 'accessControl' filter. + * @return array access control rules + */ + public function accessRules() + { + return array( + array('allow', // allow admin user to perform 'admin' and 'delete' actions + 'actions'=>array('index','create','view','update','delete'), + 'users'=>array('admin'), + ), + array('deny', // deny all users + 'users'=>array('*'), + ), + ); + } + + /** + * Displays a particular model. + * @param integer $id the ID of the model to be displayed + */ + public function actionView($id) + { + $this->render('view',array( + 'model'=>$this->loadModel($id), + )); + } + + /** + * Creates a new model. + * If creation is successful, the browser will be redirected to the 'view' page. + */ + public function actionCreate() + { + $model=new Verein; + + // Uncomment the following line if AJAX validation is needed + // $this->performAjaxValidation($model); + + if(isset($_POST['Verein'])) + { + $model->attributes=$_POST['Verein']; + if($model->save()) + $this->redirect(array('view','id'=>$model->id)); + } + + $standorte = Standort::model()->findAll(array("condition"=>"published=1")); + $this->render('create',array( + 'model'=>$model, + 'standorte'=>$standorte + )); + } + + /** + * Updates a particular model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id the ID of the model to be updated + */ + public function actionUpdate($id) + { + $model=$this->loadModel($id); + + // Uncomment the following line if AJAX validation is needed + // $this->performAjaxValidation($model); + + if(isset($_POST['Verein'])) + { + $model->attributes=$_POST['Verein']; + if($model->save()) + $this->redirect(array('view','id'=>$model->id)); + } + + $standorte = Standort::model()->findAll(array("condition"=>"published=1")); + $this->render('update',array( + 'model'=>$model, + 'standorte'=>$standorte + )); + } + + /** + * 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 + $this->loadModel($id)->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.'); + } + + /** + * Lists all models. + */ + public function actionIndex() + { + $model=new Verein('search'); + $model->unsetAttributes(); // clear any default values + if(isset($_GET['Verein'])) + $model->attributes=$_GET['Verein']; + + $this->render('index',array( + 'model'=>$model, + )); + } + + /** + * 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) + { + $model=Verein::model()->findByPk($id); + if($model===null) + throw new CHttpException(404,'The requested page does not exist.'); + return $model; + } + + /** + * Performs the AJAX validation. + * @param CModel the model to be validated + */ + protected function performAjaxValidation($model) + { + if(isset($_POST['ajax']) && $_POST['ajax']==='verein-form') + { + echo CActiveForm::validate($model); + Yii::app()->end(); + } + } +} |
