1390 |
raphael |
1 |
<?php
|
1840 |
jpm |
2 |
// declare(encoding='UTF-8');
|
1390 |
raphael |
3 |
/**
|
1840 |
jpm |
4 |
* Listes des images avec leurs infos liées.
|
1422 |
raphael |
5 |
*
|
1840 |
jpm |
6 |
* del/services/0.1/images?navigation.depart=0&navigation.limite=12&tri=votes&ordre=desc
|
|
|
7 |
* del/services/0.1/images?navigation.depart=0&navigation.limite=12&tri=votes&ordre=desc&masque=plop
|
|
|
8 |
* del/services/0.1/images?navigation.depart=0&navigation.limite=12&tri=votes&ordre=desc&protocole=3
|
|
|
9 |
* del/services/0.1/images?navigation.depart=0&navigation.limite=12&tri=votes&ordre=desc&protocole=3&masque=plop
|
1422 |
raphael |
10 |
*
|
1840 |
jpm |
11 |
* @category DEL
|
|
|
12 |
* @package Services
|
|
|
13 |
* @subpackage Images
|
|
|
14 |
* @version 0.1
|
|
|
15 |
* @author Mathias CHOUET <mathias@tela-botanica.org>
|
|
|
16 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
17 |
* @author Aurelien PERONNET <aurelien@tela-botanica.org>
|
|
|
18 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
|
|
19 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
|
|
20 |
* @copyright 1999-2014 Tela Botanica <accueil@tela-botanica.org>
|
1390 |
raphael |
21 |
*/
|
|
|
22 |
|
1840 |
jpm |
23 |
//restore_error_handler();
|
|
|
24 |
//restore_exception_handler();
|
|
|
25 |
//error_reporting(E_ALL);
|
1514 |
aurelien |
26 |
class ListeImages {
|
1390 |
raphael |
27 |
|
1840 |
jpm |
28 |
private $conteneur;
|
|
|
29 |
private $bdd;
|
|
|
30 |
private $filtrage;
|
|
|
31 |
private $sql;
|
|
|
32 |
private $navigation;
|
|
|
33 |
private $paramsFiltres = array();
|
|
|
34 |
private $mappings = array();
|
1863 |
jpm |
35 |
private $idsImagesOrdonnees = array();
|
|
|
36 |
private $infosImagesOrdonnees = array();
|
1390 |
raphael |
37 |
|
1827 |
jpm |
38 |
public function __construct(Conteneur $conteneur) {
|
|
|
39 |
$this->conteneur = $conteneur;
|
|
|
40 |
$this->bdd = $this->conteneur->getBdd();
|
1840 |
jpm |
41 |
$this->filtrage = $this->conteneur->getParametresFiltrage();
|
|
|
42 |
$this->sql = $this->conteneur->getSql();
|
|
|
43 |
$this->navigation = $this->conteneur->getNavigation();
|
|
|
44 |
|
|
|
45 |
$this->mappings['observations'] = $this->conteneur->getParametreTableau('observations.mapping');
|
|
|
46 |
$this->mappings['images'] = $this->conteneur->getParametreTableau('images.mapping');
|
1604 |
jpm |
47 |
}
|
1390 |
raphael |
48 |
|
1604 |
jpm |
49 |
public function consulter($ressources, $parametres) {
|
1840 |
jpm |
50 |
$this->paramsFiltres = $this->filtrage->filtrerUrlParamsAppliImg();
|
|
|
51 |
$this->sql->setParametres($this->paramsFiltres);
|
|
|
52 |
$this->sql->ajouterContraintes();
|
|
|
53 |
$this->sql->ajouterConstrainteAppliImg();
|
|
|
54 |
$this->sql->definirOrdreSqlAppliImg();
|
1422 |
raphael |
55 |
|
1863 |
jpm |
56 |
$this->idsImagesOrdonnees = $this->getIdImages();
|
1845 |
jpm |
57 |
$this->navigation->setTotal($this->sql->getTotalLignesTrouvees());
|
1422 |
raphael |
58 |
|
1840 |
jpm |
59 |
// Ce n'est pas la peine de continuer s'il n'y a pas eu de résultats
|
|
|
60 |
$resultat = new ResultatService();
|
|
|
61 |
$resultat->corps = array('entete' => $this->navigation->getEntete(), 'resultats' => array());
|
1863 |
jpm |
62 |
if (count($this->idsImagesOrdonnees) > 0) {
|
|
|
63 |
$this->infosImagesOrdonnees = $this->getInfosImages();
|
|
|
64 |
$images = $this->reformaterImagesDoubleIndex();
|
1390 |
raphael |
65 |
|
1840 |
jpm |
66 |
// Chargement des votes pour ces images et pour *tous* les protocoles
|
1863 |
jpm |
67 |
$votes = $this->sql->getVotesDesImages($this->idsImagesOrdonnees);
|
1840 |
jpm |
68 |
if ($votes) {
|
1863 |
jpm |
69 |
// ATTENTION : $images est récupéré par référence !
|
|
|
70 |
$this->sql->ajouterInfosVotesProtocoles($votes, $images);
|
1840 |
jpm |
71 |
}
|
1422 |
raphael |
72 |
|
1840 |
jpm |
73 |
$resultat->corps = array(
|
|
|
74 |
'entete' => $this->navigation->getEntete(),
|
1863 |
jpm |
75 |
'resultats' => array_values($images));
|
1604 |
jpm |
76 |
}
|
|
|
77 |
return $resultat;
|
|
|
78 |
}
|
1495 |
raphael |
79 |
|
1840 |
jpm |
80 |
private function getIdImages() {
|
|
|
81 |
$requete = 'SELECT SQL_CALC_FOUND_ROWS id_image '.
|
|
|
82 |
'FROM v_del_image AS vdi '.
|
|
|
83 |
$this->sql->getJoin().
|
|
|
84 |
'WHERE '.$this->sql->getWhere().
|
|
|
85 |
$this->sql->getGroupBy().
|
|
|
86 |
$this->sql->getOrderBy().
|
|
|
87 |
$this->sql->getLimit().
|
|
|
88 |
' -- '.__FILE__.':'.__LINE__;
|
1863 |
jpm |
89 |
//Debug::printr($requete);
|
1840 |
jpm |
90 |
$resultats = $this->bdd->recupererTous($requete);
|
|
|
91 |
$idImgs = array();
|
|
|
92 |
if ($resultats !== false ) {
|
|
|
93 |
foreach ($resultats as $resultat) {
|
|
|
94 |
$idImgs[] = $resultat['id_image'];
|
1604 |
jpm |
95 |
}
|
1584 |
mathias |
96 |
}
|
1840 |
jpm |
97 |
return $idImgs;
|
1604 |
jpm |
98 |
}
|
1486 |
raphael |
99 |
|
1863 |
jpm |
100 |
private function getInfosImages() {
|
1840 |
jpm |
101 |
$obsChamps = $this->sql->getAliasDesChamps($this->mappings['observations']);
|
|
|
102 |
$imgChamps = $this->sql->getAliasDesChamps($this->mappings['images']);
|
1863 |
jpm |
103 |
$idImgsConcat = implode(',', $this->idsImagesOrdonnees);
|
1491 |
raphael |
104 |
|
1863 |
jpm |
105 |
$requete = "SELECT $obsChamps, $imgChamps ".
|
1840 |
jpm |
106 |
'FROM v_del_image '.
|
|
|
107 |
"WHERE id_image IN ($idImgsConcat) ".
|
|
|
108 |
'-- '.__FILE__.':'.__LINE__;
|
|
|
109 |
return $this->bdd->recupererTous($requete);
|
1495 |
raphael |
110 |
}
|
1486 |
raphael |
111 |
|
1604 |
jpm |
112 |
// cf Observation::reformateObservationSimpleIndex() et ListeObservations::reformateObservation()
|
|
|
113 |
// (trop de variétés de formatage, à unifier côté client pour unifier côté backend ...)
|
1863 |
jpm |
114 |
private function reformaterImagesDoubleIndex() {
|
1840 |
jpm |
115 |
$urlImgTpl = $this->conteneur->getParametre('cel_img_url_tpl');
|
|
|
116 |
$imageFormat = isset($this->paramsFiltres['format']) ? $this->paramsFiltres['format'] : 'XL';
|
1863 |
jpm |
117 |
$obs_merged = array_flip($this->idsImagesOrdonnees);
|
|
|
118 |
foreach ($this->infosImagesOrdonnees as $infos) {
|
|
|
119 |
$id = $infos['id_image'];
|
1604 |
jpm |
120 |
// ainsi nous utilisons deux tableaux: le final, indexé par couple d'id(image-obs)
|
|
|
121 |
// et celui indexé par simple id_image qui est fort utile pour mapVotesToImages()
|
|
|
122 |
// mais tout deux partage leur référence à "protocole"
|
|
|
123 |
$image = array(
|
1863 |
jpm |
124 |
'id_image' => $id,
|
1840 |
jpm |
125 |
'binaire.href' => sprintf($urlImgTpl, $infos['id_image'], $imageFormat),
|
1863 |
jpm |
126 |
'mots_cles_texte' => isset($infos['mots_cles_texte_img']) ? $infos['mots_cles_texte_img'] : null,
|
1604 |
jpm |
127 |
);
|
1863 |
jpm |
128 |
unset($infos['id_image'], $infos['mots_cles_texte_img']);
|
1845 |
jpm |
129 |
|
1863 |
jpm |
130 |
$obs_merged[$id] = $image;
|
1840 |
jpm |
131 |
$obs_merged[$id]['observation'] = $infos;
|
1604 |
jpm |
132 |
$obs_merged[$id]['protocoles_votes'] = array();
|
1564 |
mathias |
133 |
}
|
1863 |
jpm |
134 |
return $obs_merged;
|
1604 |
jpm |
135 |
}
|
1490 |
raphael |
136 |
|
1840 |
jpm |
137 |
/**
|
|
|
138 |
* Supprime une image directement dans le CEL en faisant un appel à un web service du CEL.
|
|
|
139 |
* Utilisé uniquement par les admins.
|
|
|
140 |
*
|
|
|
141 |
* @param array $ressources tableau des informations contenues dans l'url après le nom du service
|
|
|
142 |
* @param array $parametres contenu du post
|
|
|
143 |
* @return mixed Chaine "OK" (en majuscule) en cas de succès, booléen "false" en cas d'échec
|
|
|
144 |
*/
|
|
|
145 |
public function supprimer($ressources) {
|
|
|
146 |
$controlAcces = $this->conteneur->getControleAcces();
|
|
|
147 |
$controlAcces->etreUtilisateurAvecDroitAdmin();
|
1490 |
raphael |
148 |
|
1840 |
jpm |
149 |
$urlServiceBase = $this->conteneur->getParametre('urlServiceCelImage');
|
|
|
150 |
$idImage = $ressources[0];
|
|
|
151 |
$url = $urlServiceBase.$idImage;
|
1604 |
jpm |
152 |
|
1840 |
jpm |
153 |
$clientHttp = $this->conteneur->getRestClient();
|
|
|
154 |
$retourCel = $clientHttp->supprimer($url);
|
|
|
155 |
$retour = preg_match('/^OK$/i', $retourCel) ? 'OK' : false;
|
|
|
156 |
return $retour;
|
1604 |
jpm |
157 |
}
|
1827 |
jpm |
158 |
}
|