<?php
namespace Notaris\AdminBundle\Entity;
use Doctrine\ORM\EntityRepository;
/**
* SectionParagraphRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class SectionParagraphRepository extends EntityRepository
{
/**
* @param $section_id
* @return bool|string
* @throws \Doctrine\DBAL\DBALException
*/
public function getMaxPosition($section_id)
{
$em = $this->getEntityManager();
$con = $em->getConnection();
$sql = "SELECT MAX(position) as max
FROM section_paragraph
WHERE section_id = :section_id";
$stmt = $con->prepare($sql);
$stmt->bindValue('section_id', $section_id);
$stmt = $stmt->execute();
return $stmt->fetchOne();
}
public function getParagraphsBySection($section)
{
$query = $this->getEntityManager()
->createQuery(
'SELECT sp FROM
NotarisAdminBundle:SectionParagraph sp
WHERE sp.section = :section
AND sp.isActive = true
AND sp.publicationDate <= :now
ORDER BY sp.position ASC'
)
->setParameter('now', new \DateTime('now'))
->setParameter('section', $section);
$sections = $query->getResult();
if($sections){
return $sections;
}
return false;
}
public function getParagraphsBySectionPreview($section)
{
$query = $this->getEntityManager()
->createQuery(
'SELECT sp FROM
NotarisAdminBundle:SectionParagraph sp
WHERE sp.section = :section
ORDER BY sp.position ASC'
)
->setParameter('section', $section);
$sections = $query->getResult();
if($sections){
return $sections;
}
return false;
}
public function getVideoByVideoPath($videoPath)
{
$query = $this->getEntityManager()
->createQuery(
'SELECT v FROM
NotarisAdminBundle:AssetVideoPath avp
INNER JOIN NotarisAdminBundle:Video v WITH v.asset = avp.asset
WHERE avp = :videopath'
)
//->setParameter('now', new \DateTime('now'))
->setParameter('videopath', $videoPath);
$video = $query->getResult();
if($video){
return array_shift($video);
}
return false;
}
public function search($keyword, $locale) {
$searchResults = $this->createQueryBuilder('p')
->select('p,s')
->addSelect("MATCH_AGAINST (p.title, p.subtitle, p.description, :address 'IN BOOLEAN MODE') as score")
->innerJoin('p.section','s')
->innerJoin('s.subsite', 'sub')
->where('p.locale = :locale AND s.publicationDate <= :now AND s.isActive = 1 AND p.isActive = 1 AND sub.isActive = 1 AND p.publicationDate <= :now')
->andWhere("MATCH_AGAINST(p.title, p.subtitle, p.description, :address 'IN BOOLEAN MODE') > 0.2")
->setParameter('address', $keyword)
->setParameter('locale', $locale)
->setParameter('now', new \DateTime('now'))
->orderBy('score', 'desc')
->getQuery()
->getResult();
if($searchResults){
return $searchResults;
}
return false;
}
}