Subversion Repositories eFlore/Applications.cel

Rev

Rev 1630 | Rev 1633 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1630 Rev 1632
1
<?php
1
<?php
2
 
2
 
3
/**
3
/**
4
* @category  PHP
4
* @category  PHP
5
* @package   jrest
5
* @package   jrest
6
* @author    Raphaël Droz <raphael@tela-botania.org>
6
* @author    Raphaël Droz <raphael@tela-botania.org>
7
* @copyright 2013 Tela-Botanica
7
* @copyright 2013 Tela-Botanica
8
* @license   http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
8
* @license   http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
9
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
9
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
10
*/
10
*/
11
 
11
 
12
/**
12
/**
13
 * Service d'export de données d'observation du CEL au format XLS
13
 * Service d'export de données d'observation du CEL au format XLS
14
 *
14
 *
15
 * Format du service :
15
 * Format du service :
16
 * POST /ExportXLS
16
 * POST /ExportXLS
17
 * POST /ExportXLS/<Utilisateur>
17
 * POST /ExportXLS/<Utilisateur>
18
 * TODO: GET /ExportXLS/<Utilisateur> [ sans "range" ? ]
18
 * TODO: GET /ExportXLS/<Utilisateur> [ sans "range" ? ]
19
 *
19
 *
20
 * Les données POST acceptées sont:
20
 * Les données POST acceptées sont:
21
 * range (obligatoire): un range d'id_observation sous la forme d'entier ou d'intervalles d'entiers
21
 * range (obligatoire): un range d'id_observation sous la forme d'entier ou d'intervalles d'entiers
22
 *						séparés par des virgules ou bien '*' (pour toutes)
22
 *						séparés par des virgules ou bien '*' (pour toutes)
23
 * TODO: limit
23
 * TODO: limit
24
 * TODO: départ
24
 * TODO: départ
25
 * TODO: sets (ou colonnes, ou extended)
25
 * TODO: sets (ou colonnes, ou extended)
26
 * TODO: + les critères supportés par fabriquerSousRequeteRecherche()
26
 * TODO: + les critères supportés par fabriquerSousRequeteRecherche()
27
 *
27
 *
28
 * Si <Utilisateur> est fourni, celui-ci doit être authentifié
28
 * Si <Utilisateur> est fourni, celui-ci doit être authentifié
29
 * TODO: export des données public et non-sensible d'un utilisateur
29
 * TODO: export des données public et non-sensible d'un utilisateur
30
 *
30
 *
31
 * Si <Utilisateur> est fourni, le observations seront le résultat de l'intersection des 2 contraintes
31
 * Si <Utilisateur> est fourni, le observations seront le résultat de l'intersection des 2 contraintes
32
 *
32
 *
33
 */
33
 */
34
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(dirname(realpath(__FILE__))) . '/lib');
34
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(dirname(realpath(__FILE__))) . '/lib');
35
require_once('lib/PHPExcel/Classes/PHPExcel.php');
35
require_once('lib/PHPExcel/Classes/PHPExcel.php');
36
 
36
 
