Exemplo n.º 1
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $layout = new Layout();
     $layout->setName('page')->setDescription('Page Layout')->setFilename('OpiferCmsBundle:Layout:page.html.twig');
     $manager->persist($layout);
     $this->addReference('page-layout', $layout);
     $manager->flush();
 }
Exemplo n.º 2
0
 /**
  * Perform search action with pagination.
  *
  * @param Layout  $layout
  * @param Content $content
  *
  * @return Response
  */
 public function indexAction(Layout $layout, Content $content)
 {
     $request = $this->get('request_stack')->getMasterRequest();
     $term = $request->get('term');
     $contentRepository = $this->getDoctrine()->getRepository('OpiferCmsBundle:Content');
     $results = $contentRepository->searchNested($term);
     $contentResults = [];
     $valueSetIds = [];
     foreach ($results as $k => $result) {
         if ($result->getNestedIn()) {
             $id = $result->getNestedIn()->getValueset()->getId();
             $valueSetIds[] = $id;
         } else {
             $contentResults[$result->getId()] = $result;
         }
     }
     $content_data = $contentRepository->findBy(['valueSet' => $valueSetIds]);
     foreach ($content_data as $result) {
         if ($result->getSearchable()) {
             $contentResults[$result->getId()] = $result;
         }
     }
     $results = $contentResults;
     $adapter = new ArrayAdapter($results);
     $page = (int) $request->query->get('page', 1);
     $pagerfanta = new Pagerfanta($adapter);
     $pagerfanta->setMaxPerPage(25);
     $pagerfanta->setCurrentPage($page);
     $view = new TwitterBootstrap3View();
     $options = ['prev_message' => $this->get('translator')->trans('pagination.prev'), 'next_message' => $this->get('translator')->trans('pagination.next')];
     $routeGenerator = function ($page) use($term) {
         return '?term=' . $term . '&page=' . $page;
     };
     $pagination = $view->render($pagerfanta, $routeGenerator, $options);
     return $this->render($layout->getFilename(), ['results' => $results, 'term' => $term, 'content' => $content, 'pagination' => $pagination, 'pagerfanta' => $pagerfanta]);
 }
Exemplo n.º 3
0
 /**
  * Helper for adding templates
  *
  * @param string $name
  * @param array  $values
  * @param Layout $layoutEntity
  *
  * @return Template
  */
 protected function addTemplate($name, $values, $layoutEntity = false)
 {
     $serializer = $this->container->get('jms_serializer');
     $templateEntity = $this->getEntityByName(new Template(), $name);
     $templateEntity->setName($name);
     foreach ($values as $key => $value) {
         $update = 'set' . ucfirst($key);
         $templateEntity->{$update}($value);
     }
     if ($layoutEntity !== false) {
         if (!$layoutEntity->getId()) {
             $this->entityManager->flush();
         }
         $templateEntity->setPresentation($serializer->serialize($layoutEntity, 'json'));
     }
     $this->entityManager->persist($templateEntity);
     return $templateEntity;
 }