Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 3478 Rev 3488
Line 17... Line 17...
17
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
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;
22
	private $table_champs_etendus = null;
22
	private $table_obs_etendus = null;
Line 23... Line 23...
23
	private $champ_id = null;
23
	private $champ_id = null;
24
 
24
 
25
	public function __construct($config, $mode = 'obs') {
25
	public function __construct($config, $mode = 'obs') {
26
		parent::__construct($config);
26
		parent::__construct($config);
27
		$this->mode = $mode;
27
		$this->mode = $mode;
Line 28... Line 28...
28
		$this->table_champs_etendus = 'extended_field_occurrence';
28
		$this->table_obs_etendus = 'extended_field_occurrence';
Line 29... Line 29...
29
		$this->champ_id = 'occurrence_id';
29
		$this->champ_id = 'occurrence_id';
Line 41... Line 41...
41
	*/
41
	*/
42
	public function existe($id_element_lie, $cle) {
42
	public function existe($id_element_lie, $cle) {
43
		$id = Cel::db()->proteger($id_element_lie);
43
		$id = Cel::db()->proteger($id_element_lie);
44
		$cle = Cel::db()->proteger($cle);
44
		$cle = Cel::db()->proteger($cle);
45
		$requete = 'SELECT COUNT(*) >= 1 AS existe '.
45
		$requete = 'SELECT COUNT(*) >= 1 AS existe '.
46
			"FROM {$this->table_champs_etendus} ".
46
			"FROM {$this->table_obs_etendus} ".
47
			"WHERE {$this->champ_id} = $id ".
47
			"WHERE {$this->champ_id} = $id ".
48
			"	AND extended_field_id = $cle ".
48
			"	AND extended_field_id = $cle ".
49
			' -- '.__FILE__.':'.__LINE__;;
49
			' -- '.__FILE__.':'.__LINE__;;
Line 50... Line 50...
50
 
50
 
Line 59... Line 59...
59
	* @return array tableau associatif des champs de la table etendu
59
	* @return array tableau associatif des champs de la table etendu
60
	*/
60
	*/
61
	public function consulter($id_element_lie) {
61
	public function consulter($id_element_lie) {
62
		$id = Cel::db()->proteger($id_element_lie);
62
		$id = Cel::db()->proteger($id_element_lie);
63
		$requete = 'SELECT * '.
63
		$requete = 'SELECT * '.
64
			"FROM {$this->table_champs_etendus} ".
64
			"FROM {$this->table_obs_etendus} ".
65
			"WHERE {$this->champ_id} = $id ".
65
			"WHERE {$this->champ_id} = $id ".
66
			' -- '.__FILE__.':'.__LINE__;
66
			' -- '.__FILE__.':'.__LINE__;
67
		$resultat = Cel::db()->requeter($requete);
67
		$resultat = Cel::db()->requeter($requete);
68
		return $resultat;
68
		return $resultat;
69
	}
69
	}
Line 80... Line 80...
80
		$champs_etendus_par_element = array();
80
		$champs_etendus_par_element = array();
81
		if (!empty($ids_element_lies)) {
81
		if (!empty($ids_element_lies)) {
82
			$ids_element_lies = array_map(array(Cel::db(), 'proteger'),$ids_element_lies);
82
			$ids_element_lies = array_map(array(Cel::db(), 'proteger'),$ids_element_lies);
83
			$ids = implode(',', $ids_element_lies);
83
			$ids = implode(',', $ids_element_lies);
Line -... Line 84...
-
 
84
 
84
 
85
			$requete = "SELECT f.*, `field_id`as cle FROM {$this->table_obs_etendus} f join extended_field_occurrence o
85
			$requete = "SELECT * FROM {$this->table_champs_etendus} WHERE {$this->champ_id} IN ($ids) ";
86
			     on f.`id` =  extended_field_id WHERE {$this->champ_id} IN ($ids) ";
86
			$resultats = Cel::db()->requeter($requete);
87
			$resultats = Cel::db()->requeter($requete);
87
 
88
			
88
			foreach ($resultats as &$ligne) {
89
			foreach ($resultats as &$ligne) {
89
				$id_element = $ligne[$this->champ_id];
90
				$id_element = $ligne[$this->champ_id];
90
				if (!isset($champs_etendus_par_element[$id_element])) {
91
				if (!isset($champs_etendus_par_element[$id_element])) {
91
					$champs_etendus_par_element[$id_element] = array();
92
					$champs_etendus_par_element[$id_element] = array();
92
				}
93
				}
93
				$champ_etendu = new ObsEtendue();
94
				$champ_etendu = new ObsEtendue();
94
				$champ_etendu->id = $id_element;
95
				$champ_etendu->id = $id_element;
95
				$champ_etendu->cle = $ligne['extended_field_id'];
96
				$champ_etendu->cle = $ligne['cle'];
Line 96... Line 97...
96
				$champ_etendu->valeur = $ligne['value'];
97
				$champ_etendu->valeur = $ligne['value'];
97
 
98
 
98
				$champs_etendus_par_element[$id_element][] = $champ_etendu;
99
				$champs_etendus_par_element[$id_element][] = $champ_etendu;
Line 111... Line 112...
111
	public function ajouter(ChampEtendu $champ_etendu) {
112
	public function ajouter(ChampEtendu $champ_etendu) {
112
		$id = Cel::db()->proteger($champ_etendu->id);
113
		$id = Cel::db()->proteger($champ_etendu->id);
113
		$cle = Cel::db()->proteger($champ_etendu->cle);
114
		$cle = Cel::db()->proteger($champ_etendu->cle);
114
		$valeur = Cel::db()->proteger($champ_etendu->valeur);
115
		$valeur = Cel::db()->proteger($champ_etendu->valeur);
Line 115... Line 116...
115
 
116
 
116
		$requete = "INSERT INTO {$this->table_champs_etendus} ".
117
		$requete = "INSERT INTO {$this->table_obs_etendus} ".
117
			"( {$this->champ_id}, extended_field_id, value) ".
118
			"( {$this->champ_id}, extended_field_id, value) ".
118
			"VALUES ($id, $cle, $valeur) ".
119
			"VALUES ($id, $cle, $valeur) ".
119
			"ON DUPLICATE KEY UPDATE value = VALUES(value) ".
120
			"ON DUPLICATE KEY UPDATE value = VALUES(value) ".
Line 146... Line 147...
146
 
147
 
147
		// la partie on duplicate key est spécifique mysql mais il sera facile de s'en passer le jour
148
		// la partie on duplicate key est spécifique mysql mais il sera facile de s'en passer le jour
148
		// où l'on change de sgbd
149
		// où l'on change de sgbd
149
		$ajout = Cel::db()->executer(sprintf(
150
		$ajout = Cel::db()->executer(sprintf(
150
			"INSERT INTO %s (%s, extended_field_id, valeur) VALUES %s ON DUPLICATE KEY UPDATE value = VALUES(valeur) -- %s:%d",
151
			"INSERT INTO %s (%s, extended_field_id, valeur) VALUES %s ON DUPLICATE KEY UPDATE value = VALUES(valeur) -- %s:%d",
151
			$this->table_champs_etendus,
152
			$this->table_obs_etendus,
152
			$this->champ_id,
153
			$this->champ_id,
153
			implode(',', $lignes),
154
			implode(',', $lignes),
154
			__FILE__, __LINE__));
155
			__FILE__, __LINE__));
155
		return ($ajout !== false);
156
		return ($ajout !== false);
Line 164... Line 165...
164
	public function modifier(ChampEtendu $champ_etendu) {
165
	public function modifier(ChampEtendu $champ_etendu) {
165
		$id = Cel::db()->proteger($champ_etendu->id);
166
		$id = Cel::db()->proteger($champ_etendu->id);
166
		$cle = Cel::db()->proteger($champ_etendu->cle);
167
		$cle = Cel::db()->proteger($champ_etendu->cle);
167
		$valeur = Cel::db()->proteger($champ_etendu->valeur);
168
		$valeur = Cel::db()->proteger($champ_etendu->valeur);
Line 168... Line 169...
168
 
169
 
169
		$requete = "UPDATE {$this->table_champs_etendus} ".
170
		$requete = "UPDATE {$this->table_obs_etendus} ".
170
			"SET value = $valeur ".
171
			"SET value = $valeur ".
171
			"WHERE extended_field_id = $cle".
172
			"WHERE extended_field_id = $cle".
172
			"	AND {$this->champ_id} = $id ".
173
			"	AND {$this->champ_id} = $id ".
173
			' -- '.__FILE__.':'.__LINE__;
174
			' -- '.__FILE__.':'.__LINE__;
Line 183... Line 184...
183
	* @return bool
184
	* @return bool
184
	*/
185
	*/
185
	public function supprimer($id_element_lie, $cle) {
186
	public function supprimer($id_element_lie, $cle) {
186
		$id = Cel::db()->proteger($id_element_lie);
187
		$id = Cel::db()->proteger($id_element_lie);
187
		$cle = Cel::db()->proteger($cle);
188
		$cle = Cel::db()->proteger($cle);
188
		$requete = "DELETE FROM {$this->table_champs_etendus} ".
189
		$requete = "DELETE FROM {$this->table_obs_etendus} ".
189
			"WHERE extended_field_id = $cle ".
190
			"WHERE extended_field_id = $cle ".
190
			"AND {$this->champ_id} = $id ".
191
			"AND {$this->champ_id} = $id ".
191
			' -- '.__FILE__.':'.__LINE__;
192
			' -- '.__FILE__.':'.__LINE__;
192
		$suppr = Cel::db()->executer($requete);
193
		$suppr = Cel::db()->executer($requete);
193
		return ($suppr !== false);
194
		return ($suppr !== false);
Line 199... Line 200...
199
	* @param int $id_element_lie
200
	* @param int $id_element_lie
200
	* @return bool
201
	* @return bool
201
	*/
202
	*/
202
	public function vider($id_element_lie) {
203
	public function vider($id_element_lie) {
203
		$id = Cel::db()->proteger($id_element_lie);
204
		$id = Cel::db()->proteger($id_element_lie);
204
		$requete = "DELETE FROM {$this->table_champs_etendus} ".
205
		$requete = "DELETE FROM {$this->table_obs_etendus} ".
205
			"WHERE {$this->champ_id} = $id ".
206
			"WHERE {$this->champ_id} = $id ".
206
			' -- '.__FILE__.':'.__LINE__;
207
			' -- '.__FILE__.':'.__LINE__;
207
		$suppr = Cel::db()->executer($requete);
208
		$suppr = Cel::db()->executer($requete);
208
		return ($suppr !== false);
209
		return ($suppr !== false);
209
	}
210
	}
Line 214... Line 215...
214
	* @param array $ids_elements_lies
215
	* @param array $ids_elements_lies
215
	* @return bool
216
	* @return bool
216
	*/
217
	*/
217
	public function viderParLots($ids_elements_lies) {
218
	public function viderParLots($ids_elements_lies) {
218
		$ids = $this->protegerTableau($ids_elements_lies);
219
		$ids = $this->protegerTableau($ids_elements_lies);
219
		$requete = "DELETE FROM {$this->table_champs_etendus} ".
220
		$requete = "DELETE FROM {$this->table_obs_etendus} ".
220
			"WHERE {$this->champ_id} IN (".implode(',',$ids).") ".
221
			"WHERE {$this->champ_id} IN (".implode(',',$ids).") ".
221
			' -- '.__FILE__.':'.__LINE__;
222
			' -- '.__FILE__.':'.__LINE__;
222
		$suppr = Cel::db()->executer($requete);
223
		$suppr = Cel::db()->executer($requete);
223
		return ($suppr !== false);
224
		return ($suppr !== false);
224
	}
225
	}