Completed
Push — master ( cbfb7e...6f5084 )
by Julito
20:33
created

findWorksByTeacher()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 23
nc 1
nop 4
dl 0
loc 30
rs 9.552
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\CoreBundle\Repository\ResourceRepository;
9
use Chamilo\UserBundle\Entity\User;
10
use Doctrine\ORM\Query\Expr\Join;
11
12
/**
13
 * Class CStudentPublicationRepository.
14
 */
15
final class CStudentPublicationRepository extends ResourceRepository
16
{
17
    /**
18
     * Find all the works registered by a teacher.
19
     *
20
     * @param Session $session Optional
21
     * @param int     $groupId Optional
22
     *
23
     * @return array
24
     */
25
    public function findWorksByTeacher(User $user, Course $course, Session $session = null, $groupId = 0)
26
    {
27
        $qb = $this->createQueryBuilder('w');
28
29
        return $qb
30
            ->leftJoin(
31
                'ChamiloCourseBundle:CStudentPublicationAssignment',
32
                'a',
33
                Join::WITH,
34
                'a.publicationId = w.iid AND a.cId = w.cId'
35
            )
36
            ->where(
37
                $qb->expr()->andX(
38
                    $qb->expr()->eq('w.cId', ':course'),
39
                    $qb->expr()->eq('w.session', ':session'),
40
                    $qb->expr()->in('w.active', [0, 1]),
41
                    $qb->expr()->eq('w.parentId', 0),
42
                    $qb->expr()->eq('w.postGroupId', ':group'),
43
                    $qb->expr()->eq('w.userId', ':user')
44
                )
45
            )
46
            ->orderBy('w.sentDate', 'ASC')
47
            ->setParameters([
48
                'course' => $course->getId(),
49
                'session' => $session,
50
                'group' => $groupId,
51
                'user' => $user->getId(),
52
            ])
53
            ->getQuery()
54
            ->getResult();
55
    }
56
}
57