Commit 71356749 authored by Laurent's avatar Laurent

Merge branch 'hotline#109386_formations_export_ajouter_bib_de_l_usager' into 'hotline'

hotline #109386 : add mail and library in trainees export

See merge request !3574
parents 63e38bac 01814a9c
Pipeline #10649 passed with stage
in 46 minutes and 44 seconds
- ticket #109386 : Administration : Activités : Ajout de l'email et de la bibliothèque dans l'export CSV des participants
\ No newline at end of file
......@@ -43,74 +43,80 @@ class Admin_SessionActivityController extends ZendAfi_Controller_Action {
public function inscriptionsAction() {
$session = Class_SessionActivity::getLoader()->find((int)$this->_getParam('id'));
if ($id_user_to_delete = $this->_getParam('delete')) {
$subscription_to_delete = Class_SessionActivityInscription::deleteBy(['stagiaire_id' => $id_user_to_delete,
'session_activity_id' => $session->getId()]);
$redirect_url = '/admin/session-activity/inscriptions/id/'.$session->getId();
if ($_GET)
$redirect_url .= '?'.http_build_query($_GET);
$session = Class_SessionActivity::find((int)$this->_getParam('id'));
$this->_redirect($redirect_url);
return;
}
if ($id_user = $this->_getParam('delete'))
return $this->_inscriptionsDelete($id_user, $session);
if ($this->_request->isPost()
&& ($ids_users_to_subscribe = $this->_request->getPost('users'))) {
foreach($ids_users_to_subscribe as $id)
$session->addStagiaire(Class_Users::getLoader()->find($id));
$session->save();
}
if ($id_users = $this->_request->getPost('users'))
$this->_inscriptionsSubscribe($id_users, $session);
$this->view->session = $session;
$this->view->page = $this->_request->getParam('page');
$this->view->page = $this->_getParam('page');
$this->view->search = $this->_getParam('search');
$this->view->titre = sprintf(
'Liste des participants à la session du %s de l\'activité "%s"',
$this->view->humanDate($session->getDateDebut(), 'd MMMM YYYY'),
$session->getActivity()->getLibelle());
$this->view->titre = $this->_('Liste des participants à la session du %s de l\'activité "%s"',
$this->view->humanDate($session->getDateDebut(), 'd MMMM YYYY'),
$session->getActivity()->getLibelle());
}
protected function _inscriptionsDelete($id_user, $session) {
Class_SessionActivityInscription::deleteBy(['stagiaire_id' => $id_user,
'session_activity_id' => $session->getId()]);
$redirect_url = '/admin/session-activity/inscriptions/id/' . $session->getId();
if ($_GET)
$redirect_url .= '?'.http_build_query($_GET);
$this->_redirect($redirect_url);
}
protected function _inscriptionsSubscribe($id_users, $session) {
if (!$id_users)
return;
foreach($id_users as $id)
$session->addStagiaire(Class_Users::find($id));
$session->save();
}
public function exportinscriptionsAction() {
$session = Class_SessionActivity::getLoader()->find((int)$this->_getParam('id'));
$this->_helper->getHelper('ViewRenderer')->setNoRender(true);
// on va devoir modifier les entetes HTTP
$response = Zend_Controller_Front::getInstance()->getResponse();
$response->canSendHeaders(true);
$response->setHeader('Content-Type',
'text/csv;charset=utf-8',
// sprintf('text/csv; name="session_%d.csv"', $session->getId()),
true);
$response->setHeader('Content-Disposition',
sprintf('attachment; filename="session_%d.csv"', $session->getId()),
true);
$content = sprintf("Activité;%s;\n".
"Session;%s;\n".
"Durée;%dh;\n".
"Effectif;%d-%d;\n",
$session->getLibelleActivity(),
$this->view->humanDate($session->getDateDebut(), 'd MMMM YYYY'),
$session->getDuree(),
$session->getEffectifMin(),
$session->getEffectifMax());
$content .= sprintf("\nNom;Prénom;Identifiant\n");
foreach ($session->getStagiairesSortedByNom() as $stagiaire) {
$content .= sprintf("%s;%s;%s\n",
$stagiaire->getNom(),
$stagiaire->getPrenom(),
$stagiaire->getLogin());
if (!$session = Class_SessionActivity::find((int)$this->_getParam('id'))) {
$this->_redirectToIndex();
return;
}
$response->setBody($content);
$description = (new Class_TableDescription(''))
->addColumn('', 'label')
->addColumn('', 'value')
;
$content = $this->view
->renderCsv($description,
[new Class_Entity(['Label' => $this->_('Activité'),
'Value' => $session->getLibelleActivity()]),
new Class_Entity(['Label' => $this->_('Session'),
'Value' => $this->view->humanDate($session->getDateDebut(),
'd MMMM YYYY')]),
new Class_Entity(['Label' => $this->_('Durée'),
'Value' => $session->getDuree() . 'h']),
new Class_Entity(['Label' => $this->_('Effectif'),
'Value' => $session->getEffectifMin()
. '-' . $session->getEffectifMax()])]);
$description = (new Class_TableDescription(''))
->addColumn($this->_('Nom'), 'nom')
->addColumn($this->_('Prénom'), 'prenom')
->addColumn($this->_('Identifiant'), 'login')
->addColumn($this->_('Mail'), 'mail')
->addColumn($this->_('Bibliothèque'), 'libelle_bib')
;
$content .= "\n" . $this->view->renderCsv($description, $session->getStagiairesSortedByNom());
$this->_helper->csv(sprintf('session_%d.csv', $session->getId()),
$content);
}
......@@ -123,47 +129,46 @@ class Admin_SessionActivityController extends ZendAfi_Controller_Action {
}
$this->view->titre = $this->_('Impressions pour la session du %s de l\'activité "%s"',
$this->view->humanDate($session->getDateDebut(), 'd MMMM YYYY'),
$session->getLibelleActivity());
$this->view->humanDate($session->getDateDebut(), 'd MMMM YYYY'),
$session->getLibelleActivity());
$this->view->session = $session;
$this->view->impressions = array(
'Liste des stagiaires' => array('action' => 'liste_stagiaires',
'form' => $this->_modeleFusionForm('ACTIVITY_LISTE_STAGIAIRES',
$session)),
$this->view->impressions =
[
'Liste des stagiaires' => ['action' => 'liste_stagiaires',
'form' => $this->_modeleFusionForm('ACTIVITY_LISTE_STAGIAIRES',
$session)],
'Fiche d\'émargement' => ['action' => 'fiche_emargement',
'form' => $this->_modeleFusionForm('ACTIVITY_EMARGEMENT', $session)],
'Fiche d\'émargement' => array('action' => 'fiche_emargement',
'form' => $this->_modeleFusionForm('ACTIVITY_EMARGEMENT',
$session)),
'Convocations' => array('action' => 'convocations',
'form' => $this->_modeleFusionForm('ACTIVITY_CONVOCATION',
$session)),
'Convocations' => ['action' => 'convocations',
'form' => $this->_modeleFusionForm('ACTIVITY_CONVOCATION', $session)],
'Attestations' => array('action' => 'attestations',
'form' => $this->_modeleFusionForm('ACTIVITY_ATTESTATION',
$session)),
'Attestations' => ['action' => 'attestations',
'form' => $this->_modeleFusionForm('ACTIVITY_ATTESTATION', $session)],
'Refus' => array('action' => 'refus',
'form' => $this->_modeleFusionForm('ACTIVITY_REFUS',
$session)));
'Refus' => ['action' => 'refus',
'form' => $this->_modeleFusionForm('ACTIVITY_REFUS', $session)]
];
}
protected function _modeleFusionForm($modele_fusion_name, $session) {
$modele_fusion = Class_ModeleFusion::get($modele_fusion_name);
return $this->view
->newForm(array('id' => $modele_fusion->getNom().'_FORM'))
->newForm(['id' => $modele_fusion->getNom().'_FORM'])
->setMethod('post')
->setAction($this->view->url(array('action' => 'modele_impression',
'id' => $modele_fusion->getId(),
'session_id' => $session->getId())))
->setAction($this->view->url(['action' => 'modele_impression',
'id' => $modele_fusion->getId(),
'session_id' => $session->getId()]))
->addElement('ckeditor',
$modele_fusion->getNom(),
array(
'label' => '',
'value' => $modele_fusion->getContenu(),
'required' => true,
'allowEmpty' => false));
['label' => '',
'value' => $modele_fusion->getContenu(),
'required' => true,
'allowEmpty' => false]);
}
......@@ -179,31 +184,31 @@ class Admin_SessionActivityController extends ZendAfi_Controller_Action {
public function ficheemargementAction() {
$this->_renderLettreFusion(new SessionOneLetterPerDayFusionStrategy(Class_ModeleFusion::getTrainingTemplateFor('EMARGEMENT')));
$this->_print(new SessionSignIn(Class_ModeleFusion::getTrainingTemplateFor('EMARGEMENT')));
}
public function listestagiairesAction() {
$this->_renderLettreFusion(new SessionFusionStrategy(Class_ModeleFusion::getTrainingTemplateFor('STAGIAIRES')));
$this->_print(new SessionTrainees(Class_ModeleFusion::getTrainingTemplateFor('STAGIAIRES')));
}
public function convocationsAction() {
$this->_renderLettreFusion(new SessionStagiairesFusionStrategy(Class_ModeleFusion::getTrainingTemplateFor('CONVOCATION')));
$this->_print(new SessionSummons(Class_ModeleFusion::getTrainingTemplateFor('CONVOCATION')));
}
public function attestationsAction() {
$this->_renderLettreFusion(new SessionStagiairesPresentsFusionStrategy(Class_ModeleFusion::getTrainingTemplateFor('ATTESTATION')));
$this->_print(new SessionCertificates(Class_ModeleFusion::getTrainingTemplateFor('ATTESTATION')));
}
public function refusAction() {
$this->_renderLettreFusion(new SessionStagiairesFusionStrategy(Class_ModeleFusion::getTrainingTemplateFor('REFUS')));
$this->_print(new SessionSummons(Class_ModeleFusion::getTrainingTemplateFor('REFUS')));
}
public function _renderLettreFusion($fusion_strategy) {
public function _print($fusion_strategy) {
$this->_helper->getHelper('viewRenderer')->setLayoutScript('empty.phtml');
$session_activity = Class_SessionActivity::getLoader()->find($this->_getParam('id'));
......@@ -214,21 +219,22 @@ class Admin_SessionActivityController extends ZendAfi_Controller_Action {
public function showAction() {
$this->_sessionDoAndNotify('show', 'La session "%s" est visible');
}
if (!$session = Class_SessionActivity::find($this->_getParam('id')))
return $this->_redirectToIndex();
public function hideAction() {
$this->_sessionDoAndNotify('hide', 'La session "%s" n\'est plus visible');
$session->show()->save();
$this->_redirectToIndex();
$this->_helper->notify($this->_('La session "%s" est visible', $session->getLibelle()));
}
protected function _sessionDoAndNotify($action, $message) {
$session = Class_SessionActivity::find($this->_getParam('id'));
call_user_func([$session, $action]);
$session->save();
public function hideAction() {
if (!$session = Class_SessionActivity::find($this->_getParam('id')))
return $this->_redirectToIndex();
$session->hide()->save();
$this->_redirectToIndex();
$this->_helper->notify($this->_($message, $session->getLibelle()));
$this->_helper->notify($this->_('La session "%s" n\'est plus visible', $session->getLibelle()));
}
......@@ -265,7 +271,7 @@ class Admin_SessionActivityController extends ZendAfi_Controller_Action {
class AbstractSessionFusionStrategy {
class AbstractSessionFusion {
protected $_modele_fusion;
public function __construct($nom) {
......@@ -274,7 +280,9 @@ class AbstractSessionFusionStrategy {
}
class SessionFusionStrategy extends AbstractSessionFusionStrategy{
class SessionTrainees extends AbstractSessionFusion{
public function getContenuFusionne($session_activity) {
return $this->_modele_fusion
->setDataSource(array("session_activity" => $session_activity,
......@@ -284,7 +292,9 @@ class SessionFusionStrategy extends AbstractSessionFusionStrategy{
}
class SessionOneLetterPerDayFusionStrategy extends AbstractSessionFusionStrategy{
class SessionSignIn extends AbstractSessionFusion{
public function getContenuFusionne($session_activity) {
$date_context = new FusionDateContext($session_activity->getDateDebut());
......@@ -346,7 +356,7 @@ class FusionDateContext {
class SessionStagiairesFusionStrategy extends AbstractSessionFusionStrategy{
class SessionSummons extends AbstractSessionFusion{
protected $_session_activity;
public function getContenuFusionne($session_activity) {
......@@ -373,7 +383,7 @@ class SessionStagiairesFusionStrategy extends AbstractSessionFusionStrategy{
class SessionStagiairesPresentsFusionStrategy extends SessionStagiairesFusionStrategy {
class SessionCertificates extends SessionSummons {
protected function _getStagiaires() {
return $this->_session_activity->getPresentStagiaires();
}
......
......@@ -61,12 +61,16 @@ abstract class Admin_ActivityControllerTestCase extends Admin_AbstractController
'prenom' => 'Benoit',
'user_groups' => [$this->_groupe_stagiaires]]);
$this->fixture('Class_Bib', ['id' => 12, 'libelle' => 'Annecy']);
$this->_patrick = $this->fixture('Class_Users',
['id' => 5,
'id_site' => 12,
'login' => 'Pat',
'password' => '123',
'prenom' => 'Patrick',
'nom' => 'Barroca',
'mail' => 'user@server.org',
'user_groups' => [$this->_groupe_stagiaires]]);
$this->_salle_reunion = $this->fixture('Class_Lieu',
......@@ -1467,7 +1471,7 @@ class Admin_ActivityControllerInscriptionsSessionMarsJavaTest extends Admin_Act
class Admin_ActivityControllerExportInscriptionsSessionMarsJavaTest extends Admin_ActivityControllerTestCase {
class Admin_ActivityControllerExportInscriptionsSessionMarsJavaTest extends Admin_ActivityControllerTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('/admin/session-activity/export_inscriptions/id/32', true);
......@@ -1476,33 +1480,32 @@ class Admin_ActivityControllerExportInscriptionsSessionMarsJavaTest extends Adm
/** @test */
public function responseHeaderShouldHaveContentTypeCSV() {
$this->assertHeaderContains('Content-Type', 'text/csv;charset=utf-8');
$this->assertHeaderContains('Content-Type', 'text/csv; name="session_32.csv"');
}
/** @test */
public function responseHeaderShouldHaveContentDispositionAttachment() {
$this->assertHeaderContains('Content-Disposition',
'attachment; filename="session_32.csv"');
$this->assertHeaderContains('Content-Disposition', 'attachment; filename="session_32.csv"');
}
/** @test */
public function contentShouldContainsPatAndBenoit() {
$this->assertContains("Nom;Prénom;Identifiant\n".
"Anonyme;;n/a\n".
"Barroca;Patrick;Pat\n".
"Curzillat;Benoit;Benoit\n",
$this->assertContains("\n\nNom;Prénom;Identifiant;Mail;Bibliothèque\n".
"Anonyme;;n/a;;\n".
"Barroca;Patrick;Pat;user@server.org;Annecy\n".
"Curzillat;Benoit;Benoit;;\n",
$this->_response->getBody());
}
/** @test */
public function contentShouldContainsDetailSession() {
$this->assertContains("Activité;Learn Java;\n".
"Session;27 mars 2012;\n".
"Durée;8h;\n".
"Effectif;5-25;\n",
$this->assertContains("Activité;\"Learn Java\"\n".
"Session;\"27 mars 2012\"\n".
"Durée;8h\n".
"Effectif;5-25\n",
$this->_response->getBody());
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment