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
     $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);
 }
Exemple #4
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;
 }