diff --git a/module/Agent/src/Entity/Db/Agent.php b/module/Agent/src/Entity/Db/Agent.php index 4bc87293e059b8ebc67166a2ea46a1bd51c8afb4..719289a2e343ccd3366e33e5c659f8d6ca3d7c16 100644 --- a/module/Agent/src/Entity/Db/Agent.php +++ b/module/Agent/src/Entity/Db/Agent.php @@ -10,6 +10,8 @@ use DateTime; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Fichier\Entity\Db\Fichier; +use Fichier\Entity\HasFichiersInterface; +use Fichier\Entity\HasFichiersTrait; use Formation\Entity\Db\Interfaces\HasFormationCollectionInterface; use Formation\Entity\Db\Traits\HasFormationCollectionTrait; use Laminas\Permissions\Acl\Resource\ResourceInterface; @@ -25,15 +27,18 @@ use UnicaenValidation\Entity\HasValidationsTrait; class Agent implements ResourceInterface, HasFormationCollectionInterface, - HasValidationsInterface, IsSynchronisableInterface + HasValidationsInterface, HasFichiersInterface, + IsSynchronisableInterface { use IsSynchronisableTrait; use AgentServiceAwareTrait; use HasFormationCollectionTrait; + use HasFichiersTrait; use HasValidationsTrait; use AgentMacroTrait; + public function getResourceId(): string { return 'Agent'; @@ -525,48 +530,6 @@ class Agent implements return $structures; } - /** - * @return Fichier[] - */ - public function getFichiers(): array - { - return $this->fichiers->toArray(); - } - - /** - * @param Fichier $fichier - * @return Agent - */ - public function addFichier(Fichier $fichier): Agent - { - $this->fichiers->add($fichier); - return $this; - } - - /** - * @param Fichier $fichier - * @return Agent - */ - public function removeFichier(Fichier $fichier): Agent - { - $this->fichiers->removeElement($fichier); - return $this; - } - - /** - * @param string $nature - * @return Fichier[] - */ - public function fetchFiles(string $nature): array - { - $fichiers = $this->getFichiers(); - $fichiers = array_filter($fichiers, function (Fichier $f) use ($nature) { - return ($f->getHistoDestruction() === null && $f->getNature()->getCode() === $nature); - }); - - return $fichiers; - } - /** HIERARCHIE ****************************************************************************************************/ /** @return AgentValidateur[] */ diff --git a/module/Agent/src/Entity/Db/AgentAffectation.php b/module/Agent/src/Entity/Db/AgentAffectation.php index c2d6a30cfb0ca99e5cfc692b0c353ae4bcee72c6..8a298feab48f503cbefec190546388b46c3506c7 100644 --- a/module/Agent/src/Entity/Db/AgentAffectation.php +++ b/module/Agent/src/Entity/Db/AgentAffectation.php @@ -83,8 +83,7 @@ class AgentAffectation implements HasPeriodeInterface, IsSynchronisableInterface $affectations = []; foreach ($agentAffectations as $agentAffectation) { $structure = $agentAffectation->getStructure(); - $niveau2 = null; - if ($structure) $niveau2 = $structure->getNiv2(); + $niveau2 = $structure?->getNiv2(); if ($structure) { $texte = $structure->getLibelleCourt(); if ($niveau2 !== null and $niveau2 !== $structure) $texte = $niveau2->getLibelleCourt() . " > " . $texte; diff --git a/module/Agent/src/Entity/Db/AgentGrade.php b/module/Agent/src/Entity/Db/AgentGrade.php index f0e1a41dce6104cafb809493d4054efa9212632e..75f663a3accdf5ace70ed521d855b1df83c54c38 100644 --- a/module/Agent/src/Entity/Db/AgentGrade.php +++ b/module/Agent/src/Entity/Db/AgentGrade.php @@ -13,8 +13,7 @@ use UnicaenSynchro\Entity\Db\IsSynchronisableInterface; use UnicaenSynchro\Entity\Db\IsSynchronisableTrait; /** - * Données synchronisées depuis Octopus: - * - pas de setter sur les données ainsi remontées + * Données synchronisées depuis Octopus : pas de setter sur les données ainsi remontées */ class AgentGrade implements HasPeriodeInterface, IsSynchronisableInterface { diff --git a/module/Agent/src/Entity/Db/AgentQuotite.php b/module/Agent/src/Entity/Db/AgentQuotite.php index 5571af1f5694df0105970f5dcb1600544913bc85..6c95f2acb249e448ba2c4a26c9808492def8aa3d 100644 --- a/module/Agent/src/Entity/Db/AgentQuotite.php +++ b/module/Agent/src/Entity/Db/AgentQuotite.php @@ -48,9 +48,4 @@ class AgentQuotite implements HasPeriodeInterface, IsSynchronisableInterface return $this->modaliteDeService; } - public function setModaliteDeService(?string $modaliteDeService): void - { - $this->modaliteDeService = $modaliteDeService; - } - } \ No newline at end of file diff --git a/module/Agent/src/Entity/Db/AgentStatut.php b/module/Agent/src/Entity/Db/AgentStatut.php index 5621c6e1332e50f0270c5f921829690840b581dc..26adc1251941b9edc2439928bad5c10bf7b5d462 100644 --- a/module/Agent/src/Entity/Db/AgentStatut.php +++ b/module/Agent/src/Entity/Db/AgentStatut.php @@ -10,8 +10,7 @@ use UnicaenSynchro\Entity\Db\IsSynchronisableInterface; use UnicaenSynchro\Entity\Db\IsSynchronisableTrait; /** - * Données synchronisées depuis Octopus : - * - pas de setter sur les données ainsi remontées + * Données synchronisées depuis Octopus : pas de setter sur les données ainsi remontées */ class AgentStatut implements HasPeriodeInterface, IsSynchronisableInterface { use HasPeriodeTrait; diff --git a/module/Agent/src/Entity/Db/AgentValidateur.php b/module/Agent/src/Entity/Db/AgentValidateur.php index a7b6d9f11c2833a5a9efac0175b222fb900e56e4..95c3a0f2e10fb0798002556cb073860618f39a26 100644 --- a/module/Agent/src/Entity/Db/AgentValidateur.php +++ b/module/Agent/src/Entity/Db/AgentValidateur.php @@ -4,6 +4,7 @@ namespace Agent\Entity\Db; use Application\Entity\Db\Interfaces\HasPeriodeInterface; use Application\Entity\Db\Traits\HasPeriodeTrait; +use DateTime; use Doctrine\ORM\QueryBuilder; use UnicaenSynchro\Entity\Db\IsSynchronisableInterface; use UnicaenSynchro\Entity\Db\IsSynchronisableTrait; @@ -68,7 +69,7 @@ class AgentValidateur implements HistoriqueAwareInterface, HasPeriodeInterface, return $qb; } - public function setCreatedOn(\DateTime $param) + public function setCreatedOn(DateTime $param): void { $this->createdOn = $param; } diff --git a/module/Agent/src/Form/SelectionAgent/SelectionAgentForm.php b/module/Agent/src/Form/SelectionAgent/SelectionAgentForm.php index 1413baf61e17f614aa05550918ea4ed5a20ed814..9cc1fe2d6c523b166d6ee2f0c324c88e2586d9d1 100644 --- a/module/Agent/src/Form/SelectionAgent/SelectionAgentForm.php +++ b/module/Agent/src/Form/SelectionAgent/SelectionAgentForm.php @@ -9,17 +9,11 @@ use Laminas\InputFilter\Factory; class SelectionAgentForm extends Form { - /** @var string */ - private $urlAgent; - - /** - * @param string $urlAgent - * @return SelectionAgentForm - */ - public function setUrlAgent(string $urlAgent) + private ?string $urlAgent = null; + + public function setUrlAgent(string $urlAgent): void { $this->urlAgent = $urlAgent; - return $this; } public function init(): void diff --git a/module/Agent/src/Form/SelectionAgent/SelectionAgentHydrator.php b/module/Agent/src/Form/SelectionAgent/SelectionAgentHydrator.php index 5a9b0f368ab96e45b9a6354e5dd17f9c75dc5442..77c0a424300925f07cf929c24ce7d6fe4aa51522 100644 --- a/module/Agent/src/Form/SelectionAgent/SelectionAgentHydrator.php +++ b/module/Agent/src/Form/SelectionAgent/SelectionAgentHydrator.php @@ -9,26 +9,20 @@ use Laminas\Hydrator\HydratorInterface; class SelectionAgentHydrator implements HydratorInterface { use AgentServiceAwareTrait; - /** - * @param HasAgentInterface $object - * @return array - */ public function extract(object $object): array { + /** @var HasAgentInterface $object */ $data = [ 'agent-sas' => ($object->getAgent())?['id' => $object->getAgent()->getId(), 'label' => $object->getAgent()->getDenomination()]:null, ]; return $data; } - /** - * @param array $data - * @param HasAgentInterface $object - * @return HasAgentInterface - */ public function hydrate(array $data,object $object): object { $agent = $this->getAgentService()->getAgent($data['agent-sas']['id'], true); + + /** @var HasAgentInterface $object */ $object->setAgent($agent); return $object; } diff --git a/module/Agent/src/Form/SelectionAgent/SelectionAgentHydratorFactory.php b/module/Agent/src/Form/SelectionAgent/SelectionAgentHydratorFactory.php index a1cce7278fda3b094ecbedb901cf2556d94ce92e..023cb35115be34243c9460a6ea6985dfeeabbad5 100644 --- a/module/Agent/src/Form/SelectionAgent/SelectionAgentHydratorFactory.php +++ b/module/Agent/src/Form/SelectionAgent/SelectionAgentHydratorFactory.php @@ -18,7 +18,7 @@ class SelectionAgentHydratorFactory /** * @var AgentService $agentService */ - $agentService = $container->get(AgentService::class); + $agentService = $container->get(AgentService::class); $hydrator = new SelectionAgentHydrator(); $hydrator->setAgentService($agentService); diff --git a/module/Agent/src/Form/Validateur/ValidateurForm.php b/module/Agent/src/Form/Validateur/ValidateurForm.php index aaba02caf789f8adcceeda99f1669de5a8c29a91..a0e9b62bbc753652d5263fa181da950543a65734 100644 --- a/module/Agent/src/Form/Validateur/ValidateurForm.php +++ b/module/Agent/src/Form/Validateur/ValidateurForm.php @@ -13,7 +13,7 @@ class ValidateurForm extends Form { private ?string $urlAgent = null; - public function setUrlAgent(string $url) + public function setUrlAgent(string $url): void { $this->urlAgent = $url; } diff --git a/module/Agent/src/Service/Agent/AgentService.php b/module/Agent/src/Service/Agent/AgentService.php index 45b7dc1be0f35ed37aa146160c9cca3bee990bce..e93526ddf17832e05fc404dea80237f042937651 100644 --- a/module/Agent/src/Service/Agent/AgentService.php +++ b/module/Agent/src/Service/Agent/AgentService.php @@ -12,13 +12,8 @@ use Doctrine\DBAL\Exception as DBA_Exception; use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\QueryBuilder; use DoctrineModule\Persistence\ProvidesObjectManager; -use Fichier\Entity\Db\Fichier; -use Formation\Entity\Db\FormationElement; use Laminas\Mvc\Controller\AbstractActionController; use Structure\Entity\Db\Structure; -use Structure\Entity\Db\StructureAgentForce; -use Structure\Entity\Db\StructureGestionnaire; -use Structure\Entity\Db\StructureResponsable; use Structure\Service\Structure\StructureServiceAwareTrait; use UnicaenApp\Exception\RuntimeException; use UnicaenParametre\Service\Parametre\ParametreServiceAwareTrait; @@ -57,8 +52,7 @@ class AgentService //quotite de l'agent ->addSelect('quotite')->leftJoin('agent.quotites', 'quotite') ->addSelect('utilisateur')->leftJoin('agent.utilisateur', 'utilisateur') - ->andWhere('agent.deletedOn IS NULL') - ; + ->andWhere('agent.deletedOn IS NULL'); if (!$enAffectation) $qb = $qb->andWhere('affectation.deletedOn IS NULL'); @@ -94,56 +88,12 @@ class AgentService return $result; } - /** - * @param DateTime|null $debut - * @param DateTime|null $fin - * @param Structure[]|null $structures - * @return Agent[] - */ - public function getAgentsWithDates(?DateTime $debut = null, ?DateTime $fin = null, ?array $structures = null): array - { - $qb = $this->getObjectManager()->getRepository(Agent::class)->createQueryBuilder('agent') - ->addSelect('affectation')->join('agent.affectations', 'affectation') - ->addSelect('statut')->join('agent.statuts', 'statut') - ->addSelect('grade')->join('agent.grades', 'grade') - ->addSelect('emploitype')->leftjoin('grade.emploiType', 'emploitype') - ->andWhere('agent.deletedOn IS NULL') - // Devrait être un filtrage ... et pas une requete même si cela accélère les choses - ->andWhere('statut.titulaire = :true OR (statut.cdd = :true AND agent.tContratLong =:true) OR statut.cdi = :true') - ->andWhere('statut.enseignant = :false') -// ->andWhere('emploitype.code <> :UCNRECH') - ->setParameter('true', 'O') - ->setParameter('false', 'N') -// ->setParameter('UCNRECH', 'UCNRECH') - ->orderBy('agent.nomUsuel, agent.prenom'); - - if ($debut) $qb = $qb - ->andWhere('affectation.dateFin IS NULL OR affectation.dateFin > :debut') - ->andWhere('statut.dateFin IS NULL OR statut.dateFin > :debut') - ->andWhere('grade.dateFin IS NULL OR grade.dateFin > :debut') - ->andWhere('emploitype.dateFin IS NULL OR emploitype.dateFin > :debut') - ->setParameter('debut', $debut); - if ($fin) $qb = $qb - ->andWhere('affectation.dateDebut IS NULL OR affectation.dateDebut < :fin') - ->andWhere('statut.dateDebut IS NULL OR statut.dateDebut < :fin') - ->andWhere('grade.dateDebut IS NULL OR grade.dateDebut < :fin') - ->andWhere('emploitype.dateDebut IS NULL OR emploitype.dateDebut < :fin') - ->setParameter('fin', $fin); - if ($structures) $qb = $qb - ->andWhere('affectation.structure in (:structures)') - ->setParameter('structures', $structures); - - $result = $qb->getQuery()->getResult(); - return $result; - } - /** * @param string|null $id * @param bool $enlarge (si mis à TRUE alors pas d'obligation de donnée minimum) - * @param bool $enAffectation * @return Agent|null */ - public function getAgent(?string $id, bool $enlarge = false, bool $enAffectation=true): ?Agent + public function getAgent(?string $id, bool $enlarge = false): ?Agent { if ($id === null) return null; @@ -197,8 +147,8 @@ class AgentService $sql = <<<EOS select a.c_individu as id from agent a -where 1=1 -and unaccent(LOWER(CONCAT(a.prenom, ' ', a.nom_usage))) like unaccent('%' || :term || '%') OR unaccent(LOWER(CONCAT(a.nom_usage, ' ', a.prenom))) like unaccent('%' || :term || '%') +where + unaccent(LOWER(CONCAT(a.prenom, ' ', a.nom_usage))) like unaccent('%' || :term || '%') OR unaccent(LOWER(CONCAT(a.nom_usage, ' ', a.prenom))) like unaccent('%' || :term || '%') and a.deleted_on IS NULL EOS; @@ -294,13 +244,12 @@ EOS; ->andWhere('affectationfilter.dateFin >= :today OR affectationfilter.dateFin IS NULL') ->andWhere('affectationfilter.dateDebut <= :today') ->setParameter('today', $date) - ->andWhere('agent.deletedOn IS NULL') ->orderBy('agent.nomUsuel, agent.prenom', 'ASC'); if ($withJoin) { $qb = $qb - //AFFECTATION ALL (NB : Si on ne remonte pas toutes les affectations doctrine nous fout dedans) + //AFFECTATION ALL (NB : Si on ne remonte pas toutes les affectations doctrine nous fout dedans) // ->addSelect('affectation') ->join('agent.affectations', 'affectation') // ->addSelect('affectation_structure') @@ -309,7 +258,7 @@ EOS; //STATUS // ->addSelect('statut') ->leftjoin('agent.statuts', 'statut') - ->andWhere('statut.deletedOn IS NULL') + ->andWhere('statut.deletedOn IS NULL') //GRADE // ->addSelect('grade') ->leftjoin('agent.grades', 'grade') @@ -323,8 +272,7 @@ EOS; ->leftjoin('grade.correspondance', 'gcorrespondance') // ->addSelect('gcorps') ->leftjoin('grade.corps', 'gcorps') - ->andWhere('grade.deletedOn IS NULL') - ; + ->andWhere('grade.deletedOn IS NULL'); } $qb = AgentValidateur::decorateWithAgentValidateur($qb); @@ -345,25 +293,6 @@ EOS; } - /** - * @param Structure[] $structures - * @return Agent[] - */ - public function getAgentsForcesByStructures(array $structures): array - { - $qb = $this->getObjectManager()->getRepository(Agent::class)->createQueryBuilder('agent') - ->addSelect('forcage')->join('agent.structuresForcees', 'forcage') - ->andWhere('forcage.histoDestruction IS NULL'); - - if (!empty(null)) { - $qb = $qb->andWhere('forcage.structure IN (:structures)') - ->setParameter('structures', $structures); - } - $result = $qb->getQuery()->getResult(); - - return $result; - } - /** * @param $st_prenom * @param $st_nom @@ -386,102 +315,6 @@ EOS; return null; } - /** Recuperation des supérieures et autorités *********************************************************************/ - - /** - * TODO :: a conserver pour init des superieurs depuis les structures - * Agent[] - */ - public function computeSuperieures(Agent $agent, ?DateTime $date = null): array - { - if ($date === null) $date = new DateTime(); - - //checking structure - $affectationsPrincipales = $this->getAgentAffectationService()->getAgentAffectationHierarchiquePrincipaleByAgent($agent); - if ($affectationsPrincipales === null or count($affectationsPrincipales) !== 1) return []; //throw new LogicException("Plusieurs affectations principales pour l'agent ".$agent->getId() . ":".$agent->getDenomination()); - - if (reset($affectationsPrincipales)) { - $affectationPrincipale = reset($affectationsPrincipales); - $structure = $affectationPrincipale->getStructure(); - do { - $responsablesAll = array_map(function (StructureResponsable $a) { - return $a->getAgent(); - }, $this->getStructureService()->getResponsables($structure, $date)); - if (!in_array($agent, $responsablesAll)) { - $responsables = []; - foreach ($responsablesAll as $responsable) { - $responsables["structure_" . $responsable->getId()] = $responsable; - } - if (!empty($responsables)) return $responsables; - } - - $structure = $structure->getParent(); - } while ($structure !== null); - } - - return []; - } - - /** - * TODO :: a conserver pour init des autorites depuis les structures - * Agent[] - */ - public function computeAutorites(Agent $agent, array $superieurs = [], ?DateTime $date = null): array - { - if ($date === null) $date = new DateTime(); - - //checking structure - $affectationsPrincipales = $this->getAgentAffectationService()->getAgentAffectationHierarchiquePrincipaleByAgent($agent); - if ($affectationsPrincipales === null) return []; - $structure = null; - if (count($affectationsPrincipales) === 1) { - $structure = current($affectationsPrincipales)->getStructure()->getNiv2(); - } else { - foreach ($affectationsPrincipales as $affectation) { - $niveau2 = $affectation->getStructure()->getNiv2(); - if ($structure === null or $niveau2 === $structure) $structure = $niveau2; - else return []; //throw new LogicException("Différentes structures de niveau2 affectations principales pour l'agent"); - } - } - do { - $responsablesAll = array_map(function (StructureResponsable $a) { - return $a->getAgent(); - }, $this->getStructureService()->getResponsables($structure, $date)); - if (!in_array($agent, $responsablesAll)) { - $responsables = []; - foreach ($responsablesAll as $responsable) { - if (!in_array($responsable, $superieurs)) { - $responsables["structure_" . $responsable->getId()] = $responsable; - } - } - if (!empty($responsables)) return $responsables; - } - - $structure = ($structure) ? $structure->getParent() : null; - } while ($structure !== null); - - return []; - } - - /** AgentFormation ************************************************************************************************/ - - /** - * @param Agent $agent - * @param string $annee - * @return FormationElement[] - */ - public function getFormationsSuiviesByAnnee(Agent $agent, string $annee): array - { - $result = []; - $formations = $agent->getFormationListe(); - foreach ($formations as $formation) { - $anneeFormation = explode(' - ', $formation->getCommentaire())[0]; - if ($anneeFormation === $annee) $result[] = $formation; - } - - return $result; - } - /** * @param Agent[] $agents * @return array @@ -494,7 +327,7 @@ EOS; $extra = ($structure) ? $structure->getLibelleCourt() : "Affectation inconnue"; $result[] = array( 'id' => $agent->getId(), - 'label' => $agent->getDenomination(false, true, false), + 'label' => $agent->getDenomination(), 'extra' => "<span class='badge' style='background-color: slategray;'>" . $extra . "</span>", ); } @@ -504,40 +337,6 @@ EOS; return $result; } - /** - * todo plutôt dans structure - * @param Agent|null $agent - * @return StructureResponsable[]|null - */ - public function getResposabiliteStructure(?Agent $agent): ?array - { - if ($agent === null) return null; - - $qb = $this->getObjectManager()->getRepository(StructureResponsable::class)->createQueryBuilder('sr') - ->andWhere('sr.agent = :agent') - ->setParameter('agent', $agent) - ->andWhere('sr.deletedOn IS NULL'); - $result = $qb->getQuery()->getResult(); - return $result; - } - - /** - * todo plutôt dans structure - * @param Agent|null $agent - * @return Structure[]|null - */ - public function getGestionnaireStructure(?Agent $agent): ?array - { - if ($agent === null) return null; - - $qb = $this->getObjectManager()->getRepository(StructureGestionnaire::class)->createQueryBuilder('sg') - ->andWhere('sg.agent = :agent') - ->setParameter('agent', $agent) - ->andWhere('sg.deletedOn IS NULL'); - $result = $qb->getQuery()->getResult(); - return $result; - } - /** * @return User[] */ @@ -600,36 +399,6 @@ EOS; return $result; } - /** FICHE DE POSTE PDF ********************************************************************************************/ - - /** - * @param Agent[] $agents - * @return Fichier[] :: [AgentId => Fichier] - */ - public function getFichesPostesPdfByAgents(array $agents): array - { - - $ids = array_map(function ($a) { - if ($a instanceof StructureAgentForce) $a = $a->getAgent(); - return $a->getId(); - }, $agents); - - $qb = $this->getObjectManager()->getRepository(Agent::class)->createQueryBuilder('agent') - ->leftJoin('agent.fichiers', 'fichier')->addSelect('fichier') - ->leftJoin('fichier.nature', 'nature')->addSelect('nature') - ->andWhere('nature.code = :ficheposte')->setParameter('ficheposte', "FICHE_POSTE") - ->andWhere('agent.id in (:ids)')->setParameter('ids', $ids); - - $result = $qb->getQuery()->getResult(); - - $fiches = []; - /** @var Agent $item */ - foreach ($result as $item) { - $fiches[$item->getId()] = $item->getFichiersByCode("FICHE_POSTE"); - } - return $fiches; - } - public function getAgentByLogin(string $login): ?Agent { $qb = $this->createQueryBuilder() diff --git a/module/Agent/src/Service/AgentAffectation/AgentAffectationService.php b/module/Agent/src/Service/AgentAffectation/AgentAffectationService.php index 3a2d92ef07281fee05f4d8d95e348b5f81a5dbf4..640ad5d0bf700caa5b99122d42234aeb83c5a460 100644 --- a/module/Agent/src/Service/AgentAffectation/AgentAffectationService.php +++ b/module/Agent/src/Service/AgentAffectation/AgentAffectationService.php @@ -2,95 +2,33 @@ namespace Agent\Service\AgentAffectation; -use Agent\Entity\Db\AgentAffectation; use Agent\Entity\Db\Agent; -use DateTime; +use Agent\Entity\Db\AgentAffectation; use Doctrine\ORM\QueryBuilder; -use Structure\Entity\Db\Structure; -use UnicaenApp\Service\EntityManagerAwareTrait; +use DoctrineModule\Persistence\ProvidesObjectManager; -class AgentAffectationService { - use EntityManagerAwareTrait; +class AgentAffectationService +{ + use ProvidesObjectManager; /** REQUETAGE *****************************************************************************************************/ - /** - * @return QueryBuilder - */ - public function createQueryBuilder() : QueryBuilder + public function createQueryBuilder(): QueryBuilder { - $qb = $this->getEntityManager()->getRepository(AgentAffectation::class)->createQueryBuilder('agentaffectation') + $qb = $this->getObjectManager()->getRepository(AgentAffectation::class)->createQueryBuilder('agentaffectation') ->join('agentaffectation.agent', 'agent')->addSelect('agent') ->join('agentaffectation.structure', 'structure')->addSelect('structure') - ->andWhere('agentaffectation.deletedOn IS NULL') - ; + ->andWhere('agentaffectation.deletedOn IS NULL'); return $qb; } /** @return AgentAffectation[] */ - public function getAgentsAffectationsByAgentAndDate(Agent $agent, ?DateTime $date = null) : array - { - if ($date === null) $date = new DateTime(); - $qb= $this->createQueryBuilder() - ->andWhere('agentaffectation.agent = :agent') - ->setParameter('agent', $agent) - ; - -// $entityName = 'agentaffectation'; -// $qb = $qb -// ->andWhere("(" .$entityName . '.dateDebut IS NULL OR ' . $entityName . '.dateDebut <= :date'.")") -//// ->andWhere("agentaffectation.dateFin >= :date") -// ->setParameter('date', $date) -// ; - - $result = $qb->getQuery()->getResult(); - $result = array_filter($result, function (AgentAffectation $a) use ($date) { -// var_dump($a->getDateDebut()->format('H/m/Y')); - if ($a->getDateDebut() !== null AND $a->getDateDebut() >= $date) return false; -// var_dump($a->getDateFin()->format('H/m/Y')); - if ($a->getDateFin() !== null AND $a->getDateFin() <= $date) return false; - return true; - }); - return $result; - } - - /** @return AgentAffectation[] */ - public function getAgentAffectationsByAgent(Agent $agent, bool $actif = true) : array + public function getAgentAffectationsByAgent(Agent $agent, bool $actif = true): array { $qb = $this->createQueryBuilder() ->andWhere('agentaffectation.agent = :agent') ->setParameter('agent', $agent) - ->orderBy('agentaffectation.dateDebut', 'DESC') - ; - - if ($actif === true) $qb = AgentAffectation::decorateWithActif($qb, 'agentaffectation'); - - $result = $qb->getQuery()->getResult(); - return $result; - } - - /** @return AgentAffectation[]|null */ - public function getAgentAffectationHierarchiquePrincipaleByAgent(Agent $agent) : ?array - { - $result = $this->getAgentAffectationsByAgent($agent, true); - $result = array_filter($result, function (AgentAffectation $a) { return $a->isPrincipale() && $a->isHierarchique();}); - $nb = count($result); - // if ( $nb > 1) throw new RuntimeException("Plusieurs affections hiérarchique principale pour l'agent [".$agent->getDenomination()."]"); - if ($nb === 0 ) return null; - return $result; - } - - /** - * @param Structure $structure - * @param bool $actif - * @return array - */ - public function getAgentAffectationsByStructure(Structure $structure, bool $actif = true) : array - { - $qb = $this->createQueryBuilder() - ->andWhere('agentaffectation.structure = :structure') - ->setParameter('structure', $structure) - ; + ->orderBy('agentaffectation.dateDebut', 'DESC'); if ($actif === true) $qb = AgentAffectation::decorateWithActif($qb, 'agentaffectation'); diff --git a/module/Agent/src/Service/AgentAffectation/AgentAffectationServiceFactory.php b/module/Agent/src/Service/AgentAffectation/AgentAffectationServiceFactory.php index a3ce26d8dab9cab32a4bcd325661995c46bc1bad..19c1bee32aeaed0c6072ba68994cda8820b3d747 100644 --- a/module/Agent/src/Service/AgentAffectation/AgentAffectationServiceFactory.php +++ b/module/Agent/src/Service/AgentAffectation/AgentAffectationServiceFactory.php @@ -24,7 +24,7 @@ class AgentAffectationServiceFactory $entityManager = $container->get('doctrine.entitymanager.orm_default'); $service = new AgentAffectationService(); - $service->setEntityManager($entityManager); + $service->setObjectManager($entityManager); return $service; } } \ No newline at end of file diff --git a/module/Agent/src/Service/AgentGrade/AgentGradeService.php b/module/Agent/src/Service/AgentGrade/AgentGradeService.php index 6a8e4f339603a32875070a8a92fef6c43189a364..5481db6fbcbf049e72bf74229f64b48375a436b0 100644 --- a/module/Agent/src/Service/AgentGrade/AgentGradeService.php +++ b/module/Agent/src/Service/AgentGrade/AgentGradeService.php @@ -9,11 +9,10 @@ use Carriere\Entity\Db\Correspondance; use Carriere\Entity\Db\EmploiType; use Carriere\Entity\Db\Grade; use Doctrine\ORM\QueryBuilder; -use Structure\Entity\Db\Structure; -use UnicaenApp\Service\EntityManagerAwareTrait; +use DoctrineModule\Persistence\ProvidesObjectManager; class AgentGradeService { - use EntityManagerAwareTrait; + use ProvidesObjectManager; /** REQUETAGE *****************************************************************************************************/ @@ -22,7 +21,7 @@ class AgentGradeService { */ public function createQueryBuilder() : QueryBuilder { - $qb = $this->getEntityManager()->getRepository(AgentGrade::class)->createQueryBuilder('agentgrade') + $qb = $this->getObjectManager()->getRepository(AgentGrade::class)->createQueryBuilder('agentgrade') ->join('agentgrade.agent', 'agent')->addSelect('agent') ->join('agentgrade.structure', 'structure')->addSelect('structure') ->leftjoin('agentgrade.grade', 'grade')->addSelect('grade') @@ -52,24 +51,6 @@ class AgentGradeService { return $result; } - /** - * @param Structure $structure - * @param bool $actif - * @return array - */ - public function getAgentGradesByStructure(Structure $structure, bool $actif = true) : array - { - $qb = $this->createQueryBuilder() - ->andWhere('agentgrade.structure = :structure') - ->setParameter('structure', $structure) - ; - - if ($actif === true) $qb = AgentGrade::decorateWithActif($qb, 'agentgrade'); - - $result = $qb->getQuery()->getResult(); - return $result; - } - /** * @param Grade $grade * @param bool $actif diff --git a/module/Agent/src/Service/AgentGrade/AgentGradeServiceFactory.php b/module/Agent/src/Service/AgentGrade/AgentGradeServiceFactory.php index 6ad5af8fe1d7a566fcd2414de7c4ea5851b45bfb..dacadfefd0cd8440acf88317dc3027bf2a84b654 100644 --- a/module/Agent/src/Service/AgentGrade/AgentGradeServiceFactory.php +++ b/module/Agent/src/Service/AgentGrade/AgentGradeServiceFactory.php @@ -21,7 +21,7 @@ class AgentGradeServiceFactory { $entityManager = $container->get('doctrine.entitymanager.orm_default'); $service = new AgentGradeService(); - $service->setEntityManager($entityManager); + $service->setObjectManager($entityManager); return $service; } } \ No newline at end of file diff --git a/module/Agent/src/Service/AgentQuotite/AgentQuotiteService.php b/module/Agent/src/Service/AgentQuotite/AgentQuotiteService.php index c3471d00dbb5af3d660fd9ad9b33db6481c3aee8..424622579da6c09b99dcefc736bed2f4b6388ac1 100644 --- a/module/Agent/src/Service/AgentQuotite/AgentQuotiteService.php +++ b/module/Agent/src/Service/AgentQuotite/AgentQuotiteService.php @@ -5,23 +5,22 @@ namespace Agent\Service\AgentQuotite; use Agent\Entity\Db\Agent; use Agent\Entity\Db\AgentQuotite; use Doctrine\ORM\QueryBuilder; -use UnicaenApp\Exception\RuntimeException; -use UnicaenApp\Service\EntityManagerAwareTrait; +use DoctrineModule\Persistence\ProvidesObjectManager; -class AgentQuotiteService { - use EntityManagerAwareTrait; +class AgentQuotiteService +{ + use ProvidesObjectManager; /** GESTION ENTITE ************************************************************************************************/ // Complétement importées et jamais modifiées /** REQUETAGE *****************************************************************************************************/ - public function createQueryBuilder() : QueryBuilder + public function createQueryBuilder(): QueryBuilder { - $qb = $this->getEntityManager()->getRepository(AgentQuotite::class)->createQueryBuilder('agentquotite') + $qb = $this->getObjectManager()->getRepository(AgentQuotite::class)->createQueryBuilder('agentquotite') ->join('agentquotite.agent', 'agent')->addSelect('agent') - ->andWhere('agentquotite.deletedOn IS NULL') - ; + ->andWhere('agentquotite.deletedOn IS NULL'); return $qb; } @@ -30,13 +29,12 @@ class AgentQuotiteService { * @param bool $actif * @return array */ - public function getAgentQuotitesbyAgent(Agent $agent, bool $actif = true) : array + public function getAgentQuotitesByAgent(Agent $agent, bool $actif = true): array { $qb = $this->createQueryBuilder() ->andWhere('agentquotite.agent = :agent') ->andWhere('agentquotite.deletedOn IS NULL') - ->setParameter('agent', $agent) - ; + ->setParameter('agent', $agent); if ($actif === true) $qb = AgentQuotite::decorateWithActif($qb, 'agentquotite'); @@ -44,18 +42,5 @@ class AgentQuotiteService { return $result; } - /** - * @param Agent $agent - * @return AgentQuotite|null - * @attention null est equivalent à une quotité de 100% - */ - public function getAgentQuotiteCurrent(Agent $agent) : ?AgentQuotite - { - $result = $this->getAgentQuotitesbyAgent($agent); - $nb = count($result); - if ($nb === 0) return null; - if ($nb > 1) throw new RuntimeException("Plusieurs AgentQuotite de retournées pour l'agent [".$agent->getId()."]"); - return $result[0]; - } } \ No newline at end of file diff --git a/module/Agent/src/Service/AgentQuotite/AgentQuotiteServiceFactory.php b/module/Agent/src/Service/AgentQuotite/AgentQuotiteServiceFactory.php index db55362c64e4299028c9fda79b09cc29623ddb25..8f1865839e8c899d22542b552cc72a2a8b9aed94 100644 --- a/module/Agent/src/Service/AgentQuotite/AgentQuotiteServiceFactory.php +++ b/module/Agent/src/Service/AgentQuotite/AgentQuotiteServiceFactory.php @@ -21,7 +21,7 @@ class AgentQuotiteServiceFactory { $entityManager = $container->get('doctrine.entitymanager.orm_default'); $service = new AgentQuotiteService(); - $service->setEntityManager($entityManager); + $service->setObjectManager($entityManager); return $service; } } \ No newline at end of file diff --git a/module/Agent/src/Service/AgentStatut/AgentStatutService.php b/module/Agent/src/Service/AgentStatut/AgentStatutService.php index 94a52365e5318456930d6040934546d952a9027d..688bcc96bc8e479f2b0a22f9d4104c2804f620b8 100644 --- a/module/Agent/src/Service/AgentStatut/AgentStatutService.php +++ b/module/Agent/src/Service/AgentStatut/AgentStatutService.php @@ -5,17 +5,17 @@ namespace Agent\Service\AgentStatut; use Agent\Entity\Db\AgentStatut; use Agent\Entity\Db\Agent; use Doctrine\ORM\QueryBuilder; +use DoctrineModule\Persistence\ProvidesObjectManager; use Structure\Entity\Db\Structure; -use UnicaenApp\Service\EntityManagerAwareTrait; class AgentStatutService { - use EntityManagerAwareTrait; + use ProvidesObjectManager; /** REQUETAGE *****************************************************************************************************/ public function createQueryBuilder() : QueryBuilder { - $qb = $this->getEntityManager()->getRepository(AgentStatut::class)->createQueryBuilder('agentstatut') + $qb = $this->getObjectManager()->getRepository(AgentStatut::class)->createQueryBuilder('agentstatut') ->join('agentstatut.agent', 'agent')->addSelect('agent') ->join('agentstatut.structure', 'structure')->addSelect('structure') ->andWhere('agentstatut.deletedOn IS NULL') diff --git a/module/Agent/src/Service/AgentStatut/AgentStatutServiceFactory.php b/module/Agent/src/Service/AgentStatut/AgentStatutServiceFactory.php index 1d890a66c370688ce01b7e5ca7f32e930bd45bfd..4dc781ef48abae4ec96c5c287780a6ad25ae9b0b 100644 --- a/module/Agent/src/Service/AgentStatut/AgentStatutServiceFactory.php +++ b/module/Agent/src/Service/AgentStatut/AgentStatutServiceFactory.php @@ -21,7 +21,7 @@ class AgentStatutServiceFactory { $entityManager = $container->get('doctrine.entitymanager.orm_default'); $service = new AgentStatutService(); - $service->setEntityManager($entityManager); + $service->setObjectManager($entityManager); return $service; } } \ No newline at end of file diff --git a/module/Agent/src/Service/AgentValidateur/AgentValidateurService.php b/module/Agent/src/Service/AgentValidateur/AgentValidateurService.php index 739100849f0b8389be08be0dcfd0e148491832e9..55d7b799a1b66f8d4c7406ba5a688689c5342976 100644 --- a/module/Agent/src/Service/AgentValidateur/AgentValidateurService.php +++ b/module/Agent/src/Service/AgentValidateur/AgentValidateurService.php @@ -10,7 +10,6 @@ use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\QueryBuilder; use DoctrineModule\Persistence\ProvidesObjectManager; use Laminas\Mvc\Controller\AbstractActionController; -use Laminas\Validator\Date; use RuntimeException; use UnicaenUtilisateur\Entity\Db\User; @@ -76,7 +75,7 @@ class AgentValidateurService try { $result = $qb->getQuery()->getOneOrNullResult(); } catch (NonUniqueResultException $e) { - throw new RuntimeException("Plusieurs [".AgentValidateur::class."] partagent le même id [".$id."]"); + throw new RuntimeException("Plusieurs [".AgentValidateur::class."] partagent le même id [".$id."]",0,$e); } return $result; } @@ -190,15 +189,6 @@ class AgentValidateurService /** FACADE ********************************************************************************************************/ - public function createAgentValidateur(Agent $agent, Agent $validateur) : AgentValidateur - { - $agentValidateur = new AgentValidateur(); - $agentValidateur->setAgent($agent); - $agentValidateur->setValidateur($validateur); - $this->create($agentValidateur); - return $agentValidateur; - } - public function historiseAll(?Agent $agent, bool $activeOnly = false) : void { if ($agent !== null) { diff --git a/module/Application/src/Application/Entity/Db/Interfaces/HasPeriodeInterface.php b/module/Application/src/Application/Entity/Db/Interfaces/HasPeriodeInterface.php index 430aeaffbc11ce6a8c178e33bc3be9eb823bad97..565e2475d1333db662dcf99be9f6618222c84daf 100644 --- a/module/Application/src/Application/Entity/Db/Interfaces/HasPeriodeInterface.php +++ b/module/Application/src/Application/Entity/Db/Interfaces/HasPeriodeInterface.php @@ -3,6 +3,7 @@ namespace Application\Entity\Db\Interfaces; use DateTime; +use Doctrine\ORM\QueryBuilder; interface HasPeriodeInterface { @@ -16,4 +17,7 @@ interface HasPeriodeInterface { public function estCommence(?DateTime $date = null) : bool; public function estFini(?DateTime $date = null) : bool; public function estEnCours(?DateTime $date = null) : bool; + + /** Décorateur*/ + static public function decorateWithActif(QueryBuilder $qb, string $entityName, ?DateTime $date = null) : QueryBuilder; } \ No newline at end of file diff --git a/module/Fichier/src/Fichier/Entity/HasFichiersInterface.php b/module/Fichier/src/Fichier/Entity/HasFichiersInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..a76d6875e06db59835942d85a7f9a7c64d664035 --- /dev/null +++ b/module/Fichier/src/Fichier/Entity/HasFichiersInterface.php @@ -0,0 +1,16 @@ +<?php + +namespace Fichier\Entity; + +use Fichier\Entity\Db\Fichier; + +interface HasFichiersInterface +{ + public function getFichiers(): array; + + public function addFichier(Fichier $fichier): void; + + public function removeFichier(Fichier $fichier): void; + + public function fetchFiles(string $nature): array; +} \ No newline at end of file diff --git a/module/Fichier/src/Fichier/Entity/HasFichiersTrait.php b/module/Fichier/src/Fichier/Entity/HasFichiersTrait.php new file mode 100644 index 0000000000000000000000000000000000000000..7d1d43038d6f484bfa2ac4110597251f3c302b85 --- /dev/null +++ b/module/Fichier/src/Fichier/Entity/HasFichiersTrait.php @@ -0,0 +1,43 @@ +<?php + +namespace Fichier\Entity; + +use Doctrine\Common\Collections\Collection; +use Fichier\Entity\Db\Fichier; + +trait HasFichiersTrait +{ + private Collection $fichiers; + + /** + * @return Fichier[] + */ + public function getFichiers(): array + { + return $this->fichiers->toArray(); + } + + public function addFichier(Fichier $fichier): void + { + $this->fichiers->add($fichier); + } + + public function removeFichier(Fichier $fichier): void + { + $this->fichiers->removeElement($fichier); + } + + /** + * @param string $nature + * @return Fichier[] + */ + public function fetchFiles(string $nature): array + { + $fichiers = $this->getFichiers(); + $fichiers = array_filter($fichiers, function (Fichier $f) use ($nature) { + return ($f->getHistoDestruction() === null && $f->getNature()->getCode() === $nature); + }); + + return $fichiers; + } +} \ No newline at end of file diff --git a/module/Structure/config/merged/structure.config.php b/module/Structure/config/merged/structure.config.php index d1bfd8ff12bba619dec9090faaf0793ad24e363d..7dbcf7100ed44ffca8dff592c57e8ea858a41044 100644 --- a/module/Structure/config/merged/structure.config.php +++ b/module/Structure/config/merged/structure.config.php @@ -15,6 +15,10 @@ use Structure\Service\Structure\StructureService; use Structure\Service\Structure\StructureServiceFactory; use Structure\Service\StructureAgentForce\StructureAgentForceService; use Structure\Service\StructureAgentForce\StructureAgentForceServiceFactory; +use Structure\Service\StructureGestionnaire\StructureGestionnaireService; +use Structure\Service\StructureGestionnaire\StructureGestionnaireServiceFactory; +use Structure\Service\StructureResponsable\StructureResponsableService; +use Structure\Service\StructureResponsable\StructureResponsableServiceFactory; use UnicaenPrivilege\Guard\PrivilegeController; use UnicaenPrivilege\Provider\Rule\PrivilegeRuleProvider; @@ -225,6 +229,8 @@ return [ 'factories' => [ StructureService::class => StructureServiceFactory::class, StructureAgentForceService::class => StructureAgentForceServiceFactory::class, + StructureGestionnaireService::class => StructureGestionnaireServiceFactory::class, + StructureResponsableService::class => StructureResponsableServiceFactory::class, StructureAssertion::class => StructureAssertionFactory::class, NotificationService::class => NotificationServiceFactory::class, diff --git a/module/Structure/src/Structure/Provider/Identity/IdentityProvider.php b/module/Structure/src/Structure/Provider/Identity/IdentityProvider.php index aa6f2b4165a3beed39f9b58b31f0379044d00fc6..198c2a90c115a3de5f0988cc0e3d627a8168222d 100644 --- a/module/Structure/src/Structure/Provider/Identity/IdentityProvider.php +++ b/module/Structure/src/Structure/Provider/Identity/IdentityProvider.php @@ -5,6 +5,7 @@ namespace Structure\Provider\Identity; use Agent\Service\Agent\AgentServiceAwareTrait; use Structure\Provider\Role\RoleProvider; use Structure\Service\Structure\StructureServiceAwareTrait; +use Structure\Service\StructureResponsable\StructureResponsableServiceAwareTrait; use UnicaenUtilisateur\Entity\Db\RoleInterface; use UnicaenUtilisateur\Entity\Db\User; use UnicaenUtilisateur\Provider\Identity\AbstractIdentityProvider; @@ -16,6 +17,7 @@ class IdentityProvider extends AbstractIdentityProvider use AgentServiceAwareTrait; use RoleServiceAwareTrait; use StructureServiceAwareTrait; + use StructureResponsableServiceAwareTrait; use UserServiceAwareTrait; /** @@ -46,7 +48,7 @@ class IdentityProvider extends AbstractIdentityProvider $agent = $this->getAgentService()->getAgentByUser($user); if ($agent !== null) { - $responsabilites = $this->getAgentService()->getResposabiliteStructure($agent); + $responsabilites = $this->getStructureResponsableService()->getStructuresResponsablesByAgent($agent); if ($responsabilites !== null and $responsabilites !== []) { $roleResponsable = $this->getRoleService()->findByRoleId(RoleProvider::RESPONSABLE); $roles[] = $roleResponsable; diff --git a/module/Structure/src/Structure/Provider/Identity/IdentityProviderFactory.php b/module/Structure/src/Structure/Provider/Identity/IdentityProviderFactory.php index e21d167d30e80f4a922958403071174139516ffc..d9befc07d17ccb2885dc70ba6c51cefbf64497f4 100644 --- a/module/Structure/src/Structure/Provider/Identity/IdentityProviderFactory.php +++ b/module/Structure/src/Structure/Provider/Identity/IdentityProviderFactory.php @@ -7,6 +7,7 @@ use Interop\Container\ContainerInterface; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; use Structure\Service\Structure\StructureService; +use Structure\Service\StructureResponsable\StructureResponsableService; use UnicaenUtilisateur\Service\Role\RoleService; use UnicaenUtilisateur\Service\User\UserService; @@ -22,17 +23,20 @@ class IdentityProviderFactory * @var AgentService $agentService * @var RoleService $roleService * @var StructureService $structureService + * @var StructureResponsableService $structureResponsableService * @var UserService $userService */ $agentService = $container->get(AgentService::class); $roleService = $container->get(RoleService::class); $structureService = $container->get(StructureService::class); + $structureResponsableService = $container->get(StructureResponsableService::class); $userService = $container->get(UserService::class); $service = new IdentityProvider(); $service->setAgentService($agentService); $service->setRoleService($roleService); $service->setStructureService($structureService); + $service->setStructureResponsableService($structureResponsableService); $service->setUserService($userService); return $service; } diff --git a/module/Structure/src/Structure/Service/Structure/StructureService.php b/module/Structure/src/Structure/Service/Structure/StructureService.php index 264445ea6df3719d9a36c1e05444554b1066265d..e161b4b2bd8d3824e74ae07c12cd0415f211cac5 100644 --- a/module/Structure/src/Structure/Service/Structure/StructureService.php +++ b/module/Structure/src/Structure/Service/Structure/StructureService.php @@ -239,6 +239,25 @@ EOS; return $options; } + /** + * @param Structure[] $structures + * @return Agent[] + */ + public function getAgentsForcesByStructures(array $structures): array + { + $qb = $this->getObjectManager()->getRepository(Agent::class)->createQueryBuilder('agent') + ->addSelect('forcage')->join('agent.structuresForcees', 'forcage') + ->andWhere('forcage.histoDestruction IS NULL'); + + if (!empty(null)) { + $qb = $qb->andWhere('forcage.structure IN (:structures)') + ->setParameter('structures', $structures); + } + $result = $qb->getQuery()->getResult(); + + return $result; + } + /** * @return User[] */ diff --git a/module/Structure/src/Structure/Service/StructureGestionnaire/StructureGestionnaireService.php b/module/Structure/src/Structure/Service/StructureGestionnaire/StructureGestionnaireService.php new file mode 100644 index 0000000000000000000000000000000000000000..c216e6160ae70dc09894c02e4fb2dcbc575c8c29 --- /dev/null +++ b/module/Structure/src/Structure/Service/StructureGestionnaire/StructureGestionnaireService.php @@ -0,0 +1,41 @@ +<?php + +namespace Structure\Service\StructureGestionnaire; + +use Agent\Entity\Db\Agent; +use Application\Entity\Db\Interfaces\HasPeriodeInterface; +use DateTime; +use Doctrine\ORM\QueryBuilder; +use DoctrineModule\Persistence\ProvidesObjectManager; +use Structure\Entity\Db\StructureGestionnaire; +use Structure\Entity\Db\StructureResponsable; + +class StructureGestionnaireService { + use ProvidesObjectManager; + + /** Entité synchronisée */ + + /** REQUETAGE ********************************************************************************************/ + + public function createQueryBuilder(): QueryBuilder + { + $qb = $this->getObjectManager()->getRepository(StructureGestionnaire::class)->createQueryBuilder('structuregestionnaire') + ->join('structuregestionnaire.structure', 'structure')->addSelect('structure') + ->join('structuregestionnaire.agent', 'agent')->addSelect('agent') + ->andWhere('structuregestionnaire.deletedOn IS NULL') + ; + return $qb; + } + + public function getStructuresGestionnairesByAgent(?Agent $agent, ?DateTime $date = null): ?array + { + if ($agent === null) return null; + + $qb = $this->createQueryBuilder() + ->andWhere('structuregestionnaire.agent = :agent')->setParameter('agent', $agent); + if ($date !== null) $qb = StructureResponsable::decorateWithActif($qb, 'structuregestionnaire', $date); + + $result = $qb->getQuery()->getResult(); + return $result; + } +} \ No newline at end of file diff --git a/module/Structure/src/Structure/Service/StructureGestionnaire/StructureGestionnaireServiceAwareTrait.php b/module/Structure/src/Structure/Service/StructureGestionnaire/StructureGestionnaireServiceAwareTrait.php new file mode 100644 index 0000000000000000000000000000000000000000..a7deb1499ed3d50dcecf9032c20396aa08d7079b --- /dev/null +++ b/module/Structure/src/Structure/Service/StructureGestionnaire/StructureGestionnaireServiceAwareTrait.php @@ -0,0 +1,19 @@ +<?php + +namespace Structure\Service\StructureGestionnaire; + +trait StructureGestionnaireServiceAwareTrait +{ + private StructureGestionnaireService $structureGestionnaireService; + + public function getStructureGestionnaireService(): StructureGestionnaireService + { + return $this->structureGestionnaireService; + } + + public function setStructureGestionnaireService(StructureGestionnaireService $structureGestionnaireService): void + { + $this->structureGestionnaireService = $structureGestionnaireService; + } + +} \ No newline at end of file diff --git a/module/Structure/src/Structure/Service/StructureGestionnaire/StructureGestionnaireServiceFactory.php b/module/Structure/src/Structure/Service/StructureGestionnaire/StructureGestionnaireServiceFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..4f50ae7a33a7da6c96709ce8f0fcd09ddef88009 --- /dev/null +++ b/module/Structure/src/Structure/Service/StructureGestionnaire/StructureGestionnaireServiceFactory.php @@ -0,0 +1,25 @@ +<?php + +namespace Structure\Service\StructureGestionnaire; + +use Doctrine\ORM\EntityManager; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\ContainerInterface; +use Psr\Container\NotFoundExceptionInterface; + +class StructureGestionnaireServiceFactory +{ + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function __invoke(ContainerInterface $container): StructureGestionnaireService + { + /** @var EntityManager $entityManager */ + $entityManager = $container->get('doctrine.entitymanager.orm_default'); + + $service = new StructureGestionnaireService(); + $service->setObjectManager($entityManager); + return $service; + } +} \ No newline at end of file diff --git a/module/Structure/src/Structure/Service/StructureResponsable/StructureResponsableService.php b/module/Structure/src/Structure/Service/StructureResponsable/StructureResponsableService.php new file mode 100644 index 0000000000000000000000000000000000000000..00fb736de7e86d9a2e2a4183c684f89429079b09 --- /dev/null +++ b/module/Structure/src/Structure/Service/StructureResponsable/StructureResponsableService.php @@ -0,0 +1,40 @@ +<?php + +namespace Structure\Service\StructureResponsable; + +use Agent\Entity\Db\Agent; +use Application\Entity\Db\Interfaces\HasPeriodeInterface; +use DateTime; +use Doctrine\ORM\QueryBuilder; +use DoctrineModule\Persistence\ProvidesObjectManager; +use Structure\Entity\Db\StructureResponsable; + +class StructureResponsableService { + use ProvidesObjectManager; + + /** Entité synchronisée */ + + /** REQUETAGE ********************************************************************************************/ + + public function createQueryBuilder(): QueryBuilder + { + $qb = $this->getObjectManager()->getRepository(StructureResponsable::class)->createQueryBuilder('structureresponsable') + ->join('structureresponsable.structure', 'structure')->addSelect('structure') + ->join('structureresponsable.agent', 'agent')->addSelect('agent') + ->andWhere('structureresponsable.deletedOn IS NULL') + ; + return $qb; + } + + public function getStructuresResponsablesByAgent(?Agent $agent, ?DateTime $date = null): ?array + { + if ($agent === null) return null; + + $qb = $this->createQueryBuilder() + ->andWhere('structureresponsable.agent = :agent')->setParameter('agent', $agent); + if ($date !== null) $qb = StructureResponsable::decorateWithActif($qb, 'structureresponsable', $date); + + $result = $qb->getQuery()->getResult(); + return $result; + } +} \ No newline at end of file diff --git a/module/Structure/src/Structure/Service/StructureResponsable/StructureResponsableServiceAwareTrait.php b/module/Structure/src/Structure/Service/StructureResponsable/StructureResponsableServiceAwareTrait.php new file mode 100644 index 0000000000000000000000000000000000000000..a745aae5807284d6ef58089d9c2d041f24bac35e --- /dev/null +++ b/module/Structure/src/Structure/Service/StructureResponsable/StructureResponsableServiceAwareTrait.php @@ -0,0 +1,19 @@ +<?php + +namespace Structure\Service\StructureResponsable; + +trait StructureResponsableServiceAwareTrait +{ + private StructureResponsableService $structureResponsableService; + + public function getStructureResponsableService(): StructureResponsableService + { + return $this->structureResponsableService; + } + + public function setStructureResponsableService(StructureResponsableService $structureResponsableService): void + { + $this->structureResponsableService = $structureResponsableService; + } + +} \ No newline at end of file diff --git a/module/Structure/src/Structure/Service/StructureResponsable/StructureResponsableServiceFactory.php b/module/Structure/src/Structure/Service/StructureResponsable/StructureResponsableServiceFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..5b74c6c2686caf1439273283c958da429f31553a --- /dev/null +++ b/module/Structure/src/Structure/Service/StructureResponsable/StructureResponsableServiceFactory.php @@ -0,0 +1,25 @@ +<?php + +namespace Structure\Service\StructureResponsable; + +use Doctrine\ORM\EntityManager; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\ContainerInterface; +use Psr\Container\NotFoundExceptionInterface; + +class StructureResponsableServiceFactory +{ + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function __invoke(ContainerInterface $container): StructureResponsableService + { + /** @var EntityManager $entityManager */ + $entityManager = $container->get('doctrine.entitymanager.orm_default'); + + $service = new StructureResponsableService(); + $service->setObjectManager($entityManager); + return $service; + } +} \ No newline at end of file