Subversion Repositories eFlore/Applications.cel

Rev

Rev 2459 | Rev 3166 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2459 Rev 2462
Line 1... Line 1...
1
<?php
1
<?php
-
 
2
// declare(encoding='UTF-8');
2
/**
3
/**
3
* PHP Version 5
4
 * Classe de gestion de l'ajout, modification et suppression des champs supplémentaires des obs et images.
4
* in=utf8
-
 
5
* out=utf8
-
 
6
*
5
 *
-
 
6
 * @internal   Mininum PHP version : 5.2
7
* @category  PHP
7
 * @category   CEL
8
* @package   jrest
8
 * @package    Services
-
 
9
 * @subpackage Bibliothèques
-
 
10
 * @version    0.1
9
* @author    Aurelien Peronnet <aurelien@tela-botanica.org>
11
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
10
* @copyright 2010 Tela-Botanica
12
 * @author     Raphaël Droz <raphael@tela-botania.org>
11
* @license   http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
13
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
12
* @version   SVN: <svn_id>
14
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
13
* @link      /doc/jrest/
15
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
14
*/
-
 
15
 
-
 
16
/**
-
 
17
* Classe de gestion de l'ajout, modification et suppression des champs supplémentaires des obs et images
16
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
-
 
17
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
18
*/
18
 */
19
class GestionChampsEtendus extends Cel {
19
class GestionChampsEtendus extends Cel {
Line 20... Line 20...
20
 
20
 
21
	private $mode = null;
21
	private $mode = null;
Line 52... Line 52...
52
		$id = Cel::db()->proteger($id_element_lie);
52
		$id = Cel::db()->proteger($id_element_lie);
53
		$cle = Cel::db()->proteger($cle);
53
		$cle = Cel::db()->proteger($cle);
54
		$requete = 'SELECT COUNT(*) >= 1 AS existe '.
54
		$requete = 'SELECT COUNT(*) >= 1 AS existe '.
55
			"FROM {$this->table_champs_etendus} ".
55
			"FROM {$this->table_champs_etendus} ".
56
			"WHERE {$this->champ_id} = $id ".
56
			"WHERE {$this->champ_id} = $id ".
57
			"	AND cle = $cle ";
57
			"	AND cle = $cle ".
-
 
58
			' -- '.__FILE__.':'.__LINE__;;
Line 58... Line 59...
58
 
59
 
59
		$resultat = Cel::db()->requeter($requete);
60
		$resultat = Cel::db()->requeter($requete);
60
		return ($resultat[0]['existe'] == '1');
61
		return ($resultat[0]['existe'] == '1');
Line 66... Line 67...
66
	* @param int $id_element_lie
67
	* @param int $id_element_lie
67
	* @return array tableau associatif des champs de la table etendu
68
	* @return array tableau associatif des champs de la table etendu
68
	*/
69
	*/
69
	public function consulter($id_element_lie) {
70
	public function consulter($id_element_lie) {
70
		$id = Cel::db()->proteger($id_element_lie);
71
		$id = Cel::db()->proteger($id_element_lie);
-
 
72
		$requete = 'SELECT * '.
71
		$requete = "SELECT * FROM {$this->table_champs_etendus} WHERE {$this->champ_id} = $id ";
73
			"FROM {$this->table_champs_etendus} ".
-
 
74
			"WHERE {$this->champ_id} = $id ".
-
 
75
			' -- '.__FILE__.':'.__LINE__;
72
		$resultat = Cel::db()->requeter($requete);
76
		$resultat = Cel::db()->requeter($requete);
73
		return $resultat;
77
		return $resultat;
74
	}
78
	}
Line 75... Line 79...
75
 
79
 
Line 119... Line 123...
119
		$valeur = Cel::db()->proteger($champ_etendu->valeur);
123
		$valeur = Cel::db()->proteger($champ_etendu->valeur);
Line 120... Line 124...
120
 
124
 
121
		$requete = "INSERT INTO {$this->table_champs_etendus} ".
125
		$requete = "INSERT INTO {$this->table_champs_etendus} ".
122
			"( {$this->champ_id}, cle, valeur) ".
126
			"( {$this->champ_id}, cle, valeur) ".
123
			"VALUES ($id, $cle, $valeur) ".
127
			"VALUES ($id, $cle, $valeur) ".
-
 
128
			"ON DUPLICATE KEY UPDATE valeur = VALUES(valeur) ".
Line 124... Line 129...
124
			"ON DUPLICATE KEY UPDATE valeur = VALUES(valeur)";
129
			' -- '.__FILE__.':'.__LINE__;
125
 
130
 
126
		// la partie on duplicate key est spécifique mysql mais il sera facile de s'en passer le jour
131
		// la partie on duplicate key est spécifique mysql mais il sera facile de s'en passer le jour
127
		// où l'on change de sgbd
132
		// où l'on change de sgbd
Line 171... Line 176...
171
		$valeur = Cel::db()->proteger($champ_etendu->valeur);
176
		$valeur = Cel::db()->proteger($champ_etendu->valeur);
Line 172... Line 177...
172
 
177
 
173
		$requete = "UPDATE {$this->table_champs_etendus} ".
178
		$requete = "UPDATE {$this->table_champs_etendus} ".
174
			"SET valeur = $valeur ".
179
			"SET valeur = $valeur ".
175
			"WHERE cle = $cle".
180
			"WHERE cle = $cle".
176
			"	AND {$this->champ_id} = $id ";
-
 
-
 
181
			"	AND {$this->champ_id} = $id ".
177
 
182
			' -- '.__FILE__.':'.__LINE__;
178
		$modif = Cel::db()->executer($requete);
183
		$modif = Cel::db()->executer($requete);
179
		return ($modif !== false);
184
		return ($modif !== false);
Line 180... Line 185...
180
	}
185
	}
