public function actionBindCategories() { $binder = new Binder(); if ($binder->load(Yii::$app->request->post(), 'Binder')) { if (PostService::bindCategories($binder)) { // Trigger Ajax Success return AjaxUtil::generateSuccess(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::MESSAGE_REQUEST)); } } // Trigger Ajax Failure return AjaxUtil::generateFailure(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_REQUEST)); }
public function actionUpdate($id, $type = null) { // Find Model $model = PermissionService::findById($id); // Update/Render if exist if (isset($model)) { $model->type = $type; $model->setScenario('update'); if ($model->load(Yii::$app->request->post(), 'Permission') && $model->validate()) { if (PermissionService::update($model)) { $binder = new Binder(); $binder->binderId = $model->id; $binder->load(Yii::$app->request->post(), 'Binder'); PermissionService::bindRoles($binder); $this->redirect($this->returnUrl); } } $roles = RoleService::getIdNameListByType($type); return $this->render('update', ['model' => $model, 'roles' => $roles]); } // Model not found throw new NotFoundHttpException(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_NOT_FOUND)); }
public function actionUpdate($id) { // Find Model $model = PostService::findById($id); // Update/Render if exist if (isset($model)) { $content = $model->content; $banner = CmgFile::loadFile($content->banner, 'File'); $model->setScenario('update'); if ($model->load(Yii::$app->request->post(), 'Post') && $content->load(Yii::$app->request->post(), 'ModelContent') && $model->validate() && $content->validate()) { $post = PostService::update($model); if (isset($post)) { // Update Content ModelContentService::update($content, $post->isPublished(), $banner); // Bind Categories $binder = new Binder(); $binder->binderId = $model->id; $binder->load(Yii::$app->request->post(), 'Binder'); PostService::bindCategories($binder); $this->redirect(['all']); } } $categories = CategoryService::getIdNameListByType(CmsGlobal::TYPE_POST); $visibilityMap = Page::$visibilityMap; $statusMap = Page::$statusMap; $templatesMap = TemplateService::getIdNameMapByType(CmsGlobal::TYPE_POST); $templatesMap = ArrayHelper::merge(['0' => 'Choose Template'], $templatesMap); return $this->render('update', ['model' => $model, 'content' => $content, 'banner' => $banner, 'categories' => $categories, 'visibilityMap' => $visibilityMap, 'statusMap' => $statusMap, 'templatesMap' => $templatesMap]); } // Model not found throw new NotFoundHttpException(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_NOT_FOUND)); }