Subversion Repositories eFlore/Applications.del

Rev

Rev 2202 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2202 Rev 2227
Line 3... Line 3...
3
 * Le web service plantnet récupère toutes les infos de la vue del_plantnet.
3
 * Le web service plantnet récupère toutes les infos de la vue del_plantnet.
4
 * Ordonées par date de modification.
4
 * Ordonées par date de modification.
5
 * Les images sont regroupées en observations.
5
 * Les images sont regroupées en observations.
6
 * Les tags, les votes et les propositions de determinations sont intégrés à l'observation.
6
 * Les tags, les votes et les propositions de determinations sont intégrés à l'observation.
7
 *
7
 *
-
 
8
 * Paramètres: date.debut et date.fin (unixtime en secondes), navigation.limite (10 par défaut), navigation.depart, ordre (DESC par défaut)
-
 
9
 * Ne pas Oublier l'api key dans le header $_SERVER['HTTP_API_KEY']
-
 
10
 *
8
 * @category DEL
11
 * @category DEL
9
 * @package Services
12
 * @package Services
10
 * @subpackage Plantnet
13
 * @subpackage Plantnet
11
 * @version 0.1
14
 * @version 0.1
12
 * @author Mathias CHOUET <mathias@tela-botanica.org>
15
 * @author Mathias CHOUET <mathias@tela-botanica.org>
Line 52... Line 55...
52
		// initialiserRessourcesEtParametres()
55
		// initialiserRessourcesEtParametres()
53
		$this->ressources = $ressources;
56
		$this->ressources = $ressources;
54
		$this->parametres = $parametres;
57
		$this->parametres = $parametres;
Line 55... Line 58...
55
 
58
 
56
		if (!isset($parametres['date.debut'])) {
59
		if (!isset($parametres['date.debut'])) {
57
			$this->parametres['date.debut'] = '1900-01-01';
60
			$this->parametres['date.debut'] = '0';
Line 58... Line 61...
58
		}
61
		}
59
 
62
 
60
		if (!isset($parametres['date.fin'])) {
63
		if (!isset($parametres['date.fin'])) {
Line 61... Line 64...
61
			$this->parametres['date.fin'] = date('Y-m-d');
64
			$this->parametres['date.fin'] = time();
62
		}
65
		}
63
 
66
 
Line 93... Line 96...
93
	/*-------------------------------------------------------------------------------
96
	/*-------------------------------------------------------------------------------
94
								CHARGEMENT DES IMAGES
97
								CHARGEMENT DES IMAGES
95
	--------------------------------------------------------------------------------*/
98
	--------------------------------------------------------------------------------*/
Line 96... Line 99...
96
 
99
 
