Skip to content
Snippets Groups Projects
Commit 40aa4a9e authored by lecluse's avatar lecluse
Browse files

Recherche et affichage de structures et d'établissements

parent 80c514aa
No related branches found
No related tags found
No related merge requests found
Showing
with 704 additions and 13 deletions
......@@ -87,6 +87,8 @@ class Module implements ControllerPluginProviderInterface, ViewHelperProviderInt
),
'factories' => array(
'intervenant' => 'Application\Controller\Plugin\IntervenantFactory',
'structure' => 'Application\Controller\Plugin\StructureFactory',
'etablissement' => 'Application\Controller\Plugin\EtablissementFactory',
'serviceReferentiel' => 'Application\Controller\Plugin\ServiceReferentielFactory',
),
);
......@@ -107,6 +109,7 @@ class Module implements ControllerPluginProviderInterface, ViewHelperProviderInt
'invokables' => array(
'intervenantDl' => 'Application\View\Helper\IntervenantDl',
'structureDl' => 'Application\View\Helper\StructureDl',
'etablissementDl' => 'Application\View\Helper\EtablissementDl',
'adresseDl' => 'Application\View\Helper\AdresseDl',
'historiqueDl' => 'Application\View\Helper\HistoriqueDl',
),
......
<?php
namespace Application;
return array(
'router' => array(
'routes' => array(
'etablissement' => array(
'type' => 'Literal',
'options' => array(
'route' => '/etablissement',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'etablissement',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'modifier' => array(
'type' => 'Segment',
'options' => array(
'route' => '/modifier/:id',
'constraints' => array(
'id' => '[0-9]*',
),
'defaults' => array(
'action' => 'modifier',
),
),
),
'recherche' => array(
'type' => 'Segment',
'options' => array(
'route' => '/recherche[/:term]',
'defaults' => array(
'action' => 'recherche',
),
),
),
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/:action[/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]*',
),
'defaults' => array(
'action' => 'index',
),
),
),
),
),
),
),
'bjyauthorize' => array(
'guards' => array(
'BjyAuthorize\Guard\Controller' => array(
array(
'controller' => 'Application\Controller\Etablissement',
//'action' => array('index', 'choisir', 'modifier', 'rechercher', 'voir', 'search'),
'roles' => array('user')),
),
),
),
'controllers' => array(
'invokables' => array(
'Application\Controller\Etablissement' => 'Application\Controller\EtablissementController',
),
),
);
......@@ -148,7 +148,8 @@ $main = array(
return array_merge_recursive(
$main,
include 'intervenant.config.php',
// include 'structure.config.php',
include 'structure.config.php',
include 'etablissement.config.php',
include 'demo.config.php',
include 'recherche.config.php'
);
\ No newline at end of file
<?php
namespace Application;
return array(
'router' => array(
'routes' => array(
'structure' => array(
'type' => 'Literal',
'options' => array(
'route' => '/structure',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Structure',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'modifier' => array(
'type' => 'Segment',
'options' => array(
'route' => '/modifier/:id',
'constraints' => array(
'id' => '[0-9]*',
),
'defaults' => array(
'action' => 'modifier',
),
),
),
'recherche' => array(
'type' => 'Segment',
'options' => array(
'route' => '/recherche[/:term]',
'defaults' => array(
'action' => 'recherche',
),
),
),
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/:action[/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]*',
),
'defaults' => array(
'action' => 'index',
),
),
),
),
),
),
),
'bjyauthorize' => array(
'guards' => array(
'BjyAuthorize\Guard\Controller' => array(
array(
'controller' => 'Application\Controller\Structure',
//'action' => array('index', 'choisir', 'modifier', 'rechercher', 'voir', 'search'),
'roles' => array('user')),
),
),
),
'controllers' => array(
'invokables' => array(
'Application\Controller\Structure' => 'Application\Controller\StructureController',
),
),
);
<?php
namespace Application\Controller;
use Zend\Form\Annotation\AnnotationBuilder;
use Zend\Mvc\Controller\AbstractActionController;
use Common\Exception\RuntimeException;
use Common\Exception\LogicException;
use Zend\View\Model\JsonModel;
/**
* Description of EtablissementController
*
* @method \Doctrine\ORM\EntityManager em()
* @method \Application\Controller\Plugin\Etablissement etablissement()
*
* @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
*/
class EtablissementController extends AbstractActionController
{
public function indexAction()
{
$url = $this->url()->fromRoute('etablissement/default', array('action' => 'choisir'));
return $this->redirect()->toUrl($url);
}
/**
*
* @return \Zend\View\Model\ViewModel
*/
public function choisirAction()
{
$url = $this->url()->fromRoute('etablissement/recherche');
$etablissement = new \UnicaenApp\Form\Element\SearchAndSelect('etablissement');
$etablissement->setAutocompleteSource($url)
->setRequired(true)
->setSelectionRequired(true)
->setLabel("Recherchez l'établissement concerné :")
->setAttributes(array('title' => "Saisissez le nom de l'établissement"));
$form = new \Zend\Form\Form('search');
$form->setAttributes(array('class' => 'etablissement-rech'));
$form->add($etablissement);
if ($this->getRequest()->isPost()) {
$data = $this->getRequest()->getPost();
$form->setData($data);
if ($form->isValid()) {
$url = $this->url()->fromRoute('etablissement/default', array('action' => 'voir', 'id' => $form->get('etablissement')->getValueId() ) );
return $this->redirect()->toUrl($url);
}
}
return compact('form');
}
public function rechercheAction()
{
if (!($term = $this->params()->fromQuery('term'))) {
return new JsonModel(array());
}
$repo = $this->etablissement()->getRepo();
$entities = $repo->findByLibelle($term);
$result = array();
foreach ($entities as $item) { /* @var $item \Application\Entity\Db\Etablissement */
$result[] = array(
'id' => $item->getId(), // identifiant unique de l'item
'label' => $item->getLibelle(), // libellé de l'item
'extra' => '( département '.$item->getDepartement().')', // infos complémentaires (facultatives) sur l'item
);
};
return new JsonModel($result);
}
public function voirAction()
{
$this->em()->getFilters()->enable('historique');
if (!($id = $this->params()->fromRoute('id', $this->params()->fromPost('id')))) {
throw new LogicException("Aucun identifiant de l'établissement spécifié.");
}
if (!($etablissement = $this->etablissement()->getRepo()->find($id))) {
throw new RuntimeException("Etablissement '$id' spécifié introuvable.");
}
$import = $this->getServiceLocator()->get('ImportProcessusImport');
$changements = $import->etablissementGetDifferentiel($etablissement);
$view = new \Zend\View\Model\ViewModel();
$view->setVariables(compact('etablissement', 'changements'));
$view->setTerminal($this->getRequest()->isXmlHttpRequest());
return $view;
}
}
\ No newline at end of file
<?php
namespace Application\Controller\Plugin;
use Common\Controller\Plugin\BasePlugin;
/**
* Description of Etablissement
*
* @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
*/
class Etablissement extends BasePlugin
{
public function __invoke()
{
return $this;
}
/**
* Retourne le repository.
*
* @return \Application\Entity\Db\Repository\EtablissementRepository
*/
public function getRepo()
{
return $this->getEntityManager()->getRepository('Application\Entity\Db\Etablissement');
}
}
\ No newline at end of file
<?php
namespace Application\Controller\Plugin;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
/**
* Description of EtablissementFactory
*
* @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
*/
class EtablissementFactory implements FactoryInterface
{
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return mixed
*/
public function createService(ServiceLocatorInterface $serviceLocator) /* @var $serviceLocator \Zend\Mvc\Controller\PluginManager */
{
$em = $serviceLocator->getServiceLocator()->get('doctrine.entitymanager.orm_default');
return new Etablissement($em);
}
}
\ No newline at end of file
<?php
namespace Application\Controller\Plugin;
use Common\Controller\Plugin\BasePlugin;
/**
* Description of Structure
*
* @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
*/
class Structure extends BasePlugin
{
public function __invoke()
{
return $this;
}
/**
* Retourne le repository.
*
* @return \Application\Entity\Db\Repository\StructureRepository
*/
public function getRepo()
{
return $this->getEntityManager()->getRepository('Application\Entity\Db\Structure');
}
}
\ No newline at end of file
<?php
namespace Application\Controller\Plugin;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
/**
* Description of StructureFactory
*
* @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
*/
class StructureFactory implements FactoryInterface
{
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return mixed
*/
public function createService(ServiceLocatorInterface $serviceLocator) /* @var $serviceLocator \Zend\Mvc\Controller\PluginManager */
{
$em = $serviceLocator->getServiceLocator()->get('doctrine.entitymanager.orm_default');
return new Structure($em);
}
}
\ No newline at end of file
<?php
namespace Application\Controller;
use Zend\Form\Annotation\AnnotationBuilder;
use Zend\Mvc\Controller\AbstractActionController;
use Common\Exception\RuntimeException;
use Common\Exception\LogicException;
use Zend\View\Model\JsonModel;
/**
* Description of StructureController
*
* @method \Doctrine\ORM\EntityManager em()
* @method \Application\Controller\Plugin\Structure structure()
*
* @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
*/
class StructureController extends AbstractActionController
{
public function indexAction()
{
$url = $this->url()->fromRoute('structure/default', array('action' => 'choisir'));
return $this->redirect()->toUrl($url);
}
/**
*
* @return \Zend\View\Model\ViewModel
*/
public function choisirAction()
{
$url = $this->url()->fromRoute('structure/recherche');
$structure = new \UnicaenApp\Form\Element\SearchAndSelect('structure');
$structure->setAutocompleteSource($url)
->setRequired(true)
->setSelectionRequired(true)
->setLabel("Recherchez la structure concernée :")
->setAttributes(array('title' => "Saisissez le nom de la structure"));
$form = new \Zend\Form\Form('search');
$form->setAttributes(array('class' => 'structure-rech'));
$form->add($structure);
if ($this->getRequest()->isPost()) {
$data = $this->getRequest()->getPost();
$form->setData($data);
if ($form->isValid()) {
$url = $this->url()->fromRoute('structure/default', array('action' => 'voir', 'id' => $form->get('structure')->getValueId() ) );
return $this->redirect()->toUrl($url);
}
}
return compact('form');
}
public function rechercheAction()
{
if (!($term = $this->params()->fromQuery('term'))) {
return new JsonModel(array());
}
$repo = $this->structure()->getRepo();
$entities = $repo->findByNom($term);
$template = "{label} <small>{extra}</small>";
$result = array();
foreach ($entities as $item) { /* @var $item \Application\Entity\Db\Structure */
$result[] = array(
'id' => $item->getId(), // identifiant unique de l'item
'label' => $item->getLibelleLong(), // libellé de l'item
'extra' => $item->getLibelleCourt(), // infos complémentaires (facultatives) sur l'item
);
};
return new JsonModel($result);
}
public function voirAction()
{
$this->em()->getFilters()->enable('historique');
if (!($id = $this->params()->fromRoute('id', $this->params()->fromPost('id')))) {
throw new LogicException("Aucun identifiant de structure spécifié.");
}
if (!($structure = $this->structure()->getRepo()->find($id))) {
throw new RuntimeException("Structure '$id' spécifiée introuvable.");
}
$import = $this->getServiceLocator()->get('ImportProcessusImport');
$changements = $import->structureGetDifferentiel($structure);
$view = new \Zend\View\Model\ViewModel();
$view->setVariables(compact('structure', 'changements'));
$view->setTerminal($this->getRequest()->isXmlHttpRequest());
return $view;
}
}
\ No newline at end of file
......@@ -388,4 +388,29 @@ class Etablissement implements HistoriqueAwareInterface
{
return $this->histoCreateur;
}
/**************************************************************************************************
* Début ajout
**************************************************************************************************/
/**
* Retourne la représentation littérale de cet objet.
*
* @return string
*/
public function __toString()
{
return $this->getLibelle();
}
/**
* Get source id
*
* @return integer
* @see \Application\Entity\Db\Source
*/
public function getSourceToString()
{
return $this->getSource()->getLibelle();
}
}
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Application\Entity\Db\Etablissement" table="ETABLISSEMENT">
<!-- NB: repository ajouté à la main sur l'entité -->
<entity name="Application\Entity\Db\Etablissement" table="ETABLISSEMENT" repository-class="Application\Entity\Db\Repository\EtablissementRepository">
<indexes>
<index name="IDX_6B15BC959860CDC" columns="HISTO_CREATEUR_ID"/>
<index name="IDX_6B15BC97E9E2204" columns="HISTO_DESTRUCTEUR_ID"/>
......
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Application\Entity\Db\Structure" table="STRUCTURE">
<!-- NB: repository ajouté à la main sur l'entité -->
<entity name="Application\Entity\Db\Structure" table="STRUCTURE" repository-class="Application\Entity\Db\Repository\StructureRepository">
<indexes>
<index name="IDX_2BC32905F1A6E54F" columns="PARENTE_ID"/>
<index name="IDX_2BC32905B3FC6B16" columns="ETABLISSEMENT_ID"/>
......
<?php
namespace Application\Entity\Db\Repository;
use Doctrine\ORM\EntityRepository;
/**
* EtablissementRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*
* @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
*/
class EtablissementRepository extends EntityRepository
{
/**
* Recherche par libellé
*
* @param string $term
* @return \Application\Entity\Db\Etablissement[]
*/
public function findByLibelle($term)
{
$terms = explode( ' ', $term );
$qb = $this->createQueryBuilder('e');
$concatFields = array(
'e.libelle',
'e.departement',
'e.localisation',
);
foreach ($concatFields as $field) {
if (!isset($searchIn)) {
$searchIn = $qb->expr()->concat($qb->expr()->literal(''), $field);
continue;
}
$searchIn = $qb->expr()->concat(
$searchIn,
$qb->expr()->concat($qb->expr()->literal(' '), $field)
);
}
$haystack = new \Doctrine\ORM\Query\Expr\Func( 'CONVERT', array( $searchIn, '?1' ) );
$parameters = array(
1 => 'US7ASCII'
);
$index = 2;
foreach( $terms as $term ){
$parameters[$index] = "%$term%";
$qb->andWhere($qb->expr()->like($qb->expr()->upper($haystack), $qb->expr()->upper("CONVERT(?$index, ?1)")));
$index++;
}
$qb->orderBy('e.libelle');
$qb->setParameters( $parameters );
return $qb->getQuery()->execute();
}
}
\ No newline at end of file
<?php
namespace Application\Entity\Db\Repository;
use Doctrine\ORM\EntityRepository;
/**
* StructureRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*
* @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
*/
class StructureRepository extends EntityRepository
{
/**
* Recherche par nom
*
* @param string $term
* @return \Application\Entity\Db\Structure[]
*/
public function findByNom($term)
{
$term = str_replace(' ', '', $term);
$qb = $this->createQueryBuilder('s');
$libelleLong = new \Doctrine\ORM\Query\Expr\Func('CONVERT', array('s.libelleLong', '?3') );
$libelleCourt = new \Doctrine\ORM\Query\Expr\Func('CONVERT', array('s.libelleCourt', '?3') );
$qb
->where('s.sourceCode = ?1')
->orWhere($qb->expr()->like($qb->expr()->upper($libelleLong), $qb->expr()->upper('CONVERT(?2, ?3)')))
->orWhere($qb->expr()->like($qb->expr()->upper($libelleCourt), $qb->expr()->upper('CONVERT(?2, ?3)')))
->orderBy('s.libelleCourt');
$qb->setParameters(array(1 => $term, 2 => "%$term%", 3 => 'US7ASCII'));
//print_r($qb->getQuery()->getSQL()); var_dump($qb->getQuery()->getParameters());die;
return $qb->getQuery()->execute();
}
}
\ No newline at end of file
<?php
namespace Application\View\Helper;
/**
* Description of EtablissementDl
*
* @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
*/
class EtablissementDl extends AbstractDl
{
/**
*
*
* @return string Code HTML
*/
public function render()
{
if (!$this->entity) {
return '';
}
$entity = $this->entity; /* @var $entity \Application\Entity\Db\Etablissement */
$tplDtdd = $this->getTemplateDtDd();
$html = '';
$dtdds = array();
$dtdds[] = sprintf($tplDtdd,
"Libellé :",
$entity->getLibelle()
);
$dtdds[] = sprintf($tplDtdd,
"Localisation :",
$entity->getLocalisation()
);
$dtdds[] = sprintf($tplDtdd,
"Département :",
$entity->getDepartement()
);
$dtdds[] = sprintf($tplDtdd,
"N° {$entity->getSource()->getLibelle()} :",
$entity->getSourceCode()
);
$dtdds[] = sprintf($tplDtdd,
"Historique :",
$this->getView()->historiqueDl($entity)
);
$html .= sprintf($this->getTemplateDl('etablissement etablissement-details'), implode(PHP_EOL, $dtdds)) . PHP_EOL;
return $html;
}
}
\ No newline at end of file
......@@ -5,7 +5,7 @@ namespace Application\View\Helper;
/**
* Description of StructureDl
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
* @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
*/
class StructureDl extends AbstractDl
{
......@@ -45,11 +45,6 @@ class StructureDl extends AbstractDl
$entity->getSourceCode()
);
$dtdds[] = sprintf($tplDtdd,
"Établissement :",
$entity->getEtablissement()->getLibelle()
);
$dtdds[] = sprintf($tplDtdd,
"Structure mère :",
$entity->getParente()->getLibelleLong()
......
<div class="jumbotron">
<h1>Choisir un établissement</h1>
</div>
<style>
span.sas-highlight { font-weight: bold; }
</style>
<?php $form->prepare(); ?>
<?php echo $this->form()->openTag($form) ?>
<?php echo $this->formControlGroup($form->get('etablissement')); ?>
<input class="btn btn-primary" type="submit" value="Choisir" name="submit">
<?php echo $this->form()->closeTag() ?>
<script>
$(function() {
$(":input").tooltip({ /*placement: 'left'*/ });
});
</script>
\ No newline at end of file
<h1><?php echo $etablissement ?> <small>(<?php echo $etablissement->getDepartement() ?>)</small></h1>
<?php echo $this->etablissementDl($etablissement, true) ?>
<br /><?php foreach( $changements as $changement ) { echo $this->differentielLigne( $changement ); } ?>
<?php echo $this->navigation('navigation')->menuContextuel()->withTarget($etablissement->getId()) ?>
<div class="jumbotron">
<h1>Choisir une structure</h1>
</div>
<style>
span.sas-highlight { font-weight: bold; }
</style>
<?php $form->prepare(); ?>
<?php echo $this->form()->openTag($form) ?>
<?php echo $this->formControlGroup($form->get('structure')); ?>
<input class="btn btn-primary" type="submit" value="Choisir" name="submit">
<?php echo $this->form()->closeTag() ?>
<script>
$(function() {
$(":input").tooltip({ /*placement: 'left'*/ });
});
</script>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment