Commit 3b7daa7a authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Ajout d'une configuration permettant de rendre obligatoire le pays / Le type...

 Ajout d'une configuration permettant de rendre obligatoire le pays / Le type de structure en passant par le formulaire d'ajout/modification
parent 22795450
Loading
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -352,6 +352,16 @@ class AdministrationController extends AbstractOscarController implements UsePro
        if ($this->getHttpXMethod() == "POST") {
            $option = $this->params()->fromPost('parameter_name');
            switch ($option) {
                case OscarConfigurationService::ORGANIZATION_REQUIRED:
                    $this->getLoggerService()->info("Enregistrement des options des organisations");
                    $typeRequired = $this->params()->fromPost('organization_type') == "on";
                    $countryRequired = $this->params()->fromPost('organization_country') == "on";
                    $this->getOscarConfigurationService()
                        ->saveEditableConfKey("organization_require_type", $typeRequired);
                    $this->getOscarConfigurationService()
                        ->saveEditableConfKey("organization_require_country", $countryRequired);
                    return $this->redirect()->toRoute('administration/parameters');

                case OscarConfigurationService::allow_node_selection:
                    $value = $this->params()->fromPost('parameter_value') == "on";
                    $this->getOscarConfigurationService()->setAllowNodeSelection($value);
@@ -427,9 +437,10 @@ class AdministrationController extends AbstractOscarController implements UsePro
                        );
                    }
                    return $this->redirect()->toRoute('administration/parameters');

                case OscarConfigurationService::ORGANIZATION_REQUIRED:
                    throw new OscarException("A faire");
                default:
                    return $this->getResponseBadRequest("Paramètres non-reconnue");
                    return $this->getResponseBadRequest("Paramètres $option non-reconnue");
            }
        }

@@ -466,6 +477,10 @@ class AdministrationController extends AbstractOscarController implements UsePro
            )->getConfiguration('validation.pfi'),
            "allow_node_selection"                                  => $this->getOscarConfigurationService(
            )->isAllowNodeSelection(),
            "organizationRequire" => [
                "type" => $this->getOscarConfigurationService()->getOrganizationRequired()['type'],
                "country" => $this->getOscarConfigurationService()->getOrganizationRequired()['country']
            ]
        ];
    }

+2 −0
Original line number Diff line number Diff line
@@ -498,6 +498,7 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
            $this->getOrganizationService(),
            $this->getOrganizationService()->getOrganizationTypesObject()
        );
        $form->configureRequired($this->getOscarConfigurationService()->getRequiredOrganization());
        $entity = new Organization();
        $form->init();
        $form->bind($entity);
@@ -883,6 +884,7 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
            $this->getOrganizationService(),
            $this->getOrganizationService()->getOrganizationTypesObject()
        );
        $form->configureRequired($this->getOscarConfigurationService()->getRequiredOrganization());
        $form->init();
        $form->bind($entity);

