src/Notaris/AdminBundle/Entity/SectionParagraphRepository.php line 38

Open in your IDE?
  1. <?php
  2. namespace Notaris\AdminBundle\Entity;
  3. use Doctrine\ORM\EntityRepository;
  4. /**
  5.  * SectionParagraphRepository
  6.  *
  7.  * This class was generated by the Doctrine ORM. Add your own custom
  8.  * repository methods below.
  9.  */
  10. class SectionParagraphRepository extends EntityRepository
  11. {
  12.     /**
  13.      * @param $section_id
  14.      * @return bool|string
  15.      * @throws \Doctrine\DBAL\DBALException
  16.      */
  17.     public function getMaxPosition($section_id)
  18.     {
  19.         $em = $this->getEntityManager();
  20.         $con = $em->getConnection();
  21.         $sql = "SELECT MAX(position) as max
  22.                 FROM section_paragraph
  23.                 WHERE section_id = :section_id";
  24.         $stmt = $con->prepare($sql);
  25.         $stmt->bindValue('section_id', $section_id);
  26.         $stmt = $stmt->execute();
  27.         return $stmt->fetchOne();
  28.     }
  29.     public function getParagraphsBySection($section)
  30.     {
  31.         $query = $this->getEntityManager()
  32.             ->createQuery(
  33.                 'SELECT sp FROM
  34.                   NotarisAdminBundle:SectionParagraph sp
  35.                   WHERE sp.section = :section
  36.                     AND sp.isActive = true
  37.                     AND sp.publicationDate <= :now
  38.                   ORDER BY sp.position ASC'
  39.             )
  40.             ->setParameter('now', new \DateTime('now'))
  41.             ->setParameter('section', $section);
  42.         $sections = $query->getResult();
  43.         if($sections){
  44.             return $sections;
  45.         }
  46.         return false;
  47.     }
  48.     public function getParagraphsBySectionPreview($section)
  49.     {
  50.         $query = $this->getEntityManager()
  51.             ->createQuery(
  52.                 'SELECT sp FROM
  53.                   NotarisAdminBundle:SectionParagraph sp
  54.                   WHERE sp.section = :section
  55.                   ORDER BY sp.position ASC'
  56.             )
  57.             ->setParameter('section', $section);
  58.         $sections = $query->getResult();
  59.         if($sections){
  60.             return $sections;
  61.         }
  62.         return false;
  63.     }
  64.     public function getVideoByVideoPath($videoPath)
  65.     {
  66.         $query = $this->getEntityManager()
  67.             ->createQuery(
  68.                 'SELECT v FROM
  69.                   NotarisAdminBundle:AssetVideoPath avp
  70.                     INNER JOIN NotarisAdminBundle:Video v WITH v.asset = avp.asset
  71.                   WHERE avp = :videopath'
  72.             )
  73.             //->setParameter('now', new \DateTime('now'))
  74.             ->setParameter('videopath', $videoPath);
  75.         $video = $query->getResult();
  76.         if($video){
  77.             return array_shift($video);
  78.         }
  79.         return false;
  80.     }
  81.     public function search($keyword, $locale) {
  82.         $searchResults = $this->createQueryBuilder('p')
  83.             ->select('p,s')
  84.             ->addSelect("MATCH_AGAINST (p.title, p.subtitle, p.description, :address 'IN BOOLEAN MODE') as score")
  85.             ->innerJoin('p.section','s')
  86.             ->innerJoin('s.subsite', 'sub')
  87.             ->where('p.locale = :locale AND s.publicationDate <= :now AND s.isActive = 1 AND p.isActive = 1 AND sub.isActive = 1 AND p.publicationDate <= :now')
  88.             ->andWhere("MATCH_AGAINST(p.title, p.subtitle, p.description, :address 'IN BOOLEAN MODE') > 0.2")
  89.             ->setParameter('address', $keyword)
  90.             ->setParameter('locale', $locale)
  91.             ->setParameter('now', new \DateTime('now'))
  92.             ->orderBy('score', 'desc')
  93.             ->getQuery()
  94.             ->getResult();
  95.         if($searchResults){
  96.             return $searchResults;
  97.         }
  98.         return false;
  99.     }
  100. }