/** * Returns an array of items for a page. * * @param int $offset Page offset * @param int $itemCountPerPage Number of items per page * * @return array */ public function getItems($offset, $itemCountPerPage) { $albumService = $this->getAlbumService(); $photoService = $this->getPhotoService(); $albums = $albumService->getAlbums($this->album, $offset, $itemCountPerPage); $photoCount = $itemCountPerPage - count($albums); $photoStart = max($offset - $this->album->getAlbumCount(), 0); $photos = $photoService->getPhotos($this->album, $photoStart, $photoCount); $items = array_merge($albums, $photos); return $items; }
/** * Updates the dates on the parent album if it exists. * * @param \Photo\Model\Album $album */ protected function albumPersisted($album) { $parent = $album->getParent(); if (!is_null($parent) && !is_null($album->getStartDateTime())) { if (is_null($parent->getStartDateTime()) || $parent->getStartDateTime()->getTimestamp() > $album->getStartDateTime()->getTimeStamp()) { $parent->setStartDateTime($album->getStartDateTime()); } if (is_null($parent->getEndDateTime()) || $parent->getEndDateTime()->getTimestamp() < $album->getEndDateTime()->getTimeStamp()) { $parent->setEndDateTime($album->getEndDateTime()); } } }
/** * Deletes the file belonging to the album cover for an album. * * @param \Photo\Model\Album $album */ public function deleteAlbumCover($album) { $this->getPhotoService()->deletePhotoFile($album->getCoverPath()); }
/** * Add a sub album to an album. * * @param \Photo\Model\Album $album */ public function addAlbum($album) { $album->setParent($this); $this->children[] = $album; }
/** * Checks if the specified photo exists in the database already and returns * it if it does. * * @param string $path The storage path of the photo * @param \Photo\Model\Album $album the album the photo is in * @return \Photo\Model\Photo|null */ public function getPhotoByData($path, $album) { return $this->getRepository()->findOneBy(['path' => $path, 'album' => $album->getId()]); }