Commit 45fcff36 authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

- Affichage / gestion des personnes dans les sous-structures

- Accès aux activités depuis une structure parente
- Message d'erreur pour les compte désactivés
parent 1af3b5fc
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -162,11 +162,12 @@ return array(
                        'spentList',
                        'newInStructure',
                        'spentSynthesisActivity',
                        'personsAccessDeep',
                        'pcru',
                        'pcruInfos',
                        "pcruList",
                        "apiUi",
                        "timesheet"
                        "timesheet",
                    ],

                    'roles' => ['user'],
+7 −0
Original line number Diff line number Diff line
@@ -929,6 +929,13 @@ contract:
                defaults:
                    action: searchActivity

        personaccess:
            type: segment
            options:
                route: /acces/:id
                defaults:
                    action: personsAccessDeep

        advancedsearch:
            type: segment
            options:
+0 −5
Original line number Diff line number Diff line
@@ -68,11 +68,6 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
        return $this;
    }






    public function deleteAction(){

        $this->getOscarUserContextService()->check(Privileges::ORGANIZATION_DELETE);
+8 −0
Original line number Diff line number Diff line
@@ -2134,6 +2134,14 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
        ];
    }

    public function personsAccessDeepAction()
    {
        $activityId = $this->params()->fromRoute('id');
        $activity = $this->getActivityService()->getActivityById($activityId);
        $access = $this->getActivityService()->getPersonsAccessDeeper($activity);
        die("ACCES dans '$activity'");
    }

    public function spentListAction()
    {
        $action = $this->params()->fromPost('action', null);
+29 −7
Original line number Diff line number Diff line
@@ -174,10 +174,16 @@ class OrganizationService implements UseOscarConfigurationService, UseEntityMana
     * @param $idParentOrganization
     * @return array
     */
    public function getOrganizationIdsDeep( int $idParentOrganization, &$output = [] ):array
    public function getOrganizationIdsDeep( int $idParentOrganization, bool $ignoreFirst = false ):array
    {
        return $this->getDescentsIdsDeep($idParentOrganization);
        $ids = $this->getDescentsIdsDeep($idParentOrganization);
        if( $ids[0] == $idParentOrganization ){
            $ids = array_slice($ids, 1);
        }
        return $ids;
    }



    public function getAncestors( int $idOrganization ) :array {
        $ancestors = [];
@@ -205,9 +211,13 @@ class OrganizationService implements UseOscarConfigurationService, UseEntityMana
        return $output;
    }

    public function getDescentsIds( int $fromParent ): array
    public function getDescentsIds( int $fromParent, bool $ignoreFirst = false ): array
    {
        return $this->getDescentsIdsDeep($fromParent);
        $descents = $this->getDescentsIdsDeep($fromParent);
        if( $ignoreFirst == true && $descents[0] == $fromParent ){
            $descents = array_slice($descents, 1);
        }
        return $descents;
    }

    private function getDescentsIdsDeep( int $fromParent, &$output = [] ): array
@@ -426,17 +436,29 @@ class OrganizationService implements UseOscarConfigurationService, UseEntityMana
        return $structures;
    }

    /**
     * @param int $masterOrganizationId
     * @param int $subOrganizationId
     * @return void
     * @throws OscarException
     * @throws \Doctrine\ORM\ORMException
     * @throws \Doctrine\ORM\OptimisticLockException
     */
    public function saveSubStructure(int $masterOrganizationId, int $subOrganizationId): void
    {
        $subStructure = $this->getOrganizationRepository()->getOrganisationById($subOrganizationId);
        $parent = $this->getOrganizationRepository()->getOrganisationById($masterOrganizationId);
        $idsInAffected = $this->getOrganizationIdsDeep($subStructure->getId());
        $this->getLoggerService()->info(sprintf('Ajout de %s dans %s', $subStructure->log(), $parent->log()));

        $parentChildren = $this->getAncestorsIdsDeep($masterOrganizationId);

//        $idsInAffected = $this->getDescentsIds($subStructure->getId(), true);

        if (!in_array($subStructure->getId(), $idsInAffected)) {
        if (!in_array($subStructure->getId(), $parentChildren) && $masterOrganizationId != $subOrganizationId) {
            $subStructure->setParent($parent);
            $this->getEntityManager()->flush($subStructure);
        } else {
            throw new OscarException("L'affectation va provoquer une récurence, opération annulée");
            throw new OscarException("L'affectation va provoquer une récurrence, opération annulée");
        }
    }

Loading