Exemple #1
0
 /**
  * @param CmgFile $file
  * @return CmgFile
  */
 public static function create($file)
 {
     $user = Yii::$app->user->getIdentity();
     $file->createdBy = $user->id;
     // File Visibility
     if (!isset($file->visibility)) {
         $file->visibility = CmgFile::VISIBILITY_PUBLIC;
     }
     // Create File
     $file->save();
     // Return File
     return $file;
 }
 public function actionAvatar()
 {
     $user = Yii::$app->user->getIdentity();
     $avatar = new CmgFile();
     if ($avatar->load(Yii::$app->request->post(), 'File') && UserService::updateAvatar($user, $avatar)) {
         $user = UserService::findById($user->id);
         $avatar = $user->avatar;
         $response = ['fileUrl' => $avatar->getFileUrl()];
         // Trigger Ajax Success
         return AjaxUtil::generateSuccess(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::MESSAGE_REQUEST), $response);
     } else {
         // Trigger Ajax Failure
         return AjaxUtil::generateFailure(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_REQUEST));
     }
 }
 public function actionCreateItem($id)
 {
     $gallery = GalleryService::findById($id);
     if (isset($gallery)) {
         $item = new CmgFile();
         if ($item->load(Yii::$app->request->post(), "File") && GalleryService::createItem($gallery, $item)) {
             // Trigger Ajax Success
             return AjaxUtil::generateSuccess(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::MESSAGE_REQUEST));
         }
         // Generate Errors
         $errors = AjaxUtil::generateErrorMessage($item);
         // Trigger Ajax Success
         return AjaxUtil::generateFailure(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_REQUEST), $errors);
     }
 }
 public function actionUpdate($id)
 {
     // Find Model
     $model = PageService::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(), 'Page') && $content->load(Yii::$app->request->post(), 'ModelContent') && $model->validate() && $content->validate()) {
             $page = PageService::update($model);
             if (isset($page)) {
                 // Update Content
                 ModelContentService::update($content, $page->isPublished(), $banner);
                 $this->redirect(['all']);
             }
         }
         $visibilityMap = Page::$visibilityMap;
         $statusMap = Page::$statusMap;
         $templatesMap = TemplateService::getIdNameMapByType(CmsGlobal::TYPE_PAGE);
         $templatesMap = ArrayHelper::merge(['0' => 'Choose Template'], $templatesMap);
         return $this->render('update', ['model' => $model, 'content' => $content, 'banner' => $banner, 'visibilityMap' => $visibilityMap, 'statusMap' => $statusMap, 'templatesMap' => $templatesMap]);
     }
     // Model not found
     throw new NotFoundHttpException(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_NOT_FOUND));
 }
 public function actionUpdate($id, $roleType = null, $roleSlug = null)
 {
     // Find Model
     $model = UserService::findById($id);
     // Update/Render if exist
     if (isset($model)) {
         $siteMember = $model->siteMember;
         $avatar = CmgFile::loadFile($model->avatar, 'File');
         $model->setScenario('update');
         UserService::checkNewsletterMember($model);
         if ($model->load(Yii::$app->request->post(), 'User') && $siteMember->load(Yii::$app->request->post(), 'SiteMember') && $model->validate()) {
             // Update User and Site Member
             if (UserService::update($model, $avatar) && SiteMemberService::update($siteMember)) {
                 $this->redirect($this->returnUrl);
             }
         }
         if (isset($roleSlug)) {
             return $this->render('@cmsgears/module-core/admin/views/user/update', ['model' => $model, 'siteMember' => $siteMember, 'avatar' => $avatar, 'status' => User::$statusMapUpdate]);
         } else {
             $roleMap = RoleService::getIdNameMapByType($roleType);
             return $this->render('@cmsgears/module-core/admin/views/user/update', ['model' => $model, 'siteMember' => $siteMember, 'avatar' => $avatar, 'roleMap' => $roleMap, 'status' => User::$statusMapUpdate]);
         }
     }
     // Model not found
     throw new NotFoundHttpException(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_NOT_FOUND));
 }
Exemple #6
0
 /**
  * @return Address - associated with parent having type set to residential
  */
 public function getFiles()
 {
     return $this->hasmany(CmgFile::className(), ['id' => 'fileId'])->viaTable(CoreTables::TABLE_MODEL_FILE, ['parentId' => 'id'], function ($query) {
         $modelFile = CoreTables::TABLE_MODEL_FILE;
         $query->onCondition("{$modelFile}.parentType=:type", [':type' => $this->fileType]);
     });
 }
 public function actionUpdate($id)
 {
     // Find Model
     $slide = SlideService::findById($id);
     // Update/Render if exist
     if (isset($slide)) {
         if ($slide->load(Yii::$app->request->post(), 'Slide') && $slide->validate()) {
             $slideImage = new CmgFile();
             $slideImage->load(Yii::$app->request->post(), 'File');
             // update slide
             if (SlideService::update($slide, $slideImage)) {
                 // Trigger Ajax Success
                 return AjaxUtil::generateSuccess(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::MESSAGE_REQUEST));
             }
         }
     }
     // Generate Errors
     $errors = AjaxUtil::generateErrorMessage($slide);
     // Trigger Ajax Success
     return AjaxUtil::generateFailure(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_REQUEST), $errors);
 }
 public function actionUpdate($id)
 {
     // Find Model
     $model = SiteService::findById($id);
     // Update/Render if exist
     if (isset($model)) {
         $avatar = CmgFile::loadFile($model->avatar, 'Avatar');
         $banner = CmgFile::loadFile($model->banner, 'Banner');
         $model->setScenario('update');
         if ($model->load(Yii::$app->request->post(), 'Site') && $model->validate()) {
             if (SiteService::update($model, $avatar)) {
                 return $this->redirect('all');
             }
         }
         return $this->render('update', ['model' => $model, 'avatar' => $avatar, 'banner' => $banner]);
     }
     // Model not found
     throw new NotFoundHttpException(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_NOT_FOUND));
 }
 public function actionUpdate($id, $type = null, $dropDown = false)
 {
     // Find Model
     $model = CategoryService::findById($id);
     // Update/Render if exist
     if (isset($model)) {
         $model->type = $type;
         $avatar = CmgFile::loadFile($model->avatar, 'Avatar');
         $model->setScenario('update');
         if ($model->load(Yii::$app->request->post(), 'Category') && $model->validate()) {
             if (CategoryService::update($model, $avatar)) {
                 return $this->redirect($this->returnUrl);
             }
         }
         $avatar = $model->avatar;
         return $this->render('@cmsgears/module-core/admin/views/category/update', ['model' => $model, 'avatar' => $avatar, 'dropDown' => $dropDown]);
     }
     // Model not found
     throw new NotFoundHttpException(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_NOT_FOUND));
 }
 public function actionUpdate($id)
 {
     // Find Model
     $model = BlockService::findById($id);
     // Update/Render if exist
     if (isset($model)) {
         $banner = CmgFile::loadFile($model->banner, 'Banner');
         $video = CmgFile::loadFile($model->video, 'Video');
         $texture = CmgFile::loadFile($model->texture, 'Texture');
         $model->setScenario('update');
         if ($model->load(Yii::$app->request->post(), 'Block') && $model->validate()) {
             if (BlockService::update($model, $banner, $video, $texture)) {
                 $this->redirect(['all']);
             }
         }
         $templatesMap = TemplateService::getIdNameMap(['conditions' => ['type' => CmsGlobal::TYPE_BLOCK], 'prepend' => [['name' => '0', 'value' => 'Choose Template']]]);
         return $this->render('update', ['model' => $model, 'banner' => $banner, 'video' => $video, 'texture' => $texture, 'templatesMap' => $templatesMap]);
     }
     // Model not found
     throw new NotFoundHttpException(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_NOT_FOUND));
 }
Exemple #11
0
 /**
  * @return CmgFile - associated file
  */
 public function getFile()
 {
     return $this->hasOne(CmgFile::className(), ['id' => 'fileId']);
 }
Exemple #12
0
 public function getVideo()
 {
     return $this->hasOne(CmgFile::className(), ['id' => 'videoId']);
 }
Exemple #13
0
 /**
  * @return File - file url
  */
 public function getBanner()
 {
     return $this->hasOne(CmgFile::className(), ['id' => 'bannerId']);
 }
Exemple #14
0
 /**
  * @param CmgFile $file
  * @param string $name
  * @return CmgFile - after loading from request url
  */
 public static function loadFile($file, $name)
 {
     if (!isset($file)) {
         $file = new CmgFile();
     }
     $file->load(Yii::$app->request->post(), $name);
     return $file;
 }
Exemple #15
0
 /**
  * @return File - file url
  */
 public function getAvatar()
 {
     return $this->hasOne(CmgFile::className(), ['id' => 'avatarId']);
 }