Finds the media with a given id.
public findMediaById ( $id ) : |
||
$id | ||
return |
/** * Sets a media with a given id as the avatar of a given contact. * * @param Contact $contact * @param array $avatar with id property * * @throws EntityNotFoundException */ private function setAvatar(Contact $contact, $avatar) { $mediaEntity = null; if (is_array($avatar) && $this->getProperty($avatar, 'id')) { $mediaId = $this->getProperty($avatar, 'id'); $mediaEntity = $this->mediaRepository->findMediaById($mediaId); if (!$mediaEntity) { throw new EntityNotFoundException($this->mediaRepository->getClassName(), $mediaId); } } $contact->setAvatar($mediaEntity); }
/** * {@inheritdoc} */ public function move($id, $locale, $destCollection) { try { $mediaEntity = $this->mediaRepository->findMediaById($id); if ($mediaEntity === null) { throw new MediaNotFoundException($id); } $mediaEntity->setCollection($this->em->getReference(self::ENTITY_NAME_COLLECTION, $destCollection)); $this->em->flush(); return $this->addFormatsAndUrl(new Media($mediaEntity, $locale, null)); } catch (DBALException $ex) { throw new CollectionNotFoundException($destCollection); } }