Exemple #1
0
 /**
  * Get author's pictures
  *
  * @return Picture[]
  */
 public function pics()
 {
     if (!$this->pics) {
         $this->pics = Picture::fetch($this);
         if ($blacklist = $this->album->meta('blacklist') and isset($blacklist[$this->name])) {
             $this->pics = array_diff_key($this->pics, array_flip($blacklist[$this->name]));
         }
     }
     return $this->pics;
 }
Exemple #2
0
 /**
  * Upload pics to album
  *
  * @access 5
  * @json
  *
  * @param int $year
  * @param int $month
  * @param int $day
  * @param string $flatname
  * @param Context $ctx
  * @return Response\Json
  *
  * @throws NotFoundException
  */
 public function upload($year, $month, $day, $flatname, Context $ctx)
 {
     $year = (int) $year;
     $month = (int) $month;
     $day = (int) $day;
     // get album
     $album = Album::one($year, $month, $day, $flatname);
     if (!$album) {
         throw new NotFoundException();
     }
     try {
         // get author (or create it)
         $author = $album->author($ctx->user->username);
         if (!$author) {
             $author = Author::create($album, $ctx->user->username);
             $ctx->logger->info($ctx->user->username . ' adds author "' . $author->name . '" in "' . $album->fullname . '"', $_POST);
         }
         // get uploaded file
         $upload = $ctx->request->file('file');
         if (!$upload) {
             throw new InvalidPictureUpload();
         }
         // add uploaded picture
         $picture = Picture::create($author, $upload);
         $ctx->logger->info($ctx->user->username . ' adds picture "' . $picture->filename . '" to "' . $album->fullname . '"');
         return ['state' => true];
     } catch (AuthorAlreadyExists $e) {
         return ['state' => false, 'message' => text('logic.author.already-exists')];
     } catch (PictureAlreadyExists $e) {
         return ['state' => false, 'message' => text('logic.picture.already-exists')];
     } catch (InvalidPictureUpload $e) {
         return ['state' => false, 'message' => text('logic.picture.upload.empty')];
     } catch (InvalidPictureFile $e) {
         return ['state' => false, 'message' => text('logic.picture.upload.denied')];
     } catch (\Exception $e) {
         return ['state' => false, 'message' => text('logic.picture.upload.failed')];
     }
 }