wip.. setting acl for new accompanying course exports

This commit is contained in:
Mathieu Jaumotte 2022-07-12 16:41:12 +02:00
parent ec38dc4d21
commit 2ce145cace
4 changed files with 61 additions and 17 deletions

View File

@ -12,56 +12,93 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Export;
use Chill\MainBundle\Export\ExportInterface;
use Chill\MainBundle\Export\FormatterInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Security\Core\Role\Role;
use LogicException;
class CountAccompanyingCourse implements ExportInterface
{
/**
* @var EntityManagerInterface
*/
protected $entityManager;
public function buildForm(FormBuilderInterface $builder)
public function __construct(
EntityManagerInterface $em
) {
$this->entityManager = $em;
}
public function buildForm(FormBuilderInterface $builder): void
{
// TODO: Implement buildForm() method.
}
public function getTitle()
public function getTitle(): string
{
return 'Count accompanying courses';
}
public function getAllowedFormattersTypes()
public function getAllowedFormattersTypes(): array
{
// TODO: Implement getAllowedFormattersTypes() method.
return [FormatterInterface::TYPE_TABULAR];
}
public function getDescription()
public function getDescription(): string
{
return 'Count accompanying courses by various parameters';
}
public function getLabels($key, array $values, $data)
{
// TODO: Implement getLabels() method.
if ('export_result' !== $key) {
throw new LogicException("the key {$key} is not used by this export");
}
$labels = array_combine($values, $values);
$labels['_header'] = $this->getTitle();
return static function ($value) use ($labels) {
return $labels[$value];
};
}
public function getQueryKeys($data)
public function getQueryKeys($data): array
{
// TODO: Implement getQueryKeys() method.
return ['export_result'];
}
public function getResult($query, $data)
public function getResult($qb, $data)
{
// TODO: Implement getResult() method.
return $qb->getQuery()->getResult(Query::HYDRATE_SCALAR);
}
public function getType()
public function getType(): string
{
// TODO: Implement getType() method.
return 'accompanying_period';
}
public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
public function initiateQuery(array $requiredModifiers, array $acl, array $data = []): QueryBuilder
{
// TODO: Implement initiateQuery() method.
$centers = array_map(static function ($el) {
return $el['center'];
}, $acl);
$qb = $this->entityManager->createQueryBuilder();
$qb->select('COUNT(acp.id) AS export_result')
->from('ChillPersonBundle:AccompanyingPeriod', 'acp')
->join('acp.center', 'center')
->andWhere('center IN (:authorized_centers)')
->setParameter('authorized_centers', $centers);
return $qb;
}
public function requiredRole(): Role
@ -69,8 +106,8 @@ class CountAccompanyingCourse implements ExportInterface
return new Role(AccompanyingPeriodVoter::STATS);
}
public function supportsModifiers()
public function supportsModifiers(): array
{
// TODO: Implement supportsModifiers() method.
return [];
}
}

View File

@ -219,6 +219,11 @@ class AccompanyingPeriodVoter extends AbstractChillVoter implements ProvideRoleH
return $token->getUser() === $subject->getUser();
}
if (self::STATS === $attribute) {
return true;
}
}
return $this->voterHelper->voteOnAttribute($attribute, $subject, $token);

View File

@ -26,9 +26,10 @@ services:
tags:
- { name: chill.export, alias: list_person_duplicate }
chill.person.export.export_count_accompanying_course:
chill.person.export.count_accompanying_course:
class: Chill\PersonBundle\Export\Export\CountAccompanyingCourse
arguments:
- "@doctrine.orm.entity_manager"
tags:
- { name: chill.export, alias: count_accompanying_course }

View File

@ -315,6 +315,7 @@ CHILL_PERSON_ACCOMPANYING_PERIOD_UPDATE: Modifier une période d'accompagnement
CHILL_PERSON_ACCOMPANYING_PERIOD_FULL: Voir les détails, créer, supprimer et mettre à jour une période d'accompagnement
CHILL_PERSON_ACCOMPANYING_COURSE_REASSIGN_BULK: Réassigner les parcours en lot
CHILL_PERSON_ACCOMPANYING_PERIOD_SEE_DETAILS: Voir les détails d'une période d'accompagnement
CHILL_PERSON_ACCOMPANYING_PERIOD_STATS: Statistiques sur les parcours d'accompagnement
#period
Period closed!: Période clôturée!