Example #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.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];
 }
Example #2
0
 /**
  * Move the uploaded photo to the storage and store it in the database.
  * All upload actions should use this function to prevent "ghost" files
  * or database entries
  *
  * @param string $path the temporary path of the uploaded photo
  * @param \Photo\Model\Album $targetAlbum the album to save the photo in
  * @param boolean $move whether to move the photo instead of copying it
  *
  * @return \Photo\Model\Photo|boolean
  */
 public function storeUploadedPhoto($path, $targetAlbum, $move = false)
 {
     if (!$this->isAllowed('photo', 'add')) {
         throw new \User\Permissions\NotAllowedException($this->getTranslator()->translate('Not allowed to add photos.'));
     }
     $config = $this->getConfig();
     $storagePath = $this->generateStoragePath($path);
     //check if photo exists already in the database
     $photo = $this->getPhotoMapper()->getPhotoByData($storagePath, $targetAlbum);
     //if the returned object is null, then the photo doesn't exist
     if (is_null($photo)) {
         $photo = new PhotoModel();
         $photo->setAlbum($targetAlbum);
         $photo = $this->getMetadataService()->populateMetaData($photo, $path);
         $photo->setPath($storagePath);
         $mapper = $this->getPhotoMapper();
         $mapper->getConnection()->beginTransaction();
         try {
             /*
              * Create and set the storage paths for thumbnails.
              */
             $photo->setLargeThumbPath($this->createThumbnail($path, $config['large_thumb_size']['width'], $config['large_thumb_size']['height']));
             $photo->setSmallThumbPath($this->createThumbnail($path, $config['small_thumb_size']['width'], $config['small_thumb_size']['height']));
             if ($move) {
                 rename($path, $config['upload_dir'] . '/' . $storagePath);
             } else {
                 copy($path, $config['upload_dir'] . '/' . $storagePath);
             }
             $mapper->persist($photo);
             $mapper->flush();
             $mapper->getConnection()->commit();
         } catch (Exception $e) {
             // Rollback if anything went wrong
             $mapper->getConnection()->rollBack();
             $this->getPhotoService()->deletePhotoFiles($photo);
             return false;
         }
     }
     return $photo;
 }
Example #3
0
 public function addAction()
 {
     $logged = $this->getConnection();
     $form = new PhotoForm();
     $form->get('submit')->setValue('Add');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $photo = new Photo();
         $form->setInputFilter($photo->getInputFilter());
         $post = $request->getPost()->toArray();
         $post['idMembre'] = $logged;
         $form->setData($post);
         if ($form->isValid()) {
             $data = $form->getData();
             $savePhoto = array('idMembre' => $logged, 'description' => $post['description'], 'titre' => $post['titre'], 'lien' => $post['lien']);
             $photo->exchangeArray($savePhoto);
             $this->getPhotoTable()->savePhoto($photo);
             // Redirect to list of photos
             return $this->redirect()->toRoute('photo');
         }
     }
     return array('form' => $form);
 }
Example #4
0
 /**
  * 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());
     }
 }
Example #5
0
 /**
  * Count a hit for the specified photo. Should be called whenever a photo is viewed.
  *
  * @param \Photo\Model\Photo $photo
  */
 public function countHit($photo)
 {
     $hit = new HitModel();
     $hit->setDateTime(new \DateTime());
     $photo->addHit($hit);
     $this->getPhotoMapper()->flush();
 }
Example #6
0
 /**
  * Populates the metadata of a photo based on the EXIF data of the photo
  *
  * @param \Photo\Model\Photo $photo the photo to add the metadata to.
  * @param string $path The path where the actual image file is stored
  *
  * @return \Photo\Model\Photo the photo with the added metadata
  */
 public function populateMetadata($photo, $path)
 {
     $exif = read_exif_data($path, 'EXIF');
     if ($exif) {
         $photo->setArtist($exif['Artist']);
         $photo->setCamera($exif['Model']);
         $photo->setDateTime(new \DateTime($exif['DateTimeOriginal']));
         $photo->setFlash($exif['Flash'] != 0);
         $photo->setFocalLength($this->frac2dec($exif['FocalLength']));
         $photo->setExposureTime($this->frac2dec($exif['ExposureTime']));
         if (isset($exif['ShutterSpeedValue'])) {
             $photo->setShutterSpeed($this->exifGetShutter($exif['ShutterSpeedValue']));
         }
         if (isset($exif['ShutterSpeedValue'])) {
             $photo->setAperture($this->exifGetFstop($exif['ApertureValue']));
         }
         $photo->setIso($exif['ISOSpeedRatings']);
     } else {
         // We must have a date/time for a photo
         // Since no date is known, we use the current one
         $photo->setDateTime(new \DateTime());
     }
     return $photo;
 }
Example #7
0
 /**
  * Add a photo to an album.
  *
  * @param \Photo\Model\Photo $photo
  */
 public function addPhoto($photo)
 {
     $photo->setAlbum($this);
     $this->photos[] = $photo;
 }