1497 |
jpm |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* Service fournissant des informations concernant COEL au format RSS1, RSS2 ou ATOM.
|
|
|
4 |
* Encodage en entrée : utf8
|
|
|
5 |
* Encodage en sortie : utf8
|
|
|
6 |
*
|
|
|
7 |
* Notes : pour les requêtes sur la table d'historique cela peut être assez compliqué!
|
|
|
8 |
* Voir : http://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/
|
|
|
9 |
*
|
|
|
10 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
11 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
|
|
12 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
|
|
13 |
* @version $Id: CoelSyndication.php 381 2010-05-17 17:10:37Z jpm $
|
|
|
14 |
* @copyright 2009
|
|
|
15 |
*/
|
|
|
16 |
class CoelSyndication extends Coel {
|
|
|
17 |
|
|
|
18 |
private $format = null;
|
|
|
19 |
private $service = null;
|
|
|
20 |
private $squelette = null;
|
|
|
21 |
private $squelette_dossier = null;
|
|
|
22 |
private $squelette_diff = null;
|
|
|
23 |
private $flux = array();
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Méthode appelée avec une requête de type GET.
|
|
|
27 |
*/
|
|
|
28 |
public function getElement($param = array()) {
|
|
|
29 |
// Initialisation des variables
|
|
|
30 |
$info = array();
|
|
|
31 |
$contenu = '';
|
|
|
32 |
|
|
|
33 |
// Pré traitement des paramêtres
|
|
|
34 |
$pour_bdd = false;
|
|
|
35 |
$p = $this->traiterParametresUrl(array('service', 'format'), $param, $pour_bdd);
|
|
|
36 |
|
|
|
37 |
// Récupération de la liste des flux
|
|
|
38 |
$this->chargerListeDesFlux();
|
|
|
39 |
|
|
|
40 |
// Chargement du bon type de service demandé
|
|
|
41 |
if (isset($p['service'])) {
|
|
|
42 |
$this->service = strtolower($p['service']);
|
|
|
43 |
$methode = $this->getNomMethodeService();
|
|
|
44 |
if (method_exists($this, $methode)) {
|
|
|
45 |
if ($this->service != 'liste_des_flux') {
|
|
|
46 |
if (isset($p['format']) && preg_match('/^(?:rss1|rss2|atom)$/i', $p['format'])) {
|
|
|
47 |
// Multiplication par deux de la limite car nous récupérons deux lignes par item
|
|
|
48 |
$this->limit = $this->limit*2;
|
|
|
49 |
// Mise en minuscule de l'indication du format
|
|
|
50 |
$this->format = strtolower($p['format']);
|
|
|
51 |
// Définition du fichier squelette demandé
|
|
|
52 |
$this->squelette_dossier = dirname(__FILE__).DIRECTORY_SEPARATOR.'squelettes'.DIRECTORY_SEPARATOR;
|
|
|
53 |
$this->squelette = $this->squelette_dossier.$this->format.'.tpl.xml';
|
|
|
54 |
$this->squelette_diff = $this->squelette_dossier.'diff.tpl.html';
|
|
|
55 |
} else {
|
|
|
56 |
$this->format = '';
|
|
|
57 |
$this->messages[] = "Le service COEL Syndication nécessite d'indiquer en second paramètre le format : rss1, rss2 ou atom.";
|
|
|
58 |
}
|
|
|
59 |
}
|
|
|
60 |
// Récupération du contenu à renvoyer
|
|
|
61 |
$contenu = $this->$methode();
|
|
|
62 |
} else {
|
|
|
63 |
$this->messages[] = "Le type d'information demandé '$this->service' n'est pas disponible.";
|
|
|
64 |
}
|
|
|
65 |
} else {
|
|
|
66 |
$this->messages[] = "Le service COEL Syndication nécessite d'indiquer en premier paramètre le type d'information demandé.";
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
// Envoie sur la sortie standard
|
|
|
70 |
$encodage = 'utf-8';
|
|
|
71 |
$mime = $this->getTypeMime();
|
|
|
72 |
$formatage_json = $this->getFormatageJson();
|
|
|
73 |
$this->envoyer($contenu, $mime, $encodage, $formatage_json);
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
private function getUrlServiceBase() {
|
|
|
77 |
$url_service = $this->config['coel']['urlBaseJrest'].'CoelSyndication/'.$this->service.'/'.$this->format;
|
|
|
78 |
return $url_service;
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
private function getNomMethodeService() {
|
|
|
82 |
$methode = '';
|
|
|
83 |
$service_formate = str_replace(' ', '', ucwords(implode(' ', explode('_', $this->service))));
|
|
|
84 |
$methode = 'getService'.$service_formate;
|
|
|
85 |
return $methode;
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
private function getTypeMime() {
|
|
|
89 |
$mime = '';
|
|
|
90 |
switch ($this->format) {
|
|
|
91 |
case 'atom' :
|
|
|
92 |
$mime = 'application/atom+xml';
|
|
|
93 |
break;
|
|
|
94 |
case 'rss1' :
|
|
|
95 |
case 'rss2' :
|
|
|
96 |
$mime = 'application/rss+xml';
|
|
|
97 |
break;
|
|
|
98 |
default:
|
|
|
99 |
$mime = 'text/html';
|
|
|
100 |
}
|
|
|
101 |
return $mime;
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
private function getFormatageJson() {
|
|
|
105 |
$json = false;
|
|
|
106 |
switch ($this->service) {
|
|
|
107 |
case 'liste_des_flux' :
|
|
|
108 |
$json = true;
|
|
|
109 |
break;
|
|
|
110 |
default:
|
|
|
111 |
$json = false;
|
|
|
112 |
}
|
|
|
113 |
return $json;
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
private function getFlux($nom) {
|
|
|
117 |
$nom = strtolower($nom);
|
|
|
118 |
return isset($this->flux[$nom]) ? $this->flux[$nom] : array();
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
private function setFlux($nom, $titre, $description) {
|
|
|
122 |
$url_base = $this->config['coel']['urlBaseJrest'].'CoelSyndication/';
|
|
|
123 |
$formats = array('atom', 'rss2', 'rss1');
|
|
|
124 |
$flux = array();
|
|
|
125 |
foreach ($formats as $format) {
|
|
|
126 |
$url = $url_base.$nom.'/'.$format;
|
|
|
127 |
$flux[$format] = $url;
|
|
|
128 |
}
|
|
|
129 |
$this->flux[$nom] = array('titre' => $titre, 'description' => $description, 'urls' => $flux);
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
private function chargerListeDesFlux() {
|
|
|
133 |
|
|
|
134 |
$this->setFlux('projet', 'Flux de syndication des projets',
|
|
|
135 |
'Ce flux fournit des informations sur les mises à jour des projets saisis dans COEL.');
|
|
|
136 |
$this->setFlux('structure','Flux de syndication des institutions',
|
|
|
137 |
'Ce flux fournit des informations sur les mises à jour des institutions saisies dans COEL.');
|
|
|
138 |
$this->setFlux('collection', 'Flux de syndication des Collections',
|
|
|
139 |
'Ce flux fournit des informations sur les mises à jour des collections saisies dans COEL.');
|
|
|
140 |
$this->setFlux('personne', 'Flux de syndication des personnes',
|
|
|
141 |
'Ce flux fournit des informations sur les mises à jour des personnes saisies dans COEL.');
|
|
|
142 |
$this->setFlux('publication', 'Flux de syndication des publications',
|
|
|
143 |
'Ce flux fournit des informations sur les mises à jour des publications saisies dans COEL.');
|
|
|
144 |
$this->setFlux('commentaire', 'Flux de syndication des notes',
|
|
|
145 |
'Ce flux fournit des informations sur les mises à jour des notes saisies dans COEL.');
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
private function getServiceListeDesFlux() {
|
|
|
149 |
return $this->flux;
|
|
|
150 |
}
|
|
|
151 |
|
|
|
152 |
private function getServiceProjet() {
|
|
|
153 |
// Construction de la requête
|
|
|
154 |
$requete = (($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
|
|
|
155 |
' h1.cmhl_id_historique_ligne, h1.cmhl_ce_table, h1.cmhl_cle_ligne, '.
|
|
|
156 |
' h1.cmhl_enregistrement, '.
|
|
|
157 |
' h1.cmhl_date_modification, h1.cmhl_ce_etat, h1.cmhl_ip, '.
|
|
|
158 |
' h1.cmhl_cle_ligne AS guid, '.
|
|
|
159 |
" 'prj' AS guid_type, ".
|
|
|
160 |
' cp_fmt_nom_complet AS modifier_par '.
|
|
|
161 |
'FROM coel_meta_historique_ligne AS h1 '.
|
|
|
162 |
' LEFT JOIN coel_meta_historique_ligne AS h2 '.
|
|
|
163 |
' ON (h1.cmhl_ce_table = h2.cmhl_ce_table '.
|
|
|
164 |
' AND h1.cmhl_cle_ligne = h2.cmhl_cle_ligne '.
|
|
|
165 |
' AND h1.cmhl_date_modification <= h2.cmhl_date_modification ) '.
|
|
|
166 |
' LEFT JOIN coel_personne ON (h1.cmhl_ce_modifier_par = cp_id_personne) '.
|
|
|
167 |
'WHERE h1.cmhl_ce_table = 115 %s '.
|
|
|
168 |
'GROUP BY h1.cmhl_cle_ligne, h1.cmhl_date_modification, h1.cmhl_date_modification '.
|
|
|
169 |
'HAVING COUNT(*) = %s '.
|
|
|
170 |
'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby : 'h1.cmhl_date_modification DESC').' '.
|
|
|
171 |
"LIMIT $this->start,$this->limit ";
|
|
|
172 |
|
|
|
173 |
$elements = $this->executerRequeteHistorique($requete);
|
|
|
174 |
|
|
|
175 |
// Création du contenu
|
|
|
176 |
$contenu = $this->executerService('cpr_nom', $elements);
|
|
|
177 |
return $contenu;
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
private function getServiceStructure() {
|
|
|
181 |
$elements = array();
|
|
|
182 |
$elements = array_merge($elements, $this->getHistoriqueTableStructure(120));
|
|
|
183 |
$elements = array_merge($elements, $this->getHistoriqueTableStructure(122));
|
|
|
184 |
$elements = array_merge($elements, $this->getHistoriqueTableStructure(123));
|
|
|
185 |
$elements = array_merge($elements, $this->getHistoriqueStructureAPersonne());
|
|
|
186 |
krsort($elements);
|
|
|
187 |
$elements = array_slice($elements, 0, ($this->limit/2));
|
|
|
188 |
|
|
|
189 |
// Création du contenu
|
|
|
190 |
$contenu = $this->executerService('cs_nom', $elements);
|
|
|
191 |
return $contenu;
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
private function getHistoriqueTableStructure($table_id) {
|
|
|
195 |
$requete = (($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
|
|
|
196 |
' h1.cmhl_id_historique_ligne, h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_enregistrement, '.
|
|
|
197 |
' h1.cmhl_date_modification, h1.cmhl_ce_etat, h1.cmhl_ip, '.
|
|
|
198 |
' h1.cmhl_cle_ligne AS guid, '.
|
|
|
199 |
" 'str' AS guid_type, ".
|
|
|
200 |
(($table_id != 120) ? ' CONCAT(IF (h1.cmhl_ce_table = 122, "Conservation", "Valorisation"), " - ", cs_nom) AS titre, ' : '').
|
|
|
201 |
' cp_fmt_nom_complet AS modifier_par '.
|
|
|
202 |
'FROM coel_meta_historique_ligne AS h1 '.
|
|
|
203 |
' LEFT JOIN coel_meta_historique_ligne AS h2 '.
|
|
|
204 |
' ON (h1.cmhl_ce_table = h2.cmhl_ce_table '.
|
|
|
205 |
' AND h1.cmhl_cle_ligne = h2.cmhl_cle_ligne '.
|
|
|
206 |
' AND h1.cmhl_date_modification <= h2.cmhl_date_modification ) '.
|
|
|
207 |
' LEFT JOIN coel_personne ON (h1.cmhl_ce_modifier_par = cp_id_personne) '.
|
|
|
208 |
(($table_id != 120) ? ' LEFT JOIN coel_structure ON (cs_id_structure = h1.cmhl_cle_ligne) ' : '').
|
|
|
209 |
"WHERE h1.cmhl_ce_table = $table_id %s ".
|
|
|
210 |
(($table_id != 120) ? ' AND h1.cmhl_ce_etat != 3 ' : '').
|
|
|
211 |
'GROUP BY h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_date_modification '.
|
|
|
212 |
'HAVING COUNT(*) = %s '.
|
|
|
213 |
'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby : 'h1.cmhl_date_modification DESC').' '.
|
|
|
214 |
"LIMIT $this->start,$this->limit ";
|
|
|
215 |
|
|
|
216 |
$elements = $this->executerRequeteHistorique($requete);
|
|
|
217 |
return $elements;
|
|
|
218 |
}
|
|
|
219 |
|
|
|
220 |
private function getHistoriqueStructureAPersonne() {
|
|
|
221 |
$requete = (($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
|
|
|
222 |
' h1.cmhl_id_historique_ligne, h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_enregistrement, '.
|
|
|
223 |
' h1.cmhl_date_modification, h1.cmhl_ce_etat, h1.cmhl_ip, '.
|
|
|
224 |
' h1.cmhl_cle_ligne AS guid, '.
|
|
|
225 |
" 'csap' AS guid_type, ".
|
|
|
226 |
' p1.cp_fmt_nom_complet AS modifier_par, '.
|
|
|
227 |
' CONCAT(IF(h1.cmhl_ce_etat = 1, "Ajout", IF (h1.cmhl_ce_etat = 3, "Suppression", "Modification")), " d\'une personne liée à «", s1.cs_nom, "»") AS titre, '.
|
|
|
228 |
' CONCAT("Personne «", p2.cp_fmt_nom_complet, "» liée à «", s1.cs_nom, "» avec rôle «", lv1.cmlv_nom, "»") AS description '.
|
|
|
229 |
'FROM coel_meta_historique_ligne AS h1 '.
|
|
|
230 |
' LEFT JOIN coel_meta_historique_ligne AS h2 '.
|
|
|
231 |
' ON (h1.cmhl_ce_table = h2.cmhl_ce_table '.
|
|
|
232 |
' AND h1.cmhl_cle_ligne = h2.cmhl_cle_ligne '.
|
|
|
233 |
' AND h1.cmhl_date_modification <= h2.cmhl_date_modification ) '.
|
|
|
234 |
' LEFT JOIN coel_personne AS p1 ON (h1.cmhl_ce_modifier_par = p1.cp_id_personne) '.
|
|
|
235 |
' LEFT JOIN coel_personne AS p2 '.
|
|
|
236 |
" ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', 1) = p2.cp_id_personne) ".
|
|
|
237 |
' LEFT JOIN coel_structure AS s1 '.
|
|
|
238 |
" ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', -1) = s1.cs_id_structure) ".
|
|
|
239 |
' LEFT JOIN coel_meta_liste_valeur AS lv1 '.
|
|
|
240 |
" ON (SUBSTRING_INDEX(SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', 2), '-', -1) = lv1.cmlv_id_valeur) ".
|
|
|
241 |
'WHERE h1.cmhl_ce_table = 121 %s '.
|
|
|
242 |
'GROUP BY h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_date_modification '.
|
|
|
243 |
'HAVING COUNT(*) = %s '.
|
|
|
244 |
'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby : 'h1.cmhl_date_modification DESC').' '.
|
|
|
245 |
"LIMIT $this->start,$this->limit ";
|
|
|
246 |
|
|
|
247 |
$elements = $this->executerRequeteHistorique($requete);
|
|
|
248 |
return $elements;
|
|
|
249 |
}
|
|
|
250 |
|
|
|
251 |
private function getServiceCollection() {
|
|
|
252 |
$elements = array();
|
|
|
253 |
$elements = array_merge($elements, $this->getHistoriqueTableCollection(101));
|
|
|
254 |
$elements = array_merge($elements, $this->getHistoriqueTableCollection(106));
|
|
|
255 |
$elements = array_merge($elements, $this->getHistoriqueCollectionAPersonne());
|
|
|
256 |
$elements = array_merge($elements, $this->getHistoriqueCollectionAPublication());
|
|
|
257 |
$elements = array_merge($elements, $this->getHistoriqueCollectionACommentaire());
|
|
|
258 |
krsort($elements);
|
|
|
259 |
$elements = array_slice($elements, 0, ($this->limit/2));
|
|
|
260 |
//echo '<pre>'.print_r($elements, true).'</pre>';
|
|
|
261 |
// Création du contenu
|
|
|
262 |
$contenu = $this->executerService('cc_nom', $elements);
|
|
|
263 |
return $contenu;
|
|
|
264 |
}
|
|
|
265 |
|
|
|
266 |
private function getHistoriqueTableCollection($table_id) {
|
|
|
267 |
// Reque générale avec paramêtres
|
|
|
268 |
$requete = (($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
|
|
|
269 |
' h1.cmhl_id_historique_ligne, h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_enregistrement, '.
|
|
|
270 |
' h1.cmhl_date_modification, h1.cmhl_ce_etat, h1.cmhl_ip, '.
|
|
|
271 |
' h1.cmhl_cle_ligne AS guid, '.
|
|
|
272 |
" 'col' AS guid_type, ".
|
|
|
273 |
(($table_id == 106) ? ' CONCAT("Botanique", " - ", cc_nom) AS titre, ' : '').
|
|
|
274 |
' cp_fmt_nom_complet AS modifier_par '.
|
|
|
275 |
'FROM coel_meta_historique_ligne AS h1 '.
|
|
|
276 |
' LEFT JOIN coel_meta_historique_ligne AS h2 '.
|
|
|
277 |
' ON (h1.cmhl_ce_table = h2.cmhl_ce_table '.
|
|
|
278 |
' AND h1.cmhl_cle_ligne = h2.cmhl_cle_ligne '.
|
|
|
279 |
' AND h1.cmhl_date_modification <= h2.cmhl_date_modification ) '.
|
|
|
280 |
' LEFT JOIN coel_personne ON (h1.cmhl_ce_modifier_par = cp_id_personne) '.
|
|
|
281 |
(($table_id == 106) ? ' LEFT JOIN coel_collection ON (cc_id_collection = h1.cmhl_cle_ligne) ' : '').
|
|
|
282 |
"WHERE h1.cmhl_ce_table = $table_id %s ".
|
|
|
283 |
(($table_id == 106) ? ' AND h1.cmhl_ce_etat != 3 ' : '').
|
|
|
284 |
'GROUP BY h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_date_modification '.
|
|
|
285 |
'HAVING COUNT(*) = %s '.
|
|
|
286 |
'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby : 'h1.cmhl_date_modification DESC').' '.
|
|
|
287 |
"LIMIT $this->start,$this->limit ";
|
|
|
288 |
$elements = $this->executerRequeteHistorique($requete);
|
|
|
289 |
return $elements;
|
|
|
290 |
}
|
|
|
291 |
|
|
|
292 |
private function getHistoriqueCollectionAPersonne() {
|
|
|
293 |
$requete = (($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
|
|
|
294 |
' h1.cmhl_id_historique_ligne, h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_enregistrement, '.
|
|
|
295 |
' h1.cmhl_date_modification, h1.cmhl_ce_etat, h1.cmhl_ip, '.
|
|
|
296 |
' p1.cp_fmt_nom_complet AS modifier_par, '.
|
|
|
297 |
' h1.cmhl_cle_ligne AS guid, '.
|
|
|
298 |
" 'ccap' AS guid_type, ".
|
|
|
299 |
' CONCAT(IF(h1.cmhl_ce_etat = 1, "Ajout", IF (h1.cmhl_ce_etat = 3, "Suppression", "Modification")), " d\'une personne liée à «", c1.cc_nom, "»") AS titre, '.
|
|
|
300 |
' CONCAT("Personne «", p2.cp_fmt_nom_complet, "» liée à «", c1.cc_nom, "» avec rôle «", lv1.cmlv_nom, "»") AS description '.
|
|
|
301 |
'FROM coel_meta_historique_ligne AS h1 '.
|
|
|
302 |
' LEFT JOIN coel_meta_historique_ligne AS h2 '.
|
|
|
303 |
' ON (h1.cmhl_ce_table = h2.cmhl_ce_table '.
|
|
|
304 |
' AND h1.cmhl_cle_ligne = h2.cmhl_cle_ligne '.
|
|
|
305 |
' AND h1.cmhl_date_modification <= h2.cmhl_date_modification ) '.
|
|
|
306 |
' LEFT JOIN coel_personne AS p1 ON (h1.cmhl_ce_modifier_par = p1.cp_id_personne) '.
|
|
|
307 |
' LEFT JOIN coel_personne AS p2 '.
|
|
|
308 |
" ON (SUBSTRING_INDEX(SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', 2), '-', -1) = p2.cp_id_personne) ".
|
|
|
309 |
' LEFT JOIN coel_collection AS c1 '.
|
|
|
310 |
" ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', 1) = c1.cc_id_collection) ".
|
|
|
311 |
' LEFT JOIN coel_meta_liste_valeur AS lv1 '.
|
|
|
312 |
" ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', -1) = lv1.cmlv_id_valeur) ".
|
|
|
313 |
'WHERE h1.cmhl_ce_table = 103 %s '.
|
|
|
314 |
'GROUP BY h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_date_modification '.
|
|
|
315 |
'HAVING COUNT(*) = %s '.
|
|
|
316 |
'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby : 'h1.cmhl_date_modification DESC').' '.
|
|
|
317 |
"LIMIT $this->start,$this->limit ";
|
|
|
318 |
|
|
|
319 |
$elements = $this->executerRequeteHistorique($requete);
|
|
|
320 |
return $elements;
|
|
|
321 |
}
|
|
|
322 |
|
|
|
323 |
private function getHistoriqueCollectionAPublication() {
|
|
|
324 |
$requete = (($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
|
|
|
325 |
' h1.cmhl_id_historique_ligne, h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_enregistrement, '.
|
|
|
326 |
' h1.cmhl_date_modification, h1.cmhl_ce_etat, h1.cmhl_ip, '.
|
|
|
327 |
' p1.cp_fmt_nom_complet AS modifier_par, '.
|
|
|
328 |
' h1.cmhl_cle_ligne AS guid, '.
|
|
|
329 |
" 'ccapu' AS guid_type, ".
|
|
|
330 |
' CONCAT(IF(h1.cmhl_ce_etat = 1, "Ajout", IF (h1.cmhl_ce_etat = 3, "Suppression", "Modification")), " d\'une publication liée à «", c1.cc_nom, "»") AS titre, '.
|
|
|
331 |
' CONCAT("Publication «", p2.cpu_fmt_nom_complet, "» liée à «", c1.cc_nom, "»") AS description '.
|
|
|
332 |
'FROM coel_meta_historique_ligne AS h1 '.
|
|
|
333 |
' LEFT JOIN coel_meta_historique_ligne AS h2 '.
|
|
|
334 |
' ON (h1.cmhl_ce_table = h2.cmhl_ce_table '.
|
|
|
335 |
' AND h1.cmhl_cle_ligne = h2.cmhl_cle_ligne '.
|
|
|
336 |
' AND h1.cmhl_date_modification <= h2.cmhl_date_modification ) '.
|
|
|
337 |
' LEFT JOIN coel_personne AS p1 ON (h1.cmhl_ce_modifier_par = p1.cp_id_personne) '.
|
|
|
338 |
' LEFT JOIN coel_publication AS p2 '.
|
|
|
339 |
" ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', -1) = p2.cpu_id_publication) ".
|
|
|
340 |
' LEFT JOIN coel_collection AS c1 '.
|
|
|
341 |
" ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', 1) = c1.cc_id_collection) ".
|
|
|
342 |
'WHERE h1.cmhl_ce_table = 104 %s '.
|
|
|
343 |
'GROUP BY h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_date_modification '.
|
|
|
344 |
'HAVING COUNT(*) = %s '.
|
|
|
345 |
'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby : 'h1.cmhl_date_modification DESC').' '.
|
|
|
346 |
"LIMIT $this->start,$this->limit ";
|
|
|
347 |
|
|
|
348 |
$elements = $this->executerRequeteHistorique($requete);
|
|
|
349 |
return $elements;
|
|
|
350 |
}
|
|
|
351 |
|
|
|
352 |
private function getHistoriqueCollectionACommentaire() {
|
|
|
353 |
$requete = (($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
|
|
|
354 |
' h1.cmhl_id_historique_ligne, h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_enregistrement, '.
|
|
|
355 |
' h1.cmhl_date_modification, h1.cmhl_ce_etat, h1.cmhl_ip, '.
|
|
|
356 |
' p1.cp_fmt_nom_complet AS modifier_par, '.
|
|
|
357 |
' h1.cmhl_cle_ligne AS guid, '.
|
|
|
358 |
" 'ccacm' AS guid_type, ".
|
|
|
359 |
' CONCAT(IF(h1.cmhl_ce_etat = 1, "Ajout", IF (h1.cmhl_ce_etat = 3, "Suppression", "Modification")), " d\'un commentaire lié à «", c1.cc_nom, "»") AS titre, '.
|
|
|
360 |
' CONCAT("Commentaire «", c.ccm_titre, "» liée à «", c1.cc_nom, "»") AS description '.
|
|
|
361 |
'FROM coel_meta_historique_ligne AS h1 '.
|
|
|
362 |
' LEFT JOIN coel_meta_historique_ligne AS h2 '.
|
|
|
363 |
' ON (h1.cmhl_ce_table = h2.cmhl_ce_table '.
|
|
|
364 |
' AND h1.cmhl_cle_ligne = h2.cmhl_cle_ligne '.
|
|
|
365 |
' AND h1.cmhl_date_modification <= h2.cmhl_date_modification ) '.
|
|
|
366 |
' LEFT JOIN coel_personne AS p1 ON (h1.cmhl_ce_modifier_par = p1.cp_id_personne) '.
|
|
|
367 |
' LEFT JOIN coel_commentaire AS c '.
|
|
|
368 |
" ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', -1) = c.ccm_id_commentaire) ".
|
|
|
369 |
' LEFT JOIN coel_collection AS c1 '.
|
|
|
370 |
" ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', 1) = c1.cc_id_collection) ".
|
|
|
371 |
'WHERE h1.cmhl_ce_table = 102 %s '.
|
|
|
372 |
'GROUP BY h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_date_modification '.
|
|
|
373 |
'HAVING COUNT(*) = %s '.
|
|
|
374 |
'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby : 'h1.cmhl_date_modification DESC').' '.
|
|
|
375 |
"LIMIT $this->start,$this->limit ";
|
|
|
376 |
|
|
|
377 |
$elements = $this->executerRequeteHistorique($requete);
|
|
|
378 |
return $elements;
|
|
|
379 |
}
|
|
|
380 |
|
|
|
381 |
private function getServicePersonne() {
|
|
|
382 |
$elements = array();
|
|
|
383 |
$elements = array_merge($elements, $this->getHistoriqueTable(113, 'per'));
|
|
|
384 |
$elements = array_merge($elements, $this->getHistoriquePublicationAPersonne());
|
|
|
385 |
krsort($elements);
|
|
|
386 |
$elements = array_slice($elements, 0, ($this->limit/2));
|
|
|
387 |
//echo '<pre>'.print_r($elements, true).'</pre>';
|
|
|
388 |
// Création du contenu
|
|
|
389 |
$contenu = $this->executerService('cp_fmt_nom_complet', $elements);
|
|
|
390 |
return $contenu;
|
|
|
391 |
}
|
|
|
392 |
|
|
|
393 |
private function getHistoriquePublicationAPersonne() {
|
|
|
394 |
$requete = (($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
|
|
|
395 |
' h1.cmhl_id_historique_ligne, h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_enregistrement, '.
|
|
|
396 |
' h1.cmhl_date_modification, h1.cmhl_ce_etat, h1.cmhl_ip, '.
|
|
|
397 |
' p1.cp_fmt_nom_complet AS modifier_par, '.
|
|
|
398 |
' h1.cmhl_cle_ligne AS guid, '.
|
|
|
399 |
" 'cpap' AS guid_type, ".
|
|
|
400 |
' CONCAT(IF(h1.cmhl_ce_etat = 1, "Ajout", IF (h1.cmhl_ce_etat = 3, "Suppression", "Modification")), " d\'une publication liée à «", p2.cp_fmt_nom_complet, "»") AS titre, '.
|
|
|
401 |
' CONCAT("Publication «", pu.cpu_fmt_nom_complet, "» liée à «", p2.cp_fmt_nom_complet, "» avec rôle «", lv1.cmlv_nom, "»") AS description '.
|
|
|
402 |
'FROM coel_meta_historique_ligne AS h1 '.
|
|
|
403 |
' LEFT JOIN coel_meta_historique_ligne AS h2 '.
|
|
|
404 |
' ON (h1.cmhl_ce_table = h2.cmhl_ce_table '.
|
|
|
405 |
' AND h1.cmhl_cle_ligne = h2.cmhl_cle_ligne '.
|
|
|
406 |
' AND h1.cmhl_date_modification <= h2.cmhl_date_modification ) '.
|
|
|
407 |
' LEFT JOIN coel_personne AS p1 ON (h1.cmhl_ce_modifier_par = p1.cp_id_personne) '.
|
|
|
408 |
' LEFT JOIN coel_publication AS pu '.
|
|
|
409 |
" ON (SUBSTRING_INDEX(SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', 2), '-', -1) = pu.cpu_id_publication) ".
|
|
|
410 |
' LEFT JOIN coel_personne AS p2 '.
|
|
|
411 |
" ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', 1) = p2.cp_id_personne) ".
|
|
|
412 |
' LEFT JOIN coel_meta_liste_valeur AS lv1 '.
|
|
|
413 |
" ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', -1) = lv1.cmlv_id_valeur) ".
|
|
|
414 |
'WHERE h1.cmhl_ce_table = 119 '.
|
|
|
415 |
' %s '.
|
|
|
416 |
" AND SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', -1) IN (2361,2362,2363) ".
|
|
|
417 |
'GROUP BY h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_date_modification '.
|
|
|
418 |
'HAVING COUNT(*) = %s '.
|
|
|
419 |
'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby : 'h1.cmhl_date_modification DESC').' '.
|
|
|
420 |
"LIMIT $this->start,$this->limit ";
|
|
|
421 |
|
|
|
422 |
$elements = $this->executerRequeteHistorique($requete);
|
|
|
423 |
return $elements;
|
|
|
424 |
}
|
|
|
425 |
|
|
|
426 |
private function getServicePublication() {
|
|
|
427 |
$elements = array();
|
|
|
428 |
$elements = $this->getHistoriqueTable(118, 'pub');
|
|
|
429 |
krsort($elements);
|
|
|
430 |
$elements = array_slice($elements, 0, ($this->limit/2));
|
|
|
431 |
//echo '<pre>'.print_r($elements, true).'</pre>';
|
|
|
432 |
// Création du contenu
|
|
|
433 |
$contenu = $this->executerService('cpu_fmt_nom_complet', $elements);
|
|
|
434 |
return $contenu;
|
|
|
435 |
}
|
|
|
436 |
|
|
|
437 |
private function getServiceCommentaire() {
|
|
|
438 |
$elements = array();
|
|
|
439 |
$elements = $this->getHistoriqueTable(107, 'com');
|
|
|
440 |
krsort($elements);
|
|
|
441 |
$elements = array_slice($elements, 0, ($this->limit/2));
|
|
|
442 |
//echo '<pre>'.print_r($elements, true).'</pre>';
|
|
|
443 |
// Création du contenu
|
|
|
444 |
$contenu = $this->executerService('ccm_titre', $elements);
|
|
|
445 |
return $contenu;
|
|
|
446 |
}
|
|
|
447 |
|
|
|
448 |
private function getHistoriqueTable($table_id, $guid_type) {
|
|
|
449 |
// Reque générale avec paramêtres
|
|
|
450 |
$requete = (($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
|
|
|
451 |
' h1.cmhl_id_historique_ligne, h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_enregistrement, '.
|
|
|
452 |
' h1.cmhl_date_modification, h1.cmhl_ce_etat, h1.cmhl_ip, '.
|
|
|
453 |
' h1.cmhl_cle_ligne AS guid, '.
|
|
|
454 |
" '$guid_type' AS guid_type, ".
|
|
|
455 |
' cp_fmt_nom_complet AS modifier_par '.
|
|
|
456 |
'FROM coel_meta_historique_ligne AS h1 '.
|
|
|
457 |
' LEFT JOIN coel_meta_historique_ligne AS h2 '.
|
|
|
458 |
' ON (h1.cmhl_ce_table = h2.cmhl_ce_table '.
|
|
|
459 |
' AND h1.cmhl_cle_ligne = h2.cmhl_cle_ligne '.
|
|
|
460 |
' AND h1.cmhl_date_modification <= h2.cmhl_date_modification ) '.
|
|
|
461 |
' LEFT JOIN coel_personne ON (h1.cmhl_ce_modifier_par = cp_id_personne) '.
|
|
|
462 |
"WHERE h1.cmhl_ce_table = $table_id %s ".
|
|
|
463 |
'GROUP BY h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_date_modification '.
|
|
|
464 |
'HAVING COUNT(*) = %s '.
|
|
|
465 |
'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby : 'h1.cmhl_date_modification DESC').' '.
|
|
|
466 |
"LIMIT $this->start,$this->limit ";
|
|
|
467 |
$elements = $this->executerRequeteHistorique($requete);
|
|
|
468 |
return $elements;
|
|
|
469 |
}
|
|
|
470 |
|
|
|
471 |
private function executerRequete($requete) {
|
|
|
472 |
try {
|
|
|
473 |
$infos = $this->bdd->query($requete)->fetchAll(PDO::FETCH_ASSOC);
|
|
|
474 |
if ($infos === false) {
|
|
|
475 |
$this->messages[] = "La requête a retourné aucun résultat.";
|
|
|
476 |
}
|
|
|
477 |
} catch (PDOException $e) {
|
|
|
478 |
$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
|
|
|
479 |
}
|
|
|
480 |
return $infos;
|
|
|
481 |
}
|
|
|
482 |
|
|
|
483 |
private function fusionnerEnregistrements($infos) {
|
|
|
484 |
// Fusion des lignes
|
|
|
485 |
$elements = array();
|
|
|
486 |
foreach ($infos as $info) {
|
|
|
487 |
$id = $info['cmhl_ce_table'].'|'.$info['cmhl_cle_ligne'];
|
|
|
488 |
if (!isset($elements[$id])) {
|
|
|
489 |
$elements[$id] = $info;
|
|
|
490 |
} else {
|
|
|
491 |
if ($elements[$id]['cmhl_date_modification'] < $info['cmhl_date_modification']) {
|
|
|
492 |
$elements[$id] = $this->traiterInfosPrecedentes($info, $elements[$id]);
|
|
|
493 |
} else {
|
|
|
494 |
$elements[$id] = $this->traiterInfosPrecedentes($elements[$id], $info);
|
|
|
495 |
}
|
|
|
496 |
}
|
|
|
497 |
}
|
|
|
498 |
|
|
|
499 |
// Nettoyage et utilisation de la date pour pouvoir trier le tableau
|
|
|
500 |
$sortie = array();
|
|
|
501 |
foreach ($elements as $id => $element) {
|
|
|
502 |
$element = $this->nettoyerNomChamps($element);
|
|
|
503 |
$id_avec_date = $element['cmhl_date_modification'].'|'.$id;
|
|
|
504 |
$sortie[$id_avec_date] = $element;
|
|
|
505 |
}
|
|
|
506 |
|
|
|
507 |
return $sortie;
|
|
|
508 |
}
|
|
|
509 |
|
|
|
510 |
private function executerRequeteHistorique($requete) {
|
|
|
511 |
$elements = array();
|
|
|
512 |
|
|
|
513 |
// Récupération des 1er éléments
|
|
|
514 |
$requete_elements_1er = sprintf($requete, '', '1');
|
|
|
515 |
$infos_elements_1er = $this->executerRequete($requete_elements_1er);
|
|
|
516 |
|
|
|
517 |
// Construction de la requête pour récupérer les second éléments
|
|
|
518 |
$elements_1er_cle_ligne = array();
|
|
|
519 |
foreach ($infos_elements_1er as $info) {
|
|
|
520 |
$elements_1er_cle_ligne[] = $info['cmhl_cle_ligne'];
|
|
|
521 |
}
|
1744 |
aurelien |
522 |
$chaine_1er_elements = 'AND h1.cmhl_cle_ligne IN ('.str_replace(',,',',',implode(',', $elements_1er_cle_ligne)).') ';
|
1497 |
jpm |
523 |
$requete_elements_2nd = sprintf($requete, $chaine_1er_elements, '2');
|
|
|
524 |
|
|
|
525 |
// Récupération des 2nd éléments
|
|
|
526 |
$infos_elements_2nd = $this->executerRequete($requete_elements_2nd);
|
|
|
527 |
|
|
|
528 |
// Fusion des 1er et 2nd éléments
|
|
|
529 |
$infos = array_merge($infos_elements_1er, $infos_elements_2nd);
|
|
|
530 |
|
|
|
531 |
$elements = $this->fusionnerEnregistrements($infos);
|
|
|
532 |
return $elements;
|
|
|
533 |
}
|
|
|
534 |
|
|
|
535 |
private function executerService($champ_titre, $elements) {
|
|
|
536 |
// Prétraitement des données
|
|
|
537 |
$donnees = $this->construireDonneesCommunesAuFlux($elements);
|
|
|
538 |
foreach ($elements as $element) {
|
|
|
539 |
$xml = $this->getXmlHisto($element);
|
|
|
540 |
$enrg = $this->getTableauDepuisXmlHisto($xml);
|
|
|
541 |
$diff = $this->getDiffInfos($element);
|
|
|
542 |
$diff['differences'] = $this->getDiff($element);
|
|
|
543 |
$diff_html = (!is_null($diff['differences'])) ? Coel::traiterSquelettePhp($this->squelette_diff, $diff) : '';
|
|
|
544 |
|
|
|
545 |
$item = $this->construireDonneesCommunesAuxItems($element);
|
|
|
546 |
$item['titre'] = $this->creerTitre($champ_titre, $element, $enrg);
|
|
|
547 |
$item['guid'] = sprintf($this->config['coel']['guid'], 'coel', $element['guid_type'].$element['guid']);
|
|
|
548 |
$item['lien'] = $this->config['coel']['urlBaseCoel'].'#'.urlencode($item['guid']);
|
|
|
549 |
$item['description'] = '<p>'.$this->getMessageModif($item).'</p>';
|
|
|
550 |
$item['description'] .= $this->creerDescription($element, $enrg);
|
|
|
551 |
$item['description'] .= $diff_html;
|
|
|
552 |
$item['description'] = $this->nettoyerTexte($item['description']);
|
|
|
553 |
$item['description_encodee'] = htmlspecialchars($item['description']);
|
|
|
554 |
|
|
|
555 |
$donnees['items'][] = $item;
|
|
|
556 |
}
|
|
|
557 |
|
|
|
558 |
// Création du contenu à partir d'un template PHP
|
|
|
559 |
$contenu = Coel::traiterSquelettePhp($this->squelette, $donnees);
|
|
|
560 |
|
|
|
561 |
return $contenu;
|
|
|
562 |
}
|
|
|
563 |
|
|
|
564 |
private function creerTitre($champ, $element, $enrg) {
|
|
|
565 |
$titre = '';
|
|
|
566 |
if (isset($element['titre'])) {
|
|
|
567 |
$titre = $element['titre'];
|
|
|
568 |
} else if (isset($element[$champ])) {
|
|
|
569 |
$titre = $element[$champ];
|
|
|
570 |
} else if (isset($enrg[$champ])) {
|
|
|
571 |
$titre = $enrg[$champ];
|
|
|
572 |
}
|
|
|
573 |
$titre = $this->nettoyerTexte($titre);
|
|
|
574 |
return $titre;
|
|
|
575 |
}
|
|
|
576 |
|
|
|
577 |
private function creerDescription($element, $enrg) {
|
|
|
578 |
$description = '';
|
|
|
579 |
if (isset($element['description'])) {
|
|
|
580 |
$description = $element['description'];
|
|
|
581 |
}
|
|
|
582 |
return $description;
|
|
|
583 |
}
|
|
|
584 |
|
|
|
585 |
private function nettoyerNomChamps($infos) {
|
|
|
586 |
$sortie = array();
|
|
|
587 |
foreach ($infos as $champ => $valeur) {
|
|
|
588 |
if (preg_match('/^__(.+)$/', $champ, $match)) {
|
|
|
589 |
$sortie[$match[1]] = $valeur;
|
|
|
590 |
} else {
|
|
|
591 |
$sortie[$champ] = $valeur;
|
|
|
592 |
}
|
|
|
593 |
}
|
|
|
594 |
return $sortie;
|
|
|
595 |
}
|
|
|
596 |
|
|
|
597 |
private function traiterInfosPrecedentes($infos_courantes, $infos_precedentes) {
|
|
|
598 |
$infos_precedentes_traitees = array();
|
|
|
599 |
foreach ($infos_precedentes as $champ => $valeur) {
|
|
|
600 |
if ($champ == 'cmhl_date_modification') {
|
|
|
601 |
$infos_precedentes_traitees['date_prec'] = $valeur;
|
|
|
602 |
} else if ($champ == 'cmhl_enregistrement') {
|
|
|
603 |
$infos_precedentes_traitees['enrg_prec'] = $valeur;
|
|
|
604 |
} else if (preg_match('/^__(.+)$/', $champ, $match)) {
|
|
|
605 |
$infos_precedentes_traitees[$match[1].'_prec'] = $valeur;
|
|
|
606 |
}
|
|
|
607 |
}
|
|
|
608 |
$sortie = array_merge($infos_courantes, $infos_precedentes_traitees);
|
|
|
609 |
return $sortie;
|
|
|
610 |
}
|
|
|
611 |
|
|
|
612 |
private function nettoyerTexte($txt) {
|
|
|
613 |
$txt = preg_replace('/&(?!amp;)/i', '&', $txt, -1);
|
|
|
614 |
return $txt;
|
|
|
615 |
}
|
|
|
616 |
|
|
|
617 |
private function getMessageModif($item) {
|
|
|
618 |
$message = $item['etat'].' le '.$item['date_maj_simple'].' par '.$item['modifier_par'].' depuis l\'IP '.$item['ip'];
|
|
|
619 |
return $message;
|
|
|
620 |
}
|
|
|
621 |
|
|
|
622 |
private function construireDonneesCommunesAuxItems($info) {
|
|
|
623 |
$item = array();
|
|
|
624 |
$date_modification_timestamp = strtotime($info['cmhl_date_modification']);
|
|
|
625 |
$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp);
|
|
|
626 |
$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
|
|
|
627 |
$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
|
|
|
628 |
$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
|
|
|
629 |
$item['guid'] = $info['cmhl_id_historique_ligne'];
|
|
|
630 |
$item['cle'] = $info['cmhl_cle_ligne'];
|
|
|
631 |
$item['ip'] = $info['cmhl_ip'];
|
|
|
632 |
$item['modifier_par'] = $info['modifier_par'];
|
|
|
633 |
$item['etat'] = isset($info['cmhl_ce_etat']) ? $this->getTexteEtat($info['cmhl_ce_etat']) : '';
|
|
|
634 |
|
|
|
635 |
return $item;
|
|
|
636 |
}
|
|
|
637 |
|
|
|
638 |
private function getXmlHisto($info) {
|
|
|
639 |
$xml = '';
|
|
|
640 |
if ($info['cmhl_ce_etat'] == '3') {
|
|
|
641 |
$xml = $info['enrg_prec'];
|
|
|
642 |
} else {
|
|
|
643 |
$xml = $info['cmhl_enregistrement'];
|
|
|
644 |
}
|
|
|
645 |
return $xml;
|
|
|
646 |
}
|
|
|
647 |
|
|
|
648 |
private function getDiff($info) {
|
|
|
649 |
$diff = null;
|
|
|
650 |
if ($info['cmhl_ce_etat'] == '1') {
|
|
|
651 |
$nouveau = $this->getTableauDepuisXmlHisto($info['cmhl_enregistrement']);
|
|
|
652 |
foreach ($nouveau as $cle => $valeur) {
|
|
|
653 |
$diff[$cle] = array('type' => 'A', 'type_txt' => 'Ajout', 'nouveau' => $valeur, 'ancien' => ' ');
|
|
|
654 |
}
|
|
|
655 |
} else if ($info['cmhl_ce_etat'] == '2') {
|
|
|
656 |
$nouveau = $this->getTableauDepuisXmlHisto($info['cmhl_enregistrement']);
|
|
|
657 |
$ancien = $this->getTableauDepuisXmlHisto($info['enrg_prec']);
|
|
|
658 |
foreach ($nouveau as $cle => $valeur) {
|
|
|
659 |
if (!isset($ancien[$cle])) {
|
|
|
660 |
$diff[$cle] = array('type' => 'A', 'type_txt' => 'Ajout', 'nouveau' => $valeur, 'ancien' => ' ');
|
|
|
661 |
} else if (isset($ancien[$cle]) && $ancien[$cle] != $valeur) {
|
|
|
662 |
$diff[$cle] = array('type' => 'M', 'type_txt' => 'Modification', 'nouveau' => $valeur, 'ancien' => $ancien[$cle]);
|
|
|
663 |
}
|
|
|
664 |
}
|
|
|
665 |
foreach ($ancien as $cle => $valeur) {
|
|
|
666 |
if (!isset($nouveau[$cle])) {
|
|
|
667 |
$diff[$cle] = array('type' => 'S', 'type_txt' => 'Suppression', 'nouveau' => ' ', 'ancien' => $valeur);
|
|
|
668 |
}
|
|
|
669 |
}
|
|
|
670 |
}
|
|
|
671 |
return $diff;
|
|
|
672 |
}
|
|
|
673 |
|
|
|
674 |
private function getDiffInfos($info) {
|
|
|
675 |
$diff = null;
|
|
|
676 |
$format = '%d/%m/%Y à %H:%M:%S';
|
|
|
677 |
if ($info['cmhl_ce_etat'] == '1') {
|
|
|
678 |
$diff['date_nouvelle'] = strftime($format, strtotime($info['cmhl_date_modification']));
|
1750 |
mathias |
679 |
$diff['date_ancienne'] = '';
|
1497 |
jpm |
680 |
$diff['etat'] = 'A';
|
|
|
681 |
} else if ($info['cmhl_ce_etat'] == '2') {
|
|
|
682 |
$diff['date_nouvelle'] = strftime($format, strtotime($info['cmhl_date_modification']));
|
|
|
683 |
$diff['date_ancienne'] = strftime($format, strtotime($info['date_prec']));
|
|
|
684 |
$diff['etat'] = 'M';
|
|
|
685 |
} else if ($info['cmhl_ce_etat'] == '3') {
|
|
|
686 |
$diff['etat'] = 'S';
|
|
|
687 |
}
|
|
|
688 |
return $diff;
|
|
|
689 |
}
|
|
|
690 |
|
|
|
691 |
private function getTexteEtat($code) {
|
|
|
692 |
$etat = '';
|
|
|
693 |
switch ($code) {
|
|
|
694 |
case '1' :
|
|
|
695 |
$etat = 'Ajouté';
|
|
|
696 |
break;
|
|
|
697 |
case '2' :
|
|
|
698 |
$etat = 'Modifié';
|
|
|
699 |
break;
|
|
|
700 |
case '3' :
|
|
|
701 |
$etat = 'Supprimé';
|
|
|
702 |
break;
|
|
|
703 |
default :
|
|
|
704 |
$etat = '!Problème!';
|
|
|
705 |
$e = "Le champ cmhl_ce_etat possède une valeur innatendue : $code";
|
|
|
706 |
$this->messages[] = $e;
|
|
|
707 |
}
|
|
|
708 |
return $etat;
|
|
|
709 |
}
|
|
|
710 |
|
|
|
711 |
private function construireDonneesCommunesAuFlux($infos) {
|
|
|
712 |
$donnees = $this->getFlux($this->service);
|
|
|
713 |
$donnees['guid'] = $this->getUrlServiceBase();
|
1625 |
aurelien |
714 |
$donnees['lien_service'] = htmlentities($this->creerUrlService());
|
1497 |
jpm |
715 |
$donnees['lien_coel'] = $this->config['coel']['urlBaseCoel'];
|
|
|
716 |
$donnees['editeur'] = $this->config['coel']['editeur'];
|
|
|
717 |
$derniere_info_en_date = reset($infos);
|
|
|
718 |
$date_modification_timestamp = strtotime($derniere_info_en_date['cmhl_date_modification']);
|
|
|
719 |
$donnees['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
|
|
|
720 |
$donnees['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
|
|
|
721 |
$donnees['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
|
|
|
722 |
$donnees['annee_courante'] = date('Y');
|
|
|
723 |
$donnees['generateur'] = 'COEL - Jrest';
|
|
|
724 |
preg_match('/([0-9]+)/', '$Revision: 381 $', $match);
|
|
|
725 |
$donnees['generateur_version'] = $match[1];
|
|
|
726 |
return $donnees;
|
|
|
727 |
}
|
|
|
728 |
|
|
|
729 |
private function creerUrlService() {
|
|
|
730 |
$url_service = $this->getUrlServiceBase();
|
|
|
731 |
if (isset($this->start) || isset($this->limit)) {
|
|
|
732 |
$arguments = array();
|
|
|
733 |
if (isset($this->start) && isset($_GET['start'])) {
|
|
|
734 |
$arguments[] = 'start='.$this->start;
|
|
|
735 |
}
|
|
|
736 |
if (isset($this->limit) && isset($_GET['limit'])) {
|
|
|
737 |
$arguments[] = 'limit='.($this->limit/2);
|
|
|
738 |
}
|
|
|
739 |
if (count($arguments) > 0) {
|
|
|
740 |
$url_service .= '?'.implode('&', $arguments);
|
|
|
741 |
}
|
|
|
742 |
}
|
|
|
743 |
return $url_service;
|
|
|
744 |
}
|
|
|
745 |
}
|