/** * Get author list * * @return Author[] */ public function authors() { if (!$this->authors) { $this->authors = Author::fetch($this); } return $this->authors; }
/** * 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')]; } }