Add a link between accompanying period and user

It is now allowed to indicates who make/made the accompanying period.

This feature may be hidden by a specific configuration option. Default
to visible.
This commit is contained in:
Julien Fastré 2019-07-01 15:21:34 +02:00
parent 5b60415166
commit 19cc54a674
13 changed files with 173 additions and 31 deletions

View File

@ -45,3 +45,4 @@ Branche master
==============
- fix error on macro renderPerson / withLink not taken into account
- add a link between accompanying person and user

View File

@ -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);

View File

@ -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')
);

View File

@ -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
;

View File

@ -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;
}
}

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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 }

View File

@ -0,0 +1,24 @@
<?php declare(strict_types=1);
namespace Application\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Add a link between accompanying periods and users
*/
final class Version20190701124238 extends AbstractMigration
{
public function up(Schema $schema) : void
{
$this->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');
}
}

View File

@ -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

View File

@ -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' } ) }}

View File

@ -10,6 +10,9 @@
<tr>
<th class="chill-red">{{ 'Opening date'|trans }}</th>
<th class="chill-green">{{ 'Closing date'|trans }}</th>
{% if chill_accompanying_periods.fields.user == 'visible' %}
<th class="chill-green">{{ 'Accompanying user'|trans }}</th>
{% endif %}
<th class="chill-orange">{{ 'Remark'|trans }}</th>
<th>&nbsp;</th>
</tr>
@ -26,6 +29,15 @@
{{ accompanying_period.closingDate|localizeddate('long', 'none', app.request.locale) }}
{% endif %}
{% endspaceless %}</td>
{% if chill_accompanying_periods.fields.user == 'visible' %}
<td>
{% if accompanying_period.user %}
{{ accompanying_period.user.username }}
{% else %}
<span class="chill-no-data-statement">{{ 'No accompanying user'|trans }}</span>
{% endif %}
</td>
{% endif %}
<td>
{% if accompanying_period.remark is empty %}
<p class="chill-no-data-statement">{{ 'No remark'|trans }}</p>