Commit 48cc5c4f authored by Antony Le Courtes's avatar Antony Le Courtes
Browse files

Formulaire pour administrer les types de ressources (paiement etat, fond propre etc...) dans OSE

parent 2d310957
Loading
Loading
Loading
Loading
+7
Changes for data/privileges.php: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -209,6 +209,13 @@ return [
            'edition'       => 'Édition',
        ],
    ],
    'type-ressource' => [
        'libelle'    => 'Types de ressources',
        'privileges' => [
            'visualisation' => 'Visualisation',
            'edition'       => 'Édition',
        ],
    ],

    'unicaen-tbl' => [
        'libelle'    => 'Tableaux de bord',
+x+116
Changes for module/Application/config/type-ressource.config.php: 116 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Application;

use Application\Provider\Privilege\Privileges;
use UnicaenAuth\Guard\PrivilegeController;

return [
    'router'          => [
        'routes' => [
            'type-ressource' => [
                'type'          => 'Segment',
                'options'       => [
                    'route'    => '/type-ressource',
                    'defaults' => [
                        'controller' => 'Application\Controller\TypeRessource',
                        'action'     => 'index',
                    ],
                ],
                'may_terminate' => true,
                'child_routes'  => [
                    'saisie'                             => [
                        'type'          => 'Segment',
                        'options'       => [
                            'route'       => '/saisie[/:typeRessource]',
                            'constraints' => [
                                'typeIntervention' => '[0-9]*',
                            ],
                            'defaults'    => [
                                'action' => 'saisie',
                            ],
                        ],
                        'may_terminate' => true,
                    ],
                    'delete'                             => [
                        'type'          => 'Segment',
                        'options'       => [
                            'route'       => '/delete[/:typeRessource]',
                            'constraints' => [
                                'typeIntervention' => '[0-9]*',
                            ],
                            'defaults'    => [
                                'action' => 'delete',
                            ],
                        ],
                        'may_terminate' => true,
                    ],
                ],
            ],
        ],
    ],
    'navigation'      => [
        'default' => [
            'home' => [
                'pages' => [
                    'administration' => [
                        'pages' => [
                            'type-ressource' => [
                                'label'        => 'Types de ressources',
                                'icon'         => 'fa  fa-commenting',
                                'route'        => 'type-ressource',
                                'resource'     => PrivilegeController::getResourceId('Application\Controller\TypeRessource', 'index'),
                                'order'        => 60,
                                'border-color' => '#71DFD7',
                            ],
                        ],
                    ],
                ],
            ],
        ],
    ],
    'bjyauthorize'    => [
        'resource_providers' => [
            'BjyAuthorize\Provider\Resource\Config' => [
                'TypeRessource' => [],
            ],
        ],
        'guards'             => [
            PrivilegeController::class => [
                [
                    'controller' => 'Application\Controller\TypeRessource',
                    'action'     => ['index'],
                    'privileges' => [Privileges::TYPE_RESSOURCE_VISUALISATION],
                ],
                [
                    'controller' => 'Application\Controller\TypeRessource',
                    'action'     => ['saisie', 'delete'],
                    'privileges' => [Privileges::TYPE_RESSOURCE_EDITION],
                ],
            ],
        ],
    ],
    'service_manager' => [
        'invokables' => [
            Service\TypeRessourceService::class => Service\TypeRessourceService::class,
        ],
    ],
    'controllers'     => [
        'invokables' => [
            'Application\Controller\TypeRessource' => Controller\TypeRessourceController::class,
        ],
    ],
    /*'form_elements'   => [
        'invokables' => [
            Form\TypeIntervention\TypeInterventionSaisieForm::class          => Form\TypeIntervention\TypeInterventionSaisieForm::class,
            Form\TypeIntervention\TypeInterventionStructureSaisieForm::class => Form\TypeIntervention\TypeInterventionStructureSaisieForm::class,
            Form\TypeIntervention\TypeInterventionStatutSaisieForm::class => Form\TypeIntervention\TypeInterventionStatutSaisieForm::class,
            Form\TypeIntervention\TypeInterventionStatutDeleteForm::class => Form\TypeIntervention\TypeInterventionStatutDeleteForm::class,
        ],
    ],*/
    /*'view_helpers'    => [
        'invokables' => [
            'typeInterventionAdmin' => View\Helper\TypeInterventionAdminViewHelper::class,
        ],
    ],*/
];
+x+55
Changes for module/Application/src/Application/Controller/TypeRessourceController.php: 55 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Application\Controller;


use Application\Entity\Db\TypeRessource;
use Application\Form\TypeRessource\Traits\TypeRessourceSaisieFormAwareTrait;
use Application\Service\Traits\TypeRessourceServiceAwareTrait;

class TypeRessourceController extends AbstractController
{
    use TypeRessourceServiceAwareTrait;
    use TypeRessourceSaisieFormAwareTrait;

    public function indexAction()
    {
        $this->em()->getFilters()->enable('historique')->init([
            TypeRessource::class,
        ]);

        $listTypesRessources = $this->getServiceTypeRessource()->getList();

        return compact('listTypesRessources');
    }

    public function saisieAction()
    {
        $typ = $this->getEvent()->getParam('typeIntervention');
        $form             = $this->getFormTypeRessourceSaisie();
        $title = 'Édition d\'un type de ressource';

        $typeRessource = $this->getEvent()->getParam('typeRessource');
        $form = $this->getFormTypeRessourceSaisie();

        $form->bindRequestSave($typeRessource, $this->getRequest(), function (TypeRessource $type) {
            try {
                $this->getServiceTypeRessource()->save($type);
                $this->flashMessenger()->addSuccessMessage('Enregistrement effectué');
            } catch (\Exception $e) {
                $this->flashMessenger()->addErrorMessage($this->translate($e));
            }
        });

        return compact('form', 'title');


        return compact();
    }

    public function deleteAction()
    {
        return compact();
    }

}
+x+47
Changes for module/Application/src/Application/Form/TypeRessource/Traits/TypeRessourceSaisieFormAwareTrait.php: 47 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Application\Form\TypeRessource\Traits;

use Application\Form\TypeRessource\TypeRessourceSaisieForm;

/**
 * Description of TypeRessourceSaisieFormAwareTrait
 *
 * @author UnicaenCode
 */
trait TypeRessourceSaisieFormAwareTrait
{
    /**
     * @var TypeRessourceSaisieForm
     */
    private $formTypeRessourceSaisieForm;



    /**
     * @param TypeRessourceSaisieForm $formTypeRessourceSaisie
     *
     * @return self
     */
    public function setFormTypeRessourceSaisie(TypeRessourceSaisieForm $formTypeRessourceSaisie)
    {
        $this->formTypeRessourceSaisieForm = $formTypeRessourceSaisie;

        return $this;
    }



    /**
     *
     * @return TypeRessourceSaisieForm
     */
    public function getFormTypeRessourceSaisie()
    {
        if (!empty($this->formTypeRessourceSaisie)) {
            return $this->formTypeRessourceSaisie;
        }

        return \Application::$container->get('FormElementManager')->get(TypeRessourceSaisieForm::class);
    }
}
+x+90
Changes for module/Application/src/Application/Form/TypeRessource/TypeRessourceSaisieForm.php: 90 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php
namespace Application\Form\TypeRessource;

use Application\Form\AbstractForm;
use Application\Hydrator\TypeRessourceHydrator;
use Zend\Form\Element\Csrf;

/**
 * Description of TypeRessourceSaisieForm
 *
 * @author LE COURTES Antony <antony.lecourtes at unicaen.fr>
 */
class TypeRessourceSaisieForm extends AbstractForm
{

    public function init()
    {
        $hydrator = new TypeRessourceHydrator();
        $this->setHydrator($hydrator);

        $this->setAttribute('action', $this->getCurrentUrl());
        $this->add([
            'name' => 'code',
            'options' => [
                'label' => "Code",
            ],
            'type' => 'Text',
        ]);
        $this->add([
            'name' => 'libelle',
            'options' => [
                'label' => "Libellé",
            ],
            'type' => 'Text',
        ]);

        $this->add([
            'name' => 'fi',
            'options' => [
                'label' => 'Fi',
            ],
            'type' => 'Checkbox',
        ]);
        $this->add([
            'name' => 'fa',
            'options' => [
                'label' => 'Fa ?',
            ],
            'type' => 'Checkbox',
        ]);
        $this->add([
            'name' => 'fc',
            'options' => [
                'label' => 'Fc',
            ],
            'type' => 'Checkbox',
        ]);

        $this->add(new Csrf('security'));
        $this->add([
            'name' => 'submit',
            'type' => 'Submit',
            'attributes' => [
                'value' => "Enregistrer",
                'class' => 'btn btn-primary'
            ],
        ]);
        return $this;
    }


    /**
     * Should return an array specification compatible with
     * {@link Zend\InputFilter\Factory::createInputFilter()}.
     *
     * @return array
     */
    public function getInputFilterSpecification()
    {
        return [
            'code' => [
                'required' => true,
            ],
            'libelle' => [
                'required' => true,
            ],
        ];
    }

}
Loading