Commit 7f3f3c6e authored by Florian Joriot's avatar Florian Joriot
Browse files

Bloqué la suppression d'un agrément lorsqu'un contrat existe sur les heures de la composante

parent ebf339a2
Loading
Loading
Loading
Loading
Loading
+57 −4
Changes for module/Agrement/src/Assertion/AgrementAssertion.php: 57 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ use Application\Acl\Role;
use Application\Entity\Db\WfEtape;
use Application\Provider\Privilege\Privileges;
use Application\Resource\WorkflowResource;
use Contrat\Service\TblContratServiceAwareTrait;
use Intervenant\Entity\Db\Intervenant;
use Laminas\Permissions\Acl\Resource\ResourceInterface;
use Lieu\Entity\Db\Structure;
@@ -22,7 +23,7 @@ use UnicaenPrivilege\Assertion\AbstractAssertion;
 */
class AgrementAssertion extends AbstractAssertion
{

    use TblContratServiceAwareTrait;

    /* ---- Routage général ---- */
    public function __invoke(array $page) // gestion des visibilités de menus
@@ -47,18 +48,21 @@ class AgrementAssertion extends AbstractAssertion
                switch ($privilege) {
                    case Privileges::AGREMENT_CONSEIL_RESTREINT_EDITION:
                    case Privileges::AGREMENT_CONSEIL_ACADEMIQUE_EDITION:
                        return $this->assertTblAgrementSaisie($role, $entity);
                    case Privileges::AGREMENT_CONSEIL_RESTREINT_SUPPRESSION:
                    case Privileges::AGREMENT_CONSEIL_ACADEMIQUE_SUPPRESSION:
                        return $this->assertTblAgrementSaisie($role, $entity);
                        return $this->assertTblAgrementSuppression($role, $entity);

                }
                break;
            case $entity instanceof Agrement:
                switch ($privilege) {
                    case Privileges::AGREMENT_CONSEIL_RESTREINT_EDITION:
                    case Privileges::AGREMENT_CONSEIL_ACADEMIQUE_EDITION:
                        return $this->assertAgrementSaisie($role, $entity);
                    case Privileges::AGREMENT_CONSEIL_RESTREINT_SUPPRESSION:
                    case Privileges::AGREMENT_CONSEIL_ACADEMIQUE_SUPPRESSION:
                        return $this->assertAgrementSaisie($role, $entity);
                        return $this->assertAgrementSuppression($role, $entity);
                }
                break;
            case $entity instanceof Structure:
@@ -169,10 +173,10 @@ class AgrementAssertion extends AbstractAssertion
            return false;
        }


        if ($structure = $entity->getStructure()) {
            return $this->assertStructureSaisie($role, $structure);
        }

        return true;
    }

@@ -209,4 +213,53 @@ class AgrementAssertion extends AbstractAssertion
        return true;
    }



    private function assertTblAgrementSuppression(Role $role, TblAgrement $entity)
    {

        /* Si c'est pour agréer et que le workflow l'interdit alors non! */
        if (!$entity->getAgrement() && !$this->isAllowed($entity->getResourceWorkflow())) {
            return false;
        }

        $tblContrat              = $this->getServiceTblContrat();
        $structureContractualise = $tblContrat->getStructureContractualise($entity->getIntervenant());
        $ids                     = array_column($structureContractualise, 'id');

        if (in_array($entity->getStructure()->getId(), $ids)) {
            return false;
        } else {
            if ($structure = $entity->getStructure()) {
                return $this->assertStructureSaisie($role, $structure);
            }
        }

        return true;
    }



    private function assertAgrementSuppression(Role $role, Agrement $entity)
    {

        if (!$this->isAllowed($entity->getResourceWorkflow())) {
            return false;
        }

        $tblContrat              = $this->getServiceTblContrat();
        $structureContractualise = $tblContrat->getStructureContractualise($entity->getIntervenant());
        $ids                     = array_column($structureContractualise, 'id');

        if (in_array($entity->getStructure()->getId(), $ids)) {
            return false;
        } else {
            if ($structure = $entity->getStructure()) {
                return $this->assertStructureSaisie($role, $structure);
            }
        }

        return true;
    }

}
 No newline at end of file
+17
Changes for module/Contrat/src/Service/TblContratService.php: 17 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -89,4 +89,21 @@ class TblContratService extends AbstractEntityService

        return $query->getOneOrNullResult();
    }



    public function getStructureContractualise(Intervenant $intervenant)
    {
        $em = $this->getEntityManager();

        $dql = 'SELECT s.id FROM ' . TblContrat::class . ' tblc 
        JOIN tblc.structure s
        WHERE tblc.intervenant = :intervenant AND tblc.actif = 1 AND tblc.contrat IS NOT NULL';

        $query = $em->createQuery($dql)
            ->setParameter('intervenant', $intervenant);
        return $query->getResult();


    }
}
 No newline at end of file