Fixes for feature "Regroupment of center"

* allow more than 15 character in regroupment name
* remove unused methods in PickCenterType
* show only active Regroupment in form
* remove dead code and commented code
This commit is contained in:
Julien Fastré 2023-03-01 17:10:59 +01:00
parent 73fa585707
commit 62532e0a90
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
6 changed files with 43 additions and 39 deletions

View File

@ -43,7 +43,7 @@ class Regroupment
private bool $isActive = true;
/**
* @ORM\Column(type="string", length=15, options={"default": ""}, nullable=false)
* @ORM\Column(type="text", options={"default": ""}, nullable=false)
*/
private string $name = '';

View File

@ -16,6 +16,7 @@ use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Regroupment;
use Chill\MainBundle\Export\ExportManager;
use Chill\MainBundle\Form\DataMapper\ExportPickCenterDataMapper;
use Chill\MainBundle\Repository\RegroupmentRepository;
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
@ -29,29 +30,28 @@ use function count;
/**
* Pick centers amongst available centers for the user.
*/
class PickCenterType extends AbstractType
final class PickCenterType extends AbstractType
{
public const CENTERS_IDENTIFIERS = 'c';
protected AuthorizationHelperInterface $authorizationHelper;
private AuthorizationHelperInterface $authorizationHelper;
protected ExportManager $exportManager;
private ExportManager $exportManager;
protected UserInterface $user;
private RegroupmentRepository $regroupmentRepository;
private UserInterface $user;
public function __construct(
TokenStorageInterface $tokenStorage,
ExportManager $exportManager,
RegroupmentRepository $regroupmentRepository,
AuthorizationHelperInterface $authorizationHelper
) {
$this->exportManager = $exportManager;
$this->user = $tokenStorage->getToken()->getUser();
$this->authorizationHelper = $authorizationHelper;
}
public function addGroupingCenter(GroupingCenterInterface $grouping)
{
$this->groupingCenters[md5($grouping->getName())] = $grouping;
$this->regroupmentRepository = $regroupmentRepository;
}
public function buildForm(FormBuilderInterface $builder, array $options)
@ -71,13 +71,14 @@ class PickCenterType extends AbstractType
'choice_label' => static function (Center $c) {
return $c->getName();
},
'data' => count($this->groupingCenters) > 0 ? null : $centers,
'data' => $centers,
])
->add('regroupment', EntityType::class, [
'class' => Regroupment::class,
'label' => 'regroupment',
'multiple' => true,
'expanded' => true,
'choices' => $this->regroupmentRepository->findAllActive(),
'choice_label' => static function (Regroupment $r) {
return $r->getName();
},

View File

@ -1,18 +0,0 @@
<?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\Export;
use Symfony\Component\Form\AbstractType;
class PickRegroupmentType extends AbstractType
{
}

View File

@ -38,6 +38,11 @@ final class RegroupmentRepository implements ObjectRepository
return $this->repository->findAll();
}
public function findAllActive(): array
{
return $this->repository->findBy(['isActive' => true], ['name' => 'ASC']);
}
/**
* @param mixed|null $limit
* @param mixed|null $offset

View File

@ -44,16 +44,6 @@
<h3 class="m-3">{{ 'Pick aggregated centers'|trans }}</h3>
{{ form_widget(form.centers.regroupment) }}
{# {% if form.centers.children.g is defined %}#}
{##}
{# <h3>{{ 'Pick aggregated centers'|trans }}</h3>#}
{##}
{# {% for f in form.centers.children.g.children %}#}
{# {{ form_row(f) }}#}
{# {% endfor %}#}
{##}
{# {% endif %}#}
</section>
<p>{{ form_widget(form.submit, { 'attr' : { 'class' : 'btn btn-action btn-create' }, 'label' : 'Go to export options' } ) }}</p>

View File

@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Chill\Migrations\Main;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20230301155213 extends AbstractMigration
{
public function getDescription(): string
{
return 'Alter type to TEXT for regroupment.name';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE regroupment ALTER name TYPE TEXT');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE regroupment ALTER name TYPE VARCHAR(15)');
}
}