vendor/roothirsch/core-bundle/Repository/UserRepository.php line 13

Open in your IDE?
  1. <?php
  2. namespace Roothirsch\CoreBundle\Repository;
  3. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  4. use Roothirsch\CoreBundle\Entity\User;
  5. use Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException;
  6. class UserRepository extends ServiceEntityRepository
  7. {
  8.     public function __construct(\Doctrine\Persistence\ManagerRegistry $registry)
  9.     {
  10.         parent::__construct($registryUser::class);
  11.     }
  12.     /**
  13.      * {@inheritdoc}
  14.      */
  15.     public function findOneByApiToken($apiToken)
  16.     {
  17.         $apiUser $this->findOneBy(['apiToken' => $apiToken]);
  18.         if (!$apiUser) {
  19.             throw new AuthenticationCredentialsNotFoundException();
  20.         }
  21.         return $apiUser;
  22.     }
  23.     /**
  24.      * @param string $email
  25.      *
  26.      * @return null|User
  27.      */
  28.     public function findUserByEmail($email)
  29.     {
  30.         return $this->findOneBy(['email' => $email]);
  31.     }
  32.     /**
  33.      * @param string $securityToken
  34.      *
  35.      * @return null|User
  36.      */
  37.     public function findUserBySecurityToken($securityToken)
  38.     {
  39.         return $this->findOneBy(['securityToken' => $securityToken]);
  40.     }
  41.     /**
  42.      * @param string $registrationToken
  43.      *
  44.      * @return null|User
  45.      */
  46.     public function findUserByRegistrationToken($registrationToken)
  47.     {
  48.         return $this->findOneBy(['registrationToken' => $registrationToken]);
  49.     }
  50.     /**
  51.      * Finds coworkers for a user.
  52.      *
  53.      * @param User $user
  54.      *
  55.      * @return array|mixed
  56.      */
  57.     public function findCoworkersForUser(User $user)
  58.     {
  59.         $company $user->getCompany();
  60.         if (!is_object($company)) {
  61.             return [];
  62.         }
  63.         $dql 'SELECT u FROM AppBundle:User AS u JOIN u.company c WHERE c.id = :company AND u.id != :user ORDER BY u.lastName';
  64.         $em $this->getEntityManager();
  65.         $query $em->createQuery($dql);
  66.         $query->setParameters(
  67.             [
  68.                 'company' => $company->getId(),
  69.                 'user' => $user->getId(),
  70.             ]
  71.         );
  72.         return $query->getResult();
  73.     }
  74. }