mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-27 18:13:48 +00:00
rewrite interface and create first tests
This commit is contained in:
@@ -19,18 +19,34 @@
|
||||
|
||||
namespace Chill\MainBundle\Export;
|
||||
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
|
||||
/**
|
||||
* Interface for Aggregators.
|
||||
*
|
||||
* Aggregators gather result of a query. Most of the time, it will add
|
||||
* a GROUP BY clause.
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
interface AggregatorInterface extends ExportElementInterface
|
||||
{
|
||||
public function applyOn();
|
||||
interface AggregatorInterface extends ModifierInterface
|
||||
{
|
||||
/**
|
||||
* give the list of keys the current export added to the queryBuilder in
|
||||
* self::initiateQuery
|
||||
*
|
||||
* Example: if your query builder will contains `SELECT count(id) AS count_id ...`,
|
||||
* this function will return `array('count_id')`.
|
||||
*
|
||||
* @param mixed[] $data the data from the export's form (added by self::buildForm)
|
||||
*/
|
||||
public function getQueryKeys($data);
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder);
|
||||
|
||||
public function alterQuery(QueryBuilder $qb, $data);
|
||||
/**
|
||||
* transform the results to viewable and understable string.
|
||||
*
|
||||
* @param string $key The column key, as added in the query
|
||||
* @param mixed[] $values The values from the result. Each value is unique
|
||||
* @param mixed $data The data from the form
|
||||
*/
|
||||
public function getLabels($key, array $values, $data);
|
||||
|
||||
}
|
||||
|
@@ -19,15 +19,29 @@
|
||||
|
||||
namespace Chill\MainBundle\Export;
|
||||
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
/**
|
||||
* The common methods between different object used to build export (i.e. : ExportInterface,
|
||||
* FilterInterface, AggregatorInterface
|
||||
* FilterInterface, AggregatorInterface)
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
interface ExportElementInterface
|
||||
{
|
||||
public function requiredRole();
|
||||
|
||||
/**
|
||||
* get a title, which will be used in UI (and translated)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle();
|
||||
|
||||
|
||||
/**
|
||||
* Add a form to collect data from the user.
|
||||
*
|
||||
* @param FormBuilderInterface $builder
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder);
|
||||
|
||||
}
|
||||
|
@@ -20,22 +20,42 @@
|
||||
namespace Chill\MainBundle\Export;
|
||||
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
/**
|
||||
* Interface for Export.
|
||||
*
|
||||
* An export is a class which will initiate a query for an export.
|
||||
*
|
||||
* @example Chill\PersonBundle\Export\CountPerson an example of implementation
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
interface ExportInterface extends ExportElementInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Return the Export's type. This will inform _on what_ export will apply.
|
||||
* Most of the type, it will be a string which references an entity.
|
||||
*
|
||||
* Example of types : Chill\PersonBundle\Export\Declarations::PERSON_TYPE
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType();
|
||||
|
||||
/**
|
||||
* A description, which will be used in the UI to explain what the export does.
|
||||
* This description will be translated.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription();
|
||||
|
||||
public function getTitle();
|
||||
|
||||
/**
|
||||
* The initial query, which will be modified by ModifiersInterface
|
||||
* (i.e. AggregatorInterface, FilterInterface).
|
||||
*
|
||||
* This query should take into account the `$acl` and restrict result only to
|
||||
* what the user is allowed to see. (Do not show personal data the user
|
||||
* is not allowed to see).
|
||||
*
|
||||
* @param QueryBuilder $qb
|
||||
* @param array $requiredModifiers
|
||||
@@ -43,14 +63,67 @@ interface ExportInterface extends ExportElementInterface
|
||||
* TODO : we should add ability to receive data from a form
|
||||
*/
|
||||
public function initiateQuery(QueryBuilder $qb, array $requiredModifiers, $acl);
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder);
|
||||
|
||||
|
||||
/**
|
||||
* Return wether this export has a form.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasForm();
|
||||
|
||||
/**
|
||||
* Inform which ModifiersInterface (i.e. AggregatorInterface, FilterInterface)
|
||||
* are allowed. The modifiers should be an array of types the _modifier_ apply on
|
||||
* (@see ModifiersInterface::applyOn()).
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function supportsModifiers();
|
||||
|
||||
/**
|
||||
* Return the required Role to execute the Export.
|
||||
*
|
||||
* @return \Symfony\Component\Security\Core\Role\Role
|
||||
*
|
||||
*/
|
||||
public function requiredRole();
|
||||
|
||||
/**
|
||||
* Return which formatter type is allowed for this report.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getAllowedFormattersTypes();
|
||||
|
||||
/**
|
||||
* give the list of keys the current export added to the queryBuilder in
|
||||
* self::initiateQuery
|
||||
*
|
||||
* Example: if your query builder will contains `SELECT count(id) AS count_id ...`,
|
||||
* this function will return `array('count_id')`.
|
||||
*
|
||||
* @param mixed[] $data the data from the export's form (added by self::buildForm)
|
||||
*/
|
||||
public function getQueryKeys($data);
|
||||
|
||||
/**
|
||||
* Return the results of the query builder.
|
||||
*
|
||||
* @param QueryBuilder $qb
|
||||
* @param mixed[] $data the data from the export's fomr (added by self::buildForm)
|
||||
* @return mixed[] an array of results
|
||||
*/
|
||||
public function getResult(QueryBuilder $qb, $data);
|
||||
|
||||
|
||||
/**
|
||||
* transform the results to viewable and understable string.
|
||||
*
|
||||
* @param string $key The column key, as added in the query
|
||||
* @param mixed[] $values The values from the result. Each value is unique
|
||||
* @param mixed $data The data from the form
|
||||
*/
|
||||
public function getLabels($key, array $values, $data);
|
||||
|
||||
}
|
||||
|
@@ -31,10 +31,11 @@ use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Symfony\Component\Security\Core\Authorization\AuthorizationChecker;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Chill\MainBundle\Form\Type\Export\PickCenterType;
|
||||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
||||
|
||||
/**
|
||||
* Collects all agregators, filters and export from
|
||||
* the installed bundle.
|
||||
* the installed bundle, and performs the export logic.
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
@@ -42,30 +43,35 @@ use Chill\MainBundle\Form\Type\Export\PickCenterType;
|
||||
class ExportManager
|
||||
{
|
||||
/**
|
||||
* The collected filters, injected by DI
|
||||
*
|
||||
* @var FilterInterface[]
|
||||
*/
|
||||
private $filters = array();
|
||||
|
||||
/**
|
||||
* The collected aggregators, injected by DI
|
||||
*
|
||||
* @var AggregatorInterface[]
|
||||
*/
|
||||
private $aggregators = array();
|
||||
|
||||
/**
|
||||
* Collected Exports, injected by DI
|
||||
*
|
||||
* @var ExportInterface[]
|
||||
*/
|
||||
private $exports = array();
|
||||
|
||||
/**
|
||||
* Collected Formatters, injected by DI
|
||||
*
|
||||
* @var FormatterInterface[]
|
||||
*/
|
||||
private $formatters = array();
|
||||
|
||||
/**
|
||||
* a logger
|
||||
*
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
@@ -109,21 +115,53 @@ class ExportManager
|
||||
$this->user = $tokenStorage->getToken()->getUser();
|
||||
}
|
||||
|
||||
/**
|
||||
* add a Filter
|
||||
*
|
||||
* @internal Normally used by the dependency injection
|
||||
*
|
||||
* @param FilterInterface $filter
|
||||
* @param string $alias
|
||||
*/
|
||||
public function addFilter(FilterInterface $filter, $alias)
|
||||
{
|
||||
$this->filters[$alias] = $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* add an aggregator
|
||||
*
|
||||
* @internal used by DI
|
||||
*
|
||||
* @param AggregatorInterface $aggregator
|
||||
* @param string $alias
|
||||
*/
|
||||
public function addAggregator(AggregatorInterface $aggregator, $alias)
|
||||
{
|
||||
$this->aggregators[$alias] = $aggregator;
|
||||
}
|
||||
|
||||
/**
|
||||
* add an export
|
||||
*
|
||||
* @internal used by DI
|
||||
*
|
||||
* @param ExportInterface $export
|
||||
* @param type $alias
|
||||
*/
|
||||
public function addExport(ExportInterface $export, $alias)
|
||||
{
|
||||
$this->exports[$alias] = $export;
|
||||
}
|
||||
|
||||
/**
|
||||
* add a formatter
|
||||
*
|
||||
* @internal used by DI
|
||||
*
|
||||
* @param FormatterInterface $formatter
|
||||
* @param type $alias
|
||||
*/
|
||||
public function addFormatter(FormatterInterface $formatter, $alias)
|
||||
{
|
||||
$this->formatters[$alias] = $formatter;
|
||||
@@ -156,7 +194,7 @@ class ExportManager
|
||||
{
|
||||
foreach ($this->exports as $alias => $export) {
|
||||
if ($whereUserIsGranted) {
|
||||
if ($this->isGrantedForElement($export, null)) {
|
||||
if ($this->isGrantedForElement($export, null, null)) {
|
||||
yield $alias => $export;
|
||||
}
|
||||
} else {
|
||||
@@ -252,15 +290,14 @@ class ExportManager
|
||||
* has access in every centers he can reach (if the user can use the filter F in
|
||||
* center A, but not in center B, the filter F will not be returned)
|
||||
*
|
||||
* @param string[] $types
|
||||
* @param \Chill\MainBundle\Entity\Center[] $centers the centers where the user have access to
|
||||
* @return FilterInterface[] a \Generator that contains filters. The key is the filter's alias
|
||||
*/
|
||||
public function &getFiltersApplyingOn(array $types, array $centers = null)
|
||||
public function &getFiltersApplyingOn(ExportInterface $export, array $centers = null)
|
||||
{
|
||||
foreach ($this->filters as $alias => $filter) {
|
||||
if (in_array($filter->applyOn(), $types)
|
||||
&& $this->isGrantedForElement($filter, $centers)) {
|
||||
if (in_array($filter->applyOn(), $export->supportsModifiers())
|
||||
&& $this->isGrantedForElement($filter, $export, $centers)) {
|
||||
yield $alias => $filter;
|
||||
}
|
||||
}
|
||||
@@ -274,11 +311,28 @@ class ExportManager
|
||||
* @param array|null $centers, if null, the function take into account all the reachables centers for the current user and the role given by element::requiredRole
|
||||
* @return boolean
|
||||
*/
|
||||
public function isGrantedForElement(ExportElementInterface $element, array $centers = null)
|
||||
public function isGrantedForElement(ExportElementInterface $element, ExportInterface $export = NULL, array $centers = null)
|
||||
{
|
||||
if($centers === null) {
|
||||
if ($element instanceof ExportInterface) {
|
||||
$role = $element->requiredRole();
|
||||
} elseif ($element instanceof ModifierInterface ) {
|
||||
if (is_null($element->addRole())) {
|
||||
if (is_null($export)) {
|
||||
throw new \LogicException("The export should not be null: as the "
|
||||
. "ModifierInstance element is not an export, we should "
|
||||
. "be aware of the export to determine which role is required");
|
||||
} else {
|
||||
$role = $export->requiredRole();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new \LogicException("The element is not an ModifiersInterface or "
|
||||
. "an ExportInterface.");
|
||||
}
|
||||
|
||||
if ($centers === null) {
|
||||
$centers = $this->authorizationHelper->getReachableCenters($this->user,
|
||||
$element->requiredRole());
|
||||
$role);
|
||||
}
|
||||
|
||||
if (count($centers) === 0) {
|
||||
@@ -286,8 +340,7 @@ class ExportManager
|
||||
}
|
||||
|
||||
foreach($centers as $center) {
|
||||
if ($this->authorizationChecker->isGranted(
|
||||
$element->requiredRole()->getRole(), $center) === false) {
|
||||
if ($this->authorizationChecker->isGranted($role->getRole(), $center) === false) {
|
||||
//debugging
|
||||
$this->logger->debug('user has no access to element', array(
|
||||
'method' => __METHOD__,
|
||||
@@ -301,32 +354,16 @@ class ExportManager
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a \Generator containing filter which support type
|
||||
*
|
||||
* @param string $types
|
||||
* @return FilterInterface[] a \Generator that contains filters. The key is the filter's alias
|
||||
*/
|
||||
public function &getFiltersSupportingType($type)
|
||||
{
|
||||
foreach ($this->filters as $alias => $filter) {
|
||||
if ($filter->supportsType($type)) {
|
||||
yield $alias => $filter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a \Generator containing aggregators which support type
|
||||
*
|
||||
* @param string[] $types
|
||||
* @return AggregatorInterface[] a \Generator that contains aggretagors. The key is the filter's alias
|
||||
*/
|
||||
public function &getAggregatorsApplyingOn(array $types, array $centers = null)
|
||||
public function &getAggregatorsApplyingOn(ExportInterface $export, array $centers = null)
|
||||
{
|
||||
foreach ($this->aggregators as $alias => $aggregator) {
|
||||
if (in_array($aggregator->applyOn(), $types) &&
|
||||
$this->isGrantedForElement($aggregator, $centers)) {
|
||||
if (in_array($aggregator->applyOn(), $export->supportsModifiers()) &&
|
||||
$this->isGrantedForElement($aggregator, $export, $centers)) {
|
||||
yield $alias => $aggregator;
|
||||
}
|
||||
}
|
||||
@@ -349,10 +386,10 @@ class ExportManager
|
||||
$this->buildCenterReachableScopes($centers, $export));
|
||||
|
||||
//handle filters
|
||||
$this->handleFilters($export, $qb, $data['filters']);
|
||||
$this->handleFilters($export, $qb, $data['filters'], $centers);
|
||||
|
||||
//handle aggregators
|
||||
$this->handleAggregators($export, $qb, $data['aggregators']);
|
||||
$this->handleAggregators($export, $qb, $data['aggregators'], $centers);
|
||||
|
||||
$this->logger->debug('current query is '.$qb->getDQL(), array(
|
||||
'class' => self::class, 'function' => __FUNCTION__
|
||||
@@ -418,6 +455,13 @@ class ExportManager
|
||||
return $data['pick_formatter']['alias'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Center picked by the user for this export. The data are
|
||||
* extracted from the PickCenterType data
|
||||
*
|
||||
* @param array $data the data from a PickCenterType
|
||||
* @return \Chill\MainBundle\Entity\Center[] the picked center
|
||||
*/
|
||||
public function getPickedCenters(array $data)
|
||||
{
|
||||
return $data[PickCenterType::CENTERS_IDENTIFIERS];
|
||||
@@ -442,6 +486,12 @@ class ExportManager
|
||||
return $usedTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the filter used in this export.
|
||||
*
|
||||
* @param mixed $data the data from the `filters` key of the ExportType
|
||||
* @return array an array with types
|
||||
*/
|
||||
private function retrieveUsedFiltersType($data)
|
||||
{
|
||||
$usedTypes = array();
|
||||
@@ -481,7 +531,7 @@ class ExportManager
|
||||
*/
|
||||
private function retrieveUsedAggregators($data)
|
||||
{
|
||||
foreach($data as $alias => $aggregatorData) {
|
||||
foreach ($data as $alias => $aggregatorData) {
|
||||
if ($aggregatorData['enabled'] === true){
|
||||
yield $alias => $this->getAggregator($alias);
|
||||
}
|
||||
@@ -490,43 +540,75 @@ class ExportManager
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ExportInterface $export
|
||||
* @param QueryBuilder $qb
|
||||
* @param mixed $data the data under the initial 'filters' data
|
||||
* @param type $data the data from the filter key of the ExportType
|
||||
*/
|
||||
private function handleFilters(ExportInterface $export, QueryBuilder $qb, $data)
|
||||
private function retrieveUsedFilters($data)
|
||||
{
|
||||
$filters = $this->getFiltersApplyingOn($export->supportsModifiers());
|
||||
|
||||
foreach($filters as $alias => $filter) {
|
||||
$this->logger->debug('handling filter '.$alias, array(
|
||||
'class' => self::class, 'function' => __FUNCTION__
|
||||
));
|
||||
|
||||
$formData = $data[$alias];
|
||||
|
||||
if ($formData['enabled'] == true) {
|
||||
$this->logger->debug('alter query by filter '.$alias, array(
|
||||
'class' => self::class, 'function' => __FUNCTION__
|
||||
));
|
||||
$filter->alterQuery($qb, $formData['form']);
|
||||
} else {
|
||||
$this->logger->debug('skipping filter '.$alias.' because not enabled',
|
||||
array('class' => self::class, 'function' => __FUNCTION__));
|
||||
foreach ($data as $alias => $filterData) {
|
||||
if ($filterData['enabled'] === true) {
|
||||
yield $alias => $this->getFilter($alias);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function handleAggregators(ExportInterface $export, QueryBuilder $qb, $data)
|
||||
/**
|
||||
* alter the query with selected filters.
|
||||
*
|
||||
* This function check the acl.
|
||||
*
|
||||
* @param ExportInterface $export
|
||||
* @param QueryBuilder $qb
|
||||
* @param mixed $data the data under the initial 'filters' data
|
||||
* @param \Chill\MainBundle\Entity\Center[] $centers the picked centers
|
||||
* @throw UnauthorizedHttpException if the user is not authorized
|
||||
*/
|
||||
private function handleFilters(
|
||||
ExportInterface $export,
|
||||
QueryBuilder $qb,
|
||||
$data,
|
||||
array $centers)
|
||||
{
|
||||
$filters = $this->retrieveUsedFilters($data);
|
||||
|
||||
foreach($filters as $alias => $filter) {
|
||||
if ($this->isGrantedForElement($filter, $export, $centers) === false) {
|
||||
throw new UnauthorizedHttpException("You are not authorized to "
|
||||
. "use the filter ".$filter->getTitle());
|
||||
}
|
||||
|
||||
$formData = $data[$alias];
|
||||
|
||||
$this->logger->debug('alter query by filter '.$alias, array(
|
||||
'class' => self::class, 'function' => __FUNCTION__
|
||||
));
|
||||
$filter->alterQuery($qb, $formData['form']);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter the query with selected aggregators
|
||||
*
|
||||
* Check for acl. If an user is not authorized to see an aggregator, throw an
|
||||
* UnauthorizedException.
|
||||
*
|
||||
* @param ExportInterface $export
|
||||
* @param QueryBuilder $qb
|
||||
* @param type $data
|
||||
* @param \Chill\MainBundle\Entity\Center[] $centers the picked centers
|
||||
* @throw UnauthorizedHttpException if the user is not authorized
|
||||
*/
|
||||
private function handleAggregators(
|
||||
ExportInterface $export,
|
||||
QueryBuilder $qb,
|
||||
$data,
|
||||
array $center)
|
||||
{
|
||||
//$aggregators = $this->getAggregatorsApplyingOn($export->supportsModifiers());
|
||||
$aggregators = $this->retrieveUsedAggregators($data);
|
||||
|
||||
foreach ($aggregators as $alias => $aggregator) {
|
||||
$formData = $data[$alias];
|
||||
//if ($formData['order'] >= 0) {
|
||||
$aggregator->alterQuery($qb, $formData['form']);
|
||||
//}
|
||||
$aggregator->alterQuery($qb, $formData['form']);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -19,19 +19,19 @@
|
||||
|
||||
namespace Chill\MainBundle\Export;
|
||||
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
/**
|
||||
* Interface for filters.
|
||||
*
|
||||
* Filter will filter result on the query initiated by Export. Most of the time,
|
||||
* it will add a `WHERE` clause on this query.
|
||||
*
|
||||
* Filters should not add column in `SELECT` clause.
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
interface FilterInterface extends ExportElementInterface
|
||||
interface FilterInterface extends ModifierInterface
|
||||
{
|
||||
public function applyOn();
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder);
|
||||
|
||||
public function alterQuery(QueryBuilder $qb, $data);
|
||||
|
||||
}
|
||||
|
@@ -19,11 +19,41 @@
|
||||
|
||||
namespace Chill\MainBundle\Export;
|
||||
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
interface FormatterInterface
|
||||
{
|
||||
//put your code here
|
||||
const TYPE_TABULAR = 'tabular';
|
||||
|
||||
public function getType();
|
||||
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* build a form, which will be used to collect data required for the execution
|
||||
* of this formatter.
|
||||
*
|
||||
* @uses appendAggregatorForm
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param type $exportAlias
|
||||
* @param array $aggregatorAliases
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, $exportAlias, array $aggregatorAliases);
|
||||
|
||||
/**
|
||||
* Generate a response from the data collected on differents ExportElementInterface
|
||||
*
|
||||
* @param mixed[] $result The result, as given by the ExportInterface
|
||||
* @param mixed[] $data collected from the current form
|
||||
* @param \Chill\MainBundle\Export\ExportInterface $export the export which is executing
|
||||
* @param \Chill\MainBundle\Export\FilterInterface[] $filters the filters applying on the export. The key will be filters aliases, and the values will be filter's data (from their own form)
|
||||
* @param \Chill\MainBundle\Export\AggregatorInterface[] $aggregators the aggregators applying on the export. The key will be aggregators aliases, and the values will be aggregator's data (from their own form)
|
||||
*/
|
||||
public function getResponse($result, $formatterData, $exportAlias, array $exportData, array $filtersData,
|
||||
array $aggregatorsData);
|
||||
|
||||
}
|
||||
|
58
Export/ModifierInterface.php
Normal file
58
Export/ModifierInterface.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2016 Champs-Libres <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/>.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Export;
|
||||
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
|
||||
/**
|
||||
* Modifiers modify the export's query.
|
||||
*
|
||||
* Known subclasses : AggregatorInterface and FilterInterface
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
interface ModifierInterface extends ExportElementInterface
|
||||
{
|
||||
/**
|
||||
* The role required for executing this Modifier
|
||||
*
|
||||
* If null, will used the ExportInterface::requiredRole role from
|
||||
* the current executing export.
|
||||
*
|
||||
* @return NULL|\Symfony\Component\Security\Core\Role\Role A role required to execute this ModifiersInterface
|
||||
*/
|
||||
public function addRole();
|
||||
|
||||
/**
|
||||
* On which type of Export this ModifiersInterface may apply.
|
||||
*
|
||||
* @return string the type on which the Modifiers apply
|
||||
*/
|
||||
public function applyOn();
|
||||
|
||||
/**
|
||||
* Alter the query initiated by the export, to add the required statements
|
||||
* (`GROUP BY`, `SELECT`, `WHERE`)
|
||||
*
|
||||
* @param QueryBuilder $qb the QueryBuilder initiated by the Export (and eventually modified by other Modifiers)
|
||||
* @param mixed[] $data the data from the Form (builded by buildForm)
|
||||
*/
|
||||
public function alterQuery(QueryBuilder $qb, $data);
|
||||
}
|
Reference in New Issue
Block a user