Commit 84c22fcf authored by Julien Fastré's avatar Julien Fastré
Browse files

add list for exports

parent 9c87db15
Pipeline #57409 failed with stages
in 43 seconds
......@@ -28,6 +28,7 @@ class ChillReportExtension extends Extension implements PrependExtensionInterfac
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
$loader->load('services/fixtures.yml');
$loader->load('services/export.yml');
}
/**
......
This diff is collapsed.
<?php
/*
*/
namespace Chill\ReportBundle\Export\Export;
use Doctrine\ORM\EntityManagerInterface;
use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\ReportBundle\Entity\Report;
use Chill\MainBundle\Export\ExportElementsProviderInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Chill\CustomFieldsBundle\Service\CustomFieldProvider;
/**
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class ReportListProvider implements ExportElementsProviderInterface
{
/**
*
* @var EntityManagerInterface
*/
protected $em;
/**
*
* @var TranslatableStringHelper
*/
protected $translatableStringHelper;
/**
*
* @var CustomFieldProvider
*/
protected $customFieldProvider;
/**
*
* @var TranslatorInterface
*/
protected $translator;
function __construct(
EntityManagerInterface $em,
TranslatableStringHelper $translatableStringHelper,
TranslatorInterface $translator,
CustomFieldProvider $customFieldProvider
) {
$this->em = $em;
$this->translatableStringHelper = $translatableStringHelper;
$this->translator = $translator;
$this->customFieldProvider = $customFieldProvider;
}
public function getExportElements()
{
$groups = $this->em->getRepository(CustomFieldsGroup::class)
->findBy([ 'entity' => Report::class ])
;
$reports = [];
foreach ($groups as $group) {
$reports[$group->getId()] = new ReportList(
$group,
$this->translatableStringHelper,
$this->translator,
$this->customFieldProvider,
$this->em);
}
return $reports;
}
}
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace Chill\ReportBundle\Export\Filter;
use Chill\MainBundle\Export\FilterInterface;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Doctrine\ORM\Query\Expr;
use Chill\MainBundle\Form\Type\ChillDateType;
/**
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class ReportDateFilter implements FilterInterface
{
public function addRole()
{
return null;
}
public function alterQuery(\Doctrine\ORM\QueryBuilder $qb, $data)
{
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->between('report.date', ':report_date_filter_date_from',
':report_date_filter_date_to');
if ($where instanceof Expr\Andx) {
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
$qb->setParameter('report_date_filter_date_from', $data['date_from']);
$qb->setParameter('report_date_filter_date_to', $data['date_to']);
}
public function applyOn()
{
return 'report';
}
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder)
{
$builder->add('date_from', ChillDateType::class, array(
'label' => "Report is after this date",
'data' => new \DateTime(),
));
$builder->add('date_to', ChillDateType::class, array(
'label' => "Report is before this date",
'data' => new \DateTime(),
));
}
public function describeAction($data, $format = 'string')
{
return array('Filtered by report\'s date: '
. 'between %date_from% and %date_to%', array(
'%date_from%' => $data['date_from']->format('d-m-Y'),
'%date_to%' => $data['date_to']->format('d-m-Y')
));
}
public function getTitle()
{
return 'Filter by report\'s date';
}
}
services:
Chill\ReportBundle\Export\Export\ReportListProvider:
arguments:
$em: '@Doctrine\ORM\EntityManagerInterface'
$translatableStringHelper: '@Chill\MainBundle\Templating\TranslatableStringHelper'
$translator: '@Symfony\Component\Translation\TranslatorInterface'
$customFieldProvider: '@Chill\CustomFieldsBundle\Service\CustomFieldProvider'
tags:
- { name: chill.export_elements_provider, prefix: 'report' }
Chill\ReportBundle\Export\Filter\ReportDateFilter:
tags:
- { name: chill.export_filter, alias: 'report_date' }
......@@ -43,4 +43,12 @@ No report registered for this person.: Aucun rapport pour cette personne.
#roles
CHILL_REPORT_UPDATE: Modifier les rapports
CHILL_REPORT_SEE: Voir les rapports
CHILL_REPORT_CREATE: Créer des rapports
\ No newline at end of file
CHILL_REPORT_CREATE: Créer des rapports
#exports
"List for report '%type%'": Liste des rapports "%type%"
"Generate list of report '%type%'": Génère une liste des rapports "%type%"
"Report's question": Question du rapport
Filter by report's date: Filtrer par date de rapport
Report is after this date: Rapports après cette date
Report is before this date: Rapports avant cette date
\ No newline at end of file
......@@ -26,6 +26,7 @@ use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\MainBundle\Security\ProvideRoleHierarchyInterface;
use Chill\ReportBundle\Entity\Report;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\Center;
/**
......@@ -38,6 +39,7 @@ class ReportVoter extends AbstractChillVoter implements ProvideRoleHierarchyInte
const CREATE = 'CHILL_REPORT_CREATE';
const SEE = 'CHILL_REPORT_SEE';
const UPDATE = 'CHILL_REPORT_UPDATE';
const LISTS = 'CHILL_REPORT_LISTS';
/**
*
......@@ -58,8 +60,8 @@ class ReportVoter extends AbstractChillVoter implements ProvideRoleHierarchyInte
return \in_array($attribute, [
self::CREATE, self::UPDATE, self::SEE
]);
} else {
return false;
} elseif ($subject instanceof Center) {
return $attribute === self::LISTS;
}
}
......@@ -75,12 +77,12 @@ class ReportVoter extends AbstractChillVoter implements ProvideRoleHierarchyInte
public function getRoles()
{
return [self::CREATE, self::UPDATE, self::SEE];
return [self::CREATE, self::UPDATE, self::SEE, self::LISTS];
}
public function getRolesWithoutScope()
{
return array();
return array(self::LISTS);
}
public function getRolesWithHierarchy()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment