Fix syntax errors.

This commit is contained in:
Pol Dellaiera 2021-05-07 19:53:13 +02:00
parent c5b8b6345d
commit ce4cbe3b8d
3 changed files with 36 additions and 33 deletions

View File

@ -14,7 +14,7 @@ use Chill\MainBundle\Export\FormatterInterface;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
/** /**
* *
* *
* @author Julien Fastré <julien.fastre@champs-libres.coop> * @author Julien Fastré <julien.fastre@champs-libres.coop>
*/ */
@ -25,94 +25,95 @@ class CountPerson implements ExportInterface
* @var EntityManagerInterface * @var EntityManagerInterface
*/ */
protected $entityManager; protected $entityManager;
public function __construct( public function __construct(
EntityManagerInterface $em EntityManagerInterface $em
) )
{ {
$this->entityManager = $em; $this->entityManager = $em;
} }
public function getType() public function getType()
{ {
return Declarations::PERSON_TYPE; return Declarations::PERSON_TYPE;
} }
public function getDescription() public function getDescription()
{ {
return "Count peoples by various parameters."; return "Count peoples by various parameters.";
} }
public function getTitle() public function getTitle()
{ {
return "Count peoples"; return "Count peoples";
} }
public function requiredRole() public function requiredRole()
{ {
return new Role(PersonVoter::STATS); return new Role(PersonVoter::STATS);
} }
public function initiateQuery(array $requiredModifiers, array $acl, array $data = array()) public function initiateQuery(array $requiredModifiers, array $acl, array $data = array())
{ {
// we gather all center the user choose. // we gather all center the user choose.
$centers = array_map(function($el) { return $el['center']; }, $acl); $centers = array_map(function($el) { return $el['center']; }, $acl);
$qb = $this->entityManager->createQueryBuilder(); $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')
->andWhere('center IN (:authorized_centers)') ->andWhere('center IN (:authorized_centers)')
->setParameter('authorized_centers', $centers); ->setParameter('authorized_centers', $centers);
; ;
return $qb; return $qb;
} }
public function getResult($qb, $data) public function getResult($qb, $data)
{ {
return $qb->getQuery()->getResult(Query::HYDRATE_SCALAR); return $qb->getQuery()->getResult(Query::HYDRATE_SCALAR);
} }
public function getQueryKeys($data) public function getQueryKeys($data)
{ {
// this array match the result keys in the query. We have only // this array match the result keys in the query. We have only
// one column. // one column.
return array('export_result'); return array('export_result');
} }
public function getLabels($key, array $values, $data) public function getLabels($key, array $values, $data)
{ {
// the Closure which will be executed by the formatter. // the Closure which will be executed by the formatter.
return function($value) { return function($value) {
switch($value) { switch($value) {
case '_header': case '_header':
// we have to process specifically the '_header' string, // we have to process specifically the '_header' string,
// which will be used by the formatter to show a column title // which will be used by the formatter to show a column title
return $this->getTitle(); return $this->getTitle();
default: default:
// for all value, we do not process them and return them // for all value, we do not process them and return them
// immediatly // immediatly
return $value; return $value;
};
}; };
} }
public function getAllowedFormattersTypes() public function getAllowedFormattersTypes()
{ {
return array(FormatterInterface::TYPE_TABULAR); return array(FormatterInterface::TYPE_TABULAR);
} }
public function buildForm(FormBuilderInterface $builder) { public function buildForm(FormBuilderInterface $builder) {
// this export does not add any form // this export does not add any form
} }
public function supportsModifiers() public function supportsModifiers()
{ {
// explain the export manager which formatters and filters are allowed // explain the export manager which formatters and filters are allowed
return array(Declarations::PERSON_TYPE, Declarations::PERSON_IMPLIED_IN); return array(Declarations::PERSON_TYPE, Declarations::PERSON_IMPLIED_IN);
} }
} }

View File

@ -8,21 +8,21 @@ use Symfony\Component\HttpFoundation\Request;
class ItemController extends Controller { class ItemController extends Controller {
public function yourAction() public function yourAction()
{ {
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
// first, get the number of total item are available // first, get the number of total item are available
$total = $em $total = $em
->createQuery("SELECT COUNT (item.id) FROM ChillMyBundle:Item item") ->createQuery("SELECT COUNT (item.id) FROM ChillMyBundle:Item item")
->getSingleScalarResult(); ->getSingleScalarResult();
// get the PaginatorFactory // get the PaginatorFactory
$paginatorFactory = $this->get('chill_main.paginator_factory'); $paginatorFactory = $this->get('chill_main.paginator_factory');
// create a pagination instance. This instance is only valid for // create a pagination instance. This instance is only valid for
// the current route and parameters // the current route and parameters
$paginator = $paginatorFactory->create($total); $paginator = $paginatorFactory->create($total);
// launch your query on item. Limit the query to the results // launch your query on item. Limit the query to the results
// for the current page using the paginator // for the current page using the paginator
$items = $em->createQuery("SELECT item FROM ChillMyBundle:Item item WHERE <your clause>") $items = $em->createQuery("SELECT item FROM ChillMyBundle:Item item WHERE <your clause>")
@ -30,12 +30,15 @@ class ItemController extends Controller {
->setFirstResult($paginator->getCurrentPage()->getFirstItemNumber()) ->setFirstResult($paginator->getCurrentPage()->getFirstItemNumber())
// use the paginator to get the number of items to display // use the paginator to get the number of items to display
->setMaxResults($paginator->getItemsPerPage()); ->setMaxResults($paginator->getItemsPerPage());
return $this->render('ChillMyBundle:Item:list.html.twig', array( return $this
'items' => $items, ->render(
'paginator' => $paginator 'ChillMyBundle:Item:list.html.twig',
); array(
'items' => $items,
'paginator' => $paginator
)
);
} }
} }

View File

@ -25,7 +25,6 @@ class ThirdPartyTypeManager
* Method used during the load of the manager by Dependency Injection * Method used during the load of the manager by Dependency Injection
* *
* @param \Chill\ThirdPartyBundle\ThirdPartyType\ThirdPartyTypeProviderInterface $provider * @param \Chill\ThirdPartyBundle\ThirdPartyType\ThirdPartyTypeProviderInterface $provider
* @return \self
*/ */
public function addProvider(ThirdPartyTypeProviderInterface $provider): self public function addProvider(ThirdPartyTypeProviderInterface $provider): self
{ {