+2 −2
Original line number Diff line number Diff line
@@ -29,9 +29,9 @@ class Country3166Repository extends EntityRepository
        return $q->getQuery()->getResult();
    }

    public function getAllForSelects()
    public function getAllForSelects() :array
    {
        $out = ["" => "Non-définit"];
        $out = ["" => "Non défini"];
        /** @var Country3166 $country */
        foreach ($this->getAll() as $country) {
            $out[$country->getFr()] = $country->getFr();
+110 −67
Original line number Diff line number Diff line
@@ -2,6 +2,8 @@

namespace Oscar\Form;

use Laminas\Validator\GreaterThan;
use Laminas\Validator\NotEmpty;
use Oscar\Hydrator\OrganizationFormHydrator;
use Oscar\Service\OrganizationService;
use Laminas\Form\Element;
@@ -19,8 +21,10 @@ class OrganizationIdentificationForm extends \Laminas\Form\Form implements Input
    private $connectors = [];
    private $types = [];
    private $countries = [];
    private bool $countryRequired = false;
    private bool $typeRequired = false;

    function __construct(OrganizationService $organizationService, $types = [])
    public function __construct(OrganizationService $organizationService, $types = [])
    {
        parent::__construct('organization');
        $this->connectors = $organizationService->getConnectorsList();
@@ -28,7 +32,14 @@ class OrganizationIdentificationForm extends \Laminas\Form\Form implements Input
        $this->types = $types;
    }

    public function init(){
    public function configureRequired(array $params): void
    {
        $this->countryRequired = $params['country'] == true;
        $this->typeRequired = $params['type'] == true;
    }

    public function init(): void
    {
        $this->setHydrator(new OrganizationFormHydrator($this->connectors, $this->types, $this->countries));

        $typesSelect = [];
@@ -185,7 +196,6 @@ class OrganizationIdentificationForm extends \Laminas\Form\Form implements Input
        ]);



        $eotp = new Element\Text('code');
        $eotp->setAttributes([
            'class' => 'form-control',
@@ -285,7 +295,7 @@ class OrganizationIdentificationForm extends \Laminas\Form\Form implements Input

    public function getInputFilterSpecification()
    {
        return [
        $filterSpecification = [
            'dateStart' => [
                'required' => false,
            ],
@@ -295,12 +305,45 @@ class OrganizationIdentificationForm extends \Laminas\Form\Form implements Input
            ],

            'country' => [
                'required' => $this->countryRequired,
                'validators' => [
                    [
                        'name' => NotEmpty::class,
                        'options' => [
                            'messages' => [
                                NotEmpty::IS_EMPTY => "Vous devez définir un pays"
                            ]
                        ]
                    ]
                ]
            ],
            'type' => [
                'required' => false
            ],

            'type' => [
            'typeObj' => [
                'required' => false
            ]
        ];

        if ($this->typeRequired) {
            $filterSpecification['typeObj'] = [
                'required' => true,
                'validators' => [
                    [
                        'name' => \Laminas\Validator\GreaterThan::class,
                        'options' => [
                            'min' => 1,
                            'inclusive' => true,
                            'messages' => [
                                GreaterThan::NOT_GREATER_INCLUSIVE => "Vous devez choisir un type d'organisation"
                            ]
                        ]
                    ]
                ]
            ];
        }

        return $filterSpecification;
    }
}
 No newline at end of file
+31 −10
Original line number Diff line number Diff line
@@ -45,9 +45,19 @@ class OscarConfigurationService implements ServiceLocatorAwareInterface
    const spent_effective_clause = 'spent_effective_clause';
    const spent_predicted_clause = 'spent_predicted_clause';

    const ORGANIZATION_REQUIRED = 'organization_required';


    const theme = 'theme';

    public function getOrganizationRequired(): array
    {
        return [
            'type' => $this->getEditableConfKey('organization_require_type', false),
            'country' => $this->getEditableConfKey('organization_require_country', false),
        ];
    }

    public function emptyProjectRequireValidation(): bool
    {
        return $this->getConfiguration(self::empty_project_require_validation);
@@ -299,7 +309,9 @@ class OscarConfigurationService implements ServiceLocatorAwareInterface
        $conf = $this->getEditableConfRoot();
        $conf[$key] = $value;
        $writer = new Dumper();
        file_put_contents($this->getYamlConfigPath(), $writer->dump($conf));
        if (!file_put_contents($this->getYamlConfigPath(), $writer->dump($conf))) {
            throw new OscarException("Impossible d'enregistrer la configuration");
        }
        return $this;
    }

@@ -954,4 +966,13 @@ class OscarConfigurationService implements ServiceLocatorAwareInterface
    {
        return $this->getServiceLocator()->get('Config')['unicaen-signature']['enabled'] == true;
    }


    public function getRequiredOrganization()
    {
        return [
            'type' => $this->getEditableConfKey('organization_require_type') == true,
            'country' => $this->getEditableConfKey('organization_require_country') == true
        ];
    }
}
 No newline at end of file
Loading