37
class ExportXLS extends Cel  {
37
class ExportXLS extends Cel  {
38
 
38
 
39
	function ExportXLS($config) {
39
	function ExportXLS($config) {
40
		parent::__construct($config);
40
		parent::__construct($config);
41
	}
41
	}
42
 
42
 
43
	/*
43
	/*
44
	 * Process $_POST et $_GET
44
	 * Process $_POST et $_GET
45
	 * TODO: changer JRest pour pouvoir disposer d'un nom de méthode plus représentatif que "updateXXX"
45
	 * TODO: changer JRest pour pouvoir disposer d'un nom de méthode plus représentatif que "updateXXX"
46
	 * en POST
46
	 * en POST
47
	 */
47
	 */
48
	function updateElement($uid, $pairs) {
48
	function updateElement($uid, $pairs) {
49
		$params = Array('uid' => $uid);
49
		$params = Array('uid' => $uid[0]);
50
		// TODO: pas de range mais un utilisateur: possible
50
		// TODO: pas de range mais un utilisateur: possible
51
		if(!isset($_POST['range'])) {
51
		if(!isset($_POST['range'])) {
52
			header('HTTP/1.0 204 No Content');
52
			header('HTTP/1.0 204 No Content');
53
			exit;
53
			exit;
54
		}
54
		}
-
 
55
		// trim() car: `POST http://url<<<"range=*"`
55
		elseif($_POST['range'] == '*') {
56
		elseif(trim($_POST['range']) == '*') {
56
			$records = Array('*');
57
			$records = Array('*');
57
		}
58
		}
58
		else {
59
		else {
59
			$records = self::rangeToList($_POST['range']);
60
			$records = self::rangeToList(trim($_POST['range']));
60
		}
61
		}
61
		$this->export($records, NULL, $params);
62
		$this->export($records, NULL, $params);
62
		exit;
63
		exit;
63
	}
64
	}
64
 
65
 
65
	/*
66
	/*
66
	 * $param: Tableau associatif, indexes supportés:
67
	 * $param: Tableau associatif, indexes supportés:
67
	 * 		   - widget: le nom du widget d'origine (utilisé pour les méta-données du tableur)
68
	 * 		   - widget: le nom du widget d'origine (utilisé pour les méta-données du tableur)
68
	 *
69
	 *
69
	 */
70
	 */
70
	function export(Array $records, String $fieldSets = NULL, Array $params = Array()) {
71
	function export(Array $records, String $fieldSets = NULL, Array $params = Array()) {
71
		$colonnes = self::fieldSetsToColumns($fieldSets);
72
		$colonnes = self::fieldSetsToColumns($fieldSets);
72
		$columnSlugs = array_keys($colonnes);
73
		$columnSlugs = array_keys($colonnes);
73
		$chercheur_observations = new RechercheObservation($this->config);
74
		$chercheur_observations = new RechercheObservation($this->config);
74
 
75
 
75
		$objPHPExcel = new PHPExcel();
76
		$objPHPExcel = new PHPExcel();
76
 
-
 
77
 
77
 
78
		// TODO: $params['part'] pour le multi-part
78
		// TODO: $params['part'] pour le multi-part
79
		$params['widget'] = isset($params['widget']) ? $params['widget'] : 'CEL';
79
		$params['widget'] = isset($params['widget']) ? $params['widget'] : 'CEL';
80
		// TODO: controleUtilisateur()
80
		// TODO: controleUtilisateur()
81
		if( /* REMOVE*/ true || ! $params['uid'] || ! $this->controleUtilisateur($params['uid'])) {
81
		if(! $params['uid']) { // || ! $this->controleUtilisateur($params['uid'])) {
82
			$params['uid'] = NULL;
82
			$params['uid'] = NULL;
83
		}
83
		}
84
 
84
 
85
		$criteres = Array();
85
		$criteres = Array();
86
		if(count($records) == 1 && $records[0] == '*') {
86
		if(! $records || count($records) == 1 && $records[0] == '*') {
87
			unset($criteres['raw']);
87
			unset($criteres['raw']);
88
		}
88
		}
89
		else {
89
		else {
90
			$criteres = Array('raw' =>
90
			$criteres = Array('raw' =>
91
							  sprintf('id_observation IN (%s)', implode(',', $records)));
91
							  sprintf('id_observation IN (%s)', implode(',', $records)));
92
		}
92
		}
93
 
93
 
94
		$criteres['debut'] = isset($_GET['debut']) ? intval($_GET['debut']) : 0;
94
		$criteres['debut'] = isset($_GET['debut']) ? intval($_GET['debut']) : 0;
95
		$criteres['limite'] = isset($_GET['limite']) ? intval($_GET['limite']) : 0;
95
		$criteres['limite'] = isset($_GET['limite']) ? intval($_GET['limite']) : 0;
96
		$observations = $chercheur_observations->rechercherObservations($params['uid'],
96
		$observations = $chercheur_observations
97
																		$criteres,
-
 
98
																		$criteres['debut'],
97
			->rechercherObservations($params['uid'], $criteres, $criteres['debut'], $criteres['limite'])
99
																		$criteres['limite']);
98
			->get();
100
 
99
			
-
 
100
		// debug //echo ($chercheur_observations->requete_selection_observations);
101
		// XXX: malheureusement l'instance de JRest n'est pas accessible ici
101
		// XXX: malheureusement l'instance de JRest n'est pas accessible ici
102
		if(!$observations) {
102
		if(!$observations) {
103
			header('HTTP/1.0 204 No Content');
103
			header('HTTP/1.0 204 No Content');
104
			exit;
104
			exit;
105
		}
105
		}
106
 
106
 
107
		$objPHPExcel->getProperties()->setCreator($params['widget']) // ou $uid ?
107
		$objPHPExcel->getProperties()->setCreator($params['widget']) // ou $uid ?
108
			->setLastModifiedBy("XX") // TODO: $uid
108
			->setLastModifiedBy("XX") // TODO: $uid
109
			->setTitle("YY") // TODO
109
			->setTitle("YY") // TODO
110
			->setSubject("ZZ") // TODO
110
			->setSubject("ZZ") // TODO
111
			->setDescription("Export blah");
111
			->setDescription("Export blah");
112
			//->setKeywords("office PHPExcel php")
112
			//->setKeywords("office PHPExcel php")
113
			//->setCategory("Test result file")
113
			//->setCategory("Test result file")
114
 
114
 
115
		$objPHPExcel->getActiveSheet()->setTitle("Observations");
115
		$objPHPExcel->getActiveSheet()->setTitle("Observations");
116
		$sheet = $objPHPExcel->setActiveSheetIndex(0);
116
		$sheet = $objPHPExcel->setActiveSheetIndex(0);
117
		$colid = 0;
117
		$colid = 0;
118
		foreach($colonnes as $colonne) {
118
		foreach($colonnes as $colonne) {
119
			$sheet->setCellValueByColumnAndRow($colid, 1, $colonne['nom']);
119
			$sheet->setCellValueByColumnAndRow($colid, 1, $colonne['nom']);
120
			if($colonne['extra']) {
120
			if($colonne['extra']) {
121
				$sheet->getStyleByColumnAndRow($colid, 1)->getBorders()->applyFromArray(
121
				$sheet->getStyleByColumnAndRow($colid, 1)->getBorders()->applyFromArray(
122
					array(
122
					array(
123
						'allborders' => array(
123
						'allborders' => array(
124
							'style' => PHPExcel_Style_Border::BORDER_DASHDOT,
124
							'style' => PHPExcel_Style_Border::BORDER_DASHDOT,
125
							'color' => array('rgb' => PHPExcel_Style_Color::COLOR_BLUE)
125
							'color' => array('rgb' => PHPExcel_Style_Color::COLOR_BLUE)
126
						)
126
						)
127
					)
127
					)
128
				);
128
				);
129
			}
129
			}
130
			$colid++;
130
			$colid++;
131
		}
131
		}
132
 
132
 
133
		$objPHPExcel->getActiveSheet()->getDefaultColumnDimension()->setWidth(12);
133
		$objPHPExcel->getActiveSheet()->getDefaultColumnDimension()->setWidth(12);
134
 
134
 
135
		$row = 2;
135
		$row = 2;
136
		foreach ($observations as $obs) {
136
		foreach ($observations as $obs) {
137
			$colid = 0;
137
			$colid = 0;
138
			foreach($colonnes as $slug => $colonne) {
138
			foreach($colonnes as $slug => $colonne) {
-
 
139
				// valeur direct depuis cel_obs ?
139
				$valeur = $obs[$slug];
140
				if(isset($obs[$slug])) $valeur = $obs[$slug];
140
 
141
 
141
				// pré-processeur des champs
142
				// pré-processeur de la champs
142
				if(function_exists($colonne['function']))
143
				if(function_exists($colonne['fonction'])) {
143
					$valeur = $colonne['function']($valeur);
144
					$valeur = $colonne['fonction']($valeur);
144
				elseif(method_exists(__CLASS__, $colonne['function']))
145
				} elseif(method_exists(__CLASS__, $colonne['fonction'])) {
145
					$valeur = call_user_func(array(__CLASS__, $colonne['function']), $valeur);
146
					$valeur = call_user_func(array(__CLASS__, $colonne['fonction']), $valeur);
146
				elseif($colonne['function']) {
147
				} elseif($colonne['fonction']) {
-
 
148
					die("méthode {$colonne['fonction']} introuvable");
-
 
149
				}
-
 
150
				// fonction pour obtenir des champs (étendus)
-
 
151
				elseif(function_exists($colonne['fonction_data'])) {
-
 
152
					$valeur = $colonne['fonction_data']($obs);
-
 
153
				}
-
 
154
				elseif(method_exists(__CLASS__, $colonne['fonction_data'])) {
147
					die("méthode {$colonne['function']} introuvable");
155
					$valeur = call_user_func(array(__CLASS__, $colonne['fonction_data']), $obs);
-
 
156
				}
148
				}
157
 
149
 
158
 
150
				// // cette section devrait être vide:
159
				// // cette section devrait être vide:
151
				// // cas particuliers ingérable avec l'architecture actuelle:
160
				// // cas particuliers ingérable avec l'architecture actuelle:
152
				if(false && $slug == 'date_observation' && $valeur == "0000-00-00") { /* blah */ }
161
				if(false && $slug == 'date_observation' && $valeur == "0000-00-00") { /* blah */ }
153
				// // fin de section "cas particuliers"
162
				// // fin de section "cas particuliers"
154
 
163
 
155
				$sheet->setCellValueByColumnAndRow($colid, $row, $valeur);
164
				$sheet->setCellValueByColumnAndRow($colid, $row, $valeur);
156
				$colid++;
165
				$colid++;
157
			}
166
			}
158
			$row++;
167
			$row++;
159
		}
168
		}
160
 
169
 
161
		header("Content-Type: application/vnd.ms-excel");
170
		header("Content-Type: application/vnd.ms-excel");
162
		header("Content-Disposition: attachment; filename=\"liste.xls\"; charset=utf-8");
171
		header("Content-Disposition: attachment; filename=\"liste.xls\"; charset=utf-8");
163
		header("Cache-Control: max-age=0");
172
		header("Cache-Control: max-age=0");
164
		// Le format Excel2007 utilise un fichier temporaire
173
		// Le format Excel2007 utilise un fichier temporaire
165
		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
174
		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
166
		// $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
175
		// $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
167
		$objWriter->save('php://output');
176
		$objWriter->save('php://output');
168
		exit;
177
		exit;
169
	}
178
	}
170
 
179
 
171
	/*
180
	/*
172
	 * @param $fieldSets: un range, eg: 1-5,8,32,58-101
181
	 * @param $fieldSets: un range, eg: 1-5,8,32,58-101
173
	 * @return un tableau trié, eg: 1,2,3,4,5,8,32,58,...,101
182
	 * @return un tableau trié, eg: 1,2,3,4,5,8,32,58,...,101
174
	 */
183
	 */
175
	static function rangeToList($in = '') {
184
	static function rangeToList($in = '') {
176
		$inSets = explode(',', $in);
185
		$inSets = explode(',', $in);
177
		$outSets = array();
186
		$outSets = array();
-
 
187
 
178
		foreach($inSets as $inSet) {
188
		foreach($inSets as $inSet) {
179
			list($start,$end) = explode('-', $inSet . '-' . $inSet);
189
			list($start,$end) = explode('-', $inSet . '-' . $inSet);
180
			$outSets = array_merge($outSets,range($start,$end));
190
			$outSets = array_merge($outSets,range($start,$end));
181
		}
191
		}
182
		$outSets = array_unique($outSets);
192
		$outSets = array_unique($outSets);
183
		$outSets = array_filter($outSets, 'is_numeric');
193
		$outSets = array_filter($outSets, 'is_numeric');
184
		sort($outSets);
194
		sort($outSets);
185
		return $outSets;
195
		return $outSets;
186
	}
196
	}
187
 
197
 
188
	/*
198
	/*
189
	 * @param $fieldSets: un liste de noms de colonnes ou de sets de colonnes
199
	 * @param $fieldSets: un liste de noms de colonnes ou de sets de colonnes
190
	 *		séparés par des virgules
200
	 *		séparés par des virgules
191
	 * 		eg: "espece" ou "champs-etendus", ...
201
	 * 		eg: "espece" ou "champs-etendus", ...
192
	 *
202
	 *
193
	 * @return: un tableau associatif déjà ordonné
203
	 * @return: un tableau associatif déjà ordonné
194
	 * 		clé: slug [machine-name] de la colonne (eg: "espece" ou "mot-clef")
204
	 * 		clé: slug [machine-name] de la colonne (eg: "espece" ou "mot-clef")
195
	 * 		valeur: des données relative à cette colonne, cf GenColInfo
205
	 * 		valeur: des données relative à cette colonne, cf GenColInfo
196
	 *
206
	 *
197
	 * @TODO: fonction commune à la génération en CSV
207
	 * @TODO: fonction commune à la génération en CSV
198
	 */
208
	 */
199
	static function fieldSetsToColumns($fieldSets = 'standard') {
209
	static function fieldSetsToColumns($fieldSets = 'standard') {
200
		if(! $fieldSets) $fieldSets = 'standard';
210
		if(! $fieldSets) $fieldSets = 'standard';
201
		$fieldSets = array_flip(explode(',', $fieldSets));
211
		$fieldSets = array_flip(explode(',', $fieldSets));
202
		$colonnes = Array();
212
		$colonnes = Array();
203
 
213
 
204
		if(isset($fieldSets['standard'])) {
214
		if(isset($fieldSets['standard'])) {
205
		   $colonnes += Array(
215
		   $colonnes += Array(
206
			   'nom_sel'			=> self::GenColInfo('nom_sel', 'Espèce'),
216
			   'nom_sel'			=> self::GenColInfo('nom_sel', 'Espèce'),
207
			   'nom_sel_nn'			=> self::GenColInfo('nom_sel_nn', 'Numero nomenclatural'),
217
			   'nom_sel_nn'			=> self::GenColInfo('nom_sel_nn', 'Numéro nomenclatural'),
208
			   'nom_ret'			=> self::GenColInfo('nom_ret', 'Nom retenu'),
218
			   'nom_ret'			=> self::GenColInfo('nom_ret', 'Nom retenu'),
209
			   'nom_ret_nn'			=> self::GenColInfo('nom_ret_nn', 'Numero nomenclatural nom retenu'),
219
			   'nom_ret_nn'			=> self::GenColInfo('nom_ret_nn', 'Numéro nomenclatural nom retenu'),
210
			   'nt'					=> self::GenColInfo('nt', 'Numero taxonomique'),
220
			   'nt'					=> self::GenColInfo('nt', 'Numéro taxonomique'),
211
			   'famille'			=> self::GenColInfo('famille', 'Famille'),
221
			   'famille'			=> self::GenColInfo('famille', 'Famille'),
212
			   'nom_referentiel'	=> self::GenColInfo('nom_referentiel', 'Referentiel taxonomique'),
222
			   'nom_referentiel'	=> self::GenColInfo('nom_referentiel', 'Referentiel taxonomique'),
213
			   'zone_geo'			=> self::GenColInfo('zone_geo', 'Commune'),
223
			   'zone_geo'			=> self::GenColInfo('zone_geo', 'Commune'),
214
			   'ce_zone_geo'		=> self::GenColInfo('ce_zone_geo', 'Identifiant Commune', 0, 'convertirCodeZoneGeoVersDepartement'),
224
			   'ce_zone_geo'		=> self::GenColInfo('ce_zone_geo', 'Identifiant Commune', 0, 'convertirCodeZoneGeoVersDepartement'),
215
			   'date_observation'	=> self::GenColInfo('date_observation', 'Date', 0, 'formaterDate'),
225
			   'date_observation'	=> self::GenColInfo('date_observation', 'Date', 0, 'formaterDate'),
216
			   'lieudit'			=> self::GenColInfo('lieudit', 'Lieu-dit'),
226
			   'lieudit'			=> self::GenColInfo('lieudit', 'Lieu-dit'),
217
			   'station'			=> self::GenColInfo('station', 'Station'),
227
			   'station'			=> self::GenColInfo('station', 'Station'),
218
			   'milieu'				=> self::GenColInfo('milieu', 'Milieu'),
228
			   'milieu'				=> self::GenColInfo('milieu', 'Milieu'),
219
			   'commentaire'		=> self::GenColInfo('commentaire', 'Notes'),
229
			   'commentaire'		=> self::GenColInfo('commentaire', 'Notes'),
220
			   'latitude'			=> self::GenColInfo('latitude', 'Latitude', 1),
230
			   'latitude'			=> self::GenColInfo('latitude', 'Latitude', 1),
221
			   'longitude'			=> self::GenColInfo('longitude', 'Longitude', 1),
231
			   'longitude'			=> self::GenColInfo('longitude', 'Longitude', 1),
222
			   'geodatum'			=> self::GenColInfo('geodatum', 'Referentiel Geographique', 1),
232
			   'geodatum'			=> self::GenColInfo('geodatum', 'Référentiel Géographique', 1),
223
 
233
 
224
			   'ordre'				=> self::GenColInfo('ordre', 'Ordre', 1),
234
			   'ordre'				=> self::GenColInfo('ordre', 'Ordre', 1),
225
			   'id_observation'		=> self::GenColInfo('id_observation', 'Identifiant', 1),
235
			   'id_observation'		=> self::GenColInfo('id_observation', 'Identifiant', 1),
226
 
236
 
227
			   'mots_cles_texte'	=> self::GenColInfo('mots_cles_texte', 'Mots Clés', 1),
237
			   'mots_cles_texte'	=> self::GenColInfo('mots_cles_texte', 'Mots Clés', 1),
228
			   'commentaire'		=> self::GenColInfo('commentaire', 'Commentaires', 1),
238
			   'commentaire'		=> self::GenColInfo('commentaire', 'Commentaires', 1),
229
			   'date_creation'		=> self::GenColInfo('date_creation', 'Date Création', 1),
239
			   'date_creation'		=> self::GenColInfo('date_creation', 'Date Création', 1),
230
			   'date_modification'	=> self::GenColInfo('date_modification', 'Date Modification', 1),
240
			   'date_modification'	=> self::GenColInfo('date_modification', 'Date Modification', 1),
231
			   'date_transmission'	=> self::GenColInfo('date_transmission', 'Date Transmission', 1),
241
			   'date_transmission'	=> self::GenColInfo('date_transmission', 'Date Transmission', 1),
232
			   'abondance'			=> self::GenColInfo('abondance', 'Abondance', 1),
242
			   'abondance'			=> self::GenColInfo('abondance', 'Abondance', 1),
233
			   'certitude'			=> self::GenColInfo('certitude', 'Certitude', 1),
243
			   'certitude'			=> self::GenColInfo('certitude', 'Certitude', 1),
234
			   'phenologie'			=> self::GenColInfo('phenologie', 'Phénologie', 1),
244
			   'phenologie'			=> self::GenColInfo('phenologie', 'Phénologie', 1),
235
			   
245
 
-
 
246
			   //'nom-commun'			=> self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun')
-
 
247
			   //'nom-commun'			=> self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun_v2')
-
 
248
			   //'nom-commun'			=> self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun_v3')
236
		   );
249
		   );
237
		}
250
		}
238
 
251
 
239
		return $colonnes;
252
		return $colonnes;
240
	}
253
	}
241
 
254
 
242
	/*
255
	/*
243
	 * Wrapper générant un tableau associatif:
256
	 * Wrapper générant un tableau associatif:
244
	 * @param $is_extra: défini si la colonne est extra (auquelle une bordure bleue entoure son nom dans la première ligne
257
	 * @param $is_extra: défini si la colonne est extra (auquelle une bordure bleue entoure son nom dans la première ligne
245
	 * @param $function: un nom optionnel d'un fonction de préprocessing
258
	 * @param $fonction (optionnel): un nom d'un fonction de préprocessing
246
	 * 		$function doit prendre comme argument la valeur et retourner la valeur transformée
259
	 * 		  $fonction doit prendre comme seul argument la valeur d'origine et retourner la valeur transformée
-
 
260
	 * @param $fonction_data (optionnel): une *méthode* d'obtention de donnée
-
 
261
	 * 		  $fonction_data doit prendre comme premier argument les champs de l'enregistrement existant
-
 
262
	 *		  $fonction_data doit retourner une valeur
-
 
263
 
247
	 */
264
	 */
248
	static function GenColInfo($slug, $nom, $is_extra = 0, $function = NULL) {
265
	static function GenColInfo($slug, $nom, $is_extra = 0, $fonction = NULL, $fonction_data = NULL) {
249
		return Array('slug' => $slug,
266
		return Array('slug' => $slug,
250
					 'nom' => $nom,
267
					 'nom' => $nom,
251
					 'extra' => $is_extra ? 1 : 0,
268
					 'extra' => $is_extra ? 1 : 0,
252
					 'function' => $function
269
					 'fonction' => $fonction,
-
 
270
					 'fonction_data' => $fonction_data
253
		);
271
		);
254
	}
272
	}
255
 
273
 
256
	protected function formaterDate($date_heure_mysql, $format = NULL) {
274
	protected function formaterDate($date_heure_mysql, $format = NULL) {
257
		if (!$date_heure_mysql || $date_heure_mysql == "0000-00-00 00:00:00") return "00/00/0000";
275
		if (!$date_heure_mysql || $date_heure_mysql == "0000-00-00 00:00:00") return "00/00/0000";
258
		$timestamp = DateTime::createFromFormat("Y-m-d H:i:s", $date_heure_mysql);
276
		$timestamp = DateTime::createFromFormat("Y-m-d H:i:s", $date_heure_mysql)->getTimestamp();
259
		if(!$timestamp) return "00/00/0000";
277
		if(!$timestamp) return "00/00/0000";
260
		// TODO: les widget ne font malheureusement pas usage de l'heure dans le CEL
278
		// TODO: les widget ne font malheureusement pas usage de l'heure dans le CEL
261
		$date_formatee = strftime('%A %d %B %Y', $timestamp->getTimestamp());
279
		$date_formatee = strftime('%A %d %B %Y', $timestamp);
262
		if(!$date_formatee) return "00/00/0000";
280
		if(!$date_formatee) return "00/00/0000";
263
		return $date_formatee;
281
		return $date_formatee;
264
	}
282
	}
265
}
283
}
266
284