Ejemplo n.º 1
0
 /**
  * @param BlockInterface $block
  */
 public function load(BlockInterface $block)
 {
     $levels = isset($block->getProperties()['levels']) ? $block->getProperties()['levels'] : 1;
     /** @var NavigationBlock $block */
     if ($block->getValue() == NavigationBlock::CHOICE_CUSTOM && isset($block->getProperties()['content'])) {
         $ids = json_decode($block->getProperties()['content'], true);
         $collection = $this->contentManager->getRepository()->findOrderedByIds($ids);
         $block->setTree($collection);
     } elseif ($block->getValue() == NavigationBlock::CHOICE_TOP_LEVEL) {
         $collection = $this->contentManager->getRepository()->findByLevels($levels);
         $block->setTree($collection);
     }
 }
Ejemplo n.º 2
0
 public function getViewParameters(BlockInterface $block)
 {
     $properties = $block->getProperties();
     $limit = isset($properties['limit']) ? $properties['limit'] : 5;
     $reviews = $this->reviewManager->getRepository()->createQueryBuilder('r')->orderBy('r.createdAt', 'DESC')->setMaxResults($limit)->getQuery()->getResult();
     $parameters = parent::getViewParameters($block);
     $parameters['reviews'] = $reviews;
     return $parameters;
 }
Ejemplo n.º 3
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);
     }
 }
Ejemplo n.º 4
0
 private function normalizeTabs(BlockInterface $block)
 {
     $properties = $block->getProperties();
     if (isset($properties['tabs']) && count($properties['tabs'])) {
         if (isset($properties['tabs'][0]) && !is_array($properties['tabs'][0])) {
             $converted = array();
             $sort = count($properties['tabs']);
             foreach ($properties['tabs'] as $key => $value) {
                 $converted[] = ['label' => $value, 'key' => $key, 'sort' => $sort--];
             }
             $properties['tabs'] = $converted;
         }
         $maxKey = 0;
         $maxSort = 0;
         array_walk($properties['tabs'], function ($tab) use(&$maxKey, &$maxSort) {
             if (isset($tab['key']) && $tab['key'] > $maxKey) {
                 $maxKey = $tab['key'];
             }
             if (isset($tab['sort']) && $tab['sort'] > $maxSort) {
                 $maxSort = $tab['sort'];
             }
         });
         $maxKey++;
         $maxSort++;
         foreach ($properties['tabs'] as &$tab) {
             if (!isset($tab['key']) || $tab['key'] === null || $tab['key'] === "") {
                 $tab['key'] = $maxKey++;
             }
             if (!isset($tab['sort']) || $tab['sort'] === null || $tab['sort'] === "") {
                 $tab['sort'] = $maxSort++;
             }
         }
         uasort($properties['tabs'], function ($a, $b) {
             return $a['sort'] < $b['sort'] ? 1 : 0;
         });
         $block->setProperties($properties);
     }
     return $block;
 }
Ejemplo n.º 5
0
 /**
  * @param BlockInterface $block
  *
  * @return array
  */
 public function getGutterClasses(BlockInterface $block)
 {
     $gutterStyles = array();
     if ($block->getColumnCount()) {
         $properties = $block->getProperties();
         if (isset($properties['gutters']) && count($properties['gutters']) > 0) {
             foreach ($properties['gutters'] as $screen => $cols) {
                 foreach ($cols as $col => $span) {
                     if (empty($span)) {
                         continue;
                     }
                     $gutterStyles[$col][] = "p-{$screen}-{$span}";
                 }
             }
         }
     }
     return $gutterStyles;
 }
Ejemplo n.º 6
0
 /**
  * @param BlockInterface $block
  */
 public function load(BlockInterface $block)
 {
     $properties = $block->getProperties();
     $opts = array();
     if (isset($properties['responseType']) && $properties['responseType'] == 'redirect') {
         $opts['action'] = $this->router->generate('opifer_mailing_list_subscribe_block', ['id' => $block->getId()]);
     }
     $this->form = $this->formFactory->create(SubscribeType::class, $this->subscription, $opts);
     $this->form->handleRequest($this->request);
     if ($this->form->isValid()) {
         foreach ($this->getMailingLists($block) as $list) {
             $subscription = $this->subscriptionManager->findOrCreate($list, $this->subscription->getEmail());
             $this->subscriptionManager->save($subscription);
         }
         $this->subscribed = true;
     }
 }
Ejemplo n.º 7
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);
     }
 }