97
	private function getIdsObsImg() {
100
	private function getIdsObsImg() {
98
		$date_debut = "'{$this->parametres['date.debut']}'";
101
        $date_debut = date('Y-m-d H:i:s', $this->parametres['date.debut']);
99
		$date_fin = "'{$this->parametres['date.fin']}'";
102
        $date_fin = date('Y-m-d H:i:s', $this->parametres['date.fin']);
100
		$limite = @min(intval($this->parametres['navigation.limite']), 1000);
-
 
101
		$limite = $limite ? $limite : 100; // 0 => 10
103
        $limite = isset($this->parametres['navigation.limite']) ? intval($this->parametres['navigation.limite']) : 10;
102
		$depart = intval(@$this->parametres['navigation.depart']);
104
		$depart = intval(@$this->parametres['navigation.depart']);
-
 
105
		$ordre = $this->parametres['ordre'];
-
 
106
        $date_debut = "'{$date_debut}'";
Line 103... Line 107...
103
		$ordre = $this->parametres['ordre'];
107
        $date_fin = "'{$date_fin}'";
104
 
108
 
-
 
109
		$requete =
105
		$requete =
110
			'SELECT SQL_CALC_FOUND_ROWS p.id_observation, GROUP_CONCAT(DISTINCT p.id_image) as id_image, '.
-
 
111
			'iv.moyenne AS moyenne_votes, '.
106
			'SELECT SQL_CALC_FOUND_ROWS p.id_observation, p.id_image, '.
112
			'iv.nb_votes AS nb_votes, '.
107
			'GROUP_CONCAT(iv.valeur) AS votes, '.
113
			'iv.nb_points AS nb_points_votes, '.
108
			'GROUP_CONCAT(DISTINCT tag) AS tags, '.
-
 
109
			'modif_date '.
114
			'GROUP_CONCAT(DISTINCT it.tag) AS del_image_tags, '.
110
 
115
			'modif_date '.
111
			'FROM del_plantnet AS p '.
116
			'FROM del_plantnet AS p '.
112
			'	JOIN del_observation_modif_date '.
117
			'	JOIN del_observation_modif_date '.
113
			'		ON (p.id_observation = del_observation_modif_date.id_observation '.
118
			'		ON (p.id_observation = del_observation_modif_date.id_observation '.
114
			'		AND modif_date >= '.date('U', strtotime($date_debut)).') '.
119
			'		AND modif_date >= '.$date_debut.' '.
115
			'		AND modif_date <= '.date('U', strtotime($date_fin)).') '.
120
			'		AND modif_date <= '.$date_fin.') '.
116
			'	LEFT JOIN del_image_vote AS iv '.
121
			'	LEFT JOIN del_image_stat AS iv '.
117
			'		ON (id_image = iv.ce_image AND iv.ce_protocole = 3) '.
122
			'		ON (id_image = iv.ce_image AND iv.ce_protocole = 3) '.
118
			'	LEFT JOIN del_image_tag AS it '.
123
			'	LEFT JOIN del_image_tag AS it '.
119
			'		ON (id_image = it.ce_image AND it.actif = 1) '.
124
			'		ON (id_image = it.ce_image AND it.actif = 1) '.
120
			'	LEFT JOIN del_commentaire AS c '.
125
			'	LEFT JOIN del_commentaire AS c '.
121
			'		ON (p.id_observation = c.ce_observation) '.
126
			'		ON (p.id_observation = c.ce_observation) '.
122
			'	LEFT JOIN del_commentaire_vote AS cv '.
127
			'	LEFT JOIN del_commentaire_vote AS cv '.
123
			'		ON (c.id_commentaire = cv.ce_proposition) '.
128
			'		ON (c.id_commentaire = cv.ce_proposition) '.
124
			'GROUP BY id_image, p.id_observation '.
129
			'GROUP BY p.id_observation '.
125
			'ORDER BY modif_date ' . $ordre . ' '.
130
			'ORDER BY modif_date ' . $ordre . ' '.
126
			'LIMIT '.$depart.', '.$limite.
-
 
127
			' -- '.__FILE__.':'.__LINE__;
131
			'LIMIT '.$depart.', '.$limite.
-
 
132
			' -- '.__FILE__.':'.__LINE__;
128
 
133
		return $this->bdd->recupererTous($requete);
Line 129... Line 134...
129
		return $this->bdd->recupererTous($requete);
134
        // On récupère id_obs, id_image, votes, tags, modif_date
130
	}
135
	}
131
 
136
 
Line 144... Line 149...
144
			$idsImg[] = $id;
149
			$idsImg[] = $id;
145
		}
150
		}
146
		$idsImgConcat = implode(',', $idsImg);
151
		$idsImgConcat = implode(',', $idsImg);
Line 147... Line 152...
147
 
152
 
148
		$requete = 'SELECT '.
153
		$requete = 'SELECT '.
149
			'p.id_observation, p.id_image, '.
154
			'p.id_observation, p.id_plantnet, p.id_image, '.
150
			'cp.id_plantnet, ' .
155
			'cp.plant_net_occurrence_id, ' .
151
			'p.nom_sel, '.
156
			'p.nom_sel, p.nom_sel_nn, p.nom_ret, p.nom_ret_nn,'.
152
			'p.nom_referentiel, p.nom_ret, p.famille, '.
157
			'p.nom_referentiel, p.famille, '.
153
			'p.zone_geo, p.latitude, p.longitude, '.
158
			'p.zone_geo, p.latitude, p.longitude,'.
154
			'p.date_observation, p.date_creation, p.date_transmission, '.
159
			'p.date_observation, p.date_created, p.date_published, '.
155
			'p.mots_cles_texte, '.
160
			'p.type_donnees, p.identiplante_score, p.is_identiplante_validated, p.mots_cles_cel_obs, p.programme, '.
156
			'p.ce_utilisateur, p.prenom_utilisateur, p.nom_utilisateur, p.courriel_utilisateur, '.
161
			'p.ce_utilisateur, p.courriel_utilisateur, '.
157
			'p.i_mots_cles_texte AS mots_cles_texte_image, p.nom_original AS nom_image '.
162
			'p.original_name AS nom_image, p.i_date_shot AS date_shot, p.i_date_updated AS image_updated, p.mots_cles_cel_image AS  mots_cles_cel_image '.
158
			'FROM del_plantnet AS p '.
163
			'FROM del_plantnet AS p '.
159
			'LEFT JOIN tb_cel.cel_plantnet AS cp ON p.id_observation = cp.id_observation '.
