fix folder name

This commit is contained in:
2021-03-18 13:37:13 +01:00
parent a2f6773f5a
commit eaa0ad925f
1578 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,132 @@
<?php
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\FormEvents;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
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;
/**
* Class AccompanyingPeriodType
*
* @package Chill\PersonBundle\Form
*/
class AccompanyingPeriodType extends AbstractType
{
/**
* array of configuration for accompanying_periods.
*
* Contains whether we should add fields some optional fields (optional per
* instance)
*
* @var string[]
*/
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') {
$builder
->add('openingDate', DateType::class, [
"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())
) {
$builder->add('closingDate', DateType::class, [
'required' => true,
'widget' => 'single_text',
'format' => 'dd-MM-yyyy'
]);
$builder->add('closingMotive', ClosingMotivePickerType::class);
}
if ($this->config['user'] === 'visible') {
$builder->add('user', UserPickerType::class, [
'center' => $options['center'],
'role' => new Role(PersonVoter::SEE),
]);
}
$builder->add('remark', TextareaType::class, [
'required' => false
]);
}
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => 'Chill\PersonBundle\Entity\AccompanyingPeriod'
]);
$resolver
->setRequired(['period_action'])
->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'];
}
/**
* @return string
*/
public function getBlockPrefix()
{
return 'chill_personbundle_accompanyingperiod';
}
}

View File

@@ -0,0 +1,138 @@
<?php
/*
* Copyright (C) 2018 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/>.
*/
namespace Chill\PersonBundle\Form\ChoiceLoader;
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
use Doctrine\ORM\EntityRepository;
use Chill\PersonBundle\Entity\Person;
/**
* Class PersonChoiceLoader
*
* @package Chill\PersonBundle\Form\ChoiceLoader
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class PersonChoiceLoader implements ChoiceLoaderInterface
{
/**
* @var EntityRepository
*/
protected $personRepository;
/**
* @var array
*/
protected $lazyLoadedPersons = [];
/**
* @var array
*/
protected $centers = [];
/**
* PersonChoiceLoader constructor.
*
* @param EntityRepository $personRepository
* @param array|null $centers
*/
public function __construct(
EntityRepository $personRepository,
array $centers = null
) {
$this->personRepository = $personRepository;
if (NULL !== $centers) {
$this->centers = $centers;
}
}
/**
* @return bool
*/
protected function hasCenterFilter()
{
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;
}
}

View File

@@ -0,0 +1,76 @@
<?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
*
* @package Chill\PersonBundle\Form
*/
class ClosingMotiveType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', TranslatableStringFormType::class, [
'label' => 'Nom'
])
->add('active', CheckboxType::class, [
'label' => 'Actif ?',
'required' => false
])
->add('ordering', NumberType::class, [
'label' => 'Ordre d\'apparition',
'required' => true,
'scale' => 5
])
->add('parent', ClosingMotivePickerType::class, [
'label' => 'Parent',
'required' => false,
'placeholder' => 'closing_motive.any parent',
'multiple' => false,
'only_leaf' => false
])
;
}
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefault('class', ClosingMotive::class)
;
}
}

View File

@@ -0,0 +1,159 @@
<?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/>.
*/
namespace Chill\PersonBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Chill\MainBundle\Form\Type\CenterType;
use Chill\PersonBundle\Form\Type\GenderType;
use Chill\MainBundle\Form\Type\DataTransformer\CenterTransformer;
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
use Chill\PersonBundle\Form\Type\PersonAltNameType;
class CreationPersonType extends AbstractType
{
const NAME = 'chill_personbundle_person_creation';
const FORM_NOT_REVIEWED = 'not_reviewed';
const FORM_REVIEWED = 'reviewed' ;
const FORM_BEING_REVIEWED = 'being_reviewed';
/**
*
* @var CenterTransformer
*/
private $centerTransformer;
/**
*
* @var ConfigPersonAltNamesHelper
*/
protected $configPersonAltNamesHelper;
public function __construct(
CenterTransformer $centerTransformer,
ConfigPersonAltNamesHelper $configPersonAltNamesHelper
) {
$this->centerTransformer = $centerTransformer;
$this->configPersonAltNamesHelper = $configPersonAltNamesHelper;
}
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
if ($options['form_status'] === self::FORM_BEING_REVIEWED) {
$dateToStringTransformer = new DateTimeToStringTransformer(
null, null, 'd-m-Y', false);
$builder->add('firstName', HiddenType::class)
->add('lastName', HiddenType::class)
->add('birthdate', HiddenType::class, array(
'property_path' => 'birthdate'
))
->add('gender', HiddenType::class)
->add('creation_date', HiddenType::class, array(
'mapped' => false
))
->add('form_status', HiddenType::class, array(
'mapped' => false,
'data' => $options['form_status']
))
->add('center', HiddenType::class)
;
if ($this->configPersonAltNamesHelper->hasAltNames()) {
$builder->add('altNames', PersonAltNameType::class, [
'by_reference' => false,
'force_hidden' => true
]);
}
$builder->get('birthdate')
->addModelTransformer($dateToStringTransformer);
$builder->get('creation_date')
->addModelTransformer($dateToStringTransformer);
$builder->get('center')
->addModelTransformer($this->centerTransformer);
} else {
$builder
->add('firstName')
->add('lastName')
->add('birthdate', DateType::class, array('required' => false,
'widget' => 'single_text', 'format' => 'dd-MM-yyyy'))
->add('gender', GenderType::class, array(
'required' => true, 'placeholder' => null
))
->add('creation_date', DateType::class, array(
'required' => true,
'widget' => 'single_text',
'format' => 'dd-MM-yyyy',
'mapped' => false,
'data' => new \DateTime()))
->add('form_status', HiddenType::class, array(
'data' => $options['form_status'],
'mapped' => false
))
->add('center', CenterType::class)
;
if ($this->configPersonAltNamesHelper->hasAltNames()) {
$builder->add('altNames', PersonAltNameType::class, [
'by_reference' => false
]);
}
}
}
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Chill\PersonBundle\Entity\Person'
));
$resolver->setRequired('form_status')
->setAllowedValues('form_status', array(
self::FORM_BEING_REVIEWED,
self::FORM_NOT_REVIEWED,
self::FORM_REVIEWED
));
}
/**
* @return string
*/
public function getBlockPrefix()
{
return self::NAME;
}
}

View File

@@ -0,0 +1,87 @@
<?php
namespace Chill\PersonBundle\Form\DataMapper;
use Symfony\Component\Form\DataMapperInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Chill\PersonBundle\Entity\PersonAltName;
/**
*
*
*/
class PersonAltNameDataMapper implements DataMapperInterface
{
public function mapDataToForms($viewData, $forms)
{
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)) {
$form->setData($viewData->get($mapIndexToKey[$key])->getLabel());
}
}
}
/**
*
* @param FormInterface[] $forms
* @param Collection $viewData
*/
public function mapFormsToData($forms, &$viewData)
{
$mapIndexToKey = [];
if (is_array($viewData)) {
$dataIterator = $viewData;
} else {
$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 ($isEmpty) {
$viewData->remove($mapIndexToKey[$key]);
} else {
$viewData->get($mapIndexToKey[$key])->setLabel($form->getData());
}
} else {
if (!$isEmpty) {
$altName = (new PersonAltName())
->setKey($key)
->setLabel($form->getData())
;
if (is_array($viewData)) {
$viewData[] = $altName;
} else {
$viewData->add($altName);
}
}
}
}
}
}

View File

@@ -0,0 +1,70 @@
<?php
namespace Chill\PersonBundle\Form\DataTransformer;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Doctrine\Persistence\ObjectManager;
use Chill\PersonBundle\Entity\Person;
class PersonToIdTransformer implements DataTransformerInterface
{
/**
* @var ObjectManager
*/
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.
*/
public function reverseTransform($id)
{
if (!$id) {
return null;
}
$issue = $this->om
->getRepository('ChillPersonBundle:Person')
->findOneBy(array('id' => $id))
;
if (null === $issue) {
throw new TransformationFailedException(sprintf(
'An issue with id "%s" does not exist!',
$id
));
}
return $issue;
}
}
?>

View File

@@ -0,0 +1,45 @@
<?php
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 Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Class MaritalStatusType
*
* @package Chill\PersonBundle\Form
*/
class MaritalStatusType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('id', TextType::class, [
'label' => 'Identifiant'
])
->add('name', TranslatableStringFormType::class, [
'label' => 'Nom'
])
;
}
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefault('class', MaritalStatus::class)
;
}
}

