Merge branch 'master' of git.framasoft.org:Chill-project/Chill-Person

This commit is contained in:
Marc Ducobu 2016-05-06 16:36:41 +02:00
commit c5bec75d82
2 changed files with 20 additions and 2 deletions

View File

@ -27,6 +27,7 @@ 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\PersonBundle\Export\Declarations;
use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\FormatterInterface;
use Doctrine\ORM\EntityManagerInterface;
/** /**
* *
@ -35,6 +36,19 @@ use Chill\MainBundle\Export\FormatterInterface;
*/ */
class CountPerson implements ExportInterface class CountPerson implements ExportInterface
{ {
/**
*
* @var EntityManagerInterface
*/
protected $entityManager;
public function __construct(
EntityManagerInterface $em
)
{
$this->entityManager = $em;
}
/** /**
* *
*/ */
@ -64,10 +78,12 @@ class CountPerson implements ExportInterface
* @param QueryBuilder $qb * @param QueryBuilder $qb
* @return QueryBuilder * @return QueryBuilder
*/ */
public function initiateQuery(QueryBuilder $qb, array $requiredModifiers, array $acl, array $data = array()) public function initiateQuery(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);
$qb = $this->entityManager->createQueryBuilder();
$qb->select('COUNT(person.id) AS export_result') $qb->select('COUNT(person.id) AS export_result')
->from('ChillPersonBundle:Person', 'person') ->from('ChillPersonBundle:Person', 'person')
->join('person.center', 'center') ->join('person.center', 'center')
@ -79,7 +95,7 @@ class CountPerson implements ExportInterface
return $qb; return $qb;
} }
public function getResult(QueryBuilder $qb, $data) public function getResult($qb, $data)
{ {
return $qb->getQuery()->getResult(Query::HYDRATE_SCALAR); return $qb->getQuery()->getResult(Query::HYDRATE_SCALAR);
} }

View File

@ -72,6 +72,8 @@ services:
chill.person.export.export_count_person: chill.person.export.export_count_person:
class: Chill\PersonBundle\Export\Export\CountPerson class: Chill\PersonBundle\Export\Export\CountPerson
arguments:
- "@doctrine.orm.entity_manager"
tags: tags:
- { name: chill.export, alias: count_person } - { name: chill.export, alias: count_person }