コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function getBox(Media $media, array $settings)
 {
     $size = $media->getBox();
     if ($settings['width'] == null && $settings['height'] == null) {
         throw new \RuntimeException(sprintf('Width/Height parameter is missing in context "%s" for provider "%s". Please add at least one parameter.', $media->getContext(), $media->getProviderName()));
     }
     if ($settings['height'] == null) {
         $settings['height'] = (int) ($settings['width'] * $size->getHeight() / $size->getWidth());
     }
     if ($settings['width'] == null) {
         $settings['width'] = (int) ($settings['height'] * $size->getWidth() / $size->getHeight());
     }
     return $this->computeBox($media, $settings);
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function getBox(Media $media, array $settings)
 {
     $size = $media->getBox();
     if (null != $settings['height']) {
         if ($size->getHeight() > $size->getWidth()) {
             $higher = $size->getHeight();
             $lower = $size->getWidth();
         } else {
             $higher = $size->getWidth();
             $lower = $size->getHeight();
         }
         if ($higher - $lower > 0) {
             return new Box($lower, $lower);
         }
     }
     $settings['height'] = (int) ($settings['width'] * $size->getHeight() / $size->getWidth());
     if ($settings['height'] < $size->getHeight() && $settings['width'] < $size->getWidth()) {
         return new Box($settings['width'], $settings['height']);
     }
     return $size;
 }
コード例 #3
0
 private function mediaObjectToArray(Media $media)
 {
     $mediaArray = null;
     if ($media->getId()) {
         if (!$this->advertisement) {
             $this->advertisement = new Advertisement();
             $this->advertisement->setInstitution($this->institution);
         }
         $mediaArray = array('id' => $media->getId(), 'uuid' => $media->getUuid(), 'name' => $media->getName(), 'caption' => $media->getCaption());
     }
     return $mediaArray;
 }
 private function doMove(Institution $institution, Media $media, $sizes)
 {
     // point file system to new path
     $this->fileSystem->rename($institution->getId() . '/' . $media->getName(), $media->getName());
     // do resize
     $this->institutionMediaService->resize($media, $sizes);
 }
コード例 #5
0
 /**
  * Delete Media and removed all files related to the media
  * @param Media $media object
  * @param array $sizes Other image sizes of the media
  * @return boolean
  */
 public function deleteMediaAndFiles($media, $sizes = array())
 {
     $result = false;
     if ($media) {
         $mediaName = $media->getName();
         $this->entityManager->remove($media);
         try {
             $this->entityManager->flush();
             //$this->filesystem->delete($mediaName);
             foreach ($sizes as $each) {
                 $key = $each . '_' . $mediaName;
                 if ($this->filesystem->has($key)) {
                     $this->filesystem->delete($key);
                 }
             }
             $result = true;
         } catch (\Exception $e) {
             $result = false;
             var_dump($e);
         }
     }
     return $result;
 }