View File

@@ -0,0 +1,175 @@
<?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/>.
*/
namespace Chill\PersonBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Chill\PersonBundle\Form\Type\GenderType;
use Chill\MainBundle\Form\Type\Select2CountryType;
use Chill\MainBundle\Form\Type\Select2LanguageType;
use Chill\CustomFieldsBundle\Form\Type\CustomFieldType;
use Chill\PersonBundle\Form\Type\Select2MaritalStatusType;
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
use Chill\PersonBundle\Form\Type\PersonAltNameType;
class PersonType extends AbstractType
{
/**
* array of configuration for person_fields.
*
* Contains whether we should add fields some optional fields (optional per
* instance)
*
* @var string[]
*/
protected $config = array();
/**
*
* @var ConfigPersonAltNamesHelper
*/
protected $configAltNamesHelper;
/**
*
* @param string[] $personFieldsConfiguration configuration of visibility of some fields
*/
public function __construct(
array $personFieldsConfiguration,
ConfigPersonAltNamesHelper $configAltNamesHelper
) {
$this->config = $personFieldsConfiguration;
$this->configAltNamesHelper = $configAltNamesHelper;
}
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('firstName')
->add('lastName')
->add('birthdate', DateType::class, array('required' => false, 'widget' => 'single_text', 'format' => 'dd-MM-yyyy'))
->add('gender', GenderType::class, array(
'required' => true
));
if ($this->configAltNamesHelper->hasAltNames()) {
$builder->add('altNames', PersonAltNameType::class, [
'by_reference' => false
]);
}
if ($this->config['memo'] === 'visible') {
$builder
->add('memo', TextareaType::class, array('required' => false))
;
}
if ($this->config['place_of_birth'] === 'visible') {
$builder->add('placeOfBirth', TextType::class, array('required' => false));
}
if ($this->config['contact_info'] === 'visible') {
$builder->add('contactInfo', TextareaType::class, array('required' => false));
}
if ($this->config['phonenumber'] === 'visible') {
$builder->add('phonenumber', TelType::class, array('required' => false));
}
if ($this->config['mobilenumber'] === 'visible') {
$builder->add('mobilenumber', TelType::class, array('required' => false));
}
if ($this->config['email'] === 'visible') {
$builder->add('email', EmailType::class, array('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(
'required' => false,
'multiple' => true
));
}
if ($this->config['marital_status'] === 'visible'){
$builder->add('maritalStatus', Select2MaritalStatusType::class, array(
'required' => false
));
}
if($options['cFGroup']) {
$builder
->add('cFData', CustomFieldType::class,
array('attr' => array('class' => 'cf-fields'), 'group' => $options['cFGroup']))
;
}
}
/**
* @param OptionsResolverInterface $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Chill\PersonBundle\Entity\Person',
'validation_groups' => array('general', 'creation')
));
$resolver->setRequired(array(
'cFGroup'
));
$resolver->setAllowedTypes(
'cFGroup', array('null', 'Chill\CustomFieldsBundle\Entity\CustomFieldsGroup')
);
}
/**
* @return string
*/
public function getBlockPrefix()
{
return 'chill_personbundle_person';
}
}

View File

@@ -0,0 +1,98 @@
<?php
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\TranslatableStringHelper;
use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive;
use Chill\MainBundle\Templating\Entity\ChillEntityRenderExtension;
use Symfony\Component\OptionsResolver\Options;
use Chill\PersonBundle\Repository\ClosingMotiveRepository;
/**
* Class ClosingMotivePickerType
* A type to add a closing motive
*
* @package Chill\PersonBundle\Form\Type
*/
class ClosingMotivePickerType extends AbstractType
{
/**
* @var TranslatableStringHelper
*/
protected $translatableStringHelper;
/**
* @var ChillEntityRenderExtension
*/
protected $entityRenderExtension;
/**
* @var ClosingMotiveRepository
*/
protected $repository;
/**
* ClosingMotivePickerType constructor.
*
* @param TranslatableStringHelper $translatableStringHelper
* @param ChillEntityRenderExtension $chillEntityRenderExtension
* @param ClosingMotiveRepository $closingMotiveRepository
*/
public function __construct(
TranslatableStringHelper $translatableStringHelper,
ChillEntityRenderExtension $chillEntityRenderExtension,
ClosingMotiveRepository $closingMotiveRepository
) {
$this->translatableStringHelper = $translatableStringHelper;
$this->entityRenderExtension = $chillEntityRenderExtension;
$this->repository = $closingMotiveRepository;
}
/**
* @return string
*/
public function getBlockPrefix()
{
return 'closing_motive';
}
/**
* @return null|string
*/
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']);
})
;
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace Chill\PersonBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Chill\PersonBundle\Entity\Person;
/**
* A type to select the civil union state
*
* @author julien
*/
class GenderType extends AbstractType {
public function getParent() {
return ChoiceType::class;
}
public function configureOptions(OptionsResolver $resolver) {
$a = array(
Person::MALE_GENDER => Person::MALE_GENDER,
Person::FEMALE_GENDER => Person::FEMALE_GENDER,
Person::BOTH_GENDER => Person::BOTH_GENDER
);
$resolver->setDefaults(array(
'choices' => $a,
'expanded' => true,
'multiple' => false,
'placeholder' => null
));
}
}