Line 187... Line 192...
187
	* @return bool
192
	* @return bool
188
	*/
193
	*/
189
	public function supprimer($id_element_lie, $cle) {
194
	public function supprimer($id_element_lie, $cle) {
190
		$id = Cel::db()->proteger($id_element_lie);
195
		$id = Cel::db()->proteger($id_element_lie);
191
		$cle = Cel::db()->proteger($cle);
196
		$cle = Cel::db()->proteger($cle);
192
		$requete = "DELETE FROM {$this->table_champs_etendus} WHERE cle = $cle AND {$this->champ_id} = $id ";
197
		$requete = "DELETE FROM {$this->table_champs_etendus} ".
-
 
198
			"WHERE cle = $cle ".
-
 
199
			"AND {$this->champ_id} = $id ".
-
 
200
			' -- '.__FILE__.':'.__LINE__;
193
		$suppr = Cel::db()->executer($requete);
201
		$suppr = Cel::db()->executer($requete);
194
		return ($suppr !== false);
202
		return ($suppr !== false);
195
	}
203
	}
Line 196... Line 204...
196
 
204
 
Line 200... Line 208...
200
	* @param int $id_element_lie
208
	* @param int $id_element_lie
201
	* @return bool
209
	* @return bool
202
	*/
210
	*/
203
	public function vider($id_element_lie) {
211
	public function vider($id_element_lie) {
204
		$id = Cel::db()->proteger($id_element_lie);
212
		$id = Cel::db()->proteger($id_element_lie);
205
		$requete = "DELETE FROM {$this->table_champs_etendus} WHERE {$this->champ_id} = $id ";
213
		$requete = "DELETE FROM {$this->table_champs_etendus} ".
-
 
214
			"WHERE {$this->champ_id} = $id ".
-
 
215
			' -- '.__FILE__.':'.__LINE__;
206
		$suppr = Cel::db()->executer($requete);
216
		$suppr = Cel::db()->executer($requete);
207
		return ($suppr !== false);
217
		return ($suppr !== false);
208
	}
218
	}
Line 209... Line 219...
209
 
219
 
Line 213... Line 223...
213
	* @param array $ids_elements_lies
223
	* @param array $ids_elements_lies
214
	* @return bool
224
	* @return bool
215
	*/
225
	*/
216
	public function viderParLots($ids_elements_lies) {
226
	public function viderParLots($ids_elements_lies) {
217
		$ids = $this->protegerTableau($ids_elements_lies);
227
		$ids = $this->protegerTableau($ids_elements_lies);
218
		$requete = "DELETE FROM {$this->table_champs_etendus} WHERE {$this->champ_id} IN (".implode(',',$ids).") ";
228
		$requete = "DELETE FROM {$this->table_champs_etendus} ".
-
 
229
			"WHERE {$this->champ_id} IN (".implode(',',$ids).") ".
-
 
230
			' -- '.__FILE__.':'.__LINE__;
219
		$suppr = Cel::db()->executer($requete);
231
		$suppr = Cel::db()->executer($requete);
220
		return ($suppr !== false);
232
		return ($suppr !== false);
221
	}
233
	}
Line 222... Line 234...
222
 
234
 
Line 228... Line 240...
228
	*/
240
	*/
