Exemple #1
0
 /**
  * @Route("/upload.php",name="content_media_upload")
  * @Method({"POST"})
  */
 public function uploadAction(Request $request)
 {
     $parentId = $request->get('parent', null);
     $type = $request->get('type', null);
     $schema = $request->get('schema', null);
     if (is_null($type) || is_null($schema) || is_null($parentId)) {
         return $this->returnErrorResponse();
     }
     try {
         $uploadedFile = $request->files->get('file');
         $mediaInfo = $this->mm()->handleUpload($uploadedFile);
     } catch (\Exception $e) {
         return new Response($e->getMessage(), 500);
     }
     if (!empty($mediaInfo)) {
         /**
          * @var \Bellwether\BWCMSBundle\Entity\ContentRepository $contentRepository
          * @var \Bellwether\BWCMSBundle\Entity\ContentEntity $content
          */
         $contentRepository = $this->em()->getRepository('BWCMSBundle:ContentEntity');
         $content = new ContentEntity();
         $content->setType($type);
         $content->setSchema($schema);
         $content->setSite($this->getSite());
         if ($parentId == 'Root') {
             $content->setTreeParent(null);
         } else {
             $parentEntity = $contentRepository->find($parentId);
             $content->setTreeParent($parentEntity);
         }
         $content->setTitle($mediaInfo['originalName']);
         $content->setTemplate('');
         $contentMedia = new ContentMediaEntity();
         $contentMedia->setFile($mediaInfo['filename']);
         $contentMedia->setExtension($mediaInfo['extension']);
         $contentMedia->setMime($mediaInfo['mimeType']);
         $contentMedia->setSize($mediaInfo['size']);
         $contentMedia->setHeight($mediaInfo['height']);
         $contentMedia->setWidth($mediaInfo['width']);
         if (!is_null($mediaInfo['binary'])) {
             $contentMedia->setData($mediaInfo['binary']);
         }
         $contentMedia->setContent($content);
         $this->em()->persist($contentMedia);
         $content->setSlug($this->cm()->generateSlug($content->getTitle(), $content->getType(), $parentId));
         $content->setStatus(ContentPublishType::Published);
         $this->cm()->save($content);
     }
     return new Response('Ok', 200);
 }
Exemple #2
0
 /**
  * @return ContentEntity
  */
 public function getNewContent()
 {
     $contentEntity = new ContentEntity();
     if ($this->isHierarchy()) {
         $contentEntity->setSortBy(ContentSortByType::SortIndex);
         $contentEntity->setSortOrder(ContentSortOrderType::ASC);
     } else {
         $contentEntity->setSortBy(ContentSortByType::Published);
         $contentEntity->setSortOrder(ContentSortOrderType::DESC);
     }
     if ($this->isUploadEnabled() || $this->isHierarchy()) {
         $contentEntity->setStatus(ContentPublishType::Published);
     } else {
         $contentEntity->setStatus(ContentPublishType::Draft);
     }
     if ($this->isPublishDateEnabled()) {
         $contentEntity->setPublishDate(new \DateTime());
     }
     if ($this->isExpireDateEnabled()) {
         $contentEntity->setExpireDate(new \DateTime());
     }
     $contentEntity->setScope(ContentScopeType::CPublic);
     return $contentEntity;
 }
 /**
  * @param string $slug
  * @param ContentEntity $parent
  * @return null|ContentEntity
  */
 public function getContentBySlug($slug, $parent = null, $contentTypes = array())
 {
     $qb = $this->cm()->getContentRepository()->createQueryBuilder('node');
     if (!empty($contentTypes)) {
         $condition = array();
         foreach ($contentTypes as $cInfo) {
             $condition[] = " (node.type = '" . $cInfo['type'] . "' AND node.schema = '" . $cInfo['schema'] . "' )";
         }
         if (!empty($condition)) {
             $qb->andWhere(' ( ' . implode(' OR ', $condition) . ' ) ');
         }
     }
     $qb->andWhere(" node.slug = '{$slug}' ");
     if (!empty($parent)) {
         $qb->andWhere(" node.treeParent = '" . $parent->getId() . "' ");
     }
     $qb->andWhere(" node.status ='" . ContentPublishType::Published . "' ");
     $qb->setMaxResults(1);
     try {
         return $qb->getQuery()->getSingleResult();
     } catch (NoResultException $e) {
         return null;
     }
 }
Exemple #4
0
 /**
  * @param ContentEntity $contentEntity
  * @param int $width
  * @param int $height
  * @return string|null
  */
 public function getContentThumbURL($contentEntity, $width = 128, $height = 128)
 {
     $contentClass = $this->cm()->getContentClass($contentEntity->getType(), $contentEntity->getSchema());
     if (!$contentClass->isUploadEnabled()) {
         $thumbURL = $this->getThumbService()->open($contentClass->getImage())->resize($width, $height)->cacheFile('guess');
         return $thumbURL;
     }
     if (!$this->isMedia($contentEntity)) {
         return null;
     }
     $media = $contentEntity->getMedia()->first();
     $this->checkAndCreateMediaCacheFile($media);
     if ($this->isImage($contentEntity)) {
         $thumbURL = $this->getThumbService()->open($this->getMediaCachePath($media))->resize($width, $height)->cacheFile('guess');
     } else {
         $thumbURL = $this->getThumbService()->open($this->getMimeResourceImage($media->getMime()))->resize($width, $height)->cacheFile('guess');
     }
     return $thumbURL;
 }
Exemple #5
0
 /**
  * @param ContentEntity $content
  * @return ContentEntity|void
  */
 public function save(ContentEntity $content = null)
 {
     if (null === $content) {
         return;
     }
     $currentUser = $this->getUser();
     $newRecord = false;
     if ($content->getId() == null) {
         $content->setCreatedDate(new \DateTime());
         if ($content->getAuthor() == null) {
             $content->setAuthor($currentUser);
         }
         $newRecord = true;
     } else {
         $content->setLastModifiedAuthor($currentUser);
         $content->setModifiedDate(new \DateTime());
     }
     if ($content->getPublishDate() == null && $content->getStatus() == ContentPublishType::Published) {
         $content->setPublishDate(new \DateTime());
     }
     if ($content->getExpireDate() == null && $content->getStatus() == ContentPublishType::Expired) {
         $content->setExpireDate(new \DateTime());
     }
     $this->em()->persist($content);
     $this->em()->flush();
     if ($newRecord) {
         $this->admin()->addAudit(AuditLevelType::Normal, 'Content::' . $content->getType() . '::' . $content->getSchema(), AuditActionType::Add, $content->getId(), 'Added: ' . $content->getTitle());
     } else {
         $this->admin()->addAudit(AuditLevelType::Normal, 'Content::' . $content->getType() . '::' . $content->getSchema(), AuditActionType::Edit, $content->getId(), 'Edit: ' . $content->getTitle());
     }
     return $content;
 }