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();
|
1881 |
jpm |
36 |
private $infosImages = array();
|
1863 |
jpm |
37 |
private $infosImagesOrdonnees = array();
|
1390 |
raphael |
38 |
|
1827 |
jpm |
39 |
public function __construct(Conteneur $conteneur) {
|
|
|
40 |
$this->conteneur = $conteneur;
|
|
|
41 |
$this->bdd = $this->conteneur->getBdd();
|
1840 |
jpm |
42 |
$this->filtrage = $this->conteneur->getParametresFiltrage();
|
|
|
43 |
$this->sql = $this->conteneur->getSql();
|
|
|
44 |
$this->navigation = $this->conteneur->getNavigation();
|
|
|
45 |
|
|
|
46 |
$this->mappings['observations'] = $this->conteneur->getParametreTableau('observations.mapping');
|
|
|
47 |
$this->mappings['images'] = $this->conteneur->getParametreTableau('images.mapping');
|
1604 |
jpm |
48 |
}
|
1390 |
raphael |
49 |
|
1604 |
jpm |
50 |
public function consulter($ressources, $parametres) {
|
1840 |
jpm |
51 |
$this->paramsFiltres = $this->filtrage->filtrerUrlParamsAppliImg();
|
1871 |
jpm |
52 |
$this->sql->setAppli(Sql::APPLI_IMG);
|
1840 |
jpm |
53 |
$this->sql->setParametres($this->paramsFiltres);
|
|
|
54 |
$this->sql->ajouterContraintes();
|
|
|
55 |
$this->sql->ajouterConstrainteAppliImg();
|
|
|
56 |
$this->sql->definirOrdreSqlAppliImg();
|
1422 |
raphael |
57 |
|
1863 |
jpm |
58 |
$this->idsImagesOrdonnees = $this->getIdImages();
|
1845 |
jpm |
59 |
$this->navigation->setTotal($this->sql->getTotalLignesTrouvees());
|
1422 |
raphael |
60 |
|
1840 |
jpm |
61 |
// Ce n'est pas la peine de continuer s'il n'y a pas eu de résultats
|
|
|
62 |
$resultat = new ResultatService();
|
|
|
63 |
$resultat->corps = array('entete' => $this->navigation->getEntete(), 'resultats' => array());
|
1863 |
jpm |
64 |
if (count($this->idsImagesOrdonnees) > 0) {
|
1881 |
jpm |
65 |
$this->infosImages = $this->getInfosImages();
|
|
|
66 |
$this->infosImagesOrdonnees = $this->formaterImages();
|
1390 |
raphael |
67 |
|
1840 |
jpm |
68 |
// Chargement des votes pour ces images et pour *tous* les protocoles
|
1863 |
jpm |
69 |
$votes = $this->sql->getVotesDesImages($this->idsImagesOrdonnees);
|
1840 |
jpm |
70 |
if ($votes) {
|
1863 |
jpm |
71 |
// ATTENTION : $images est récupéré par référence !
|
1881 |
jpm |
72 |
$this->sql->ajouterInfosVotesProtocoles($votes, $this->infosImagesOrdonnees);
|
1840 |
jpm |
73 |
}
|
1422 |
raphael |
74 |
|
1840 |
jpm |
75 |
$resultat->corps = array(
|
|
|
76 |
'entete' => $this->navigation->getEntete(),
|
1881 |
jpm |
77 |
'resultats' => array_values($this->infosImagesOrdonnees));
|
1604 |
jpm |
78 |
}
|
|
|
79 |
return $resultat;
|
|
|
80 |
}
|
1495 |
raphael |
81 |
|
1840 |
jpm |
82 |
private function getIdImages() {
|
1887 |
jpm |
83 |
$requete = 'SELECT SQL_CALC_FOUND_ROWS DISTINCT di.id_image '.
|
1871 |
jpm |
84 |
'FROM del_image AS di '.
|
1840 |
jpm |
85 |
$this->sql->getJoin().
|
|
|
86 |
'WHERE '.$this->sql->getWhere().
|
|
|
87 |
$this->sql->getGroupBy().
|
|
|
88 |
$this->sql->getOrderBy().
|
|
|
89 |
$this->sql->getLimit().
|
|
|
90 |
' -- '.__FILE__.':'.__LINE__;
|
1887 |
jpm |
91 |
// TODO : si le DISCTINCT dans la requête pose des pb de perf, supprimer les doublons d'id à l'aide de PHP
|
1863 |
jpm |
92 |
//Debug::printr($requete);
|
1840 |
jpm |
93 |
$resultats = $this->bdd->recupererTous($requete);
|
|
|
94 |
$idImgs = array();
|
|
|
95 |
if ($resultats !== false ) {
|
|
|
96 |
foreach ($resultats as $resultat) {
|
|
|
97 |
$idImgs[] = $resultat['id_image'];
|
1604 |
jpm |
98 |
}
|
1584 |
mathias |
99 |
}
|
1840 |
jpm |
100 |
return $idImgs;
|
1604 |
jpm |
101 |
}
|
1486 |
raphael |
102 |
|
1863 |
jpm |
103 |
private function getInfosImages() {
|
1871 |
jpm |
104 |
$obsChamps = $this->sql->getAliasDesChamps($this->mappings['observations'], null, 'do');
|
|
|
105 |
$imgChamps = $this->sql->getAliasDesChamps($this->mappings['images'], null, 'di');
|
1863 |
jpm |
106 |
$idImgsConcat = implode(',', $this->idsImagesOrdonnees);
|
1491 |
raphael |
107 |
|
1863 |
jpm |
108 |
$requete = "SELECT $obsChamps, $imgChamps ".
|
1871 |
jpm |
109 |
'FROM del_image AS di '.
|
|
|
110 |
' LEFT JOIN del_observation AS do ON (di.ce_observation = do.id_observation) '.
|
|
|
111 |
"WHERE di.id_image IN ($idImgsConcat) ".
|
1840 |
jpm |
112 |
'-- '.__FILE__.':'.__LINE__;
|
1871 |
jpm |
113 |
//Debug::printr($requete);
|
1840 |
jpm |
114 |
return $this->bdd->recupererTous($requete);
|
1495 |
raphael |
115 |
}
|
1486 |
raphael |
116 |
|
1604 |
jpm |
117 |
// cf Observation::reformateObservationSimpleIndex() et ListeObservations::reformateObservation()
|
|
|
118 |
// (trop de variétés de formatage, à unifier côté client pour unifier côté backend ...)
|
1881 |
jpm |
119 |
private function formaterImages() {
|
1840 |
jpm |
120 |
$urlImgTpl = $this->conteneur->getParametre('cel_img_url_tpl');
|
|
|
121 |
$imageFormat = isset($this->paramsFiltres['format']) ? $this->paramsFiltres['format'] : 'XL';
|
1881 |
jpm |
122 |
$obsFormatees = array_flip($this->idsImagesOrdonnees);// Permet de garder l'ordre de sortie !
|
|
|
123 |
foreach ($this->infosImages as $infos) {
|
1863 |
jpm |
124 |
$id = $infos['id_image'];
|
1604 |
jpm |
125 |
// ainsi nous utilisons deux tableaux: le final, indexé par couple d'id(image-obs)
|
|
|
126 |
// et celui indexé par simple id_image qui est fort utile pour mapVotesToImages()
|
|
|
127 |
// mais tout deux partage leur référence à "protocole"
|
|
|
128 |
$image = array(
|
1863 |
jpm |
129 |
'id_image' => $id,
|
1840 |
jpm |
130 |
'binaire.href' => sprintf($urlImgTpl, $infos['id_image'], $imageFormat),
|
1871 |
jpm |
131 |
'mots_cles_texte' => isset($infos['mots_cles_texte']) ? $infos['mots_cles_texte'] : null,
|
1604 |
jpm |
132 |
);
|
1871 |
jpm |
133 |
unset($infos['id_image'], $infos['mots_cles_texte']);
|
1845 |
jpm |
134 |
|
1881 |
jpm |
135 |
$obsFormatees[$id] = $image;
|
|
|
136 |
$obsFormatees[$id]['observation'] = $infos;
|
|
|
137 |
$obsFormatees[$id]['protocoles_votes'] = array();
|
1564 |
mathias |
138 |
}
|
1881 |
jpm |
139 |
return $obsFormatees;
|
1604 |
jpm |
140 |
}
|
1490 |
raphael |
141 |
|
1840 |
jpm |
142 |
/**
|
|
|
143 |
* Supprime une image directement dans le CEL en faisant un appel à un web service du CEL.
|
|
|
144 |
* Utilisé uniquement par les admins.
|
|
|
145 |
*
|
|
|
146 |
* @param array $ressources tableau des informations contenues dans l'url après le nom du service
|
|
|
147 |
* @param array $parametres contenu du post
|
|
|
148 |
* @return mixed Chaine "OK" (en majuscule) en cas de succès, booléen "false" en cas d'échec
|
|
|
149 |
*/
|
|
|
150 |
public function supprimer($ressources) {
|
|
|
151 |
$controlAcces = $this->conteneur->getControleAcces();
|
|
|
152 |
$controlAcces->etreUtilisateurAvecDroitAdmin();
|
1490 |
raphael |
153 |
|
1840 |
jpm |
154 |
$urlServiceBase = $this->conteneur->getParametre('urlServiceCelImage');
|
|
|
155 |
$idImage = $ressources[0];
|
|
|
156 |
$url = $urlServiceBase.$idImage;
|
1604 |
jpm |
157 |
|
1840 |
jpm |
158 |
$clientHttp = $this->conteneur->getRestClient();
|
|
|
159 |
$retourCel = $clientHttp->supprimer($url);
|
|
|
160 |
$retour = preg_match('/^OK$/i', $retourCel) ? 'OK' : false;
|
|
|
161 |
return $retour;
|
1604 |
jpm |
162 |
}
|
1827 |
jpm |
163 |
}
|