crudification + corrections on thirdparty

This commit is contained in:
2021-10-04 18:25:49 +02:00
parent cc7e38194f
commit 05b9476a71
16 changed files with 313 additions and 212 deletions

View File

@@ -2,22 +2,52 @@
namespace Chill\ThirdPartyBundle\Repository;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Security\Core\Security;
/**
* @Author Mathieu Jaumotte mathieu.jaumotte@champs-libres.coop
*/
class ThirdPartyACLAwareRepository implements ThirdPartyACLAwareRepositoryInterface
final class ThirdPartyACLAwareRepository implements ThirdPartyACLAwareRepositoryInterface
{
private Security $security;
private AuthorizationHelper $authorizationHelper;
private ThirdPartyRepository $thirdPartyRepository;
public function findByThirdparty(
ThirdParty $thirdparty,
string $role,
?array $orderBy = [],
int $limit = null,
int $offset = null
public function __construct(Security $security, AuthorizationHelper $authorizationHelper, ThirdPartyRepository $thirdPartyRepository)
{
$this->security = $security;
$this->authorizationHelper = $authorizationHelper;
$this->thirdPartyRepository = $thirdPartyRepository;
}
public function listThirdParties(
string $role,
?array $orderBy = [],
?int $limit = null,
?int $offset = null
): array {
$qb = $this->buildQuery($role);
// TODO: Implement findByThirdparty() method.
foreach ($orderBy as $sort => $direction) {
$qb->addOrderBy('tp.'.$sort, $direction);
}
$qb->setFirstResult($offset)
->setMaxResults($limit);
return $qb->getQuery()->getResult();
}
public function countThirdParties(
string $role
): int {
$qb = $this->buildQuery($role);
$qb->select('count(tp)');
return $qb->getQuery()->getSingleScalarResult();
}
public function buildQuery(): QueryBuilder {
return $this->thirdPartyRepository->createQueryBuilder('tp');
}
}