/** * Create a new media entry * * @param AbstractClassContent $content * @param string $title * * @return void */ protected function createNewMedia(AbstractClassContent $content, $title = '') { $newMedia = new NestedNodeMedia(); $newMedia->setMediaFolder($this->_em->getRepository('BackBee\\NestedNode\\MediaFolder')->getRoot()); $newMedia->setContent($content); $newMedia->setTitle(trim($title . ' [' . $this->request->get('selectedProportion') . ']')); $this->_em->persist($newMedia); $this->_em->flush(); }
/** * @covers BackBee\NestedNode\Media::setModified * @covers BackBee\NestedNode\Media::getModified */ public function testSetAndGetModified() { $tomorrow = new \DateTime('tomorrow'); $this->assertEquals($this->media, $this->media->setModified($tomorrow)); $this->assertEquals($tomorrow, $this->media->getModified()); }
/** * @param Request $request * @return Response * @throws BadRequestHttpException */ public function postAction(Request $request) { $contentUid = $request->request->get('content_uid'); $contentType = $request->request->get('content_type', null); $mediaFolderUid = $request->request->get('folder_uid', null); $mediaTitle = $request->request->get('title', 'Untitled media'); if (null === $mediaFolderUid) { $mediaFolder = $this->getMediaFolderRepository()->getRoot(); } else { $mediaFolder = $this->getMediaFolderRepository()->find($mediaFolderUid); } if (null === $mediaFolder) { throw new NotFoundHttpException('Cannot find a media folder'); } if (null !== ($content = $this->getClassContentManager()->findOneByTypeAndUid($contentType, $contentUid))) { $this->autoCommitContent($content); } $media = new Media(); $media->setContent($content); $media->setTitle($mediaTitle); $media->setMediaFolder($mediaFolder); $this->getEntityManager()->persist($media); $this->getEntityManager()->flush(); return $this->createJsonResponse(null, 201, ['BB-RESOURCE-UID' => $media->getId(), 'Location' => $this->getApplication()->getRouting()->getUrlByRouteName('bb.rest.media.get', ['version' => $request->attributes->get('version'), 'uid' => $media->getId()], '', false)]); }
/** * @param \BackBee\ClassContent\AbstractClassContent $content * @return string * * @deprecated since version 0.10.0 */ public static function getAbsolutePath($content = null) { return __DIR__ . '/../../repository/' . Media::getUploadDir(); }