Loading module/Application/src/Application/Controller/AgentController.php +2 −26 Original line number Diff line number Diff line Loading @@ -622,7 +622,7 @@ class AgentController extends AbstractActionController { if (($term = $this->params()->fromQuery('term'))) { $agents = $this->getAgentService()->getAgentsByTerm($term); $result = $this->formatAgentJSON($agents); $result = $this->getAgentService()->formatAgentJSON($agents); return new JsonModel($result); } exit; Loading @@ -637,35 +637,12 @@ class AgentController extends AbstractActionController if (($term = $this->params()->fromQuery('term'))) { $agents = $this->getAgentService()->getAgentsByTerm($term, $structures); $result = $this->formatAgentJSON($agents); $result = $this->getAgentService()->formatAgentJSON($agents); return new JsonModel($result); } exit; } /** * @param Agent[] $agents * @return array */ private function formatAgentJSON(array $agents) { $result = []; /** @var Agent[] $agents */ foreach ($agents as $agent) { $structure = ($agent->getAffectationPrincipale()) ? ($agent->getAffectationPrincipale()->getStructure()) : null; $extra = ($structure) ? $structure->getLibelleCourt() : "Affectation inconnue"; $result[] = array( 'id' => $agent->getId(), 'label' => $agent->getDenomination(), 'extra' => "<span class='badge' style='background-color: slategray;'>" . $extra . "</span>", ); } usort($result, function ($a, $b) { return strcmp($a['label'], $b['label']); }); return $result; } public function rechercherResponsableAction() { if (($term = $this->params()->fromQuery('term'))) { Loading @@ -679,7 +656,6 @@ class AgentController extends AbstractActionController public function rechercherGestionnaireAction() { if (($term = $this->params()->fromQuery('term'))) { // $gestionnaires = $this->getUserService()->findByTermAndRole($term, RoleConstant::GESTIONNAIRE); $gestionnaires = $this->getUserService()->findByTerm($term); $result = $this->getUserService()->formatUserJSON($gestionnaires); return new JsonModel($result); Loading module/Application/src/Application/Controller/StructureController.php +3 −44 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ use EntretienProfessionnel\Service\Campagne\CampagneServiceAwareTrait; use EntretienProfessionnel\Service\EntretienProfessionnel\EntretienProfessionnelServiceAwareTrait; use UnicaenApp\Form\Element\SearchAndSelect; use UnicaenApp\View\Model\CsvModel; use UnicaenUtilisateur\Entity\Db\User; use UnicaenUtilisateur\Service\Role\RoleServiceAwareTrait; use UnicaenUtilisateur\Service\User\UserServiceAwareTrait; use Zend\Http\Request; Loading Loading @@ -294,7 +293,7 @@ class StructureController extends AbstractActionController { { if (($term = $this->params()->fromQuery('term'))) { $structures = $this->getStructureService()->getStructuresByTerm($term); $result = $result = $this->formatStructureJSON($structures); $result = $this->getStructureService()->formatStructureJSON($structures); return new JsonModel($result); } exit; Loading @@ -310,7 +309,7 @@ class StructureController extends AbstractActionController { $term = $this->params()->fromQuery('term'); if ($term) { $structures = $this->getStructureService()->getStructuresByTerm($term, $structures); $result = $this->formatStructureJSON($structures); $result = $this->getStructureService()->formatStructureJSON($structures); return new JsonModel($result); } exit; Loading @@ -333,52 +332,12 @@ class StructureController extends AbstractActionController { foreach ($users as $user) { if (strpos(strtolower($user->getDisplayName()), $term) !== false) $selected[] = $user; } $result = $this->formatUtilisateurJSON($selected); $result = $this->getUserService()->formatUserJSON($selected); return new JsonModel($result); } exit; } /** * @param Structure[] $structures * @return array */ private function formatStructureJSON(array $structures) { $result = []; foreach ($structures as $structure) { $result[] = array( 'id' => $structure->getId(), 'label' => $structure->getLibelleLong(), 'extra' => "<span class='badge' style='background-color: slategray;'>".$structure->getLibelleCourt()."</span>", ); } usort($result, function($a, $b) { return strcmp($a['label'], $b['label']); }); return $result; } /** * @param User[] $users * @return array */ private function formatUtilisateurJSON(array $users) { $result = []; foreach ($users as $user) { $result[] = array( 'id' => $user->getId(), 'label' => $user->getDisplayName(), 'extra' => "<span class='badge' style='background-color: slategray;'>".$user->getEmail()."</span>", ); } usort($result, function($a, $b) { return strcmp($a['label'], $b['label']); }); return $result; } /** AGENTS FORCES *************************************************************************************************/ public function ajouterManuellementAgentAction() Loading module/Application/src/Application/Entity/Db/Agent.php +7 −1 Original line number Diff line number Diff line Loading @@ -209,12 +209,18 @@ class Agent implements } /** * @param DateTime|null $date * @return AgentAffectation[] */ public function getAffectations() public function getAffectations(?DateTime $date = null) { $affectations = $this->affectations->toArray(); $affectations = array_filter($affectations, function (AgentAffectation $aa) { return !$aa->isDeleted();}); if ($date !== null) { $affectations = array_filter($affectations, function (AgentAffectation $aa) use ($date) { return (($aa->getDateDebut() <= $date) AND ($aa->getDateFin() === null OR $aa->getDateFin() >= $date)); }); } usort($affectations, function (AgentAffectation $a, AgentAffectation $b) { return $a->getDateDebut() < $b->getDateDebut(); }); Loading module/Application/src/Application/Service/Agent/AgentService.php +23 −0 Original line number Diff line number Diff line Loading @@ -438,4 +438,27 @@ class AgentService { $this->deleteFromTrait($agentMissionSpecifique); return $agentMissionSpecifique; } /** * @param Agent[] $agents * @return array */ public function formatAgentJSON(array $agents) { $result = []; /** @var Agent[] $agents */ foreach ($agents as $agent) { $structure = ($agent->getAffectationPrincipale()) ? ($agent->getAffectationPrincipale()->getStructure()) : null; $extra = ($structure) ? $structure->getLibelleCourt() : "Affectation inconnue"; $result[] = array( 'id' => $agent->getId(), 'label' => $agent->getDenomination(), 'extra' => "<span class='badge' style='background-color: slategray;'>" . $extra . "</span>", ); } usort($result, function ($a, $b) { return strcmp($a['label'], $b['label']); }); return $result; } } No newline at end of file module/Application/src/Application/Service/Structure/StructureService.php +19 −0 Original line number Diff line number Diff line Loading @@ -270,4 +270,23 @@ class StructureService return $gestionnaires; } /** * @param Structure[] $structures * @return array */ public function formatStructureJSON(array $structures) { $result = []; foreach ($structures as $structure) { $result[] = array( 'id' => $structure->getId(), 'label' => $structure->getLibelleLong(), 'extra' => "<span class='badge' style='background-color: slategray;'>".$structure->getLibelleCourt()."</span>", ); } usort($result, function($a, $b) { return strcmp($a['label'], $b['label']); }); return $result; } } Loading
module/Application/src/Application/Controller/AgentController.php +2 −26 Original line number Diff line number Diff line Loading @@ -622,7 +622,7 @@ class AgentController extends AbstractActionController { if (($term = $this->params()->fromQuery('term'))) { $agents = $this->getAgentService()->getAgentsByTerm($term); $result = $this->formatAgentJSON($agents); $result = $this->getAgentService()->formatAgentJSON($agents); return new JsonModel($result); } exit; Loading @@ -637,35 +637,12 @@ class AgentController extends AbstractActionController if (($term = $this->params()->fromQuery('term'))) { $agents = $this->getAgentService()->getAgentsByTerm($term, $structures); $result = $this->formatAgentJSON($agents); $result = $this->getAgentService()->formatAgentJSON($agents); return new JsonModel($result); } exit; } /** * @param Agent[] $agents * @return array */ private function formatAgentJSON(array $agents) { $result = []; /** @var Agent[] $agents */ foreach ($agents as $agent) { $structure = ($agent->getAffectationPrincipale()) ? ($agent->getAffectationPrincipale()->getStructure()) : null; $extra = ($structure) ? $structure->getLibelleCourt() : "Affectation inconnue"; $result[] = array( 'id' => $agent->getId(), 'label' => $agent->getDenomination(), 'extra' => "<span class='badge' style='background-color: slategray;'>" . $extra . "</span>", ); } usort($result, function ($a, $b) { return strcmp($a['label'], $b['label']); }); return $result; } public function rechercherResponsableAction() { if (($term = $this->params()->fromQuery('term'))) { Loading @@ -679,7 +656,6 @@ class AgentController extends AbstractActionController public function rechercherGestionnaireAction() { if (($term = $this->params()->fromQuery('term'))) { // $gestionnaires = $this->getUserService()->findByTermAndRole($term, RoleConstant::GESTIONNAIRE); $gestionnaires = $this->getUserService()->findByTerm($term); $result = $this->getUserService()->formatUserJSON($gestionnaires); return new JsonModel($result); Loading
module/Application/src/Application/Controller/StructureController.php +3 −44 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ use EntretienProfessionnel\Service\Campagne\CampagneServiceAwareTrait; use EntretienProfessionnel\Service\EntretienProfessionnel\EntretienProfessionnelServiceAwareTrait; use UnicaenApp\Form\Element\SearchAndSelect; use UnicaenApp\View\Model\CsvModel; use UnicaenUtilisateur\Entity\Db\User; use UnicaenUtilisateur\Service\Role\RoleServiceAwareTrait; use UnicaenUtilisateur\Service\User\UserServiceAwareTrait; use Zend\Http\Request; Loading Loading @@ -294,7 +293,7 @@ class StructureController extends AbstractActionController { { if (($term = $this->params()->fromQuery('term'))) { $structures = $this->getStructureService()->getStructuresByTerm($term); $result = $result = $this->formatStructureJSON($structures); $result = $this->getStructureService()->formatStructureJSON($structures); return new JsonModel($result); } exit; Loading @@ -310,7 +309,7 @@ class StructureController extends AbstractActionController { $term = $this->params()->fromQuery('term'); if ($term) { $structures = $this->getStructureService()->getStructuresByTerm($term, $structures); $result = $this->formatStructureJSON($structures); $result = $this->getStructureService()->formatStructureJSON($structures); return new JsonModel($result); } exit; Loading @@ -333,52 +332,12 @@ class StructureController extends AbstractActionController { foreach ($users as $user) { if (strpos(strtolower($user->getDisplayName()), $term) !== false) $selected[] = $user; } $result = $this->formatUtilisateurJSON($selected); $result = $this->getUserService()->formatUserJSON($selected); return new JsonModel($result); } exit; } /** * @param Structure[] $structures * @return array */ private function formatStructureJSON(array $structures) { $result = []; foreach ($structures as $structure) { $result[] = array( 'id' => $structure->getId(), 'label' => $structure->getLibelleLong(), 'extra' => "<span class='badge' style='background-color: slategray;'>".$structure->getLibelleCourt()."</span>", ); } usort($result, function($a, $b) { return strcmp($a['label'], $b['label']); }); return $result; } /** * @param User[] $users * @return array */ private function formatUtilisateurJSON(array $users) { $result = []; foreach ($users as $user) { $result[] = array( 'id' => $user->getId(), 'label' => $user->getDisplayName(), 'extra' => "<span class='badge' style='background-color: slategray;'>".$user->getEmail()."</span>", ); } usort($result, function($a, $b) { return strcmp($a['label'], $b['label']); }); return $result; } /** AGENTS FORCES *************************************************************************************************/ public function ajouterManuellementAgentAction() Loading
module/Application/src/Application/Entity/Db/Agent.php +7 −1 Original line number Diff line number Diff line Loading @@ -209,12 +209,18 @@ class Agent implements } /** * @param DateTime|null $date * @return AgentAffectation[] */ public function getAffectations() public function getAffectations(?DateTime $date = null) { $affectations = $this->affectations->toArray(); $affectations = array_filter($affectations, function (AgentAffectation $aa) { return !$aa->isDeleted();}); if ($date !== null) { $affectations = array_filter($affectations, function (AgentAffectation $aa) use ($date) { return (($aa->getDateDebut() <= $date) AND ($aa->getDateFin() === null OR $aa->getDateFin() >= $date)); }); } usort($affectations, function (AgentAffectation $a, AgentAffectation $b) { return $a->getDateDebut() < $b->getDateDebut(); }); Loading
module/Application/src/Application/Service/Agent/AgentService.php +23 −0 Original line number Diff line number Diff line Loading @@ -438,4 +438,27 @@ class AgentService { $this->deleteFromTrait($agentMissionSpecifique); return $agentMissionSpecifique; } /** * @param Agent[] $agents * @return array */ public function formatAgentJSON(array $agents) { $result = []; /** @var Agent[] $agents */ foreach ($agents as $agent) { $structure = ($agent->getAffectationPrincipale()) ? ($agent->getAffectationPrincipale()->getStructure()) : null; $extra = ($structure) ? $structure->getLibelleCourt() : "Affectation inconnue"; $result[] = array( 'id' => $agent->getId(), 'label' => $agent->getDenomination(), 'extra' => "<span class='badge' style='background-color: slategray;'>" . $extra . "</span>", ); } usort($result, function ($a, $b) { return strcmp($a['label'], $b['label']); }); return $result; } } No newline at end of file
module/Application/src/Application/Service/Structure/StructureService.php +19 −0 Original line number Diff line number Diff line Loading @@ -270,4 +270,23 @@ class StructureService return $gestionnaires; } /** * @param Structure[] $structures * @return array */ public function formatStructureJSON(array $structures) { $result = []; foreach ($structures as $structure) { $result[] = array( 'id' => $structure->getId(), 'label' => $structure->getLibelleLong(), 'extra' => "<span class='badge' style='background-color: slategray;'>".$structure->getLibelleCourt()."</span>", ); } usort($result, function($a, $b) { return strcmp($a['label'], $b['label']); }); return $result; } }