Entity/TagRepository.php
changeset 77 021131fbe2c5
parent 75 ca2a145e67f3
equal deleted inserted replaced
76:bb7808e180c3 77:021131fbe2c5
     1 <?php
     1 <?php
       
     2 /*
       
     3  * This file is part of the WikiTagBundle package.
       
     4  *
       
     5  * (c) IRI <http://www.iri.centrepompidou.fr/>
       
     6  *
       
     7  * For the full copyright and license information, please view the LICENSE
       
     8  * file that was distributed with this source code.
       
     9  */
     2 
    10 
     3 namespace IRI\Bundle\WikiTagBundle\Entity;
    11 namespace IRI\Bundle\WikiTagBundle\Entity;
     4 
    12 
     5 use Doctrine\ORM\EntityRepository;
    13 use Doctrine\ORM\EntityRepository;
     6 use IRI\Bundle\WikiTagBundle\Utils\WikiTagUtils;
    14 use IRI\Bundle\WikiTagBundle\Utils\WikiTagUtils;
    34      * @param string $seed
    42      * @param string $seed
    35      */
    43      */
    36     public function getCompletion($seed)
    44     public function getCompletion($seed)
    37     {
    45     {
    38         $qb = $this->getEntityManager()->createQueryBuilder();
    46         $qb = $this->getEntityManager()->createQueryBuilder();
    39         $qb->select('DISTINCT t.label');
    47         $qb->select('t.label', 'COUNT(dt.id) AS nb_docs');
    40         $qb->from('WikiTagBundle:Tag','t');
    48         $qb->from('WikiTagBundle:Tag','t');
       
    49         $qb->leftJoin('t.documents', 'dt', 'WITH', 't = dt.tag');
       
    50         $qb->addGroupBy('t.label');
    41         $qb->where($qb->expr()->orx(
    51         $qb->where($qb->expr()->orx(
    42             $qb->expr()->like('t.label',$qb->expr()->literal(addcslashes(mysql_real_escape_string($seed),"%_")."%")),
    52             $qb->expr()->like('t.label',$qb->expr()->literal(addcslashes(mysql_real_escape_string($seed),"%_")."%")),
    43             $qb->expr()->like('t.label',$qb->expr()->literal("%".addcslashes(mysql_real_escape_string($seed),"%_"))),
    53             $qb->expr()->like('t.label',$qb->expr()->literal("%".addcslashes(mysql_real_escape_string($seed),"%_"))),
    44             $qb->expr()->like('t.label',$qb->expr()->literal("% ".addcslashes(mysql_real_escape_string($seed),"%_")."%"))
    54             $qb->expr()->like('t.label',$qb->expr()->literal("% ".addcslashes(mysql_real_escape_string($seed),"%_")."%"))
    45         ));
    55         ));