/**
  * Returns the URI of the icon of the provided content.
  * 
  * @param  AbstractContent $content The content.
  * 
  * @return string|null              The icon URL if found, null otherwise.
  */
 public function getIcon(AbstractContent $content)
 {
     if (null === ($baseFolder = $this->getBaseFolder())) {
         return null;
     }
     $defaultImage = $content->getDefaultImageName();
     if ('/' === substr($defaultImage, 0, 1)) {
         $iconUrl = $defaultImage;
         $urlType = RouteCollection::IMAGE_URL;
     } else {
         $iconUrl = $this->resolveResourceThumbnail($defaultImage);
         $urlType = RouteCollection::RESOURCE_URL;
     }
     return $this->application->getRouting()->getUri($iconUrl, null, null, $urlType);
 }
 /**
  * @param Request $request
  *
  * @Rest\Pagination(default_count=25, max_count=100)
  */
 public function getCollectionAction(Request $request, $start, $count)
 {
     $queryParams = $request->query->all();
     $mediaFolderUid = $request->get('mediaFolder_uid', null);
     $usePagination = $request->get("usePagination", false);
     $contentType = $request->get('contentType', null);
     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 !== $contentType) {
         try {
             $queryParams['contentType'] = AbstractContent::getClassnameByContentType($contentType);
         } catch (InvalidContentTypeException $e) {
             throw new NotFoundHttpException(sprintf('Provided content type (:%s) is invalid.', $queryParams['contentType']));
         }
     }
     $paging = ['start' => $start, 'limit' => $count];
     $paginator = $this->getMediaRepository()->getMedias($mediaFolder, $queryParams, '_modified', 'desc', $paging);
     $resultsIter = $paginator->getIterator();
     $results = [];
     while ($resultsIter->valid()) {
         $results[] = $resultsIter->current();
         $resultsIter->next();
     }
     $pager = $usePagination ? $paginator : null;
     return $this->addRangeToContent($this->createJsonResponse($this->mediaToJson($results)), $pager, $start, count($results));
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $em = $this->getContainer()->get('bbapp')->getEntityManager();
     $orphans = $em->getConnection()->executeQuery('SELECT c.uid, c.classname FROM content c
          LEFT JOIN content_has_subcontent sc ON sc.content_uid = c.uid
          LEFT JOIN page p ON p.contentset = c.uid
          LEFT JOIN media m ON m.content_uid = c.uid
          WHERE sc.content_uid IS NULL AND p.contentset IS NULL AND m.content_uid IS NULL')->fetchAll();
     $contents_count = $em->getConnection()->executeQuery('SELECT count(*) FROM content')->fetch(\PDO::FETCH_NUM);
     $before_contents_count = $contents_count[0];
     $output->writeln("\nBefore cleaning, content table contains {$before_contents_count} row(s)" . " (including " . count($orphans) . " potentials orphans).\n");
     foreach ($orphans as $orphan) {
         try {
             $classname = AbstractContent::getFullClassname($orphan['classname']);
             $orphan_object = $em->find($classname, $orphan['uid']);
             $em->getRepository($classname)->deleteContent($orphan_object);
         } catch (ClassNotFoundException $e) {
             $uid = $orphan['uid'];
             $em->getConnection()->executeUpdate("DELETE FROM content_has_subcontent WHERE content_uid = '{$uid}' OR parent_uid = '{$uid}'");
             $em->getConnection()->executeUpdate("DELETE FROM revision WHERE content_uid = '{$uid}'");
             $em->getConnection()->executeUpdate("DELETE FROM content WHERE uid = '{$uid}'");
         }
     }
     $em->flush();
     $contents_count = $em->getConnection()->executeQuery('SELECT count(*) FROM content')->fetch(\PDO::FETCH_NUM);
     $rows_saved = $before_contents_count - $contents_count[0];
     $output->writeln("After cleaning, content table contains {$contents_count['0']} row(s) ({$rows_saved} row(s) saved).\n");
 }
 /**
  * Returns the icon URL from the parameter value.
  * 
  * @param  AbstractContent $content   The content.
  * @param  string          $paramName The parameter name.
  * 
  * @return string|null                The icon URL.
  */
 private function iconizeByParam(AbstractContent $content, $paramName)
 {
     if (null === ($parameter = $content->getParam($paramName))) {
         return null;
     }
     if (empty($parameter['value'])) {
         return null;
     }
     return $this->getUri($parameter['value']);
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function jsonSerialize()
 {
     $this->getContent()->setDraft(null);
     $sourceData = $this->getContent()->jsonSerialize(self::JSON_CONCISE_FORMAT);
     $this->getContent()->setDraft($this);
     $draftData = parent::jsonSerialize(self::JSON_CONCISE_FORMAT);
     $draftData['uid'] = $sourceData['uid'];
     $draftData['type'] = $sourceData['type'];
     $draftData['elements'] = $this->computeElements($sourceData['elements'], $draftData['elements']);
     $parameters = [];
     foreach ($draftData['parameters'] as $key => $parameter) {
         if ($parameter['value'] !== $sourceData['parameters'][$key]['value']) {
             $parameters[$key] = ['current' => $sourceData['parameters'][$key]['value'], 'draft' => $parameter['value']];
         }
     }
     $draftData['parameters'] = $parameters;
     if ($this->getRevision() !== $this->getContent()->getRevision()) {
         $draftData['state'] = self::STATE_CONFLICTED;
     }
     return array_merge(parent::jsonSerialize(self::JSON_INFO_FORMAT), $draftData);
 }
 /**
  * {@inheritdoc}
  */
 public function jsonSerialize($format = self::JSON_DEFAULT_FORMAT)
 {
     $data = parent::jsonSerialize($format);
     if (self::JSON_INFO_FORMAT === $format) {
         return $data;
     }
     if (!isset($data['label'])) {
         $data['label'] = $this->getProperty('name');
     }
     if (self::JSON_CONCISE_FORMAT === $format) {
         $data['image'] = $this->getImageName();
         return $data;
     }
     if (self::JSON_DEFINITION_FORMAT === $format) {
         $data['parameters'] = 0 === count($this->getDefaultParams()) ? new \ArrayObject() : $this->getDefaultParams();
     }
     $properties = $this->getProperty();
     unset($properties['indexation'], $properties['labelized-by'], $properties['clonemode'], $properties['cache-lifetime']);
     $data = array_merge(['defaultOptions' => 0 === count($this->defaultOptions) ? new \ArrayObject() : $this->defaultOptions, 'properties' => $properties, 'image' => self::JSON_DEFINITION_FORMAT === $format ? $this->getDefaultImageName() : $this->getImageName()], $data);
     return $data;
 }
 private function getClassicCollection(Request $request, $mediafolder, $start, $count)
 {
     $params = $request->query->all();
     $contentType = $request->get('contentType', null);
     if (null !== $contentType) {
         try {
             $params['contentType'] = AbstractContent::getClassnameByContentType($contentType);
         } catch (InvalidContentTypeException $e) {
             throw new NotFoundHttpException(sprintf('Provided content type (:%s) is invalid.', $params['contentType']));
         }
     }
     return $this->getMediaRepository()->getMedias($mediafolder, $params, '_modified', 'desc', ['start' => $start, 'limit' => $count]);
 }