Exemple #1
0
 /**
  * Returns the previous photo in the album to display
  *
  * @param \Photo\Model\Photo $photo
  *
  * @return \Photo\Model\Album|null Photo if there is a previous
  * photo, null otherwise
  */
 public function getPreviousPhoto($photo)
 {
     $qb = $this->em->createQueryBuilder();
     $qb->select('a')->from('Photo\\Model\\Photo', 'a')->where('a.id < ?1 AND a.album = ?2')->setParameter(1, $photo->getId())->setParameter(2, $photo->getAlbum())->addOrderBy('a.id', 'DESC')->setMaxResults(1);
     $res = $qb->getQuery()->getResult();
     return empty($res) ? null : $res[0];
 }
Exemple #2
0
 /**
  * Returns a unique file name for a photo.
  *
  * @param \Photo\Model\Photo $photo the photo to get a name for
  *
  * @return string
  */
 public function getPhotoFileName($photo)
 {
     // filtering is required to prevent invalid characters in file names.
     $filter = new \Zend\I18n\Filter\Alnum(true);
     $albumName = $filter->filter($photo->getAlbum()->getName());
     // don't put spaces in file names
     $albumName = str_replace(' ', '-', $albumName);
     $extension = substr($photo->getPath(), strpos($photo->getPath(), '.'));
     $photoName = $albumName . '-' . $photo->getDateTime()->format('Y') . '-' . $photo->getId() . $extension;
     return $photoName;
 }