Skip to content
Snippets Groups Projects
Commit 0c995253 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Cleaning

parent 6856c74e
No related branches found
No related tags found
No related merge requests found
Showing
with 57 additions and 450 deletions
......@@ -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[] */
......
......@@ -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;
......
......@@ -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
{
......
......@@ -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
......@@ -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;
......
......@@ -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;
}
......
......@@ -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
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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,7 +244,6 @@ 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');
......@@ -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()
......
......@@ -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
{
$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
{
$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');
......
......@@ -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
......@@ -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
......
......@@ -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
......@@ -5,11 +5,11 @@ 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
......@@ -18,10 +18,9 @@ class AgentQuotiteService {
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
......@@ -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
......@@ -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')
......
......@@ -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
......@@ -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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment