Ejemplo n.º 1
0
 /**
  * @param ResourceEvent $resourceEvent
  */
 public function onSave(ResourceEvent $resourceEvent)
 {
     //        var_dump($resourceEvent);
     //        $module = $resourceEvent->getContainer()->getModule();
     $entities = $this->moduleRepository->setClass(new ResourceRepository())->findByAllResources();
     $entitiesToRemove = $this->objectManager->getRepository("BigfishCoreBundle:CacheRouting")->findAll();
     $flush = false;
     foreach ($entitiesToRemove as $remove) {
         $this->objectManager->remove($remove);
         $flush = true;
     }
     if ($flush) {
         $this->objectManager->flush();
     }
     $flush = false;
     foreach ($entities as $entity) {
         if (isset($entity["resource_id"])) {
             //
             $resource = $this->objectManager->getRepository("BigfishCoreBundle:Resource")->find($entity["resource_id"]);
             if ($resource) {
                 $routeData = $this->getParentsEntities($entities, $entity["resource_id"]);
                 $route = new CacheRouting();
                 $route->setResource($resource);
                 $route->setLanguage($this->languageManager->getObject());
                 $path = $this->validateSlug($entity["routerPath"], $routeData);
                 $route->setPath($path);
                 $this->objectManager->persist($route);
                 $flush = true;
             }
         }
     }
     if ($flush) {
         $this->objectManager->flush();
     }
 }
Ejemplo n.º 2
0
 public function onUpdate(EavPersisterEvent $event)
 {
     $optionalData = $event->getOptionalData();
     $moduleId = $event->getModule()->getId();
     $tableName = '_flat_module_' . $moduleId;
     $container = $event->getContainer();
     $module = $event->getModule();
     if ($module->getGenerateFlat()) {
         $tableExists = $this->pdo->query('SELECT * FROM information_schema.tables WHERE table_name = "' . $tableName . '" LIMIT 1')->rowCount();
         if (!$tableExists) {
             $this->flatternTable->generate($module, true);
         }
         $context = $event->getContainer()->getContext();
         $containerId = $event->getContainer()->getId();
         $contextId = $event->getContainer()->getContext()->getId();
         $culture = $this->languageManager->getCulture();
         /** @var $moduleRepository EavModuleRepository * */
         $moduleRepository = $this->moduleRepository->getRepository($event->getModule())->setClass(new EavModuleRepository());
         $containerSQL = $moduleRepository->findByForFlatById($container, $module, $context)->getSQL();
         $containerRow = $moduleRepository->findByForFlatById($container, $module, $context)->getQuery()->getResult();
         $countColumnsSQL = $this->pdo->query('SHOW COLUMNS FROM ' . $tableName);
         $countColumnsSQL->execute();
         $columnsRes = $countColumnsSQL->fetchAll();
         $diffColumn = array();
         foreach ($columnsRes as $t) {
             $diffColumn[] = $t['Field'];
         }
         $columns = array_keys($containerRow[0]);
         if (count(array_diff($columns, $diffColumn)) > 0 || count(array_diff($diffColumn, $columns))) {
             $this->flatternTable->generate($module, true);
         }
         $sql = 'DELETE FROM ' . $tableName . '
         WHERE container_id = :container_id
         AND context_id = :context_id
         AND module_id = :module_id';
         $pdo = $this->pdo->prepare($sql);
         $pdo->bindParam('container_id', $containerId);
         $pdo->bindParam('context_id', $contextId);
         $pdo->bindParam('module_id', $moduleId);
         $pdo->execute();
         $sql = 'INSERT INTO ' . $tableName . ' ';
         $sql .= ' (' . implode(', ', $columns) . ' )';
         $sql .= $containerSQL;
         $pdo = $this->pdo->prepare($sql);
         $pdo->bindParam(':container_id', $containerId);
         $pdo->bindParam(':context_id', $contextId);
         $pdo->bindParam(':module_id', $moduleId);
         $pdo->execute();
     }
 }
Ejemplo n.º 3
0
 public function buildEavQuery(\Bigfish\Bundle\EavBundle\Entity\Module $module, $skipFlat = false)
 {
     if ($module && $module->getFlatIsGenerated() && $module->getGenerateFlat() && !$skipFlat) {
         return '_flat_module_' . $module->getId();
     }
     $unions = array();
     $languages = $this->languageManager->getLanguages();
     foreach ($languages as $lang) {
         $qb = $this->createQueryBuilder();
         $qb->addSelect('_container.*');
         $qb->addSelect('"' . $lang . '" as culture');
         $qb->addSelect($this->getInvokeColumns()->setModule($module)->setLanguage($lang)->getSql());
         $qb->from('eav_container', EavTables::CONTAINER_PREFIX);
         if ($module) {
             $qb->where($qb->expr()->eq(EavTables::CONTAINER_PREFIX . '.module_id', ':module_id'));
         }
         $unions[] = $qb->getSQL();
     }
     if (count($unions) > 0) {
         $sql = implode(' UNION ', $unions);
         return '( ' . $sql . ' ) ';
     } else {
         return;
     }
 }
Ejemplo n.º 4
0
 /**
  * @param Request $request
  * @param ResourceHasInstance $resourceHasInstance
  * @param Resource $resource
  * @return RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function duplicateAction(Request $request, ResourceHasInstance $resourceHasInstance, Resource $resource)
 {
     $culture = $this->languageManager->getCulture();
     /** @var \Bigfish\Bundle\EavBundle\Entity\Module $module */
     $module = $resourceHasInstance->getInstance()->getComponent()->getModule();
     // Add a custom form type for the component itself.
     $formBuilder = $this->createFormBuilder()->add('instance', new InstanceType($resourceHasInstance));
     /** @var \Bigfish\Bundle\EavBundle\Form\FormBuilder $form */
     $form = $this->get('eav.form.builder')->createFormBuilder($module, array('container' => $resourceHasInstance->getInstance()->getContainer()), array(), $formBuilder)->getForm();
     if ($this->formHandler->handleDuplicate($form, $request, $resourceHasInstance, $resource)) {
         return new JsonResponse(array("success" => true));
     }
     return $this->render('BigfishPagekitBundle:Component:edit.html.twig', array('form' => $form->createView(), 'actionUrl' => $this->generateUrl('pagekit_component_duplicate', array('resourceHasInstance' => $resourceHasInstance->getId(), 'resource' => $resource->getId(), 'bflanguage' => $culture))));
 }
Ejemplo n.º 5
0
 public function getLanguages()
 {
     return $this->languageManager->getLanguages();
 }
Ejemplo n.º 6
0
 /**
  * @param $locale
  *
  * @return $this
  */
 public function setLanguage($locale)
 {
     $this->language = $this->languageManager->getObject($locale);
     return $this;
 }