mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,4 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Form;
|
||||
@@ -12,11 +20,14 @@ class AccompanyingCourseType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->add('closingDate', ChillDateType::class,
|
||||
[
|
||||
'required' => true,
|
||||
]);
|
||||
$builder->add(
|
||||
'closingDate',
|
||||
ChillDateType::class,
|
||||
[
|
||||
'required' => true,
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('closingMotive', ClosingMotivePickerType::class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,25 +1,29 @@
|
||||
<?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\PersonBundle\Form;
|
||||
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Chill\MainBundle\Form\Type\ChillTextareaType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
use Chill\MainBundle\Form\Type\UserPickerType;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Chill\PersonBundle\Form\Type\ClosingMotivePickerType;
|
||||
|
||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
|
||||
/**
|
||||
* Class AccompanyingPeriodType
|
||||
*
|
||||
* @package Chill\PersonBundle\Form
|
||||
* Class AccompanyingPeriodType.
|
||||
*/
|
||||
class AccompanyingPeriodType extends AbstractType
|
||||
{
|
||||
@@ -34,72 +38,65 @@ class AccompanyingPeriodType extends AbstractType
|
||||
protected $config = [];
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string[] $config configuration of visibility of some fields
|
||||
*/
|
||||
public function __construct(array $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param array $options
|
||||
*/
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
//if the period_action is close, date opening should not be seen
|
||||
if ($options['period_action'] !== 'close') {
|
||||
if ('close' !== $options['period_action']) {
|
||||
$builder
|
||||
->add('openingDate', DateType::class, [
|
||||
"required" => true,
|
||||
'widget' => 'single_text',
|
||||
'format' => 'dd-MM-yyyy'
|
||||
])
|
||||
;
|
||||
'required' => true,
|
||||
'widget' => 'single_text',
|
||||
'format' => 'dd-MM-yyyy',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
// closingDate should be seen only if
|
||||
// period_action = close
|
||||
// OR ( period_action = update AND accompanying period is already closed )
|
||||
$accompanyingPeriod = $options['data'];
|
||||
|
||||
|
||||
if (
|
||||
($options['period_action'] === 'close')
|
||||
OR
|
||||
($options['period_action'] === 'create')
|
||||
OR
|
||||
($options['period_action'] === 'update' AND !$accompanyingPeriod->isOpen())
|
||||
('close' === $options['period_action'])
|
||||
or ('create' === $options['period_action'])
|
||||
or ('update' === $options['period_action'] and !$accompanyingPeriod->isOpen())
|
||||
) {
|
||||
|
||||
$builder->add('closingDate', DateType::class, [
|
||||
'required' => true,
|
||||
'widget' => 'single_text',
|
||||
'format' => 'dd-MM-yyyy'
|
||||
'format' => 'dd-MM-yyyy',
|
||||
]);
|
||||
|
||||
|
||||
$builder->add('closingMotive', ClosingMotivePickerType::class);
|
||||
}
|
||||
|
||||
if ($this->config['user'] === 'visible') {
|
||||
|
||||
if ('visible' === $this->config['user']) {
|
||||
$builder->add('user', UserPickerType::class, [
|
||||
'center' => $options['center'],
|
||||
'role' => new Role(PersonVoter::SEE),
|
||||
'role' => new Role(PersonVoter::SEE),
|
||||
]);
|
||||
}
|
||||
|
||||
$builder->add('remark', ChillTextareaType::class, [
|
||||
'required' => false
|
||||
]);
|
||||
$builder->add('remark', ChillTextareaType::class, [
|
||||
'required' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
{
|
||||
$view->vars['action'] = $options['period_action'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OptionsResolver $resolver
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => 'Chill\PersonBundle\Entity\AccompanyingPeriod'
|
||||
'data_class' => 'Chill\PersonBundle\Entity\AccompanyingPeriod',
|
||||
]);
|
||||
|
||||
$resolver
|
||||
@@ -107,18 +104,7 @@ class AccompanyingPeriodType extends AbstractType
|
||||
->addAllowedTypes('period_action', 'string')
|
||||
->addAllowedValues('period_action', ['update', 'open', 'close', 'create'])
|
||||
->setRequired('center')
|
||||
->setAllowedTypes('center', Center::class)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FormView $view
|
||||
* @param FormInterface $form
|
||||
* @param array $options
|
||||
*/
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
{
|
||||
$view->vars['action'] = $options['period_action'];
|
||||
->setAllowedTypes('center', Center::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,56 +1,113 @@
|
||||
<?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\PersonBundle\Form\ChoiceLoader;
|
||||
|
||||
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
|
||||
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Repository\PersonRepository;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
|
||||
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
|
||||
use function call_user_func;
|
||||
use function in_array;
|
||||
|
||||
/**
|
||||
* Allow to load a list of person
|
||||
* Allow to load a list of person.
|
||||
*/
|
||||
class PersonChoiceLoader implements ChoiceLoaderInterface
|
||||
{
|
||||
protected PersonRepository $personRepository;
|
||||
|
||||
protected array $lazyLoadedPersons = [];
|
||||
|
||||
protected array $centers = [];
|
||||
|
||||
|
||||
protected array $lazyLoadedPersons = [];
|
||||
|
||||
protected PersonRepository $personRepository;
|
||||
|
||||
/**
|
||||
* PersonChoiceLoader constructor.
|
||||
*
|
||||
* @param EntityRepository $personRepository
|
||||
* @param array|null $centers
|
||||
*/
|
||||
public function __construct(
|
||||
PersonRepository $personRepository,
|
||||
array $centers = null
|
||||
?array $centers = null
|
||||
) {
|
||||
$this->personRepository = $personRepository;
|
||||
if (NULL !== $centers) {
|
||||
|
||||
if (null !== $centers) {
|
||||
$this->centers = $centers;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param null $value
|
||||
*/
|
||||
public function loadChoiceList($value = null): ChoiceListInterface
|
||||
{
|
||||
return new \Symfony\Component\Form\ChoiceList\ArrayChoiceList(
|
||||
$this->lazyLoadedPersons,
|
||||
function (Person $p) use ($value) {
|
||||
return call_user_func($value, $p);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $value
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function loadChoicesForValues(array $values, $value = null)
|
||||
{
|
||||
$choices = [];
|
||||
|
||||
foreach ($values as $value) {
|
||||
if (empty($value)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$person = $this->personRepository->find($value);
|
||||
|
||||
if ($this->hasCenterFilter()
|
||||
&& !in_array($person->getCenter(), $this->centers)) {
|
||||
throw new RuntimeException('chosen a person not in correct center');
|
||||
}
|
||||
|
||||
$choices[] = $person;
|
||||
}
|
||||
|
||||
return $choices;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $value
|
||||
*
|
||||
* @return array|string[]
|
||||
*/
|
||||
public function loadValuesForChoices(array $choices, $value = null)
|
||||
{
|
||||
$values = [];
|
||||
|
||||
foreach ($choices as $choice) {
|
||||
if (null === $choice) {
|
||||
$values[] = null;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$id = call_user_func($value, $choice);
|
||||
$values[] = $id;
|
||||
$this->lazyLoadedPersons[$id] = $choice;
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
@@ -58,69 +115,4 @@ class PersonChoiceLoader implements ChoiceLoaderInterface
|
||||
{
|
||||
return count($this->centers) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $value
|
||||
* @return ChoiceListInterface
|
||||
*/
|
||||
public function loadChoiceList($value = null): ChoiceListInterface
|
||||
{
|
||||
$list = new \Symfony\Component\Form\ChoiceList\ArrayChoiceList(
|
||||
$this->lazyLoadedPersons,
|
||||
function(Person $p) use ($value) {
|
||||
return \call_user_func($value, $p);
|
||||
});
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $values
|
||||
* @param null $value
|
||||
* @return array
|
||||
*/
|
||||
public function loadChoicesForValues(array $values, $value = null)
|
||||
{
|
||||
$choices = [];
|
||||
|
||||
foreach($values as $value) {
|
||||
if (empty($value)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$person = $this->personRepository->find($value);
|
||||
|
||||
if ($this->hasCenterFilter() &&
|
||||
!\in_array($person->getCenter(), $this->centers)) {
|
||||
throw new \RuntimeException("chosen a person not in correct center");
|
||||
}
|
||||
|
||||
$choices[] = $person;
|
||||
}
|
||||
|
||||
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) {
|
||||
$values[] = null;
|
||||
continue;
|
||||
}
|
||||
|
||||
$id = \call_user_func($value, $choice);
|
||||
$values[] = $id;
|
||||
$this->lazyLoadedPersons[$id] = $choice;
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
|
@@ -1,76 +1,55 @@
|
||||
<?php
|
||||
/*
|
||||
*
|
||||
* Copyright (C) 2014-2020, 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/>.
|
||||
*/
|
||||
namespace Chill\PersonBundle\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive;
|
||||
use Chill\PersonBundle\Form\Type\ClosingMotivePickerType;
|
||||
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\NumberType;
|
||||
|
||||
/**
|
||||
* Class ClosingMotiveType
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* @package Chill\PersonBundle\Form
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Form;
|
||||
|
||||
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive;
|
||||
use Chill\PersonBundle\Form\Type\ClosingMotivePickerType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\NumberType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* Class ClosingMotiveType.
|
||||
*/
|
||||
class ClosingMotiveType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param array $options
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('name', TranslatableStringFormType::class, [
|
||||
'label' => 'Nom'
|
||||
'label' => 'Nom',
|
||||
])
|
||||
->add('active', CheckboxType::class, [
|
||||
'label' => 'Actif ?',
|
||||
'required' => false
|
||||
'required' => false,
|
||||
])
|
||||
->add('ordering', NumberType::class, [
|
||||
'label' => 'Ordre d\'apparition',
|
||||
'required' => true,
|
||||
'scale' => 5
|
||||
'scale' => 5,
|
||||
])
|
||||
->add('parent', ClosingMotivePickerType::class, [
|
||||
'label' => 'Parent',
|
||||
'required' => false,
|
||||
'placeholder' => 'closing_motive.any parent',
|
||||
'multiple' => false,
|
||||
'only_leaf' => false
|
||||
])
|
||||
;
|
||||
'only_leaf' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OptionsResolver $resolver
|
||||
*/
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver
|
||||
->setDefault('class', ClosingMotive::class)
|
||||
;
|
||||
->setDefault('class', ClosingMotive::class);
|
||||
}
|
||||
}
|
||||
|
@@ -1,22 +1,29 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Form;
|
||||
|
||||
use Chill\MainBundle\Form\Event\CustomizeFormEvent;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\MainBundle\Form\Type\PickCenterType;
|
||||
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Form\Type\GenderType;
|
||||
use Chill\PersonBundle\Form\Type\PersonAltNameType;
|
||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\MainBundle\Form\Type\PickCenterType;
|
||||
use Chill\PersonBundle\Form\Type\GenderType;
|
||||
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
|
||||
use Chill\PersonBundle\Form\Type\PersonAltNameType;
|
||||
|
||||
final class CreationPersonType extends AbstractType
|
||||
{
|
||||
@@ -24,26 +31,22 @@ final class CreationPersonType extends AbstractType
|
||||
// TODO: See if this is still valid and update accordingly.
|
||||
public const NAME = 'chill_personbundle_person_creation';
|
||||
|
||||
private bool $askCenters;
|
||||
|
||||
private ConfigPersonAltNamesHelper $configPersonAltNamesHelper;
|
||||
|
||||
private EventDispatcherInterface $dispatcher;
|
||||
|
||||
private bool $askCenters;
|
||||
|
||||
public function __construct(
|
||||
ConfigPersonAltNamesHelper $configPersonAltNamesHelper,
|
||||
EventDispatcherInterface $dispatcher,
|
||||
ParameterBagInterface $parameterBag
|
||||
) {
|
||||
) {
|
||||
$this->configPersonAltNamesHelper = $configPersonAltNamesHelper;
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->askCenters = $parameterBag->get('chill_main')['acl']['form_show_centers'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param array $options
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
@@ -52,9 +55,9 @@ final class CreationPersonType extends AbstractType
|
||||
->add('birthdate', ChillDateType::class, [
|
||||
'required' => false,
|
||||
])
|
||||
->add('gender', GenderType::class, array(
|
||||
'required' => true, 'placeholder' => null
|
||||
));
|
||||
->add('gender', GenderType::class, [
|
||||
'required' => true, 'placeholder' => null,
|
||||
]);
|
||||
|
||||
if ($this->askCenters) {
|
||||
$builder
|
||||
@@ -65,25 +68,22 @@ final class CreationPersonType extends AbstractType
|
||||
}
|
||||
|
||||
if ($this->configPersonAltNamesHelper->hasAltNames()) {
|
||||
$builder->add('altNames', PersonAltNameType::class, [
|
||||
'by_reference' => false
|
||||
$builder->add('altNames', PersonAltNameType::class, [
|
||||
'by_reference' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->dispatcher->dispatch(
|
||||
new CustomizeFormEvent(static::class, $builder),
|
||||
new CustomizeFormEvent(self::class, $builder),
|
||||
CustomizeFormEvent::NAME
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OptionsResolver $resolver
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => Person::class
|
||||
));
|
||||
$resolver->setDefaults([
|
||||
'data_class' => Person::class,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,17 +1,21 @@
|
||||
<?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\PersonBundle\Form\DataMapper;
|
||||
|
||||
use Symfony\Component\Form\DataMapperInterface;
|
||||
use Chill\PersonBundle\Entity\PersonAltName;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Symfony\Component\Form\DataMapperInterface;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
use Chill\PersonBundle\Entity\PersonAltName;
|
||||
use function array_key_exists;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
class PersonAltNameDataMapper implements DataMapperInterface
|
||||
{
|
||||
public function mapDataToForms($viewData, $forms)
|
||||
@@ -19,26 +23,26 @@ class PersonAltNameDataMapper implements DataMapperInterface
|
||||
if (null === $viewData) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!$viewData instanceof Collection) {
|
||||
throw new UnexpectedTypeException($viewData, Collection::class);
|
||||
}
|
||||
|
||||
|
||||
$mapIndexToKey = [];
|
||||
|
||||
foreach ($viewData->getIterator() as $key => $altName) {
|
||||
/** @var PersonAltName $altName */
|
||||
$mapIndexToKey[$altName->getKey()] = $key;
|
||||
}
|
||||
|
||||
|
||||
foreach ($forms as $key => $form) {
|
||||
if (\array_key_exists($key, $mapIndexToKey)) {
|
||||
if (array_key_exists($key, $mapIndexToKey)) {
|
||||
$form->setData($viewData->get($mapIndexToKey[$key])->getLabel());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param FormInterface[] $forms
|
||||
* @param Collection $viewData
|
||||
*/
|
||||
@@ -52,16 +56,16 @@ class PersonAltNameDataMapper implements DataMapperInterface
|
||||
$dataIterator = $viewData instanceof ArrayCollection ?
|
||||
$viewData->toArray() : $viewData->getIterator();
|
||||
}
|
||||
|
||||
|
||||
foreach ($dataIterator as $key => $altName) {
|
||||
/** @var PersonAltName $altName */
|
||||
$mapIndexToKey[$altName->getKey()] = $key;
|
||||
}
|
||||
|
||||
|
||||
foreach ($forms as $key => $form) {
|
||||
$isEmpty = empty($form->getData());
|
||||
|
||||
if (\array_key_exists($key, $mapIndexToKey)) {
|
||||
|
||||
if (array_key_exists($key, $mapIndexToKey)) {
|
||||
if ($isEmpty) {
|
||||
$viewData->remove($mapIndexToKey[$key]);
|
||||
} else {
|
||||
@@ -71,8 +75,7 @@ class PersonAltNameDataMapper implements DataMapperInterface
|
||||
if (!$isEmpty) {
|
||||
$altName = (new PersonAltName())
|
||||
->setKey($key)
|
||||
->setLabel($form->getData())
|
||||
;
|
||||
->setLabel($form->getData());
|
||||
|
||||
if (is_array($viewData)) {
|
||||
$viewData[] = $altName;
|
||||
@@ -82,6 +85,5 @@ class PersonAltNameDataMapper implements DataMapperInterface
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +1,18 @@
|
||||
<?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\PersonBundle\Form\DataTransformer;
|
||||
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
|
||||
class PersonToIdTransformer implements DataTransformerInterface
|
||||
{
|
||||
@@ -14,37 +21,19 @@ class PersonToIdTransformer implements DataTransformerInterface
|
||||
*/
|
||||
private $om;
|
||||
|
||||
/**
|
||||
* @param ObjectManager $om
|
||||
*/
|
||||
public function __construct(ObjectManager $om)
|
||||
{
|
||||
$this->om = $om;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms an object (issue) to a string (id).
|
||||
*
|
||||
* @param Person|null $issue
|
||||
* @return string
|
||||
*/
|
||||
public function transform($issue)
|
||||
{
|
||||
if (null === $issue) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return $issue->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a string (id) to an object (issue).
|
||||
*
|
||||
* @param string $id
|
||||
*
|
||||
* @return Person|null
|
||||
*
|
||||
* @throws TransformationFailedException if object (issue) is not found.
|
||||
*
|
||||
* @return Person|null
|
||||
*/
|
||||
public function reverseTransform($id)
|
||||
{
|
||||
@@ -54,8 +43,7 @@ class PersonToIdTransformer implements DataTransformerInterface
|
||||
|
||||
$issue = $this->om
|
||||
->getRepository('ChillPersonBundle:Person')
|
||||
->findOneBy(array('id' => $id))
|
||||
;
|
||||
->findOneBy(['id' => $id]);
|
||||
|
||||
if (null === $issue) {
|
||||
throw new TransformationFailedException(sprintf(
|
||||
@@ -66,5 +54,20 @@ class PersonToIdTransformer implements DataTransformerInterface
|
||||
|
||||
return $issue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms an object (issue) to a string (id).
|
||||
*
|
||||
* @param Person|null $issue
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function transform($issue)
|
||||
{
|
||||
if (null === $issue) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $issue->getId();
|
||||
}
|
||||
}
|
||||
?>
|
@@ -1,9 +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\PersonBundle\Form;
|
||||
|
||||
use Chill\MainBundle\Form\Type\ChillTextareaType;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\MainBundle\Form\Type\ChillTextareaType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
@@ -17,21 +24,21 @@ class HouseholdMemberType extends AbstractType
|
||||
'label' => 'household.Start date',
|
||||
'input' => 'datetime_immutable',
|
||||
]);
|
||||
|
||||
if ($options['data']->getPosition()->isAllowHolder()) {
|
||||
$builder
|
||||
->add('holder', ChoiceType::class, [
|
||||
'label' => 'household.holder',
|
||||
'choices' => [
|
||||
'household.is holder' => true,
|
||||
'household.is not holder' => false
|
||||
]
|
||||
'household.is not holder' => false,
|
||||
],
|
||||
]);
|
||||
}
|
||||
$builder
|
||||
->add('comment', ChillTextareaType::class, [
|
||||
'label' => 'household.Comment',
|
||||
'required' => false
|
||||
])
|
||||
;
|
||||
}
|
||||
'required' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@@ -1,12 +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\PersonBundle\Form;
|
||||
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\MainBundle\Form\Type\CommentType;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
@@ -17,18 +24,17 @@ class HouseholdType extends AbstractType
|
||||
$builder
|
||||
->add('commentMembers', CommentType::class, [
|
||||
'label' => 'household.comment_membership',
|
||||
'required' => false
|
||||
'required' => false,
|
||||
])
|
||||
->add('waitingForBirth', CheckboxType::class, [
|
||||
'required' => false,
|
||||
'label' => 'household.expecting_birth'
|
||||
'label' => 'household.expecting_birth',
|
||||
])
|
||||
->add('waitingForBirthDate', ChillDateType::class, [
|
||||
'required' => false,
|
||||
'label' => 'household.date_expecting_birth',
|
||||
'input' => 'datetime_immutable'
|
||||
])
|
||||
;
|
||||
'input' => 'datetime_immutable',
|
||||
]);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
|
@@ -1,45 +1,40 @@
|
||||
<?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\PersonBundle\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Chill\PersonBundle\Entity\MaritalStatus;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||
use Chill\PersonBundle\Entity\MaritalStatus;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* Class MaritalStatusType
|
||||
*
|
||||
* @package Chill\PersonBundle\Form
|
||||
* Class MaritalStatusType.
|
||||
*/
|
||||
class MaritalStatusType extends AbstractType
|
||||
{
|
||||
|
||||
/**
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param array $options
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('id', TextType::class, [
|
||||
'label' => 'Identifiant'
|
||||
'label' => 'Identifiant',
|
||||
])
|
||||
->add('name', TranslatableStringFormType::class, [
|
||||
'label' => 'Nom'
|
||||
])
|
||||
;
|
||||
'label' => 'Nom',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OptionsResolver $resolver
|
||||
*/
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver
|
||||
->setDefault('class', MaritalStatus::class)
|
||||
;
|
||||
->setDefault('class', MaritalStatus::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\PersonBundle\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
@@ -8,17 +15,13 @@ use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
class PersonConfimDuplicateType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param array $options
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('confirm', CheckboxType::class, [
|
||||
'label' => 'I confirm the merger of these 2 people',
|
||||
'mapped' => false,
|
||||
]);
|
||||
->add('confirm', CheckboxType::class, [
|
||||
'label' => 'I confirm the merger of these 2 people',
|
||||
'mapped' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,19 +1,21 @@
|
||||
<?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\PersonBundle\Form;
|
||||
|
||||
use Chill\PersonBundle\Form\Type\PickPersonType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
class PersonFindManuallyDuplicateType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param array $options
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
@@ -23,8 +25,7 @@ class PersonFindManuallyDuplicateType extends AbstractType
|
||||
])
|
||||
->add('direction', HiddenType::class, [
|
||||
'data' => 'starting',
|
||||
])
|
||||
;
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,22 +1,10 @@
|
||||
<?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\PersonBundle\Form;
|
||||
@@ -24,29 +12,29 @@ namespace Chill\PersonBundle\Form;
|
||||
use Chill\CustomFieldsBundle\Form\Type\CustomFieldType;
|
||||
use Chill\MainBundle\Entity\Civility;
|
||||
use Chill\MainBundle\Form\Type\ChillCollectionType;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\MainBundle\Form\Type\ChillTextareaType;
|
||||
use Chill\MainBundle\Form\Type\CommentType;
|
||||
use Chill\MainBundle\Form\Type\Select2CountryType;
|
||||
use Chill\MainBundle\Form\Type\Select2LanguageType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
|
||||
use Chill\PersonBundle\Entity\PersonPhone;
|
||||
use Chill\PersonBundle\Form\Type\GenderType;
|
||||
use Chill\PersonBundle\Form\Type\PersonAltNameType;
|
||||
use Chill\PersonBundle\Form\Type\PersonPhoneType;
|
||||
use Chill\PersonBundle\Entity\PersonPhone;
|
||||
use Chill\PersonBundle\Form\Type\Select2MaritalStatusType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\MainBundle\Form\Type\CommentType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\CallbackTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TelType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TelType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
@@ -60,10 +48,9 @@ class PersonType extends AbstractType
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $config = array();
|
||||
protected $config = [];
|
||||
|
||||
/**
|
||||
*
|
||||
* @var ConfigPersonAltNamesHelper
|
||||
*/
|
||||
protected $configAltNamesHelper;
|
||||
@@ -71,7 +58,6 @@ class PersonType extends AbstractType
|
||||
protected TranslatableStringHelper $translatableStringHelper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string[] $personFieldsConfiguration configuration of visibility of some fields
|
||||
*/
|
||||
public function __construct(
|
||||
@@ -84,10 +70,6 @@ class PersonType extends AbstractType
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param array $options
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
@@ -99,35 +81,34 @@ class PersonType extends AbstractType
|
||||
->add('deathdate', DateType::class, [
|
||||
'required' => false,
|
||||
'input' => 'datetime_immutable',
|
||||
'widget' => 'single_text'
|
||||
'widget' => 'single_text',
|
||||
])
|
||||
->add('gender', GenderType::class, array(
|
||||
'required' => true
|
||||
))
|
||||
->add('genderComment', CommentType::class, array(
|
||||
'required' => false
|
||||
))
|
||||
->add('numberOfChildren', IntegerType::class, array(
|
||||
'required' => false
|
||||
));
|
||||
->add('gender', GenderType::class, [
|
||||
'required' => true,
|
||||
])
|
||||
->add('genderComment', CommentType::class, [
|
||||
'required' => false,
|
||||
])
|
||||
->add('numberOfChildren', IntegerType::class, [
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
if ($this->configAltNamesHelper->hasAltNames()) {
|
||||
$builder->add('altNames', PersonAltNameType::class, [
|
||||
'by_reference' => false
|
||||
'by_reference' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
if ($this->config['memo'] === 'visible') {
|
||||
if ('visible' === $this->config['memo']) {
|
||||
$builder
|
||||
->add('memo', ChillTextareaType::class, array('required' => false))
|
||||
;
|
||||
->add('memo', ChillTextareaType::class, ['required' => false]);
|
||||
}
|
||||
|
||||
if ($this->config['place_of_birth'] === 'visible') {
|
||||
$builder->add('placeOfBirth', TextType::class, array(
|
||||
if ('visible' === $this->config['place_of_birth']) {
|
||||
$builder->add('placeOfBirth', TextType::class, [
|
||||
'required' => false,
|
||||
'attr' => ['style' => 'text-transform: uppercase;'],
|
||||
));
|
||||
]);
|
||||
|
||||
$builder->get('placeOfBirth')->addModelTransformer(new CallbackTransformer(
|
||||
function ($string) {
|
||||
@@ -136,26 +117,26 @@ class PersonType extends AbstractType
|
||||
function ($string) {
|
||||
return strtoupper($string);
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
if ($this->config['contact_info'] === 'visible') {
|
||||
$builder->add('contactInfo', ChillTextareaType::class, array('required' => false));
|
||||
}
|
||||
|
||||
if ($this->config['phonenumber'] === 'visible') {
|
||||
$builder->add('phonenumber', TelType::class, array(
|
||||
'required' => false,
|
||||
// 'placeholder' => '+33623124554' //TODO placeholder for phone numbers
|
||||
));
|
||||
}
|
||||
|
||||
if ($this->config['mobilenumber'] === 'visible') {
|
||||
if ('visible' === $this->config['contact_info']) {
|
||||
$builder->add('contactInfo', ChillTextareaType::class, ['required' => false]);
|
||||
}
|
||||
|
||||
if ('visible' === $this->config['phonenumber']) {
|
||||
$builder->add('phonenumber', TelType::class, [
|
||||
'required' => false,
|
||||
// 'placeholder' => '+33623124554' //TODO placeholder for phone numbers
|
||||
]);
|
||||
}
|
||||
|
||||
if ('visible' === $this->config['mobilenumber']) {
|
||||
$builder
|
||||
->add('mobilenumber', TelType::class, array('required' => false))
|
||||
->add('acceptSMS', CheckboxType::class, array(
|
||||
'required' => false
|
||||
));
|
||||
->add('mobilenumber', TelType::class, ['required' => false])
|
||||
->add('acceptSMS', CheckboxType::class, [
|
||||
'required' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
$builder->add('otherPhoneNumbers', ChillCollectionType::class, [
|
||||
@@ -167,43 +148,43 @@ class PersonType extends AbstractType
|
||||
'allow_delete' => true,
|
||||
'by_reference' => false,
|
||||
'label' => false,
|
||||
'delete_empty' => function(PersonPhone $pp = null) {
|
||||
return NULL === $pp || $pp->isEmpty();
|
||||
'delete_empty' => function (?PersonPhone $pp = null) {
|
||||
return null === $pp || $pp->isEmpty();
|
||||
},
|
||||
'error_bubbling' => false,
|
||||
'empty_collection_explain' => 'No additional phone numbers'
|
||||
'empty_collection_explain' => 'No additional phone numbers',
|
||||
]);
|
||||
|
||||
if ($this->config['email'] === 'visible') {
|
||||
if ('visible' === $this->config['email']) {
|
||||
$builder
|
||||
->add('email', EmailType::class, array('required' => false));
|
||||
->add('email', EmailType::class, ['required' => false]);
|
||||
}
|
||||
|
||||
if ($this->config['acceptEmail'] === 'visible') {
|
||||
if ('visible' === $this->config['acceptEmail']) {
|
||||
$builder
|
||||
->add('acceptEmail', CheckboxType::class, array('required' => false));
|
||||
->add('acceptEmail', CheckboxType::class, ['required' => false]);
|
||||
}
|
||||
|
||||
if ($this->config['country_of_birth'] === 'visible') {
|
||||
$builder->add('countryOfBirth', Select2CountryType::class, array(
|
||||
'required' => false
|
||||
));
|
||||
}
|
||||
|
||||
if ($this->config['nationality'] === 'visible') {
|
||||
$builder->add('nationality', Select2CountryType::class, array(
|
||||
'required' => false
|
||||
));
|
||||
}
|
||||
|
||||
if ($this->config['spoken_languages'] === 'visible') {
|
||||
$builder->add('spokenLanguages', Select2LanguageType::class, array(
|
||||
if ('visible' === $this->config['country_of_birth']) {
|
||||
$builder->add('countryOfBirth', Select2CountryType::class, [
|
||||
'required' => false,
|
||||
'multiple' => true
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
if ($this->config['civility'] === 'visible'){
|
||||
if ('visible' === $this->config['nationality']) {
|
||||
$builder->add('nationality', Select2CountryType::class, [
|
||||
'required' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
if ('visible' === $this->config['spoken_languages']) {
|
||||
$builder->add('spokenLanguages', Select2LanguageType::class, [
|
||||
'required' => false,
|
||||
'multiple' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
if ('visible' === $this->config['civility']) {
|
||||
$builder
|
||||
->add('civility', EntityType::class, [
|
||||
'label' => 'Civility',
|
||||
@@ -216,30 +197,31 @@ class PersonType extends AbstractType
|
||||
->where('c.active = true');
|
||||
},
|
||||
'placeholder' => 'choose civility',
|
||||
'required' => false
|
||||
'required' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
if ($this->config['marital_status'] === 'visible'){
|
||||
if ('visible' === $this->config['marital_status']) {
|
||||
$builder
|
||||
->add('maritalStatus', Select2MaritalStatusType::class, array(
|
||||
'required' => false
|
||||
))
|
||||
->add('maritalStatusDate', ChillDateType::class, array(
|
||||
'required' => false
|
||||
))
|
||||
->add('maritalStatusComment', CommentType::class, array(
|
||||
'required' => false
|
||||
));
|
||||
->add('maritalStatus', Select2MaritalStatusType::class, [
|
||||
'required' => false,
|
||||
])
|
||||
->add('maritalStatusDate', ChillDateType::class, [
|
||||
'required' => false,
|
||||
])
|
||||
->add('maritalStatusComment', CommentType::class, [
|
||||
'required' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
if($options['cFGroup']) {
|
||||
if ($options['cFGroup']) {
|
||||
$builder
|
||||
->add('cFData', CustomFieldType::class,
|
||||
array('attr' => array('class' => 'cf-fields'), 'group' => $options['cFGroup']))
|
||||
;
|
||||
->add(
|
||||
'cFData',
|
||||
CustomFieldType::class,
|
||||
['attr' => ['class' => 'cf-fields'], 'group' => $options['cFGroup']]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -247,17 +229,18 @@ class PersonType extends AbstractType
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
$resolver->setDefaults([
|
||||
'data_class' => 'Chill\PersonBundle\Entity\Person',
|
||||
'validation_groups' => array('general', 'creation'),
|
||||
));
|
||||
'validation_groups' => ['general', 'creation'],
|
||||
]);
|
||||
|
||||
$resolver->setRequired(array(
|
||||
'cFGroup'
|
||||
));
|
||||
$resolver->setRequired([
|
||||
'cFGroup',
|
||||
]);
|
||||
|
||||
$resolver->setAllowedTypes(
|
||||
'cFGroup', array('null', 'Chill\CustomFieldsBundle\Entity\CustomFieldsGroup')
|
||||
'cFGroup',
|
||||
['null', 'Chill\CustomFieldsBundle\Entity\CustomFieldsGroup']
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -1,53 +1,36 @@
|
||||
<?php
|
||||
/*
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2021, 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\PersonBundle\Form\SocialWork;
|
||||
|
||||
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\PersonBundle\Entity\SocialWork\Evaluation;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Chill\PersonBundle\Entity\SocialWork\Evaluation;
|
||||
|
||||
/**
|
||||
* Class EvaluationType
|
||||
*
|
||||
* @package Chill\PersonBundle\Form
|
||||
* Class EvaluationType.
|
||||
*/
|
||||
class EvaluationType extends AbstractType
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var TranslatableStringHelper
|
||||
*/
|
||||
protected $translatableStringHelper;
|
||||
|
||||
public function __construct(TranslatableStringHelper $translatableStringHelper) {
|
||||
public function __construct(TranslatableStringHelper $translatableStringHelper)
|
||||
{
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param array $options
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
@@ -59,13 +42,9 @@ class EvaluationType extends AbstractType
|
||||
->add('notificationDelay');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OptionsResolver $resolver
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver
|
||||
->setDefault('class', Evaluation::class)
|
||||
;
|
||||
->setDefault('class', Evaluation::class);
|
||||
}
|
||||
}
|
||||
|
@@ -1,85 +1,66 @@
|
||||
<?php
|
||||
/*
|
||||
*
|
||||
* Copyright (C) 2014-2021, 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/>.
|
||||
*/
|
||||
namespace Chill\PersonBundle\Form\SocialWork;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Chill\PersonBundle\Entity\SocialWork\Goal;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
||||
|
||||
/**
|
||||
* Class GoalType
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* @package Chill\PersonBundle\Form
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Form\SocialWork;
|
||||
|
||||
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\PersonBundle\Entity\SocialWork\Goal;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* Class GoalType.
|
||||
*/
|
||||
class GoalType extends AbstractType
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var TranslatableStringHelper
|
||||
*/
|
||||
protected $translatableStringHelper;
|
||||
|
||||
public function __construct(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('title', TranslatableStringFormType::class, [
|
||||
'label' => 'Nom'
|
||||
'label' => 'Nom',
|
||||
])
|
||||
|
||||
->add('socialActions', EntityType::class, [
|
||||
'class' => SocialAction::class,
|
||||
'required' => false,
|
||||
'required' => false,
|
||||
'multiple' => true,
|
||||
'choice_label' => function (SocialAction $issue) {
|
||||
return $this->translatableStringHelper->localize($issue->getTitle());
|
||||
}
|
||||
},
|
||||
])
|
||||
|
||||
->add('desactivationDate', DateType::class, [
|
||||
'attr' => array('class' => 'datepicker'),
|
||||
'widget'=> 'single_text',
|
||||
'attr' => ['class' => 'datepicker'],
|
||||
'widget' => 'single_text',
|
||||
'format' => 'dd-MM-yyyy',
|
||||
'required' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OptionsResolver $resolver
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver
|
||||
->setDefault('class', Goal::class)
|
||||
;
|
||||
->setDefault('class', Goal::class);
|
||||
}
|
||||
}
|
||||
|
@@ -1,76 +1,56 @@
|
||||
<?php
|
||||
/*
|
||||
*
|
||||
* Copyright (C) 2014-2021, 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/>.
|
||||
*/
|
||||
namespace Chill\PersonBundle\Form\SocialWork;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Chill\PersonBundle\Entity\SocialWork\Result;
|
||||
|
||||
/**
|
||||
* Class ResultType
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* @package Chill\PersonBundle\Form
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Form\SocialWork;
|
||||
|
||||
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\PersonBundle\Entity\SocialWork\Result;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* Class ResultType.
|
||||
*/
|
||||
class ResultType extends AbstractType
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var TranslatableStringHelper
|
||||
*/
|
||||
protected $translatableStringHelper;
|
||||
|
||||
public function __construct(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('title', TranslatableStringFormType::class, [
|
||||
'label' => 'Nom'
|
||||
'label' => 'Nom',
|
||||
])
|
||||
->add('accompanyingPeriodWorks')
|
||||
->add('accompanyingPeriodWorkGoals')
|
||||
->add('desactivationDate', DateType::class, [
|
||||
'attr' => array('class' => 'datepicker'),
|
||||
'widget'=> 'single_text',
|
||||
'attr' => ['class' => 'datepicker'],
|
||||
'widget' => 'single_text',
|
||||
'format' => 'dd-MM-yyyy',
|
||||
'required' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OptionsResolver $resolver
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver
|
||||
->setDefault('class', Result::class)
|
||||
;
|
||||
->setDefault('class', Result::class);
|
||||
}
|
||||
}
|
||||
|
@@ -1,90 +1,70 @@
|
||||
<?php
|
||||
/*
|
||||
*
|
||||
* Copyright (C) 2014-2021, 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/>.
|
||||
*/
|
||||
namespace Chill\PersonBundle\Form\SocialWork;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||
|
||||
|
||||
/**
|
||||
* Class SocialActionType
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* @package Chill\PersonBundle\Form
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Form\SocialWork;
|
||||
|
||||
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* Class SocialActionType.
|
||||
*/
|
||||
class SocialActionType extends AbstractType
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var TranslatableStringHelper
|
||||
*/
|
||||
protected $translatableStringHelper;
|
||||
|
||||
public function __construct(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('title', TranslatableStringFormType::class, [
|
||||
'label' => 'Nom'
|
||||
'label' => 'Nom',
|
||||
])
|
||||
->add('issue', EntityType::class, [
|
||||
'class' => SocialIssue::class,
|
||||
'choice_label' => function (SocialIssue $issue) {
|
||||
return $this->translatableStringHelper->localize($issue->getTitle());
|
||||
}
|
||||
},
|
||||
])
|
||||
->add('parent', EntityType::class, [
|
||||
'class' => SocialAction::class,
|
||||
'required' => false,
|
||||
'required' => false,
|
||||
'choice_label' => function (SocialAction $issue) {
|
||||
return $this->translatableStringHelper->localize($issue->getTitle());
|
||||
}
|
||||
},
|
||||
])
|
||||
->add('defaultNotificationDelay')
|
||||
->add('desactivationDate', DateType::class, [
|
||||
'attr' => array('class' => 'datepicker'),
|
||||
'widget'=> 'single_text',
|
||||
'attr' => ['class' => 'datepicker'],
|
||||
'widget' => 'single_text',
|
||||
'format' => 'dd-MM-yyyy',
|
||||
'required' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OptionsResolver $resolver
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver
|
||||
->setDefault('class', SocialIssue::class)
|
||||
;
|
||||
->setDefault('class', SocialIssue::class);
|
||||
}
|
||||
}
|
||||
|
@@ -1,17 +1,24 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Form\SocialWork;
|
||||
|
||||
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||
|
||||
class SocialIssueType extends AbstractType
|
||||
{
|
||||
@@ -27,16 +34,16 @@ class SocialIssueType extends AbstractType
|
||||
{
|
||||
$builder
|
||||
->add('title', TranslatableStringFormType::class, [
|
||||
'label' => 'Nom'
|
||||
'label' => 'Nom',
|
||||
])
|
||||
->add('parent', EntityType::class, [
|
||||
'class' => SocialIssue::class,
|
||||
'required' => false,
|
||||
'choice_label' => fn (SocialIssue $issue): ?string => $this->translatableStringHelper->localize($issue->getTitle())
|
||||
'required' => false,
|
||||
'choice_label' => fn (SocialIssue $issue): ?string => $this->translatableStringHelper->localize($issue->getTitle()),
|
||||
])
|
||||
->add('desactivationDate', DateType::class, [
|
||||
'attr' => ['class' => 'datepicker'],
|
||||
'widget'=> 'single_text',
|
||||
'attr' => ['class' => 'datepicker'],
|
||||
'widget' => 'single_text',
|
||||
'format' => 'dd-MM-yyyy',
|
||||
'required' => false,
|
||||
]);
|
||||
|
@@ -1,32 +1,29 @@
|
||||
<?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\PersonBundle\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Chill\MainBundle\Templating\Entity\ChillEntityRenderExtension;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive;
|
||||
use Chill\MainBundle\Templating\Entity\ChillEntityRenderExtension;
|
||||
use Symfony\Component\OptionsResolver\Options;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriod\ClosingMotiveRepository;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\OptionsResolver\Options;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* Class ClosingMotivePickerType
|
||||
* A type to add a closing motive
|
||||
*
|
||||
* @package Chill\PersonBundle\Form\Type
|
||||
* A type to add a closing motive.
|
||||
*/
|
||||
class ClosingMotivePickerType extends AbstractType
|
||||
{
|
||||
|
||||
/**
|
||||
* @var TranslatableStringHelper
|
||||
*/
|
||||
protected $translatableStringHelper;
|
||||
|
||||
/**
|
||||
* @var ChillEntityRenderExtension
|
||||
*/
|
||||
@@ -37,12 +34,13 @@ class ClosingMotivePickerType extends AbstractType
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* @var TranslatableStringHelper
|
||||
*/
|
||||
protected $translatableStringHelper;
|
||||
|
||||
/**
|
||||
* ClosingMotivePickerType constructor.
|
||||
*
|
||||
* @param TranslatableStringHelper $translatableStringHelper
|
||||
* @param ChillEntityRenderExtension $chillEntityRenderExtension
|
||||
* @param ClosingMotiveRepository $closingMotiveRepository
|
||||
*/
|
||||
public function __construct(
|
||||
TranslatableStringHelper $translatableStringHelper,
|
||||
@@ -53,7 +51,27 @@ class ClosingMotivePickerType extends AbstractType
|
||||
$this->entityRenderExtension = $chillEntityRenderExtension;
|
||||
$this->repository = $closingMotiveRepository;
|
||||
}
|
||||
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'class' => ClosingMotive::class,
|
||||
'empty_data' => null,
|
||||
'placeholder' => 'Choose a motive',
|
||||
'choice_label' => function (ClosingMotive $cm) {
|
||||
return $this->entityRenderExtension->renderString($cm);
|
||||
},
|
||||
'only_leaf' => true,
|
||||
]);
|
||||
|
||||
$resolver
|
||||
->setAllowedTypes('only_leaf', 'bool')
|
||||
->setNormalizer('choices', function (Options $options) {
|
||||
return $this->repository
|
||||
->getActiveClosingMotive($options['only_leaf']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -61,38 +79,12 @@ class ClosingMotivePickerType extends AbstractType
|
||||
{
|
||||
return 'closing_motive';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
* @return string|null
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
return EntityType::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OptionsResolver $resolver
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
|
||||
$resolver->setDefaults([
|
||||
'class' => ClosingMotive::class,
|
||||
'empty_data' => null,
|
||||
'placeholder' => 'Choose a motive',
|
||||
'choice_label' => function(ClosingMotive $cm) {
|
||||
return $this->entityRenderExtension->renderString($cm);
|
||||
},
|
||||
'only_leaf' => true
|
||||
]);
|
||||
|
||||
$resolver
|
||||
->setAllowedTypes('only_leaf', 'bool')
|
||||
->setNormalizer('choices', function (Options $options) {
|
||||
return $this->repository
|
||||
->getActiveClosingMotive($options['only_leaf']);
|
||||
})
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,38 +1,43 @@
|
||||
<?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\PersonBundle\Form\Type;
|
||||
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* A type to select the civil union state
|
||||
*
|
||||
* @author julien
|
||||
* A type to select the civil union state.
|
||||
*/
|
||||
class GenderType extends AbstractType {
|
||||
|
||||
public function getParent() {
|
||||
return ChoiceType::class;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver) {
|
||||
|
||||
$a = array(
|
||||
class GenderType extends AbstractType
|
||||
{
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$a = [
|
||||
Person::MALE_GENDER => Person::MALE_GENDER,
|
||||
Person::FEMALE_GENDER => Person::FEMALE_GENDER,
|
||||
Person::BOTH_GENDER => Person::BOTH_GENDER
|
||||
);
|
||||
Person::BOTH_GENDER => Person::BOTH_GENDER,
|
||||
];
|
||||
|
||||
$resolver->setDefaults(array(
|
||||
$resolver->setDefaults([
|
||||
'choices' => $a,
|
||||
'expanded' => true,
|
||||
'multiple' => false,
|
||||
'placeholder' => null,
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
public function getParent()
|
||||
{
|
||||
return ChoiceType::class;
|
||||
}
|
||||
}
|
||||
|
@@ -1,35 +1,36 @@
|
||||
<?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\PersonBundle\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 Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
class PersonAltNameType extends AbstractType
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var ConfigPersonAltNamesHelper
|
||||
*/
|
||||
private $configHelper;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @var TranslatableStringHelper
|
||||
*/
|
||||
private $translatableStringHelper;
|
||||
|
||||
|
||||
public function __construct(
|
||||
ConfigPersonAltNamesHelper $configHelper,
|
||||
ConfigPersonAltNamesHelper $configHelper,
|
||||
TranslatableStringHelper $translatableStringHelper
|
||||
) {
|
||||
$this->configHelper = $configHelper;
|
||||
@@ -40,28 +41,17 @@ class PersonAltNameType extends AbstractType
|
||||
{
|
||||
foreach ($this->getKeyChoices() as $label => $key) {
|
||||
$builder->add(
|
||||
$key,
|
||||
$options['force_hidden'] ? HiddenType::class : TextType::class, [
|
||||
'label' => $label,
|
||||
'required' => false
|
||||
]);
|
||||
$key,
|
||||
$options['force_hidden'] ? HiddenType::class : TextType::class,
|
||||
[
|
||||
'label' => $label,
|
||||
'required' => false,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
$builder->setDataMapper(new \Chill\PersonBundle\Form\DataMapper\PersonAltNameDataMapper());
|
||||
}
|
||||
|
||||
protected function getKeyChoices()
|
||||
{
|
||||
$choices = $this->configHelper->getChoices();
|
||||
$translatedChoices = [];
|
||||
|
||||
foreach ($choices as $key => $labels) {
|
||||
$label = $this->translatableStringHelper->localize($labels);
|
||||
$translatedChoices[$label] = $key;
|
||||
}
|
||||
|
||||
return $translatedChoices;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
@@ -69,8 +59,19 @@ class PersonAltNameType extends AbstractType
|
||||
->setDefault('class', \Chill\PersonBundle\Entity\PersonAltName::class)
|
||||
->setDefined('force_hidden')
|
||||
->setAllowedTypes('force_hidden', 'bool')
|
||||
->setDefault('force_hidden', false)
|
||||
;
|
||||
->setDefault('force_hidden', false);
|
||||
}
|
||||
|
||||
protected function getKeyChoices()
|
||||
{
|
||||
$choices = $this->configHelper->getChoices();
|
||||
$translatedChoices = [];
|
||||
|
||||
foreach ($choices as $key => $labels) {
|
||||
$label = $this->translatableStringHelper->localize($labels);
|
||||
$translatedChoices[$label] = $key;
|
||||
}
|
||||
|
||||
return $translatedChoices;
|
||||
}
|
||||
}
|
||||
|
@@ -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\PersonBundle\Form\Type;
|
||||
|
||||
use Chill\MainBundle\Phonenumber\PhonenumberHelper;
|
||||
@@ -11,16 +18,14 @@ use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class PersonPhoneType extends AbstractType
|
||||
{
|
||||
private PhonenumberHelper $phonenumberHelper;
|
||||
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
private PhonenumberHelper $phonenumberHelper;
|
||||
|
||||
public function __construct(PhonenumberHelper $phonenumberHelper, EntityManagerInterface $em)
|
||||
{
|
||||
$this->phonenumberHelper = $phonenumberHelper;
|
||||
@@ -38,11 +43,11 @@ class PersonPhoneType extends AbstractType
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
$builder->addEventListener(FormEvents::POST_SUBMIT, function(FormEvent $event) {
|
||||
if (NULL === $event->getData()) {
|
||||
$builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
|
||||
if (null === $event->getData()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$oldPersonPhone = $this->em->getUnitOfWork()
|
||||
->getOriginalEntityData($event->getData());
|
||||
|
||||
@@ -59,7 +64,6 @@ class PersonPhoneType extends AbstractType
|
||||
->setDefaults([
|
||||
'data_class' => PersonPhone::class,
|
||||
'validation_groups' => ['general', 'creation'],
|
||||
])
|
||||
;
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@@ -1,41 +1,31 @@
|
||||
<?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\PersonBundle\Form\Type;
|
||||
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Entity\GroupCenter;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Form\ChoiceLoader\PersonChoiceLoader;
|
||||
use Chill\PersonBundle\Repository\PersonRepository;
|
||||
use Chill\PersonBundle\Search\PersonSearch;
|
||||
use RuntimeException;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\Options;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Chill\MainBundle\Entity\GroupCenter;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\PersonBundle\Repository\PersonRepository;
|
||||
use Chill\PersonBundle\Search\PersonSearch;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
use Chill\PersonBundle\Form\ChoiceLoader\PersonChoiceLoader;
|
||||
use Symfony\Component\OptionsResolver\Options;
|
||||
|
||||
/**
|
||||
* This type allow to pick a person.
|
||||
@@ -49,49 +39,41 @@ use Symfony\Component\OptionsResolver\Options;
|
||||
* `Chill\MainBundle\Entity\Center`. By default, all the reachable centers as selected.
|
||||
* - with the `role` option, only the people belonging to the reachable center for the
|
||||
* given role are displayed.
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class PickPersonType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* @var PersonRepository
|
||||
*/
|
||||
protected $personRepository;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Chill\MainBundle\Entity\User
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var AuthorizationHelper
|
||||
*/
|
||||
protected $authorizationHelper;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @var UrlGeneratorInterface
|
||||
* @var PersonRepository
|
||||
*/
|
||||
protected $urlGenerator;
|
||||
|
||||
protected $personRepository;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
/**
|
||||
* @var UrlGeneratorInterface
|
||||
*/
|
||||
protected $urlGenerator;
|
||||
|
||||
/**
|
||||
* @var \Chill\MainBundle\Entity\User
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
public function __construct(
|
||||
PersonRepository $personRepository,
|
||||
TokenStorageInterface $tokenStorage,
|
||||
AuthorizationHelper $authorizationHelper,
|
||||
UrlGeneratorInterface $urlGenerator,
|
||||
TranslatorInterface $translator
|
||||
)
|
||||
{
|
||||
PersonRepository $personRepository,
|
||||
TokenStorageInterface $tokenStorage,
|
||||
AuthorizationHelper $authorizationHelper,
|
||||
UrlGeneratorInterface $urlGenerator,
|
||||
TranslatorInterface $translator
|
||||
) {
|
||||
$this->personRepository = $personRepository;
|
||||
$this->user = $tokenStorage->getToken()->getUser();
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
@@ -99,42 +81,16 @@ class PickPersonType extends AbstractType
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
protected function filterCentersfom(Options $options)
|
||||
public function buildView(\Symfony\Component\Form\FormView $view, \Symfony\Component\Form\FormInterface $form, array $options)
|
||||
{
|
||||
if ($options['role'] === NULL) {
|
||||
$centers = array_map(function (GroupCenter $g) {
|
||||
|
||||
return $g->getCenter();
|
||||
}, $this->user->getGroupCenters()->toArray());
|
||||
} else {
|
||||
$centers = $this->authorizationHelper
|
||||
->getReachableCenters($this->user, $options['role']);
|
||||
}
|
||||
|
||||
if ($options['centers'] === NULL) {
|
||||
// we select all selected centers
|
||||
$selectedCenters = $centers;
|
||||
} else {
|
||||
$selectedCenters = array();
|
||||
$optionsCenters = is_array($options['centers']) ?
|
||||
$options['centers'] : array($options['centers']);
|
||||
|
||||
foreach ($optionsCenters as $c) {
|
||||
// check that every member of the array is a center
|
||||
if (!$c instanceof Center) {
|
||||
throw new \RuntimeException('Every member of the "centers" '
|
||||
. 'option must be an instance of '.Center::class);
|
||||
}
|
||||
if (!in_array($c->getId(), array_map(
|
||||
function(Center $c) { return $c->getId();},
|
||||
$centers))) {
|
||||
throw new AccessDeniedException('The given center is not reachable');
|
||||
}
|
||||
$selectedCenters[] = $c;
|
||||
}
|
||||
}
|
||||
|
||||
return $selectedCenters;
|
||||
$view->vars['attr']['data-person-picker'] = true;
|
||||
$view->vars['attr']['data-select-interactive-loading'] = true;
|
||||
$view->vars['attr']['data-search-url'] = $this->urlGenerator
|
||||
->generate('chill_main_search', ['name' => PersonSearch::NAME, '_format' => 'json']);
|
||||
$view->vars['attr']['data-placeholder'] = $this->translator->trans($options['placeholder']);
|
||||
$view->vars['attr']['data-no-results-label'] = $this->translator->trans('select2.no_results');
|
||||
$view->vars['attr']['data-error-load-label'] = $this->translator->trans('select2.error_loading');
|
||||
$view->vars['attr']['data-searching-label'] = $this->translator->trans('select2.searching');
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
@@ -143,49 +99,74 @@ class PickPersonType extends AbstractType
|
||||
|
||||
// add the possibles options for this type
|
||||
$resolver->setDefined('centers')
|
||||
->addAllowedTypes('centers', array('array', Center::class, 'null'))
|
||||
->setDefault('centers', null)
|
||||
->setDefined('role')
|
||||
->addAllowedTypes('role', array(Role::class, 'null'))
|
||||
->setDefault('role', null)
|
||||
;
|
||||
->addAllowedTypes('centers', ['array', Center::class, 'null'])
|
||||
->setDefault('centers', null)
|
||||
->setDefined('role')
|
||||
->addAllowedTypes('role', [Role::class, 'null'])
|
||||
->setDefault('role', null);
|
||||
|
||||
// add the default options
|
||||
$resolver->setDefaults(array(
|
||||
$resolver->setDefaults([
|
||||
'class' => Person::class,
|
||||
'choice_label' => function(Person $p) {
|
||||
return $p->getFirstname().' '.$p->getLastname();
|
||||
'choice_label' => function (Person $p) {
|
||||
return $p->getFirstname() . ' ' . $p->getLastname();
|
||||
},
|
||||
'placeholder' => 'Pick a person',
|
||||
'choice_attr' => function(Person $p) {
|
||||
return array(
|
||||
'data-center' => $p->getCenter()->getId()
|
||||
);
|
||||
'choice_attr' => function (Person $p) {
|
||||
return [
|
||||
'data-center' => $p->getCenter()->getId(),
|
||||
];
|
||||
},
|
||||
'attr' => array('class' => 'select2 '),
|
||||
'choice_loader' => function(Options $options) {
|
||||
'attr' => ['class' => 'select2 '],
|
||||
'choice_loader' => function (Options $options) {
|
||||
$centers = $this->filterCentersfom($options);
|
||||
|
||||
|
||||
return new PersonChoiceLoader($this->personRepository, $centers);
|
||||
}
|
||||
));
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
public function getParent()
|
||||
{
|
||||
return EntityType::class;
|
||||
}
|
||||
|
||||
public function buildView(\Symfony\Component\Form\FormView $view, \Symfony\Component\Form\FormInterface $form, array $options)
|
||||
{
|
||||
$view->vars['attr']['data-person-picker'] = true;
|
||||
$view->vars['attr']['data-select-interactive-loading'] = true;
|
||||
$view->vars['attr']['data-search-url'] = $this->urlGenerator
|
||||
->generate('chill_main_search', [ 'name' => PersonSearch::NAME, '_format' => 'json' ]);
|
||||
$view->vars['attr']['data-placeholder'] = $this->translator->trans($options['placeholder']);
|
||||
$view->vars['attr']['data-no-results-label'] = $this->translator->trans('select2.no_results');
|
||||
$view->vars['attr']['data-error-load-label'] = $this->translator->trans('select2.error_loading');
|
||||
$view->vars['attr']['data-searching-label'] = $this->translator->trans('select2.searching');
|
||||
}
|
||||
|
||||
protected function filterCentersfom(Options $options)
|
||||
{
|
||||
if (null === $options['role']) {
|
||||
$centers = array_map(function (GroupCenter $g) {
|
||||
return $g->getCenter();
|
||||
}, $this->user->getGroupCenters()->toArray());
|
||||
} else {
|
||||
$centers = $this->authorizationHelper
|
||||
->getReachableCenters($this->user, $options['role']);
|
||||
}
|
||||
|
||||
if (null === $options['centers']) {
|
||||
// we select all selected centers
|
||||
$selectedCenters = $centers;
|
||||
} else {
|
||||
$selectedCenters = [];
|
||||
$optionsCenters = is_array($options['centers']) ?
|
||||
$options['centers'] : [$options['centers']];
|
||||
|
||||
foreach ($optionsCenters as $c) {
|
||||
// check that every member of the array is a center
|
||||
if (!$c instanceof Center) {
|
||||
throw new RuntimeException('Every member of the "centers" '
|
||||
. 'option must be an instance of ' . Center::class);
|
||||
}
|
||||
|
||||
if (!in_array($c->getId(), array_map(
|
||||
function (Center $c) { return $c->getId(); },
|
||||
$centers
|
||||
))) {
|
||||
throw new AccessDeniedException('The given center is not reachable');
|
||||
}
|
||||
$selectedCenters[] = $c;
|
||||
}
|
||||
}
|
||||
|
||||
return $selectedCenters;
|
||||
}
|
||||
}
|
||||
|
@@ -1,40 +1,25 @@
|
||||
<?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\PersonBundle\Form\Type;
|
||||
|
||||
use Chill\MainBundle\Form\Type\DataTransformer\ObjectToIdTransformer;
|
||||
use Chill\MainBundle\Form\Type\Select2ChoiceType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\PersonBundle\Entity\MaritalStatus;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Chill\MainBundle\Form\Type\DataTransformer\ObjectToIdTransformer;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Chill\MainBundle\Form\Type\Select2ChoiceType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* A type to select the marital status
|
||||
*
|
||||
* @author Champs-Libres COOP
|
||||
* A type to select the marital status.
|
||||
*/
|
||||
class Select2MaritalStatusType extends AbstractType
|
||||
{
|
||||
@@ -48,24 +33,16 @@ class Select2MaritalStatusType extends AbstractType
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
public function getBlockPrefix() {
|
||||
return 'select2_chill_marital_status';
|
||||
}
|
||||
|
||||
public function getParent() {
|
||||
return Select2ChoiceType::class;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$transformer = new ObjectToIdTransformer($this->em,'Chill\PersonBundle\Entity\MaritalStatus');
|
||||
$transformer = new ObjectToIdTransformer($this->em, 'Chill\PersonBundle\Entity\MaritalStatus');
|
||||
$builder->addModelTransformer($transformer);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$maritalStatuses = $this->em->getRepository('Chill\PersonBundle\Entity\MaritalStatus')->findAll();
|
||||
$choices = array();
|
||||
$choices = [];
|
||||
|
||||
foreach ($maritalStatuses as $ms) {
|
||||
$choices[$ms->getId()] = $this->translatableStringHelper->localize($ms->getName());
|
||||
@@ -73,9 +50,19 @@ class Select2MaritalStatusType extends AbstractType
|
||||
|
||||
asort($choices, SORT_STRING | SORT_FLAG_CASE);
|
||||
|
||||
$resolver->setDefaults(array(
|
||||
'class' => MaritalStatus::class,
|
||||
'choices' => array_combine(array_values($choices),array_keys($choices))
|
||||
));
|
||||
$resolver->setDefaults([
|
||||
'class' => MaritalStatus::class,
|
||||
'choices' => array_combine(array_values($choices), array_keys($choices)),
|
||||
]);
|
||||
}
|
||||
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'select2_chill_marital_status';
|
||||
}
|
||||
|
||||
public function getParent()
|
||||
{
|
||||
return Select2ChoiceType::class;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user