mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-07-03 15:36:14 +00:00
106 lines
2.8 KiB
PHP
106 lines
2.8 KiB
PHP
<?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\DocGeneratorBundle\Context;
|
|
|
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
|
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation;
|
|
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
|
use Exception;
|
|
|
|
/**
|
|
* Context that display a form to select a member of a houseHold.
|
|
*/
|
|
class HouseholdMemberSelectionContext implements DocGeneratorContextInterface
|
|
{
|
|
/**
|
|
* Get the data that will be injected to the generated document.
|
|
*
|
|
* @param mixed $entity
|
|
*/
|
|
public function getData($entity): array
|
|
{
|
|
$datas = [
|
|
'setValues' => [],
|
|
'cloneRowAndSetValues' => [],
|
|
];
|
|
|
|
$persons = $entity->getAccompanyingPeriodWork()->getPersons();
|
|
|
|
if (count($persons) > 0) {
|
|
$firstPerson = $persons[0];
|
|
|
|
$datas['setValues'][] = [
|
|
'firstPersonFirstName' => $firstPerson->getFirstName(),
|
|
'firstPersonLastName' => $firstPerson->getLastName(), ];
|
|
}
|
|
|
|
if (get_class($entity) == AccompanyingPeriodWorkEvaluation::class) {
|
|
$values = [];
|
|
|
|
foreach ($entity->getAccompanyingPeriodWork()->getPersons() as $person) {
|
|
$i = 1;
|
|
$values[] = [
|
|
'personRowId' => $i,
|
|
'personFirstName' => $person->getFirstName(),
|
|
'personLastName' => $person->getLastName(),
|
|
];
|
|
}
|
|
|
|
$datas['cloneRowAndSetValues'][] = [
|
|
'personRowId', $values, ];
|
|
}
|
|
|
|
return $datas;
|
|
}
|
|
|
|
/**
|
|
* Generate the form that display.
|
|
*
|
|
* @param mixed $entity
|
|
*/
|
|
public function getForm($entity)
|
|
{
|
|
throw new Exception('No implemented yet', 1);
|
|
$choices = [];
|
|
|
|
if (get_class($entity) == AccompanyingPeriodWorkEvaluation::class) {
|
|
foreach ($entity->getAccompanyingPeriodWork()->getPersons() as $person) {
|
|
$choices[$person->getId()] = $person->getName();
|
|
}
|
|
}
|
|
|
|
$builder->add('members', ChoiceType::class, [
|
|
'choices' => $choices,
|
|
'placeholder' => 'Choose a person',
|
|
'label' => 'Person to add',
|
|
]);
|
|
|
|
return $builder;
|
|
}
|
|
|
|
/**
|
|
* has form.
|
|
*/
|
|
public function hasForm(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* True of false which entity supports.
|
|
*/
|
|
public function supports(string $entityClass): bool
|
|
{
|
|
return
|
|
(AccompanyingPeriod::class == $entityClass)
|
|
|| (SocialAction::class == $entityClass);
|
|
}
|
|
}
|