diff --git a/CHANGELOG.md b/CHANGELOG.md index 420719dfd..8e09cbb8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,3 +45,4 @@ Branche master ============== - fix error on macro renderPerson / withLink not taken into account +- add a link between accompanying person and user diff --git a/Controller/AccompanyingPeriodController.php b/Controller/AccompanyingPeriodController.php index dd6354b20..6351189c9 100644 --- a/Controller/AccompanyingPeriodController.php +++ b/Controller/AccompanyingPeriodController.php @@ -79,8 +79,13 @@ class AccompanyingPeriodController extends Controller $person->addAccompanyingPeriod( $accompanyingPeriod); - $form = $this->createForm(AccompanyingPeriodType::class, - $accompanyingPeriod, array('period_action' => 'create')); + $form = $this->createForm( + AccompanyingPeriodType::class, + $accompanyingPeriod, + [ + 'period_action' => 'create', + 'center' => $person->getCenter() + ]); if ($request->getMethod() === 'POST') { $form->handleRequest($request); @@ -135,7 +140,8 @@ class AccompanyingPeriodController extends Controller 'You are not allowed to update this person'); $form = $this->createForm(AccompanyingPeriodType::class, - $accompanyingPeriod, array('period_action' => 'update')); + $accompanyingPeriod, array('period_action' => 'update', + 'center' => $person->getCenter())); if ($request->getMethod() === 'POST') { $form->handleRequest($request); @@ -190,7 +196,8 @@ class AccompanyingPeriodController extends Controller $current = $person->getCurrentAccompanyingPeriod(); $form = $this->createForm(AccompanyingPeriodType::class, $current, array( - 'period_action' => 'close' + 'period_action' => 'close', + 'center' => $person->getCenter() )); if ($request->getMethod() === 'POST') { @@ -286,7 +293,8 @@ class AccompanyingPeriodController extends Controller $accompanyingPeriod = new AccompanyingPeriod(new \DateTime()); $form = $this->createForm(AccompanyingPeriodType::class, - $accompanyingPeriod, array('period_action' => 'open')); + $accompanyingPeriod, array('period_action' => 'open', + 'center' => $person->getCenter())); if ($request->getMethod() === 'POST') { $form->handleRequest($request); diff --git a/DependencyInjection/ChillPersonExtension.php b/DependencyInjection/ChillPersonExtension.php index 41a7ab71f..3f78351cc 100644 --- a/DependencyInjection/ChillPersonExtension.php +++ b/DependencyInjection/ChillPersonExtension.php @@ -53,6 +53,7 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac $config['validation']['birthdate_not_after']); $this->handlePersonFieldsParameters($container, $config['person_fields']); + $this->handleAccompanyingPeriodsFieldsParameters($container, $config['accompanying_periods_fields']); $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yml'); @@ -65,6 +66,7 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac $loader->load('services/privacyEvent.yml'); $loader->load('services/command.yml'); $loader->load('services/actions.yml'); + $loader->load('services/form.yml'); if ($container->getParameter('chill_person.accompanying_period') !== 'hidden') { $loader->load('services/exports_accompanying_period.yml'); @@ -90,6 +92,21 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac } } } + + private function handleAccompanyingPeriodsFieldsParameters(ContainerBuilder $container, $config) + { + $container->setParameter('chill_person.accompanying_period_fields', $config); + + foreach ($config as $key => $value) { + switch($key) { + case 'enabled': + break; + default: + $container->setParameter('chill_person.accompanying_period_fields.'.$key, $value); + break; + } + } + } private function declarePersonAsCustomizable (ContainerBuilder $container) { @@ -131,7 +148,10 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac 'globals' => array( 'chill_person' => array( 'fields' => $config['person_fields'] - ) + ), + 'chill_accompanying_periods' => [ + 'fields' => $config['accompanying_periods_fields'] + ] ), 'form_themes' => array('ChillPersonBundle:Export:ListPersonFormFields.html.twig') ); diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 3807d7750..f71344029 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -78,6 +78,12 @@ class Configuration implements ConfigurationInterface ->append($this->addFieldNode('memo')) ->end() //children for 'person_fields', parent = array 'person_fields' ->end() // person_fields, parent = children of root + ->arrayNode('accompanying_periods_fields') + ->canBeDisabled() + ->children() + ->append($this->addFieldNode('user')) + ->end() //children for 'accompanying_person_fields', parent = array 'person_fields' + ->end() // paccompanying_person_fields, parent = children of root ->end() // children of 'root', parent = root ; diff --git a/Entity/AccompanyingPeriod.php b/Entity/AccompanyingPeriod.php index 2c4132698..872a2a978 100644 --- a/Entity/AccompanyingPeriod.php +++ b/Entity/AccompanyingPeriod.php @@ -24,6 +24,7 @@ namespace Chill\PersonBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Context\ExecutionContextInterface; +use Chill\MainBundle\Entity\User; /** * AccompanyingPeriod @@ -48,6 +49,13 @@ class AccompanyingPeriod /** @var AccompanyingPeriod\ClosingMotive */ private $closingMotive = null; + /** + * The user making the accompanying + * + * @var User + */ + private $user; + /** * * @param \DateTime $dateOpening @@ -244,4 +252,18 @@ class AccompanyingPeriod return false; } } + + function getUser(): ?User + { + return $this->user; + } + + function setUser(User $user): self + { + $this->user = $user; + + return $this; + } + + } diff --git a/Form/AccompanyingPeriodType.php b/Form/AccompanyingPeriodType.php index d7b39dde6..1c195a5fc 100644 --- a/Form/AccompanyingPeriodType.php +++ b/Form/AccompanyingPeriodType.php @@ -11,11 +11,33 @@ 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\ClosingMotiveType; 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 = array(); + + /** + * + * @param string[] $config configuration of visibility of some fields + */ + public function __construct(array $config) + { + $this->config = $config; + } + /** * @param FormBuilderInterface $builder * @param array $options @@ -53,6 +75,13 @@ class AccompanyingPeriodType extends AbstractType $form->add('closingMotive', ClosingMotiveType::class); } }); + + if ($this->config['user'] === 'visible') { + $builder->add('user', UserPickerType::class, [ + 'center' => $options['center'], + 'role' => new Role(PersonVoter::SEE), + ]); + } $builder->add('remark', TextareaType::class, array( 'required' => false @@ -71,9 +100,12 @@ class AccompanyingPeriodType extends AbstractType $resolver ->setRequired(array('period_action')) - ->addAllowedTypes('period_action','string') + ->addAllowedTypes('period_action', 'string') ->addAllowedValues('period_action', array( - 'update', 'open', 'close', 'create')); + 'update', 'open', 'close', 'create')) + ->setRequired('center') + ->setAllowedTypes('center', \Chill\MainBundle\Entity\Center::class) + ; } public function buildView(FormView $view, FormInterface $form, array $options) diff --git a/Resources/config/doctrine/AccompanyingPeriod.orm.yml b/Resources/config/doctrine/AccompanyingPeriod.orm.yml index 9b2ebe225..af2083ee3 100644 --- a/Resources/config/doctrine/AccompanyingPeriod.orm.yml +++ b/Resources/config/doctrine/AccompanyingPeriod.orm.yml @@ -23,3 +23,6 @@ Chill\PersonBundle\Entity\AccompanyingPeriod: closingMotive: targetEntity: Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive nullable: true + user: + targetEntity: Chill\MainBundle\Entity\User + nullable: true diff --git a/Resources/config/services.yml b/Resources/config/services.yml index ceeeeeaed..26ffd979c 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -2,19 +2,7 @@ parameters: # cl_chill_person.example.class: Chill\PersonBundle\Example services: - chill.person.form.person_creation: - class: Chill\PersonBundle\Form\PersonType - arguments: - - %chill_person.person_fields% - tags: - - { name: form.type } - - chill.person.accompanying_period_closing_motive: - class: Chill\PersonBundle\Form\Type\ClosingMotiveType - arguments: - - "@chill.main.helper.translatable_string" - tags: - - { name: form.type, alias: closing_motive } + chill.person.form.type.select2maritalstatus: class: Chill\PersonBundle\Form\Type\Select2MaritalStatusType @@ -59,16 +47,6 @@ services: tags: - { name: form.type, alias: chill_personbundle_person_creation } - chill.person.form.type.pick_person: - class: Chill\PersonBundle\Form\Type\PickPersonType - arguments: - - "@chill.person.repository.person" - - "@security.token_storage" - - "@chill.main.security.authorization.helper" - - '@Symfony\Component\Routing\Generator\UrlGeneratorInterface' - - '@Symfony\Component\Translation\TranslatorInterface' - tags: - - { name: form.type } chill.person.repository.person: class: Chill\PersonBundle\Entity\PersonRepository diff --git a/Resources/config/services/form.yml b/Resources/config/services/form.yml new file mode 100644 index 000000000..c2ae1d3dc --- /dev/null +++ b/Resources/config/services/form.yml @@ -0,0 +1,31 @@ +services: + chill.person.form.person_creation: + class: Chill\PersonBundle\Form\PersonType + arguments: + - "%chill_person.person_fields%" + tags: + - { name: form.type } + + chill.person.accompanying_period_closing_motive: + class: Chill\PersonBundle\Form\Type\ClosingMotiveType + arguments: + - "@chill.main.helper.translatable_string" + tags: + - { name: form.type, alias: closing_motive } + + Chill\PersonBundle\Form\AccompanyingPeriodType: + arguments: + $config: "%chill_person.accompanying_period_fields%" + tags: + - { name: form.type } + + chill.person.form.type.pick_person: + class: Chill\PersonBundle\Form\Type\PickPersonType + arguments: + - "@chill.person.repository.person" + - "@security.token_storage" + - "@chill.main.security.authorization.helper" + - '@Symfony\Component\Routing\Generator\UrlGeneratorInterface' + - '@Symfony\Component\Translation\TranslatorInterface' + tags: + - { name: form.type } diff --git a/Resources/migrations/Version20190701124238.php b/Resources/migrations/Version20190701124238.php new file mode 100644 index 000000000..b826dc3bc --- /dev/null +++ b/Resources/migrations/Version20190701124238.php @@ -0,0 +1,24 @@ +addSql('ALTER TABLE chill_person_accompanying_period ADD user_id INT DEFAULT NULL;'); + $this->addSql('ALTER TABLE chill_person_accompanying_period ADD CONSTRAINT FK_E260A868A76ED395 FOREIGN KEY (user_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE;'); + $this->addSql('CREATE INDEX IDX_E260A868A76ED395 ON chill_person_accompanying_period (user_id);'); + } + + public function down(Schema $schema) : void + { + $this->addSql('ALTER TABLE chill_person_accompanying_period DROP user_id'); + } +} diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index a82bfe0e1..8989aee47 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -127,6 +127,7 @@ Re-Open a period: Ré-ouvrir une période d'accompagnement Are you sure you want to re-open this period ?: Êtes-vous sûr de vouloir ré-ouvrir cette période d'accompagnement ? 'The period has been re-opened': La période d'accompagnement a été ré-ouverte. Pediod closing form is not valid: Le formulaire n'est pas valide +Accompanying user: Accompagnant No data given: Pas d'information # pickAPersonType Pick a person: Choisir une personne diff --git a/Resources/views/AccompanyingPeriod/form.html.twig b/Resources/views/AccompanyingPeriod/form.html.twig index 939be435d..04645224c 100644 --- a/Resources/views/AccompanyingPeriod/form.html.twig +++ b/Resources/views/AccompanyingPeriod/form.html.twig @@ -39,6 +39,10 @@ {% if form.closingMotive is defined %} {{ form_row(form.closingMotive, {'label' : 'Closing motive'} ) }} {% endif %} + +{% if form.user is defined %} + {{ form_row(form.user, {'label': 'Accompanying user'}) }} +{% endif %} {{ form_row(form.remark, {'label' : 'Remark' } ) }} diff --git a/Resources/views/AccompanyingPeriod/list.html.twig b/Resources/views/AccompanyingPeriod/list.html.twig index 532180d25..bf711919d 100644 --- a/Resources/views/AccompanyingPeriod/list.html.twig +++ b/Resources/views/AccompanyingPeriod/list.html.twig @@ -10,6 +10,9 @@ {{ 'Opening date'|trans }} {{ 'Closing date'|trans }} + {% if chill_accompanying_periods.fields.user == 'visible' %} + {{ 'Accompanying user'|trans }} + {% endif %} {{ 'Remark'|trans }}   @@ -26,6 +29,15 @@ {{ accompanying_period.closingDate|localizeddate('long', 'none', app.request.locale) }} {% endif %} {% endspaceless %} + {% if chill_accompanying_periods.fields.user == 'visible' %} + + {% if accompanying_period.user %} + {{ accompanying_period.user.username }} + {% else %} + {{ 'No accompanying user'|trans }} + {% endif %} + + {% endif %} {% if accompanying_period.remark is empty %}

{{ 'No remark'|trans }}