Completed
Push — 1.10.x ( 510322...3cf4d9 )
by Angel Fernando Quiroz
246:38 queued 207:48
created

CStudentPublicationRepository::findByTeacher()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 24
c 1
b 0
f 1
nc 1
nop 4
dl 0
loc 30
rs 8.8571
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CourseBundle\Entity\Repository;
5
6
use Chamilo\CoreBundle\Entity\Course;
7
use Chamilo\UserBundle\Entity\User;
8
use Doctrine\ORM\EntityRepository;
9
use Doctrine\ORM\Query\Expr;
10
use Doctrine\ORM\Query\Expr\Join;
11
use Doctrine\ORM\Query\Expr\OrderBy;
12
13
class CStudentPublicationRepository extends EntityRepository
14
{
15
    /**
16
     * Find all the works registered by a teacher
17
     * @param User $user
18
     * @param Course $course
19
     * @param int $sessionId Optional
20
     * @param int $groupId Optional
21
     * @return array
22
     */
23
    public function findByTeacher(User $user, Course $course, $sessionId = 0, $groupId = 0)
24
    {
25
        $qb = $this->createQueryBuilder('w');
26
        return $qb
27
            ->leftJoin(
28
                'ChamiloCourseBundle:CStudentPublicationAssignment',
29
                'a',
30
                Join::WITH,
31
                'a.publicationId = w.iid AND a.cId = w.cId'
32
            )
33
            ->where(
34
                $qb->expr()->andX(
35
                    $qb->expr()->eq('w.cId', ':course'),
36
                    $qb->expr()->eq('w.sessionId', ':session'),
37
                    $qb->expr()->in('w.active', [0, 1]),
38
                    $qb->expr()->eq('w.parentId', 0),
39
                    $qb->expr()->eq('w.postGroupId', ':group'),
40
                    $qb->expr()->eq('w.userId', ':user')
41
                )
42
            )
43
            ->orderBy('w.sentDate', 'DESC')
44
            ->setParameters([
45
                'course' => intval($course->getId()),
46
                'session' => intval($sessionId),
47
                'group' => intval($groupId),
48
                'user' => $user->getId()
49
            ])
50
            ->getQuery()
51
            ->getResult();
52
    }
53
}