SaisieForm.php 7.23 KB
Newer Older
1
2
3
4
<?php

namespace Application\View\Helper\Service;

5
6
7
use Application\Entity\Db\Periode;
use Application\Entity\Db\Service;
use Application\Entity\Db\TypeVolumeHoraire;
8
use Application\Form\Service\Saisie;
9
use Application\View\Helper\AbstractViewHelper;
10
use \Application\Service\Traits\ContextServiceAwareTrait;
11
12
use \Application\Service\Traits\PeriodeServiceAwareTrait;
use \Application\Service\Traits\TypeInterventionServiceAwareTrait;
13
14
use \Application\Service\Traits\TypeVolumeHoraireServiceAwareTrait;
use \Application\Service\Traits\EtatVolumeHoraireServiceAwareTrait;
15

16
17
18
19
20
21

/**
 * Description of SaisieForm
 *
 * @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
 */
22
class SaisieForm extends AbstractViewHelper
23
{
24
    use ContextServiceAwareTrait;
25
26
    use PeriodeServiceAwareTrait;
    use TypeInterventionServiceAwareTrait;
27
28
    use TypeVolumeHoraireServiceAwareTrait;
    use EtatVolumeHoraireServiceAwareTrait;
29

30
31
32
33
34
    /**
     * @var Saisie
     */
    protected $form;

35
36


37
38
    /**
     *
39
     * @return Periode[]
40
41
42
     */
    public function getPeriodes()
    {
43
44
45
46
        $service = $this->form->get('service')->getObject();
        /* @var $service Service */
        if ($service->getElementPedagogique() && $service->getElementPedagogique()->getPeriode()) {
            return [$service->getElementPedagogique()->getPeriode()];
47
        }
48

49
        return $this->getServicePeriode()->getEnseignement();
50
51
    }

52
53


54
55
56
    /**
     *
     * @param Saisie $form
57
     *
58
59
60
61
     * @return SaisieForm|string
     */
    public function __invoke(Saisie $form = null)
    {
62
63
        $this->form = $form;
        $this->form->prepare();
64

65
66
67
        return $this;
    }

68
69


70
71
72
    public function __toString()
    {
        return $this->render();
73
74
    }

75
76


77
78
79
    public function getVolumesHorairesRefreshUrl()
    {
        $url = $this->getView()->url(
80
81
82
83
84
            'service/volumes-horaires-refresh',
            [
                'id' => $this->form->get('service')->get('id')->getValue(),
            ]);

85
86
87
        return $url;
    }

88
89


90
91
92
93
    /**
     * Rendu du formulaire
     *
     * @param Saisie $form
94
     *
95
96
     * @return string
     */
97
    public function render()
98
    {
99
        $fservice = $this->form->get('service');
100

101
        $res = $this->getView()->form()->openTag($this->form);
102
        if (!$this->getServiceContext()->getSelectedIdentityRole()->getIntervenant()) {
103
104
            $res .= $this->getView()->formControlGroup($fservice->get('intervenant'));
        }
105
        if ($fservice->has('interne-externe')) {
106
            $interne = $fservice->get('interne-externe')->getValue() == 'service-interne';
107
108
109
110
111
112
113
114
            $res     .= $this->getView()->formControlGroup($fservice->get('interne-externe'), 'formButtonGroup');
            $res     .= '<div id="element-interne" ' . (($interne) ? '' : 'style="display:none"') . '>' . $this->getView()->fieldsetElementPedagogiqueRecherche($fservice->get('element-pedagogique')) . '</div>';
            $res     .= '<div id="element-externe" ' . (($interne) ? 'style="display:none"' : '') . '>'
                . $this->getView()->formControlGroup($fservice->get('etablissement'))
                . $this->getView()->formControlGroup($fservice->get('description'))
                . '</div>';
        } else {
            $res .= '<div id="element-interne">' . $this->getView()->fieldsetElementPedagogiqueRecherche($fservice->get('element-pedagogique'))->render() . '</div>';
115
        }
116
        $res .= '<div id="volumes-horaires" data-url="' . $this->getVolumesHorairesRefreshUrl() . '">';
117
118
119
120
        $res .= $this->renderVolumesHoraires();
        $res .= '</div>';
        $res .= '<br />';
        $res .= $this->getView()->formRow($this->form->get('submit'));
lecluse's avatar
#994    
lecluse committed
121
        $res .= $this->getView()->formHidden($this->form->get('type-volume-horaire'));
122
        $res .= $this->getView()->formHidden($fservice->get('id'));
123
124
        $res .= $this->getView()->form()->closeTag() . '<br />';

125
126
127
        return $res;
    }

128
129


130
131
    public function renderVolumesHoraires()
    {
132
        if (!$this->getServiceContext()->isModaliteServicesSemestriel($this->form->getTypeVolumeHoraire())){
Laurent Lécluse's avatar
#14896    
Laurent Lécluse committed
133
134
            return null;
        }
135
        $res = '';
136
137
138
139
        foreach ($this->getPeriodes() as $periode) {
            $res .= '<div class="periode" id="' . $periode->getCode() . '">';
            $res .= '<h3>' . $periode . '</h3>';
            $res .= $this->renderVolumeHoraire($this->form->get($periode->getCode()));
140
            $res .= '</div>';
141
        }
142

143
144
        return $res;
    }
145

146
147


lecluse's avatar
#994    
lecluse committed
148
149
    public function renderVolumeHoraire($fieldset)
    {
150
        $typeVolumeHoraire = $this->getServiceTypeVolumeHoraire()->get($fieldset->get('type-volume-horaire')->getValue());
151
152
        /* @var $typeVolumeHoraire TypeVolumeHoraire */
        $inRealise = $typeVolumeHoraire->isRealise();
153
        if ($inRealise) {
lecluse's avatar
lecluse committed
154
155
            $vhl = $fieldset->getObject()->getService()->getVolumeHoraireListe()->getChild();
            /* @var $vhl \Application\Entity\VolumeHoraireListe */
156
157
158
            $vhl->setTypeVolumeHoraire($this->getServiceTypeVolumeHoraire()->getPrevu());
            $vhl->setEtatVolumeHoraire($this->getServiceEtatVolumeHoraire()->getValide());
            $vhl->setPeriode($this->getServicePeriode()->get($fieldset->get('periode')->getValue()));
lecluse's avatar
lecluse committed
159
160
        }

lecluse's avatar
#994    
lecluse committed
161
        $element = $fieldset->getObject()->getService()->getElementPedagogique();
162
        if ($element) {
lecluse's avatar
#994    
lecluse committed
163
            $typesIntervention = $element->getTypeIntervention();
164
        } else {
165
166
167
            $qb = $this->getServiceTypeIntervention()->finderByHistorique();
            $this->getServiceTypeIntervention()->finderByContext($qb);
            $typesIntervention = $this->getServiceTypeIntervention()->getList($qb);
lecluse's avatar
#994    
lecluse committed
168
169
        }

170
        $res = $this->getView()->formHidden($fieldset->get('service'));
lecluse's avatar
#994    
lecluse committed
171
172
173
174
        $res .= $this->getView()->formHidden($fieldset->get('periode'));
        $res .= $this->getView()->formHidden($fieldset->get('type-volume-horaire'));

        $res .= '<div class="volume-horaire-saisie-multiple">';
175
176
177
178
        foreach ($typesIntervention as $typeIntervention) {
            if ($fieldset->has($typeIntervention->getCode())) {
                $element = $fieldset->get($typeIntervention->getCode());
                $element->setAttribute('class', 'form-control')
179
                    ->setLabelAttributes(['class' => 'control-label']);
180
181
182
183
184
185
186
187
188
189
190
                $res .= '<div>';
                $res .= $this->getView()->formLabel($element);
                if ($inRealise) {
                    $heures = $vhl->setTypeIntervention($typeIntervention)->getHeures();
                    $res    .= '<br />Prévues : <span id="prev-' . $typeIntervention->getCode() . '" data-heures="' . $heures . '">';
                    $res    .= \UnicaenApp\Util::formattedNumber($heures);
                    $res    .= '</span>';
                }
                $res .= '<br />';
                $res .= $this->getView()->formText($element);
                $res .= '</div>';
lecluse's avatar
lecluse committed
191
            }
lecluse's avatar
#994    
lecluse committed
192
        }
193
        if ($inRealise) {
lecluse's avatar
lecluse committed
194
195
196
197
            $res .= '<div><label>&nbsp;</label><br /><br /><button type="button" class="btn btn-default prevu-to-realise" title="Initialise le formulaire avec les heures prévues">Prévu <span class="glyphicon glyphicon-arrow-right"></span> réalisé</button>';

            $res .= '</div>';
        }
lecluse's avatar
#994    
lecluse committed
198
        $res .= '</div><div class="volume-horaire-saisie-multiple-fin"></div>';
199

lecluse's avatar
#994    
lecluse committed
200
201
        return $res;
    }
202
}