You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
143 lines
3.4 KiB
143 lines
3.4 KiB
<?php
|
|
|
|
namespace Entity\Repository;
|
|
|
|
use Doctrine\ORM\EntityRepository;
|
|
use Doctrine\Common\Collections\Criteria;
|
|
use Doctrine\ORM\NoResultException;
|
|
|
|
/**
|
|
* JuryRepository
|
|
*
|
|
*/
|
|
class JuryRepository extends EntityRepository
|
|
{
|
|
/**
|
|
* Get all users that are registered in the course. No matter the status
|
|
*
|
|
* @param \Entity\Course $course
|
|
* @return \Entity\Jury
|
|
*/
|
|
public function getJuryByPresidentId($userId)
|
|
{
|
|
$qb = $this->createQueryBuilder('a');
|
|
|
|
//Selecting user info
|
|
$qb->select('DISTINCT u');
|
|
|
|
// Loading EntityUser
|
|
$qb->from('Entity\Jury', 'u');
|
|
|
|
// Selecting members
|
|
$qb->innerJoin('u.members', 'c');
|
|
|
|
// Inner join with the table c_quiz_question_rel_category.
|
|
$qb->innerJoin('c.role', 'r');
|
|
|
|
//@todo check app settings
|
|
//$qb->add('orderBy', 'u.lastname ASC');
|
|
|
|
$wherePart = $qb->expr()->andx();
|
|
|
|
//Get only users subscribed to this course
|
|
$wherePart->add($qb->expr()->eq('r.role', $qb->expr()->literal('ROLE_JURY_PRESIDENT')));
|
|
$wherePart->add($qb->expr()->eq('c.userId', $userId));
|
|
|
|
$qb->where($wherePart);
|
|
$q = $qb->getQuery();
|
|
|
|
try {
|
|
return $q->getSingleResult();
|
|
} catch (NoResultException $e) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param $userId
|
|
* @return \Entity\Jury
|
|
*/
|
|
public function getJuryByUserId($userId)
|
|
{
|
|
$qb = $this->createQueryBuilder('a');
|
|
|
|
//Selecting user info
|
|
$qb->select('DISTINCT u');
|
|
|
|
// Loading EntityUser
|
|
$qb->from('Entity\Jury', 'u');
|
|
|
|
// Selecting members
|
|
$qb->innerJoin('u.members', 'c');
|
|
|
|
// Inner join with the table c_quiz_question_rel_category.
|
|
$qb->innerJoin('c.role', 'r');
|
|
|
|
//@todo check app settings
|
|
//$qb->add('orderBy', 'u.lastname ASC');
|
|
|
|
$wherePart = $qb->expr()->andx();
|
|
|
|
//Get user
|
|
$wherePart->add($qb->expr()->eq('c.userId', $userId));
|
|
|
|
$qb->where($wherePart);
|
|
$q = $qb->getQuery();
|
|
|
|
try {
|
|
return $q->getSingleResult();
|
|
} catch (NoResultException $e) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param int $juryId
|
|
* @param array skip this roles
|
|
*
|
|
* @return bool|mixed
|
|
*/
|
|
public function getStudentsByJury($juryId, $skipRoles = array())
|
|
{
|
|
$qb = $this->createQueryBuilder('a');
|
|
|
|
//Selecting user info
|
|
$qb->select('DISTINCT u');
|
|
|
|
// Loading EntityUser
|
|
$qb->from('Entity\Jury', 'u');
|
|
|
|
// Selecting members
|
|
$qb->innerJoin('u.members', 'c');
|
|
|
|
// Inner join with the table c_quiz_question_rel_category.
|
|
$qb->innerJoin('c.role', 'r');
|
|
|
|
$qb->innerJoin('c.students', 's');
|
|
|
|
//@todo check app settings
|
|
//$qb->add('orderBy', 'u.lastname ASC');
|
|
|
|
$wherePart = $qb->expr()->andx();
|
|
|
|
// Get jury
|
|
$wherePart->add($qb->expr()->eq('u.id', $juryId));
|
|
|
|
if (!empty($skipRoles)) {
|
|
foreach ($skipRoles as $role) {
|
|
$wherePart->add($qb->expr()->neq('r.role', $qb->expr()->literal($role)));
|
|
}
|
|
}
|
|
|
|
$qb->where($wherePart);
|
|
|
|
$q = $qb->getQuery();
|
|
|
|
try {
|
|
return $q->getSingleResult();
|
|
} catch (NoResultException $e) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|