Chamilo is a learning management system focused on ease of use and accessibility
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.
chamilo-lms/src/Chamilo/UserBundle/Repository/UserRepository.php

143 lines
3.7 KiB

<?php
namespace Chamilo\UserBundle\Repository;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\NoResultException;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Chamilo\UserBundle\Entity\User as User;
/**
* Class UserRepository
* @package Entity\Repository
*/
class UserRepository extends EntityRepository
{
13 years ago
/**
* @param string $keyword
* @return mixed
*/
13 years ago
public function searchUserByKeyword($keyword)
{
$qb = $this->createQueryBuilder('a');
// Selecting user info
13 years ago
$qb->select('DISTINCT b');
$qb->from('Chamilo\UserBundle\Entity\User', 'b');
13 years ago
// Selecting courses for users
13 years ago
//$qb->innerJoin('u.courses', 'c');
//@todo check app settings
$qb->add('orderBy', 'b.firstname ASC');
$qb->where('b.firstname LIKE :keyword OR b.lastname LIKE :keyword ');
$qb->setParameter('keyword', "%$keyword%");
$query = $qb->getQuery();
return $query->execute();
}
/**
* @param string $username
* @return User
* @throws UsernameNotFoundException
*/
/*public function loadUserByUsername($username)
{
$query = $this
->createQueryBuilder('u')
->where('u.username = :username OR u.email = :email')
->leftJoin('u.roles', 'r')
->setParameter('username', $username)
->setParameter('email', $username)
->getQuery();
try {
$user = $query->getSingleResult();
} catch (NoResultException $e) {
throw new UsernameNotFoundException(
sprintf('Unable to find an active admin User identified by "%s".', $username),
0,
$e
);
}
return $user;
}*/
/**
* @param string $class
* @return bool
*/
/*public function supportsClass($class)
{
return $this->getEntityName() === $class || is_subclass_of($class, $this->getEntityName());
}*/
/**
* Get course user relationship based in the course_rel_user table.
* @return array
*/
public function getCourses(User $user)
{
$queryBuilder = $this->createQueryBuilder('user');
// Selecting course info.
$queryBuilder->select('c');
// Loading User.
//$qb->from('Chamilo\UserBundle\Entity\User', 'u');
// Selecting course
$queryBuilder->innerJoin('Chamilo\CoreBundle\Entity\Course', 'c');
//@todo check app settings
//$qb->add('orderBy', 'u.lastname ASC');
$wherePart = $queryBuilder->expr()->andx();
// Get only users subscribed to this course
$wherePart->add($queryBuilder->expr()->eq('user.userId', $user->getUserId()));
$queryBuilder->where($wherePart);
$query = $queryBuilder->getQuery();
return $query->execute();
}
public function getTeachers()
{
$queryBuilder = $this->createQueryBuilder('u');
// Selecting course info.
$queryBuilder
->select('u')
->where('u.groups.id = :groupId')
->setParameter('groupId', 1);
$query = $queryBuilder->getQuery();
return $query->execute();
/*$studentGroup = $this->findOneBy(array('name' => 'students'));
return $this->getUsers($studentGroup);*/
}
public function getUsers($group)
{
$queryBuilder = $this->createQueryBuilder('u');
// Selecting course info.
$queryBuilder
->select('u')
->where('u.groups = :groupId')
->setParameter('groupId', $group);
$query = $queryBuilder->getQuery();
return $query->execute();
}
}