Commit a3e544b4 authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

UP : Remise à niveau des affectations des personnes aux organisations

 - Simplification dans le contrôleur
 - passage par un service centralisé
 - Les mouvements de personnel déclenche (si besoin) un recalcule des notifications (ex: ajout d'un directeur)
parent e96ee186
Loading
Loading
Loading
Loading
Loading
+2 −0
Changes for module/Oscar/src/Oscar/Command/OscarCommandAbstract.php: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ abstract class OscarCommandAbstract extends Command

    const COMMAND_ACTIVITY_SEARCH_REINDEX = 'activity:search:reindex';

    const COMMAND_ACTIVITY_SEARCH_REINDEX_ALL = 'activity:search-rebuild';

    const COMMAND_ACTIVITY_NOTIFICATION_UPDATE = 'activity:notification:update';

    const COMMAND_NOTIFICATIONS_REBUILD = 'notifications:rebuild';
+55 −5
Changes for module/Oscar/src/Oscar/Controller/EnrollController.php: 55 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -81,7 +81,7 @@ class EnrollController extends AbstractOscarController implements UsePersonServi

                break;
            case OrganizationPerson::class:
                $roles = $repo->getRolesAtOrganizationArray();
                $roles = $repo->getRolesAvailableForPersonInOrganizationArray();
        }
        return $roles;
    }
@@ -823,10 +823,56 @@ class EnrollController extends AbstractOscarController implements UsePersonServi
    ////////////////////////////////////////////////////////////////////////////
    // Organization <> Person
    ////////////////////////////////////////////////////////////////////////////
    protected function getOrganizationPersonForm(Organization $enroller)
    {
        $form = new RoleForm(
            $this->getOscarUserContextService()->getAvailabledRolesPersonOrganization(),
            $this->getPersonService(),
            $enroller,
            [
                'label' => 'Personne',
                'url' => $this->url()->fromRoute('person/search')
            ]
        );

        return $form;
    }

    public function organizationPersonNewAction()
    {
        $this->getOscarUserContextService()->check(Privileges::ORGANIZATION_EDIT, $this->getOrganizationEntity());
        return $this->saveEnroll(OrganizationPerson::class);
        $organization = $this->getOrganizationEntity();
        $this->getOscarUserContextService()->check(Privileges::ORGANIZATION_EDIT, $organization);
        $organizationPerson = new OrganizationPerson();
        $form = $this->getOrganizationPersonForm($organization);
        $form->bind($organizationPerson);

        if( $this->getRequest()->isPost() ){
            $posted = $this->getRequest()->getPost();
            $form->setData($posted);
            if( $form->isValid() ){
                $this->getPersonService()->personOrganizationAdd($organization, $organizationPerson->getPerson(), $organizationPerson->getRoleObj(), $organizationPerson->getDateStart(), $organizationPerson->getDateEnd());
                $this->redirect()->toRoute('organization/show', ['id' => $organization->getId()]);
            }
        }

        $view = new ViewModel(
            array(
                'id' => null,
                'title' => "Nouvelle personne dans $organization",
                'form' => $form,
                'labelEnrolled' => "Personne",
                'enroller' => $organization,
                'enrolled' => null
            )
        );

        if ($this->getRequest()->isXmlHttpRequest()) {
            $view->setTerminal(true);
        }

        $view->setTemplate('partials/role-form.phtml');

        return $view;
    }

    public function organizationPersonDeleteAction()
@@ -836,11 +882,15 @@ class EnrollController extends AbstractOscarController implements UsePersonServi
            $this->params()->fromRoute('idenroll')
        );

        $organization = $organizationPerson->getOrganization();

        $this->getOscarUserContextService()->check(
            Privileges::ORGANIZATION_EDIT,
            $organizationPerson->getOrganization()
            $organization
        );
        return $this->deleteEnroll(OrganizationPerson::class);

        $this->getPersonService()->personOrganizationRemove($organizationPerson);
        $this->redirect()->toRoute('organization/show', ['id' => $organization->getId()]);
    }

    ////////////////////////////////////////////////////////////////////////////
+1 −1
Changes for module/Oscar/src/Oscar/Entity/PersonRepository.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -250,7 +250,7 @@ class PersonRepository extends EntityRepository implements IConnectedRepository

    public function getRolesOrganizationArray()
    {
        return $this->getEntityManager()->getRepository(Role::class)->getRolesAtOrganizationArray();
        return $this->getEntityManager()->getRepository(Role::class)->getRolesAvailableForPersonInOrganizationArray();
    }


+14 −4
Changes for module/Oscar/src/Oscar/Entity/RoleRepository.php: 14 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\NoResultException;
use Doctrine\ORM\Query\ResultSetMapping;
use Oscar\Exception\OscarException;
use Oscar\Utils\OscarConstants;

class RoleRepository extends EntityRepository
{
@@ -67,21 +68,30 @@ class RoleRepository extends EntityRepository
    /**
     * Retourne la liste des rôles d'une activité sous la forme d'un tableau
     *
     * @return \Doctrine\ORM\QueryBuilder
     * @return array
     */
    public function getRolesAtOrganizationArray()
    public function getRolesAvailableForPersonInOrganizationArray()
    {
        static $rolesOrganization;
        if( $rolesOrganization === null ){
            $rolesOrganization = [];
            /** @var Role $role */
            foreach( $this->getRolesAtLevel(Role::LEVEL_ORGANIZATION)->getQuery()->getResult() as $role ){
            foreach( $this->getRolesAvailableForPersonInOrganization() as $role ){
                $rolesOrganization[$role->getId()] = $role->getRoleId();
            }
        }
        return $rolesOrganization;
    }

    /**
     * Retourne la liste des rôles disponibles pour une personne dans une organisation.
     *
     * @return Role[]
     */
    public function getRolesAvailableForPersonInOrganization() :array
    {
        return $this->getRolesAtLevel(Role::LEVEL_ORGANIZATION)->getQuery()->getResult();
    }

    /**
     * Retourne la liste des rôles au niveau spécifié.
     *
+25 −5
Changes for module/Oscar/src/Oscar/Form/RoleForm.php: 25 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -8,13 +8,16 @@
namespace Oscar\Form;


use Oscar\Hydrator\RoleFormHydrator;
use Zend\Form\Form;
use Zend\InputFilter\InputFilterProviderInterface;

class RoleForm extends Form
class RoleForm extends Form implements InputFilterProviderInterface
{
    function __construct( $roles, $enroledData )
    function __construct( $roles, $personService, $enroller, $enroledData )
    {
        parent::__construct('role');
        $this->setHydrator(new RoleFormHydrator($personService, $enroller));

        $this->add(array(
            'name'  => 'id',
@@ -23,16 +26,16 @@ class RoleForm extends Form

        // Enroled
        $this->add([
            'name'   => 'enroled',
            'name'   => 'enrolled',
            'options' => [
                'label' => $enroledData['label']
            ],
            'attributes'    => [
                'class'       => 'form-control select2',
                'class'       => 'form-control',
                'placeholder'   => $enroledData['label'],
                'data-url' => $enroledData['url']
            ],
            'type'=>'Select'
            'type'=>'Hidden'
        ]);


@@ -81,4 +84,21 @@ class RoleForm extends Form
            'type'  => 'Csrf',
        ));
    }
    public function getInputFilterSpecification()
    {
        return [
            'dateStart'=> [
                'required' => false,
            ],

            'dateEnd'=> [
                'required' => false,
            ],

            'enrolled'=> [
                'required' => false,
            ]
        ];
    }

}
 No newline at end of file
Loading