Skip to content
Snippets Groups Projects
Commit 797984a4 authored by lecluse's avatar lecluse
Browse files

Refactoring services :

 - plus de possibilités de personnalisation de l'état de sortie (possibilité de cacher les colonnes intervenant et structure à la demande)
 - correction de bugs 
 - moins d'appels au Javascript
parent f39521ac
No related branches found
No related tags found
No related merge requests found
......@@ -79,7 +79,9 @@ class ServiceController extends AbstractActionController
$services = array();
}
$viewModel->setVariables(compact('annee', 'services', 'typeVolumeHoraire','action', 'role', 'title', 'intervenant'));
$renderReferentiel = !$role instanceof IntervenantExterieurRole && !$intervenant instanceof IntervenantExterieur;
$viewModel->setVariables(compact('annee', 'services', 'typeVolumeHoraire','action', 'role', 'title', 'intervenant', 'renderReferentiel'));
if ($totaux){
$viewModel->setTemplate('application/service/rafraichir-totaux');
}else{
......@@ -212,10 +214,23 @@ class ServiceController extends AbstractActionController
$service = $this->context()->serviceFromRoute();
$typeVolumeHoraire = $this->context()->typeVolumeHoraireFromRoute();
$service->setTypeVolumeHoraire($typeVolumeHoraire);
$details = 1 == (int)$this->params()->fromQuery('details', (int)$this->params()->fromPost('details',0));
$renderIntervenants = 1 == (int)$this->params()->fromQuery('render-intervenants', (int)$this->params()->fromPost('render-intervenants',0));
$onlyContent = 1 == (int)$this->params()->fromQuery('only-content', 0);
return compact('service', 'typeVolumeHoraire', 'details', 'onlyContent', 'renderIntervenants');
$intervenant = $this->params()->fromQuery('intervenant');
if ('false' === $intervenant) $intervenant = false;
if ('true' === $intervenant) $intervenant = true;
if ('' === $intervenant) $intervenant = null;
$intervenant = $this->getServiceLocator()->get('applicationIntervenant')->get((int)$intervenant);
$structure = $this->params()->fromQuery('structure');
if ('false' === $structure) $structure = false;
if ('true' === $structure) $structure = true;
if ('' === $structure) $structure = null;
$structure = $this->getServiceLocator()->get('applicationStructure')->get((int)$structure);
return compact('service', 'typeVolumeHoraire', 'details', 'onlyContent', 'intervenant', 'structure');
}
public function suppressionAction()
......
......@@ -9,6 +9,8 @@ use Zend\ServiceManager\ServiceLocatorAwareTrait;
use Application\Service\ContextProviderAwareInterface;
use Application\Service\ContextProviderAwareTrait;
use Application\Entity\Db\TypeVolumeHoraire;
use Application\Entity\Db\Intervenant;
use Application\Entity\Db\Structure;
/**
* Aide de vue permettant d'afficher une ligne de service
......@@ -28,22 +30,93 @@ class Ligne extends AbstractHelper implements ServiceLocatorAwareInterface, Cont
/**
* description
*
* @var boolean
* @var Intervenant|boolean
*/
protected $renderIntervenants = true;
protected $intervenant;
/**
* description
*
* @var Structure|boolean
*/
protected $structure;
public function getRenderIntervenants()
/**
*
* @return Intervenant|boolean
*/
public function getIntervenant()
{
return $this->renderIntervenants;
return $this->intervenant;
}
public function setRenderIntervenants($renderIntervenants)
/**
*
* @param Intervenant $intervenant
* @return self
*/
public function setIntervenant( $intervenant)
{
$this->renderIntervenants = $renderIntervenants;
if (is_bool($intervenant) || $intervenant === null || $intervenant instanceof Intervenant){
$this->intervenant = $intervenant;
}else{
throw new \Common\Exception\LogicException('La valeur transmise pour Intervenant n\'est pas correcte');
}
return $this;
}
/**
*
* @return boolean
*/
protected function mustRenderIntervenant()
{
return $this->intervenant === null || $this->intervenant === false;
}
/**
*
* @return Structure|boolean
*/
public function getStructure()
{
return $this->structure;
}
/**
*
* @param Structure $structure
* @return self
*/
public function setStructure( $structure )
{
if (is_bool($structure) || $structure === null || $structure instanceof Structure){
$this->structure = $structure;
}else{
throw new \Common\Exception\LogicException('La valeur transmise pour Structure n\'est pas correcte');
}
return $this;
}
/**
*
* @return boolean
*/
protected function mustRenderStructure()
{
return $this->structure === null || $this->structure === false;
}
protected function toQuery($param)
{
if (null === $param) return null;
elseif (false === $param) return 'false';
elseif( true === $param) return 'true';
elseif(method_exists($param, 'getId')) return $param->getId();
else throw new \Common\Exception\LogicException('Le paramètre n\'est pas du bon type');
}
/**
* Helper entry point.
*
......@@ -82,7 +155,8 @@ class Ligne extends AbstractHelper implements ServiceLocatorAwareInterface, Cont
],
['query' => [
'only-content' => 1,
'render-intervenants' => $this->getRenderIntervenants(),
'intervenant' => $this->toQuery($this->getIntervenant()),
'structure' => $this->toQuery($this->getStructure()),
]]);
return $url;
}
......@@ -108,27 +182,33 @@ class Ligne extends AbstractHelper implements ServiceLocatorAwareInterface, Cont
}
$out = '';
if ($this->getRenderIntervenants()) {
if ($this->mustRenderIntervenant()) {
$out .= '<td>'.$this->renderIntervenant($this->service->getIntervenant()).'</td>';
if ($this->service->getIntervenant() instanceof Application\Entity\Db\IntervenantExterieur){
if ($this->service->getIntervenant() instanceof \Application\Entity\Db\IntervenantPermanent){
$out .= '<td>'.$this->renderStructure( $this->service->getStructureAff() )."</td>\n";
}
else {
} else {
$out .= "<td>&nbsp;</td>\n";
}
}
if ($this->service->getEtablissement() === $context->getEtablissement()) {
if ($this->mustRenderStructure()){
$out .= '<td>'.$this->renderStructure($this->service->getStructureEns())."</td>\n";
}
$out .= '<td>'.$this->renderEtape($this->service->getElementPedagogique()->getEtape())."</td>\n";
$out .= '<td>'.$this->renderElementPedagogique($this->service->getElementPedagogique())."</td>\n";
if ($role instanceof \Application\Acl\ComposanteDbRole) {
$out .= '<td>'.$this->renderFOAD($this->service->getElementPedagogique())."</td>\n";
$out .= '<td>'.$this->renderRegimeInscription($this->service->getElementPedagogique())."</td>\n";
}
}else{
$colspan = 2;
if ($this->mustRenderStructure()){
$colspan++;
}
if ($role instanceof \Application\Acl\ComposanteDbRole) {
$colspan += 2;
}
else {
$colspan = $role instanceof \Application\Acl\ComposanteDbRole ? 5 : 3;
$out .= '<td colspan="'.$colspan.'">'.$this->renderEtablissement( $this->service->getEtablissement() )."</td>\n";
}
if (!$context->getAnnee()) {
......@@ -146,7 +226,7 @@ class Ligne extends AbstractHelper implements ServiceLocatorAwareInterface, Cont
protected function renderIntervenant($intervenant)
{
$pourl = $this->getView()->url('intervenant/default', array('action' => 'voir', 'intervenant' => $intervenant->getId()));
$pourl = $this->getView()->url('intervenant/default', array('action' => 'voir', 'intervenant' => $intervenant->getSourceCode()));
$out = '<a href="'.$pourl.'" data-po-href="'.$pourl.'" class="ajax-modal services">'.$intervenant.'</a>';
return $out;
}
......
......@@ -2,20 +2,21 @@
namespace Application\View\Helper\Service;
use Zend\View\Helper\AbstractHelper;
use Zend\View\Helper\AbstractHtmlElement;
use Application\Entity\Db\Service;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorAwareTrait;
use Application\Service\ContextProviderAwareInterface;
use Application\Service\ContextProviderAwareTrait;
use Application\Entity\Db\Intervenant;
use Application\Entity\Db\Structure;
/**
* Aide de vue permettant d'afficher une liste de services
*
* @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
*/
class Liste extends AbstractHelper implements ServiceLocatorAwareInterface, ContextProviderAwareInterface
class Liste extends AbstractHtmlElement implements ServiceLocatorAwareInterface, ContextProviderAwareInterface
{
use ServiceLocatorAwareTrait;
use ContextProviderAwareTrait;
......@@ -23,10 +24,17 @@ class Liste extends AbstractHelper implements ServiceLocatorAwareInterface, Cont
/**
* description
*
* @var Intervenant
* @var Intervenant|boolean
*/
protected $intervenant;
/**
* description
*
* @var Structure|boolean
*/
protected $structure;
/**
*
* @var typeVolumeHoraire
......@@ -36,7 +44,7 @@ class Liste extends AbstractHelper implements ServiceLocatorAwareInterface, Cont
/**
*
* @return Intervenant
* @return Intervenant|boolean
*/
public function getIntervenant()
{
......@@ -48,12 +56,58 @@ class Liste extends AbstractHelper implements ServiceLocatorAwareInterface, Cont
* @param Intervenant $intervenant
* @return self
*/
public function setIntervenant( Intervenant $intervenant)
public function setIntervenant( $intervenant)
{
if (is_bool($intervenant) || $intervenant === null || $intervenant instanceof Intervenant){
$this->intervenant = $intervenant;
}else{
throw new \Common\Exception\LogicException('La valeur transmise pour Intervenant n\'est pas correcte');
}
return $this;
}
/**
*
* @return boolean
*/
protected function mustRenderIntervenant()
{
return $this->intervenant === null || $this->intervenant === false;
}
/**
*
* @return Structure|boolean
*/
public function getStructure()
{
return $this->structure;
}
/**
*
* @param Structure $structure
* @return self
*/
public function setStructure( $structure )
{
if (is_bool($structure) || $structure === null || $structure instanceof Structure){
$this->structure = $structure;
}else{
throw new \Common\Exception\LogicException('La valeur transmise pour Structure n\'est pas correcte');
}
return $this;
}
/**
*
* @return boolean
*/
protected function mustRenderStructure()
{
return $this->structure === null || $this->structure === false;
}
/**
*
* @param \Application\Entity\Db\TypeVolumeHoraire $typeVolumeHoraire
......@@ -76,6 +130,15 @@ class Liste extends AbstractHelper implements ServiceLocatorAwareInterface, Cont
return $this->typeVolumeHoraire;
}
protected function toQuery($param)
{
if (null === $param) return null;
elseif (false === $param) return 'false';
elseif( true === $param) return 'true';
elseif(method_exists($param, 'getId')) return $param->getId();
else throw new \Common\Exception\LogicException('Le paramètre n\'est pas du bon type');
}
/**
* Helper entry point.
*
......@@ -114,17 +177,28 @@ class Liste extends AbstractHelper implements ServiceLocatorAwareInterface, Cont
$role = $this->getContextProvider()->getSelectedIdentityRole();
$typesIntervention = $this->getServiceLocator()->getServiceLocator()->get('ApplicationTypeIntervention')->getTypesIntervention();
$colspan = 4;
$colspan = 3;
$out = $this->renderShowHide();
$out .= '<table id="services" class="table table-bordered service">';
$attribs = $this->htmlAttribs([
'id' => 'services',
'class' => 'table table-bordered service',
'data-intervenant' => $this->toQuery( $this->getIntervenant() ),
'data-structure' => $this->toQuery( $this->getStructure() ),
'data-type-volume-horaire' => $this->getTypeVolumeHoraire()->getId(),
]);
$out .= '<table '.$attribs.'>';
$out .= '<tr>';
if (! $this->getIntervenant()) {
if ($this->mustRenderIntervenant()) {
$out .= "<th>Intervenant</th>\n";
$out .= "<th title=\"Structure d'appartenance de l'intervenant\">Structure d'affectation</th>\n";
$colspan += 2;
}
if ($this->mustRenderStructure()){
$out .= "<th title=\"Structure gestionnaire de l'enseignement\">Composante d'enseignement</th>\n";
$colspan++;
}
$out .= "<th title=\"Formation\">Formation</th>\n";
$out .= "<th title=\">Enseignement\">Enseignement</th>\n";
if ($role instanceof \Application\Acl\ComposanteDbRole) {
......@@ -153,8 +227,7 @@ class Liste extends AbstractHelper implements ServiceLocatorAwareInterface, Cont
$out .= '</table>'."\n";
$out .= $this->renderShowHide();
$out .= '<script type="text/javascript">';
$out .= '$(function() { Service.init("'.$this->getTypeVolumeHoraire()->getId().'");
Service.setRenderIntervenants('.(! $this->getIntervenant() ? 'true' : 'false').')});';
$out .= '$(function() { Service.init(); });';
$out .= '</script>';
return $out;
}
......@@ -165,7 +238,11 @@ class Liste extends AbstractHelper implements ServiceLocatorAwareInterface, Cont
throw new \Common\Exception\LogicException('Le type de volume horaire du service ne correspond pas à celui de la liste');
}
$ligneView = $this->getView()->serviceLigne( $service )->setRenderIntervenants(! $this->getIntervenant());
$ligneView = $this
->getView()
->serviceLigne( $service )
->setIntervenant($this->getIntervenant())
->setStructure($this->getStructure());
$vhlView = $this->getView()->volumeHoraireListe( $service->getVolumeHoraireListe() );
$out = '<tr id="service-'.$service->getId().'-ligne" data-url="'.$ligneView->getRefreshUrl().'">';
......@@ -195,7 +272,7 @@ class Liste extends AbstractHelper implements ServiceLocatorAwareInterface, Cont
}
}
if ($this->getIntervenant()){
if ($this->getIntervenant() instanceof Intervenant){
$data['total_paye'] = $this->getFormuleHetd()->getServiceTotal($this->getIntervenant());
$data['total_hetd'] = $this->getFormuleHetd()->getHetd($this->getIntervenant());
// $data['total_compl'] = $this->getFormuleHetd()->getHeuresComplementaires($this->getIntervenant());
......@@ -208,9 +285,10 @@ class Liste extends AbstractHelper implements ServiceLocatorAwareInterface, Cont
$context = $this->getContextProvider()->getGlobalContext();
$role = $this->getContextProvider()->getSelectedIdentityRole();
$typesIntervention = $this->getServiceLocator()->getServiceLocator()->get('ApplicationTypeIntervention')->getTypesIntervention();
$colspan = 3;
$colspan = 2;
if (! $this->getIntervenant()) $colspan += 2;
if ($this->mustRenderIntervenant()) $colspan += 2;
if ($this->mustRenderStructure()) $colspan++;
if ($role instanceof \Application\Acl\ComposanteDbRole) $colspan += 2;
if (!$context->getAnnee()) $colspan += 1;
......@@ -219,15 +297,13 @@ class Liste extends AbstractHelper implements ServiceLocatorAwareInterface, Cont
$out = '<tr>';
$out .= "<th colspan='$colspan' style=\"text-align:right\">Totaux par type d'intervention :</th>\n";
foreach( $typesIntervention as $ti ){
$colspan++;
$out .= "<td id=\"".$ti->getCode()."\" style=\"text-align:right\">".\UnicaenApp\Util::formattedFloat($data[$ti->getCode()], \NumberFormatter::DECIMAL, -1)."</td>\n";
}
$colspan--;
$out .= "<td colspan='3'>&nbsp;</td>\n";
$out .= "</tr>\n";
$out .= '<tr>';
$out .= "<th colspan=\"$colspan\" style=\"text-align:right\">Total des heures de service :</th>\n";
$out .= "<td style=\"text-align:right\">".\UnicaenApp\Util::formattedFloat($data['total_general'], \NumberFormatter::DECIMAL, -1)."</td>\n";
$out .= "<td style=\"text-align:right\" colspan=\"".count($typesIntervention)."\">".\UnicaenApp\Util::formattedFloat($data['total_general'], \NumberFormatter::DECIMAL, -1)."</td>\n";
$out .= "<td colspan='3'>&nbsp;</td>\n";
$out .= "</tr>\n";
$title = [
......@@ -240,9 +316,9 @@ class Liste extends AbstractHelper implements ServiceLocatorAwareInterface, Cont
$out .= '<tr>';
$out .= "<th colspan=\"$colspan\" style=\"text-align:right\">Total Heures &Eacute;quivalent TD :</th>\n";
if (! empty($title)){
$out .= "<td style=\"text-align:right\"><abbr title=\"".implode(",\n",$title).".\">".\UnicaenApp\Util::formattedFloat($data['total_hetd'], \NumberFormatter::DECIMAL, -1)."</abbr></td>\n";
$out .= "<td style=\"text-align:right\" colspan=\"".count($typesIntervention)."\"><abbr title=\"".implode(",\n",$title).".\">".\UnicaenApp\Util::formattedFloat($data['total_hetd'], \NumberFormatter::DECIMAL, -1)."</abbr></td>\n";
}else{
$out .= "<td style=\"text-align:right\">".\UnicaenApp\Util::formattedFloat($data['total_hetd'], \NumberFormatter::DECIMAL, -1)."</td>\n";
$out .= "<td style=\"text-align:right\" colspan=\"".count($typesIntervention)."\">".\UnicaenApp\Util::formattedFloat($data['total_hetd'], \NumberFormatter::DECIMAL, -1)."</td>\n";
}
$out .= "<td colspan='3'>&nbsp;</td>\n";
$out .= "</tr>\n";
......
<?php
if ($onlyContent){
echo $this->serviceLigne( $service )->setRenderIntervenants($renderIntervenants)->render($details);
echo $this->serviceLigne( $service )
->setIntervenant($intervenant)
->setStructure($structure)
->render($details);
}else{
echo $this->serviceListe( array($service) )->setRenderIntervenants($renderIntervenants)->renderLigne( $service, $details );
echo $this->serviceListe( array($service) )
->setIntervenant($intervenant)
->setStructure($structure)
->renderLigne( $service, $details );
}
\ No newline at end of file
......@@ -53,14 +53,6 @@ function Service( id ) {
this.id = id;
this.delete = function( url ){
ok = window.confirm('Voulez-vous vraiment supprimer ce service ?');
if (ok){
$('#service-div').modal({remote: url});
}
return false;
}
this.showHideDetails = function( serviceA ){
var state = $.data(serviceA,'state');
......@@ -107,17 +99,15 @@ function Service( id ) {
}
this.onAfterAdd = function(){
var url = Url("service/rafraichir-ligne/"+this.id+"/"+Service.typeVolumeHoraireId, {
var url = Url("service/rafraichir-ligne/"+this.id+"/"+$("#services").data('type-volume-horaire'), {
'only-content' : 0,
'details' : 1,
'render-intervenants': Service.getRenderIntervenants()
'intervenant' : $("#services").data('intervenant'),
'structure' : $("#services").data('structure')
});
$.get( url, function( data ) {
$( "#service-"+this.id+"-ligne" ).refresh();
$( "#service-"+this.id+"-volume-horaire-td" ).refresh();
$( "#service-resume" ).refresh(); // Si on est dans le résumé
$('#services > tbody:last').append(data);
console.log(data);
Service.refreshFiltres();
Service.refreshTotaux();
Service.refreshWorkflowNavigation();
......@@ -149,9 +139,7 @@ Service.get = function( id ){
return Service.services[id];
}
Service.init = function( typeVolumeHoraireId ){
Service.typeVolumeHoraireId = typeVolumeHoraireId;
Service.renderIntervenants = 1; // par défaut
Service.init = function(){
$("body").on("service-modify-message", function(event, data) {
var id = null;
......@@ -169,15 +157,6 @@ Service.init = function( typeVolumeHoraireId ){
}
});
// $('#service-div').on('loaded.bs.modal', function (e) {
// if (id = $('#service-deleted-id').val()){
// var terminated = $("form .input-error, form .has-error, div.alert", $(e.target)).length ? false : true;
// if (terminated){
// Service.get(id).onAfterDelete();
// }
// }
// });
$("body").on("service-add-message", function(event, data) {
var id = null;
if ($("div .messenger, div .alert", event.div).length ? false : true){
......@@ -213,10 +192,6 @@ Service.init = function( typeVolumeHoraireId ){
$(".service-show-all-details").on('click', function(){ Service.showAllDetails(); });
$(".service-hide-all-details").on('click', function(){ Service.hideAllDetails(); });
// $('body').on('click', '.service-delete', function(){
// Service.get( $(this).data('id') ).delete( $(this).attr('href') );
// return false;
// });
VolumeHoraire.init();
}
......@@ -243,14 +218,6 @@ Service.refreshTotaux = function(){
$("#services tfoot").refresh();
}
Service.setRenderIntervenants = function( renderIntervenants ){
Service.renderIntervenants = renderIntervenants;
}
Service.getRenderIntervenants = function(){
return Service.renderIntervenants;
}
/**
* Mise à jour de la div affichant le bouton pointant vers l'étape suivante (workflow).
* @returns void
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment