src/Notaris/AdminBundle/Entity/SectionRepository.php line 141

Open in your IDE?
  1. <?php
  2. namespace Notaris\AdminBundle\Entity;
  3. use Doctrine\ORM\EntityRepository;
  4. use Symfony\Component\Debug\Exception\UndefinedMethodException;
  5. /**
  6.  * SectionRepository
  7.  *
  8.  * This class was generated by the Doctrine ORM. Add your own custom
  9.  * repository methods below.
  10.  */
  11. class SectionRepository extends EntityRepository
  12. {
  13.     /**
  14.      * @param $subsite
  15.      * @return array
  16.      * @throws \Doctrine\DBAL\DBALException
  17.      */
  18.     public function getSections($subsite)
  19.     {
  20.         $em = $this->getEntityManager();
  21.         $sql = "SELECT s
  22.               FROM NotarisAdminBundle:Section s LEFT JOIN NotarisAdminBundle:Meta m WITH s.meta = m.id
  23.               WHERE s.parent is null AND s.subsite = :subsite
  24.               ORDER BY s.position ASC";
  25.         $query = $em->createQuery($sql);
  26.         $query = $query->setParameter('subsite', $subsite);
  27.         $result = $query->getResult();
  28.         return $result;
  29.     }
  30.     /**
  31.      * @param $parent_id
  32.      * @return array
  33.      * @throws \Doctrine\DBAL\DBALException
  34.      */
  35.     public function getChildren($parent_id)
  36.     {
  37.         $em = $this->getEntityManager();
  38.         $sql = "SELECT s
  39.               FROM NotarisAdminBundle:Section s LEFT JOIN NotarisAdminBundle:Meta m WITH s.meta = m.id
  40.               WHERE s.parent = :parent
  41.               ORDER BY s.position ASC";
  42.         $query = $em->createQuery($sql);
  43.         $query = $query->setParameter('parent', $parent_id);
  44.         $result = $query->getResult();
  45.         return $result;
  46.     }
  47.     /**
  48.      * @param $id
  49.      * @return array
  50.      * @throws \Doctrine\DBAL\DBALException
  51.      */
  52.     public function getSection($id)
  53.     {
  54.         $em = $this->getEntityManager();
  55.         $con = $em->getConnection();
  56.         $sql = "SELECT s
  57.               FROM NotarisAdminBundle:Section s LEFT JOIN NotarisAdminBundle:Meta m WITH s.meta = m.id
  58.               WHERE s.id = :parent
  59.               ORDER BY s.position ASC";
  60.         $query = $em->createQuery($sql);
  61.         $query = $query->setParameter('parent', $id);
  62.         $result = $query->getResult();
  63.         return $result;
  64.     }
  65.     /**
  66.      * @param $parent_id
  67.      * @return mixed
  68.      */
  69.     public function getNextParent($parent_id)
  70.     {
  71.         $em = $this->getEntityManager();
  72.         $con = $em->getConnection();
  73.         $sql = "SELECT s.parent_id FROM section s WHERE s.id = :parent LIMIT 1";
  74.         $stmt = $con->prepare($sql);
  75.         $stmt->bindValue('parent', $parent_id);
  76.         $stmt = $stmt->execute();
  77.         return $stmt->fetchOne();
  78.     }
  79.     /**
  80.      * @param $subsite
  81.      * @return mixed
  82.      */
  83.     public function getMaxPosition($subsite, $parent_id)
  84.     {
  85.         $em = $this->getEntityManager();
  86.         $con = $em->getConnection();
  87.         $where_parent = $parent_id ? 'AND parent_id =:parent_id' : '';
  88.         $sql = "SELECT MAX(section.position) as max
  89.                 FROM section
  90.                 INNER JOIN subsite s ON s.id = section.subsite_id
  91.                 WHERE s.slug = :slug " . $where_parent;
  92.         $stmt = $con->prepare($sql);
  93.         $stmt->bindValue('slug', $subsite);
  94.         if ($parent_id) {
  95.             $stmt->bindValue('parent_id', $parent_id);
  96.         }
  97.         $stmt = $stmt->execute();
  98.         return $stmt->fetchOne();
  99.     }
  100.     public function getSectionBySlug($slug)
  101.     {
  102.         $query = $this->getEntityManager()
  103.             ->createQuery(
  104.                 'SELECT s FROM
  105.                   NotarisAdminBundle:Section s
  106.                   WHERE s.slug = :slug
  107.                     AND s.isActive = true
  108.                     AND s.publicationDate <= :now'
  109.             )
  110.             ->setParameter('now', new \DateTime('now'))
  111.             ->setParameter('slug', $slug);
  112.         $sectie = $query->getResult();
  113.         if($sectie){
  114.             return array_shift($sectie);
  115.         }
  116.         return false;
  117.     }
  118.     public function getFirstSectionFromSubsite(Subsite $subsite)
  119.     {
  120.         $query = $this->getEntityManager()
  121.             ->createQuery(
  122.                 'SELECT s FROM
  123.                   NotarisAdminBundle:Section s
  124.                   WHERE s.subsite = :subsite
  125.                     AND s.isActive = true
  126.                     AND s.publicationDate <= :now
  127.                   ORDER BY s.id'
  128.             )
  129.             ->setParameter('now', new \DateTime('now'))
  130.             ->setParameter('subsite', $subsite);
  131.         $sectie = $query->getResult();
  132.         if($sectie){
  133.             return array_shift($sectie);
  134.         }
  135.         return false;
  136.     }
  137.     public function getAllSectionsFromSubsite(Subsite $subsite)
  138.     {
  139.         $query = $this->getEntityManager()
  140.             ->createQuery(
  141.                 'SELECT s FROM
  142.                   NotarisAdminBundle:Section s
  143.                   WHERE s.subsite = :subsite
  144.                     AND s.isActive = true
  145.                     AND s.publicationDate <= :now
  146.                     AND s.show_navigation = true
  147.                     AND s.parent IS NULL
  148.                   ORDER BY s.updated DESC'
  149.             )
  150.             ->setParameter('now', new \DateTime('now'))
  151.             ->setParameter('subsite', $subsite);
  152.         $sectie = $query->getResult();
  153.         if($sectie){
  154.             return $sectie;
  155.         }
  156.         return false;
  157.     }
  158.     public function getAllSectionsFromParent(Section $section)
  159.     {
  160.         $query = $this->getEntityManager()
  161.             ->createQuery(
  162.                 'SELECT s FROM
  163.                   NotarisAdminBundle:Section s
  164.                   WHERE s.isActive = true
  165.                     AND s.publicationDate <= :now
  166.                     AND s.show_navigation = true
  167.                     AND s.parent = :parent
  168.                   ORDER BY s.updated DESC'
  169.             )
  170.             ->setParameter('now', new \DateTime('now'))
  171.             ->setParameter('parent', $section);
  172.         $sectie = $query->getResult();
  173.         if($sectie){
  174.             return $sectie;
  175.         }
  176.         return false;
  177.     }
  178.     public function getSectionBySlugPreview($slug)
  179.     {
  180.         $query = $this->getEntityManager()
  181.             ->createQuery(
  182.                 'SELECT s FROM
  183.                   NotarisAdminBundle:Section s
  184.                   WHERE s.slug = :slug'
  185.             )
  186.             ->setParameter('slug', $slug);
  187.         $sectie = $query->getResult();
  188.         if($sectie){
  189.             return array_shift($sectie);
  190.         }
  191.         return false;
  192.     }
  193.     public function getPreviewSectionBySlug($slug)
  194.     {
  195.         $query = $this->getEntityManager()
  196.             ->createQuery(
  197.                 'SELECT s FROM
  198.                   NotarisAdminBundle:Section s
  199.                   WHERE s.slug = :slug'
  200.             )
  201.             ->setParameter('slug', $slug);
  202.         $sectie = $query->getResult();
  203.         if($sectie){
  204.             return array_shift($sectie);
  205.         }
  206.         return false;
  207.     }
  208.     public function search($keyword, $locale='nl') {
  209.         $searchResults = $this->createQueryBuilder('s')
  210.             ->select('s')
  211.             ->addSelect("MATCH_AGAINST (s.title, s.description, s.navigation, :address 'IN BOOLEAN MODE') as score")
  212.             ->innerJoin('s.subsite','sub')
  213.             ->where('sub.locale = :locale AND s.publicationDate <= :now AND s.isActive = 1 AND sub.isActive = 1')
  214.             ->andWhere("MATCH_AGAINST(s.title, s.description, s.navigation, :address 'IN BOOLEAN MODE') > 0.2")
  215.             ->setParameter('address', $keyword)
  216.             ->setParameter('locale', $locale)
  217.             ->setParameter('now', new \DateTime('now'))
  218.             ->orderBy('score', 'desc')
  219.             ->getQuery()
  220.             ->getResult();
  221.         if($searchResults){
  222.             return $searchResults;
  223.         }
  224.         return false;
  225.     }
  226.     public function getFirstSections(Subsite $subsite) {
  227.         $searchResults = $this->createQueryBuilder('s')
  228.             ->select('s')
  229.             ->where('s.subsite = :subsite')
  230.             ->andWhere("s.parent IS NULL")
  231.             ->setParameter('subsite', $subsite)
  232.             ->orderBy('s.position', 'asc')
  233.             ->getQuery()
  234.             ->getResult();
  235.         if($searchResults){
  236.             return $searchResults;
  237.         }
  238.         return false;
  239.     }
  240. }