Пример #1
0
 /**
  * @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)]);
 }
Пример #2
0
 /**
  * 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();
 }
Пример #3
0
 /**
  * @covers BackBee\NestedNode\Media::setTitle
  * @covers BackBee\NestedNode\Media::getTitle
  */
 public function testSetAndGetTitle()
 {
     $this->assertEquals($this->media, $this->media->setTitle('test-title'));
     $this->assertEquals('test-title', $this->media->getTitle());
 }