cs: Fix code style (safe rules only).

This commit is contained in:
Pol Dellaiera
2021-11-23 14:06:38 +01:00
parent 149d7ce991
commit 8f96a1121d
1223 changed files with 65199 additions and 64625 deletions

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Repository;
@@ -18,16 +25,19 @@ final class AddressReferenceRepository implements ObjectRepository
$this->repository = $entityManager->getRepository(AddressReference::class);
}
public function countAll(): int
{
$qb = $this->repository->createQueryBuilder('ar');
$qb->select('count(ar.id)');
return $qb->getQuery()->getSingleScalarResult();
}
public function find($id, $lockMode = null, $lockVersion = null): ?AddressReference
{
return $this->repository->find($id, $lockMode, $lockVersion);
}
public function findOneBy(array $criteria, array $orderBy = null): ?AddressReference
{
return $this->repository->findOneBy($criteria, $orderBy);
}
/**
* @return AddressReference[]
*/
@@ -36,23 +46,24 @@ final class AddressReferenceRepository implements ObjectRepository
return $this->repository->findAll();
}
public function countAll(): int
{
$qb = $this->repository->createQueryBuilder('ar');
$qb->select('count(ar.id)');
return $qb->getQuery()->getSingleScalarResult();
}
/**
* @param mixed|null $limit
* @param mixed|null $offset
*
* @return AddressReference[]
*/
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
public function getClassName() {
public function findOneBy(array $criteria, ?array $orderBy = null): ?AddressReference
{
return $this->repository->findOneBy($criteria, $orderBy);
}
public function getClassName()
{
return AddressReference::class;
}
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Repository;
@@ -19,16 +26,16 @@ final class AddressRepository implements ObjectRepository
$this->repository = $entityManager->getRepository(Address::class);
}
public function createQueryBuilder(string $alias, ?string $indexBy = null): QueryBuilder
{
return $this->repository->createQueryBuilder($alias, $indexBy);
}
public function find($id, $lockMode = null, $lockVersion = null): ?Address
{
return $this->repository->find($id, $lockMode, $lockVersion);
}
public function findOneBy(array $criteria, array $orderBy = null): ?Address
{
return $this->repository->findOneBy($criteria, $orderBy);
}
/**
* @return Address[]
*/
@@ -38,19 +45,23 @@ final class AddressRepository implements ObjectRepository
}
/**
* @param mixed|null $limit
* @param mixed|null $offset
*
* @return Address[]
*/
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
public function getClassName() {
return Address::class;
public function findOneBy(array $criteria, ?array $orderBy = null): ?Address
{
return $this->repository->findOneBy($criteria, $orderBy);
}
public function createQueryBuilder(string $alias, ?string $indexBy = null): QueryBuilder
public function getClassName()
{
return $this->repository->createQueryBuilder($alias, $indexBy);
return Address::class;
}
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Repository;
@@ -23,11 +30,6 @@ final class CenterRepository implements ObjectRepository
return $this->repository->find($id, $lockMode, $lockVersion);
}
public function findOneBy(array $criteria, array $orderBy = null): ?Center
{
return $this->repository->findOneBy($criteria, $orderBy);
}
/**
* @return Center[]
*/
@@ -37,14 +39,23 @@ final class CenterRepository implements ObjectRepository
}
/**
* @param mixed|null $limit
* @param mixed|null $offset
*
* @return Center[]
*/
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
public function getClassName() {
public function findOneBy(array $criteria, ?array $orderBy = null): ?Center
{
return $this->repository->findOneBy($criteria, $orderBy);
}
public function getClassName()
{
return Center::class;
}
}

View File

@@ -1,23 +1,10 @@
<?php
/*
/**
* Chill is a software for social workers
*
* Copyright (C) 2021, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Repository;
@@ -38,5 +25,4 @@ class CivilityRepository extends ServiceEntityRepository
{
parent::__construct($registry, Civility::class);
}
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Repository;
@@ -23,11 +30,6 @@ final class CountryRepository implements ObjectRepository
return $this->repository->find($id, $lockMode, $lockVersion);
}
public function findOneBy(array $criteria, array $orderBy = null): ?Country
{
return $this->repository->findOneBy($criteria, $orderBy);
}
/**
* @return Country[]
*/
@@ -37,14 +39,23 @@ final class CountryRepository implements ObjectRepository
}
/**
* @param mixed|null $limit
* @param mixed|null $offset
*
* @return Country[]
*/
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
public function getClassName() {
public function findOneBy(array $criteria, ?array $orderBy = null): ?Country
{
return $this->repository->findOneBy($criteria, $orderBy);
}
public function getClassName()
{
return Country::class;
}
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Repository;
@@ -23,11 +30,6 @@ final class GroupCenterRepository implements ObjectRepository
return $this->repository->find($id, $lockMode, $lockVersion);
}
public function findOneBy(array $criteria, array $orderBy = null): ?GroupCenter
{
return $this->repository->findOneBy($criteria, $orderBy);
}
/**
* @return GroupCenter[]
*/
@@ -37,14 +39,23 @@ final class GroupCenterRepository implements ObjectRepository
}
/**
* @param mixed|null $limit
* @param mixed|null $offset
*
* @return GroupCenter[]
*/
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
public function getClassName() {
public function findOneBy(array $criteria, ?array $orderBy = null): ?GroupCenter
{
return $this->repository->findOneBy($criteria, $orderBy);
}
public function getClassName()
{
return GroupCenter::class;
}
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Repository;
@@ -23,11 +30,6 @@ final class LanguageRepository implements ObjectRepository
return $this->repository->find($id, $lockMode, $lockVersion);
}
public function findOneBy(array $criteria, array $orderBy = null): ?Language
{
return $this->repository->findOneBy($criteria, $orderBy);
}
/**
* @return Language[]
*/
@@ -37,14 +39,23 @@ final class LanguageRepository implements ObjectRepository
}
/**
* @param mixed|null $limit
* @param mixed|null $offset
*
* @return Language[]
*/
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
public function getClassName() {
public function findOneBy(array $criteria, ?array $orderBy = null): ?Language
{
return $this->repository->findOneBy($criteria, $orderBy);
}
public function getClassName()
{
return Language::class;
}
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Repository;
use Chill\MainBundle\Entity\Location;
@@ -20,7 +27,7 @@ class LocationRepository extends ServiceEntityRepository
}
/**
* fetch locations which are selectable for users
* fetch locations which are selectable for users.
*
* @return Location[]
*/

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Repository;
use Chill\MainBundle\Entity\LocationType;
@@ -18,5 +25,4 @@ class LocationTypeRepository extends ServiceEntityRepository
{
parent::__construct($registry, LocationType::class);
}
}

View File

@@ -1,30 +1,20 @@
<?php
/*
* Copyright (C) 2021 Champs-Libres <info@champs-libres.coop>
/**
* Chill is a software for social workers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Repository;
use Chill\MainBundle\Entity\Notification;
use Chill\MainBundle\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\Persistence\ObjectRepository;
use Chill\MainBundle\Entity\User;
use Doctrine\ORM\Query;
use Doctrine\Persistence\ObjectRepository;
final class NotificationRepository implements ObjectRepository
{
@@ -35,16 +25,18 @@ final class NotificationRepository implements ObjectRepository
$this->repository = $entityManager->getRepository(Notification::class);
}
public function countAllForAttendee(User $addressee): int // TODO passer à attendees avec S
{
$query = $this->queryAllForAttendee($addressee, $countQuery = true);
return $query->getSingleScalarResult();
}
public function find($id, $lockMode = null, $lockVersion = null): ?Notification
{
return $this->repository->find($id, $lockMode, $lockVersion);
}
public function findOneBy(array $criteria, array $orderBy = null): ?Notification
{
return $this->repository->findOneBy($criteria, $orderBy);
}
/**
* @return Notification[]
*/
@@ -54,19 +46,54 @@ final class NotificationRepository implements ObjectRepository
}
/**
* @param mixed|null $limit
* @param mixed|null $offset
*
* @return Notification[]
*/
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
public function findAllForAttendee(User $addressee, $limit = null, $offset = null): array // TODO passer à attendees avec S
{
$query = $this->queryAllForAttendee($addressee);
if ($limit) {
$query = $query->setMaxResults($limit);
}
if ($offset) {
$query = $query->setFirstResult($offset);
}
return $query->getResult();
}
/**
* @param mixed|null $limit
* @param mixed|null $offset
*
* @return Notification[]
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
private function queryAllForAttendee(User $addressee, bool $countQuery=False): Query
public function findOneBy(array $criteria, ?array $orderBy = null): ?Notification
{
return $this->repository->findOneBy($criteria, $orderBy);
}
public function getClassName()
{
return Notification::class;
}
private function queryAllForAttendee(User $addressee, bool $countQuery = false): Query
{
$qb = $this->repository->createQueryBuilder('n');
$select = 'n';
if($countQuery) {
if ($countQuery) {
$select = 'count(n)';
}
@@ -78,37 +105,4 @@ final class NotificationRepository implements ObjectRepository
return $qb->getQuery();
}
/**
* @return int
*/
public function countAllForAttendee(User $addressee): int // TODO passer à attendees avec S
{
$query = $this->queryAllForAttendee($addressee, $countQuery=True);
return $query->getSingleScalarResult();
}
/**
* @return Notification[]
*/
public function findAllForAttendee(User $addressee, $limit = null, $offset = null): array // TODO passer à attendees avec S
{
$query = $this->queryAllForAttendee($addressee);
if($limit) {
$query = $query->setMaxResults($limit);
}
if($offset) {
$query = $query->setFirstResult($offset);
}
return $query->getResult();
}
public function getClassName() {
return Notification::class;
}
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Repository;
@@ -23,11 +30,6 @@ final class PermissionsGroupRepository implements ObjectRepository
return $this->repository->find($id, $lockMode, $lockVersion);
}
public function findOneBy(array $criteria, array $orderBy = null): ?PermissionsGroup
{
return $this->repository->findOneBy($criteria, $orderBy);
}
/**
* @return PermissionsGroup[]
*/
@@ -37,14 +39,23 @@ final class PermissionsGroupRepository implements ObjectRepository
}
/**
* @param mixed|null $limit
* @param mixed|null $offset
*
* @return PermissionsGroup[]
*/
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
public function getClassName() {
public function findOneBy(array $criteria, ?array $orderBy = null): ?PermissionsGroup
{
return $this->repository->findOneBy($criteria, $orderBy);
}
public function getClassName()
{
return PermissionsGroup::class;
}
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Repository;
@@ -23,11 +30,6 @@ final class PostalCodeRepository implements ObjectRepository
return $this->repository->find($id, $lockMode, $lockVersion);
}
public function findOneBy(array $criteria, array $orderBy = null): ?PostalCode
{
return $this->repository->findOneBy($criteria, $orderBy);
}
/**
* @return PostalCode[]
*/
@@ -37,14 +39,23 @@ final class PostalCodeRepository implements ObjectRepository
}
/**
* @param mixed|null $limit
* @param mixed|null $offset
*
* @return PostalCode[]
*/
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
public function getClassName() {
public function findOneBy(array $criteria, ?array $orderBy = null): ?PostalCode
{
return $this->repository->findOneBy($criteria, $orderBy);
}
public function getClassName()
{
return PostalCode::class;
}
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Repository;
@@ -23,11 +30,6 @@ final class RoleScopeRepository implements ObjectRepository
return $this->repository->find($id, $lockMode, $lockVersion);
}
public function findOneBy(array $criteria, array $orderBy = null): ?RoleScope
{
return $this->repository->findOneBy($criteria, $orderBy);
}
/**
* @return RoleScope[]
*/
@@ -37,14 +39,23 @@ final class RoleScopeRepository implements ObjectRepository
}
/**
* @param mixed|null $limit
* @param mixed|null $offset
*
* @return RoleScope[]
*/
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
public function getClassName() {
public function findOneBy(array $criteria, ?array $orderBy = null): ?RoleScope
{
return $this->repository->findOneBy($criteria, $orderBy);
}
public function getClassName()
{
return RoleScope::class;
}
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Repository;
@@ -18,16 +25,16 @@ final class ScopeRepository implements ObjectRepository
$this->repository = $entityManager->getRepository(Scope::class);
}
public function createQueryBuilder($alias, $indexBy = null)
{
return $this->repository->createQueryBuilder($alias, $indexBy);
}
public function find($id, $lockMode = null, $lockVersion = null): ?Scope
{
return $this->repository->find($id, $lockMode, $lockVersion);
}
public function findOneBy(array $criteria, array $orderBy = null): ?Scope
{
return $this->repository->findOneBy($criteria, $orderBy);
}
/**
* @return Scope[]
*/
@@ -37,19 +44,23 @@ final class ScopeRepository implements ObjectRepository
}
/**
* @param mixed|null $limit
* @param mixed|null $offset
*
* @return Scope[]
*/
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
public function createQueryBuilder($alias, $indexBy = null)
public function findOneBy(array $criteria, ?array $orderBy = null): ?Scope
{
return $this->repository->createQueryBuilder($alias, $indexBy);
return $this->repository->findOneBy($criteria, $orderBy);
}
public function getClassName() {
public function getClassName()
{
return Scope::class;
}
}

View File

@@ -1,19 +1,26 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Repository;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\MainBundle\Security\ParentRoleHelper;
use Doctrine\ORM\EntityManagerInterface;
class UserACLAwareRepository implements UserACLAwareRepositoryInterface
{
private ParentRoleHelper $parentRoleHelper;
private EntityManagerInterface $em;
private ParentRoleHelper $parentRoleHelper;
public function __construct(ParentRoleHelper $parentRoleHelper, EntityManagerInterface $em)
{
$this->parentRoleHelper = $parentRoleHelper;
@@ -33,30 +40,26 @@ class UserACLAwareRepository implements UserACLAwareRepositoryInterface
->join('u.groupCenters', 'gc')
->join('gc.permissionsGroup', 'pg')
->join('pg.roleScopes', 'rs')
->where($qb->expr()->in('rs.role', $parents))
;
->where($qb->expr()->in('rs.role', $parents));
if ($onlyEnabled) {
$qb->andWhere($qb->expr()->eq('u.enabled', "'TRUE'"));
}
if (NULL !== $center) {
if (null !== $center) {
$centers = $center instanceof Center ? [$center] : $center;
$qb
->andWhere($qb->expr()->in('gc.center', ':centers'))
->setParameter('centers', $centers)
;
->setParameter('centers', $centers);
}
if (NULL !== $scope) {
if (null !== $scope) {
$scopes = $scope instanceof Scope ? [$scope] : $scope;
$qb
->andWhere($qb->expr()->in('rs.scope', ':scopes'))
->setParameter('scopes', $scopes)
;
->setParameter('scopes', $scopes);
}
return $qb->getQuery()->getResult();
}
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Repository;
use Chill\MainBundle\Entity\Center;
@@ -9,11 +16,10 @@ use Chill\MainBundle\Entity\User;
interface UserACLAwareRepositoryInterface
{
/**
* Find the users reaching the given center and scope, for the given role
* Find the users reaching the given center and scope, for the given role.
*
* @param string $role
* @param Center|Center[]|array $center
* @param Scope|Scope[]|array|null $scope
* @param array|Center|Center[] $center
* @param array|Scope|Scope[]|null $scope
* @param bool $onlyActive true if get only active users
*
* @return User[]

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Repository;
use Chill\MainBundle\Entity\UserJob;
@@ -30,7 +37,10 @@ class UserJobRepository implements ObjectRepository
}
/**
* @return array|UserJob[]|object[]
* @param mixed|null $limit
* @param mixed|null $offset
*
* @return array|object[]|UserJob[]
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null)
{

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Repository;
@@ -13,42 +20,16 @@ use Doctrine\Persistence\ObjectRepository;
final class UserRepository implements ObjectRepository
{
private EntityRepository $repository;
private EntityManagerInterface $entityManager;
private EntityRepository $repository;
public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
$this->repository = $entityManager->getRepository(User::class);
}
public function find($id, $lockMode = null, $lockVersion = null): ?User
{
return $this->repository->find($id, $lockMode, $lockVersion);
}
public function findOneBy(array $criteria, array $orderBy = null): ?User
{
return $this->repository->findOneBy($criteria, $orderBy);
}
/**
* @return User[]
*/
public function findAll(): array
{
return $this->repository->findAll();
}
/**
* @return User[]
*/
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
public function countBy(array $criteria): int
{
return $this->repository->count($criteria);
@@ -59,18 +40,6 @@ final class UserRepository implements ObjectRepository
return $this->countBy(['enabled' => true]);
}
/**
* @return User[]|array
*/
public function findByActive(array $orderBy = null, int $limit = null, int $offset = null): array
{
return $this->findBy(['enabled' => true], $orderBy, $limit, $offset);
}
public function getClassName() {
return User::class;
}
public function countByUsernameOrEmail(string $pattern): int
{
$qb = $this->queryByUsernameOrEmail($pattern);
@@ -80,6 +49,38 @@ final class UserRepository implements ObjectRepository
return (int) $qb->getQuery()->getSingleScalarResult();
}
public function find($id, $lockMode = null, $lockVersion = null): ?User
{
return $this->repository->find($id, $lockMode, $lockVersion);
}
/**
* @return User[]
*/
public function findAll(): array
{
return $this->repository->findAll();
}
/**
* @param mixed|null $limit
* @param mixed|null $offset
*
* @return User[]
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
/**
* @return array|User[]
*/
public function findByActive(?array $orderBy = null, ?int $limit = null, ?int $offset = null): array
{
return $this->findBy(['enabled' => true], $orderBy, $limit, $offset);
}
public function findByUsernameOrEmail(string $pattern)
{
$qb = $this->queryByUsernameOrEmail($pattern);
@@ -87,6 +88,11 @@ final class UserRepository implements ObjectRepository
return $qb->getQuery()->getResult();
}
public function findOneBy(array $criteria, ?array $orderBy = null): ?User
{
return $this->repository->findOneBy($criteria, $orderBy);
}
public function findOneByUsernameOrEmail(string $pattern)
{
$qb = $this->queryByUsernameOrEmail($pattern);
@@ -95,28 +101,29 @@ final class UserRepository implements ObjectRepository
}
/**
* Get the users having a specific flags
* Get the users having a specific flags.
*
* If provided, only the users amongst "filtered users" are searched. This
* allows to make a first search amongst users based on role and center
* and, then filter those users having some flags.
*
* @param \Chill\MainBundle\Entity\User[] $amongstUsers
* @param mixed $flag
*/
public function findUsersHavingFlags($flag, array $amongstUsers = []): array
{
$gcs = $this
->entityManager
->createQuery(
"SELECT DISTINCT gc " .
"FROM ".GroupCenter::class." gc " .
"JOIN gc.permissionsGroup pg " .
"WHERE " .
"JSONB_EXISTS_IN_ARRAY(pg.flags, :flag) = :true "
'SELECT DISTINCT gc ' .
'FROM ' . GroupCenter::class . ' gc ' .
'JOIN gc.permissionsGroup pg ' .
'WHERE ' .
'JSONB_EXISTS_IN_ARRAY(pg.flags, :flag) = :true '
)
->setParameters([
'true' => true,
'flag' => $flag
'flag' => $flag,
])
->getResult();
@@ -132,14 +139,14 @@ final class UserRepository implements ObjectRepository
$orx = $qb->expr()->orX();
foreach($gcs as $i => $gc) {
foreach ($gcs as $i => $gc) {
$orx->add(':gc_' . $i . ' MEMBER OF u.groupCenters');
$qb->setParameter('gc_' . $i, $gc);
}
$qb->andWhere($orx);
if ($amongstUsers !== []) {
if ([] !== $amongstUsers) {
$qb
->andWhere($qb->expr()->in('u', ':amongstUsers'))
->setParameter('amongstUsers', $amongstUsers);
@@ -148,7 +155,12 @@ final class UserRepository implements ObjectRepository
return $qb->getQuery()->getResult();
}
protected function queryByUsernameOrEmail(string $pattern): QueryBuilder
public function getClassName()
{
return User::class;
}
private function queryByUsernameOrEmail(string $pattern): QueryBuilder
{
$qb = $this->entityManager->createQueryBuilder('u');