/**
  * Update Album Cover Image.
  * @param int $id
  * @throws CHttpException
  */
 public function actionCover($id)
 {
     $model = $this->loadModel($id);
     $model->scenario = 'update-cover';
     $user = $this->getUser();
     if (!$model->canEdit()) {
         throw new CHttpException(403, 'You are not allowed to perform this action');
     }
     if (isset($_POST['Album'])) {
         $model->attributes = $_POST['Album'];
         if ($model->validate('image')) {
             if ($model->cover instanceof PublicFile) {
                 $model->cover->delete();
             }
             PublicFile::attachPrecreated($model, $model->image);
             $this->redirect(['/album/view', 'id' => $model->id, 'username' => $user->username, 'uguid' => $user->guid]);
         }
     }
     $this->render('/album/cover', compact('model', 'user'));
 }
 /**
  * Creates a new album with optional album cover.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $user = $this->getUser();
     if ($user->id != Yii::app()->user->id) {
         throw new CHttpException(403, 'You can create album only on your profile.');
     }
     $this->subLayout = "application.modules.album.views._layout";
     $model = new Album();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Album'])) {
         $_POST = Yii::app()->input->stripClean($_POST);
         $_POST['containerGuid'] = Yii::app()->user->guid;
         $_POST['containerClass'] = 'User';
         $model->content->populateByForm();
         $model->attributes = $_POST['Album'];
         if ($model->save()) {
             PublicFile::attachPrecreated($model, Yii::app()->request->getParam('cover'));
             $this->redirect(['/album/view', 'id' => $model->id, 'username' => $user->username, 'uguid' => $user->guid]);
         }
     }
     $this->render('/album/create', ['model' => $model, 'user' => $user]);
 }
 /**
  * Handles a single upload by given CUploadedFile and returns an array
  * of informations.
  *
  * The 'error' attribute of the array, indicates there was an error.
  *
  * Informations on error:
  *       - error: true
  *       - errorMessage: some message
  *       - name: name of the file
  *       - size: file size
  *
  * Informations on success:
  *      - error: false
  *      - name: name of the uploaded file
  *      - size: file size
  *      - guid: of the file
  *      - url: url to the file
  *      - thumbnailUrl: url to the thumbnail if exists
  *
  * @param type $cFile
  * @return Array Informations about the uploaded file
  */
 protected function handleFileUpload($cFile, $object = null)
 {
     $output = [];
     $file = new PublicFile();
     $file->setUploadedFile($cFile);
     if ($object != null) {
         $file->object_id = $object->getPrimaryKey();
         $file->object_model = get_class($object);
     }
     if ($file->validate() && $file->save()) {
         $output['error'] = false;
         $output['guid'] = $file->guid;
         $output['name'] = $file->file_name;
         $output['title'] = $file->title;
         $output['size'] = $file->size;
         $output['mimeIcon'] = HHtml::getMimeIconClassByExtension($file->getExtension());
     } else {
         $output['error'] = true;
         $output['errors'] = $file->getErrors();
     }
     $output['name'] = $file->file_name;
     $output['size'] = $file->size;
     $output['deleteUrl'] = "";
     $output['deleteType'] = "";
     $output['url'] = "";
     $output['thumbnailUrl'] = "";
     return $output;
 }