Loading module/Application/config/others/coencadrant.config.php→module/Application/config/others/co-encadrant.config.php +18 −0 Changes for module/Application/config/others/co-encadrant.config.php: 18 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -6,6 +6,8 @@ use Application\Controller\CoEncadrantController; use Application\Controller\Factory\CoEncadrantControllerFactory; use Application\Form\Factory\RechercherCoEncadrantFormFactory; use Application\Form\RechercherCoEncadrantForm; use Application\Service\CoEncadrant\CoEncadrantService; use Application\Service\CoEncadrant\CoEncadrantServiceFactory; use UnicaenAuth\Guard\PrivilegeController; use Zend\Router\Http\Literal; use Zend\Router\Http\Segment; Loading @@ -19,6 +21,7 @@ return [ 'action' => [ 'index', 'historique', 'rechercher-co-encadrant', 'ajouter-co-encadrant', 'retirer-co-encadrant', ], Loading Loading @@ -52,6 +55,16 @@ return [ ], ], ], 'rechercher-co-encadrant' => [ 'type' => Literal::class, 'options' => [ 'route' => '/rechercher-co-encadrant', 'defaults' => [ 'controller' => CoEncadrantController::class, 'action' => 'rechercher-co-encadrant', ], ], ], 'ajouter-co-encadrant' => [ 'type' => Segment::class, 'options' => [ Loading Loading @@ -114,4 +127,9 @@ return [ RechercherCoEncadrantForm::class => RechercherCoEncadrantFormFactory::class, ], ], 'service_manager' => [ 'factories' => [ CoEncadrantService::class => CoEncadrantServiceFactory::class, ], ], ]; module/Application/src/Application/Controller/CoEncadrantController.php +44 −3 Changes for module/Application/src/Application/Controller/CoEncadrantController.php: 44 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -2,12 +2,17 @@ namespace Application\Controller; use Application\Entity\Db\These; use Application\Form\RechercherCoEncadrantFormAwareTrait; use Zend\Form\Element\Button; use Application\Service\CoEncadrant\CoEncadrantServiceAwareTrait; use Application\Service\These\TheseServiceAwareTrait; use Zend\Mvc\Controller\AbstractActionController; use Zend\View\Model\JsonModel; use Zend\View\Model\ViewModel; class CoEncadrantController extends AbstractActionController { use CoEncadrantServiceAwareTrait; use TheseServiceAwareTrait; use RechercherCoEncadrantFormAwareTrait; public function indexAction() Loading @@ -15,7 +20,7 @@ class CoEncadrantController extends AbstractActionController { $form = $this->getRechercherCoEncadrantForm(); $form->setAttribute('action', $this->url()->fromRoute('co-encadrant', [], [], true)); //todo !doit remonter un acteur $form->setUrlCoEncadrant($this->url()->fromRoute('utilisateur/rechercher-individu', [], [], true)); $form->setUrlCoEncadrant($this->url()->fromRoute('co-encadrant/rechercher-co-encadrant', [], [], true)); $form->get('bouton')->setLabel("Afficher l'historique de co-encadrement"); $request = $this->getRequest(); Loading @@ -31,12 +36,48 @@ class CoEncadrantController extends AbstractActionController { ]); } public function rechercherCoEncadrantAction() { if (($term = $this->params()->fromQuery('term'))) { $acteurs = $this->getCoEncadrantService()->findByText($term); $result = []; foreach ($acteurs as $acteur) { // mise en forme attendue par l'aide de vue FormSearchAndSelect $label = $acteur->getIndividu()->getPrenom() . ' ' . $acteur->getIndividu()->getNomUsuel(); $extra = ($acteur->getIndividu()->getEmail())?:$acteur->getIndividu()->getSourceCode(); $result[$acteur->getId()] = array( 'id' => $acteur->getId(), // identifiant unique de l'item 'label' => $label, // libellé de l'item 'extra' => $extra, // infos complémentaires (facultatives) sur l'item ); } usort($result, function ($a, $b) { return strcmp($a['label'], $b['label']); }); return new JsonModel($result); } exit; } public function historiqueAction() { $coencadrant = null; $coencadrant = $this->getCoEncadrantService()->getRequestedCoEncadrant($this); $theses = $this->getTheseService()->getRepository()->fetchThesesByCoEncadrant($coencadrant->getIndividu()); $encours = []; $closes = []; foreach ($theses as $these) { if ($these->getEtatThese() === These::ETAT_EN_COURS) { $encours[] = $these; } else { $closes[] = $these; } } return new ViewModel([ 'coencadrant' => $coencadrant, 'encours' => $encours, 'closes' => $closes, ]); } } No newline at end of file module/Application/src/Application/Controller/Factory/CoEncadrantControllerFactory.php +11 −0 Changes for module/Application/src/Application/Controller/Factory/CoEncadrantControllerFactory.php: 11 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -4,6 +4,8 @@ namespace Application\Controller\Factory; use Application\Controller\CoEncadrantController; use Application\Form\RechercherCoEncadrantForm; use Application\Service\CoEncadrant\CoEncadrantService; use Application\Service\These\TheseService; use Interop\Container\ContainerInterface; class CoEncadrantControllerFactory { Loading @@ -14,12 +16,21 @@ class CoEncadrantControllerFactory { */ public function __invoke(ContainerInterface $container) { /** * @var CoEncadrantService $coEncadrantService * @var TheseService $theseService */ $coEncadrantService = $container->get(CoEncadrantService::class); $theseService = $container->get('TheseService'); /** * @var RechercherCoEncadrantForm $rechercheCoEncadrantForm */ $rechercheCoEncadrantForm = $container->get('FormElementManager')->get(RechercherCoEncadrantForm::class); $controller = new CoEncadrantController(); $controller->setCoEncadrantService($coEncadrantService); $controller->setTheseService($theseService); $controller->setRechercherCoEncadrantForm($rechercheCoEncadrantForm); return $controller; } Loading module/Application/src/Application/Entity/Db/Repository/TheseRepository.php +21 −0 Changes for module/Application/src/Application/Entity/Db/Repository/TheseRepository.php: 21 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -214,6 +214,27 @@ class TheseRepository extends DefaultEntityRepository return $result; } /** * @param Individu $individu * @return These[] */ public function fetchThesesByCoEncadrant($individu) { $qb = $this->createQueryBuilder('t') ->join('t.acteurs', 'a') ->join('a.role', 'r') ->andWhere('r.code = :coencadrant') ->setParameter('coencadrant', Role::CODE_CO_ENCADRANT) ->andWhere('a.individu = :individu') ->setParameter('individu', $individu) ->andWhere('1 = pasHistorise(t)') ->orderBy('t.datePremiereInscription', 'ASC') ; $result = $qb->getQuery()->getResult(); return $result; } } No newline at end of file module/Application/src/Application/Service/CoEncadrant/CoEncadrantService.php 0 → 100644 +71 −0 Changes for module/Application/src/Application/Service/CoEncadrant/CoEncadrantService.php: 71 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Application\Service\CoEncadrant; use Application\Entity\Db\Acteur; use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\QueryBuilder; use UnicaenApp\Exception\RuntimeException; use UnicaenApp\Service\EntityManagerAwareTrait; use Zend\Mvc\Controller\AbstractActionController; class CoEncadrantService { use EntityManagerAwareTrait; /** * @return QueryBuilder */ public function createQueryBuilder() { $qb = $this->getEntityManager()->getRepository(Acteur::class)->createQueryBuilder('acteur') ->addSelect('individu')->join('acteur.individu', 'individu') ->addSelect('role')->join('acteur.role', 'role') ->andWhere('role.code = :code') ->setParameter('code', 'B') ; return $qb; } /** * @param string $term * @return Acteur[] */ public function findByText(string $term) { $qb = $this->createQueryBuilder() ->andWhere("LOWER(concat(concat(concat(concat(individu.prenom1, ' '),individu.nomUsuel), ' '), individu.prenom1)) like :term") ->setParameter('term', '%'.strtolower($term).'%') ; $result = $qb->getQuery()->getResult(); return $result; } /** * @param int $id * @return Acteur */ public function getCoEncadrant(int $id) { $qb = $this->createQueryBuilder() ->andWhere('acteur.id = :id') ->setParameter('id', $id) ; try { $result = $qb->getQuery()->getOneOrNullResult(); } catch (NonUniqueResultException $e) { throw new RuntimeException("Plusieurs Acteur partagent le même id [".$id."]."); } return $result; } /** * @param AbstractActionController $controller * @param string $param * @return Acteur */ public function getRequestedCoEncadrant(AbstractActionController $controller, string $param = 'co-encadrant') { $id = $controller->params()->fromRoute($param); $result = $this->getCoEncadrant($id); return $result; } } No newline at end of file Loading
module/Application/config/others/coencadrant.config.php→module/Application/config/others/co-encadrant.config.php +18 −0 Changes for module/Application/config/others/co-encadrant.config.php: 18 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -6,6 +6,8 @@ use Application\Controller\CoEncadrantController; use Application\Controller\Factory\CoEncadrantControllerFactory; use Application\Form\Factory\RechercherCoEncadrantFormFactory; use Application\Form\RechercherCoEncadrantForm; use Application\Service\CoEncadrant\CoEncadrantService; use Application\Service\CoEncadrant\CoEncadrantServiceFactory; use UnicaenAuth\Guard\PrivilegeController; use Zend\Router\Http\Literal; use Zend\Router\Http\Segment; Loading @@ -19,6 +21,7 @@ return [ 'action' => [ 'index', 'historique', 'rechercher-co-encadrant', 'ajouter-co-encadrant', 'retirer-co-encadrant', ], Loading Loading @@ -52,6 +55,16 @@ return [ ], ], ], 'rechercher-co-encadrant' => [ 'type' => Literal::class, 'options' => [ 'route' => '/rechercher-co-encadrant', 'defaults' => [ 'controller' => CoEncadrantController::class, 'action' => 'rechercher-co-encadrant', ], ], ], 'ajouter-co-encadrant' => [ 'type' => Segment::class, 'options' => [ Loading Loading @@ -114,4 +127,9 @@ return [ RechercherCoEncadrantForm::class => RechercherCoEncadrantFormFactory::class, ], ], 'service_manager' => [ 'factories' => [ CoEncadrantService::class => CoEncadrantServiceFactory::class, ], ], ];
module/Application/src/Application/Controller/CoEncadrantController.php +44 −3 Changes for module/Application/src/Application/Controller/CoEncadrantController.php: 44 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -2,12 +2,17 @@ namespace Application\Controller; use Application\Entity\Db\These; use Application\Form\RechercherCoEncadrantFormAwareTrait; use Zend\Form\Element\Button; use Application\Service\CoEncadrant\CoEncadrantServiceAwareTrait; use Application\Service\These\TheseServiceAwareTrait; use Zend\Mvc\Controller\AbstractActionController; use Zend\View\Model\JsonModel; use Zend\View\Model\ViewModel; class CoEncadrantController extends AbstractActionController { use CoEncadrantServiceAwareTrait; use TheseServiceAwareTrait; use RechercherCoEncadrantFormAwareTrait; public function indexAction() Loading @@ -15,7 +20,7 @@ class CoEncadrantController extends AbstractActionController { $form = $this->getRechercherCoEncadrantForm(); $form->setAttribute('action', $this->url()->fromRoute('co-encadrant', [], [], true)); //todo !doit remonter un acteur $form->setUrlCoEncadrant($this->url()->fromRoute('utilisateur/rechercher-individu', [], [], true)); $form->setUrlCoEncadrant($this->url()->fromRoute('co-encadrant/rechercher-co-encadrant', [], [], true)); $form->get('bouton')->setLabel("Afficher l'historique de co-encadrement"); $request = $this->getRequest(); Loading @@ -31,12 +36,48 @@ class CoEncadrantController extends AbstractActionController { ]); } public function rechercherCoEncadrantAction() { if (($term = $this->params()->fromQuery('term'))) { $acteurs = $this->getCoEncadrantService()->findByText($term); $result = []; foreach ($acteurs as $acteur) { // mise en forme attendue par l'aide de vue FormSearchAndSelect $label = $acteur->getIndividu()->getPrenom() . ' ' . $acteur->getIndividu()->getNomUsuel(); $extra = ($acteur->getIndividu()->getEmail())?:$acteur->getIndividu()->getSourceCode(); $result[$acteur->getId()] = array( 'id' => $acteur->getId(), // identifiant unique de l'item 'label' => $label, // libellé de l'item 'extra' => $extra, // infos complémentaires (facultatives) sur l'item ); } usort($result, function ($a, $b) { return strcmp($a['label'], $b['label']); }); return new JsonModel($result); } exit; } public function historiqueAction() { $coencadrant = null; $coencadrant = $this->getCoEncadrantService()->getRequestedCoEncadrant($this); $theses = $this->getTheseService()->getRepository()->fetchThesesByCoEncadrant($coencadrant->getIndividu()); $encours = []; $closes = []; foreach ($theses as $these) { if ($these->getEtatThese() === These::ETAT_EN_COURS) { $encours[] = $these; } else { $closes[] = $these; } } return new ViewModel([ 'coencadrant' => $coencadrant, 'encours' => $encours, 'closes' => $closes, ]); } } No newline at end of file
module/Application/src/Application/Controller/Factory/CoEncadrantControllerFactory.php +11 −0 Changes for module/Application/src/Application/Controller/Factory/CoEncadrantControllerFactory.php: 11 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -4,6 +4,8 @@ namespace Application\Controller\Factory; use Application\Controller\CoEncadrantController; use Application\Form\RechercherCoEncadrantForm; use Application\Service\CoEncadrant\CoEncadrantService; use Application\Service\These\TheseService; use Interop\Container\ContainerInterface; class CoEncadrantControllerFactory { Loading @@ -14,12 +16,21 @@ class CoEncadrantControllerFactory { */ public function __invoke(ContainerInterface $container) { /** * @var CoEncadrantService $coEncadrantService * @var TheseService $theseService */ $coEncadrantService = $container->get(CoEncadrantService::class); $theseService = $container->get('TheseService'); /** * @var RechercherCoEncadrantForm $rechercheCoEncadrantForm */ $rechercheCoEncadrantForm = $container->get('FormElementManager')->get(RechercherCoEncadrantForm::class); $controller = new CoEncadrantController(); $controller->setCoEncadrantService($coEncadrantService); $controller->setTheseService($theseService); $controller->setRechercherCoEncadrantForm($rechercheCoEncadrantForm); return $controller; } Loading
module/Application/src/Application/Entity/Db/Repository/TheseRepository.php +21 −0 Changes for module/Application/src/Application/Entity/Db/Repository/TheseRepository.php: 21 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -214,6 +214,27 @@ class TheseRepository extends DefaultEntityRepository return $result; } /** * @param Individu $individu * @return These[] */ public function fetchThesesByCoEncadrant($individu) { $qb = $this->createQueryBuilder('t') ->join('t.acteurs', 'a') ->join('a.role', 'r') ->andWhere('r.code = :coencadrant') ->setParameter('coencadrant', Role::CODE_CO_ENCADRANT) ->andWhere('a.individu = :individu') ->setParameter('individu', $individu) ->andWhere('1 = pasHistorise(t)') ->orderBy('t.datePremiereInscription', 'ASC') ; $result = $qb->getQuery()->getResult(); return $result; } } No newline at end of file
module/Application/src/Application/Service/CoEncadrant/CoEncadrantService.php 0 → 100644 +71 −0 Changes for module/Application/src/Application/Service/CoEncadrant/CoEncadrantService.php: 71 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Application\Service\CoEncadrant; use Application\Entity\Db\Acteur; use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\QueryBuilder; use UnicaenApp\Exception\RuntimeException; use UnicaenApp\Service\EntityManagerAwareTrait; use Zend\Mvc\Controller\AbstractActionController; class CoEncadrantService { use EntityManagerAwareTrait; /** * @return QueryBuilder */ public function createQueryBuilder() { $qb = $this->getEntityManager()->getRepository(Acteur::class)->createQueryBuilder('acteur') ->addSelect('individu')->join('acteur.individu', 'individu') ->addSelect('role')->join('acteur.role', 'role') ->andWhere('role.code = :code') ->setParameter('code', 'B') ; return $qb; } /** * @param string $term * @return Acteur[] */ public function findByText(string $term) { $qb = $this->createQueryBuilder() ->andWhere("LOWER(concat(concat(concat(concat(individu.prenom1, ' '),individu.nomUsuel), ' '), individu.prenom1)) like :term") ->setParameter('term', '%'.strtolower($term).'%') ; $result = $qb->getQuery()->getResult(); return $result; } /** * @param int $id * @return Acteur */ public function getCoEncadrant(int $id) { $qb = $this->createQueryBuilder() ->andWhere('acteur.id = :id') ->setParameter('id', $id) ; try { $result = $qb->getQuery()->getOneOrNullResult(); } catch (NonUniqueResultException $e) { throw new RuntimeException("Plusieurs Acteur partagent le même id [".$id."]."); } return $result; } /** * @param AbstractActionController $controller * @param string $param * @return Acteur */ public function getRequestedCoEncadrant(AbstractActionController $controller, string $param = 'co-encadrant') { $id = $controller->params()->fromRoute($param); $result = $this->getCoEncadrant($id); return $result; } } No newline at end of file