wip.. setting acl for new accompanying course exports

This commit is contained in:
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 [];
}
}