public function actionCreateGroup()
 {
     /* validate all query string param */
     $model = new Group('create');
     $fileModel = new FileUploadFormModel();
     $fileModel->setScenario(FileUploadFormModel::FILE_UPLOAD_MODE_SINGLE);
     /*define the required variable for the controller base on the query string param */
     if (isset($_POST['Group'])) {
         $model->setAttributes($_POST['Group']);
         //$fileHandler->LoadUploadedeImageToModel();
         //$model->photos = $fileHandler->photos;
         //$model->photos = CUploadedFile::getInstancesByName(BSMultiFileUploadWidget::fieldName);
         if ($model->validate()) {
             $fileModel->LoadUploadedeImage();
             if ($fileModel->isUploadedFile()) {
                 if ($fileModel->validate()) {
                     $SavedFileRelativePaths = $fileModel->processImage(get_class($model), $model->group_name, md5(DateTimeHelper::now()));
                     $model->apply_img = ArrayHelper::array2string($SavedFileRelativePaths);
                     if ($model->save()) {
                         $model->addOwnerUser(Yii::app()->user->id);
                         Yii::app()->user->setFlash(FlashMsg::SUCCESS, "已提交組織申請");
                         $this->redirect(array('index'));
                     } else {
                         Yii::app()->user->setFlash(FlashMsg::ERROR, "提交組織申請失敗");
                     }
                 }
             } else {
                 if ($model->save()) {
                     $model->addOwnerUser(Yii::app()->user->id);
                     Yii::app()->user->setFlash(FlashMsg::SUCCESS, "已提交組織申請");
                     $this->redirect(array('index'));
                 } else {
                     Yii::app()->user->setFlash(FlashMsg::ERROR, "提交組織申請失敗");
                 }
             }
         }
     }
     $this->render('createGroup', array('model' => $model, 'fileModel' => $fileModel));
 }
Exemple #2
0
 /**
  * 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);
     $fileModel = new FileUploadFormModel();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     $this->layout = '//layouts/admin';
     if (isset($_POST['Event'])) {
         $transaction = Yii::app()->db->beginTransaction();
         try {
             $model->attributes = $_POST['Event'];
             if ($model->save()) {
                 $fileModel->LoadUploadedeImage();
                 $fileModel->setScenario(FileUploadFormModel::FILE_UPLOAD_MODE_SINGLE);
                 if ($fileModel->isUploadedFile()) {
                     if ($fileModel->validate()) {
                         $ips = new ImageProcessService($fileModel, get_class($model), $model->id, "icon");
                         $ips->saveImage(300, 300);
                         $SavedFileRelativePaths = $ips->getOriginalImageVirtualPath();
                         $SavedThumbnailFileRelativePaths = $ips->getThumbnailImageVirtualPath();
                         $model->save_img_src($SavedFileRelativePaths, $SavedThumbnailFileRelativePaths);
                         $transaction->commit();
                         $this->redirect(array('view', 'id' => $model->id));
                     }
                 } else {
                     $transaction->commit();
                     $this->redirect(array('view', 'id' => $model->id));
                 }
             }
         } catch (Exception $ex) {
             $transaction->rollback();
             Yii::app()->user->setFlash(FlashMsg::ERROR, $e->getMessage());
         }
     }
     $this->render('create', array('model' => $model, 'fileModel' => $fileModel));
 }
Exemple #3
0
 /**
  * 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 = Group::model()->findByPk($id);
     $currentUesrId = Yii::App()->user->id;
     if (!$model->isGroupOwners($currentUesrId)) {
         throw new CHttpException(404, "You are not the owner");
     }
     $fileModel = new FileUploadFormModel();
     $fileModel->setScenario(FileUploadFormModel::FILE_UPLOAD_MODE_SINGLE);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Group'])) {
         $model->setScenario('update');
         $model->setAttributes($_POST['Group']);
         if ($model->validate()) {
             $fileModel->LoadUploadedeImage();
             if ($fileModel->isUploadedFile()) {
                 if ($fileModel->validate()) {
                     $SavedFileRelativePaths = $fileModel->processImage(get_class($model), $model->group_name, md5(DateTimeHelper::now()));
                     $model->icon_src = ArrayHelper::array2string($SavedFileRelativePaths);
                     if ($model->save()) {
                         Yii::app()->user->setFlash(FlashMsg::SUCCESS, "組織資料已更新");
                         $this->redirect(array('index'));
                     } else {
                         Yii::app()->user->setFlash(FlashMsg::ERROR, "更新組織資料失敗");
                     }
                 } else {
                     $this->render('updateUser', array('model' => $model, 'fileModel' => $fileModel));
                 }
             }
             if ($model->save()) {
                 Yii::app()->user->setFlash(FlashMsg::SUCCESS, "組織資料已更新");
                 $this->redirect(array('index'));
             }
         }
     }
     $this->render('update', array('model' => $model, 'fileModel' => $fileModel));
 }