mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,59 +1,42 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2017 Champs Libres Cooperative <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\MainBundle\Form;
|
||||
|
||||
use Chill\MainBundle\Search\SearchProvider;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Chill\MainBundle\Search\SearchProvider;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class AdvancedSearchType extends AbstractType
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var SearchProvider
|
||||
*/
|
||||
protected $searchProvider;
|
||||
|
||||
|
||||
public function __construct(SearchProvider $searchProvider)
|
||||
{
|
||||
$this->searchProvider = $searchProvider;
|
||||
}
|
||||
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$this->searchProvider
|
||||
->getHasAdvancedFormByName($options['search_service'])
|
||||
->createSearchForm($builder)
|
||||
;
|
||||
->createSearchForm($builder);
|
||||
}
|
||||
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver
|
||||
->setRequired('search_service')
|
||||
->setAllowedTypes('search_service', [ 'string' ])
|
||||
;
|
||||
->setAllowedTypes('search_service', ['string']);
|
||||
}
|
||||
}
|
||||
|
@@ -1,23 +1,25 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
|
||||
class CenterType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param array $options
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('name', TextType::class)
|
||||
;
|
||||
->add('name', TextType::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -25,17 +27,16 @@ class CenterType extends AbstractType
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'Chill\MainBundle\Entity\Center'
|
||||
));
|
||||
$resolver->setDefaults([
|
||||
'data_class' => 'Chill\MainBundle\Entity\Center',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getBlockPrefix()
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'chill_mainbundle_center';
|
||||
}
|
||||
|
||||
return 'chill_mainbundle_center';
|
||||
}
|
||||
}
|
||||
|
@@ -1,82 +1,66 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2018 Champs-Libres <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\MainBundle\Form\ChoiceLoader;
|
||||
|
||||
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
|
||||
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
|
||||
use Chill\MainBundle\Repository\PostalCodeRepository;
|
||||
use Chill\MainBundle\Entity\PostalCode;
|
||||
use Chill\MainBundle\Repository\PostalCodeRepository;
|
||||
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
|
||||
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
|
||||
use function call_user_func;
|
||||
|
||||
/**
|
||||
* Class PostalCodeChoiceLoader
|
||||
*
|
||||
* @package Chill\MainBundle\Form\ChoiceLoader
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* Class PostalCodeChoiceLoader.
|
||||
*/
|
||||
class PostalCodeChoiceLoader implements ChoiceLoaderInterface
|
||||
{
|
||||
/**
|
||||
* @var PostalCodeRepository
|
||||
*/
|
||||
protected $postalCodeRepository;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $lazyLoadedPostalCodes = [];
|
||||
|
||||
|
||||
/**
|
||||
* @var PostalCodeRepository
|
||||
*/
|
||||
protected $postalCodeRepository;
|
||||
|
||||
/**
|
||||
* PostalCodeChoiceLoader constructor.
|
||||
*
|
||||
* @param PostalCodeRepository $postalCodeRepository
|
||||
*/
|
||||
public function __construct(PostalCodeRepository $postalCodeRepository)
|
||||
{
|
||||
$this->postalCodeRepository = $postalCodeRepository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param null $value
|
||||
* @return ChoiceListInterface
|
||||
*/
|
||||
public function loadChoiceList($value = null): ChoiceListInterface
|
||||
{
|
||||
$list = new \Symfony\Component\Form\ChoiceList\ArrayChoiceList(
|
||||
$this->lazyLoadedPostalCodes,
|
||||
function(PostalCode $pc = null) use ($value) {
|
||||
return \call_user_func($value, $pc);
|
||||
});
|
||||
|
||||
return $list;
|
||||
return new \Symfony\Component\Form\ChoiceList\ArrayChoiceList(
|
||||
$this->lazyLoadedPostalCodes,
|
||||
function (?PostalCode $pc = null) use ($value) {
|
||||
return call_user_func($value, $pc);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $values
|
||||
* @param null $value
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function loadChoicesForValues(array $values, $value = null)
|
||||
{
|
||||
$choices = [];
|
||||
|
||||
foreach($values as $value) {
|
||||
|
||||
foreach ($values as $value) {
|
||||
if (empty($value)) {
|
||||
$choices[] = null;
|
||||
} else {
|
||||
@@ -86,27 +70,28 @@ class PostalCodeChoiceLoader implements ChoiceLoaderInterface
|
||||
|
||||
return $choices;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $choices
|
||||
* @param null $value
|
||||
*
|
||||
* @return array|string[]
|
||||
*/
|
||||
public function loadValuesForChoices(array $choices, $value = null)
|
||||
{
|
||||
$values = [];
|
||||
|
||||
|
||||
foreach ($choices as $choice) {
|
||||
if (NULL === $choice) {
|
||||
if (null === $choice) {
|
||||
$values[] = null;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$id = \call_user_func($value, $choice);
|
||||
|
||||
$id = call_user_func($value, $choice);
|
||||
$values[] = $id;
|
||||
$this->lazyLoadedPostalCodes[$id] = $choice;
|
||||
}
|
||||
|
||||
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
|
@@ -1,68 +1,70 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2019 Champs Libres Cooperative <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\MainBundle\Form\DataMapper;
|
||||
|
||||
use Symfony\Component\Form\DataMapperInterface;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Chill\MainBundle\Entity\PostalCode;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Iterator;
|
||||
use Symfony\Component\Form\DataMapperInterface;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
|
||||
/**
|
||||
* Add a data mapper to Address.
|
||||
*
|
||||
*
|
||||
* If the address is incomplete, the data mapper returns null
|
||||
*/
|
||||
class AddressDataMapper implements DataMapperInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @param Address $address
|
||||
* @param \Iterator $forms
|
||||
* @param Iterator $forms
|
||||
*/
|
||||
public function mapDataToForms($address, $forms)
|
||||
{
|
||||
if (NULL === $address) {
|
||||
if (null === $address) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!$address instanceof Address) {
|
||||
throw new UnexpectedTypeException($address, Address::class);
|
||||
}
|
||||
|
||||
|
||||
foreach ($forms as $key => $form) {
|
||||
/** @var FormInterface $form */
|
||||
switch ($key) {
|
||||
case 'streetAddress1':
|
||||
$form->setData($address->getStreetAddress1());
|
||||
|
||||
break;
|
||||
|
||||
case 'streetAddress2':
|
||||
$form->setData($address->getStreetAddress2());
|
||||
|
||||
break;
|
||||
|
||||
case 'postCode':
|
||||
$form->setData($address->getPostcode());
|
||||
|
||||
break;
|
||||
|
||||
case 'validFrom':
|
||||
$form->setData($address->getValidFrom());
|
||||
|
||||
break;
|
||||
|
||||
case 'isNoAddress':
|
||||
$form->setData($address->isNoAddress());
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -70,8 +72,7 @@ class AddressDataMapper implements DataMapperInterface
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param \Iterator $forms
|
||||
* @param Iterator $forms
|
||||
* @param Address $address
|
||||
*/
|
||||
public function mapFormsToData($forms, &$address)
|
||||
@@ -79,40 +80,53 @@ class AddressDataMapper implements DataMapperInterface
|
||||
if (!$address instanceof Address) {
|
||||
$address = new Address();
|
||||
}
|
||||
|
||||
|
||||
$isNoAddress = false;
|
||||
|
||||
foreach ($forms as $key => $form) {
|
||||
if ($key === 'isNoAddress') {
|
||||
if ('isNoAddress' === $key) {
|
||||
$isNoAddress = $form->get('isNoAddress')->getData();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach ($forms as $key => $form) {
|
||||
/** @var FormInterface $form */
|
||||
switch($key) {
|
||||
switch ($key) {
|
||||
case 'postCode':
|
||||
if (!$form->getData() instanceof PostalCode && !$isNoAddress) {
|
||||
$address = null;
|
||||
|
||||
return;
|
||||
}
|
||||
$address->setPostcode($form->getData());
|
||||
|
||||
break;
|
||||
|
||||
case 'streetAddress1':
|
||||
if (empty($form->getData()) && !$isNoAddress) {
|
||||
$address = null;
|
||||
|
||||
return;
|
||||
}
|
||||
$address->setStreetAddress1($form->getData());
|
||||
|
||||
break;
|
||||
|
||||
case 'streetAddress2':
|
||||
$address->setStreetAddress2($form->getData());
|
||||
|
||||
break;
|
||||
|
||||
case 'validFrom':
|
||||
$address->setValidFrom($form->getData());
|
||||
|
||||
break;
|
||||
|
||||
case 'isNoAddress':
|
||||
$address->setIsNoAddress($form->getData());
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@@ -1,10 +1,16 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Form\DataMapper;
|
||||
|
||||
use Chill\MainBundle\Entity\Scope;
|
||||
use Symfony\Component\Form\DataMapperInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
|
||||
class ScopePickerDataMapper implements DataMapperInterface
|
||||
{
|
||||
@@ -13,7 +19,7 @@ class ScopePickerDataMapper implements DataMapperInterface
|
||||
*/
|
||||
private $scope;
|
||||
|
||||
public function __construct(Scope $scope = null)
|
||||
public function __construct(?Scope $scope = null)
|
||||
{
|
||||
$this->scope = $scope;
|
||||
}
|
||||
@@ -24,6 +30,7 @@ class ScopePickerDataMapper implements DataMapperInterface
|
||||
|
||||
if ($this->scope instanceof Scope) {
|
||||
$forms['scope']->setData($this->scope);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -1,36 +1,37 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Form\Event;
|
||||
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
class CustomizeFormEvent extends \Symfony\Component\EventDispatcher\Event
|
||||
{
|
||||
const NAME = 'chill_main.customize_form';
|
||||
|
||||
protected string $type;
|
||||
public const NAME = 'chill_main.customize_form';
|
||||
|
||||
protected FormBuilderInterface $builder;
|
||||
|
||||
protected string $type;
|
||||
|
||||
public function __construct(string $type, FormBuilderInterface $builder)
|
||||
{
|
||||
$this->type = $type;
|
||||
$this->builder = $builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FormBuilderInterface
|
||||
*/
|
||||
public function getBuilder(): FormBuilderInterface
|
||||
{
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
}
|
||||
|
@@ -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.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Form;
|
||||
|
||||
use Chill\MainBundle\Entity\LocationType as EntityLocationType;
|
||||
@@ -14,12 +21,8 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
final class LocationFormType extends AbstractType
|
||||
{
|
||||
|
||||
private TranslatableStringHelper $translatableStringHelper;
|
||||
|
||||
/**
|
||||
* @param TranslatableStringHelper $translatableStringHelper
|
||||
*/
|
||||
public function __construct(TranslatableStringHelper $translatableStringHelper)
|
||||
{
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
@@ -27,7 +30,6 @@ final class LocationFormType extends AbstractType
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
|
||||
$builder
|
||||
->add('locationType', EntityType::class, [
|
||||
'class' => EntityLocationType::class,
|
||||
@@ -52,25 +54,27 @@ final class LocationFormType extends AbstractType
|
||||
'use_valid_to' => false,
|
||||
'mapped' => false,
|
||||
])
|
||||
->add('active', ChoiceType::class,
|
||||
[
|
||||
'choices' => [
|
||||
'Yes' => true,
|
||||
'No' => false
|
||||
],
|
||||
'expanded' => true
|
||||
]);
|
||||
->add(
|
||||
'active',
|
||||
ChoiceType::class,
|
||||
[
|
||||
'choices' => [
|
||||
'Yes' => true,
|
||||
'No' => false,
|
||||
],
|
||||
'expanded' => true,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param OptionsResolverInterface $resolver
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'Chill\MainBundle\Entity\Location'
|
||||
));
|
||||
$resolver->setDefaults([
|
||||
'data_class' => 'Chill\MainBundle\Entity\Location',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,5 +84,4 @@ final class LocationFormType extends AbstractType
|
||||
{
|
||||
return 'chill_mainbundle_location';
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Form;
|
||||
|
||||
use Chill\MainBundle\Entity\LocationType;
|
||||
@@ -12,43 +19,58 @@ final class LocationTypeType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->add('title', TranslatableStringFormType::class,
|
||||
[
|
||||
'label' => 'Name',
|
||||
])
|
||||
->add('availableForUsers', ChoiceType::class,
|
||||
[
|
||||
'choices' => [
|
||||
'Yes' => true,
|
||||
'No' => false
|
||||
],
|
||||
'expanded' => true
|
||||
])
|
||||
->add('addressRequired', ChoiceType::class,
|
||||
[
|
||||
'choices' => [
|
||||
'optional' => LocationType::STATUS_OPTIONAL,
|
||||
'required' => LocationType::STATUS_REQUIRED,
|
||||
'never' => LocationType::STATUS_NEVER,
|
||||
],
|
||||
'expanded' => true
|
||||
])
|
||||
->add('contactData', ChoiceType::class,
|
||||
[
|
||||
'choices' => [
|
||||
'optional' => LocationType::STATUS_OPTIONAL,
|
||||
'required' => LocationType::STATUS_REQUIRED,
|
||||
'never' => LocationType::STATUS_NEVER,
|
||||
],
|
||||
'expanded' => true
|
||||
])
|
||||
->add('active', ChoiceType::class,
|
||||
[
|
||||
'choices' => [
|
||||
'Yes' => true,
|
||||
'No' => false
|
||||
],
|
||||
'expanded' => true
|
||||
]);
|
||||
$builder->add(
|
||||
'title',
|
||||
TranslatableStringFormType::class,
|
||||
[
|
||||
'label' => 'Name',
|
||||
]
|
||||
)
|
||||
->add(
|
||||
'availableForUsers',
|
||||
ChoiceType::class,
|
||||
[
|
||||
'choices' => [
|
||||
'Yes' => true,
|
||||
'No' => false,
|
||||
],
|
||||
'expanded' => true,
|
||||
]
|
||||
)
|
||||
->add(
|
||||
'addressRequired',
|
||||
ChoiceType::class,
|
||||
[
|
||||
'choices' => [
|
||||
'optional' => LocationType::STATUS_OPTIONAL,
|
||||
'required' => LocationType::STATUS_REQUIRED,
|
||||
'never' => LocationType::STATUS_NEVER,
|
||||
],
|
||||
'expanded' => true,
|
||||
]
|
||||
)
|
||||
->add(
|
||||
'contactData',
|
||||
ChoiceType::class,
|
||||
[
|
||||
'choices' => [
|
||||
'optional' => LocationType::STATUS_OPTIONAL,
|
||||
'required' => LocationType::STATUS_REQUIRED,
|
||||
'never' => LocationType::STATUS_NEVER,
|
||||
],
|
||||
'expanded' => true,
|
||||
]
|
||||
)
|
||||
->add(
|
||||
'active',
|
||||
ChoiceType::class,
|
||||
[
|
||||
'choices' => [
|
||||
'Yes' => true,
|
||||
'No' => false,
|
||||
],
|
||||
'expanded' => true,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -1,75 +1,63 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Form;
|
||||
|
||||
use Chill\MainBundle\Form\Utils\PermissionsGroupFlagProvider;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Chill\MainBundle\Form\Utils\PermissionsGroupFlagProvider;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use function array_combine;
|
||||
use function array_merge;
|
||||
|
||||
class PermissionsGroupType extends AbstractType
|
||||
{
|
||||
public const FLAG_SCOPE = 'permissions_group';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var PermissionsGroupFlagProvider[]
|
||||
*/
|
||||
protected $flagProviders = [];
|
||||
|
||||
const FLAG_SCOPE = 'permissions_group';
|
||||
|
||||
/**
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param array $options
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('name', TextType::class)
|
||||
;
|
||||
|
||||
$flags = $this->getFlags();
|
||||
|
||||
if (count($flags) > 0) {
|
||||
$builder
|
||||
->add('flags', ChoiceType::class, [
|
||||
'choices' => \array_combine($flags, $flags),
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'required' => false
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getFlags(): array
|
||||
{
|
||||
$flags = [];
|
||||
|
||||
foreach ($this->flagProviders as $flagProvider) {
|
||||
$flags = \array_merge($flags, $flagProvider->getPermissionsGroupFlags());
|
||||
}
|
||||
|
||||
return $flags;
|
||||
}
|
||||
|
||||
|
||||
public function addFlagProvider(PermissionsGroupFlagProvider $provider)
|
||||
{
|
||||
$this->flagProviders[] = $provider;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('name', TextType::class);
|
||||
|
||||
$flags = $this->getFlags();
|
||||
|
||||
if (count($flags) > 0) {
|
||||
$builder
|
||||
->add('flags', ChoiceType::class, [
|
||||
'choices' => array_combine($flags, $flags),
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'required' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OptionsResolverInterface $resolver
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'Chill\MainBundle\Entity\PermissionsGroup'
|
||||
));
|
||||
$resolver->setDefaults([
|
||||
'data_class' => 'Chill\MainBundle\Entity\PermissionsGroup',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,4 +67,15 @@ class PermissionsGroupType extends AbstractType
|
||||
{
|
||||
return 'chill_mainbundle_permissionsgroup';
|
||||
}
|
||||
|
||||
protected function getFlags(): array
|
||||
{
|
||||
$flags = [];
|
||||
|
||||
foreach ($this->flagProviders as $flagProvider) {
|
||||
$flags = array_merge($flags, $flagProvider->getPermissionsGroupFlags());
|
||||
}
|
||||
|
||||
return $flags;
|
||||
}
|
||||
}
|
||||
|
@@ -1,23 +1,25 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Form;
|
||||
|
||||
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||
|
||||
class ScopeType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param array $options
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('name', TranslatableStringFormType::class)
|
||||
;
|
||||
->add('name', TranslatableStringFormType::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -25,9 +27,9 @@ class ScopeType extends AbstractType
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'Chill\MainBundle\Entity\Scope'
|
||||
));
|
||||
$resolver->setDefaults([
|
||||
'data_class' => 'Chill\MainBundle\Entity\Scope',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,36 +1,24 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2016 Champs-Libres <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\MainBundle\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Chill\MainBundle\Form\Type\PostalCodeType;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\MainBundle\Form\DataMapper\AddressDataMapper;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* A type to create/update Address entity
|
||||
* A type to create/update Address entity.
|
||||
*
|
||||
* Options:
|
||||
*
|
||||
@@ -45,25 +33,27 @@ class AddressType extends AbstractType
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('street', TextType::class, array(
|
||||
'required' => !$options['has_no_address'] // true if has no address is false
|
||||
))
|
||||
->add('streetNumber', TextType::class, array(
|
||||
'required' => false
|
||||
))
|
||||
->add('postCode', PostalCodeType::class, array(
|
||||
'label' => 'Postal code',
|
||||
'placeholder' => 'Choose a postal code',
|
||||
'required' => !$options['has_no_address'] // true if has no address is false
|
||||
))
|
||||
;
|
||||
->add('street', TextType::class, [
|
||||
'required' => !$options['has_no_address'], // true if has no address is false
|
||||
])
|
||||
->add('streetNumber', TextType::class, [
|
||||
'required' => false,
|
||||
])
|
||||
->add('postCode', PostalCodeType::class, [
|
||||
'label' => 'Postal code',
|
||||
'placeholder' => 'Choose a postal code',
|
||||
'required' => !$options['has_no_address'], // true if has no address is false
|
||||
]);
|
||||
|
||||
if ($options['has_valid_from']) {
|
||||
$builder
|
||||
->add('validFrom', ChillDateType::class, array(
|
||||
'required' => true,
|
||||
)
|
||||
);
|
||||
->add(
|
||||
'validFrom',
|
||||
ChillDateType::class,
|
||||
[
|
||||
'required' => true,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
if ($options['has_no_address']) {
|
||||
@@ -72,13 +62,13 @@ class AddressType extends AbstractType
|
||||
'required' => true,
|
||||
'choices' => [
|
||||
'address.consider homeless' => true,
|
||||
'address.real address' => false
|
||||
'address.real address' => false,
|
||||
],
|
||||
'label' => 'address.address_homeless'
|
||||
'label' => 'address.address_homeless',
|
||||
]);
|
||||
}
|
||||
|
||||
if ($options['null_if_empty'] === TRUE) {
|
||||
if (true === $options['null_if_empty']) {
|
||||
$builder->setDataMapper(new AddressDataMapper());
|
||||
}
|
||||
}
|
||||
@@ -95,7 +85,6 @@ class AddressType extends AbstractType
|
||||
->setAllowedTypes('has_no_address', 'bool')
|
||||
->setDefined('null_if_empty')
|
||||
->setDefault('null_if_empty', false)
|
||||
->setAllowedTypes('null_if_empty', 'bool')
|
||||
;
|
||||
->setAllowedTypes('null_if_empty', 'bool');
|
||||
}
|
||||
}
|
||||
|
@@ -1,37 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
* Copyright (C) 2015 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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Form\Type;
|
||||
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Form\Type\DataTransformer\ScopeTransformer;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Chill\MainBundle\Form\Type\DataTransformer\ScopeTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
|
||||
/**
|
||||
* Trait to add an input with reachable scope for a given center and role.
|
||||
@@ -78,75 +67,73 @@ use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
*
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @author Champs Libres <info@champs-libres.coop>
|
||||
*/
|
||||
trait AppendScopeChoiceTypeTrait
|
||||
{
|
||||
/**
|
||||
* Append a scope choice field, with the scopes reachable by given
|
||||
* user for the given role and center.
|
||||
*
|
||||
* The field is added on event FormEvents::PRE_SET_DATA
|
||||
*
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param Role $role
|
||||
* @param Center $center
|
||||
* @param User $user
|
||||
* @param AuthorizationHelper $authorizationHelper
|
||||
* @param TranslatableStringHelper $translatableStringHelper
|
||||
* @param string $name
|
||||
*/
|
||||
protected function appendScopeChoices(FormBuilderInterface $builder,
|
||||
Role $role, Center $center, User $user,
|
||||
AuthorizationHelper $authorizationHelper,
|
||||
TranslatableStringHelper $translatableStringHelper,
|
||||
ObjectManager $om, $name = 'scope')
|
||||
{
|
||||
$reachableScopes = $authorizationHelper
|
||||
->getReachableScopes($user, $role, $center);
|
||||
|
||||
$choices = array();
|
||||
foreach($reachableScopes as $scope) {
|
||||
$choices[$scope->getId()] = $translatableStringHelper
|
||||
->localize($scope->getName());
|
||||
}
|
||||
|
||||
$dataTransformer = new ScopeTransformer($om);
|
||||
|
||||
$builder->addEventListener(FormEvents::PRE_SET_DATA,
|
||||
function (FormEvent $event) use ($choices, $name, $dataTransformer, $builder) {
|
||||
$form = $event->getForm();
|
||||
$form->add(
|
||||
$builder
|
||||
->create($name, ChoiceType::class, array(
|
||||
'choices' => array_combine(array_values($choices),array_keys($choices)),
|
||||
'auto_initialize' => false
|
||||
)
|
||||
)
|
||||
->addModelTransformer($dataTransformer)
|
||||
->getForm()
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Append a `role` and `center` option to the form.
|
||||
*
|
||||
* The allowed types are :
|
||||
* - Chill\MainBundle\Entity\Center for center
|
||||
* - Symfony\Component\Security\Core\Role\Role for role
|
||||
*
|
||||
* @param OptionsResolver $resolver
|
||||
*/
|
||||
public function appendScopeChoicesOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver
|
||||
->setRequired(array('center', 'role'))
|
||||
->setAllowedTypes('center', 'Chill\MainBundle\Entity\Center')
|
||||
->setAllowedTypes('role', 'Symfony\Component\Security\Core\Role\Role')
|
||||
;
|
||||
->setRequired(['center', 'role'])
|
||||
->setAllowedTypes('center', 'Chill\MainBundle\Entity\Center')
|
||||
->setAllowedTypes('role', 'Symfony\Component\Security\Core\Role\Role');
|
||||
}
|
||||
|
||||
/**
|
||||
* Append a scope choice field, with the scopes reachable by given
|
||||
* user for the given role and center.
|
||||
*
|
||||
* The field is added on event FormEvents::PRE_SET_DATA
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
protected function appendScopeChoices(
|
||||
FormBuilderInterface $builder,
|
||||
Role $role,
|
||||
Center $center,
|
||||
User $user,
|
||||
AuthorizationHelper $authorizationHelper,
|
||||
TranslatableStringHelper $translatableStringHelper,
|
||||
ObjectManager $om,
|
||||
$name = 'scope'
|
||||
)
|
||||
{
|
||||
$reachableScopes = $authorizationHelper
|
||||
->getReachableScopes($user, $role, $center);
|
||||
|
||||
$choices = [];
|
||||
|
||||
foreach ($reachableScopes as $scope) {
|
||||
$choices[$scope->getId()] = $translatableStringHelper
|
||||
->localize($scope->getName());
|
||||
}
|
||||
|
||||
$dataTransformer = new ScopeTransformer($om);
|
||||
|
||||
$builder->addEventListener(
|
||||
FormEvents::PRE_SET_DATA,
|
||||
function (FormEvent $event) use ($choices, $name, $dataTransformer, $builder) {
|
||||
$form = $event->getForm();
|
||||
$form->add(
|
||||
$builder
|
||||
->create(
|
||||
$name,
|
||||
ChoiceType::class,
|
||||
[
|
||||
'choices' => array_combine(array_values($choices), array_keys($choices)),
|
||||
'auto_initialize' => false,
|
||||
]
|
||||
)
|
||||
->addModelTransformer($dataTransformer)
|
||||
->getForm()
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -1,40 +1,40 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2018 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\MainBundle\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
|
||||
/**
|
||||
* Available options :
|
||||
* Available options :.
|
||||
*
|
||||
* - `button_add_label`
|
||||
* - `button_remove_label`
|
||||
* - `identifier`: an identifier to identify the kind of collecton. Useful if some
|
||||
* javascript should be launched associated to `add_entry`, `remove_entry` events.
|
||||
* - `empty_collection_explain`
|
||||
*
|
||||
*
|
||||
*/
|
||||
class ChillCollectionType extends AbstractType
|
||||
{
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
{
|
||||
$view->vars['button_add_label'] = $options['button_add_label'];
|
||||
$view->vars['button_remove_label'] = $options['button_remove_label'];
|
||||
$view->vars['allow_delete'] = (int) $options['allow_delete'];
|
||||
$view->vars['allow_add'] = (int) $options['allow_add'];
|
||||
$view->vars['identifier'] = $options['identifier'];
|
||||
$view->vars['empty_collection_explain'] = $options['empty_collection_explain'];
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver
|
||||
@@ -46,16 +46,6 @@ class ChillCollectionType extends AbstractType
|
||||
]);
|
||||
}
|
||||
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
{
|
||||
$view->vars['button_add_label'] = $options['button_add_label'];
|
||||
$view->vars['button_remove_label'] = $options['button_remove_label'];
|
||||
$view->vars['allow_delete'] = (int) $options['allow_delete'];
|
||||
$view->vars['allow_add'] = (int) $options['allow_add'];
|
||||
$view->vars['identifier'] = $options['identifier'];
|
||||
$view->vars['empty_collection_explain'] = $options['empty_collection_explain'];
|
||||
}
|
||||
|
||||
public function getParent()
|
||||
{
|
||||
return \Symfony\Component\Form\Extension\Core\Type\CollectionType::class;
|
||||
|
@@ -1,20 +1,12 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2017 Champs Libres Cooperative <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\MainBundle\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
@@ -23,11 +15,9 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* Display the date in a date picker.
|
||||
*
|
||||
*
|
||||
* Extends the symfony `Symfony\Component\Form\Extension\Core\Type\DateType`
|
||||
* to automatically create a date picker.
|
||||
*
|
||||
* @author Mathieu Jaumotte <jaum_mathieu@collectifs.net>
|
||||
*/
|
||||
class ChillDateTimeType extends AbstractType
|
||||
{
|
||||
@@ -39,10 +29,9 @@ class ChillDateTimeType extends AbstractType
|
||||
->setDefault('time_widget', 'choice')
|
||||
->setDefault('minutes', range(0, 59, 5))
|
||||
->setDefault('hours', range(8, 22))
|
||||
->setDefault('html5', true)
|
||||
;
|
||||
->setDefault('html5', true);
|
||||
}
|
||||
|
||||
|
||||
public function getParent()
|
||||
{
|
||||
return DateTimeType::class;
|
||||
|
@@ -1,20 +1,12 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2017 Champs Libres Cooperative <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\MainBundle\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
@@ -23,11 +15,9 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* Display the date in a date picker.
|
||||
*
|
||||
*
|
||||
* Extends the symfony `Symfony\Component\Form\Extension\Core\Type\DateType`
|
||||
* to automatically create a date picker.
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class ChillDateType extends AbstractType
|
||||
{
|
||||
@@ -35,10 +25,9 @@ class ChillDateType extends AbstractType
|
||||
{
|
||||
$resolver
|
||||
->setDefault('widget', 'single_text')
|
||||
->setDefault('html5', true)
|
||||
;
|
||||
->setDefault('html5', true);
|
||||
}
|
||||
|
||||
|
||||
public function getParent()
|
||||
{
|
||||
return DateType::class;
|
||||
|
@@ -1,45 +1,38 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2017 Champs Libres Cooperative <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\MainBundle\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* Create a Textarea
|
||||
*
|
||||
* By default, add a WYSIWYG editor.
|
||||
*
|
||||
* Options:
|
||||
*
|
||||
* * `disable_editor`: set true to disable editor
|
||||
* Create a Textarea.
|
||||
*
|
||||
* By default, add a WYSIWYG editor.
|
||||
*
|
||||
* Options:
|
||||
*
|
||||
* * `disable_editor`: set true to disable editor
|
||||
*/
|
||||
final class ChillTextareaType extends AbstractType
|
||||
{
|
||||
public function getParent()
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
{
|
||||
return TextareaType::class;
|
||||
if (!$options['disable_editor']) {
|
||||
$view->vars['attr']['ckeditor'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver
|
||||
@@ -47,11 +40,9 @@ final class ChillTextareaType extends AbstractType
|
||||
->setDefault('disable_editor', false)
|
||||
->setAllowedTypes('disable_editor', 'bool');
|
||||
}
|
||||
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
|
||||
public function getParent()
|
||||
{
|
||||
if (!$options['disable_editor']) {
|
||||
$view->vars['attr']['ckeditor'] = true;
|
||||
}
|
||||
return TextareaType::class;
|
||||
}
|
||||
}
|
||||
|
@@ -1,26 +1,17 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2017 Champs Libres Cooperative <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\MainBundle\Form\Type;
|
||||
|
||||
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
|
||||
use DateTime;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Chill\MainBundle\Form\Type\ChillTextareaType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
@@ -47,15 +38,14 @@ class CommentType extends AbstractType
|
||||
->add('comment', ChillTextareaType::class, [
|
||||
'disable_editor' => $options['disable_editor'],
|
||||
'label' => $options['label'],
|
||||
])
|
||||
;
|
||||
]);
|
||||
|
||||
$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
|
||||
$data = $event->getForm()->getData();
|
||||
$comment = $event->getData() ?? ['comment' => ''];
|
||||
|
||||
if (null !== $data && $data->getComment() !== $comment['comment']) {
|
||||
$data->setDate(new \DateTime());
|
||||
$data->setDate(new DateTime());
|
||||
$data->setUserId($this->user->getId());
|
||||
$event->getForm()->setData($data);
|
||||
}
|
||||
@@ -65,7 +55,8 @@ class CommentType extends AbstractType
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
{
|
||||
$view->vars = array_replace(
|
||||
$view->vars, [
|
||||
$view->vars,
|
||||
[
|
||||
'hideLabel' => true,
|
||||
]
|
||||
);
|
||||
@@ -78,7 +69,7 @@ class CommentType extends AbstractType
|
||||
->setAllowedTypes('disable_editor', 'bool')
|
||||
->setDefaults([
|
||||
'data_class' => CommentEmbeddable::class,
|
||||
'disable_editor' => false
|
||||
'disable_editor' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@@ -1,54 +1,37 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015 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\MainBundle\Form\Type;
|
||||
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
|
||||
use Chill\MainBundle\Entity\PermissionsGroup;
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Entity\PermissionsGroup;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class ComposedGroupCenterType extends AbstractType
|
||||
{
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->add('permissionsgroup', EntityType::class, array(
|
||||
$builder->add('permissionsgroup', EntityType::class, [
|
||||
'class' => 'Chill\MainBundle\Entity\PermissionsGroup',
|
||||
'choice_label' => function(PermissionsGroup $group) {
|
||||
'choice_label' => function (PermissionsGroup $group) {
|
||||
return $group->getName();
|
||||
}
|
||||
))->add('center', EntityType::class, array(
|
||||
},
|
||||
])->add('center', EntityType::class, [
|
||||
'class' => 'Chill\MainBundle\Entity\Center',
|
||||
'choice_label' => function(Center $center) {
|
||||
'choice_label' => function (Center $center) {
|
||||
return $center->getName();
|
||||
}
|
||||
))
|
||||
;
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
@@ -60,5 +43,4 @@ class ComposedGroupCenterType extends AbstractType
|
||||
{
|
||||
return 'composed_groupcenter';
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,71 +1,50 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
* Copyright (C) 2015 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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Form\Type;
|
||||
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\MainBundle\Entity\Scope;
|
||||
use Chill\MainBundle\Security\RoleProvider;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* Form to Edit/create a role scope. If the role scope does not
|
||||
* exists in the database, he is generated.
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @author Champs Libres <info@champs-libres.coop>
|
||||
*/
|
||||
class ComposedRoleScopeType extends AbstractType
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $roles = array();
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $rolesWithoutScope = array();
|
||||
|
||||
/**
|
||||
*
|
||||
* @var TranslatableStringHelper
|
||||
*/
|
||||
private $translatableStringHelper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var RoleProvider
|
||||
*/
|
||||
private $roleProvider;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $roles = [];
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $rolesWithoutScope = [];
|
||||
|
||||
/**
|
||||
* @var TranslatableStringHelper
|
||||
*/
|
||||
private $translatableStringHelper;
|
||||
|
||||
public function __construct(
|
||||
TranslatableStringHelper $translatableStringHelper,
|
||||
RoleProvider $roleProvider
|
||||
@@ -83,40 +62,39 @@ class ComposedRoleScopeType extends AbstractType
|
||||
$rolesWithoutScopes = $this->rolesWithoutScope;
|
||||
|
||||
//build roles
|
||||
$values = array();
|
||||
$values = [];
|
||||
|
||||
foreach ($this->roles as $role) {
|
||||
$values[$role] = $role;
|
||||
}
|
||||
|
||||
$builder
|
||||
->add('role', ChoiceType::class, array(
|
||||
'choices' => array_combine(array_values($values),array_keys($values)),
|
||||
'placeholder' => 'Choose amongst roles',
|
||||
'choice_attr' => function($role) use ($rolesWithoutScopes) {
|
||||
->add('role', ChoiceType::class, [
|
||||
'choices' => array_combine(array_values($values), array_keys($values)),
|
||||
'placeholder' => 'Choose amongst roles',
|
||||
'choice_attr' => function ($role) use ($rolesWithoutScopes) {
|
||||
if (in_array($role, $rolesWithoutScopes)) {
|
||||
return array('data-has-scope' => '0');
|
||||
} else {
|
||||
return array('data-has-scope' => '1');
|
||||
return ['data-has-scope' => '0'];
|
||||
}
|
||||
},
|
||||
'group_by' => function($role, $key, $index) {
|
||||
|
||||
return ['data-has-scope' => '1'];
|
||||
},
|
||||
'group_by' => function ($role, $key, $index) {
|
||||
return $this->roleProvider->getRoleTitle($role);
|
||||
}
|
||||
))
|
||||
->add('scope', EntityType::class, array(
|
||||
},
|
||||
])
|
||||
->add('scope', EntityType::class, [
|
||||
'class' => 'ChillMainBundle:Scope',
|
||||
'choice_label' => function(Scope $scope) use ($translatableStringHelper) {
|
||||
'choice_label' => function (Scope $scope) use ($translatableStringHelper) {
|
||||
return $translatableStringHelper->localize($scope->getName());
|
||||
},
|
||||
'required' => false,
|
||||
'data' => null
|
||||
));
|
||||
|
||||
'data' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefault('data_class', 'Chill\MainBundle\Entity\RoleScope');
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Form\Type\DataTransformer;
|
||||
|
||||
use Chill\MainBundle\Repository\AddressRepository;
|
||||
@@ -17,16 +24,16 @@ final class AddressToIdDataTransformer implements DataTransformerInterface
|
||||
|
||||
public function reverseTransform($value)
|
||||
{
|
||||
if (NULL === $value || '' === $value) {
|
||||
if (null === $value || '' === $value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$address = $this->addressRepository->find($value);
|
||||
|
||||
if (NULL === $address) {
|
||||
$failure = new TransformationFailedException(sprintf("Address with id %s does not exists", $value));
|
||||
if (null === $address) {
|
||||
$failure = new TransformationFailedException(sprintf('Address with id %s does not exists', $value));
|
||||
$failure
|
||||
->setInvalidMessage("The given {{ value }} is not a valid address id", [ '{{ value }}' => $value]);
|
||||
->setInvalidMessage('The given {{ value }} is not a valid address id', ['{{ value }}' => $value]);
|
||||
|
||||
throw $failure;
|
||||
}
|
||||
@@ -36,7 +43,7 @@ final class AddressToIdDataTransformer implements DataTransformerInterface
|
||||
|
||||
public function transform($value)
|
||||
{
|
||||
if (NULL === $value) {
|
||||
if (null === $value) {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
@@ -1,20 +1,10 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015 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\MainBundle\Form\Type\DataTransformer;
|
||||
@@ -22,15 +12,15 @@ namespace Chill\MainBundle\Form\Type\DataTransformer;
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Repository\CenterRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
use Traversable;
|
||||
|
||||
class CenterTransformer implements DataTransformerInterface
|
||||
{
|
||||
private CenterRepository $centerRepository;
|
||||
|
||||
private bool $multiple = false;
|
||||
|
||||
public function __construct(
|
||||
@@ -43,12 +33,12 @@ class CenterTransformer implements DataTransformerInterface
|
||||
|
||||
public function reverseTransform($id)
|
||||
{
|
||||
if ($id === NULL) {
|
||||
if (null === $id) {
|
||||
if ($this->multiple) {
|
||||
return new ArrayCollection();
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$ids = [];
|
||||
@@ -61,11 +51,13 @@ class CenterTransformer implements DataTransformerInterface
|
||||
|
||||
$centers = $this
|
||||
->centerRepository
|
||||
->findBy(['id' => $ids ]);
|
||||
->findBy(['id' => $ids]);
|
||||
|
||||
if ([] === $centers || count($ids) > count($centers)) {
|
||||
throw new TransformationFailedException(sprintf(
|
||||
'No center found for one of those ids: %s', implode(',', $ids)));
|
||||
'No center found for one of those ids: %s',
|
||||
implode(',', $ids)
|
||||
));
|
||||
}
|
||||
|
||||
if ($this->multiple) {
|
||||
@@ -77,25 +69,27 @@ class CenterTransformer implements DataTransformerInterface
|
||||
|
||||
public function transform($center)
|
||||
{
|
||||
if ($center === NULL) {
|
||||
if (null === $center) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($this->multiple) {
|
||||
if (!is_iterable($center)) {
|
||||
throw new UnexpectedTypeException($center, \Traversable::class);
|
||||
throw new UnexpectedTypeException($center, Traversable::class);
|
||||
}
|
||||
$ids = [];
|
||||
|
||||
foreach ($center as $c) {
|
||||
$ids[] = $c->getId();
|
||||
}
|
||||
|
||||
return implode(',', $ids);
|
||||
} else {
|
||||
if (!$center instanceof Center) {
|
||||
throw new UnexpectedTypeException($center, Center::class);
|
||||
}
|
||||
return (string) $center->getId();
|
||||
}
|
||||
|
||||
if (!$center instanceof Center) {
|
||||
throw new UnexpectedTypeException($center, Center::class);
|
||||
}
|
||||
|
||||
return (string) $center->getId();
|
||||
}
|
||||
}
|
||||
|
@@ -1,70 +1,35 @@
|
||||
<?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\MainBundle\Form\Type\DataTransformer;
|
||||
|
||||
use DateInterval;
|
||||
use Exception;
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
|
||||
class DateIntervalTransformer implements DataTransformerInterface
|
||||
{
|
||||
public function transform($value)
|
||||
{
|
||||
if (empty($value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!$value instanceof \DateInterval) {
|
||||
throw new UnexpectedTypeException($value, \DateInterval::class);
|
||||
}
|
||||
|
||||
if ($value->d > 0) {
|
||||
// we check for weeks (weeks are converted to 7 days)
|
||||
if ($value->d % 7 === 0) {
|
||||
return [
|
||||
'n' => $value->d / 7,
|
||||
'unit' => 'W'
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'n' => $value->d,
|
||||
'unit' => 'D'
|
||||
];
|
||||
}
|
||||
|
||||
if ($value->m > 0) {
|
||||
return [
|
||||
'n' => $value->m,
|
||||
'unit' => 'M'
|
||||
];
|
||||
}
|
||||
|
||||
if ($value->y > 0) {
|
||||
return [
|
||||
'n' => $value->y,
|
||||
'unit' => 'Y'
|
||||
];
|
||||
}
|
||||
|
||||
throw new TransformationFailedException(
|
||||
'The date interval does not contains any days, months or years.'
|
||||
);
|
||||
}
|
||||
|
||||
public function reverseTransform($value)
|
||||
{
|
||||
if (empty($value) || empty($value['n'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$string = 'P'.$value['n'].$value['unit'];
|
||||
$string = 'P' . $value['n'] . $value['unit'];
|
||||
|
||||
try {
|
||||
return new \DateInterval($string);
|
||||
} catch (\Exception $e) {
|
||||
return new DateInterval($string);
|
||||
} catch (Exception $e) {
|
||||
throw new TransformationFailedException(
|
||||
'Could not transform value into DateInterval',
|
||||
1542,
|
||||
@@ -72,4 +37,48 @@ class DateIntervalTransformer implements DataTransformerInterface
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function transform($value)
|
||||
{
|
||||
if (empty($value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!$value instanceof DateInterval) {
|
||||
throw new UnexpectedTypeException($value, DateInterval::class);
|
||||
}
|
||||
|
||||
if (0 < $value->d) {
|
||||
// we check for weeks (weeks are converted to 7 days)
|
||||
if ($value->d % 7 === 0) {
|
||||
return [
|
||||
'n' => $value->d / 7,
|
||||
'unit' => 'W',
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'n' => $value->d,
|
||||
'unit' => 'D',
|
||||
];
|
||||
}
|
||||
|
||||
if (0 < $value->m) {
|
||||
return [
|
||||
'n' => $value->m,
|
||||
'unit' => 'M',
|
||||
];
|
||||
}
|
||||
|
||||
if (0 < $value->y) {
|
||||
return [
|
||||
'n' => $value->y,
|
||||
'unit' => 'Y',
|
||||
];
|
||||
}
|
||||
|
||||
throw new TransformationFailedException(
|
||||
'The date interval does not contains any days, months or years.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -1,37 +1,24 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
* Copyright (C) 2014 Champs-Libres Coopérative <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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Form\Type\DataTransformer;
|
||||
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
|
||||
class MultipleObjectsToIdTransformer implements DataTransformerInterface
|
||||
{
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
private ?string $class;
|
||||
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
public function __construct(EntityManagerInterface $em, ?string $class = null)
|
||||
{
|
||||
$this->em = $em;
|
||||
@@ -39,28 +26,12 @@ class MultipleObjectsToIdTransformer implements DataTransformerInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms an object (use) to a string (id).
|
||||
*
|
||||
* @param array $array
|
||||
* @return ArrayCollection
|
||||
*/
|
||||
public function transform($array)
|
||||
{
|
||||
$ret = array();
|
||||
|
||||
foreach ($array as $el) {
|
||||
$ret[] = ($el->getId());
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a string (id) to an object (item).
|
||||
*
|
||||
* @param string $id
|
||||
* @return ArrayCollection
|
||||
*/
|
||||
* Transforms a string (id) to an object (item).
|
||||
*
|
||||
* @param mixed $array
|
||||
*
|
||||
* @return ArrayCollection
|
||||
*/
|
||||
public function reverseTransform($array)
|
||||
{
|
||||
$ret = new ArrayCollection();
|
||||
@@ -72,6 +43,25 @@ class MultipleObjectsToIdTransformer implements DataTransformerInterface
|
||||
->find($el)
|
||||
);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms an object (use) to a string (id).
|
||||
*
|
||||
* @param array $array
|
||||
*
|
||||
* @return ArrayCollection
|
||||
*/
|
||||
public function transform($array)
|
||||
{
|
||||
$ret = [];
|
||||
|
||||
foreach ($array as $el) {
|
||||
$ret[] = ($el->getId());
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
@@ -1,21 +1,10 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
* Copyright (C) 2014 Champs-Libres Coopérative <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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Form\Type\DataTransformer;
|
||||
@@ -23,14 +12,13 @@ namespace Chill\MainBundle\Form\Type\DataTransformer;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
|
||||
class ObjectToIdTransformer implements DataTransformerInterface
|
||||
{
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
private ?string $class;
|
||||
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
public function __construct(EntityManagerInterface $em, ?string $class = null)
|
||||
{
|
||||
$this->em = $em;
|
||||
@@ -38,26 +26,13 @@ class ObjectToIdTransformer implements DataTransformerInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms an object to a string (id)
|
||||
*
|
||||
* @param Object|null $Object
|
||||
* @return string
|
||||
*/
|
||||
public function transform($object)
|
||||
{
|
||||
if (!$object) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return $object->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a string (id) to an object
|
||||
* Transforms a string (id) to an object.
|
||||
*
|
||||
* @param string $id
|
||||
* @return Object|null
|
||||
*
|
||||
* @throws TransformationFailedException if object is not found.
|
||||
*
|
||||
* @return object|null
|
||||
*/
|
||||
public function reverseTransform($id)
|
||||
{
|
||||
@@ -67,13 +42,28 @@ class ObjectToIdTransformer implements DataTransformerInterface
|
||||
|
||||
$object = $this->em
|
||||
->getRepository($this->class)
|
||||
->find($id)
|
||||
;
|
||||
->find($id);
|
||||
|
||||
if (! $object) {
|
||||
if (!$object) {
|
||||
throw new TransformationFailedException();
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms an object to a string (id).
|
||||
*
|
||||
* @param mixed $object
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function transform($object)
|
||||
{
|
||||
if (!$object) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $object->getId();
|
||||
}
|
||||
}
|
||||
|
@@ -1,30 +1,18 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015 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\MainBundle\Form\Type\DataTransformer;
|
||||
|
||||
use Chill\MainBundle\Entity\Scope;
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
|
||||
class ScopeTransformer implements DataTransformerInterface
|
||||
{
|
||||
@@ -35,19 +23,10 @@ class ScopeTransformer implements DataTransformerInterface
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
public function transform($scope)
|
||||
{
|
||||
if ($scope === NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return $scope->getId();
|
||||
}
|
||||
|
||||
public function reverseTransform($id)
|
||||
{
|
||||
if ($id == NULL) {
|
||||
return NULL;
|
||||
if (null == $id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$scope = $this
|
||||
@@ -55,12 +34,20 @@ class ScopeTransformer implements DataTransformerInterface
|
||||
->getRepository(Scope::class)
|
||||
->find($id);
|
||||
|
||||
if ($scope === NULL) {
|
||||
throw new TransformationFailedException(sprintf("The scope with id "
|
||||
if (null === $scope) {
|
||||
throw new TransformationFailedException(sprintf('The scope with id '
|
||||
. "'%d' were not found", $id));
|
||||
}
|
||||
|
||||
return $scope;
|
||||
}
|
||||
|
||||
public function transform($scope)
|
||||
{
|
||||
if (null === $scope) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $scope->getId();
|
||||
}
|
||||
}
|
||||
|
@@ -1,40 +1,34 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2018 Champs Libres Cooperative <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\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Chill\MainBundle\Form\Type\DataTransformer\DateIntervalTransformer;
|
||||
use Symfony\Component\Validator\Constraints\GreaterThan;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
|
||||
|
||||
|
||||
/**
|
||||
* Show a dateInterval type
|
||||
*
|
||||
* 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\MainBundle\Form\Type;
|
||||
|
||||
use Chill\MainBundle\Form\Type\DataTransformer\DateIntervalTransformer;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Validator\Constraints\GreaterThan;
|
||||
use function array_diff;
|
||||
use function array_values;
|
||||
use function implode;
|
||||
|
||||
/**
|
||||
* Show a dateInterval type.
|
||||
*
|
||||
* Options:
|
||||
*
|
||||
* - `unit_choices`: an array of available units choices.
|
||||
*
|
||||
* The oiriginal `unit_choices` are :
|
||||
*
|
||||
* - `unit_choices`: an array of available units choices.
|
||||
*
|
||||
* The oiriginal `unit_choices` are :
|
||||
* ```
|
||||
* [
|
||||
* 'Days' => 'D',
|
||||
@@ -43,11 +37,11 @@ use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
|
||||
* 'Years' => 'Y'
|
||||
* ]
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* You can remove one or more entries:
|
||||
*
|
||||
*
|
||||
* ```
|
||||
* $builder
|
||||
* $builder
|
||||
* ->add('duration', DateIntervalType::class, array(
|
||||
* 'unit_choices' => [
|
||||
* 'Years' => 'Y',
|
||||
@@ -55,7 +49,6 @@ use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
|
||||
* ]
|
||||
* ));
|
||||
* ```
|
||||
*
|
||||
*/
|
||||
class DateIntervalType extends AbstractType
|
||||
{
|
||||
@@ -66,18 +59,17 @@ class DateIntervalType extends AbstractType
|
||||
'scale' => 0,
|
||||
'constraints' => [
|
||||
new GreaterThan([
|
||||
'value' => 0
|
||||
])
|
||||
]
|
||||
'value' => 0,
|
||||
]),
|
||||
],
|
||||
])
|
||||
->add('unit', ChoiceType::class, [
|
||||
'choices' => $options['unit_choices'],
|
||||
])
|
||||
;
|
||||
|
||||
]);
|
||||
|
||||
$builder->addModelTransformer(new DateIntervalTransformer());
|
||||
}
|
||||
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver
|
||||
@@ -86,23 +78,24 @@ class DateIntervalType extends AbstractType
|
||||
'Days' => 'D',
|
||||
'Weeks' => 'W',
|
||||
'Months' => 'M',
|
||||
'Years' => 'Y'
|
||||
'Years' => 'Y',
|
||||
])
|
||||
->setAllowedValues('unit_choices', function($values) {
|
||||
if (FALSE === is_array($values)) {
|
||||
throw new InvalidOptionsException("The value `unit_choice` should be an array");
|
||||
->setAllowedValues('unit_choices', function ($values) {
|
||||
if (false === is_array($values)) {
|
||||
throw new InvalidOptionsException('The value `unit_choice` should be an array');
|
||||
}
|
||||
|
||||
$diff = \array_diff(\array_values($values), ['D', 'W', 'M', 'Y']);
|
||||
|
||||
$diff = array_diff(array_values($values), ['D', 'W', 'M', 'Y']);
|
||||
|
||||
if (count($diff) == 0) {
|
||||
return true;
|
||||
} else {
|
||||
throw new InvalidOptionsException(sprintf("The values of the "
|
||||
. "units should be 'D', 'W', 'M', 'Y', those are invalid: %s",
|
||||
\implode(', ', $diff)));
|
||||
}
|
||||
})
|
||||
;
|
||||
}
|
||||
|
||||
throw new InvalidOptionsException(sprintf(
|
||||
'The values of the '
|
||||
. "units should be 'D', 'W', 'M', 'Y', those are invalid: %s",
|
||||
implode(', ', $diff)
|
||||
));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -1,40 +1,22 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015 Champs-Libres <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\MainBundle\Form\Type\Export;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
use Chill\MainBundle\Export\ExportManager;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class AggregatorType extends AbstractType
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
@@ -45,30 +27,27 @@ class AggregatorType extends AbstractType
|
||||
$aggregator = $exportManager->getAggregator($options['aggregator_alias']);
|
||||
|
||||
$builder
|
||||
->add('enabled', CheckboxType::class, array(
|
||||
'value' => true,
|
||||
'required' => false,
|
||||
'data' => false
|
||||
));
|
||||
->add('enabled', CheckboxType::class, [
|
||||
'value' => true,
|
||||
'required' => false,
|
||||
'data' => false,
|
||||
]);
|
||||
|
||||
$filterFormBuilder = $builder->create('form', FormType::class, array(
|
||||
'compound' => true,
|
||||
'required' => false,
|
||||
'error_bubbling' => false
|
||||
));
|
||||
$filterFormBuilder = $builder->create('form', FormType::class, [
|
||||
'compound' => true,
|
||||
'required' => false,
|
||||
'error_bubbling' => false,
|
||||
]);
|
||||
$aggregator->buildForm($filterFormBuilder);
|
||||
|
||||
$builder->add($filterFormBuilder);
|
||||
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setRequired('aggregator_alias')
|
||||
->setRequired('export_manager')
|
||||
->setDefault('compound', true)
|
||||
->setDefault('error_bubbling', false)
|
||||
;
|
||||
->setRequired('export_manager')
|
||||
->setDefault('compound', true)
|
||||
->setDefault('error_bubbling', false);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,57 +1,36 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
|
||||
* <http://www.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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Form\Type\Export;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Chill\MainBundle\Export\ExportManager;
|
||||
use Chill\MainBundle\Form\Type\Export\FilterType;
|
||||
use Chill\MainBundle\Form\Type\Export\AggregatorType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||
use Chill\MainBundle\Validator\Constraints\Export\ExportElementConstraint;
|
||||
use Chill\MainBundle\Export\ExportElementWithValidationInterface;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class ExportType extends AbstractType
|
||||
{
|
||||
public const AGGREGATOR_KEY = 'aggregators';
|
||||
|
||||
public const EXPORT_KEY = 'export';
|
||||
|
||||
public const FILTER_KEY = 'filters';
|
||||
|
||||
public const PICK_FORMATTER_KEY = 'pick_formatter';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var ExportManager
|
||||
*/
|
||||
protected $exportManager;
|
||||
|
||||
const FILTER_KEY = 'filters';
|
||||
const AGGREGATOR_KEY = 'aggregators';
|
||||
const PICK_FORMATTER_KEY = 'pick_formatter';
|
||||
const EXPORT_KEY = 'export';
|
||||
|
||||
public function __construct(ExportManager $exportManager)
|
||||
{
|
||||
$this->exportManager = $exportManager;
|
||||
@@ -61,12 +40,11 @@ class ExportType extends AbstractType
|
||||
{
|
||||
$export = $this->exportManager->getExport($options['export_alias']);
|
||||
|
||||
$exportOptions = array(
|
||||
$exportOptions = [
|
||||
'compound' => true,
|
||||
'constraints' => array(
|
||||
|
||||
)
|
||||
);
|
||||
'constraints' => [
|
||||
],
|
||||
];
|
||||
|
||||
// add a contraint if required by export
|
||||
$exportBuilder = $builder->create(self::EXPORT_KEY/*, FormType::class, $exportOptions*/);
|
||||
@@ -78,66 +56,65 @@ class ExportType extends AbstractType
|
||||
if ($export instanceof \Chill\MainBundle\Export\ExportInterface) {
|
||||
//add filters
|
||||
$filters = $this->exportManager->getFiltersApplyingOn($export, $options['picked_centers']);
|
||||
$filterBuilder = $builder->create(self::FILTER_KEY, FormType::class, array('compound' => true));
|
||||
$filterBuilder = $builder->create(self::FILTER_KEY, FormType::class, ['compound' => true]);
|
||||
|
||||
foreach($filters as $alias => $filter) {
|
||||
$filterBuilder->add($alias, FilterType::class, array(
|
||||
foreach ($filters as $alias => $filter) {
|
||||
$filterBuilder->add($alias, FilterType::class, [
|
||||
'filter_alias' => $alias,
|
||||
'export_manager' => $this->exportManager,
|
||||
'label' => $filter->getTitle(),
|
||||
'constraints' => array(
|
||||
new ExportElementConstraint(['element' => $filter])
|
||||
)
|
||||
));
|
||||
'constraints' => [
|
||||
new ExportElementConstraint(['element' => $filter]),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
$builder->add($filterBuilder);
|
||||
|
||||
//add aggregators
|
||||
$aggregators = $this->exportManager
|
||||
->getAggregatorsApplyingOn($export, $options['picked_centers']);
|
||||
$aggregatorBuilder = $builder->create(self::AGGREGATOR_KEY, FormType::class,
|
||||
array('compound' => true));
|
||||
->getAggregatorsApplyingOn($export, $options['picked_centers']);
|
||||
$aggregatorBuilder = $builder->create(
|
||||
self::AGGREGATOR_KEY,
|
||||
FormType::class,
|
||||
['compound' => true]
|
||||
);
|
||||
|
||||
foreach($aggregators as $alias => $aggregator) {
|
||||
$aggregatorBuilder->add($alias, AggregatorType::class, array(
|
||||
foreach ($aggregators as $alias => $aggregator) {
|
||||
$aggregatorBuilder->add($alias, AggregatorType::class, [
|
||||
'aggregator_alias' => $alias,
|
||||
'export_manager' => $this->exportManager,
|
||||
'label' => $aggregator->getTitle(),
|
||||
'constraints' => array(
|
||||
new ExportElementConstraint(['element' => $aggregator])
|
||||
)
|
||||
));
|
||||
'constraints' => [
|
||||
new ExportElementConstraint(['element' => $aggregator]),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
$builder->add($aggregatorBuilder);
|
||||
}
|
||||
|
||||
// add export form
|
||||
$exportBuilder = $builder->create(self::EXPORT_KEY, FormType::class, array('compound' => true));
|
||||
$exportBuilder = $builder->create(self::EXPORT_KEY, FormType::class, ['compound' => true]);
|
||||
$this->exportManager->getExport($options['export_alias'])
|
||||
->buildForm($exportBuilder);
|
||||
->buildForm($exportBuilder);
|
||||
$builder->add($exportBuilder);
|
||||
|
||||
if ($export instanceof \Chill\MainBundle\Export\ExportInterface) {
|
||||
$builder->add(self::PICK_FORMATTER_KEY, PickFormatterType::class, array(
|
||||
'export_alias' => $options['export_alias']
|
||||
));
|
||||
$builder->add(self::PICK_FORMATTER_KEY, PickFormatterType::class, [
|
||||
'export_alias' => $options['export_alias'],
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setRequired(array('export_alias', 'picked_centers'))
|
||||
->setAllowedTypes('export_alias', array('string'))
|
||||
->setDefault('compound', true)
|
||||
->setDefault('constraints', array(
|
||||
//new \Chill\MainBundle\Validator\Constraints\Export\ExportElementConstraint()
|
||||
))
|
||||
;
|
||||
|
||||
$resolver->setRequired(['export_alias', 'picked_centers'])
|
||||
->setAllowedTypes('export_alias', ['string'])
|
||||
->setDefault('compound', true)
|
||||
->setDefault('constraints', [
|
||||
//new \Chill\MainBundle\Validator\Constraints\Export\ExportElementConstraint()
|
||||
]);
|
||||
}
|
||||
|
||||
public function getParent()
|
||||
|
@@ -1,42 +1,23 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015 Champs-Libres <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\MainBundle\Form\Type\Export;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Chill\MainBundle\Export\ExportManager;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Chill\MainBundle\Export\ExportElementWithValidationInterface;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class FilterType extends AbstractType
|
||||
{
|
||||
const ENABLED_FIELD = 'enabled';
|
||||
public const ENABLED_FIELD = 'enabled';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -44,35 +25,31 @@ class FilterType extends AbstractType
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
|
||||
$exportManager = $options['export_manager'];
|
||||
$filter = $exportManager->getFilter($options['filter_alias']);
|
||||
|
||||
$builder
|
||||
->add(self::ENABLED_FIELD, CheckboxType::class, array(
|
||||
'value' => true,
|
||||
'data' => false,
|
||||
'required' => false
|
||||
));
|
||||
->add(self::ENABLED_FIELD, CheckboxType::class, [
|
||||
'value' => true,
|
||||
'data' => false,
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
$filterFormBuilder = $builder->create('form', FormType::class, array(
|
||||
$filterFormBuilder = $builder->create('form', FormType::class, [
|
||||
'compound' => true,
|
||||
'error_bubbling' => false,
|
||||
'required' => false,
|
||||
));
|
||||
]);
|
||||
$filter->buildForm($filterFormBuilder);
|
||||
|
||||
$builder->add($filterFormBuilder);
|
||||
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setRequired('filter_alias')
|
||||
->setRequired('export_manager')
|
||||
->setDefault('compound', true)
|
||||
->setDefault('error_bubbling', false)
|
||||
;
|
||||
->setRequired('export_manager')
|
||||
->setDefault('compound', true)
|
||||
->setDefault('error_bubbling', false);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,59 +1,45 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2016 Champs-Libres <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\MainBundle\Form\Type\Export;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Chill\MainBundle\Export\ExportManager;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class FormatterType extends AbstractType
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var ExportManager
|
||||
*/
|
||||
protected $exportManager;
|
||||
|
||||
public function __construct(ExportManager $manager)
|
||||
|
||||
public function __construct(ExportManager $manager)
|
||||
{
|
||||
$this->exportManager = $manager;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setRequired(array('formatter_alias', 'export_alias',
|
||||
'aggregator_aliases'));
|
||||
}
|
||||
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$formatter = $this->exportManager->getFormatter($options['formatter_alias']);
|
||||
|
||||
$formatter->buildForm($builder, $options['export_alias'],
|
||||
$options['aggregator_aliases']);
|
||||
|
||||
$formatter->buildForm(
|
||||
$builder,
|
||||
$options['export_alias'],
|
||||
$options['aggregator_aliases']
|
||||
);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setRequired(['formatter_alias', 'export_alias',
|
||||
'aggregator_aliases', ]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,182 +1,176 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2016 Champs-Libres <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\MainBundle\Form\Type\Export;
|
||||
|
||||
use Chill\MainBundle\Center\GroupingCenterInterface;
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Export\ExportManager;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\CallbackTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Chill\MainBundle\Export\ExportManager;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Center\GroupingCenterInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\CallbackTransformer;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use function array_intersect;
|
||||
use function array_key_exists;
|
||||
use function array_merge;
|
||||
use function array_unique;
|
||||
use function in_array;
|
||||
|
||||
/**
|
||||
* Pick centers amongst available centers for the user
|
||||
*
|
||||
* Pick centers amongst available centers for the user.
|
||||
*/
|
||||
class PickCenterType extends AbstractType
|
||||
{
|
||||
public const CENTERS_IDENTIFIERS = 'c';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Symfony\Component\Security\Core\User\UserInterface
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var ExportManager
|
||||
*/
|
||||
protected $exportManager;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var GroupingCenterInterface[]
|
||||
*/
|
||||
protected $groupingCenters = [];
|
||||
|
||||
const CENTERS_IDENTIFIERS = 'c';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var AuthorizationHelper
|
||||
*/
|
||||
protected $authorizationHelper;
|
||||
|
||||
public function __construct(TokenStorageInterface $tokenStorage,
|
||||
ExportManager $exportManager, AuthorizationHelper $authorizationHelper)
|
||||
|
||||
/**
|
||||
* @var ExportManager
|
||||
*/
|
||||
protected $exportManager;
|
||||
|
||||
/**
|
||||
* @var GroupingCenterInterface[]
|
||||
*/
|
||||
protected $groupingCenters = [];
|
||||
|
||||
/**
|
||||
* @var \Symfony\Component\Security\Core\User\UserInterface
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
public function __construct(
|
||||
TokenStorageInterface $tokenStorage,
|
||||
ExportManager $exportManager,
|
||||
AuthorizationHelper $authorizationHelper
|
||||
)
|
||||
{
|
||||
$this->exportManager = $exportManager;
|
||||
$this->user = $tokenStorage->getToken()->getUser();
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
}
|
||||
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
|
||||
public function addGroupingCenter(GroupingCenterInterface $grouping)
|
||||
{
|
||||
$resolver->setRequired('export_alias')
|
||||
;
|
||||
$this->groupingCenters[md5($grouping->getName())] = $grouping;
|
||||
}
|
||||
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$export = $this->exportManager->getExport($options['export_alias']);
|
||||
$centers = $this->authorizationHelper->getReachableCenters($this->user,
|
||||
$export->requiredRole());
|
||||
|
||||
$builder->add(self::CENTERS_IDENTIFIERS, EntityType::class, array(
|
||||
'class' => 'ChillMainBundle:Center',
|
||||
'query_builder' => function(EntityRepository $er) use ($centers) {
|
||||
$centers = $this->authorizationHelper->getReachableCenters(
|
||||
$this->user,
|
||||
$export->requiredRole()
|
||||
);
|
||||
|
||||
$builder->add(self::CENTERS_IDENTIFIERS, EntityType::class, [
|
||||
'class' => 'ChillMainBundle:Center',
|
||||
'query_builder' => function (EntityRepository $er) use ($centers) {
|
||||
$qb = $er->createQueryBuilder('c');
|
||||
$ids = array_map(function(Center $el) { return $el->getId(); },
|
||||
$centers);
|
||||
$ids = array_map(
|
||||
function (Center $el) { return $el->getId(); },
|
||||
$centers
|
||||
);
|
||||
|
||||
return $qb->where($qb->expr()->in('c.id', $ids));
|
||||
},
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'choice_label' => function(Center $c) { return $c->getName(); },
|
||||
'data' => count($this->groupingCenters) > 0 ? null : $centers
|
||||
));
|
||||
|
||||
},
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'choice_label' => function (Center $c) { return $c->getName(); },
|
||||
'data' => count($this->groupingCenters) > 0 ? null : $centers,
|
||||
]);
|
||||
|
||||
if (count($this->groupingCenters) > 0) {
|
||||
$groupingBuilder = $builder->create('g', null, [
|
||||
'compound' => true
|
||||
'compound' => true,
|
||||
]);
|
||||
|
||||
foreach ($this->groupingCenters as $key => $gc) {
|
||||
$choices = $this->buildChoices($centers, $gc);
|
||||
|
||||
|
||||
if (count($choices) > 0) {
|
||||
$groupingBuilder->add($key, ChoiceType::class, [
|
||||
'choices' => $choices,
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'label' => $gc->getName(),
|
||||
'required' => false
|
||||
'required' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($groupingBuilder->count() > 0) {
|
||||
$builder->add($groupingBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$builder->addModelTransformer(new CallbackTransformer(
|
||||
function($data) use ($centers) { return $this->transform($data, $centers); },
|
||||
function($data) use ($centers) { return $this->reverseTransform($data, $centers); }
|
||||
));
|
||||
function ($data) use ($centers) { return $this->transform($data, $centers); },
|
||||
function ($data) use ($centers) { return $this->reverseTransform($data, $centers); }
|
||||
));
|
||||
}
|
||||
|
||||
public function addGroupingCenter(GroupingCenterInterface $grouping)
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$this->groupingCenters[md5($grouping->getName())] = $grouping;
|
||||
$resolver->setRequired('export_alias');
|
||||
}
|
||||
|
||||
|
||||
protected function buildChoices($reachablesCenters, GroupingCenterInterface $gc)
|
||||
{
|
||||
$result = [];
|
||||
|
||||
|
||||
foreach ($gc->getGroups() as $group) {
|
||||
foreach ($gc->getCentersForGroup($group) as $center) {
|
||||
if (\in_array($center, $reachablesCenters)) {
|
||||
if (in_array($center, $reachablesCenters)) {
|
||||
$result[$group] = $group;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
protected function reverseTransform($data, $centers)
|
||||
{
|
||||
$picked = $data[self::CENTERS_IDENTIFIERS]
|
||||
instanceof \Doctrine\Common\Collections\Collection ?
|
||||
$data[self::CENTERS_IDENTIFIERS]->toArray()
|
||||
:
|
||||
$data[self::CENTERS_IDENTIFIERS];
|
||||
|
||||
if (array_key_exists('g', $data)) {
|
||||
foreach ($data['g'] as $gcid => $group) {
|
||||
$picked =
|
||||
array_merge(
|
||||
array_intersect(
|
||||
$this->groupingCenters[$gcid]->getCentersForGroup($group),
|
||||
$centers
|
||||
),
|
||||
$picked
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return array_unique($picked);
|
||||
}
|
||||
|
||||
protected function transform($data, $centers)
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function reverseTransform($data, $centers)
|
||||
{
|
||||
$picked = $data[self::CENTERS_IDENTIFIERS]
|
||||
instanceof \Doctrine\Common\Collections\Collection ?
|
||||
$data[self::CENTERS_IDENTIFIERS]->toArray()
|
||||
:
|
||||
$data[self::CENTERS_IDENTIFIERS];
|
||||
|
||||
if (\array_key_exists('g', $data)) {
|
||||
foreach($data['g'] as $gcid => $group) {
|
||||
$picked =
|
||||
\array_merge(
|
||||
\array_intersect(
|
||||
$this->groupingCenters[$gcid] ->getCentersForGroup($group),
|
||||
$centers
|
||||
),
|
||||
$picked
|
||||
)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
return \array_unique($picked);
|
||||
}
|
||||
}
|
||||
|
@@ -1,36 +1,23 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2016 Champs-Libres <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\MainBundle\Form\Type\Export;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
|
||||
use Chill\MainBundle\Export\ExportManager;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* Choose a formatter amongst the available formatters
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* Choose a formatter amongst the available formatters.
|
||||
*/
|
||||
class PickFormatterType extends AbstractType
|
||||
{
|
||||
@@ -45,26 +32,26 @@ class PickFormatterType extends AbstractType
|
||||
{
|
||||
$export = $this->exportManager->getExport($options['export_alias']);
|
||||
$allowedFormatters = $this->exportManager
|
||||
->getFormattersByTypes($export->getAllowedFormattersTypes());
|
||||
->getFormattersByTypes($export->getAllowedFormattersTypes());
|
||||
|
||||
//build choices
|
||||
$choices = array();
|
||||
foreach($allowedFormatters as $alias => $formatter) {
|
||||
$choices = [];
|
||||
|
||||
foreach ($allowedFormatters as $alias => $formatter) {
|
||||
$choices[$formatter->getName()] = $alias;
|
||||
}
|
||||
|
||||
$builder->add('alias', ChoiceType::class, array(
|
||||
$builder->add('alias', ChoiceType::class, [
|
||||
'choices' => $choices,
|
||||
'multiple' => false,
|
||||
'placeholder' => 'Choose a format'
|
||||
));
|
||||
'placeholder' => 'Choose a format',
|
||||
]);
|
||||
|
||||
//$builder->get('type')->addModelTransformer($transformer);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setRequired(array('export_alias'));
|
||||
$resolver->setRequired(['export_alias']);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Form\Type\Listing;
|
||||
|
||||
use Chill\MainBundle\Templating\Listing\FilterOrderHelper;
|
||||
@@ -10,6 +17,8 @@ use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use function array_combine;
|
||||
use function array_map;
|
||||
|
||||
final class FilterOrderType extends \Symfony\Component\Form\AbstractType
|
||||
{
|
||||
@@ -28,17 +37,20 @@ final class FilterOrderType extends \Symfony\Component\Form\AbstractType
|
||||
if ($helper->hasSearchBox()) {
|
||||
$builder->add('q', SearchType::class, [
|
||||
'label' => false,
|
||||
'required' => false
|
||||
'required' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
$checkboxesBuilder = $builder->create('checkboxes', null, [ 'compound' => true ]);
|
||||
foreach ($helper->getCheckboxes() as $name => $c) {
|
||||
$checkboxesBuilder = $builder->create('checkboxes', null, ['compound' => true]);
|
||||
|
||||
$choices = \array_combine(
|
||||
\array_map(function($c, $t) {
|
||||
if ($t !== NULL) { return $t; }
|
||||
else { return $c; }
|
||||
foreach ($helper->getCheckboxes() as $name => $c) {
|
||||
$choices = array_combine(
|
||||
array_map(function ($c, $t) {
|
||||
if (null !== $t) {
|
||||
return $t;
|
||||
}
|
||||
|
||||
return $c;
|
||||
}, $c['choices'], $c['trans']),
|
||||
$c['choices']
|
||||
);
|
||||
@@ -55,19 +67,23 @@ final class FilterOrderType extends \Symfony\Component\Form\AbstractType
|
||||
}
|
||||
|
||||
foreach ($this->requestStack->getCurrentRequest()->query->getIterator() as $key => $value) {
|
||||
switch($key) {
|
||||
switch ($key) {
|
||||
case 'q':
|
||||
case 'checkboxes'.$key:
|
||||
case 'checkboxes' . $key:
|
||||
break;
|
||||
|
||||
case 'page':
|
||||
$builder->add($key, HiddenType::class, [
|
||||
'data' => 1
|
||||
'data' => 1,
|
||||
]);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
$builder->add($key, HiddenType::class, [
|
||||
'data' => $value
|
||||
'data' => $value,
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -79,14 +95,15 @@ final class FilterOrderType extends \Symfony\Component\Form\AbstractType
|
||||
$helper = $options['helper'];
|
||||
$view->vars['has_search_box'] = $helper->hasSearchBox();
|
||||
$view->vars['checkboxes'] = [];
|
||||
|
||||
foreach ($helper->getCheckboxes() as $name => $c) {
|
||||
$view->vars['checkboxes'][$name] = [];
|
||||
$view->vars['checkboxes'][$name] = [];
|
||||
}
|
||||
}
|
||||
|
||||
public function configureOptions(\Symfony\Component\OptionsResolver\OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setRequired('helper')
|
||||
->setAllowedTypes('helper', FilterOrderHelper::class);
|
||||
$resolver->setRequired('helper')
|
||||
->setAllowedTypes('helper', FilterOrderHelper::class);
|
||||
}
|
||||
}
|
||||
|
@@ -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.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Form\Type;
|
||||
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
@@ -11,6 +18,7 @@ use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use function uniqid;
|
||||
|
||||
/**
|
||||
* Form type for picking an address.
|
||||
@@ -33,6 +41,7 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
final class PickAddressType extends AbstractType
|
||||
{
|
||||
private AddressToIdDataTransformer $addressToIdDataTransformer;
|
||||
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
public function __construct(
|
||||
@@ -50,7 +59,7 @@ final class PickAddressType extends AbstractType
|
||||
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
{
|
||||
$view->vars['uniqid'] = $view->vars['attr']['data-input-address'] =\uniqid('input_address_');
|
||||
$view->vars['uniqid'] = $view->vars['attr']['data-input-address'] = uniqid('input_address_');
|
||||
$view->vars['attr']['data-use-valid-from'] = (int) $options['use_valid_from'];
|
||||
$view->vars['attr']['data-use-valid-to'] = (int) $options['use_valid_to'];
|
||||
$view->vars['attr']['data-button-text-create'] = $this->translator->trans($options['button_text_create']);
|
||||
|
@@ -1,56 +1,45 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015 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\MainBundle\Form\Type;
|
||||
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Form\Type\DataTransformer\CenterTransformer;
|
||||
use Chill\MainBundle\Repository\CenterRepository;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
||||
use RuntimeException;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\CallbackTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Form\Type\DataTransformer\CenterTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use function array_merge;
|
||||
use function array_values;
|
||||
|
||||
/**
|
||||
* Pick a center
|
||||
* Pick a center.
|
||||
*
|
||||
* For a given role and, eventually, scopes, show a dropdown (if more than
|
||||
* one reachable center) or a HiddenType (if one or zero center).
|
||||
*
|
||||
*
|
||||
*/
|
||||
class PickCenterType extends AbstractType
|
||||
{
|
||||
protected AuthorizationHelperInterface $authorizationHelper;
|
||||
|
||||
protected Security $security;
|
||||
|
||||
protected CenterRepository $centerRepository;
|
||||
|
||||
protected Security $security;
|
||||
|
||||
public function __construct(
|
||||
AuthorizationHelperInterface $authorizationHelper,
|
||||
Security $security,
|
||||
@@ -61,13 +50,64 @@ class PickCenterType extends AbstractType
|
||||
$this->centerRepository = $centerRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* add a data transformer if user can reach only one center.
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$centers = $this->getReachableCenters($options['role'], $options['scopes']);
|
||||
|
||||
if (count($centers) <= 1) {
|
||||
$multiple = $options['choice_options']['multiple'] ?? false;
|
||||
$builder->add('center', HiddenType::class);
|
||||
$builder->get('center')->addModelTransformer(
|
||||
new CenterTransformer($this->centerRepository, $multiple)
|
||||
);
|
||||
} else {
|
||||
$builder->add(
|
||||
'center',
|
||||
EntityType::class,
|
||||
array_merge(
|
||||
$options['choice_options'],
|
||||
[
|
||||
'class' => Center::class,
|
||||
'choices' => $centers,
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$builder
|
||||
->addModelTransformer(new CallbackTransformer(
|
||||
function ($data) {
|
||||
if (null === $data) {
|
||||
return ['center' => null];
|
||||
}
|
||||
|
||||
return ['center' => $data];
|
||||
},
|
||||
function ($data) {
|
||||
return $data['center'];
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
{
|
||||
$view->vars['is_hidden'] = count($this->getReachableCenters(
|
||||
$options['role'],
|
||||
$options['scopes']
|
||||
)) <= 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* return a 'hidden' field if only one center is available.
|
||||
*
|
||||
* Return a 'choice' field if more than one center is available.
|
||||
*
|
||||
* @throws RuntimeException if the user is not associated with any center
|
||||
*
|
||||
* @return string
|
||||
* @throws \RuntimeException if the user is not associated with any center
|
||||
*/
|
||||
/*
|
||||
public function getParent()
|
||||
@@ -80,71 +120,26 @@ class PickCenterType extends AbstractType
|
||||
return EntityType::class;
|
||||
}
|
||||
}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* configure default options, i.e. add choices if user can reach multiple
|
||||
* centers.
|
||||
*
|
||||
* @param OptionsResolver $resolver
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver
|
||||
->setDefault('class', Center::class)
|
||||
->setRequired('role')
|
||||
->setAllowedTypes('role', [ 'string' ])
|
||||
->setAllowedTypes('role', ['string'])
|
||||
->setDefault('scopes', [])
|
||||
->setAllowedTypes('scopes', ['iterable'])
|
||||
->setDefault('choice_options', [])
|
||||
;
|
||||
->setDefault('choice_options', []);
|
||||
/*
|
||||
->setDefault('choices', $this->reachableCenters)
|
||||
->setDefault('placeholder', 'Pick a center')
|
||||
;
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* add a data transformer if user can reach only one center
|
||||
*
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param array $options
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$centers = $this->getReachableCenters($options['role'], $options['scopes']);
|
||||
|
||||
if (count($centers) <= 1) {
|
||||
$multiple = $options['choice_options']['multiple'] ?? false;
|
||||
$builder->add('center', HiddenType::class);
|
||||
$builder->get('center')->addModelTransformer(
|
||||
new CenterTransformer($this->centerRepository, $multiple)
|
||||
);
|
||||
} else {
|
||||
$builder->add('center', EntityType::class,
|
||||
\array_merge(
|
||||
$options['choice_options'],
|
||||
[
|
||||
'class' => Center::class,
|
||||
'choices' => $centers
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$builder
|
||||
->addModelTransformer(new CallbackTransformer(
|
||||
function($data) {
|
||||
if (NULL === $data) {
|
||||
return ['center' => null];
|
||||
}
|
||||
return ['center' => $data];
|
||||
},
|
||||
function($data) {
|
||||
return $data['center'];
|
||||
}
|
||||
));
|
||||
*/
|
||||
}
|
||||
|
||||
private function getReachableCenters(string $role, iterable $scopes): array
|
||||
@@ -152,23 +147,17 @@ class PickCenterType extends AbstractType
|
||||
if (0 < count($scopes)) {
|
||||
$centers = [];
|
||||
|
||||
foreach($scopes as $scope) {
|
||||
foreach ($scopes as $scope) {
|
||||
foreach ($this->authorizationHelper
|
||||
->getReachableCenters($this->security->getUser(), $role, $scope) as $center) {
|
||||
->getReachableCenters($this->security->getUser(), $role, $scope) as $center) {
|
||||
$centers[spl_object_hash($center)] = $center;
|
||||
}
|
||||
}
|
||||
|
||||
return \array_values($centers);
|
||||
} else {
|
||||
return $this->authorizationHelper
|
||||
->getReachableCenters($this->security->getUser(), $role);
|
||||
return array_values($centers);
|
||||
}
|
||||
}
|
||||
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
{
|
||||
$view->vars['is_hidden'] = count($this->getReachableCenters($options['role'],
|
||||
$options['scopes'])) <= 1;
|
||||
return $this->authorizationHelper
|
||||
->getReachableCenters($this->security->getUser(), $role);
|
||||
}
|
||||
}
|
||||
|
@@ -1,67 +1,50 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2016 Champs-Libres <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\MainBundle\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\MainBundle\Entity\PostalCode;
|
||||
use Chill\MainBundle\Form\ChoiceLoader\PostalCodeChoiceLoader;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Chill\MainBundle\Form\ChoiceLoader\PostalCodeChoiceLoader;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
|
||||
/**
|
||||
* A form to pick between PostalCode
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @author Champs Libres <info@champs-libres.coop>
|
||||
* A form to pick between PostalCode.
|
||||
*/
|
||||
class PostalCodeType extends AbstractType
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var TranslatableStringHelper
|
||||
*/
|
||||
protected $translatableStringHelper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var UrlGeneratorInterface
|
||||
*/
|
||||
protected $urlGenerator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var PostalCodeChoiceLoader
|
||||
*/
|
||||
protected $choiceLoader;
|
||||
|
||||
|
||||
/**
|
||||
* @var TranslatableStringHelper
|
||||
*/
|
||||
protected $translatableStringHelper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
/**
|
||||
* @var UrlGeneratorInterface
|
||||
*/
|
||||
protected $urlGenerator;
|
||||
|
||||
public function __construct(
|
||||
TranslatableStringHelper $helper,
|
||||
UrlGeneratorInterface $urlGenerator,
|
||||
@@ -74,27 +57,6 @@ class PostalCodeType extends AbstractType
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
|
||||
public function getParent()
|
||||
{
|
||||
return EntityType::class;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
// create a local copy for usage in Closure
|
||||
$helper = $this->translatableStringHelper;
|
||||
$resolver
|
||||
->setDefault('class', PostalCode::class)
|
||||
->setDefault('choice_label', function(PostalCode $code) use ($helper) {
|
||||
return $code->getCode().' '.$code->getName().' ['.
|
||||
$helper->localize($code->getCountry()->getName()).']';
|
||||
})
|
||||
->setDefault('choice_loader', $this->choiceLoader)
|
||||
->setDefault('placeholder', 'Select a postal code')
|
||||
;
|
||||
}
|
||||
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
{
|
||||
$view->vars['attr']['data-postal-code'] = 'data-postal-code';
|
||||
@@ -107,4 +69,22 @@ class PostalCodeType extends AbstractType
|
||||
$view->vars['attr']['data-searching-label'] = $this->translator->trans('select2.searching');
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
// create a local copy for usage in Closure
|
||||
$helper = $this->translatableStringHelper;
|
||||
$resolver
|
||||
->setDefault('class', PostalCode::class)
|
||||
->setDefault('choice_label', function (PostalCode $code) use ($helper) {
|
||||
return $code->getCode() . ' ' . $code->getName() . ' [' .
|
||||
$helper->localize($code->getCountry()->getName()) . ']';
|
||||
})
|
||||
->setDefault('choice_loader', $this->choiceLoader)
|
||||
->setDefault('placeholder', 'Select a postal code');
|
||||
}
|
||||
|
||||
public function getParent()
|
||||
{
|
||||
return EntityType::class;
|
||||
}
|
||||
}
|
||||
|
@@ -1,19 +1,10 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2017 Champs Libres Cooperative <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\MainBundle\Form\Type;
|
||||
@@ -23,11 +14,8 @@ use Chill\MainBundle\Entity\Scope;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Form\DataMapper\ScopePickerDataMapper;
|
||||
use Chill\MainBundle\Repository\ScopeRepository;
|
||||
use Chill\MainBundle\Repository\UserACLAwareRepositoryInterface;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
@@ -39,6 +27,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use function array_map;
|
||||
|
||||
/**
|
||||
* Allow to pick amongst available scope for the current
|
||||
@@ -48,29 +37,28 @@ use Symfony\Component\Security\Core\Security;
|
||||
*
|
||||
* - `center`: the center of the entity
|
||||
* - `role` : the role of the user
|
||||
*
|
||||
*/
|
||||
class ScopePickerType extends AbstractType
|
||||
{
|
||||
protected AuthorizationHelperInterface $authorizationHelper;
|
||||
|
||||
/**
|
||||
* @var ScopeRepository
|
||||
*/
|
||||
protected $scopeRepository;
|
||||
|
||||
protected Security $security;
|
||||
|
||||
/**
|
||||
* @var TokenStorageInterface
|
||||
*/
|
||||
protected $tokenStorage;
|
||||
|
||||
/**
|
||||
* @var ScopeRepository
|
||||
*/
|
||||
protected $scopeRepository;
|
||||
|
||||
/**
|
||||
* @var TranslatableStringHelper
|
||||
*/
|
||||
protected $translatableStringHelper;
|
||||
|
||||
protected Security $security;
|
||||
|
||||
public function __construct(
|
||||
AuthorizationHelperInterface $authorizationHelper,
|
||||
TokenStorageInterface $tokenStorage,
|
||||
@@ -87,8 +75,11 @@ class ScopePickerType extends AbstractType
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$items = $this->authorizationHelper->getReachableScopes($this->security->getUser(),
|
||||
$options['role'], $options['center']);
|
||||
$items = $this->authorizationHelper->getReachableScopes(
|
||||
$this->security->getUser(),
|
||||
$options['role'],
|
||||
$options['center']
|
||||
);
|
||||
|
||||
if (1 !== count($items)) {
|
||||
$builder->add('scope', EntityType::class, [
|
||||
@@ -111,7 +102,8 @@ class ScopePickerType extends AbstractType
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
{
|
||||
$view->vars = array_replace(
|
||||
$view->vars, [
|
||||
$view->vars,
|
||||
[
|
||||
'hideLabel' => true,
|
||||
]
|
||||
);
|
||||
@@ -129,15 +121,16 @@ class ScopePickerType extends AbstractType
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Center|array|Center[] $center
|
||||
* @param array|Center|Center[] $center
|
||||
* @param string $role
|
||||
*
|
||||
* @return \Doctrine\ORM\QueryBuilder
|
||||
*/
|
||||
protected function buildAccessibleScopeQuery($center, $role)
|
||||
{
|
||||
$roles = $this->authorizationHelper->getParentRoles($role);
|
||||
$roles[] = $role;
|
||||
$centers = $center instanceof Center ? [$center]: $center;
|
||||
$centers = $center instanceof Center ? [$center] : $center;
|
||||
|
||||
$qb = $this->scopeRepository->createQueryBuilder('s');
|
||||
$qb
|
||||
@@ -147,13 +140,13 @@ class ScopePickerType extends AbstractType
|
||||
->join('pg.groupCenters', 'gc')
|
||||
// add center constraint
|
||||
->where($qb->expr()->in('IDENTITY(gc.center)', ':centers'))
|
||||
->setParameter('centers', \array_map(fn(Center $c) => $c->getId(), $centers))
|
||||
->setParameter('centers', array_map(fn (Center $c) => $c->getId(), $centers))
|
||||
// role constraints
|
||||
->andWhere($qb->expr()->in('rs.role', ':roles'))
|
||||
->setParameter('roles', $roles)
|
||||
// user contraint
|
||||
->andWhere(':user MEMBER OF gc.users')
|
||||
->setParameter('user', $this->tokenStorage->getToken()->getUser());
|
||||
->andWhere(':user MEMBER OF gc.users')
|
||||
->setParameter('user', $this->tokenStorage->getToken()->getUser());
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
@@ -1,36 +1,32 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
* Copyright (C) 2014 Champs-Libres Coopérative <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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* Extends choice to allow adding select2 library on widget
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* Extends choice to allow adding select2 library on widget.
|
||||
*/
|
||||
class Select2ChoiceType extends AbstractType
|
||||
{
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(
|
||||
[
|
||||
'attr' => ['class' => 'select2 '],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'select2_choice';
|
||||
@@ -40,12 +36,4 @@ class Select2ChoiceType extends AbstractType
|
||||
{
|
||||
return ChoiceType::class;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(
|
||||
array(
|
||||
'attr' => array('class' => 'select2 '),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@@ -1,80 +1,54 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Chill\MainBundle\Form\Type\DataTransformer\ObjectToIdTransformer;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Chill\MainBundle\Form\Type\Select2ChoiceType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* Extends choice to allow adding select2 library on widget
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @author Marc Ducobu <marc.ducobu@champs-libres.coop>
|
||||
* Extends choice to allow adding select2 library on widget.
|
||||
*/
|
||||
class Select2CountryType extends AbstractType
|
||||
{
|
||||
private RequestStack $requestStack;
|
||||
|
||||
private ObjectManager $em;
|
||||
protected ParameterBagInterface $parameterBag;
|
||||
|
||||
protected TranslatableStringHelper $translatableStringHelper;
|
||||
|
||||
protected ParameterBagInterface $parameterBag;
|
||||
private ObjectManager $em;
|
||||
|
||||
private RequestStack $requestStack;
|
||||
|
||||
public function __construct(
|
||||
RequestStack $requestStack,
|
||||
ObjectManager $em,
|
||||
TranslatableStringHelper $translatableStringHelper,
|
||||
ParameterBagInterface $parameterBag
|
||||
)
|
||||
{
|
||||
) {
|
||||
$this->requestStack = $requestStack;
|
||||
$this->em = $em;
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
$this->parameterBag = $parameterBag;
|
||||
}
|
||||
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'select2_chill_country';
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$transformer = new ObjectToIdTransformer($this->em,'Chill\MainBundle\Entity\Country');
|
||||
$transformer = new ObjectToIdTransformer($this->em, 'Chill\MainBundle\Entity\Country');
|
||||
$builder->addModelTransformer($transformer);
|
||||
}
|
||||
|
||||
public function getParent()
|
||||
{
|
||||
return Select2ChoiceType::class;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$countries = $this->em->getRepository('Chill\MainBundle\Entity\Country')->findAll();
|
||||
@@ -96,10 +70,20 @@ class Select2CountryType extends AbstractType
|
||||
|
||||
asort($choices, SORT_STRING | SORT_FLAG_CASE);
|
||||
|
||||
$resolver->setDefaults(array(
|
||||
'class' => 'Chill\MainBundle\Entity\Country',
|
||||
'choices' => array_combine(array_values($choices),array_keys($choices)),
|
||||
'preferred_choices' => array_combine(array_values($preferredChoices), array_keys($preferredChoices))
|
||||
));
|
||||
$resolver->setDefaults([
|
||||
'class' => 'Chill\MainBundle\Entity\Country',
|
||||
'choices' => array_combine(array_values($choices), array_keys($choices)),
|
||||
'preferred_choices' => array_combine(array_values($preferredChoices), array_keys($preferredChoices)),
|
||||
]);
|
||||
}
|
||||
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'select2_chill_country';
|
||||
}
|
||||
|
||||
public function getParent()
|
||||
{
|
||||
return Select2ChoiceType::class;
|
||||
}
|
||||
}
|
||||
|
@@ -1,36 +1,30 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
* Copyright (C) 2014 Champs-Libres Coopérative <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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Form\Type;
|
||||
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
|
||||
/**
|
||||
* Extends choice to allow adding select2 library on widget
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* Extends choice to allow adding select2 library on widget.
|
||||
*/
|
||||
class Select2EntityType extends AbstractType
|
||||
{
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->replaceDefaults(
|
||||
['attr' => ['class' => 'select2 ']]
|
||||
);
|
||||
}
|
||||
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'select2_entity';
|
||||
@@ -40,11 +34,4 @@ class Select2EntityType extends AbstractType
|
||||
{
|
||||
return EntityType::class;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->replaceDefaults(
|
||||
array('attr' => array('class' => 'select2 '))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -1,77 +1,54 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Chill\MainBundle\Form\Type\DataTransformer\MultipleObjectsToIdTransformer;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Chill\MainBundle\Form\Type\Select2ChoiceType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* Extends choice to allow adding select2 library on widget for languages (multiple)
|
||||
* Extends choice to allow adding select2 library on widget for languages (multiple).
|
||||
*/
|
||||
class Select2LanguageType extends AbstractType
|
||||
{
|
||||
private RequestStack $requestStack;
|
||||
|
||||
private ObjectManager $em;
|
||||
protected ParameterBagInterface $parameterBag;
|
||||
|
||||
protected TranslatableStringHelper $translatableStringHelper;
|
||||
|
||||
protected ParameterBagInterface $parameterBag;
|
||||
private ObjectManager $em;
|
||||
|
||||
private RequestStack $requestStack;
|
||||
|
||||
public function __construct(
|
||||
RequestStack $requestStack,
|
||||
ObjectManager $em,
|
||||
TranslatableStringHelper $translatableStringHelper,
|
||||
ParameterBagInterface $parameterBag
|
||||
)
|
||||
{
|
||||
) {
|
||||
$this->requestStack = $requestStack;
|
||||
$this->em = $em;
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
$this->parameterBag = $parameterBag;
|
||||
}
|
||||
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'select2_chill_language';
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$transformer = new MultipleObjectsToIdTransformer($this->em,'Chill\MainBundle\Entity\Language');
|
||||
$transformer = new MultipleObjectsToIdTransformer($this->em, 'Chill\MainBundle\Entity\Language');
|
||||
$builder->addModelTransformer($transformer);
|
||||
}
|
||||
|
||||
public function getParent()
|
||||
{
|
||||
return Select2ChoiceType::class;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$languages = $this->em->getRepository('Chill\MainBundle\Entity\Language')->findAll();
|
||||
@@ -82,16 +59,27 @@ class Select2LanguageType extends AbstractType
|
||||
foreach ($languages as $l) {
|
||||
$choices[$l->getId()] = $this->translatableStringHelper->localize($l->getName());
|
||||
}
|
||||
|
||||
foreach ($preferredLanguages as $l) {
|
||||
$preferredChoices[$l] = $choices[$l];
|
||||
}
|
||||
|
||||
asort($choices, SORT_STRING | SORT_FLAG_CASE);
|
||||
|
||||
$resolver->setDefaults(array(
|
||||
'class' => 'Chill\MainBundle\Entity\Language',
|
||||
'choices' => array_combine(array_values($choices), array_keys($choices)),
|
||||
'preferred_choices' => array_combine(array_values($preferredChoices), array_keys($preferredChoices))
|
||||
));
|
||||
$resolver->setDefaults([
|
||||
'class' => 'Chill\MainBundle\Entity\Language',
|
||||
'choices' => array_combine(array_values($choices), array_keys($choices)),
|
||||
'preferred_choices' => array_combine(array_values($preferredChoices), array_keys($preferredChoices)),
|
||||
]);
|
||||
}
|
||||
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'select2_chill_language';
|
||||
}
|
||||
|
||||
public function getParent()
|
||||
{
|
||||
return Select2ChoiceType::class;
|
||||
}
|
||||
}
|
||||
|
@@ -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.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Form\Type;
|
||||
|
||||
/*
|
||||
@@ -7,25 +14,33 @@ namespace Chill\MainBundle\Form\Type;
|
||||
*/
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Translation\Translator;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
|
||||
class TranslatableStringFormType extends AbstractType
|
||||
{
|
||||
private $availableLanguages; // The langauges availaible
|
||||
|
||||
private $frameworkTranslatorFallback; // The langagues used for the translation
|
||||
|
||||
public function __construct(array $availableLanguages, Translator $translator) {
|
||||
public function __construct(array $availableLanguages, Translator $translator)
|
||||
{
|
||||
$this->availableLanguages = $availableLanguages;
|
||||
$this->frameworkTranslatorFallback = $translator->getFallbackLocales();
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options) {
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
foreach ($this->availableLanguages as $lang) {
|
||||
$builder->add($lang, TextType::class,
|
||||
array('required' => (in_array($lang,
|
||||
$this->frameworkTranslatorFallback))));
|
||||
$builder->add(
|
||||
$lang,
|
||||
TextType::class,
|
||||
['required' => (in_array(
|
||||
$lang,
|
||||
$this->frameworkTranslatorFallback
|
||||
))]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,37 +1,26 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2017 Champs Libres Cooperative <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\MainBundle\Form\Type;
|
||||
|
||||
use Chill\MainBundle\Entity\Scope;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Repository\UserACLAwareRepositoryInterface;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Chill\MainBundle\Repository\UserRepository;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\OptionsResolver\Options;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Repository\UserRepository;
|
||||
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
|
||||
|
||||
/**
|
||||
* Pick a user available for the given role and center.
|
||||
*
|
||||
@@ -39,27 +28,23 @@ use Symfony\Component\Security\Core\Role\Role;
|
||||
*
|
||||
* - `role` : the role the user can reach
|
||||
* - `center`: the center a user can reach
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class UserPickerType extends AbstractType
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var AuthorizationHelper
|
||||
*/
|
||||
protected $authorizationHelper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var TokenStorageInterface
|
||||
*/
|
||||
protected $tokenStorage;
|
||||
|
||||
protected UserRepository $userRepository;
|
||||
|
||||
protected UserACLAwareRepositoryInterface $userACLAwareRepository;
|
||||
|
||||
protected UserRepository $userRepository;
|
||||
|
||||
public function __construct(
|
||||
AuthorizationHelper $authorizationHelper,
|
||||
TokenStorageInterface $tokenStorage,
|
||||
@@ -72,42 +57,37 @@ class UserPickerType extends AbstractType
|
||||
$this->userACLAwareRepository = $userACLAwareRepository;
|
||||
}
|
||||
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver
|
||||
// create `center` option
|
||||
->setRequired('center')
|
||||
->setAllowedTypes('center', [\Chill\MainBundle\Entity\Center::class, 'null', 'array' ])
|
||||
->setAllowedTypes('center', [\Chill\MainBundle\Entity\Center::class, 'null', 'array'])
|
||||
// create ``role` option
|
||||
->setRequired('role')
|
||||
->setAllowedTypes('role', ['string', \Symfony\Component\Security\Core\Role\Role::class ])
|
||||
;
|
||||
->setAllowedTypes('role', ['string', \Symfony\Component\Security\Core\Role\Role::class]);
|
||||
|
||||
$resolver
|
||||
->setDefault('having_permissions_group_flag', null)
|
||||
->setAllowedTypes('having_permissions_group_flag', ['string', 'null'])
|
||||
->setDefault('class', User::class)
|
||||
->setDefault('placeholder', 'Choose an user')
|
||||
->setDefault('choice_label', function(User $u) {
|
||||
->setDefault('choice_label', function (User $u) {
|
||||
return $u->getUsername();
|
||||
})
|
||||
->setDefault('scope', null)
|
||||
->setAllowedTypes('scope', [Scope::class, 'array', 'null'])
|
||||
->setNormalizer('choices', function(Options $options) {
|
||||
|
||||
->setNormalizer('choices', function (Options $options) {
|
||||
$users = $this->userACLAwareRepository
|
||||
->findUsersByReachedACL($options['role'], $options['center'], $options['scope'], true);
|
||||
|
||||
if (NULL !== $options['having_permissions_group_flag']) {
|
||||
if (null !== $options['having_permissions_group_flag']) {
|
||||
return $this->userRepository
|
||||
->findUsersHavingFlags($options['having_permissions_group_flag'], $users)
|
||||
;
|
||||
->findUsersHavingFlags($options['having_permissions_group_flag'], $users);
|
||||
}
|
||||
|
||||
return $users;
|
||||
})
|
||||
;
|
||||
});
|
||||
}
|
||||
|
||||
public function getParent()
|
||||
|
@@ -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.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Form;
|
||||
|
||||
use Chill\MainBundle\Entity\Location;
|
||||
@@ -9,15 +16,12 @@ use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
|
||||
class UserCurrentLocationType extends AbstractType
|
||||
{
|
||||
private LocationRepository $locationRepository;
|
||||
|
||||
private TranslatableStringHelper $translatableStringHelper;
|
||||
|
||||
/**
|
||||
* @param TranslatableStringHelper $translatableStringHelper
|
||||
*/
|
||||
public function __construct(TranslatableStringHelper $translatableStringHelper, LocationRepository $locationRepository)
|
||||
{
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
@@ -32,7 +36,7 @@ class UserCurrentLocationType extends AbstractType
|
||||
'choices' => $this->locationRepository->findByPublicLocations(),
|
||||
'choice_label' => function (Location $entity) {
|
||||
return $entity->getName() ?
|
||||
$entity->getName().' ('.$this->translatableStringHelper->localize($entity->getLocationType()->getTitle()).')' :
|
||||
$entity->getName() . ' (' . $this->translatableStringHelper->localize($entity->getLocationType()->getTitle()) . ')' :
|
||||
$this->translatableStringHelper->localize($entity->getLocationType()->getTitle());
|
||||
},
|
||||
'placeholder' => 'Pick a location',
|
||||
|
@@ -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.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Form;
|
||||
|
||||
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||
@@ -13,15 +20,13 @@ class UserJobType extends \Symfony\Component\Form\AbstractType
|
||||
$builder
|
||||
->add('label', TranslatableStringFormType::class, [
|
||||
'label' => 'Label',
|
||||
'required' => true
|
||||
'required' => true,
|
||||
])
|
||||
->add('active', ChoiceType::class, [
|
||||
'choices' => [
|
||||
'Active' => true,
|
||||
'Inactive' => false
|
||||
]
|
||||
])
|
||||
;
|
||||
'Inactive' => false,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,104 +1,102 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Form;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
|
||||
use Symfony\Component\Validator\Constraints\Callback;
|
||||
use Symfony\Component\Validator\Constraints\Length;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Symfony\Component\Validator\Constraints\Regex;
|
||||
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
||||
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraints\Callback;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class UserPasswordType extends AbstractType
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var UserPasswordEncoderInterface
|
||||
*/
|
||||
protected $passwordEncoder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
protected $chillLogger;
|
||||
|
||||
|
||||
/**
|
||||
* @var UserPasswordEncoderInterface
|
||||
*/
|
||||
protected $passwordEncoder;
|
||||
|
||||
public function __construct(
|
||||
UserPasswordEncoderInterface $passwordEncoder,
|
||||
UserPasswordEncoderInterface $passwordEncoder,
|
||||
LoggerInterface $chillLogger
|
||||
) {
|
||||
$this->passwordEncoder = $passwordEncoder;
|
||||
$this->chillLogger = $chillLogger;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param array $options
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('new_password', RepeatedType::class, array(
|
||||
->add('new_password', RepeatedType::class, [
|
||||
'type' => PasswordType::class,
|
||||
'required' => false,
|
||||
'options' => array(),
|
||||
'first_options' => array(
|
||||
'label' => 'Password'
|
||||
),
|
||||
'second_options' => array(
|
||||
'label' => 'Repeat the password'
|
||||
),
|
||||
'invalid_message' => "The password fields must match",
|
||||
'constraints' => array(
|
||||
new Length(array(
|
||||
'options' => [],
|
||||
'first_options' => [
|
||||
'label' => 'Password',
|
||||
],
|
||||
'second_options' => [
|
||||
'label' => 'Repeat the password',
|
||||
],
|
||||
'invalid_message' => 'The password fields must match',
|
||||
'constraints' => [
|
||||
new Length([
|
||||
'min' => 9,
|
||||
'minMessage' => 'The password must be greater than {{ limit }} characters'
|
||||
)),
|
||||
'minMessage' => 'The password must be greater than {{ limit }} characters',
|
||||
]),
|
||||
new NotBlank(),
|
||||
new Regex(array(
|
||||
'pattern' => "/((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%!,;:+\"'-\/{}~=µ\(\)£]).{6,})/",
|
||||
'message' => "The password must contains one letter, one "
|
||||
. "capitalized letter, one number and one special character "
|
||||
. "as *[@#$%!,;:+\"'-/{}~=µ()£]). Other characters are allowed."
|
||||
))
|
||||
)
|
||||
))
|
||||
new Regex([
|
||||
'pattern' => "/((?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%!,;:+\"'-\\/{}~=µ\\(\\)£]).{6,})/",
|
||||
'message' => 'The password must contains one letter, one '
|
||||
. 'capitalized letter, one number and one special character '
|
||||
. "as *[@#$%!,;:+\"'-/{}~=µ()£]). Other characters are allowed.",
|
||||
]),
|
||||
],
|
||||
])
|
||||
->add('actual_password', PasswordType::class, [
|
||||
'label' => 'Your actual password',
|
||||
'mapped' => false,
|
||||
'constraints' => [
|
||||
new Callback([
|
||||
'callback' => function($password, ExecutionContextInterface $context, $payload) use ($options) {
|
||||
if (TRUE === $this->passwordEncoder->isPasswordValid($options['user'], $password)) {
|
||||
'callback' => function ($password, ExecutionContextInterface $context, $payload) use ($options) {
|
||||
if (true === $this->passwordEncoder->isPasswordValid($options['user'], $password)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// password problem :-)
|
||||
$this->chillLogger
|
||||
->notice("incorrect password when trying to change password", [
|
||||
'username' => $options['user']->getUsername()
|
||||
->notice('incorrect password when trying to change password', [
|
||||
'username' => $options['user']->getUsername(),
|
||||
]);
|
||||
$context->addViolation('Incorrect password');
|
||||
}
|
||||
])
|
||||
]
|
||||
])
|
||||
;
|
||||
},
|
||||
]),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver
|
||||
->setRequired('user')
|
||||
->setAllowedTypes('user', \Chill\MainBundle\Entity\User::class)
|
||||
;
|
||||
->setAllowedTypes('user', \Chill\MainBundle\Entity\User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Form;
|
||||
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
@@ -9,41 +16,32 @@ use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
|
||||
use Symfony\Component\Validator\Constraints\Length;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Symfony\Component\Validator\Constraints\Regex;
|
||||
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
||||
|
||||
use Chill\MainBundle\Form\UserPasswordType;
|
||||
|
||||
class UserType extends AbstractType
|
||||
{
|
||||
private TranslatableStringHelper $translatableStringHelper;
|
||||
|
||||
/**
|
||||
* @param TranslatableStringHelper $translatableStringHelper
|
||||
*/
|
||||
public function __construct(TranslatableStringHelper $translatableStringHelper)
|
||||
{
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param array $options
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('username')
|
||||
->add('email', EmailType::class, [
|
||||
'required' => true
|
||||
'required' => true,
|
||||
])
|
||||
->add('label', TextType::class)
|
||||
->add('mainCenter', EntityType::class, [
|
||||
@@ -56,7 +54,7 @@ class UserType extends AbstractType
|
||||
$qb->addOrderBy('c.name');
|
||||
|
||||
return $qb;
|
||||
}
|
||||
},
|
||||
])
|
||||
->add('mainScope', EntityType::class, [
|
||||
'label' => 'Main scope',
|
||||
@@ -75,47 +73,47 @@ class UserType extends AbstractType
|
||||
'choice_label' => function (UserJob $c) {
|
||||
return $this->translatableStringHelper->localize($c->getLabel());
|
||||
},
|
||||
])
|
||||
;
|
||||
]);
|
||||
|
||||
if ($options['is_creation']) {
|
||||
$builder->add('plainPassword', RepeatedType::class, array(
|
||||
$builder->add('plainPassword', RepeatedType::class, [
|
||||
'mapped' => false,
|
||||
'type' => PasswordType::class,
|
||||
'required' => false,
|
||||
'options' => array(),
|
||||
'first_options' => array(
|
||||
'label' => 'Password'
|
||||
),
|
||||
'second_options' => array(
|
||||
'label' => 'Repeat the password'
|
||||
),
|
||||
'invalid_message' => "The password fields must match",
|
||||
'constraints' => array(
|
||||
new Length(array(
|
||||
'options' => [],
|
||||
'first_options' => [
|
||||
'label' => 'Password',
|
||||
],
|
||||
'second_options' => [
|
||||
'label' => 'Repeat the password',
|
||||
],
|
||||
'invalid_message' => 'The password fields must match',
|
||||
'constraints' => [
|
||||
new Length([
|
||||
'min' => 9,
|
||||
'minMessage' => 'The password must be greater than {{ limit }} characters'
|
||||
)),
|
||||
'minMessage' => 'The password must be greater than {{ limit }} characters',
|
||||
]),
|
||||
new NotBlank(),
|
||||
new Regex(array(
|
||||
'pattern' => "/((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%!,;:+\"'-\/{}~=µ\(\)£]).{6,})/",
|
||||
'message' => "The password must contains one letter, one "
|
||||
. "capitalized letter, one number and one special character "
|
||||
. "as *[@#$%!,;:+\"'-/{}~=µ()£]). Other characters are allowed."
|
||||
))
|
||||
)
|
||||
));
|
||||
|
||||
new Regex([
|
||||
'pattern' => "/((?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%!,;:+\"'-\\/{}~=µ\\(\\)£]).{6,})/",
|
||||
'message' => 'The password must contains one letter, one '
|
||||
. 'capitalized letter, one number and one special character '
|
||||
. "as *[@#$%!,;:+\"'-/{}~=µ()£]). Other characters are allowed.",
|
||||
]),
|
||||
],
|
||||
]);
|
||||
} else {
|
||||
$builder->add($builder
|
||||
->create('enabled', ChoiceType::class, array(
|
||||
'choices' => array(
|
||||
'Disabled, the user is not allowed to login' => 0,
|
||||
'Enabled, the user is active' => 1
|
||||
),
|
||||
'expanded' => false,
|
||||
'multiple' => false,
|
||||
))
|
||||
);
|
||||
$builder->add(
|
||||
$builder
|
||||
->create('enabled', ChoiceType::class, [
|
||||
'choices' => [
|
||||
'Disabled, the user is not allowed to login' => 0,
|
||||
'Enabled, the user is active' => 1,
|
||||
],
|
||||
'expanded' => false,
|
||||
'multiple' => false,
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,14 +122,13 @@ class UserType extends AbstractType
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'Chill\MainBundle\Entity\User'
|
||||
));
|
||||
$resolver->setDefaults([
|
||||
'data_class' => 'Chill\MainBundle\Entity\User',
|
||||
]);
|
||||
|
||||
$resolver
|
||||
->setDefaults(array('is_creation' => false))
|
||||
->addAllowedValues('is_creation', array(true, false))
|
||||
;
|
||||
->setDefaults(['is_creation' => false])
|
||||
->addAllowedValues('is_creation', [true, false]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,17 +1,19 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Form\Utils;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
interface PermissionsGroupFlagProvider
|
||||
{
|
||||
/**
|
||||
* Return an array of flags
|
||||
*
|
||||
* Return an array of flags.
|
||||
*
|
||||
* @return string[] an array. Keys are ignored.
|
||||
*/
|
||||
public function getPermissionsGroupFlags(): array;
|
||||
|
Reference in New Issue
Block a user