Merge remote-tracking branch 'origin/111_exports_suite' into calendar/finalization

This commit is contained in:
2022-11-25 15:29:17 +01:00
169 changed files with 7481 additions and 1515 deletions

View File

@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
/*
* 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\MainBundle\Form\DataMapper;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Symfony\Component\Form\DataMapperInterface;
use Symfony\Component\Form\Exception;
class RollingDateDataMapper implements DataMapperInterface
{
public function mapDataToForms($viewData, $forms)
{
if (null === $viewData) {
return;
}
if (!$viewData instanceof RollingDate) {
throw new Exception\UnexpectedTypeException($viewData, RollingDate::class);
}
$forms = iterator_to_array($forms);
$forms['roll']->setData($viewData->getRoll());
$forms['fixedDate']->setData($viewData->getFixedDate());
}
public function mapFormsToData($forms, &$viewData): void
{
$forms = iterator_to_array($forms);
$viewData = new RollingDate(
$forms['roll']->getData(),
$forms['fixedDate']->getData()
);
}
}

View File

@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
/*
* 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\MainBundle\Form;
use Chill\MainBundle\Entity\SavedExport;
use Chill\MainBundle\Form\Type\ChillTextareaType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class SavedExportType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('title', TextType::class, [
'required' => true,
])
->add('description', ChillTextareaType::class, [
'required' => false,
]);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'class' => SavedExport::class,
]);
}
}

View File

@@ -51,7 +51,9 @@ class EntityToJsonTransformer implements DataTransformerInterface
}
return array_map(
function ($item) { return $this->denormalizeOne($item); },
function ($item) {
return $this->denormalizeOne($item);
},
$denormalized
);
}

View File

@@ -0,0 +1,73 @@
<?php
declare(strict_types=1);
/*
* 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\MainBundle\Form\Type;
use Chill\MainBundle\Form\DataMapper\RollingDateDataMapper;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
class PickRollingDateType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('roll', ChoiceType::class, [
'choices' => array_combine(
array_map(static fn (string $item) => 'rolling_date.' . $item, RollingDate::ALL_T),
RollingDate::ALL_T
),
'multiple' => false,
'expanded' => false,
'label' => 'rolling_date.roll_movement',
])
->add('fixedDate', ChillDateType::class, [
'input' => 'datetime_immutable',
'label' => 'rolling_date.fixed_date_date',
]);
$builder->setDataMapper(new RollingDateDataMapper());
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'class' => RollingDate::class,
'empty_data' => new RollingDate(RollingDate::T_TODAY),
'constraints' => [
new Callback([$this, 'validate']),
],
]);
}
public function validate($data, ExecutionContextInterface $context, $payload): void
{
/** @var RollingDate $data */
if (RollingDate::T_FIXED_DATE === $data->getRoll() && null === $data->getFixedDate()) {
$context
->buildViolation('rolling_date.When fixed date is selected, you must provide a date')
->atPath('fixedDate')
->addViolation();
}
}
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['uniqid'] = uniqid('rollingdate-');
}
}

View File

@@ -66,7 +66,9 @@ class ScopePickerType extends AbstractType
$options['role'] instanceof Role ? $options['role']->getRole() : $options['role'],
$options['center']
),
static function (Scope $s) { return $s->isActive(); }
static function (Scope $s) {
return $s->isActive();
}
);
if (0 === count($items)) {