Use user/group repositories as services.

Remove unused UserManager.
pull/3064/head
Julio Montoya 5 years ago
parent bca9a3b7c5
commit 4dd404f196
  1. 27
      src/UserBundle/Entity/Manager/UserManager.php
  2. 14
      src/UserBundle/Entity/User.php
  3. 16
      src/UserBundle/Repository/GroupRepository.php
  4. 43
      src/UserBundle/Repository/UserRepository.php
  5. 8
      src/UserBundle/Resources/config/services.yml

@ -1,27 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\UserBundle\Entity\Manager;
use Chamilo\UserBundle\Entity\User;
use Sonata\UserBundle\Entity\UserManager as BaseUserManager;
/**
* Class UserManager.
*
* @package Chamilo\UserBundle\Entity\Manager
*/
class UserManager extends BaseUserManager
{
/**
* @param string $code
*
* @return User
*/
public function findUserByOfficialCode($code)
{
$criteria = ['officialCode' => $code];
return $this->findUserBy($criteria);
}
}

@ -3,7 +3,6 @@
namespace Chamilo\UserBundle\Entity;
//use Chamilo\CoreBundle\Entity\UserFieldValues;
use Chamilo\CoreBundle\Entity\AccessUrl;
use Chamilo\CoreBundle\Entity\AccessUrlRelUser;
use Chamilo\CoreBundle\Entity\Course;
@ -15,7 +14,6 @@ use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Mapping as ORM;
//use FOS\UserBundle\Model\GroupInterface;
use Sonata\UserBundle\Entity\BaseUser;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\HttpFoundation\File\File;
@ -24,16 +22,6 @@ use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Mapping\ClassMetadata;
//use Chamilo\CoreBundle\Component\Auth;
//use FOS\MessageBundle\Model\ParticipantInterface;
//use Chamilo\ThemeBundle\Model\UserInterface as ThemeUser;
//use Vich\UploaderBundle\Mapping\Annotation as Vich;
//use Application\Sonata\MediaBundle\Entity\Media;
//use Chamilo\UserBundle\Model\UserInterface as UserInterfaceModel;
//use Sylius\Component\Attribute\Model\AttributeValueInterface as BaseAttributeValueInterface;
//use Sylius\Component\Variation\Model\OptionInterface as BaseOptionInterface;
//use Sylius\Component\Variation\Model\VariantInterface as BaseVariantInterface;
/**
* @ORM\HasLifecycleCallbacks
* @ORM\Table(
@ -45,7 +33,7 @@ use Symfony\Component\Validator\Mapping\ClassMetadata;
* )
* @UniqueEntity("username")
*
* @ORM\Entity(repositoryClass="Chamilo\UserBundle\Repository\UserRepository")
* @ORM\Entity()
*
* @ORM\AttributeOverrides({
* @ORM\AttributeOverride(name="username",

@ -3,22 +3,34 @@
namespace Chamilo\UserBundle\Repository;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use FOS\UserBundle\Model\Group;
/**
* Class GroupRepository.
*
* @package Entity\Repository
*/
class GroupRepository extends EntityRepository
class GroupRepository
{
/**
* @var EntityRepository
*/
private $repository;
public function __construct(EntityManagerInterface $entityManager)
{
$this->repository = $entityManager->getRepository(Group::class);
}
/**
* @return mixed
*/
public function getAdmins()
{
$criteria = ['name' => 'admins'];
$group = $this->findOneBy($criteria);
$group = $this->repository->findOneBy($criteria);
return $group->getUsers();
}

@ -44,26 +44,39 @@ use Chamilo\CourseBundle\Entity\CSurveyAnswer;
use Chamilo\CourseBundle\Entity\CWiki;
use Chamilo\TicketBundle\Entity\Ticket;
use Chamilo\UserBundle\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query\Expr\Join;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
use Symfony\Component\Serializer\Serializer;
//use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
//use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
/**
* Class UserRepository.
*
* All functions that query the database (selects)
* Functions should return query builders.
*
* @package Chamilo\UserBundle\Repository
*/
class UserRepository extends EntityRepository
class UserRepository
{
/**
* @var EntityRepository
*/
private $repository;
public function __construct(EntityManagerInterface $entityManager)
{
$this->repository = $entityManager->getRepository(User::class);
}
public function findByUsername(string $username): ?User
{
return $this->repository->findOneBy(['username' => $username]);
}
/**
* @param string $keyword
*
@ -71,7 +84,7 @@ class UserRepository extends EntityRepository
*/
public function searchUserByKeyword($keyword)
{
$qb = $this->createQueryBuilder('a');
$qb = $this->repository->createQueryBuilder('a');
// Selecting user info
$qb->select('DISTINCT b');
@ -97,7 +110,7 @@ class UserRepository extends EntityRepository
*/
public function findByRole($role)
{
$em = $this->getEntityManager();
$em = $this->repository->getEntityManager();
$qb = $em->createQueryBuilder();
$qb->select('u')
@ -184,7 +197,7 @@ class UserRepository extends EntityRepository
public function searchUsersByStatus($query, $status, $accessUrlId = null)
{
$accessUrlId = (int) $accessUrlId;
$queryBuilder = $this->createQueryBuilder('u');
$queryBuilder = $this->repository->createQueryBuilder('u');
if ($accessUrlId > 0) {
$queryBuilder->innerJoin(
@ -218,7 +231,7 @@ class UserRepository extends EntityRepository
*/
public function getCoachesForSessionCourse(Session $session, Course $course)
{
$queryBuilder = $this->createQueryBuilder('u');
$queryBuilder = $this->repository->createQueryBuilder('u');
$queryBuilder->select('u')
->innerJoin(
@ -307,7 +320,7 @@ class UserRepository extends EntityRepository
*/
public function getSessionAdmins(User $user)
{
$queryBuilder = $this->createQueryBuilder('u');
$queryBuilder = $this->repository->createQueryBuilder('u');
$queryBuilder
->distinct()
->innerJoin(
@ -340,7 +353,7 @@ class UserRepository extends EntityRepository
*/
public function getStudentBosses(User $user)
{
$queryBuilder = $this->createQueryBuilder('u');
$queryBuilder = $this->repository->createQueryBuilder('u');
$queryBuilder
->distinct()
->innerJoin(
@ -366,7 +379,7 @@ class UserRepository extends EntityRepository
*/
public function getCountUsersByUrl(AccessUrl $url)
{
return $this->createQueryBuilder('a')
return $this->repository->createQueryBuilder('a')
->select('COUNT(a)')
->innerJoin('a.portals', 'u')
->where('u.portal = :u')
@ -382,7 +395,7 @@ class UserRepository extends EntityRepository
*/
public function getCountTeachersByUrl(AccessUrl $url)
{
$qb = $this->createQueryBuilder('a');
$qb = $this->repository->createQueryBuilder('a');
return $qb
->select('COUNT(a)')
@ -489,7 +502,7 @@ class UserRepository extends EntityRepository
*/
public function getAssignedHrmUserList($userId, $urlId)
{
$qb = $this->createQueryBuilder('user');
$qb = $this->repository->createQueryBuilder('user');
$hrmList = $qb
->select('uru')

@ -1,4 +1,8 @@
services:
_defaults:
autowire: true
public: true
chamilo_user.security.user_provider:
class: Chamilo\UserBundle\Security\FOSUBUserProvider
arguments:
@ -7,4 +11,6 @@ services:
chamilo_user.security.login_form_authenticator:
class: Chamilo\UserBundle\Security\LoginFormAuthenticator
autowire: true
Chamilo\UserBundle\Repository\UserRepository: ~
Chamilo\UserBundle\Repository\GroupRepository: ~

Loading…
Cancel
Save