164
			'LEFT JOIN tb_new_cel.pn_tb_pair AS cp ON p.id_observation = cp.occurrence_id '.
160
			"WHERE id_image IN ($idsImgConcat) ".
165
			"WHERE id_image IN ($idsImgConcat) ".
161
			' -- '.__FILE__.':'.__LINE__;
166
			' -- '.__FILE__.':'.__LINE__;
162
		// recuperer les donnees
167
		// recuperer les donnees
Line 179... Line 184...
179
		// regroupe les observations
184
		// regroupe les observations
180
		$obs = array();
185
		$obs = array();
181
		$imgCelTpl = $this->conteneur->getParametre('cel_img_url_tpl');
186
		$imgCelTpl = $this->conteneur->getParametre('cel_img_url_tpl');
182
		foreach ($this->idsObsImg as $ids) {
187
		foreach ($this->idsObsImg as $ids) {
183
			$idobs = $ids['id_observation'];
188
			$idobs = $ids['id_observation'];
184
			$idimg = $ids['id_image'];
189
			$idimg = explode(',', $ids['id_image']);
Line 185... Line 190...
185
 
190
 
Line 186... Line 191...
186
			$imgdata = $this->infosObsImg[$idimg];
191
            $obs[$idobs]['id_observation'] = $idobs;
-
 
192
 
187
 
193
            foreach ($idimg as $image){
188
			if (!isset($obs[$idobs])) {
-
 
189
				$obs[$idobs] = array();
194
                $imgInfos = null;
190
			}
195
                $imgdata = null;
191
 
196
 
-
 
197
                $imgdata = $this->infosObsImg[$image];
192
			$obs[$idobs]['id_observation'] = $idobs;
198
                $imgInfos = $this->recupererInfosParImage($image);
193
			$obs[$idobs]['id_plantnet'] = $imgdata['id_plantnet'];
199
 
-
 
200
                if (!isset($obs[$idobs])) {
-
 
201
                    $obs[$idobs] = array();
194
			$obs[$idobs]['auteur_id'] = $imgdata['ce_utilisateur'];
202
                }
195
			$obs[$idobs]['auteur_prenom'] = $imgdata['prenom_utilisateur'];
203
 
196
			$obs[$idobs]['auteur_nom'] = $imgdata['nom_utilisateur'];
204
                $obs[$idobs]['id_plantnet'] = $imgdata['id_plantnet'];
197
			$obs[$idobs]['auteur_courriel'] = $imgdata['courriel_utilisateur'];
205
                $obs[$idobs]['auteur_courriel'] = $imgdata['courriel_utilisateur'];
-
 
206
 
198
 
207
                $obs[$idobs]['mots_cles_cel_obs'] = $imgdata['mots_cles_cel_obs'];
199
			$obs[$idobs]['mots_cles_obs_cel'] = $this->formaterMotsClesCel($imgdata['mots_cles_texte']);
208
                $obs[$idobs]['programme'] = $imgdata['programme'];
200
 
209
 
-
 
210
                $obs[$idobs]['date_observation'] = $imgdata['date_observation'];
201
			$obs[$idobs]['date_observation'] = $imgdata['date_observation'];
211
                $obs[$idobs]['date_creation'] = $imgdata['date_created'];
202
			$obs[$idobs]['date_publication'] = $imgdata['date_transmission'];
212
                $obs[$idobs]['date_changement'] = $ids['modif_date'];
-
 
213
                $obs[$idobs]['date_publication'] = $imgdata['date_published'];
-
 
214
                $obs[$idobs]['type_donnees'] = $imgdata['type_donnees'];
203
			$obs[$idobs]['date_creation'] = $imgdata['date_creation'];
215
                $obs[$idobs]['identiplante_score'] = $imgdata['identiplante_score'];
204
			$obs[$idobs]['date_changement'] = $ids['modif_date'];
216
                $obs[$idobs]['is_identiplante_validated'] = $imgdata['is_identiplante_validated'];
205
 
217
 
206
			$obs[$idobs]['nom_sel'] = $imgdata['nom_sel'];
218
                $obs[$idobs]['nom_sel'] = $imgdata['nom_sel'];
207
			$obs[$idobs]['nom_referentiel'] = $imgdata['nom_referentiel'];
219
                $obs[$idobs]['nom_sel_nn'] = $imgdata['nom_sel_nn'];
208
			$obs[$idobs]['nom_ret'] = $imgdata['nom_ret'];
220
                $obs[$idobs]['nom_referentiel'] = $imgdata['nom_referentiel'];
209
			//$obs[$idobs]['nn'] = $imgdata['nom_ret_nn'];
221
                $obs[$idobs]['nom_ret'] = $imgdata['nom_ret'];
210
			//$obs[$idobs]['nt'] = $imgdata['nt'];
222
                $obs[$idobs]['nom_ret_nn'] = $imgdata['nom_ret_nn'];
211
			$obs[$idobs]['famille'] = $imgdata['famille'];
223
                $obs[$idobs]['famille'] = $imgdata['famille'];
212
 
224
 
213
			$obs[$idobs]['zone_geo'] = $imgdata['zone_geo'];
225
                $obs[$idobs]['zone_geo'] = $imgdata['zone_geo'];
214
			$obs[$idobs]['latitude'] = floatval($imgdata['latitude']);
226
                $obs[$idobs]['latitude'] = $imgdata['latitude'];
215
			$obs[$idobs]['longitude'] = floatval($imgdata['longitude']);
227
                $obs[$idobs]['longitude'] = $imgdata['longitude'];
216
 
228
 
-
 
229
                if (!isset($obs[$idobs]['images'])) {
217
			if (!isset($obs[$idobs]['images'])) {
230
                    $obs[$idobs]['images'] = array();
-
 
231
                }
-
 
232
 
-
 
233
                $img_obj = array(
-
 
234
                    'id_image' => $image,
-
 
235
                    'nom_image' => $imgdata['nom_image'],
-
 
236
                    'image_updated' => $imgdata['image_updated'],
-
 
237
                    'date_shot' => $imgdata['date_shot'],
-
 
238
                    'mots_cles_cel_image' => $imgInfos[0]['mots_cles_cel_image'],
-
 
239
                    'url' => sprintf($imgCelTpl, $idimg, 'O'),
-
 
240
                    'votes' => [
-
 
241
                        'moyenne_votes' => $imgInfos[0]['moyenne_votes'],
-
 
242
                        'nb_votes' => $imgInfos[0]['nb_votes'],
-
 
243
                        'nb_points_votes' => $imgInfos[0]['nb_points_votes'],
-
 
244
                    ],
-
 
245
                    'del_tags' => explode(',', $imgInfos[0]['del_image_tags']),
-
 
246
                );
-
 
247
                // push
Line 218... Line -...
218
				$obs[$idobs]['images'] = array();
-
 
219
			}
-
 
220
 
-
 
221
			$img_obj = array(
-
 
222
				'id_image' => $idimg,
-
 
223
				'nom_image' => $imgdata['nom_image'],
-
 
224
				'url' => sprintf($imgCelTpl, $idimg, 'O'),
-
 
225
				'votes' => array_map('intval', explode(',', $ids['votes'])),
-
 
226
				'tags' => explode(',', $ids['tags']),
-
 
227
				'mots_cles_img_cel' => $this->formaterMotsClesCel($imgdata['mots_cles_texte_image'])
-
 
228
				);
248
                $obs[$idobs]['images'][] = $img_obj;
229
			// push
249
            }
230
			$obs[$idobs]['images'][] = $img_obj;
250
 
Line 231... Line 251...
231
		}
251
		}
