Liste.php 26 KB
Newer Older
1
2
3
4
<?php

namespace Application\View\Helper\Service;

lecluse's avatar
#3357    
lecluse committed
5
use Application\Entity\Db\Intervenant;
lecluse's avatar
lecluse committed
6
use Application\Processus\Traits\IntervenantProcessusAwareTrait;
7
use Application\Service\Traits\ContextServiceAwareTrait;
8
use Application\Service\Traits\EtatVolumeHoraireServiceAwareTrait;
9
use Application\Service\Traits\IntervenantServiceAwareTrait;
10
use Application\Service\Traits\TypeInterventionServiceAwareTrait;
11
use Application\View\Helper\AbstractViewHelper;
12
use Application\Entity\Db\Service;
13
use Application\Entity\Db\TypeIntervention;
14
use Application\Entity\Db\Traits\TypeVolumeHoraireAwareTrait;
15
use Application\Service\Traits\TypeVolumeHoraireServiceAwareTrait as ServiceTypeVolumeHoraireAwareTrait;
16
17
18
19
20
21

/**
 * Aide de vue permettant d'afficher une liste de services
 *
 * @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
 */
22
class Liste extends AbstractViewHelper
23
{
lecluse's avatar
#3357    
lecluse committed
24
    use TypeVolumeHoraireAwareTrait;
25
    use ContextServiceAwareTrait;
26
    use TypeInterventionServiceAwareTrait;
lecluse's avatar
#3357    
lecluse committed
27
    use ServiceTypeVolumeHoraireAwareTrait;
28
    use EtatVolumeHoraireServiceAwareTrait;
29
    use IntervenantServiceAwareTrait;
lecluse's avatar
lecluse committed
30
    use IntervenantProcessusAwareTrait;
31

32
    /**
lecluse's avatar
#994    
lecluse committed
33
34
     *
     * @var string
35
     */
lecluse's avatar
#994    
lecluse committed
36
    private $id;
37
38

    /**
lecluse's avatar
lecluse committed
39
     *
lecluse's avatar
#994    
lecluse committed
40
     * @var array
41
     */
lecluse's avatar
#994    
lecluse committed
42
    private $totaux;
43

44
45
    /**
     *
lecluse's avatar
#994    
lecluse committed
46
     * @var array
47
     */
lecluse's avatar
#994    
lecluse committed
48
    private $typesInterventionVisibility = [];
49

50
51
52
53
    /**
     *
     * @var boolean
     */
lecluse's avatar
#994    
lecluse committed
54
    private $addButtonVisibility;
55

56
57
58
59
    /**
     *
     * @var array
     */
lecluse's avatar
#994    
lecluse committed
60
    private $columns = [
lecluse's avatar
#3357    
lecluse committed
61
62
63
        'intervenant'         => [
            'visibility' => false,
            'head-text'  => "<th>Intervenant</th>",
lecluse's avatar
#994    
lecluse committed
64
        ],
lecluse's avatar
#3357    
lecluse committed
65
66
        'structure-aff'       => [
            'visibility' => false,
67
            'head-text'  => "<th title=\"StructureService d'appartenance de l'intervenant\">StructureService d'affectation</th>",
lecluse's avatar
#994    
lecluse committed
68
        ],
lecluse's avatar
#3357    
lecluse committed
69
70
        'structure-ens'       => [
            'visibility' => true,
71
            'head-text'  => "<th title=\"StructureService gestionnaire de l'enseignement\">Composante d'enseignement</th>",
lecluse's avatar
#994    
lecluse committed
72
        ],
lecluse's avatar
#3357    
lecluse committed
73
74
75
        'formation'           => [
            'visibility' => true,
            'head-text'  => "<th title=\"Formation\">Formation</th>",
lecluse's avatar
#994    
lecluse committed
76
        ],
lecluse's avatar
#3357    
lecluse committed
77
78
79
        'periode'             => [
            'visibility' => true,
            'head-text'  => "<th title=\"Période\">Période</th>",
80
        ],
lecluse's avatar
#3357    
lecluse committed
81
82
83
        'enseignement'        => [
            'visibility' => true,
            'head-text'  => "<th title=\">Enseignement\">Enseignement</th>",
lecluse's avatar
#994    
lecluse committed
84
        ],
lecluse's avatar
#3357    
lecluse committed
85
86
87
        'foad'                => [
            'visibility' => false,
            'head-text'  => "<th title=\"Formation ouverte à distance\">FOAD</th>",
lecluse's avatar
#994    
lecluse committed
88
        ],
lecluse's avatar
#3357    
lecluse committed
89
90
91
        'regimes-inscription' => [
            'visibility' => false,
            'head-text'  => "<th title=\"Régime d'inscription\">Rég. d'insc.</th>",
lecluse's avatar
#994    
lecluse committed
92
        ],
lecluse's avatar
#3357    
lecluse committed
93
94
95
        'annee'               => [
            'visibility' => false,
            'head-text'  => "<th>Année univ.</th>",
lecluse's avatar
#994    
lecluse committed
96
97
        ],
    ];
98

99
100
101
102
103
104
105
    /**
     * Types d'intervention
     *
     * @var TypeIntervention[]
     */
    protected $typesIntervention;

106
    /**
lecluse's avatar
#994    
lecluse committed
107
     * Lecture seule ou non
108
     *
lecluse's avatar
#994    
lecluse committed
109
     * @var boolean
110
     */
lecluse's avatar
#994    
lecluse committed
111
    private $readOnly = false;
112

lecluse's avatar
#3357    
lecluse committed
113
114
115
116
117
    /**
     * @var Intervenant|null
     */
    private $prevuToPrevu;

118

lecluse's avatar
lecluse committed
119

120
121
122
123
    /**
     * Helper entry point.
     *
     * @param Service[] $services
lecluse's avatar
#3357    
lecluse committed
124
     *
125
126
     * @return self
     */
127
    final public function __invoke($services)
128
    {
lecluse's avatar
#994    
lecluse committed
129
130
        $this->setServices($services);
        $this->calcDefaultColumnsVisibility();
lecluse's avatar
#3357    
lecluse committed
131

132
133
134
        return $this;
    }

lecluse's avatar
#3357    
lecluse committed
135
136


137
138
139
140
141
142
143
144
145
146
    /**
     * Retourne le code HTML généré par cette aide de vue.
     *
     * @return string
     */
    public function __toString()
    {
        return $this->render();
    }

lecluse's avatar
#3357    
lecluse committed
147
148


lecluse's avatar
#994    
lecluse committed
149
150
151
152
153
    public function getAddUrl()
    {
        return $this->getView()->url('service/saisie', [], ['query' => ['type-volume-horaire' => $this->getTypeVolumeHoraire()->getId()]]);
    }

lecluse's avatar
#3357    
lecluse committed
154
155


156
157
158
159
160
    /**
     * Génère le code HTML.
     *
     * @return string
     */
lecluse's avatar
#3357    
lecluse committed
161
    public function render($details = false)
162
    {
lecluse's avatar
#3357    
lecluse committed
163
        $this->totaux      = [];
164
        $typesIntervention = $this->getTypesIntervention();
lecluse's avatar
#3357    
lecluse committed
165
        $colspan           = 2;
lecluse's avatar
lecluse committed
166

lecluse's avatar
#994    
lecluse committed
167
        $attribs = [
lecluse's avatar
#3357    
lecluse committed
168
169
170
            'id'          => $this->getId(true),
            'class'       => 'service-liste',
            'data-params' => json_encode($this->exportParams()),
lecluse's avatar
#994    
lecluse committed
171
        ];
172

lecluse's avatar
#3357    
lecluse committed
173
174
175
        $out = '<div ' . $this->htmlAttribs($attribs) . '>';
        if (count($this->getServices()) > 150) {
            return $out . '<div class="alert alert-danger" role="alert">Le nombre de services à afficher est trop important. Merci d\'affiner vos critères de recherche.</div></div>';
176
        }
lecluse's avatar
#3357    
lecluse committed
177
        if ($this->getAddButtonVisibility() && !$this->getReadOnly()) {
178
            $out .= $this->renderActionButtons();
179
        }
lecluse's avatar
#994    
lecluse committed
180
        $out .= $this->renderShowHide();
181

lecluse's avatar
#994    
lecluse committed
182
        $out .= '<table class="table table-condensed table-extra-condensed table-bordered service">';
183
        $out .= '<tr>';
184

lecluse's avatar
#3357    
lecluse committed
185
        foreach ($this->getColumnsList() as $columnName) {
lecluse's avatar
#994    
lecluse committed
186
            if ($this->getColumnVisibility($columnName)) {
lecluse's avatar
#3357    
lecluse committed
187
188
                $out .= $this->getColumnHeadText($columnName) . "\n";
                $colspan++;
lecluse's avatar
#994    
lecluse committed
189
            }
190
        }
lecluse's avatar
#3357    
lecluse committed
191
        foreach ($typesIntervention as $ti) {
lecluse's avatar
#994    
lecluse committed
192
            $display = $this->getTypeInterventionVisibility($ti) ? '' : ';display:none';
193
            $colspan++;
lecluse's avatar
#3357    
lecluse committed
194
            $out .= "<th class=\"heures type-intervention " . $ti->getCode() . "\" style=\"width:8%$display\"><abbr title=\"" . $ti->getLibelle() . "\">" . $ti->getCode() . "</abbr></th>\n";
195
196
197
        }
        $out .= "<th>&nbsp;</th>\n";
        $out .= "</tr>\n";
198

lecluse's avatar
#3357    
lecluse committed
199
        foreach ($this->services as $service) {
200
            $out .= $this->renderLigne($service, $details);
201
        }
202

lecluse's avatar
#3357    
lecluse committed
203
        $style = $this->getTotaux()['total_general'] == 0 ? ' style="display:none"' : '';
204
        $out .= '<tfoot ' . $style . '>' . "\n";
205
        $out .= $this->renderTotaux();
lecluse's avatar
#3357    
lecluse committed
206
207
        $out .= '</tfoot>' . "\n";
        $out .= '</table>' . "\n";
208
        $out .= $this->renderShowHide();
lecluse's avatar
#3357    
lecluse committed
209
210
        $out .= '</div>' . "\n";

211
212
213
        return $out;
    }

lecluse's avatar
#3357    
lecluse committed
214
215


216
    public function renderActionButtons()
217
    {
218
        $out = '';
lecluse's avatar
#3357    
lecluse committed
219
        if ($this->isInRealise()) {
220
            $attribs = [
lecluse's avatar
#3357    
lecluse committed
221
222
223
                'class'       => 'btn btn-warning prevu-to-realise-show',
                'data-toggle' => 'modal',
                'data-target' => '#prevu-to-realise-modal',
224
225
                //'data-event'    => 'service-constatation',
                //'href'          => $this->getAddUrl(),
lecluse's avatar
#3357    
lecluse committed
226
227
                'title'       => "Saisir comme réalisées l'ensemble des heures prévisionnelles"
                    . ". Attention toutefois : si des heures réalisées ont déjà été saisies alors ces dernières seront écrasées!",
228
            ];
lecluse's avatar
#3357    
lecluse committed
229
            $out .= '<button type="button" ' . $this->htmlAttribs($attribs) . '>Prévu <span class="glyphicon glyphicon-arrow-right"></span> réalisé</button>&nbsp;';
230
            $out .= '<div class="modal fade" id="prevu-to-realise-modal" tabindex="-1" role="dialog" aria-hidden="true">';
231
            $out .= '<div class="modal-dialog modal-md">';
232
233
234
235
236
237
238
            $out .= '<div class="modal-content">';
            $out .= '<div class="modal-header">';
            $out .= '<button type="button" class="close" data-dismiss="modal" aria-label="Annuler"><span aria-hidden="true">&times;</span></button>';
            $out .= '<h4 class="modal-title">Saisir comme réalisées l\'ensemble des heures prévisionnelles</h4>';
            $out .= '</div>';
            $out .= '<div class="modal-body">';
            $out .= '<p>Souhaitez-vous réellement saisir comme réalisées l\'ensemble des heures prévisionnelles ?</p>';
239
            $out .= '<div class="alert alert-warning" role="alert">Attention : si des heures réalisées ont déjà été saisies alors ces dernières seront écrasées!</div>';
240
241
242
243
244
245
246
247
            $out .= '</div>';
            $out .= '<div class="modal-footer">';
            $out .= '<button type="button" class="btn btn-default" data-dismiss="modal">Annuler</button>';
            $out .= '<button type="button" class="btn btn-primary prevu-to-realise">OK</button>';
            $out .= '</div>';
            $out .= '</div>';
            $out .= '</div>';
            $out .= '</div>';
lecluse's avatar
lecluse committed
248
249
250
251
        } elseif ($this->prevuToPrevu){
            $iPrec = $this->getServiceIntervenant()->getPrecedent($this->prevuToPrevu);
            $tvh = $this->getServiceTypeVolumeHoraire()->getPrevu();
            $evh = $this->getServiceEtatVolumeHoraire()->getValide();
lecluse's avatar
lecluse committed
252
            $hasHeures = $iPrec ? $this->getProcessusIntervenant()->hasHeuresEnseignement($iPrec, $tvh, $evh ) : false;
lecluse's avatar
lecluse committed
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
            if ($hasHeures) {
                $attribs = [
                    'class'       => 'btn btn-warning prevu-to-prevu-show',
                    'data-toggle' => 'modal',
                    'data-target' => '#prevu-to-prevu-modal',
                    //'data-event'    => 'service-constatation',
                    //'href'          => $this->getAddUrl(),
                    'title'       => "Initialiser le service prévisionnel avec le service prévisionnel validé l'année dernière",
                ];
                $out .= '<button type="button" ' . $this->htmlAttribs($attribs) . '>Prévu ' . $this->getServiceContext()->getAnneePrecedente() . ' <span class="glyphicon glyphicon-arrow-right"></span> Prévu ' . $this->getServiceContext()->getAnnee() . '</button>&nbsp;';
                $out .= '<div class="modal fade" id="prevu-to-prevu-modal" tabindex="-1" role="dialog" aria-hidden="true">';
                $out .= '<div class="modal-dialog modal-md">';
                $out .= '<div class="modal-content">';
                $out .= '<div class="modal-header">';
                $out .= '<button type="button" class="close" data-dismiss="modal" aria-label="Annuler"><span aria-hidden="true">&times;</span></button>';
                $out .= '<h4 class="modal-title">Reporter ici le service prévisionnel validé de l\'année précédente.</h4>';
                $out .= '</div>';
                $out .= '<div class="modal-body">';
                $out .= '<p>Souhaitez-vous réellement initialiser votre service prévisionnel à partir de votre service prévisionnel validé de l\'an dernier ?</p>';
lecluse's avatar
lecluse committed
272
273
274
275
                $out .= '<div class="alert alert-info" id="prevu-to-prevu-attente" style="display:none">';
                $out .= '<img src="'.$this->getView()->basePath().'/images/wait.gif" alt="Attente..."/>';
                $out .= '<div>Reprise des enseignements de l\'année dernière en cours... Merci de patienter.</div>';
                $out .= '</div>';
lecluse's avatar
lecluse committed
276
277
278
279
280
281
282
283
284
                $out .= '</div>';
                $out .= '<div class="modal-footer">';
                $out .= '<button type="button" class="btn btn-default" data-dismiss="modal">Annuler</button>';
                $out .= '<button type="button" class="btn btn-primary prevu-to-prevu" data-intervenant="' . $this->prevuToPrevu->getRouteParam() . '">OK</button>';
                $out .= '</div>';
                $out .= '</div>';
                $out .= '</div>';
                $out .= '</div>';
            }
285
        }
286
        $attribs = [
lecluse's avatar
#3357    
lecluse committed
287
288
289
290
291
292
293
            'class'      => 'ajax-modal services btn btn-primary',
            'data-event' => 'service-add-message',
            'href'       => $this->getAddUrl(),
            'title'      => 'Ajouter un nouvel enseignement',
        ];
        $out .= '<a ' . $this->htmlAttribs($attribs) . '><span class="glyphicon glyphicon-plus"></span> Je saisis</a>';

lecluse's avatar
#994    
lecluse committed
294
295
        return $out;
    }
296

lecluse's avatar
#3357    
lecluse committed
297
298
299


    public function renderLigne(Service $service, $details = false, $show = true)
lecluse's avatar
#994    
lecluse committed
300
    {
lecluse's avatar
#3357    
lecluse committed
301
        $ligneView = $this->getView()->serviceLigne($this, $service);
lecluse's avatar
#994    
lecluse committed
302

303
304
305
306
307
308
309
310
        if ($this->getServiceContext()->isModaliteServicesSemestriel()){
            $volumeHoraireListe = $this->getView()->volumeHoraireListe($service->getVolumeHoraireListe());
            /* @var $volumeHoraireListe \Application\View\Helper\VolumeHoraire\Liste */
        }else{
            $volumeHoraireListe = $this->getView()->volumeHoraireListeCalendaire($service->getVolumeHoraireListe());
            /* @var $volumeHoraireListe \Application\View\Helper\VolumeHoraire\ListeCalendaire */
        }

lecluse's avatar
#994    
lecluse committed
311
312

        $attribs = [
lecluse's avatar
#3357    
lecluse committed
313
314
315
316
            'id'       => 'service-' . $service->getId() . '-ligne',
            'data-id'  => $service->getId(),
            'class'    => 'service-ligne',
            'data-url' => $ligneView->getRefreshUrl(),
lecluse's avatar
#994    
lecluse committed
317
        ];
lecluse's avatar
#3357    
lecluse committed
318
319
        if (!$show) $attribs['style'] = 'display:none';
        $out = '<tr ' . $this->htmlAttribs($attribs) . '>';
320
        $out .= $ligneView->render($details);
321
        $out .= '</tr>';
lecluse's avatar
#3357    
lecluse committed
322
323
324
        $out .= '<tr class="volume-horaire" id="service-' . $service->getId() . '-volume-horaire-tr"' . ($details ? '' : ' style="display:none"') . '>';
        if ($this->isInRealise()) {
            $out .= '<td class="volume-horaire" style="padding-left:5em" id="service-' . $service->getId() . '-volume-horaire-td" colspan="999">';
lecluse's avatar
#994    
lecluse committed
325

lecluse's avatar
#3357    
lecluse committed
326
            $volumeHoraireListe->getVolumeHoraireListe()->setTypeVolumeHoraire($this->getServiceTypeVolumeHoraire()->getPrevu());
327
            $volumeHoraireListe->getVolumeHoraireListe()->setEtatVolumeHoraire($etat = $this->getServiceEtatVolumeHoraire()->getValide());
lecluse's avatar
#994    
lecluse committed
328
            $volumeHoraireListe->setReadOnly(true);
329
            $out .= '<div class="rappel-volume-horaire-prevu">';
330
            $out .= sprintf('<div style="float:left;width:15%%"><h5>Prévisionnel<br />%s :</h5></div>', $etat);
lecluse's avatar
#3357    
lecluse committed
331
            $out .= '<div id="vhl-prev" style="width:85%" data-url="' . $volumeHoraireListe->getRefreshUrl() . '">' . $volumeHoraireListe->render() . '</div>';
332
            $out .= '</div>';
lecluse's avatar
#3357    
lecluse committed
333
334
335
336

            $volumeHoraireListe->getVolumeHoraireListe()->setTypeVolumeHoraire($this->getTypeVolumeHoraire());
            $volumeHoraireListe->getVolumeHoraireListe()->setEtatVolumeHoraire($this->getServiceEtatVolumeHoraire()->getSaisi());
            $volumeHoraireListe->setReadOnly($this->getReadOnly());
lecluse's avatar
#994    
lecluse committed
337
            $out .= '<div style="float:left;width:15%"><h5>Réalisé :</h5></div>';
lecluse's avatar
#3357    
lecluse committed
338
339
340
341
342
343
344
345
            $out .= '<div id="vhl" style="width:85%" data-url="' . $volumeHoraireListe->getRefreshUrl() . '">' . $volumeHoraireListe->render() . '</div>';
        } else {
            $out .= '<td class="volume-horaire" style="padding-left:10em" id="service-' . $service->getId() . '-volume-horaire-td" colspan="999">';

            $volumeHoraireListe->getVolumeHoraireListe()->setTypeVolumeHoraire($this->getTypeVolumeHoraire());
            $volumeHoraireListe->getVolumeHoraireListe()->setEtatVolumeHoraire($this->getServiceEtatVolumeHoraire()->getSaisi());
            $volumeHoraireListe->setReadOnly($this->getReadOnly());
            $out .= '<div id="vhl" data-url="' . $volumeHoraireListe->getRefreshUrl() . '">' . $volumeHoraireListe->render() . '</div>';
lecluse's avatar
#994    
lecluse committed
346
347
348
        }
        $out .= '</td>';
        $out .= '</tr>';
lecluse's avatar
#3357    
lecluse committed
349

350
351
352
        return $out;
    }

lecluse's avatar
#3357    
lecluse committed
353
354


lecluse's avatar
#994    
lecluse committed
355
356
357
358
359
    public function renderTotaux()
    {
        $typesIntervention = $this->getTypesIntervention();

        $colspan = 0;
lecluse's avatar
#3357    
lecluse committed
360
361
362
363
364
365
366
367
368
        if ($this->getColumnVisibility('intervenant')) $colspan++;
        if ($this->getColumnVisibility('structure-aff')) $colspan++;
        if ($this->getColumnVisibility('structure-ens')) $colspan++;
        if ($this->getColumnVisibility('formation')) $colspan++;
        if ($this->getColumnVisibility('periode')) $colspan++;
        if ($this->getColumnVisibility('enseignement')) $colspan++;
        if ($this->getColumnVisibility('foad')) $colspan++;
        if ($this->getColumnVisibility('regimes-inscription')) $colspan++;
        if ($this->getColumnVisibility('annee')) $colspan++;
lecluse's avatar
#994    
lecluse committed
369
370
371
372
373
374

        $data = $this->getTotaux();

        $out = '<tr>';
        $out .= "<th colspan='$colspan' style=\"text-align:right\">Totaux par type d'intervention :</th>\n";
        $typesInterventionDisplayed = 0;
lecluse's avatar
#3357    
lecluse committed
375
376
        foreach ($typesIntervention as $ti) {
            if ($this->getTypeInterventionVisibility($ti)) {
lecluse's avatar
#994    
lecluse committed
377
378
                $display = '';
                $typesInterventionDisplayed++;
lecluse's avatar
#3357    
lecluse committed
379
            } else {
lecluse's avatar
#994    
lecluse committed
380
381
                $display = ';display:none';
            }
382
            $out .= "<td id=\"" . $ti->getCode() . "\" class=\"type-intervention " . $ti->getCode() . "\" style=\"text-align:right$display\">" . \UnicaenApp\Util::formattedNumber($data[$ti->getCode()]) . "</td>\n";
lecluse's avatar
#994    
lecluse committed
383
384
385
386
387
        }
        $out .= "<td>&nbsp;</td>\n";
        $out .= "</tr>\n";
        $out .= '<tr>';
        $out .= "<th colspan=\"$colspan\" style=\"text-align:right\">Total des heures de service :</th>\n";
388
        $out .= "<td id=\"total-general\" style=\"text-align:right\" data-total=\"".$data['total_general']."\" colspan=\"" . $typesInterventionDisplayed . "\">" . \UnicaenApp\Util::formattedNumber($data['total_general']) . "</td>\n";
lecluse's avatar
#994    
lecluse committed
389
390
        $out .= "<td>&nbsp;</td>\n";
        $out .= "</tr>\n";
lecluse's avatar
#3357    
lecluse committed
391

lecluse's avatar
#994    
lecluse committed
392
393
394
        return $out;
    }

lecluse's avatar
#3357    
lecluse committed
395
396


lecluse's avatar
#994    
lecluse committed
397
398
399
400
    public function renderShowHide()
    {
        return
            '<div class="service-show-hide-buttons">'
lecluse's avatar
#3357    
lecluse committed
401
402
403
            . '<button type="button" class="btn btn-default btn-xs service-show-all-details"><span class="glyphicon glyphicon-chevron-down"></span> Tout déplier</button> '
            . '<button type="button" class="btn btn-default btn-xs service-hide-all-details"><span class="glyphicon glyphicon-chevron-up"></span> Tout replier</button>'
            . '</div>';
lecluse's avatar
#994    
lecluse committed
404
405
    }

lecluse's avatar
#3357    
lecluse committed
406
407


408
409
410
411
412
413
414
415
416
417
    /**
     * Détermine si nous sommes en service réalisé ou non
     *
     * @return boolean
     */
    public function isInRealise()
    {
        return $this->getTypeVolumeHoraire()->getCode() === \Application\Entity\Db\TypeVolumeHoraire::CODE_REALISE;
    }

lecluse's avatar
#994    
lecluse committed
418

lecluse's avatar
#3357    
lecluse committed
419

lecluse's avatar
#994    
lecluse committed
420
421
422
    /**
     * @return string
     */
lecluse's avatar
#3357    
lecluse committed
423
    public function getId($reNew = false)
lecluse's avatar
#994    
lecluse committed
424
    {
lecluse's avatar
#3357    
lecluse committed
425
        if (null === $this->id || $reNew) {
lecluse's avatar
#994    
lecluse committed
426
427
            $this->id = uniqid('service-liste-');
        }
lecluse's avatar
#3357    
lecluse committed
428

lecluse's avatar
#994    
lecluse committed
429
430
431
        return $this->id;
    }

lecluse's avatar
#3357    
lecluse committed
432
433


434
435
    protected function getTotaux()
    {
lecluse's avatar
#3357    
lecluse committed
436
        if (!$this->totaux) {
437
            $typesIntervention = $this->getTypesIntervention();
lecluse's avatar
#3357    
lecluse committed
438
439
440
441
            $data              = [
                'total_general' => 0,
            ];
            foreach ($typesIntervention as $ti) {
442
443
                $data[$ti->getCode()] = 0;

lecluse's avatar
#3357    
lecluse committed
444
                foreach ($this->getServices() as $service) {
445
446
447
448
                    $h = $service->getVolumeHoraireListe()->setTypeVolumeHoraire($this->getTypeVolumehoraire())->setTypeIntervention($ti)->getHeures();
                    $data[$ti->getCode()] += $h;
                }
            }
lecluse's avatar
#3357    
lecluse committed
449
            foreach ($this->getServices() as $service) {
lecluse's avatar
#994    
lecluse committed
450
                $data['total_general'] += $service->getVolumeHoraireListe()->setTypeVolumeHoraire($this->getTypeVolumehoraire())->setTypeIntervention(false)->getHeures();
451
            }
452
            $this->totaux = $data;
453
        }
lecluse's avatar
#3357    
lecluse committed
454

455
456
457
        return $this->totaux;
    }

lecluse's avatar
#3357    
lecluse committed
458
459


lecluse's avatar
#994    
lecluse committed
460
461
462
463
464
465
466
467
468
469
470
    /**
     * Retourne les paramètres de configuration du View Helper sous forme de tableau transformable en JSON
     *
     * @return array
     */
    public function exportParams()
    {
        $params = [
            'read-only'                     => $this->getReadOnly(),
            'type-volume-horaire'           => $this->getTypeVolumeHoraire()->getId(),
            'columns-visibility'            => [],
471
            'in-realise'                    => $this->isInRealise(),
lecluse's avatar
#994    
lecluse committed
472
        ];
lecluse's avatar
#3357    
lecluse committed
473
        foreach ($this->getColumnsList() as $columnName) {
lecluse's avatar
#994    
lecluse committed
474
475
476
477
478
479
            $params['columns-visibility'][$columnName] = $this->getColumnVisibility($columnName);
        }

        return $params;
    }

lecluse's avatar
#3357    
lecluse committed
480
481


lecluse's avatar
#994    
lecluse committed
482
483
484
485
    /**
     * Copnfigure le View Helper selon les paramètres transmis
     *
     * @param array $params
lecluse's avatar
#3357    
lecluse committed
486
     *
lecluse's avatar
#994    
lecluse committed
487
488
     * @return self
     */
lecluse's avatar
#3357    
lecluse committed
489
    public function applyParams(array $params)
lecluse's avatar
#994    
lecluse committed
490
    {
lecluse's avatar
#3357    
lecluse committed
491
492
        if (isset($params['read-only'])) {
            $this->setReadOnly(filter_var($params['read-only'], FILTER_VALIDATE_BOOLEAN));
lecluse's avatar
#994    
lecluse committed
493
        }
lecluse's avatar
#3357    
lecluse committed
494
495
        if (isset($params['type-volume-horaire'])) {
            $this->setTypeVolumeHoraire($this->getServiceTypeVolumeHoraire()->get((int)$params['type-volume-horaire']));
lecluse's avatar
#994    
lecluse committed
496
        }
lecluse's avatar
#3357    
lecluse committed
497
498
499
        if (isset($params['columns-visibility']) && is_array($params['columns-visibility'])) {
            foreach ($params['columns-visibility'] as $columnName => $visibility) {
                $this->setColumnVisibility($columnName, filter_var($visibility, FILTER_VALIDATE_BOOLEAN));
lecluse's avatar
#994    
lecluse committed
500
501
            }
        }
lecluse's avatar
#3357    
lecluse committed
502

lecluse's avatar
#994    
lecluse committed
503
504
505
        return $this;
    }

lecluse's avatar
#3357    
lecluse committed
506
507


lecluse's avatar
#994    
lecluse committed
508
509
    /**
     * Calcule la visibilité par défaut des colonnes en fonction des données transmises!!
lecluse's avatar
#3357    
lecluse committed
510
     *
lecluse's avatar
#994    
lecluse committed
511
512
513
514
515
     * @return \Application\View\Helper\Service\Liste
     */
    public function calcDefaultColumnsVisibility()
    {
        $services = $this->getServices();
lecluse's avatar
#3357    
lecluse committed
516
        $role     = $this->getServiceContext()->getSelectedIdentityRole();
lecluse's avatar
#994    
lecluse committed
517
518
519

        // si plusieurs années différentes sont détectées alors on prévoit d'afficher la colonne année par défaut
        // si plusieurs intervenants différents alors on prévoit d'afficher la colonne intervenant par défaut
lecluse's avatar
#3357    
lecluse committed
520
521
522
523
        $annee             = null;
        $multiAnnees       = false;
        $intervenant       = null;
        $multiIntervenants = false;
524
        foreach ($services as $service) if ($service){
lecluse's avatar
#3357    
lecluse committed
525
526
527
528
529
530
531
532
533
534
535
536
537
            if (empty($annee)) {
                $annee = $service->getIntervenant()->getAnnee();
            } elseif ($annee !== $service->getIntervenant()->getAnnee()) {
                $multiAnnees = true;
                break;
            }

            if (empty($intervenant)) {
                $intervenant = $service->getIntervenant();
            } elseif ($intervenant !== $service->getIntervenant()) {
                $multiIntervenants = true;
                break;
            }
lecluse's avatar
#994    
lecluse committed
538
        }
lecluse's avatar
#3357    
lecluse committed
539
540
541
        $this->setColumnVisibility('annee', $multiAnnees);
        $this->setColumnVisibility('intervenant', $multiIntervenants);
        $this->setColumnVisibility('structure-aff', $multiIntervenants);
lecluse's avatar
#994    
lecluse committed
542
543

        // si c'est une composante alors on affiche le détail pour l'enseignement
544
        $detailsEns = !$role->getIntervenant();
lecluse's avatar
#3357    
lecluse committed
545
546
547
        /** @todo associer ça à un paramètre... */
        $this->setColumnVisibility('foad', $detailsEns);
        $this->setColumnVisibility('regimes-inscription', $detailsEns);
lecluse's avatar
#994    
lecluse committed
548
549
550
551

        return $this;
    }

lecluse's avatar
#3357    
lecluse committed
552
553


554
555
    /**
     * @param TypeIntervention $typeIntervention
lecluse's avatar
#3357    
lecluse committed
556
     *
557
558
     * @return boolean
     */
lecluse's avatar
#3357    
lecluse committed
559
    public function getTypeInterventionVisibility(TypeIntervention $typeIntervention)
560
    {
lecluse's avatar
#3357    
lecluse committed
561
        if (isset($this->typesInterventionVisibility[$typeIntervention->getCode()])) { // visibilité déterminée
lecluse's avatar
#994    
lecluse committed
562
            return $this->typesInterventionVisibility[$typeIntervention->getCode()];
lecluse's avatar
#3357    
lecluse committed
563
        } else { // visibilité calculée
lecluse's avatar
#994    
lecluse committed
564
            $totaux = $this->getTotaux();
lecluse's avatar
#3357    
lecluse committed
565

566
            return $typeIntervention->isVisible() || (isset($totaux[$typeIntervention->getCode()]) && $totaux[$typeIntervention->getCode()] > 0);
lecluse's avatar
#3357    
lecluse committed
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
        }
    }



    /**
     * Détermine si le bouton prévu => prévu doit être affiché ou non.
     *
     * @param $intervenant
     */
    public function showPrevuToPrevu($intervenant)
    {
        if ($intervenant instanceof Intervenant) {
            $this->prevuToPrevu = $intervenant;
        } else {
            $this->prevuToPrevu = null;
lecluse's avatar
#994    
lecluse committed
583
584
585
        }
    }

lecluse's avatar
#3357    
lecluse committed
586
587


lecluse's avatar
#994    
lecluse committed
588
589
590
591
592
    /**
     * @return @string[]
     */
    public function getColumnsList()
    {
lecluse's avatar
#3357    
lecluse committed
593
        return array_keys($this->columns);
594
595
    }

lecluse's avatar
#3357    
lecluse committed
596
597


598
599
    /**
     *
lecluse's avatar
#3357    
lecluse committed
600
     * @param string  $columnName
lecluse's avatar
#994    
lecluse committed
601
     * @param boolean $visibility
lecluse's avatar
#3357    
lecluse committed
602
     *
603
604
     * @return self
     */
lecluse's avatar
#3357    
lecluse committed
605
    public function setColumnVisibility($columnName, $visibility)
606
    {
lecluse's avatar
#994    
lecluse committed
607
        $this->columns[$columnName]['visibility'] = (boolean)$visibility;
lecluse's avatar
#3357    
lecluse committed
608

609
610
611
        return $this;
    }

lecluse's avatar
#3357    
lecluse committed
612
613


614
    /**
lecluse's avatar
#994    
lecluse committed
615
616
     *
     * @param string $columnName
lecluse's avatar
#3357    
lecluse committed
617
     *
lecluse's avatar
#994    
lecluse committed
618
     * @return boolean
619
     */
lecluse's avatar
#3357    
lecluse committed
620
    public function getColumnVisibility($columnName)
621
    {
lecluse's avatar
#3357    
lecluse committed
622
        if (!array_key_exists($columnName, $this->columns)) {
623
            throw new \LogicException('La colonne "' . $columnName . '" n\'existe pas.');
624
        }
lecluse's avatar
#3357    
lecluse committed
625

lecluse's avatar
#994    
lecluse committed
626
        return $this->columns[$columnName]['visibility'];
627
628
    }

lecluse's avatar
#3357    
lecluse committed
629
630


lecluse's avatar
#994    
lecluse committed
631
632
633
    /**
     *
     * @param string $columnName
lecluse's avatar
#3357    
lecluse committed
634
     *
lecluse's avatar
#994    
lecluse committed
635
     * @return string
636
     * @throws \LogicException
lecluse's avatar
#994    
lecluse committed
637
     */
lecluse's avatar
#3357    
lecluse committed
638
    public function getColumnHeadText($columnName)
639
    {
lecluse's avatar
#3357    
lecluse committed
640
        if (!array_key_exists($columnName, $this->columns)) {
641
            throw new \LogicException('La colonne "' . $columnName . '" n\'existe pas.');
lecluse's avatar
#994    
lecluse committed
642
        }
lecluse's avatar
#3357    
lecluse committed
643

lecluse's avatar
#994    
lecluse committed
644
645
        return $this->columns[$columnName]['head-text'];
    }
646

lecluse's avatar
#3357    
lecluse committed
647
648


lecluse's avatar
#994    
lecluse committed
649
650
651
652
653
    /**
     * @return TypeIntervention[]
     */
    public function getTypesIntervention()
    {
lecluse's avatar
#3357    
lecluse committed
654
        if (!isset($this->typesIntervention)) {
655
656
657
            $qb = $this->getServiceTypeIntervention()->finderByContext();
            $this->getServiceTypeIntervention()->finderByHistorique($qb);
            $this->typesIntervention = $this->getServiceTypeIntervention()->getList( $qb );
lecluse's avatar
#994    
lecluse committed
658
        }
lecluse's avatar
#3357    
lecluse committed
659

lecluse's avatar
#994    
lecluse committed
660
661
        return $this->typesIntervention;
    }
662

lecluse's avatar
#3357    
lecluse committed
663
664


lecluse's avatar
#994    
lecluse committed
665
666
    /**
     * @param TypeIntervention[] $typesIntervention
lecluse's avatar
#3357    
lecluse committed
667
     *
lecluse's avatar
#994    
lecluse committed
668
669
670
671
672
     * @return self
     */
    public function setTypesIntervention($typesIntervention)
    {
        $this->typesIntervention = $typesIntervention;
lecluse's avatar
#3357    
lecluse committed
673

lecluse's avatar
#994    
lecluse committed
674
675
        return $this;
    }
676

lecluse's avatar
#3357    
lecluse committed
677
678


lecluse's avatar
#994    
lecluse committed
679
680
681
682
683
684
685
    /**
     * Retourne le type de volume horaire concerné.
     *
     * @return TypeVolumeHoraire
     */
    public function getTypeVolumeHoraire()
    {
lecluse's avatar
#3357    
lecluse committed
686
        if (empty($this->typeVolumeHoraire)) {
lecluse's avatar
#994    
lecluse committed
687
            $this->typeVolumeHoraire = $this->getServiceTypeVolumeHoraire()->getPrevu();
688
        }
lecluse's avatar
#3357    
lecluse committed
689

lecluse's avatar
#994    
lecluse committed
690
        return $this->typeVolumeHoraire;
691
692
    }

lecluse's avatar
#3357    
lecluse committed
693
694


lecluse's avatar
#994    
lecluse committed
695
696
697
698
699
    /**
     *
     * @return boolean
     */
    public function getReadOnly()
700
    {
lecluse's avatar
#994    
lecluse committed
701
702
703
        return $this->readOnly;
    }

lecluse's avatar
#3357    
lecluse committed
704
705


lecluse's avatar
#994    
lecluse committed
706
707
708
    /**
     *
     * @param boolean $readOnly
lecluse's avatar
#3357    
lecluse committed
709
     *
lecluse's avatar
#994    
lecluse committed
710
711
712
713
714
     * @return self
     */
    public function setReadOnly($readOnly)
    {
        $this->readOnly = $readOnly;
lecluse's avatar
#3357    
lecluse committed
715

lecluse's avatar
#994    
lecluse committed
716
        return $this;
717
718
    }

lecluse's avatar
#3357    
lecluse committed
719
720


721
722
723
724
725
726
727
728
729
    /**
     *
     * @return Service[]
     */
    public function getServices()
    {
        return $this->services;
    }

lecluse's avatar
#3357    
lecluse committed
730
731


732
733
734
    /**
     *
     * @param Service[] $services
lecluse's avatar
#3357    
lecluse committed
735
     *
736
737
738
739
740
     * @return self
     */
    public function setServices(array $services)
    {
        $this->services = $services;
lecluse's avatar
#3357    
lecluse committed
741

742
743
744
        return $this;
    }

lecluse's avatar
#3357    
lecluse committed
745
746


lecluse's avatar
#994    
lecluse committed
747
    /**
lecluse's avatar
#3357    
lecluse committed
748
     *
lecluse's avatar
#994    
lecluse committed
749
750
751
752
753
754
755
     * @return boolean
     */
    function getAddButtonVisibility()
    {
        return $this->addButtonVisibility;
    }

lecluse's avatar
#3357    
lecluse committed
756
757


lecluse's avatar
#994    
lecluse committed
758
759
760
    /**
     *
     * @param boolean $addButtonVisibility
lecluse's avatar
#3357    
lecluse committed
761
     *
lecluse's avatar
#994    
lecluse committed
762
763
764
765
766
     * @return self
     */
    function setAddButtonVisibility($addButtonVisibility)
    {
        $this->addButtonVisibility = $addButtonVisibility;
lecluse's avatar
#3357    
lecluse committed
767

lecluse's avatar
#994    
lecluse committed
768
769
        return $this;
    }
770
}