Subversion Repositories eFlore/Applications.cel

Rev

Rev 2038 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2038 Rev 2143
Line 54... Line 54...
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 ";
Line 58... Line 58...
58
 
58
 
59
		$resultat = Cel::db()->executerRequete($requete);
59
		$resultat = Cel::db()->requeter($requete);
60
		return ($resultat[0]['existe'] == '1');
60
		return ($resultat[0]['existe'] == '1');
Line 61... Line 61...
61
	}
61
	}
62
 
62
 
Line 67... Line 67...
67
	* @return array tableau associatif des champs de la table etendu
67
	* @return array tableau associatif des champs de la table etendu
68
	*/
68
	*/
69
	public function consulter($id_element_lie) {
69
	public function consulter($id_element_lie) {
70
		$id = Cel::db()->proteger($id_element_lie);
70
		$id = Cel::db()->proteger($id_element_lie);
71
		$requete = "SELECT * FROM {$this->table_champs_etendus} WHERE {$this->champ_id} = $id ";
71
		$requete = "SELECT * FROM {$this->table_champs_etendus} WHERE {$this->champ_id} = $id ";
72
		$resultat = Cel::db()->executerRequete($requete);
72
		$resultat = Cel::db()->requeter($requete);
73
		return $resultat;
73
		return $resultat;
74
	}
74
	}
Line 75... Line 75...
75
 
75
 
76
	/**
76
	/**
Line 86... Line 86...
86
		if (!empty($ids_element_lies)) {
86
		if (!empty($ids_element_lies)) {
87
			$ids_element_lies = array_map(array(Cel::db(), 'proteger'),$ids_element_lies);
87
			$ids_element_lies = array_map(array(Cel::db(), 'proteger'),$ids_element_lies);
88
			$ids = implode(',', $ids_element_lies);
88
			$ids = implode(',', $ids_element_lies);
Line 89... Line 89...
89
 
89
 
90
			$requete = "SELECT * FROM {$this->table_champs_etendus} WHERE {$this->champ_id} IN ($ids) ";
90
			$requete = "SELECT * FROM {$this->table_champs_etendus} WHERE {$this->champ_id} IN ($ids) ";
Line 91... Line 91...
91
			$resultats = Cel::db()->executerRequete($requete);
91
			$resultats = Cel::db()->requeter($requete);
92
 
92
 
93
			foreach ($resultats as &$ligne) {
93
			foreach ($resultats as &$ligne) {
94
				$id_element = $ligne[$this->champ_id];
94
				$id_element = $ligne[$this->champ_id];
Line 125... Line 125...
125
			"VALUES ($id, $cle, $label, $valeur) ".
125
			"VALUES ($id, $cle, $label, $valeur) ".
126
			"ON DUPLICATE KEY UPDATE valeur = VALUES(valeur)";
126
			"ON DUPLICATE KEY UPDATE valeur = VALUES(valeur)";
Line 127... Line 127...
127
 
127
 
128
		// la partie on duplicate key est spécifique mysql mais il sera facile de s'en passer le jour
128
		// la partie on duplicate key est spécifique mysql mais il sera facile de s'en passer le jour
129
		// où l'on change de sgbd
129
		// où l'on change de sgbd
130
		$ajout = Cel::db()->executerRequeteSimple($requete);
130
		$ajout = Cel::db()->executer($requete);
131
		return ($ajout !== false);
131
		return ($ajout !== false);
Line 132... Line 132...
132
	}
132
	}
133
 
133
 
Line 151... Line 151...
151
			$lignes[] = "($id, $cle, $label, $valeur)";
151
			$lignes[] = "($id, $cle, $label, $valeur)";
152
		}
152
		}
Line 153... Line 153...
153
 
153
 
154
		// la partie on duplicate key est spécifique mysql mais il sera facile de s'en passer le jour
154
		// la partie on duplicate key est spécifique mysql mais il sera facile de s'en passer le jour
155
		// où l'on change de sgbd
155
		// où l'on change de sgbd
156
		$ajout = Cel::db()->executerRequeteSimple(sprintf(
156
		$ajout = Cel::db()->executer(sprintf(
157
            "INSERT INTO %s (%s, cle, label, valeur) VALUES %s ON DUPLICATE KEY UPDATE valeur = VALUES(valeur) -- %s:%d",
157
            "INSERT INTO %s (%s, cle, label, valeur) VALUES %s ON DUPLICATE KEY UPDATE valeur = VALUES(valeur) -- %s:%d",
158
            $this->table_champs_etendus,
158
            $this->table_champs_etendus,
159
            $this->champ_id,
159
            $this->champ_id,
160
            implode(',', $lignes),
160
            implode(',', $lignes),
Line 177... Line 177...
177
		$requete = "UPDATE {$this->table_champs_etendus} ".
177
		$requete = "UPDATE {$this->table_champs_etendus} ".
178
			"SET label = $label, valeur = $valeur ".
178
			"SET label = $label, valeur = $valeur ".
179
			"WHERE cle = $cle".
179
			"WHERE cle = $cle".
180
			"	AND {$this->champ_id} = $id ";
180
			"	AND {$this->champ_id} = $id ";
Line 181... Line 181...
181
 
181
 
182
		$modif = Cel::db()->executerRequeteSimple($requete);
182
		$modif = Cel::db()->executer($requete);
183
		return ($modif !== false);
183
		return ($modif !== false);
Line 184... Line 184...
184
	}
184
	}
185
 
185
 
Line 192... Line 192...
192
	*/
192
	*/
193
	public function supprimer($id_element_lie, $cle) {
193
	public function supprimer($id_element_lie, $cle) {
194
		$id = Cel::db()->proteger($id_element_lie);
194
		$id = Cel::db()->proteger($id_element_lie);
195
		$cle = Cel::db()->proteger($cle);
195
		$cle = Cel::db()->proteger($cle);
196
		$requete = "DELETE FROM {$this->table_champs_etendus} WHERE cle = $cle AND {$this->champ_id} = $id ";
196
		$requete = "DELETE FROM {$this->table_champs_etendus} WHERE cle = $cle AND {$this->champ_id} = $id ";
197
		$suppr = Cel::db()->executerRequeteSimple($requete);
197
		$suppr = Cel::db()->executer($requete);
198
		return ($suppr !== false);
198
		return ($suppr !== false);
199
	}
199
	}
Line 200... Line 200...
200
 
200
 
201
	/**
201
	/**
Line 205... Line 205...
205
	* @return bool
205
	* @return bool
206
	*/
206
	*/
207
	public function vider($id_element_lie) {
207
	public function vider($id_element_lie) {
208
		$id = Cel::db()->proteger($id_element_lie);
208
		$id = Cel::db()->proteger($id_element_lie);
209
		$requete = "DELETE FROM {$this->table_champs_etendus} WHERE {$this->champ_id} = $id ";
209
		$requete = "DELETE FROM {$this->table_champs_etendus} WHERE {$this->champ_id} = $id ";
210
		$suppr = Cel::db()->executerRequeteSimple($requete);
210
		$suppr = Cel::db()->executer($requete);
211
		return ($suppr !== false);
211
		return ($suppr !== false);
212
	}
212
	}
Line 213... Line 213...
213
 
213
 
214
	/**
214
	/**
Line 218... Line 218...
218
	* @return bool
218
	* @return bool
219
	*/
219
	*/
220
	public function viderParLots($ids_elements_lies) {
220
	public function viderParLots($ids_elements_lies) {
221
		$ids = $this->protegerTableau($ids_elements_lies);
221
		$ids = $this->protegerTableau($ids_elements_lies);
222
		$requete = "DELETE FROM {$this->table_champs_etendus} WHERE {$this->champ_id} IN (".implode(',',$ids).") ";
222
		$requete = "DELETE FROM {$this->table_champs_etendus} WHERE {$this->champ_id} IN (".implode(',',$ids).") ";
223
		$suppr = Cel::db()->executerRequeteSimple($requete);
223
		$suppr = Cel::db()->executer($requete);
224
		return ($suppr !== false);
224
		return ($suppr !== false);
225
	}
225
	}
226
	
226
 
227
	/**
227
	/**
228
	* Revnoie tous les intitules aux éléments passés en paramètre
228
	* Revnoie tous les intitules aux éléments passés en paramètre
229
	*
229
	*
230
	* @param array $ids_elements_lies
230
	* @param array $ids_elements_lies
231
	* @return bool
231
	* @return bool
Line 233... Line 233...
233
	public function consulterClesParLots($ids_elements_lies) {
233
	public function consulterClesParLots($ids_elements_lies) {
234
		$cles_fmt = array();
234
		$cles_fmt = array();
235
		if(!empty($ids_elements_lies)) {
235
		if(!empty($ids_elements_lies)) {
236
			$ids = $this->protegerTableau($ids_elements_lies);
236
			$ids = $this->protegerTableau($ids_elements_lies);
237
			$requete = "SELECT cle FROM {$this->table_champs_etendus} WHERE {$this->champ_id} IN (".implode(',',$ids).") ";
237
			$requete = "SELECT cle FROM {$this->table_champs_etendus} WHERE {$this->champ_id} IN (".implode(',',$ids).") ";
238
			$cles = Cel::db()->executerRequete($requete);
238
			$cles = Cel::db()->requeter($requete);
239
			$i = 0;
239
			$i = 0;
240
			foreach($cles as &$cle) {
240
			foreach($cles as &$cle) {
241
				$cles_fmt[$cle['cle']] = $i++;
241
				$cles_fmt[$cle['cle']] = $i++;
242
			}
242
			}
243
		}
243
		}
244
		return array_values(array_flip($cles_fmt));
244
		return array_values(array_flip($cles_fmt));
245
	}
245
	}
246
	
246
 
247
	/**
247
	/**
248
	 * Renvoie la liste des groupes de champs étendus
248
	 * Renvoie la liste des groupes de champs étendus
249
	 */
249
	 */
250
	public function consulterGroupesChampsEtendusPredefinis() {
250
	public function consulterGroupesChampsEtendusPredefinis() {
251
		$groupes = array();
251
		$groupes = array();
252
		/*$requete = "SELECT * FROM {$this->table_champs_etendus}_groupes ";
252
		/*$requete = "SELECT * FROM {$this->table_champs_etendus}_groupes ";
253
		$champs = Cel::db()->executerRequete($requete);
253
		$champs = Cel::db()->executerRequete($requete);
254
		
254
 
255
		foreach ($champs as $champ) {
255
		foreach ($champs as $champ) {
256
			if(!isset($groupes[$champ['groupe']])) {
256
			if(!isset($groupes[$champ['groupe']])) {
257
				$groupes[$champ['groupe']] = array();
257
				$groupes[$champ['groupe']] = array();
258
			}
258
			}
259
			$groupes[$champ['groupe']][$champ['cle']] = $champ['label'];
259
			$groupes[$champ['groupe']][$champ['cle']] = $champ['label'];