Line 314... Line 334...
314
		}
334
		}
315
		$ret = explode(',', implode(',', $result));
335
		$ret = explode(',', implode(',', $result));
316
		return $ret;
336
		return $ret;
317
	}
337
	}
Line -... Line 338...
-
 
338
 
-
 
339
    /**
-
 
340
     * On charge les infos spécifique à chaque image d'une obs
-
 
341
     */
-
 
342
    private function recupererInfosParImage($id_image){
-
 
343
        $requete =
-
 
344
            'SELECT SQL_CALC_FOUND_ROWS p.id_image, '.
-
 
345
            'p.mots_cles_cel_image, '.
-
 
346
            'iv.moyenne AS moyenne_votes, '.
-
 
347
            'iv.nb_votes AS nb_votes, '.
-
 
348
            'iv.nb_points AS nb_points_votes, '.
-
 
349
            'GROUP_CONCAT(DISTINCT it.tag) AS del_image_tags '.
-
 
350
            'FROM del_plantnet_images AS p '.
-
 
351
            '	LEFT JOIN del_image_stat AS iv '.
-
 
352
            '		ON (id_image = iv.ce_image AND iv.ce_protocole = 3) '.
-
 
353
            '	LEFT JOIN del_image_tag AS it '.
-
 
354
            '		ON (id_image = it.ce_image AND it.actif = 1) '.
-
 
355
            '		WHERE id_image = '. $id_image .' '.
-
 
356
            'GROUP BY p.id_image '.
-
 
357
            ' -- '.__FILE__.':'.__LINE__;
-
 
358
        return $this->bdd->recupererTous($requete);
318
 
359
    }