cs: Fix code style (safe rules only).

This commit is contained in:
Pol Dellaiera
2021-11-23 14:06:38 +01:00
parent 149d7ce991
commit 8f96a1121d
1223 changed files with 65199 additions and 64625 deletions

View File

@@ -1,9 +1,10 @@
<?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.
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Widget;
@@ -11,19 +12,18 @@ namespace Chill\PersonBundle\Widget;
use Chill\MainBundle\Templating\Widget\WidgetInterface;
use Twig\Environment;
/**
* Add a button "add a person"
*
* @author julien
* Add a button "add a person".
*/
class AddAPersonWidget implements WidgetInterface
{
public function render(
Environment $env,
$place,
array $context,
array $config) {
return $env->render("ChillPersonBundle:Widget:homepage_add_a_person.html.twig");
}
Environment $env,
$place,
array $context,
array $config
)
{
return $env->render('ChillPersonBundle:Widget:homepage_add_a_person.html.twig');
}
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\PersonBundle\Widget;
@@ -7,17 +14,18 @@ namespace Chill\PersonBundle\Widget;
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
use Chill\MainBundle\Templating\Widget\WidgetInterface;
use Chill\PersonBundle\Repository\PersonRepository;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use DateTime;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query\Expr;
use Doctrine\DBAL\Types\Types;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use RuntimeException;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Symfony\Component\Security\Core\Role\Role;
use Doctrine\ORM\EntityManager;
use Symfony\Component\Security\Core\User\UserInterface;
use Twig\Environment;
use UnexpectedValueException;
use function array_key_exists;
/**
* add a widget with person list.
@@ -29,21 +37,21 @@ use Twig\Environment;
*/
class PersonListWidget implements WidgetInterface
{
protected PersonRepository $personRepository;
protected AuthorizationHelperInterface $authorizationHelper;
protected EntityManagerInterface $entityManager;
protected AuthorizationHelperInterface $authorizationHelper;
protected PersonRepository $personRepository;
protected TokenStorageInterface $tokenStorage;
protected UserInterface $user;
public function __construct(
PersonRepository $personRepostory,
EntityManagerInterface $em,
AuthorizationHelperInterface $authorizationHelper,
TokenStorageInterface $tokenStorage
PersonRepository $personRepostory,
EntityManagerInterface $em,
AuthorizationHelperInterface $authorizationHelper,
TokenStorageInterface $tokenStorage
) {
$this->personRepository = $personRepostory;
$this->authorizationHelper = $authorizationHelper;
@@ -52,26 +60,24 @@ class PersonListWidget implements WidgetInterface
}
/**
* @param array $context
* @param array $config
* @param mixed $place
*/
public function render(Environment $env, $place, array $context, array $config)
{
$numberOfItems = $config['number_of_items'] ?? 20;
$qb = $this->personRepository
->createQueryBuilder('person');
->createQueryBuilder('person');
// show only the person from the authorized centers
$and = $qb->expr()->andX();
$centers = $this->authorizationHelper
->getReachableCenters($this->getUser(), new Role(PersonVoter::SEE));
->getReachableCenters($this->getUser(), new Role(PersonVoter::SEE));
$and->add($qb->expr()->in('person.center', ':centers'));
$qb->setParameter('centers', $centers);
// add the "only active" query
if (\array_key_exists('only_active', $config) && $config['only_active'] === true) {
if (array_key_exists('only_active', $config) && true === $config['only_active']) {
$qb->join('person.accompanyingPeriods', 'ap');
$or = new Expr\Orx();
// add the case where closingDate IS NULL
@@ -81,19 +87,22 @@ class PersonListWidget implements WidgetInterface
$or->add($andWhenClosingDateIsNull);
// add the case when closingDate is in the future
$or->add(
(new Expr())->between(':now', 'ap.openingDate', 'ap.closingDate')
);
(new Expr())->between(':now', 'ap.openingDate', 'ap.closingDate')
);
$and->add($or);
$qb->setParameter('now', new \DateTime(), Types::DATE_MUTABLE);
$qb->setParameter('now', new DateTime(), Types::DATE_MUTABLE);
}
if (array_key_exists('filtering_class', $config) && null !== $config['filtering_class']) {
$filteringClass = new $config['filtering_class']();
if (\array_key_exists('filtering_class', $config) && $config['filtering_class'] !== NULL) {
$filteringClass = new $config['filtering_class'];
if ( ! $filteringClass instanceof PersonListWidget\PersonFilteringInterface) {
throw new \UnexpectedValueException(sprintf("the class %s does not "
. "implements %s", $config['filtering_class'],
PersonListWidget\PersonFilteringInterface::class));
if (!$filteringClass instanceof PersonListWidget\PersonFilteringInterface) {
throw new UnexpectedValueException(sprintf(
'the class %s does not '
. 'implements %s',
$config['filtering_class'],
PersonListWidget\PersonFilteringInterface::class
));
}
$ids = $filteringClass->getPersonIds(
$this->entityManager,
@@ -109,8 +118,7 @@ class PersonListWidget implements WidgetInterface
// ordering the query by lastname, firstname
$qb->addOrderBy('person.lastName', 'ASC')
->addOrderBy('person.firstName', 'ASC');
->addOrderBy('person.firstName', 'ASC');
$qb->setFirstResult(0)->setMaxResults($numberOfItems);
@@ -118,14 +126,15 @@ class PersonListWidget implements WidgetInterface
// get some custom field when the view is overriden and we want to
// show some custom field in the overriden view.
$cfields = array();
$cfields = [];
if (isset($config['custom_fields'])) {
if (count($config['custom_fields']) > 0) {
$cfs = $this->entityManager
->getRepository('ChillCustomFieldsBundle:CustomField')
->findBy(array('slug' => $config['custom_fields']));
->getRepository('ChillCustomFieldsBundle:CustomField')
->findBy(['slug' => $config['custom_fields']]);
// store the custom fields in a array
foreach($cfs as $cf) {
foreach ($cfs as $cf) {
$cfields[$cf->getSlug()] = $cf;
}
}
@@ -133,31 +142,29 @@ class PersonListWidget implements WidgetInterface
return $env->render(
'ChillPersonBundle:Widget:homepage_person_list.html.twig',
array(
[
'persons' => $persons,
'customFields' => $cfields
)
);
'customFields' => $cfields,
]
);
}
private function getUser(): UserInterface
{
$token = $this->tokenStorage->getToken();
if ($token === null) {
throw new \RuntimeException("the token should not be null");
if (null === $token) {
throw new RuntimeException('the token should not be null');
}
$user = $token->getUser();
if ($user === null) {
throw new \RuntimeException(
if (null === $user) {
throw new RuntimeException(
'The user should implement UserInterface. Are you logged in ?'
);
}
return $user;
}
}

View File

@@ -1,34 +1,22 @@
<?php
/*
* Copyright (C) 2016 Champs-Libres Coopérative <info@champs-libres.coop>
/**
* Chill is a software for social workers
*
* 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/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Widget\PersonListWidget;
use Doctrine\ORM\EntityManager;
use Chill\MainBundle\Entity\User;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* Interface to implement on classes called in configuration for
* PersonListWidget (`person_list`), under the key `filtering_class` :
* PersonListWidget (`person_list`), under the key `filtering_class` :.
*
* ```
* widgets:
@@ -37,7 +25,6 @@ use Symfony\Component\Security\Core\User\UserInterface;
* # where \FQDN\To\Class implements PersonFiltering
* class_filtering: \FQDN\To\Class
* ```
*
*/
interface PersonFilteringInterface
{
@@ -57,27 +44,27 @@ interface PersonFilteringInterface
*
* Example of use : filtering based on custom field data :
* ```
class HomepagePersonFiltering implements PersonFilteringInterface {
public function getPersonIds(EntityManager $em, User $user)
{
$rsmBuilder = new ResultSetMappingBuilder($em);
$rsmBuilder->addScalarResult('id', 'id', Types::BIGINT);
$personTable = $em->getClassMetadata('ChillPersonBundle:Person')
->getTableName();
$personIdColumn = $em->getClassMetadata('ChillPersonBundle:Person')
->getColumnName('id');
$personCfDataColumn = $em->getClassMetadata('ChillPersonBundle:Person')
->getColumnName('cfData');
return $em->createNativeQuery(sprintf("SELECT %s FROM %s WHERE "
. "jsonb_exists(%s, 'school-2fb5440e-192c-11e6-b2fd-74d02b0c9b55')",
$personIdColumn, $personTable, $personCfDataColumn), $rsmBuilder)
->getScalarResult();
}
}
*
* class HomepagePersonFiltering implements PersonFilteringInterface {
*
* public function getPersonIds(EntityManager $em, User $user)
* {
* $rsmBuilder = new ResultSetMappingBuilder($em);
* $rsmBuilder->addScalarResult('id', 'id', Types::BIGINT);
*
* $personTable = $em->getClassMetadata('ChillPersonBundle:Person')
* ->getTableName();
* $personIdColumn = $em->getClassMetadata('ChillPersonBundle:Person')
* ->getColumnName('id');
* $personCfDataColumn = $em->getClassMetadata('ChillPersonBundle:Person')
* ->getColumnName('cfData');
*
* return $em->createNativeQuery(sprintf("SELECT %s FROM %s WHERE "
* . "jsonb_exists(%s, 'school-2fb5440e-192c-11e6-b2fd-74d02b0c9b55')",
* $personIdColumn, $personTable, $personCfDataColumn), $rsmBuilder)
* ->getScalarResult();
* }
* }
* ```
*
* @return int[] an array of persons id to show

View File

@@ -1,27 +1,17 @@
<?php
/*
* Copyright (C) 2016 Julien Fastré <julien.fastre@champs-libres.coop>
/**
* Chill is a software for social workers
*
* 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/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Widget;
use Chill\MainBundle\DependencyInjection\Widget\Factory\AbstractWidgetFactory;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* add configuration for the person_list widget.
@@ -31,36 +21,35 @@ class PersonListWidgetFactory extends AbstractWidgetFactory
public function configureOptions($place, NodeBuilder $node)
{
$node->booleanNode('only_active')
->defaultTrue()
->end();
->defaultTrue()
->end();
$node->integerNode('number_of_items')
->defaultValue(50)
->end();
$node->scalarNode('filtering_class')
->defaultNull()
->end();
->defaultNull()
->end();
$node->arrayNode('custom_fields')
->prototype('scalar')->end()
->info("Add some custom field to the view. Add the slug of some custom field"
. " if you want to override the view and show their value in the list")
->example(array("custom-field-slug-1", "custom-field-slug-2"))
->requiresAtLeastOneElement()
->end();
->prototype('scalar')->end()
->info('Add some custom field to the view. Add the slug of some custom field'
. ' if you want to override the view and show their value in the list')
->example(['custom-field-slug-1', 'custom-field-slug-2'])
->requiresAtLeastOneElement()
->end();
}
public function getAllowedPlaces()
{
return array('homepage');
return ['homepage'];
}
public function getWidgetAlias()
{
return 'person_list';
}
public function getServiceId(ContainerBuilder $containerBuilder, $place, $order, array $config)
{
return 'chill_person.widget.person_list';
}
public function getWidgetAlias()
{
return 'person_list';
}
}