/** * Deletes a entity. * * @param string $type ['widget', 'page'] * * @return Response * @access public * @author Etienne de Longeaux <*****@*****.**> */ public function deletetwigcacheajaxAction($type) { $request = $this->container->get('request'); $em = $this->getDoctrine()->getManager(); if ($request->isXmlHttpRequest()) { $data = $request->get('data', null); $new_data = null; foreach ($data as $key => $value) { $values = explode('_', $value); $id = $values[2]; $position = $values[0]; $new_data[$key] = array('position' => $position, 'id' => $id); $new_pos[$key] = $position; } array_multisort($new_pos, SORT_ASC, $new_data); // get all locales $all_locales = $this->container->get('sfynx.auth.locale_manager')->getAllLocales(); // foreach ($new_data as $key => $value) { if ($type == "widget") { $entity = $em->getRepository("SfynxCmfBundle:Widget")->find($value['id']); } elseif ($type == "page") { $entity = $value['id']; } else { throw ControllerException::callAjaxOnlySupported('deleteajax'); } foreach ($all_locales as $lang_page) { if ($type == "widget") { $this->container->get('pi_app_admin.manager.page')->cacheRefreshWidget($entity, $lang_page); } elseif ($type == "page") { $this->container->get('pi_app_admin.manager.page')->cacheRefreshPage($entity, $lang_page); } } } // we disable all flash message $this->container->get('session')->getFlashBag()->clear(); // we encode results $tab = array(); $tab['id'] = '-1'; $tab['error'] = ''; $tab['fieldErrors'] = ''; $tab['data'] = ''; $response = new Response(json_encode($tab)); $response->headers->set('Content-Type', 'application/json'); return $response; } else { throw ControllerException::callAjaxOnlySupported('deleteajax'); } }
/** * Template : Finds and displays a MediasDiaporama entity. * * @Cache(maxage="86400") * @return \Symfony\Component\HttpFoundation\Response * * @access public * @author Etienne de Longeaux <*****@*****.**> */ public function _template_showAction($id, $template = '_tmp_show.html.twig', $lang = "") { $em = $this->getDoctrine()->getManager(); if (empty($lang)) { $lang = $this->container->get('request')->getLocale(); } $entity = $em->getRepository("PluginsContentBundle:MediasDiaporama")->findOneByEntity($lang, $id, 'object', false); if (!$entity) { throw ControllerException::NotFoundException('MediasDiaporama'); } if (method_exists($entity, "getTemplate") && $entity->getTemplate() != "") { $template = $entity->getTemplate(); } return $this->render("PluginsContentBundle:MediasDiaporama:{$template}", array('entity' => $entity, 'locale' => $lang)); }
/** * Deletes a Layout entity. * * @Secure(roles="ROLE_SUPER_ADMIN") * @return \Symfony\Component\HttpFoundation\RedirectResponse * * @access public * @author Etienne de Longeaux <*****@*****.**> */ public function deleteAction($id) { $form = $this->createDeleteForm($id); $request = $this->getRequest(); $form->bind($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository('SfynxAuthBundle:Layout')->find($id); if (!$entity) { throw ControllerException::NotFoundEntity('Layout'); } $em->remove($entity); $em->flush(); } return $this->redirect($this->generateUrl('admin_layout')); }
/** * Admin Ajax action management of all blocks and widgets of a page * * @Secure(roles="ROLE_EDITOR") * @return Response * @author Etienne de Longeaux <*****@*****.**> * @since 2012-05-04 */ public function urlmanagementAction() { $request = $this->container->get('request'); if ($request->isXmlHttpRequest()) { $urls = null; // if ($request->query->has('id')) { $id = $request->query->get('id'); } else { $id = null; } if ($request->query->has('type')) { $type = $request->query->get('type'); } else { $type = null; } if ($request->query->has('routename')) { $routename = $request->query->get('routename'); } else { $routename = ""; } if ($request->query->has('action')) { $action = $request->query->get('action'); } else { $action = "no"; } // we get the page manager $pageManager = $this->get('pi_app_admin.manager.page'); // if ($type == 'routename') { // we return the url result of the routename $urls[$action] = $this->get('sfynx.tool.route.factory')->getRoute($routename); } elseif ($type == 'page') { // we get the object Translation Page by route $page = $pageManager->setPageByRoute($routename); if ($page instanceof Page) { $urls = $pageManager->getUrlByType('page', $page); } else { $urls = $pageManager->getUrlByType('page'); } // we get all the urls in order to the management of widgets.l $urls = $pageManager->getUrlByType('page', $page); } elseif ($type == 'block') { // we get the object block by id $block = $pageManager->getBlockById($id); // we get all the urls in order to the management of a block. $urls = $pageManager->getUrlByType('block', $block); } elseif ($type == 'widget') { // we get the object widget by id $widget = $pageManager->getWidgetById($id); // we get all the urls in order to the management of a widget. $urls = $pageManager->getUrlByType('widget', $widget); } // we return the desired url $values[0]['url'] = $urls[$action]; $response = new Response(json_encode($values)); $response->headers->set('Content-Type', 'application/json'); return $response; } else { throw ControllerException::callAjaxOnlySupported('urlmanagement'); } }
/** * Deletes a Word entity. * * @Secure(roles="ROLE_EDITOR") * @return \Symfony\Component\HttpFoundation\RedirectResponse * @access public * @author Riad HELLAL <*****@*****.**> */ public function deleteAction($id) { $em = $this->getDoctrine()->getManager(); $locale = $this->container->get('request')->getLocale(); $NoLayout = $this->container->get('request')->query->get('NoLayout'); // $form = $this->createDeleteForm($id); $request = $this->getRequest(); $form->bind($request); if ($form->isValid()) { $entity = $em->getRepository("SfynxTranslatorBundle:Word")->findOneByEntity($locale, $id, 'object'); if (!$entity) { throw ControllerException::NotFoundEntity('Word'); } $em->remove($entity); $em->flush(); } return $this->redirect($this->generateUrl('admin_word', array('NoLayout' => $NoLayout))); }
/** * Deletes a BlocGeneral entity. * * @Secure(roles="ROLE_USER") * @return \Symfony\Component\HttpFoundation\RedirectResponse * * @access public * @author Etienne de Longeaux <*****@*****.**> */ public function deleteAction($id) { $em = $this->getDoctrine()->getManager(); $locale = $this->container->get('request')->getLocale(); $NoLayout = $this->container->get('request')->query->get('NoLayout'); $category = $this->container->get('request')->query->get('category'); $form = $this->createDeleteForm($id); $request = $this->getRequest(); $form->bind($request); if ($form->isValid()) { $entity = $em->getRepository("PluginsContentBundle:BlocGeneral")->findOneByEntity($locale, $id, 'object'); if (!$entity) { throw ControllerException::NotFoundException('BlocGeneral'); } try { $em->remove($entity); $em->flush(); } catch (\Exception $e) { $this->container->get('request')->getSession()->getFlashBag()->add('notice', 'pi.session.flash.wrong.undelete'); } } return $this->redirect($this->generateUrl('admin_content_bloc_general', array('NoLayout' => $NoLayout, 'category' => $category))); }
/** * Removes given $node from the tree and reparents its descendants * * @Secure(roles="ROLE_USER") * @param int $id * @param string $category * @access public * * @author Etienne de Longeaux <*****@*****.**> */ public function removeAction($id, $category) { $em = $this->getDoctrine()->getManager(); $locale = $this->container->get('request')->getLocale(); $node = $em->getRepository("PluginsContentBundle:Rub")->findNodeOr404($id, $locale); $NoLayout = $this->container->get('request')->query->get('NoLayout'); //$em->getRepository("PluginsContentBundle:Rub")->removeFromTree($node); if (!$node) { throw ControllerException::NotFoundException('Rub'); } try { if (method_exists($node, 'setArchived')) { $node->setArchived(true); } if (method_exists($node, 'setEnabled')) { $node->setEnabled(false); } if (method_exists($node, 'setArchiveAt')) { $node->setArchiveAt(new \DateTime()); } if (method_exists($node, 'setPosition')) { $node->setPosition(null); } $em->persist($node); $em->flush(); $this->container->get('request')->getSession()->getFlashBag()->add('notice', 'Rubrique supprimée avec succès'); } catch (\Exception $e) { $this->container->get('request')->getSession()->getFlashBag()->add('notice', 'pi.session.flash.wrong.undelete'); } return $this->redirect($this->generateUrl('admin_content_rub_tree', array('category' => $category, 'NoLayout' => $NoLayout))); }
/** * Create Ajax query * * @param string $type ["select","count"] * @param string $table * @param string $aColumns * @param string $table * @param array $dateSearch * @param array $cacheQuery_hash * * @return array * @access protected * @author Etienne de Longeaux <*****@*****.**> */ public function createAjaxQuery($type, $aColumns, $qb = null, $tablecode = 'u', $table = null, $dateSearch = null, $cacheQuery_hash = null) { $request = $this->container->get('request'); $locale = $this->container->get('request')->getLocale(); $em = $this->getDoctrine()->getManager(); if (is_null($qb)) { $qb = $em->createQueryBuilder(); if ($type == 'select') { $qb->add('select', $tablecode); } elseif ($type == "count") { $qb->add('select', $tablecode . '.id'); } else { throw ControllerException::NotFoundOption('type'); } if (isset($this->_entityName) && !empty($this->_entityName)) { $qb->add('from', $this->_entityName . ' ' . $tablecode); } elseif (!is_null($table)) { $qb->add('from', $table . ' ' . $tablecode); } else { throw ControllerException::NotFoundOption('table'); } } elseif ($type == "count") { $qb->add('select', $tablecode . '.id'); } /** * Date */ if (!is_null($dateSearch) && is_array($dateSearch)) { foreach ($dateSearch as $k => $columnSearch) { $idMin = "date-{$columnSearch['idMin']}"; $idMax = "date-{$columnSearch['idMax']}"; if ($request->get($idMin) != '') { $date = \DateTime::createFromFormat($columnSearch['format'], $request->get($idMin)); $dateMin = $date->format('Y-m-d 00:00:00'); //$dateMin = $this->container->get('sfynx.tool.date_manager')->format($date->getTimestamp(), 'long','medium', $locale, "yyyy-MM-dd 00:00:00"); $qb->andWhere("{$columnSearch['column']} >= '" . $dateMin . "'"); } if ($request->get($idMax) != '') { $date = \DateTime::createFromFormat($columnSearch['format'], $request->get($idMax)); $dateMax = $date->format('Y-m-d 23:59:59'); $qb->andWhere("{$columnSearch['column']} <= '" . $dateMax . "'"); } } } /** * Filtering * NOTE this does not match the built-in DataTables filtering which does it * word by word on any field. It's possible to do here, but concerned about efficiency * on very large tables, and MySQL's regex functionality is very limited */ $array_params = array(); $and = $qb->expr()->andx(); for ($i = 0; $i < count($aColumns); $i++) { if ($request->get('bSearchable_' . $i) == "true" && $request->get('sSearch_' . $i) != '') { $search_tab = explode("|", $request->get('sSearch_' . $i)); $or = $qb->expr()->orx(); foreach ($search_tab as $s) { $or->add("LOWER(" . $aColumns[intval($i) - 1] . ") LIKE :var" . $i . ""); // $current_encoding = mb_detect_encoding($s, 'auto'); $s = iconv($current_encoding, 'UTF-8', $s); $s = PiStringManager::withoutaccent($s); // $array_params["var" . $i] = '%' . strtolower($s) . '%'; } $and->add($or); } } if ($and != "") { $qb->andWhere($and); } $or = $qb->expr()->orx(); for ($i = 0; $i < count($aColumns); $i++) { if ($request->get('bSearchable_' . $i) == "true" && $request->get('sSearch') != '') { $search_tab = explode("|", $request->get('sSearch')); foreach ($search_tab as $s) { if (!empty($s)) { $or->add("LOWER(" . $aColumns[$i] . ") LIKE :var2" . $i . ""); // $current_encoding = mb_detect_encoding($s, 'auto'); $s = iconv($current_encoding, 'UTF-8', $s); $s = PiStringManager::withoutaccent($s); // $array_params["var2" . $i] = '%' . strtolower($s) . '%'; } } } } if ($or != "") { $qb->andWhere($or); } /** * Grouping */ $qb->groupBy($tablecode . '.id'); /** * Ordering */ $iSortingCols = $request->get('iSortingCols', ''); if (!empty($iSortingCols)) { for ($i = 0; $i < intval($request->get('iSortingCols')); $i++) { $iSortCol_ = $request->get('iSortCol_' . $i, ''); $iSortCol_col = intval($iSortCol_) - 1; if (!empty($iSortCol_) && $request->get('bSortable_' . intval($iSortCol_)) == "true" && isset($aColumns[$iSortCol_col])) { $column = $aColumns[$iSortCol_col]; $sort = $request->get('sSortDir_' . $i) === 'asc' ? 'ASC' : 'DESC'; $qb->addOrderBy($column, $sort); } } } /** * Paging */ if ($type == 'select') { $iDisplayStart = $request->get('iDisplayStart', 0); $iDisplayLength = $request->get('iDisplayLength', 25); $qb->setFirstResult($iDisplayStart); $qb->setMaxResults($iDisplayLength); } $qb->setParameters($array_params); //$query_sql = $qb->getQuery()->getSql(); //var_dump($query_sql); //exit; if (is_null($cacheQuery_hash)) { $qb = $qb->getQuery(); } elseif (is_array($cacheQuery_hash)) { // we define all options if (!isset($cacheQuery_hash['time'])) { $cacheQuery_hash['time'] = 3600; } if (!isset($cacheQuery_hash['mode'])) { $cacheQuery_hash['mode'] = 3; } // \Doctrine\ORM\Cache::MODE_NORMAL; if (!isset($cacheQuery_hash['setCacheable'])) { $cacheQuery_hash['setCacheable'] = true; } if (!isset($cacheQuery_hash['input_hash'])) { $cacheQuery_hash['input_hash'] = ''; } if (!isset($cacheQuery_hash['namespace'])) { $cacheQuery_hash['namespace'] = ''; } // we set the query result $qb = $em->getRepository($this->_entityName)->cacheQuery($qb->getQuery(), $cacheQuery_hash['time'], $cacheQuery_hash['mode'], $cacheQuery_hash['setCacheable'], $cacheQuery_hash['namespace'], $cacheQuery_hash['input_hash']); } $result = $em->getRepository($this->_entityName)->setTranslatableHints($qb, $locale, false, true)->getResult(); if ($type == 'count') { $result = count($result); } return $result; }
/** * Deletes a Langue entity. * * @Secure(roles="ROLE_ADMIN") * @return \Symfony\Component\HttpFoundation\RedirectResponse * * @access public * @author Etienne de Longeaux <*****@*****.**> */ public function deleteAction($id) { $form = $this->createDeleteForm($id); $request = $this->getRequest(); $form->bind($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository('SfynxAuthBundle:Langue')->find($id); if (!$entity) { throw ControllerException::NotFoundEntity('Langue'); } try { $em->remove($entity); $em->flush(); } catch (\Exception $e) { $this->container->get('request')->getSession()->getFlashBag()->clear(); $this->container->get('request')->getSession()->getFlashBag()->add('notice', 'pi.session.flash.wrong.undelete'); } } return $this->redirect($this->generateUrl('admin_langue')); }
/** * Deletes a Block entity. * * @Secure(roles="ROLE_SUPER_ADMIN") * @return \Symfony\Component\HttpFoundation\RedirectResponse * * @access public * @author Etienne de Longeaux <*****@*****.**> */ public function deleteAction($id) { $NoLayout = $this->container->get('request')->query->get('NoLayout'); $form = $this->createDeleteForm($id); $request = $this->getRequest(); $form->bind($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository('SfynxCmfBundle:Block')->find($id); $id_page = $entity->getPage()->getId(); if (!$entity) { throw ControllerException::NotFoundEntity('Block'); } try { $em->remove($entity); $em->flush(); } catch (\Exception $e) { $this->container->get('request')->getSession()->getFlashBag()->clear(); $this->container->get('request')->getSession()->getFlashBag()->add('notice', 'pi.session.flash.wrong.undelete'); } } return $this->redirect($this->generateUrl('admin_pagebyblock_show', array('id' => $id_page, 'NoLayout' => $NoLayout))); }
/** * Deletes a Organigram entity. * * @Secure(roles="ROLE_EDITOR") * @access public * @author Etienne de Longeaux <*****@*****.**> */ public function deleteAction($id) { $em = $this->getDoctrine()->getManager(); $locale = $this->container->get('request')->getLocale(); $NoLayout = $this->container->get('request')->query->get('NoLayout'); $form = $this->createDeleteForm($id); $request = $this->getRequest(); $form->bind($request); if ($form->isValid()) { $entity = $em->getRepository("PiAppGedmoBundle:Organigram")->findNodeOr404($id, $locale, 'object'); if (!$entity) { throw ControllerException::NotFoundEntity('Organigram'); } try { $em->remove($entity); $em->flush(); } catch (\Exception $e) { $this->container->get('request')->getSession()->getFlashBag()->clear(); $this->container->get('request')->getSession()->getFlashBag()->add('notice', 'pi.session.flash.wrong.undelete'); } } return $this->redirect($this->generateUrl('admin_gedmo_organigram', array('NoLayout' => $NoLayout))); }
/** * Template : Finds and displays a Content entity. * * @Template() * @Cache(maxage="86400") * * @access public * @author Etienne de Longeaux <*****@*****.**> */ public function _template_showAction($id, $template = '_tmp_show.html.twig', $lang = "") { $em = $this->getDoctrine()->getManager(); if (empty($lang)) { $lang = $this->container->get('request')->getLocale(); } $entity = $em->getRepository("PiAppGedmoBundle:Content")->findOneByEntity($lang, $id, 'object', false); if (!$entity) { throw ControllerException::NotFoundEntity('Content'); } return $this->render("PiAppGedmoBundle:Content:{$template}", array('entity' => $entity, 'locale' => $lang, 'lang' => $lang)); }
/** * Finds and displays a Page entity. * * @param integer $id Id value * * @Secure(roles="ROLE_EDITOR") * @return Response * @access public * @author Etienne de Longeaux <*****@*****.**> */ public function showAction($id) { $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository('SfynxCmfBundle:Page')->find($id); $NoLayout = $this->container->get('request')->query->get('NoLayout'); if (!$entity) { throw ControllerException::NotFoundEntity('Page'); } $deleteForm = $this->createDeleteForm($id); return $this->render("SfynxCmfBundle:PageByTrans:show.html.twig", array('entity' => $entity, 'delete_form' => $deleteForm->createView(), 'NoLayout' => $NoLayout)); }
/** * Deletes a Diaporama entity. * * @Secure(roles="ROLE_USER") * @return \Symfony\Component\HttpFoundation\RedirectResponse * * @access public * @author Etienne de Longeaux <*****@*****.**> */ public function deleteAction($id) { $em = $this->getDoctrine()->getManager(); $locale = $this->container->get('request')->getLocale(); $NoLayout = $this->container->get('request')->query->get('NoLayout'); $category = $this->container->get('request')->query->get('category'); $form = $this->createDeleteForm($id); $request = $this->getRequest(); $form->bind($request); if ($form->isValid()) { $entity = $em->getRepository("PluginsContentBundle:Diaporama")->findOneByEntity($locale, $id, 'object'); if (!$entity) { throw ControllerException::NotFoundException('Diaporama'); } try { if (method_exists($entity, 'setArchived')) { $entity->setArchived(true); } if (method_exists($entity, 'setEnabled')) { $entity->setEnabled(false); } if (method_exists($entity, 'setArchiveAt')) { $entity->setArchiveAt(new \DateTime()); } if (method_exists($entity, 'setPosition')) { $entity->setPosition(null); } $entity->getBlocgeneral()->setArchived(true); $entity->getBlocgeneral()->setEnabled(false); $entity->getBlocgeneral()->setArchiveAt(new \DateTime()); $em->persist($entity); $em->flush(); } catch (\Exception $e) { $this->container->get('request')->getSession()->getFlashBag()->add('notice', 'pi.session.flash.wrong.undelete'); } } return $this->redirect($this->generateUrl('admin_content_bloc_general', array('NoLayout' => $NoLayout, 'category' => $category, 'type' => 'diaporama'))); }
/** * Move up/down widget action * * @Secure(roles="ROLE_EDITOR") * @return \Symfony\Component\HttpFoundation\Response * * @author Etienne de Longeaux <*****@*****.**> * @since 2012-07-05 */ public function moveajaxAction() { $request = $this->container->get('request'); $em = $this->getDoctrine()->getManager(); if ($request->isXmlHttpRequest()) { if ($request->query->has('id')) { $id = $request->query->get('id'); } else { $id = null; } if ($request->query->has('type')) { $type = $request->query->get('type'); } else { $type = null; } if (!is_null($id) && !is_null($type) && in_array($type, array('up', 'down'))) { $entity_widget = $em->getRepository('SfynxCmfBundle:Widget')->find($id); $entity_block = $entity_widget->getBlock(); $entity_widget_pos = $entity_widget->getPosition(); $break = false; if (is_null($entity_widget_pos)) { $entity_widget_pos = 1; $entity_widget->setPosition($entity_widget_pos); $em->persist($entity_widget); $em->flush(); } if ($type == 'up') { $all_widget_block = $em->getRepository('SfynxCmfBundle:Widget')->getAllWidgetsByBlock($entity_block->getId(), "DESC")->getResult(); //$entity_block->getWidgets(); foreach ($all_widget_block as $key => $widget) { $widg_pos = $widget->getPosition(); if (!$break && $widg_pos < $entity_widget_pos) { $widget->setPosition($entity_widget_pos); $em->persist($widget); $entity_widget->setPosition($widg_pos); $em->persist($entity_widget); $em->flush(); $break = true; } } } elseif ($type == 'down') { $all_widget_block = $em->getRepository('SfynxCmfBundle:Widget')->getAllWidgetsByBlock($entity_block->getId(), "ASC")->getResult(); //$entity_block->getWidgets(); foreach ($all_widget_block as $key => $widget) { $widg_pos = $widget->getPosition(); if (!$break && $widg_pos > $entity_widget_pos) { $widget->setPosition($entity_widget_pos); $em->persist($widget); $entity_widget->setPosition($widg_pos); $em->persist($entity_widget); $em->flush(); $break = true; } } } } // we return the desired url $values[0]['request'] = true; $response = new Response(json_encode($values)); $response->headers->set('Content-Type', 'application/json'); return $response; } else { throw ControllerException::callAjaxOnlySupported('moveajax'); } }