1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* For license terms, see /license.txt */ |
4
|
|
|
|
5
|
|
|
namespace Chamilo\PluginBundle\TopLinks\Entity\Repository; |
6
|
|
|
|
7
|
|
|
use Chamilo\CoreBundle\Entity\Course; |
8
|
|
|
use Chamilo\CourseBundle\Entity\CTool; |
9
|
|
|
use Chamilo\PluginBundle\TopLinks\Entity\TopLink; |
10
|
|
|
use Chamilo\PluginBundle\TopLinks\Entity\TopLinkRelTool; |
11
|
|
|
use Doctrine\ORM\EntityRepository; |
12
|
|
|
use Doctrine\ORM\Query\Expr\Join; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class TopLinkRelToolRepository. |
16
|
|
|
*/ |
17
|
|
|
class TopLinkRelToolRepository extends EntityRepository |
18
|
|
|
{ |
19
|
|
|
public function findInCourse(Course $course) |
20
|
|
|
{ |
21
|
|
|
$qb = $this->createQueryBuilder('tlrt'); |
22
|
|
|
|
23
|
|
|
return $qb |
24
|
|
|
->innerJoin('tlrt.tool', 'tool', Join::WITH) |
25
|
|
|
->where($qb->expr()->eq('tool.cId', ':course')) |
26
|
|
|
->setParameter('course', $course) |
27
|
|
|
->getQuery() |
28
|
|
|
->getResult(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function updateTools(TopLink $link) |
32
|
|
|
{ |
33
|
|
|
$subQb = $this->createQueryBuilder('tlrt'); |
34
|
|
|
$subQb |
35
|
|
|
->select('tool.iid') |
36
|
|
|
->innerJoin('tlrt.tool', 'tool', Join::WITH) |
37
|
|
|
->where($subQb->expr()->eq('tlrt.link', ':link')) |
38
|
|
|
->setParameter('link', $link); |
39
|
|
|
|
40
|
|
|
$linkTools = $subQb->getQuery()->getArrayResult(); |
41
|
|
|
|
42
|
|
|
$qb = $this->_em->createQueryBuilder(); |
43
|
|
|
$qb |
44
|
|
|
->update(CTool::class, 'tool') |
45
|
|
|
->set('tool.name', ':link_name') |
46
|
|
|
->set('tool.target', ':link_target') |
47
|
|
|
->where( |
48
|
|
|
$qb->expr()->in('tool.iid', ':tools') |
49
|
|
|
) |
50
|
|
|
->setParameter('link_name', $link->getTitle()) |
51
|
|
|
->setParameter('link_target', $link->getTarget()) |
52
|
|
|
->setParameter('tools', array_column($linkTools, 'iid')) |
53
|
|
|
->getQuery() |
54
|
|
|
->execute(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function getMissingCoursesForTool(int $linkId) |
58
|
|
|
{ |
59
|
|
|
$qb = $this->_em->createQueryBuilder(); |
60
|
|
|
|
61
|
|
|
$subQb = $this->_em->createQueryBuilder(); |
62
|
|
|
$subQb |
63
|
|
|
->select('t.cId') |
64
|
|
|
->from(CTool::class, 't') |
65
|
|
|
->innerJoin(TopLinkRelTool::class, 'tlrt', Join::WITH, $subQb->expr()->eq('t.iid', 'tlrt.tool')) |
66
|
|
|
->where($subQb->expr()->eq('tlrt.link', ':link_id')); |
67
|
|
|
|
68
|
|
|
return $qb |
69
|
|
|
->select('c') |
70
|
|
|
->from(Course::class, 'c') |
71
|
|
|
->where($qb->expr()->notIn('c.id', $subQb->getDQL())) |
72
|
|
|
->setParameter('link_id', $linkId) |
73
|
|
|
->getQuery() |
74
|
|
|
->getResult(); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|