Example #1
0
 public function SectionsMenu($options)
 {
     /*
      * Настроки кеширования
      */
     $env = $this->container->getParameter("kernel.environment");
     $cacheDriver = new \Doctrine\Common\Cache\ApcuCache();
     $namespace = 'menu_section_' . $env . '_' . $options['BLOCK_ID'];
     $cacheDriver->setNamespace($namespace);
     // засекаем время
     $time_start = microtime(1);
     /*
      * Добавляем текущую страницу в id кеша
      */
     $request = $this->container->get('request_stack')->getMasterRequest();
     $routeParams = $request->attributes->get('_route_params');
     $currentCode = false;
     if (array_key_exists('SECTION_CODE', $routeParams)) {
         $currentCode = trim($routeParams['SECTION_CODE'], '/');
     }
     //$currentCode = trim($routeParams['CODE'], '/');
     $options['@currentCode'] = $currentCode;
     // id кеша
     $cacheId = json_encode($options);
     if ($fooString = $cacheDriver->fetch($cacheId)) {
         //if (false) {
         /*
          * Выдаем результат из кеша
          */
         $result = unserialize($fooString);
     } else {
         /*
          * Генерируем результат
          */
         $SectionClass = $this->container->get('SectionClass');
         $tree = $SectionClass->SectionsList(array('block_id' => $options['BLOCK_ID']));
         //echo '<pre>' . print_r('tree on SectionMenu', true) . '</pre>';
         //echo '<pre>' . print_r($tree, true) . '</pre>';
         $factory = new MenuFactory();
         $menu = $factory->createItem('root');
         //echo '<pre>' . print_r($routeName, true) . '</pre>';
         //echo '<pre>' . print_r($routeParams, true) . '</pre>';
         $this->generateMenuFromTree($tree, $menu, $options['route'], $currentCode);
         $menuRenderer = $this->getMenuRenderer();
         $result = $menuRenderer->render($menu, array('template' => $options['template'], 'currentAsLink' => false));
         /*
          * Сохраняем результат в кеш
          */
         $cacheDriver->save($cacheId, serialize($result));
     }
     echo $result;
     $time_end = microtime(1);
     $time = number_format(($time_end - $time_start) * 1000, 2);
     //echo $time.' мс';
 }
Example #2
0
 public function sections_listAction($block_id = false, $section_id = null, $template_code = "default", $get_elements = null, $params)
 {
     //$cache = new \Doctrine\Common\Cache\FilesystemCache($_SERVER['DOCUMENT_ROOT'] . '/../app/cache/sys/components/sections_list/');
     $cache = new \Doctrine\Common\Cache\ApcuCache();
     $cacheId = md5(json_encode(array('block_id' => $block_id, 'section_id' => $section_id, 'template_code' => $template_code, 'get_elements' => $get_elements)));
     //echo '<pre>' . print_r($cache->fetch($cacheId), true) . '</pre>';
     if ($fooString = $cache->fetch($cacheId)) {
         //echo '<pre>' . print_r('возвращаем закешированные данные', true) . '</pre>';
         $render = unserialize($fooString);
     } else {
         //echo '<pre>' . print_r('возвращаем не закешированные данные', true) . '</pre>';
         $em = $this->getDoctrine()->getManager();
         //echo '<pre>' . print_r($block_id, true) . '</pre>';
         if (is_numeric($block_id)) {
             //$sections = $em->getRepository('NovuscomCMFBundle:Section')->findBy(array('block' => $block_id, 'lvl' => 0));
             //echo '<pre>' . print_r($block_id, true) . '</pre>';
             $repository = $em->getRepository('NovuscomCMFBundle:Section');
             $query = $repository->createQueryBuilder('p')->where('p.block = :block_id')->setParameters(array('block_id' => $block_id))->orderBy('p.sort', 'ASC')->getQuery();
             $sections = $query->getResult();
             /*foreach($sections as $s) {
             			echo '<pre>' . print_r($s->getName(), true) . '</pre>';
             		}*/
         } else {
             //echo '<pre>' . print_r('notfound', true) . '</pre>';
             throw $this->createNotFoundException('');
         }
         if (is_int($section_id)) {
             $repository = $em->getRepository('NovuscomCMFBundle:Section');
             $query = $repository->createQueryBuilder('p')->where('p.id = :section_id')->setParameter('section_id', $section_id)->orderBy('p.sort', 'ASC')->getQuery();
             $sections = $query->getResult();
         }
         $this->setSectionsElements($sections);
         $response = new Response();
         $data = array();
         $data['sections'] = $sections;
         //echo '<pre>' . print_r($template_code, true) . '</pre>';
         $render = $this->render('@templates/' . $params['params']['template_directory'] . '/SectionsList/' . $template_code . '.html.twig', $data, $response);
     }
     return $render;
 }
Example #3
0
 public function elementAction($id, Request $request, $template_code = 'default')
 {
     $host = $request->headers->get('host');
     $cacheId = 'id=[' . $id . ']';
     $env = $this->get('kernel')->getEnvironment();
     //$cache = new \Doctrine\Common\Cache\FilesystemCache($_SERVER['DOCUMENT_ROOT'] . '/../app/cache/'.$env.'/sys/'.$host.'/element/');
     $cache = new \Doctrine\Common\Cache\ApcuCache();
     if ($fooString = $cache->fetch($cacheId)) {
         //echo '<pre>' . print_r('есть кэш '.$cacheId, true) . '</pre>';
         $response = unserialize($fooString);
     } else {
         $element = new FrontElement();
         $em = $this->getDoctrine()->getManager();
         $entity = $em->getRepository('NovuscomCMFBundle:Element')->find($id);
         $element->setInfo($entity);
         $propertyFiles = $em->getRepository('NovuscomCMFBundle:ElementPropertyF')->findBy(array('element' => $entity, 'property_id' => 26));
         foreach ($propertyFiles as $pf) {
             //echo '<pre>' . print_r($pf->getFile(), true) . '</pre>';
             $element->addPropertyFile($pf->getFile());
         }
         //echo '<pre>' . print_r($entity->getName(), true) . '</pre>';
         if ($entity) {
             $templatePath = 'CMFTemplateBundle:Element:' . $template_code . '.html.twig';
             $response = $this->render($templatePath, array('element' => $element));
         } else {
             $response = new Response('<div>Элемент не найден</div>');
         }
         $cache->save($cacheId, serialize($response));
     }
     return $response;
 }