229
	public function consulterClesParLots($ids_elements_lies) {
241
	public function consulterClesParLots($ids_elements_lies) {
230
		$cles_fmt = array();
242
		$cles_fmt = array();
231
		if(!empty($ids_elements_lies)) {
243
		if(!empty($ids_elements_lies)) {
232
			$ids = $this->protegerTableau($ids_elements_lies);
244
			$ids = $this->protegerTableau($ids_elements_lies);
-
 
245
			$requete = 'SELECT cle '.
-
 
246
				"FROM {$this->table_champs_etendus} ".
233
			$requete = "SELECT cle FROM {$this->table_champs_etendus} WHERE {$this->champ_id} IN (".implode(',',$ids).") ";
247
				"WHERE {$this->champ_id} IN (".implode(',',$ids).") ".
-
 
248
				' -- '.__FILE__.':'.__LINE__;
234
			$cles = Cel::db()->requeter($requete);
249
			$cles = Cel::db()->requeter($requete);
235
			$i = 0;
250
			$i = 0;
236
			foreach($cles as &$cle) {
251
			foreach($cles as &$cle) {
237
				$cles_fmt[$cle['cle']] = $i++;
252
				$cles_fmt[$cle['cle']] = $i++;
238
			}
253
			}
Line 246... Line 261...
246
	public function consulterGroupesChampsEtendusPredefinis() {
261
	public function consulterGroupesChampsEtendusPredefinis() {
247
		$groupes = array();
262
		$groupes = array();
248
		$requete =  "SELECT cc.cle as cle_groupe, cc.label as nom_groupe, ccc.cle as cle_champ, ccc.label as label_champ, ccc.invisible, ccc.prive ".
263
		$requete =  "SELECT cc.cle as cle_groupe, cc.label as nom_groupe, ccc.cle as cle_champ, ccc.label as label_champ, ccc.invisible, ccc.prive ".
249
					"FROM `cel_catalogue_champs_etendus` cc ".
264
			"FROM `cel_catalogue_champs_etendus` cc ".
250
					"INNER JOIN cel_catalogue_champs_etendus_liaison cl ON cc.cle = cl.groupe ".
265
			"INNER JOIN cel_catalogue_champs_etendus_liaison cl ON cc.cle = cl.groupe ".
251
					"INNER JOIN cel_catalogue_champs_etendus ccc ON ccc.cle = cl.champ";
266
			"INNER JOIN cel_catalogue_champs_etendus ccc ON ccc.cle = cl.champ ".
252
 
-
 
-
 
267
			' -- '.__FILE__.':'.__LINE__;
253
		$groupes_champs = Cel::db()->executerRequete($requete);
268
		$groupes_champs = Cel::db()->executerRequete($requete);
Line 254... Line 269...
254
		
269
 
255
		$cle_groupe = "";
270
		$cle_groupe = '';
Line 256... Line 271...
256
		$infos_groupe = null;
271
		$infos_groupe = null;
257
		
272
 
258
		foreach ($groupes_champs as $groupe_champ) {
273
		foreach ($groupes_champs as $groupe_champ) {
Line 276... Line 291...
276
			}
291
			}
Line 277... Line 292...
277
			
292
 
278
			$infos_groupe['champs'][] = array(
293
			$infos_groupe['champs'][] = array(
279
											'cle'	=> $groupe_champ['cle_champ'],
294
				'cle'	=> $groupe_champ['cle_champ'],
-
 
295
				'label' => $groupe_champ['label_champ'],
280
											'label' => $groupe_champ['label_champ'],
296
				'options' => array(
281
											'options' => array('invisible' => $groupe_champ['invisible'],
297
					'invisible' => $groupe_champ['invisible'],
282
														 		'prive'	=> $groupe_champ['prive']
-
 
283
													)
298
					'prive'	=> $groupe_champ['prive'])
284
										);
299
			);
Line 285... Line 300...
285
		}
300
		}
286
		
301
 
Line 296... Line 311...
296
	
311
 
297
	/**
312
	/**
298
	 * Renvoie le catalogue des champs étendus
313
	 * Renvoie le catalogue des champs étendus
299
	 */
314
	 */
300
	public function consulterCatalogueChampsEtendusPredefinis($ordonner_par_cle = false) {
315
	public function consulterCatalogueChampsEtendusPredefinis($ordonner_par_cle = false) {
301
		$requete =  "SELECT cle, label, invisible, prive ".
316
		$requete =  'SELECT cle, label, invisible, prive '.
302
					"FROM cel_catalogue_champs_etendus cc ";
-
 
-
 
317
			'FROM cel_catalogue_champs_etendus AS cc '.
303
		
318
			' -- '.__FILE__.':'.__LINE__;
304
		$catalogue = Cel::db()->executerRequete($requete);
-
 
Line -... Line 319...
-
 
319
		$catalogue = Cel::db()->executerRequete($requete);
305
		$infos_champs = array();
320
 
306
		
321
		$infos_champs = array();
307
		foreach ($catalogue as $champ) {
322
		foreach ($catalogue as $champ) {
308
			$champ_fmt = array(
323
			$champ_fmt = array(
-
 
324
				'cle'	=> $champ['cle'],
309
				'cle'	=> $champ['cle'],
325
				'label' => $champ['label'],
310
				'label' => $champ['label'],
326
				'options' => array(
311
				'options' => array('invisible' => $champ['invisible'],
-
 
312
									'prive'	=> $champ['prive']
327
					'invisible' => $champ['invisible'],
313
							)
328
					'prive'	=> $champ['prive'])
314
			);
329
			);
315
			if($ordonner_par_cle) {
330
			if ($ordonner_par_cle) {
316
				$infos_champs[$champ_fmt['cle']] = $champ_fmt;
331
				$infos_champs[$champ_fmt['cle']] = $champ_fmt;
Line 358... Line 373...
358
		$cle{0} = strtolower($cle{0});
373
		$cle{0} = strtolower($cle{0});
Line 359... Line 374...
359
 
374
 
360
		return $cle;
375
		return $cle;
361
	}
376
	}
362
}
-
 
363
?>
377
}