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

Export CSV des services

parent a8f1175c
Branches
Tags
No related merge requests found
......@@ -26,6 +26,15 @@ return array(
),
),
),
'export' => array(
'type' => 'Segment',
'options' => array(
'route' => '/export',
'defaults' => array(
'action' => 'export',
),
),
),
'resume-refresh' => array(
'type' => 'Segment',
'options' => array(
......@@ -174,7 +183,7 @@ return array(
'BjyAuthorize\Guard\Controller' => array(
array(
'controller' => 'Application\Controller\Service',
'action' => array('index', 'saisie', 'suppression', 'voir', 'rafraichir-ligne', 'volumes-horaires-refresh'),
'action' => array('index', 'export', 'saisie', 'suppression', 'voir', 'rafraichir-ligne', 'volumes-horaires-refresh'),
'roles' => [R_ROLE],
), array(
'controller' => 'Application\Controller\Service',
......
......@@ -122,6 +122,112 @@ class ServiceController extends AbstractActionController
return $viewModel;
}
public function exportAction()
{
$service = $this->getServiceService();
$role = $this->getContextProvider()->getSelectedIdentityRole();
$intervenant = $this->context()->intervenantFromRoute();
$typeVolumeHoraire = $this->getServiceTypeVolumehoraire()->getPrevu();
$showMultiplesIntervenants = (! $intervenant) && $this->isAllowed('ServiceController', 'show-multiples-intervenants');
if (! $this->isAllowed($this->getServiceService()->newEntity()->setIntervenant($intervenant), 'read')){
throw new \BjyAuthorize\Exception\UnAuthorizedException();
}
$this->initFilters();
$qb = $service->finderByContext();
$service->leftJoin($this->getServiceElementPedagogique(), $qb, 'elementPedagogique', true);
$this->getServiceElementPedagogique()->leftJoin( 'applicationEtape', $qb, 'etape', true );
$this->getServiceElementPedagogique()->leftJoin( 'applicationPeriode', $qb, 'periode', true);
$service->join( $this->getServiceIntervenant(), $qb, 'intervenant', true);
$volumeHoraireService = $this->getServiceLocator()->get('applicationVolumehoraire'); /* @var $volumeHoraireService \Application\Service\VolumeHoraire */
$service->leftjoin($volumeHoraireService, $qb, 'volumeHoraire', true);
$volumeHoraireService->leftJoin('applicationMotifNonPaiement', $qb, 'motifNonPaiement', true);
$this->getServiceElementPedagogique()->leftJoin('applicationTypeIntervention', $qb, 'typeIntervention', true);
if (! $intervenant){
$intervenant = method_exists($role, 'getIntervenant') ? $role->getIntervenant() : null;
}else{
$service->finderByIntervenant( $intervenant, $qb ); // filtre par intervenant souhaité
$this->getContextProvider()->getLocalContext()->setIntervenant($intervenant);
}
if ($showMultiplesIntervenants){
$this->filtresAction();
$rechercheForm = $this->getServiceLocator()->get('FormElementManager')->get('ServiceRecherche');
/* @var $rechercheForm \Application\Form\Service\Recherche */
$filter = $rechercheForm->hydrateFromSession();
$service->finderByFilterObject($filter, null, $qb);
if($role instanceof \Application\Acl\ComposanteRole){
$service->finderByComposante($role->getStructure(), $qb);
}
}
/* Préparation et affichage */
$services = $service->getList($qb);
$service->setTypeVolumehoraire($services, $typeVolumeHoraire);
$csvModel = new \UnicaenApp\View\Model\CsvModel();
$head = [
'Code Intervenant',
'Intervenant',
'Statut',
'Type',
'Fc. Référentiel',
'Structure d\'affectation',
'Composante d\'enseignement',
'Code formation',
'Formation',
'Code enseignement',
'Enseignement',
];
$typesIntervention = [];
foreach( $services as $service ){
$tis = $service->getVolumeHoraireListe()->getTypesIntervention();
foreach( $tis as $ti ){
if (! isset($typesIntervention[$ti->getId()])){
$typesIntervention[$ti->getId()] = $ti;
}
}
}
usort( $typesIntervention, function($ti1,$ti2){
return $ti1->getOrdre() > $ti2->getOrdre();
} );
foreach( $typesIntervention as $typeIntervention ){
$head[] = $typeIntervention->getCode();
}
$csvModel->setHeader( $head );
foreach( $services as $service ){ /* @var $service \Application\Entity\Db\Service */
$line = [
'code_intervenant' => $service->getIntervenant()->getSourceCode(),
'intervenant' => (string)$service->getIntervenant(),
'statut' => (string)$service->getIntervenant()->getStatut(),
'type' => (string)$service->getIntervenant()->getStatut()->getTypeIntervenant(),
'referentiel' => $this->getServiceLocator()->get('ProcessFormuleHetd')->getServiceReferentiel($service->getIntervenant()),
'str_aff' => (string)$service->getStructureAff(),
'str_ens' => (string)$service->getStructureEns(),
'code_etape' => $service->getElementPedagogique() ? $service->getElementPedagogique()->getEtape()->getSourceCode() : '',
'etape' => $service->getElementPedagogique() ? (string)$service->getElementPedagogique()->getEtape() : '',
'code_element' => $service->getElementPedagogique() ? $service->getElementPedagogique()->getSourceCode() : '',
'element' => $service->getElementPedagogique() ? (string)$service->getElementPedagogique() : '',
];
foreach( $typesIntervention as $typeIntervention ){
$line[$typeIntervention->getCode()] = $service->getVolumeHoraireListe(null, $typeIntervention)->getHeures();
}
$data[$service->getId()] = $line;
$csvModel->addLine($line);
}
$csvModel->setFilename('service.csv');
return $csvModel;
}
/**
* Totaux de services et de référentiel par intervenant.
*
......
......@@ -143,6 +143,21 @@ class VolumeHoraireListe
return $this->typeIntervention;
}
/**
* Retourne la liste des types d'intervention concernés par le service
*/
public function getTypesIntervention()
{
$typesIntervention = [];
$vhs = $this->get();
foreach( $vhs as $vh ){
if (! isset($typesIntervention[$vh->getTypeIntervention()->getId()])){
$typesIntervention[$vh->getTypeIntervention()->getId()] = $vh->getTypeIntervention();
}
}
return $typesIntervention;
}
/**
*
* @param TypeIntervention|boolean $typeIntervention
......
......@@ -40,6 +40,7 @@ class Recherche extends Form implements InputFilterProviderInterface, ServiceLoc
$resumeUrl = $url('service/resume');
$resumeDetailsUrl = $url('service/default', ['action' => 'index']);
$resumeExportUrl = $url('service/export');
$formId = uniqid();
......@@ -111,6 +112,20 @@ class Recherche extends Form implements InputFilterProviderInterface, ServiceLoc
'onclick' => '$("#'.$formId.'").attr("action", "'.$resumeDetailsUrl.'");',
),
));
/**
* Submit
*/
$this->add(array(
'name' => 'submit-export',
'type' => 'Button',
'options' => ['label' => 'Exporter (CSV)'],
'attributes' => array(
'type' => 'submit',
'class' => 'btn btn-default',
'onclick' => '$("#'.$formId.'").attr("action", "'.$resumeExportUrl.'");',
),
));
}
/**
......
......@@ -31,7 +31,11 @@
</div>
<div class="row">
<div class="col-md-4">&nbsp;</div>
<div class="col-md-8"><?php echo $this->formRow($rechercheForm->get('submit-resume')); ?> <?php echo $this->formRow($rechercheForm->get('submit-details')); ?> </div>
<div class="col-md-8">
<?php echo $this->formRow($rechercheForm->get('submit-resume')); ?>
<?php echo $this->formRow($rechercheForm->get('submit-details')); ?>
<?php echo $this->formRow($rechercheForm->get('submit-export')); ?>
</div>
</div>
<?php
echo $this->formHidden( $rechercheForm->get('action')->setValue('afficher') );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment