IntervenantViewHelper.php 7.62 KB
Newer Older
lecluse's avatar
lecluse committed
1
2
3
4
<?php

namespace Application\View\Helper\Intervenant;

5
use Application\Constants;
6
use Application\Provider\Privilege\Privileges;
7
use Application\Service\Traits\ContextServiceAwareTrait;
8
use Application\Service\Traits\IntervenantServiceAwareTrait;
lecluse's avatar
lecluse committed
9
10
use Zend\View\Helper\AbstractHtmlElement;
use Application\Entity\Db\Intervenant;
11
use Application\Entity\Db\Traits\IntervenantAwareTrait;
lecluse's avatar
lecluse committed
12
13
14
15
16
17
18
19
20

/**
 * Description of Intervenant
 *
 * @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
 */
class IntervenantViewHelper extends AbstractHtmlElement
{
    use IntervenantAwareTrait;
21
    use ContextServiceAwareTrait;
22
    use IntervenantServiceAwareTrait;
lecluse's avatar
lecluse committed
23

24

lecluse's avatar
lecluse committed
25
26
27
    /**
     *
     * @param Intervenant $intervenant
28
     *
lecluse's avatar
lecluse committed
29
30
     * @return self
     */
31
    public function __invoke(Intervenant $intervenant = null)
lecluse's avatar
lecluse committed
32
33
    {
        if ($intervenant) $this->setIntervenant($intervenant);
34

lecluse's avatar
lecluse committed
35
36
37
        return $this;
    }

38
39


lecluse's avatar
lecluse committed
40
41
42
43
44
    public function __toString()
    {
        return $this->render();
    }

45
46


lecluse's avatar
lecluse committed
47
48
49
50
51
52
53
    /**
     *
     *
     * @return string Code HTML
     */
    public function render()
    {
54
55
56
57
58
59
60
61
        $entity = $this->getIntervenant();

        if (!$entity) {
            return '';
        }

        $vars = [
            'identite'    => [
62
63
64
65
66
                "NOM prénom"           => $entity,
                "Civilité"             => (string)$entity->getCivilite(),
                "Date de naissance"    => (string)$entity->getDateNaissance()->format(Constants::DATE_FORMAT),
                "Commune de naissance" => (string)$entity->getCommuneNaissance() ?: '<span class="inconnu">(Inconnue)</span>',
                "Pays de naissance"    => (string)$entity->getPaysNaissance(),
67
68
            ],
            'coordonnees' => [
69
70
71
72
                "Email"           => $entity->getEmailPro() ?: '<span class="inconnu">(Inconnu)</span>',
                "Téléphone perso" => $entity->getTelPerso() ?: '<span class="inconnu">(Inconnu)</span>',
                "Téléphone pro"   => $entity->getTelPro() ?: '<span class="inconnu">(Inconnu)</span>',
                "Adresse"         => nl2br($entity->getAdresse(false)),
73
74
            ],
            'metier'      => [
lecluse's avatar
#2574    
lecluse committed
75
76
                "Type d'intervenant"        => $entity->getStatut()->getTypeIntervenant(),
                "Statut de l'intervenant"   => $entity->getStatut(),
77
                "N° {$entity->getSource()}" => $entity->getCode(),
lecluse's avatar
#2574    
lecluse committed
78
79
                "Affectation principale"    => $entity->getStructure() ?: '<span class="inconnu">(Inconnue)</span>',
                "Montant de l'indemnité FC" => $entity->getMontantIndemniteFc() !== null ? \UnicaenApp\Util::formattedEuros($entity->getMontantIndemniteFc()) : '<span class="inconnu">(Inconnue)</span>',
80
81
            ],
            'divers'      => [
lecluse's avatar
#2574    
lecluse committed
82
                "Id" => $entity->getId(),
83
                //"Id de connexion" => ($u = $entity->getUtilisateur()) ? $u->getUsername() : "(Aucun)",
84
85
86
87
88
89
90
91
92
93
94
95
            ],
        ];

        $html = '';
        foreach ($vars as $bloc => $vvs) {
            $html .= "<dl class=\"intervenant intervenant-$bloc dl-horizontal\">\n";
            foreach ($vvs as $key => $value) {
                $html .= "\t<dt>$key :</dt><dd>$value</dd>\n";
            }
            $html .= "</dl>";
        }

96
        if ($entity->getHistoDestruction()) {
97
            $msg = 'Cet intervenant a été supprimé de OSE le ' . $entity->getHistoDestruction()->format(Constants::DATE_FORMAT) . '.';
98

99
100
            if ($entity->getSource()->getCode() !== \Application\Service\SourceService::CODE_SOURCE_OSE) {
                $msg .= ' Sa fiche ne remonte plus depuis l\'application ' . $entity->getSource() . '.';
101
102
            }

103
            $html .= '<div class="alert alert-danger">' . $msg . '</div>';
104
105
        }

106
        return $html;
lecluse's avatar
lecluse committed
107
108
    }

109
110


lecluse's avatar
lecluse committed
111
112
113
    public function renderLink()
    {
        $intervenant = $this->getIntervenant();
114
        if (!$intervenant) return '';
lecluse's avatar
lecluse committed
115

116
117
        if ($intervenant->getHistoDestruction()) {
            return '<span class="bg-danger"><abbr title="Cet intervenant a été supprimé de OSE">' . $intervenant . '</abbr></span>';
lecluse's avatar
lecluse committed
118
119
        }

120
        $pourl = $this->getView()->url('intervenant/voir', ['intervenant' => $intervenant->getId()]);
121
122
        $out   = '<a href="' . $pourl . '" data-po-href="' . $pourl . '" class="ajax-modal">' . $intervenant . '</a>';

lecluse's avatar
lecluse committed
123
124
        return $out;
    }
125
126
127
128
129



