Merge remote-tracking branch 'framagit-julien/export' into export

This commit is contained in:
Julien Fastré 2016-04-15 23:25:13 +02:00
commit 4efbfd4bfc
6 changed files with 49 additions and 21 deletions

View File

@ -24,8 +24,7 @@ use Symfony\Component\Form\FormBuilderInterface;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Translation\TranslatorInterface; use Symfony\Component\Translation\TranslatorInterface;
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Security\Authorization\PersonVoter; use Chill\PersonBundle\Export\Declarations;
use Symfony\Component\Security\Core\Role\Role;
/** /**
* *
@ -48,7 +47,7 @@ class GenderAggregator implements AggregatorInterface
public function applyOn() public function applyOn()
{ {
return 'person'; return Declarations::PERSON_TYPE;
} }
@ -85,9 +84,9 @@ class GenderAggregator implements AggregatorInterface
); );
} }
public function requiredRole() public function addRole()
{ {
return new Role(PersonVoter::STATS); return NULL;
} }
} }

View File

@ -125,9 +125,9 @@ class NationalityAggregator implements AggregatorInterface
return array('nationality_aggregator'); return array('nationality_aggregator');
} }
public function requiredRole() public function addRole()
{ {
return new Role(PersonVoter::STATS); return NULL;
} }
public function getLabels($key, array $values, $data) public function getLabels($key, array $values, $data)

31
Export/Declarations.php Normal file
View File

@ -0,0 +1,31 @@
<?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\PersonBundle\Export;
/**
* This class declare constants used for the export framework.
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
abstract class Declarations
{
CONST PERSON_TYPE = 'person';
}

View File

@ -25,6 +25,8 @@ use Symfony\Component\Form\FormBuilderInterface;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Chill\PersonBundle\Security\Authorization\PersonVoter; use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Symfony\Component\Security\Core\Role\Role; use Symfony\Component\Security\Core\Role\Role;
use Chill\PersonBundle\Export\Declarations;
use Chill\MainBundle\Export\FormatterInterface;
/** /**
* *
@ -38,7 +40,7 @@ class CountPerson implements ExportInterface
*/ */
public function getType() public function getType()
{ {
return 'person'; return Declarations::PERSON_TYPE;
} }
public function getDescription() public function getDescription()
@ -62,7 +64,7 @@ class CountPerson implements ExportInterface
* @param QueryBuilder $qb * @param QueryBuilder $qb
* @return QueryBuilder * @return QueryBuilder
*/ */
public function initiateQuery(QueryBuilder $qb, array $requiredModifiers, $acl) public function initiateQuery(QueryBuilder $qb, array $requiredModifiers, array $acl, array $data = array())
{ {
$centers = array_map(function($el) { return $el['center']; }, $acl); $centers = array_map(function($el) { return $el['center']; }, $acl);
@ -77,7 +79,7 @@ class CountPerson implements ExportInterface
return $qb; return $qb;
} }
public function getResult($qb, $data) public function getResult(QueryBuilder $qb, $data)
{ {
return $qb->getQuery()->getResult(Query::HYDRATE_SCALAR); return $qb->getQuery()->getResult(Query::HYDRATE_SCALAR);
} }
@ -101,20 +103,16 @@ class CountPerson implements ExportInterface
public function getAllowedFormattersTypes() public function getAllowedFormattersTypes()
{ {
return array('tabular'); return array(FormatterInterface::TYPE_TABULAR);
} }
public function buildForm(FormBuilderInterface $builder) { public function buildForm(FormBuilderInterface $builder) {
throw new \LogicException('This export does not require a form');
}
public function hasForm(){
return false;
} }
public function supportsModifiers() public function supportsModifiers()
{ {
return array('person'); return array(Declarations::PERSON_TYPE);
} }
} }

View File

@ -80,8 +80,8 @@ class GenderFilter implements FilterInterface
return 'Filter by person gender'; return 'Filter by person gender';
} }
public function requiredRole() public function addRole()
{ {
return new Role(\Chill\PersonBundle\Security\Authorization\PersonVoter::STATS); return NULL;
} }
} }

View File

@ -65,8 +65,8 @@ class NationalityFilter implements FilterInterface
return "Filter by person's nationality"; return "Filter by person's nationality";
} }
public function requiredRole() public function addRole()
{ {
return new Role(\Chill\PersonBundle\Security\Authorization\PersonVoter::STATS); return NULL;
} }
} }