Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 3474 Rev 3477
Line 20... Line 20...
20
 
20
 
21
	private $mode = null;
21
	private $mode = null;
22
	private $table_champs_etendus = null;
22
	private $table_champs_etendus = null;
Line 23... Line 23...
23
	private $champ_id = null;
23
	private $champ_id = null;
24
 
24
 
25
	public function __construct($config, $mode) {
25
	public function __construct($config, $mode = 'obs') {
-
 
26
		parent::__construct($config);
-
 
27
		$this->mode = $mode;
Line 26... Line -...
26
		parent::__construct($config);
-
 
27
		$this->mode = $mode;
-
 
28
 
-
 
29
		if ($this->mode == 'obs') {
-
 
30
			$this->mode = 'obs';
-
 
31
			$this->table_champs_etendus = 'cel_obs_etendues';
-
 
32
			$this->champ_id = 'id_observation';
-
 
33
		} else if ($this->mode == 'image') {
-
 
34
			$this->mode = 'image';
-
 
35
			$this->table_champs_etendus = 'cel_images_etendues';
-
 
36
			$this->champ_id = 'id_image';
-
 
37
		} else {
28
		$this->table_champs_etendus = 'extended_field_occurrence';
Line 38... Line 29...
38
			throw new Exception('Mode inconnu, les modes autorisés sont "obs" et "image"');
29
		$this->champ_id = 'occurrence_id';
39
		}
30
		
40
	}
31
	}
Line 52... Line 43...
52
		$id = Cel::db()->proteger($id_element_lie);
43
		$id = Cel::db()->proteger($id_element_lie);
53
		$cle = Cel::db()->proteger($cle);
44
		$cle = Cel::db()->proteger($cle);
54
		$requete = 'SELECT COUNT(*) >= 1 AS existe '.
45
		$requete = 'SELECT COUNT(*) >= 1 AS existe '.
55
			"FROM {$this->table_champs_etendus} ".
46
			"FROM {$this->table_champs_etendus} ".
56
			"WHERE {$this->champ_id} = $id ".
47
			"WHERE {$this->champ_id} = $id ".
57
			"	AND cle = $cle ".
48
			"	AND extended_field_id = $cle ".
58
			' -- '.__FILE__.':'.__LINE__;;
49
			' -- '.__FILE__.':'.__LINE__;;
Line 59... Line 50...
59
 
50
 
60
		$resultat = Cel::db()->requeter($requete);
51
		$resultat = Cel::db()->requeter($requete);
61
		return ($resultat[0]['existe'] == '1');
52
		return ($resultat[0]['existe'] == '1');
Line 99... Line 90...
99
				if (!isset($champs_etendus_par_element[$id_element])) {
90
				if (!isset($champs_etendus_par_element[$id_element])) {
100
					$champs_etendus_par_element[$id_element] = array();
91
					$champs_etendus_par_element[$id_element] = array();
101
				}
92
				}
102
				$champ_etendu = new ObsEtendue();
93
				$champ_etendu = new ObsEtendue();
103
				$champ_etendu->id = $id_element;
94
				$champ_etendu->id = $id_element;
104
				$champ_etendu->cle = $ligne['cle'];
95
				$champ_etendu->cle = $ligne['extended_field_id'];
105
				$champ_etendu->valeur = $ligne['valeur'];
96
				$champ_etendu->valeur = $ligne['value'];
Line 106... Line 97...
106
 
97
 
107
				$champs_etendus_par_element[$id_element][] = $champ_etendu;
98
				$champs_etendus_par_element[$id_element][] = $champ_etendu;
108
			}
99
			}
109
		}
100
		}
Line 121... Line 112...
121
		$id = Cel::db()->proteger($champ_etendu->id);
112
		$id = Cel::db()->proteger($champ_etendu->id);
122
		$cle = Cel::db()->proteger($champ_etendu->cle);
113
		$cle = Cel::db()->proteger($champ_etendu->cle);
123
		$valeur = Cel::db()->proteger($champ_etendu->valeur);
114
		$valeur = Cel::db()->proteger($champ_etendu->valeur);
Line 124... Line 115...
124
 
115
 
125
		$requete = "INSERT INTO {$this->table_champs_etendus} ".
116
		$requete = "INSERT INTO {$this->table_champs_etendus} ".
126
			"( {$this->champ_id}, cle, valeur) ".
117
			"( {$this->champ_id}, extended_field_id, value) ".
127
			"VALUES ($id, $cle, $valeur) ".
118
			"VALUES ($id, $cle, $valeur) ".
128
			"ON DUPLICATE KEY UPDATE valeur = VALUES(valeur) ".
119
			"ON DUPLICATE KEY UPDATE value = VALUES(value) ".
Line 129... Line 120...
129
			' -- '.__FILE__.':'.__LINE__;
120
			' -- '.__FILE__.':'.__LINE__;
130
 
121
 
131
		// la partie on duplicate key est spécifique mysql mais il sera facile de s'en passer le jour
122
		// la partie on duplicate key est spécifique mysql mais il sera facile de s'en passer le jour
Line 154... Line 145...
154
		}
145
		}
Line 155... Line 146...
155
 
146
 
156
		// la partie on duplicate key est spécifique mysql mais il sera facile de s'en passer le jour
147
		// la partie on duplicate key est spécifique mysql mais il sera facile de s'en passer le jour
157
		// où l'on change de sgbd
148
		// où l'on change de sgbd
158
		$ajout = Cel::db()->executer(sprintf(
149
		$ajout = Cel::db()->executer(sprintf(
159
			"INSERT INTO %s (%s, cle, valeur) VALUES %s ON DUPLICATE KEY UPDATE valeur = VALUES(valeur) -- %s:%d",
150
			"INSERT INTO %s (%s, extended_field_id, valeur) VALUES %s ON DUPLICATE KEY UPDATE value = VALUES(valeur) -- %s:%d",
160
			$this->table_champs_etendus,
151
			$this->table_champs_etendus,
161
			$this->champ_id,
152
			$this->champ_id,
162
			implode(',', $lignes),
153
			implode(',', $lignes),
163
			__FILE__, __LINE__));
154
			__FILE__, __LINE__));
Line 174... Line 165...
174
		$id = Cel::db()->proteger($champ_etendu->id);
165
		$id = Cel::db()->proteger($champ_etendu->id);
175
		$cle = Cel::db()->proteger($champ_etendu->cle);
166
		$cle = Cel::db()->proteger($champ_etendu->cle);
176
		$valeur = Cel::db()->proteger($champ_etendu->valeur);
167
		$valeur = Cel::db()->proteger($champ_etendu->valeur);
Line 177... Line 168...
177
 
168
 
178
		$requete = "UPDATE {$this->table_champs_etendus} ".
169
		$requete = "UPDATE {$this->table_champs_etendus} ".
179
			"SET valeur = $valeur ".
170
			"SET value = $valeur ".
180
			"WHERE cle = $cle".
171
			"WHERE extended_field_id = $cle".
181
			"	AND {$this->champ_id} = $id ".
172
			"	AND {$this->champ_id} = $id ".
182
			' -- '.__FILE__.':'.__LINE__;
173
			' -- '.__FILE__.':'.__LINE__;
183
		$modif = Cel::db()->executer($requete);
174
		$modif = Cel::db()->executer($requete);
184
		return ($modif !== false);
175
		return ($modif !== false);
Line 193... Line 184...
193
	*/
184
	*/
194
	public function supprimer($id_element_lie, $cle) {
185
	public function supprimer($id_element_lie, $cle) {
195
		$id = Cel::db()->proteger($id_element_lie);
186
		$id = Cel::db()->proteger($id_element_lie);
196
		$cle = Cel::db()->proteger($cle);
187
		$cle = Cel::db()->proteger($cle);
197
		$requete = "DELETE FROM {$this->table_champs_etendus} ".
188
		$requete = "DELETE FROM {$this->table_champs_etendus} ".
198
			"WHERE cle = $cle ".
189
			"WHERE extended_field_id = $cle ".
199
			"AND {$this->champ_id} = $id ".
190
			"AND {$this->champ_id} = $id ".
200
			' -- '.__FILE__.':'.__LINE__;
191
			' -- '.__FILE__.':'.__LINE__;
201
		$suppr = Cel::db()->executer($requete);
192
		$suppr = Cel::db()->executer($requete);
202
		return ($suppr !== false);
193
		return ($suppr !== false);
203
	}
194
	}
Line 240... Line 231...
240
	*/
231
	*/
241
	public function consulterClesParLots($ids_elements_lies) {
232
	public function consulterClesParLots($ids_elements_lies) {
242
		$cles_fmt = array();
233
		$cles_fmt = array();
243
		if(!empty($ids_elements_lies)) {
234
		if(!empty($ids_elements_lies)) {
244
			$ids = $this->protegerTableau($ids_elements_lies);
235
			$ids = $this->protegerTableau($ids_elements_lies);
245
			$requete = 'SELECT cle '.
236
			$requete = 'SELECT extended_field_id as cle '.
246
				"FROM {$this->table_champs_etendus} ".
237
				"FROM {$this->table_champs_etendus} ".
247
				"WHERE {$this->champ_id} IN (".implode(',',$ids).") ".
238
				"WHERE {$this->champ_id} IN (".implode(',',$ids).") ".
248
				' -- '.__FILE__.':'.__LINE__;
239
				' -- '.__FILE__.':'.__LINE__;
249
			$cles = Cel::db()->requeter($requete);
240
			$cles = Cel::db()->requeter($requete);
250
			$i = 0;
241
			$i = 0;
Line 258... Line 249...
258
	/**
249
	/**
259
	 * Renvoie la liste des groupes de champs étendus
250
	 * Renvoie la liste des groupes de champs étendus
260
	 */
251
	 */
261
	public function consulterGroupesChampsEtendusPredefinis($groupe = "", $langue = 'fr') {
252
	public function consulterGroupesChampsEtendusPredefinis($groupe = "", $langue = 'fr') {
262
		$groupes = array();
253
		$groupes = array();
263
		$requete =  "SELECT cc.cle as cle_groupe, cc.label as nom_groupe, ccc.cle as cle_champ, ccc.label as label_champ, ccc.type as type_champ, ccc.valeur as valeur_champ, ccc.invisible, ccc.prive ".
254
		$requete =  "SELECT cc.extended_field_id as cle_groupe, cc.label as nom_groupe, ccc.cle as cle_champ, ccc.label as label_champ, ccc.type as type_champ, ccc.valeur as valeur_champ, ccc.invisible, ccc.prive ".
264
			"FROM `cel_catalogue_champs_etendus` cc ".
255
			"FROM `cel_catalogue_champs_etendus` cc ".
265
			"INNER JOIN cel_catalogue_champs_etendus_liaison cl ON cc.cle = cl.groupe ".
256
			"INNER JOIN cel_catalogue_champs_etendus_liaison cl ON cc.cle = cl.groupe ".
266
			"INNER JOIN cel_catalogue_champs_etendus ccc ON ccc.cle = cl.champ ".
257
			"INNER JOIN cel_catalogue_champs_etendus ccc ON ccc.cle = cl.champ ".
267
			"WHERE cc.langue = '".$langue."' ";
258
			"WHERE cc.langue = '".$langue."' ";
268
		if ($groupe !== "") $requete .= " AND cl.groupe = '".$groupe."'";
259
		if ($groupe !== "") $requete .= " AND cl.groupe = '".$groupe."'";