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)); }
/** * 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)); }