View File

@@ -0,0 +1,76 @@
<?php
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;
/**
*
*
*/
class PersonAltNameType extends AbstractType
{
/**
*
* @var ConfigPersonAltNamesHelper
*/
private $configHelper;
/**
*
* @var TranslatableStringHelper
*/
private $translatableStringHelper;
public function __construct(
ConfigPersonAltNamesHelper $configHelper,
TranslatableStringHelper $translatableStringHelper
) {
$this->configHelper = $configHelper;
$this->translatableStringHelper = $translatableStringHelper;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
foreach ($this->getKeyChoices() as $label => $key) {
$builder->add(
$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)
{
$resolver
->setDefault('class', \Chill\PersonBundle\Entity\PersonAltName::class)
->setDefined('force_hidden')
->setAllowedTypes('force_hidden', 'bool')
->setDefault('force_hidden', false)
;
}
}

View File

@@ -0,0 +1,191 @@
<?php
/*
* Copyright (C) 2016 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/>.
*/
namespace Chill\PersonBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
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.
*
* The form is embedded in a select2 input.
*
* The people may be filtered :
*
* - with the `centers` option, only the people associated with the given center(s)
* are seen. May be an instance of `Chill\MainBundle\Entity\Center`, or an array of
* `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
*/
protected $urlGenerator;
/**
*
* @var TranslatorInterface
*/
protected $translator;
public function __construct(
PersonRepository $personRepository,
TokenStorageInterface $tokenStorage,
AuthorizationHelper $authorizationHelper,
UrlGeneratorInterface $urlGenerator,
TranslatorInterface $translator
)
{
$this->personRepository = $personRepository;
$this->user = $tokenStorage->getToken()->getUser();
$this->authorizationHelper = $authorizationHelper;
$this->urlGenerator = $urlGenerator;
$this->translator = $translator;
}
protected function filterCentersfom(Options $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;
}
public function configureOptions(OptionsResolver $resolver)
{
parent::configureOptions($resolver);
// 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)
;
// add the default options
$resolver->setDefaults(array(
'class' => Person::class,
'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()
);
},
'attr' => array('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');
}
}

View File

@@ -0,0 +1,81 @@
<?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/>.
*/
namespace Chill\PersonBundle\Form\Type;
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;
/**
* A type to select the marital status
*
* @author Champs-Libres COOP
*/
class Select2MaritalStatusType extends AbstractType
{
/** @var RequestStack */
private $requestStack;
/** @var ObjectManager */
private $em;
public function __construct(RequestStack $requestStack,ObjectManager $em)
{
$this->requestStack = $requestStack;
$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');
$builder->addModelTransformer($transformer);
}
public function configureOptions(OptionsResolver $resolver)
{
$locale = $this->requestStack->getCurrentRequest()->getLocale();
$maritalStatuses = $this->em->getRepository('Chill\PersonBundle\Entity\MaritalStatus')->findAll();
$choices = array();
foreach ($maritalStatuses as $ms) {
$choices[$ms->getId()] = $ms->getName()[$locale];
}
asort($choices, SORT_STRING | SORT_FLAG_CASE);
$resolver->setDefaults(array(
'class' => 'Chill\PersonBundle\Entity\MaritalStatus',
'choices' => array_combine(array_values($choices),array_keys($choices))
));
}
}