Subversion Repositories eFlore/Applications.cel

Rev

Rev 3886 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3890 idir 1
 <?php
3092 delphine 2
// declare(encoding='UTF-8');
3
/**
4
 * Service fournissant des informations sur les widgets existants et permettant d'en créer d'autres.
5
 *
6
 * Format du service :
7
 * /CelWidgetExport/format
8
 * /CelWidgetExport/csv
9
 *
10
 * Les paramêtres :
11
 *  - "start" indique le numéro du premier item à afficher
12
 *  - "limit" nombre d'items à afficher
13
 *
14
 * @internal   Mininum PHP version : 5.2
15
 * @category   CEL
16
 * @package    Services
17
 * @subpackage Widget
18
 * @version    0.1
19
 * @author     Delphine CAUQUIL <delphine@tela-botanica.org>
20
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
21
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
22
 * @copyright  1999-2017 Tela Botanica <accueil@tela-botanica.org>
23
 */
24
 
25
 
26
class CelWidgetManager extends Cel {
27
 
3890 idir 28
        // correspondance entre les champs de l'interface et les champs de la BD (format 2018 / 2019)
29
        private $parametres_autorises = array(
30
                        'projet' => 'project',
31
                        'type' => 'type',
32
                        'esttype' => 'is_type',
33
                        'langue' => 'language',
34
                        'order' => 'order'
35
        );
36
 
37
        private $correspondance_config_widget= array(
38
                        'projet' =>  'project',
39
                        'langue' =>  'language',
40
                        'titre' =>  'title',
41
                        'logo' =>  'logo',
42
                        'description' =>  'description',
43
                        'type' =>  'type',
44
                        'est_type' =>  'is_type',
45
                        'style_css' =>  'css_style',
46
                        'image_fond' =>  'image_font',
47
                        'date_creation' =>  'date_created',
48
                        'type_especes' =>  'taxo_restriction_type',
49
                        'referentiel' =>  'taxo_restriction_value',
50
                        'type_localisation' =>  'location_type',
51
                        'localisation' =>  'location',
52
                'fond_carte' => 'basemap',
53
                'adresse' => 'is_mandatory_address',
54
                'photo_obligatoire' => 'is_mandatory_photo',
55
                        'milieux' =>  'environment',
56
                        'motscles' =>  'project_tag_name',
57
                        'info' =>  'info',
58
                'id_projet' => 'project_id'
59
        );
60
 
61
        private $correspondance_champs_etendus = array(
62
                        "key" => "field_id",
63
                        "element" => "data_type",
64
                        "mandatory" => "is_mandatory",
65
                        "unit" => "unit",
66
                        "is_visible" => "is_visible"
67
        );
68
 
69
        private $correspondance_champs_etendus_trad = array(
70
                        "key" => "extended_field_id",
71
                        "name" => "label",
72
                        "description" => "description",
73
                        "fieldValues" => "default_value",
74
                        "help" => "help"
75
        );
3092 delphine 76
 
3890 idir 77
        public function getRessource() {
78
                return $this->getElement(array());
79
        }
3092 delphine 80
 
3890 idir 81
        /**
82
         * Méthode appelée avec une requête de type GET.
83
         */
84
        public function getElement($params = array()) {
85
                switch(@strtolower($params[0])) {
86
                case 'widget':
87
                        $this->getWidget();
88
                        break;
89
                case 'champsetendus';
90
                        $this->getChampsEtendus();
91
                        break;
92
                default:
93
                        $this->getWidget();
94
                }
95
        }
96
 
97
 
98
        public function createElement($requeteDonnees) {
99
                unset($requeteDonnees['signup_submit']);
100
                if (isset($requeteDonnees['champs-supp'])) {
101
                        $gestionchamps = new GestionChampsEtendus2($this->config);
102
                        $champs = $this->traiterCorrespondanceChampsEtendusInterfaceBD($requeteDonnees); //var_dump($champs);exit;
103
                        $liste = $gestionchamps->ajouterParProjet($champs);
104
                        unset($requeteDonnees['champs-supp']);
105
                }
106
                $requeteDonnees['est_type'] = (isset($requeteDonnees['est_type']) && $requeteDonnees['est_type']== "on") ? 1 : 0;
107
                $manager = new GestionWidget($this->config);
108
                $requeteDonnees = $this->traiterCorresponceConfigWidgetInterfaceBD($requeteDonnees);
109
                $retour = $manager->ajouterWidget($requeteDonnees);
3193 delphine 110
 
3890 idir 111
                $this->envoyerJson($retour);
3092 delphine 112
 
3890 idir 113
        }
114
 
115
        public function updateElement($uid,$params) {
116
                $retour = "";
117
                if (isset($params['projet']) && isset($params['langue'])) {
118
                    if (isset($params['champs-supp'])) {
119
                        $gestionchamps = new GestionChampsEtendus2($this->config);
120
                        $champs = $this->traiterCorrespondanceChampsEtendusInterfaceBD($params); //var_dump($champs);exit;
121
                        $liste = $gestionchamps->modifierParProjet($champs, $params['langue']);
122
                        unset($params['champs-supp']);
123
                    }
124
                    $manager = new GestionWidget($this->config);
125
                    $params['est_type'] = (isset($params['est_type']) && $params['est_type']== "on") ? 1 : 0;
126
                    $requeteDonnees = $this->traiterCorresponceConfigWidgetInterfaceBD($params);
127
                        $retour = $manager->modifierWidget($params['projet'], $params['langue'], $requeteDonnees);
128
 
129
                }
130
                $this->envoyerJson($retour);
131
                return "ff";
132
 
133
        }
3092 delphine 134
 
3890 idir 135
        private function getWidget() {
136
                $criteres = $this->traiterParametresAutorises($_GET);
137
                $manager = new GestionWidget($this->config);
138
                $liste = $manager->obtenirWidget($criteres);
139
                $liste = $this->traiterCorresponceConfigWidgetBDInterface($liste);
3092 delphine 140
 
3890 idir 141
                $this->envoyerJson($liste);
142
        }
143
 
144
        private function getChampsEtendus() {
145
                $champs = new GestionChampsEtendus2($this->config);
146
                $projet = (isset($_GET['projet'])) ? $_GET['projet'] : "";
147
                $langue = (isset($_GET['langue'])) ? $_GET['langue'] : "fr";
148
                $liste = $champs->consulterProjetChampsEtendus($projet, $langue);
149
                $liste = $this->traiterCorrespondanceChampsEtendusBDInterface($liste, $projet);
150
 
151
                $this->envoyerJson($liste);
152
        }
3092 delphine 153
 
154
 
3890 idir 155
        protected function traiterParametresAutorises(Array $parametres) {
156
                $parametres_traites = array();
157
 
158
                foreach($parametres as $cle => $valeur) {
159
                        if(is_string($valeur) && !trim($valeur)) continue;
160
                        if(isset($this->parametres_autorises[$cle])) {
161
                                $parametres_traites[$this->parametres_autorises[$cle]] = $valeur;
162
                        }
163
                }
164
                return $parametres_traites;
165
        }
166
 
167
        protected function traiterCorresponceConfigWidgetBDInterface(Array $widgets) {
168
                $parametres_traites = array();
169
                $corresp = array_flip($this->correspondance_config_widget);
170
                foreach($widgets as $id => $widget) {
171
                        foreach($widget as $cle => $valeur) {
172
                                if(is_string($valeur) && !trim($valeur)) continue;
173
                                if(isset($corresp[$cle])) {
174
                                        $parametres_traites[$id][$corresp[$cle]] = $valeur;
175
                                }
176
                        }
177
                }
178
                return $parametres_traites;
179
        }
180
 
181
        protected function traiterCorresponceConfigWidgetInterfaceBD(Array $parametres) {
182
                $parametres_traites = array();
183
                $corresp = $this->correspondance_config_widget;
184
                foreach($parametres as $cle => $valeur) {
185
                                if(is_string($valeur) && !trim($valeur) && $valeur !== '0') $valeur=NULL;
186
                                if(isset($corresp[$cle])) {
187
                                        $parametres_traites[$corresp[$cle]] = $valeur;
188
                                }
189
                        }
190
                return $parametres_traites;
191
        }
192
 
193
        protected function traiterCorrespondanceChampsEtendusInterfaceBD(Array $champsinterface) {
194
                $champsrequete = array(); $i = 0;
195
                $champssupp = json_decode($champsinterface['champs-supp'], true);
196
                // pour chaque champs-supp, mettre correspondance extended field et extended field trad
197
                foreach ($champssupp as $champ) {
198
                        $champsrequete['ce'][$i]['project'] = $champsrequete['cet'][$i]['project'] = $champsinterface['projet'];
199
                        $champsrequete['cet'][$i]['language_iso_code'] = isset($champsinterface['langue']) && $champsinterface['langue'] != "" ? $champsinterface['langue'] : "fr";
200
                        // pour la table extended fiels champs interface => champs bd
201
                        foreach ($this->correspondance_champs_etendus as $ci => $ce) {
202
                                if (isset($champ[$ci]) && $champ[$ci] != "") {
203
                                        $champsrequete['ce'][$i][$ce] = $champ[$ci];
204
                                } else {
205
                                        if ($ci == "mandatory" || $ci == "is_visible") {
206
                                                $champsrequete['ce'][$i][$ce] = "0";
207
                                        } else {
208
                                                $champsrequete['ce'][$i][$ce] = "";
209
                                        }
210
                                }
211
                        }
212
                        //$champsrequete['ce'][$i]["is_visible"] = "1";
213
                        // pour la table extended fiels trad champs interface => champs bd
214
                        foreach ($this->correspondance_champs_etendus_trad as $cit => $cr) {
215
                                if (isset($champ[$cit]) && is_array($champ[$cit])) {
216
                                        $champsrequete['cet'][$i][$cr] = json_encode($champ[$cit]);
217
                                } elseif (isset($champ[$cit]) && $champ[$cit] != "") {
218
                                        $champsrequete['cet'][$i][$cr] = $champ[$cit];
219
                                } else {
220
                                        $champsrequete['cet'][$i][$cr] = "";
221
                                }
222
                        }
223
                        $i++;
224
                }
225
                return $champsrequete;
226
        }
227
        protected function traiterCorrespondanceChampsEtendusBDInterface(Array $champsrequete, $projet = "null") {
228
                $champssupp = array(); $i = 0;
229
                foreach ($champsrequete as $champ) {
230
                        $champssupp[$projet]['projet'] = $champ['project'];
231
                        $champssupp[$projet]['langue'] = $champ['language_iso_code'];
232
                        // pour la table extended fiels champs interface => champs bd
233
                        foreach ($this->correspondance_champs_etendus as $ci => $ce) {
234
                                if (isset($champ[$ce]) && $champ[$ce] != "") {
235
                                    $champssupp[$projet]['champs-supp'][$i][$ci] = $champ[$ce];
236
                                } else {
237
                                    $champssupp[$projet]['champs-supp'][$i][$ci]= "";
238
                                }
239
                        }
240
                        // pour la table extended fiels trad champs interface => champs bd
241
                        foreach ($this->correspondance_champs_etendus_trad as $cet => $cr) {
242
                                if (isset($champ[$cr]) && $champ[$cr] != "") {
243
                                    $champssupp[$projet]['champs-supp'][$i][$cet]= $champ[$cr];
244
                                } else {
245
                                    $champssupp[$projet]['champs-supp'][$i][$cet]="";
246
                                }
247
                        }$i++;
248
                }
249
                return $champssupp;
250
        }
3092 delphine 251
 
252
 
253
}
3890 idir 254
?>