Subversion Repositories eFlore/Applications.del

Rev

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

Rev 1755 Rev 1793
Line 27... Line 27...
27
*/
27
*/
Line 28... Line 28...
28
 
28
 
Line 29... Line 29...
29
class ListeObservations {
29
class ListeObservations {
30
 
-
 
31
    private $conteneur;
30
 
32
    private $gestionBdd;
31
	private $conteneur;
33
    private $bdd;
32
	private $bdd;
Line 34... Line 33...
34
    private $parametres = array();
33
	private $parametres = array();
Line 49... Line 48...
49
	'di' => array('id_image', 'date_prise_de_vue AS `date`', 'hauteur',/* 'largeur','nom_original' // apparemment inutilisés */),
48
		'di' => array('id_image', 'date_prise_de_vue AS `date`', 'hauteur',/* 'largeur','nom_original' // apparemment inutilisés */),
50
	'du' => array('prenom', 'nom', 'courriel'),
49
		'du' => array('prenom', 'nom', 'courriel'),
51
	'dc' => array('commentaire')
50
		'dc' => array('commentaire')
52
    );
51
	);
Line 53... Line -...
53
 
-
 
54
 
52
 
55
    public function __construct(Conteneur $conteneur = null) {
53
	public function __construct(Conteneur $conteneur = null) {
56
		$this->conteneur = $conteneur == null ? new Conteneur() : $conteneur;
54
		$this->conteneur = $conteneur == null ? new Conteneur() : $conteneur;
57
		$this->conteneur->chargerConfiguration('config_departements_bruts.ini');
55
		$this->conteneur->chargerConfiguration('config_departements_bruts.ini');
58
		$this->conteneur->chargerConfiguration('config_observations.ini');
56
		$this->conteneur->chargerConfiguration('config_observations.ini');
59
		$this->conteneur->chargerConfiguration('config_mapping_votes.ini');
57
		$this->conteneur->chargerConfiguration('config_mapping_votes.ini');
60
		$this->conteneur->chargerConfiguration('config_mapping_commentaires.ini');
58
		$this->conteneur->chargerConfiguration('config_mapping_commentaires.ini');
61
		$this->navigation = $conteneur->getNavigation();
59
		$this->navigation = $conteneur->getNavigation();
62
		$this->masque = $conteneur->getMasque();
-
 
63
		$this->gestionBdd = $conteneur->getGestionBdd();
60
		$this->masque = $conteneur->getMasque();
64
		$this->bdd = $this->gestionBdd->getBdd();
61
		$this->bdd = $this->conteneur->getBdd();
Line 65... Line 62...
65
    }
62
    }
66
 
63
 
67
    static function reformateObservation($obs, $url_pattern = '') {
64
	static function reformateObservation($obs, $url_pattern = '') {
Line 202... Line 199...
202
	}
199
		}
203
	// ordre préservé, à partir d'ici c'est important.
200
		// ordre préservé, à partir d'ici c'est important.
204
	return $res;
201
		return $res;
205
    }
202
	}
Line 206... Line 203...
206
 
203
 
207
    /*
204
	/**
208
      Champs récupérés:
205
	 * Champs récupérés:
209
      Pour del_images, la vue retourne déjà ce que nous recherchons de cel_obs et cel_images
206
	 * Pour del_images, la vue retourne déjà ce que nous recherchons de cel_obs et cel_images
210
      (cel_obs.* et cel_[obs_]images.{id_observation, id_image, date_prise_de_vue AS date, hauteur, largeur})
207
	 * (cel_obs.* et cel_[obs_]images.{id_observation, id_image, date_prise_de_vue AS date, hauteur, largeur})
211
      Pour del_commentaires: nous voulons *
208
	 * Pour del_commentaires: nous voulons *
212
      Reste ensuite à formatter.
209
	 * Reste ensuite à formatter.
213
      Note: le préfixe de table utilisé ici (vdi) n'impacte *aucune* autre partie du code car rien
210
	 * Note: le préfixe de table utilisé ici (vdi) n'impacte *aucune* autre partie du code car rien
214
      n'en dépend pour l'heure. (inutilisation de $req['select'])
211
	 * n'en dépend pour l'heure. (inutilisation de $req['select'])
215
    */
212
	 */
216
    static function getInfos($idobs, $db) {
213
	static function getInfos($idobs, $db) {
217
	/*$select_fields = implode(',', array_merge(
214
		/*$select_fields = implode(',', array_merge(
218
	  array_map(create_function('$a', 'return "vdi.".$a;'), self::$sql_fields_liaisons['dob']),
215
		 array_map(create_function('$a', 'return "vdi.".$a;'), self::$sql_fields_liaisons['dob']),
219
	  array_map(create_function('$a', 'return "vdi.".$a;'), self::$sql_fields_liaisons['di']),
216
		 array_map(create_function('$a', 'return "vdi.".$a;'), self::$sql_fields_liaisons['di']),
220
	  array_map(create_function('$a', 'return "du.".$a;'), self::$sql_fields_liaisons['du'])));*/
217
		 array_map(create_function('$a', 'return "du.".$a;'), self::$sql_fields_liaisons['du'])));*/
221
	$select_fields = array_merge(self::$sql_fields_liaisons['dob'],
-
 
222
				     self::$sql_fields_liaisons['di']);
218
		$select_fields = array_merge(self::$sql_fields_liaisons['dob'], self::$sql_fields_liaisons['di']);
223
	$req_s = sprintf('SELECT %s FROM v_del_image vdi'.
219
		$req_s = sprintf('SELECT %s FROM v_del_image vdi'.
224
			 // ' LEFT JOIN del_commentaire AS dc ON di.id_observation = dc.ce_observation AND dc.nom_sel IS NOT NULL'.
220
			// ' LEFT JOIN del_commentaire AS dc ON di.id_observation = dc.ce_observation AND dc.nom_sel IS NOT NULL'.
225
			 ' WHERE id_observation IN (%s)',
221
			' WHERE id_observation IN (%s)',
226
			 implode(',', $select_fields),
222
			implode(',', $select_fields),
227
			 implode(',', $idobs));
223
			implode(',', $idobs));
228
	return $db->recupererTous($req_s);
224
		return $db->recupererTous($req_s);
Line 229... Line -...
229
    }
-
 
230
 
225
	}
231
 
226
 
232
    /**
227
	/**
233
     * Complément à DelTk::sqlAddConstraint()
228
	 * Complément à DelTk::sqlAddConstraint()
234
     *
229
	 *
Line 253... Line 248...
253
		    $subwhere[] = sprintf('LOWER(CONCAT(%s)) REGEXP %s',
248
					$subwhere[] = sprintf('LOWER(CONCAT(%s)) REGEXP %s',
254
					  DelTk::sqlAddIfNullPourConcat(array('vdi.mots_cles_texte', 'vdi.i_mots_cles_texte')),
249
						DelTk::sqlAddIfNullPourConcat(array('vdi.mots_cles_texte', 'vdi.i_mots_cles_texte')),
255
					  $db->proteger(strtolower($tag)));
250
						$db->proteger(strtolower($tag)));
256
		}
251
				}
257
		$req['where'][] = '(' . implode(' AND ', $subwhere) . ')';
252
				$req['where'][] = '(' . implode(' AND ', $subwhere) . ')';
258
	    }
-
 
259
	    else {
253
			} else {
260
		$req['where'][] = sprintf('LOWER(CONCAT(%s)) REGEXP %s',
254
				$req['where'][] = sprintf('LOWER(CONCAT(%s)) REGEXP %s',
261
					  DelTk::sqlAddIfNullPourConcat(array('vdi.mots_cles_texte', 'vdi.i_mots_cles_texte')),
255
					DelTk::sqlAddIfNullPourConcat(array('vdi.mots_cles_texte', 'vdi.i_mots_cles_texte')),
262
					  $db->proteger(strtolower(implode('|', $p['masque.tag']['OR']))));
256
					$db->proteger(strtolower(implode('|', $p['masque.tag']['OR']))));
263
	    }
257
			}
264
	}
258
		}
Line 266... Line 260...
266
	if(!empty($p['masque.type'])) {
260
		if (!empty($p['masque.type'])) {
267
	    self::addTypeConstraints($p['masque.type'], $db, $req, $c);
261
			self::addTypeConstraints($p['masque.type'], $db, $req, $c);
268
	}
262
		}
269
    }
263
	}
Line 270... Line 264...
270
 
264
 
271
    /* Le masque fait une recherche générique parmi de nombreux champs ci-dessus.
265
	/** Le masque fait une recherche générique parmi de nombreux champs ci-dessus.
272
       Nous initialisons donc ces paramètres (excepté masque biensur), et nous rappelons
266
	 * Nous initialisons donc ces paramètres (excepté masque biensur), et nous rappelons
273
       récursivement. À la seule différence que nous n'utiliserons que $or_req['where']
267
	 * récursivement. À la seule différence que nous n'utiliserons que $or_req['where']
-
 
268
	 * imploded par des " OR ".
274
       imploded par des " OR ". */
269
	 */
275
    static function sqlAddMasqueConstraint($p, $db, &$req, Conteneur $c = NULL) {
270
	static function sqlAddMasqueConstraint($p, $db, &$req, Conteneur $c = NULL) {
276
	if(!empty($p['masque'])) {
271
		if (!empty($p['masque'])) {
277
	    $or_params = array('masque.auteur' => $p['masque'],
272
			$or_params = array('masque.auteur' => $p['masque'],
278
			       'masque.departement' => $p['masque'],
273
				'masque.departement' => $p['masque'],
Line 311... Line 306...
311
		$req['join'] = array_unique(array_merge($req['join'], $or_req['join']));
306
				$req['join'] = array_unique(array_merge($req['join'], $or_req['join']));
312
	    }
307
			}
313
	}
308
		}
314
    }
309
	}
Line 315... Line -...
315
 
-
 
316
 
310
 
317
    private function configurer() {
311
	private function configurer() {
318
	$this->mappingVotes = $this->conteneur->getParametre('mapping_votes');
312
		$this->mappingVotes = $this->conteneur->getParametre('mapping_votes');
319
	$this->mappingCommentaire = $this->conteneur->getParametre('mapping_commentaire');
313
		$this->mappingCommentaire = $this->conteneur->getParametre('mapping_commentaire');
Line 320... Line -...
320
    }
-
 
321
 
314
	}
322
 
315
 
323
    /*
316
	/**
324
     * @param $req: la représentation de la requête MySQL complète, à amender.
317
	 * @param $req: la représentation de la requête MySQL complète, à amender.
325
     */
318
	 */
326
    static function addTypeConstraints($val, $db, &$req, Conteneur $c) {
319
	static function addTypeConstraints($val, $db, &$req, Conteneur $c) {
Line 354... Line 347...
354
	    $req['where'][] = '(SELECT COUNT(id_commentaire) FROM del_commentaire AS dc'.
347
			$req['where'][] = '(SELECT COUNT(id_commentaire) FROM del_commentaire AS dc'.
355
		' WHERE ce_observation = id_observation) > ' . intval($c->getParametre('nb_commentaires_discussion'));
348
				' WHERE ce_observation = id_observation) > ' . intval($c->getParametre('nb_commentaires_discussion'));
356
	}
349
		}
357
    }
350
	}
Line 358... Line -...
358
 
-
 
359
 
351
 
360
    /**
352
	/**
361
     * Récupérer toutes les déterminations et le nombre de commentaire au total
353
	 * Récupérer toutes les déterminations et le nombre de commentaire au total
362
     * @param array $observations la liste des observations à mettre à jour
354
	 * @param array $observations la liste des observations à mettre à jour
363
     * */
355
	 */
364
    private function chargerDeterminations(&$observations) {
356
	private function chargerDeterminations(&$observations) {
365
	$idObs = array_values(array_map(create_function('$a', 'return $a["id_observation"];'),
-
 
366
					$observations));
357
		$idObs = array_values(array_map(create_function('$a', 'return $a["id_observation"];'), $observations));
367
	$r = sprintf('SELECT * FROM del_commentaire AS dc WHERE dc.nom_sel IS NOT NULL AND ce_observation IN (%s) -- %s',
358
		$r = sprintf('SELECT * FROM del_commentaire AS dc WHERE dc.nom_sel IS NOT NULL AND ce_observation IN (%s) -- %s',
368
		     implode(',',$idObs),
359
			implode(',',$idObs),
369
		     __FILE__ . ':' . __LINE__);
360
			__FILE__ . ':' . __LINE__);
370
	$propositions = $this->bdd->recupererTous($r);
361
		$propositions = $this->bdd->recupererTous($r);
Line 394... Line 385...
394
 
385
 
395
	foreach ($resultatsVotes as $vote) {
386
		foreach ($resultatsVotes as $vote) {
396
	    $proposition_formatee['votes'][$vote['id_vote']] = $this->formaterVote($vote);
387
			$proposition_formatee['votes'][$vote['id_vote']] = $this->formaterVote($vote);
Line 397... Line -...
397
	}
-
 
398
 
388
		}
399
 
389
 
400
	// chargerNombreCommentaire()
390
		// chargerNombreCommentaire()
401
	// Charger le nombre de commentaires (sans détermination) associé à l'observation
391
		// Charger le nombre de commentaires (sans détermination) associé à l'observation
402
	$listeCommentaires = $this->bdd->recupererTous(sprintf(
392
		$listeCommentaires = $this->bdd->recupererTous(sprintf(
Line 423... Line 413...
423
    }
413
	}
Line 424... Line 414...
424
 
414
 
425
    /**
415
	/**
426
     *	Formater un vote en fonction du fichier de configuration config_votes.ini
416
	 * Formater un vote en fonction du fichier de configuration config_votes.ini
427
     *	@param $votes array()
417
	 * @param $votes array()
428
     * */
418
	 */
429
    private function formaterVote($vote) {
419
	private function formaterVote($vote) {
430
	$retour = array();
420
		$retour = array();
431
	foreach ($vote as $param=>$valeur) {
421
		foreach ($vote as $param=>$valeur) {
432
	    $retour[$this->mappingVotes[$param]] = $valeur;
422
			$retour[$this->mappingVotes[$param]] = $valeur;