Exemplo n.º 1
0
 /**
  * @param BlockInterface $block
  */
 public function load(BlockInterface $block)
 {
     $collection = $this->contentManager->getRepository()->findOrderedByIds(json_decode($block->getValue()));
     if ($collection) {
         $block->setCollection($collection);
     }
 }
Exemplo n.º 2
0
 /**
  * @param BlockInterface $block
  */
 public function load(BlockInterface $block)
 {
     $collection = $this->contentManager->getRepository()->createQueryBuilder('c')->where('c.id IN (:ids)')->setParameter('ids', json_decode($block->getValue()))->getQuery()->getResult();
     if ($collection) {
         $block->setCollection($collection);
     }
 }
Exemplo n.º 3
0
 /**
  * Tries to match a URL path with a set of routes.
  *
  * If the matcher can not find information, it must throw one of the
  * exceptions documented below.
  *
  * @param string $pathinfo The path info to be parsed (raw format, i.e. not
  *                         urldecoded)
  *
  * @return array An array of parameters
  *
  * @throws ResourceNotFoundException If the resource could not be found
  * @throws MethodNotAllowedException If the resource was found but the
  *                                   request method is not allowed
  */
 public function match($pathinfo)
 {
     $urlMatcher = new UrlMatcher($this->routeCollection, $this->getContext());
     $result = $urlMatcher->match($pathinfo);
     if (!empty($result)) {
         try {
             // The route matches, now check if it actually exists
             $result['content'] = $this->contentManager->findActiveBySlug($result['slug']);
         } catch (NoResultException $e) {
             try {
                 //is it directory index
                 if (substr($result['slug'], -1) == '/' || $result['slug'] == '') {
                     $result['content'] = $this->contentManager->findActiveBySlug($result['slug'] . 'index');
                 } else {
                     if ($this->contentManager->findActiveBySlug($result['slug'] . '/index')) {
                         $redirect = new RedirectResponse($this->request->getBaseUrl() . "/" . $result['slug'] . '/');
                         $redirect->sendHeaders();
                         exit;
                     }
                 }
             } catch (NoResultException $ex) {
                 try {
                     $result['content'] = $this->contentManager->findActiveByAlias($result['slug']);
                 } catch (NoResultException $ex) {
                     throw new ResourceNotFoundException('No page found for slug ' . $pathinfo);
                 }
             }
         }
     }
     return $result;
 }
 /**
  * @param  string $json
  * @return array
  */
 public function getTree($json)
 {
     $simpleTree = json_decode($json, true);
     if (!$simpleTree) {
         return [];
     }
     $collection = $this->contentManager->getRepository()->createQueryBuilder('c')->where('c.id IN (:ids)')->setParameter('ids', $this->gatherIds($simpleTree))->getQuery()->getArrayResult();
     // TODO Serialize instead of transforming the complete object to array
     $this->setCollection($collection);
     return $this->buildTree($simpleTree);
 }
Exemplo n.º 5
0
 /**
  * @param BlockInterface $block
  */
 public function load(BlockInterface $block)
 {
     $properties = $block->getProperties();
     $qb = $this->contentManager->getRepository()->createQueryBuilder('c');
     if (isset($properties['order_by'])) {
         $direction = isset($properties['order_direction']) ? $properties['order_direction'] : 'ASC';
         $qb->orderBy('c.' . $properties['order_by'], $direction);
     }
     $limit = isset($properties['limit']) ? $properties['limit'] : 10;
     $qb->setMaxResults($limit);
     $collection = $qb->getQuery()->getResult();
     if ($collection) {
         $block->setCollection($collection);
     }
 }
