Beispiel #1
0
 /**
  * @param Widget $widget
  * @param        $content
  */
 public function save(Widget $widget, $content)
 {
     $hash = $this->getHash($widget);
     if ($hash) {
         $this->redis->set($hash, $content);
         $this->redis->expire($hash, $this->widgetHelper->getCacheTimeout($widget));
         // cache for a week
     }
 }
Beispiel #2
0
 /**
  * render a widget.
  *
  * @param Widget $widget
  * @param View   $view
  *
  * @return string
  */
 public function renderContainer(Widget $widget, View $view)
 {
     $dispatcher = $this->container->get('event_dispatcher');
     $dispatcher->dispatch(VictoireCmsEvents::WIDGET_PRE_RENDER, new WidgetRenderEvent($widget));
     $widgetMap = WidgetMapHelper::getWidgetMapByWidgetAndView($widget, $view);
     $directive = '';
     if ($this->container->get('security.authorization_checker')->isGranted('ROLE_VICTOIRE')) {
         $directive = 'widget';
     }
     $id = 'vic-widget-' . $widget->getId() . '-container';
     $html = sprintf('<div %s widget-map="%s" id="%s" class="vic-widget-container" data-id="%s">', $directive, $widgetMap->getId(), $id, $widget->getId());
     if ($this->widgetHelper->isCacheEnabled($widget)) {
         $content = $this->widgetCache->fetch($widget);
         if (null === $content) {
             $content = $this->render($widget, $view);
             $this->widgetCache->save($widget, $content);
         } else {
             $this->victoireCollector->addCachedWidget($widget);
         }
     } else {
         $content = $this->render($widget, $view);
     }
     $html .= $content;
     $html .= '</div>';
     //close container
     $dispatcher->dispatch(VictoireCmsEvents::WIDGET_POST_RENDER, new WidgetRenderEvent($widget, $html));
     return $html;
 }