|
2
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
namespace IRI\Bundle\WikiTagBundle\Entity; |
|
|
4 |
|
|
|
5 |
use Doctrine\ORM\EntityRepository; |
|
|
6 |
|
|
|
7 |
/** |
|
|
8 |
* TagRepository |
|
|
9 |
* |
|
|
10 |
* This class was generated by the Doctrine ORM. Add your own custom |
|
|
11 |
* repository methods below. |
|
|
12 |
*/ |
|
|
13 |
class TagRepository extends EntityRepository |
|
|
14 |
{ |
|
34
|
15 |
public function getTagCloud($max_tags) |
|
|
16 |
{ |
|
|
17 |
$qb = $this->getEntityManager()->createQueryBuilder(); |
|
|
18 |
$qb->select('t.id', 't.label', 'COUNT( dt.id ) AS nb_docs'); |
|
|
19 |
$qb->from('WikiTagBundle:Tag','t'); |
|
|
20 |
$qb->leftJoin('t.documents', 'dt', 'WITH', 't = dt.tag'); |
|
|
21 |
$qb->addGroupBy('t.id'); |
|
|
22 |
$qb->addOrderBy('nb_docs','DESC'); |
|
|
23 |
$qb->setMaxResults($max_tags); |
|
|
24 |
|
|
|
25 |
$query = $qb->getQuery(); |
|
|
26 |
return $query->getResult(); |
|
|
27 |
} |
|
|
28 |
|
|
|
29 |
public function getCompletion($seed) |
|
|
30 |
{ |
|
|
31 |
$qb = $this->getEntityManager()->createQueryBuilder(); |
|
|
32 |
$qb->select('t.label'); |
|
|
33 |
$qb->from('WikiTagBundle:Tag','t'); |
|
|
34 |
$qb->where($qb->expr()->orx( |
|
|
35 |
$qb->expr()->like('t.label',$qb->expr()->literal("%".addcslashes(mysql_real_escape_string($seed),"%_"))), |
|
|
36 |
$qb->expr()->like('t.label',$qb->expr()->literal("% ".addcslashes(mysql_real_escape_string($seed),"%_")."%")) |
|
|
37 |
)); |
|
|
38 |
|
|
|
39 |
$query = $qb->getQuery(); |
|
|
40 |
|
|
|
41 |
return $query->getResult(); |
|
|
42 |
|
|
|
43 |
} |
|
2
|
44 |
} |