Exemplo n.º 6
0
 /**
  * @param BlockInterface $block
  *
  * @return array
  */
 public function getViewParameters(BlockInterface $block)
 {
     $parameters = ['block_service' => $this, 'block' => $block];
     if ($this->environment->getObject() instanceof Content) {
         // Get current page slug to mark it as active when listing
         $parameters['content'] = $this->environment->getObject();
         $parameters['breadcrumbs'] = $parameters['content']->getBreadCrumbs();
     } else {
         $parameters['content'] = $this->contentManager->initialize();
         $parameters['content']->setSlug('example');
         $parameters['breadcrumbs'] = ['directory' => 'Example Directory', 'example' => 'Example Page'];
     }
     // Add homepage link as first breadcrumb if it does not exist in breadcrumbs
     if (!array_key_exists('index', $parameters['breadcrumbs'])) {
         $homePage = $this->contentManager->findOneBySlug('index');
         $parameters['breadcrumbs'] = array_merge(['index' => $homePage->getShortTitle()], $parameters['breadcrumbs']);
     }
     return $parameters;
 }
Exemplo n.º 7
0
 /**
  * Tries to match a URL path with a set of routes.
  *
  * If the matcher can not find information, it must throw one of the
  * exceptions documented below.
  *
  * @param string $pathinfo The path info to be parsed (raw format, i.e. not
  *                         urldecoded)
  *
  * @return array An array of parameters
  *
  * @throws ResourceNotFoundException If the resource could not be found
  */
 public function match($pathinfo)
 {
     $urlMatcher = new UrlMatcher($this->routeCollection, $this->getContext());
     $result = $urlMatcher->match($pathinfo);
     if (!empty($result)) {
         // The route matches, now check if it actually exists
         $slug = $result['slug'];
         try {
             //is it directory index
             if (substr($slug, -1) == '/') {
                 $slug = rtrim($slug, '/');
             }
             $result['content'] = $this->contentManager->findActiveBySlug($slug);
         } catch (NoResultException $e) {
             try {
                 $result['content'] = $this->contentManager->findActiveByAlias($slug);
             } catch (NoResultException $ex) {
                 throw new ResourceNotFoundException('No page found for slug ' . $pathinfo);
             }
         }
     }
     return $result;
 }
Exemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     if ($options['as_object']) {
         $builder->addModelTransformer(new CallbackTransformer(function ($original) {
             return $original;
         }, function ($submitted) {
             if (null == $submitted) {
                 return null;
             }
             $entity = $this->contentManager->getRepository()->find($submitted);
             return $entity;
         }));
     } else {
         $builder->addModelTransformer(new CallbackTransformer(function ($original) {
             if (null == $original) {
                 return null;
             }
             $entity = $this->contentManager->getRepository()->find($original);
             return $entity;
         }, function ($submitted) {
             return $submitted;
         }));
     }
 }
Exemplo n.º 9
0
 /**
  * Load the collection if any conditions are defined
  *
  * @param BlockInterface $block
  */
 protected function loadCollection(BlockInterface $block)
 {
     $properties = $block->getProperties();
     $conditions = isset($properties['conditions']) ? $properties['conditions'] : '[]';
     $conditions = $this->expressionEngine->deserialize($conditions);
     if (empty($conditions)) {
         return;
     }
     $qb = $this->expressionEngine->toQueryBuilder($conditions, $this->contentManager->getClass());
     if (isset($properties['order_by'])) {
         $direction = isset($properties['order_direction']) ? $properties['order_direction'] : 'ASC';
         $qb->orderBy('a.' . $properties['order_by'], $direction);
     }
     $limit = isset($properties['limit']) ? $properties['limit'] : 10;
     $qb->setMaxResults($limit);
     $collection = $qb->getQuery()->getResult();
     if ($collection) {
         $block->setCollection($collection);
     }
 }
Exemplo n.º 10
0
 /**
  * Get the search results
  *
  * @return Content[]
  */
 public function getSearchResults()
 {
     $term = $this->getRequest()->get('search', '');
     return $this->contentManager->getRepository()->search($term);
 }
Exemplo n.º 11
0
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $optionsResolver)
 {
     $tree = $this->contentManager->getRepository()->childrenHierarchy();
     $optionsResolver->setDefaults(['tree' => $tree]);
 }