Passed
Push — master ( cf75f9...66ca98 )
by Julito
09:35
created

CStudentPublicationRepository::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CourseBundle\Repository;
5
6
use Chamilo\CoreBundle\Entity\Course;
7
use Chamilo\CoreBundle\Entity\Session;
8
use Chamilo\CourseBundle\Entity\CStudentPublication;
9
use Chamilo\UserBundle\Entity\User;
10
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
11
use Doctrine\Common\Persistence\ManagerRegistry;
12
use Doctrine\ORM\Query\Expr\Join;
13
14
/**
15
 * Class CStudentPublicationRepository.
16
 *
17
 * @package Chamilo\CourseBundle\Repository
18
 */
19
class CStudentPublicationRepository extends ServiceEntityRepository
20
{
21
    /**
22
     * CStudentPublicationRepository constructor.
23
     *
24
     * @param ManagerRegistry $registry
25
     */
26
    public function __construct(ManagerRegistry $registry)
27
    {
28
        parent::__construct($registry, CStudentPublication::class);
29
    }
30
31
    /**
32
     * Find all the works registered by a teacher.
33
     *
34
     * @param User    $user
35
     * @param Course  $course
36
     * @param Session $session Optional
37
     * @param int     $groupId Optional
38
     *
39
     * @return array
40
     */
41
    public function findWorksByTeacher(User $user, Course $course, Session $session = null, $groupId = 0)
42
    {
43
        $qb = $this->createQueryBuilder('w');
44
45
        return $qb
46
            ->leftJoin(
47
                'ChamiloCourseBundle:CStudentPublicationAssignment',
48
                'a',
49
                Join::WITH,
50
                'a.publicationId = w.iid AND a.cId = w.cId'
51
            )
52
            ->where(
53
                $qb->expr()->andX(
54
                    $qb->expr()->eq('w.cId', ':course'),
55
                    $qb->expr()->eq('w.session', ':session'),
56
                    $qb->expr()->in('w.active', [0, 1]),
57
                    $qb->expr()->eq('w.parentId', 0),
58
                    $qb->expr()->eq('w.postGroupId', ':group'),
59
                    $qb->expr()->eq('w.userId', ':user')
60
                )
61
            )
62
            ->orderBy('w.sentDate', 'ASC')
63
            ->setParameters([
64
                'course' => intval($course->getId()),
65
                'session' => $session,
66
                'group' => intval($groupId),
67
                'user' => $user->getId(),
68
            ])
69
            ->getQuery()
70
            ->getResult();
71
    }
72
}
73