    public function renderTitle(?string $title)
    {
130
        $title       = $title;
131
132
        $intervenant = $this->getIntervenant();

133
        /*if ($this->getServiceContext()->getIntervenant() == $intervenant) {
134
135
136

        } else {

137
        }*/
138

139
140
        //echo $intervenant . ' <small>' . $intervenant->getStatut() . '</small>';

141
        $canAddIntervenant = $this->getView()->isAllowed(Privileges::getResourceId(Privileges::INTERVENANT_AJOUT_STATUT));
142

143
144
145
        $this->getView()->headTitle()->append($intervenant->getNomUsuel())->append($title);
        $title .= ' <small>' . $intervenant . '</small>';

146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
        echo $this->getView()->tag('h1', ['class' => 'page-header'])->open();
        echo $title . '<br />';
        $statuts = $this->getStatuts();
        ?>
        <nav class="navbar navbar-default intervenant-statuts">
            <div class="container-fluid">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                            data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                        <span class="sr-only">Statuts</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <span class="navbar-brand" href="#">Statut<?= (count($statuts) > 1) ? 's' : '' ?></span>
                </div>

                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                    <ul class="nav navbar-nav">
                        <?php foreach ($statuts as $intervenantId => $statut): ?>
                            <li<?= ($statut == $intervenant->getStatut()) ? ' class="active"' : '' ?>>
                                <a href="<?= $this->getView()->url(null, ['intervenant' => $intervenantId]); ?>"><span
                                            class="type-intervenant"><?= $statut->getTypeIntervenant() . '</span><br />' . $statut->getLibelle() ?>
                                </a>
                            </li>
                        <?php endforeach; ?>
                        <?php if ($canAddIntervenant): ?>
                            <li class="ajout-intervenant">
174
                                <a href="<?= $this->getView()->url('intervenant/dupliquer', ['intervenant' => $intervenantId]); ?>"
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
                                   title="Ajout d'un nouveau statut à l'intervenant"><span
                                            class="glyphicon glyphicon-plus"></span></a>
                            </li>
                        <?php endif; ?>
                    </ul>
                </div><!-- /.navbar-collapse -->
            </div><!-- /.container-fluid -->
        </nav>
        <?php
        echo $this->getView()->tag('h1')->close();
    }



    protected function getStatuts()
    {
        $intervernants = $this->getServiceIntervenant()->getIntervenants($this->getIntervenant());
        $statuts       = [];
        foreach ($intervernants as $intervenant) {
            if ($intervenant->estNonHistorise() && $intervenant->getStatut()) {
                $statuts[$intervenant->getId()] = $intervenant->getStatut();
            }
        }
        uasort($statuts, function ($a, $b) {
            return $a->getOrdre() > $b->getOrdre();
        });

        return $statuts;
203
    }
lecluse's avatar
lecluse committed
204
}