Skip to content

Commit

Permalink
Add SkillRepository - refs BT#10372 #TMI
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Oct 2, 2015
1 parent bc3bbe8 commit 8450f2f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
57 changes: 57 additions & 0 deletions src/Chamilo/CoreBundle/Entity/Repository/SkillRepository.php
@@ -0,0 +1,57 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity\Repository;

use \Doctrine\ORM\EntityRepository;
use \Chamilo\UserBundle\Entity\User;
use \Chamilo\CoreBundle\Entity\Course;
use \Chamilo\CoreBundle\Entity\Session;
use \Doctrine\ORM\Query\Expr\Join;

/**
* SkillRepository class
*
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
*/
class SkillRepository extends EntityRepository{

/**
* Get the last acquired skill by a user on course and/or session
* @param User $user The user
* @param Course $course The course
* @param Session $session The session
* @return Skill
*/
public function getLastByUser(User $user, Course $course = null, Session $session = null)
{
$qb = $this->createQueryBuilder('s');

$qb->innerJoin(
'ChamiloCoreBundle:SkillRelUser',
'su',
Join::WITH,
's.id = su.skillId'
)
->where(
$qb->expr()->eq('su.userId', $user->getId())
);

if ($course) {
$qb->andWhere(
$qb->expr()->eq('su.courseId', $course->getId())
);
}

if ($session) {
$qb->andWhere(
$qb->expr()->eq('su.sessionId', $session->getId())
);
}

$qb->setMaxResults(1)
->orderBy('su.id', 'DESC');

return $qb->getQuery()->getOneOrNullResult();
}

}
2 changes: 1 addition & 1 deletion src/Chamilo/CoreBundle/Entity/Skill.php
Expand Up @@ -8,7 +8,7 @@
* Skill
*
* @ORM\Table(name="skill")
* @ORM\Entity
* @ORM\Entity(repositoryClass="Chamilo\CoreBundle\Entity\Repository\SkillRepository")
*/
class Skill
{
Expand Down

0 comments on commit 8450f2f

Please sign in to comment.