Subversion Repositories eFlore/Applications.coel

Rev

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

Rev 1685 Rev 1688
Line 63... Line 63...
63
	 */
63
	 */
64
	public function getElementParDefaut($p) {
64
	public function getElementParDefaut($p) {
65
		// Initialisation des variables
65
		// Initialisation des variables
66
		$info = array();
66
		$info = array();
Line -... Line 67...
-
 
67
 
-
 
68
        $whereClause = array();
-
 
69
        if(isset($p['id_projet'])) $whereClause[] = "cs_ce_projet = {$p['id_projet']}";
-
 
70
        if(isset($p['id_structure'])) $whereClause[] = "cs_id_structure = {$p['id_structure']}";
-
 
71
        if(isset($p['recherche'])) $whereClause[] = "(" . implode(" OR ", array("cs_nom LIKE {$p['recherche']}", "cs_ville LIKE {$p['recherche']}")) . ")";
-
 
72
 
67
 
73
 
68
		// Construction de la requête
74
		// Construction de la requête
69
		$requete =	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' cs.*, csc.*, csv.*, '.
75
		$requete = sprintf(
70
					'	cmhl_date_modification, cmhl_notes, cmhl_source, cmhl_ce_modifier_par, cmhl_ce_etat, cmhl_ip '.
76
            'SELECT SQL_CALC_FOUND_ROWS %s cs.*, csc.*, csv.*, cmhl_date_modification, cmhl_notes, cmhl_source, cmhl_ce_modifier_par, cmhl_ce_etat, cmhl_ip '
71
					'FROM coel_structure AS cs '.
77
            . ' FROM coel_structure AS cs '
72
					'	LEFT JOIN coel_meta_historique_ligne ON (cs_ce_meta = cmhl_id_historique_ligne) '.
78
            . ' LEFT JOIN coel_meta_historique_ligne ON (cs_ce_meta = cmhl_id_historique_ligne) '
73
					'	LEFT JOIN coel_structure_conservation AS csc ON (cs_id_structure = csc_id_structure) '.
79
            . ' LEFT JOIN coel_structure_conservation AS csc ON (cs_id_structure = csc_id_structure) '
74
					'	LEFT JOIN coel_structure_valorisation AS csv ON (cs_id_structure = csv_id_structure) '.
80
            . ' LEFT JOIN coel_structure_valorisation AS csv ON (cs_id_structure = csv_id_structure) '
-
 
81
            . ' WHERE %s ORDER BY %s LIMIT %d, %d -- %s:%d',
75
					((count($p) != 0) ? 'WHERE ' : '').			
82
 
76
					((isset($p['id_projet'])) ? "AND cs_ce_projet = {$p['id_projet']} " : '').
83
            $this->distinct ? 'DISTINCT' : '',
77
					((isset($p['id_structure'])) ? "AND cs_id_structure = {$p['id_structure']} " : '').
84
            $whereClause ? implode(" AND ", $whereClause) : TRUE,
78
					(isset($p['recherche']) ? $this->construireWhereRecherche($p['recherche']) : '').
85
            is_null($this->orderby) ? 'cs.cs_nom ASC' : $this->orderby,
-
 
86
            $this->start, $this->limit,
79
					'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'cs.cs_nom ASC').' ';
87
            __FILE__, __LINE__);
80
		
-
 
81
		$requete = str_replace('WHERE AND', 'WHERE', $requete);
-
 
82
		$requete_compte = $requete;
-
 
Line 83... Line 88...
83
		$requete .= "LIMIT $this->start, $this->limit ";
88
 
84
 
89
 
85
		// Récupération des résultats
90
		// Récupération des résultats
86
		try {
91
		try {
87
			// SPÉCIAL :
92
			// SPÉCIAL :
88
			// Lorsqu'on cherche une seule structure avec un id passé en paramêtre, nous devons renvoyer un objet
93
			// Lorsqu'on cherche une seule structure avec un id passé en paramêtre, nous devons renvoyer un objet
89
			$donnees = ($this->formatRetour == 'objet' && isset($p['id_structure'])) ? $this->bdd->query($requete)->fetch(PDO::FETCH_OBJ) : $this->bdd->query($requete)->fetchAll(PDO::FETCH_ASSOC);
94
			$donnees = ($this->formatRetour == 'objet' && isset($p['id_structure'])) ? $this->bdd->query($requete)->fetch(PDO::FETCH_OBJ) : $this->bdd->query($requete)->fetchAll(PDO::FETCH_ASSOC);
90
			if ($donnees === false) {
95
			if ($donnees === false) {
Line 91... Line 96...
91
				$this->messages[] = "La requête a retourné aucun résultat.";
96
				$this->messages[] = "La requête a retourné aucun résultat.";
92
			}
97
			}
93
			
98
			
94
			$elements_nbre = $this->bdd->query($requete_compte)->rowCount();
99
			$elements_nbre = $this->bdd->query("SELECT FOUND_ROWS() AS c")->fetch(PDO::FETCH_ASSOC);
95
			$info['nbElements'] = $elements_nbre;
100
			$info['nbElements'] = $elements_nbre['c'];
96
			$info['structures'] = $donnees;			
101
			$info['structures'] = $donnees;			
Line 97... Line 102...
97
		} catch (PDOException $e) {
102
		} catch (PDOException $e) {
98
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
103
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
Line 99... Line -...
99
		}
-
 
100
 
-
 
101
		return $info;
-
 
102
	}
-
 
103
	
-
 
104
	private function construireWhereRecherche($recherche) {
-
 
105
		$recherche = "AND ".
-
 
106
		"(".
-
 
107
			"cs_nom LIKE {$recherche}  OR ".
-
 
108
			"cs_ville LIKE {$recherche} ".
104
		}
109
		")";
105
 
110
		return $recherche;
106
		return $info;
111
	}
107
	}
112
	
108