1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* For licensing terms, see /license.txt */ |
6
|
|
|
|
7
|
|
|
namespace Chamilo\CoreBundle\Repository; |
8
|
|
|
|
9
|
|
|
use Chamilo\CoreBundle\Entity\ExtraField; |
10
|
|
|
use Chamilo\CoreBundle\Entity\Tag; |
11
|
|
|
use Chamilo\CoreBundle\Entity\User; |
12
|
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
13
|
|
|
use Doctrine\Common\Collections\Collection; |
14
|
|
|
use Doctrine\Persistence\ManagerRegistry; |
15
|
|
|
|
16
|
|
|
class TagRepository extends ServiceEntityRepository |
17
|
|
|
{ |
18
|
|
|
public function __construct(ManagerRegistry $registry) |
19
|
|
|
{ |
20
|
|
|
parent::__construct($registry, Tag::class); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @return Collection|Tag[] |
25
|
|
|
*/ |
26
|
|
|
public function findTagsByField(string $tag, ExtraField $field) |
27
|
|
|
{ |
28
|
|
|
$qb = $this->createQueryBuilder('t') |
29
|
|
|
->where('t.tag LIKE :tag') |
30
|
|
|
->andWhere('t.field = :field') |
31
|
|
|
->setParameter('field', $field) |
32
|
|
|
->setParameter('tag', "$tag%") |
33
|
|
|
; |
34
|
|
|
|
35
|
|
|
return $qb->getQuery()->getResult(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return Collection|Tag[] |
40
|
|
|
*/ |
41
|
|
|
public function getTagsByUser(ExtraField $field, User $user) |
42
|
|
|
{ |
43
|
|
|
$qb = $this->createQueryBuilder('t') |
44
|
|
|
->innerJoin('t.userRelTags', 'ut') |
45
|
|
|
->where('t.field = :field') |
46
|
|
|
->andWhere('ut.user = :user') |
47
|
|
|
->setParameter('field', $field) |
48
|
|
|
->setParameter('user', $user) |
49
|
|
|
; |
50
|
|
|
|
51
|
|
|
return $qb->getQuery()->getResult(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get the tags for an item. |
56
|
|
|
* |
57
|
|
|
* @return Collection|Tag[] |
58
|
|
|
*/ |
59
|
|
|
public function getTagsByItem(ExtraField $extraField, int $itemId) |
60
|
|
|
{ |
61
|
|
|
$qb = $this->createQueryBuilder('t') |
62
|
|
|
->innerJoin('t.extraFieldRelTags', 'et') |
63
|
|
|
->where('et.itemId = :itemId') |
64
|
|
|
->andWhere('et.field = :field') |
65
|
|
|
->setParameter('field', $extraField) |
66
|
|
|
->setParameter('itemId', $itemId) |
67
|
|
|
; |
68
|
|
|
|
69
|
|
|
return $qb->getQuery()->getResult(); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|