/** * Updates the dates on the parent album. * * @param \Photo\Model\Photo $photo */ protected function photoPersisted($photo) { $album = $photo->getAlbum(); // Update start and end date if the added photo is newer or older $albumStartDateTime = $album->getStartDateTime(); if (is_null($albumStartDateTime) || $albumStartDateTime->getTimestamp() > $photo->getDateTime()->getTimeStamp()) { $album->setStartDateTime($photo->getDateTime()); } $albumEndDateTime = $album->getEndDateTime(); if (is_null($albumEndDateTime) || $albumEndDateTime->getTimestamp() < $photo->getDateTime()->getTimeStamp()) { $photo->getAlbum()->setEndDateTime($photo->getDateTime()); } }
/** * 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.dateTime < ?1 AND a.album = ?2')->setParameter(1, $photo->getDateTime())->setParameter(2, $photo->getAlbum())->orderBy('a.dateTime', 'DESC')->setMaxResults(1); $res = $qb->getQuery()->getResult(); return empty($res) ? null : $res[0]; }
/** * Determine the preference rating of the photo. * * @param \Photo\Model\Photo $photo * @param integer $occurences * @return float */ public function ratePhoto($photo, $occurences) { $tagged = $photo->getTags()->count() > 0; $now = new \DateTime(); $age = $now->diff($photo->getDateTime(), true)->days; $res = $occurences * (1 + 1 / $age); return $tagged ? 1.5 * $res : $res; }