26,8 → 26,8 |
protected $limite_requete = array( 'depart' => 0, 'limite' => 10); |
private $tables; |
private $champs_recherches = '*'; |
private $requete_jointure = array(); |
private $requete_condition = array(); |
private $requete_jointure = ""; |
private $requete_condition = ""; |
private $total_resultat; |
protected $serviceNom = 'informations'; |
private $masque; |
235,38 → 235,36 |
|
|
public function assemblerLaRequete() { |
$requete = ' SELECT '.$this->champs_recherches. |
' FROM '.$this->tables['index'].' ' |
.self::retournerRequeteJointure($this->requete_jointure).' ' |
.self::retournerRequeteCondition($this->requete_condition).' ' |
.$this->delimiterResultatsRequete(); |
$requete = ' SELECT '.$this->champs_recherches.' FROM '.$this->tables['index'].' ' |
.$this->retournerRequeteJointure().' '.$this->retournerRequeteCondition(). |
' '.$this->delimiterResultatsRequete(); |
return $requete; |
} |
|
static function retournerRequeteCondition($cond) { |
return $cond ? (' WHERE '.implode(' AND ', $cond)) : ''; |
public function retournerRequeteCondition() { |
$condition = ''; |
if ($this->requete_condition !== "") { |
$condition = ' WHERE '.implode(' AND ', $this->requete_condition); |
} |
return $condition; |
} |
|
|
static function calculerTotalResultat($db, $table, Array $join, Array $cond) { |
$requete = sprintf( |
'SELECT count(*) as nombre FROM %s %s %s -- %s:%d', |
$table, |
$join ? implode(' ', $join) : '', |
$cond ? (' WHERE '.implode(' AND ', $cond)) : '', |
__FILE__, |
__LINE__); |
$res = $db->recuperer($requete); |
if ($res && $res['nombre']) return $res['nombre']; |
throw new Exception('Données introuvables dans la base', RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE); |
public function calculerTotalResultat() { |
$requete = 'SELECT count(*) as nombre FROM '.$this->tables['index'].' ' |
.$this->retournerRequeteJointure().' '.$this->retournerRequeteCondition(); |
$res = $this->getBdd()->recuperer($requete); |
if ($res) { |
$this->total_resultat = $res['nombre']; |
} else { |
$this->total_resultat = 0; |
$e = 'Données introuvables dans la base'; |
$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $e); |
} |
} |
|
public function delimiterResultatsRequete() { |
$this->total_resultat = self::calculerTotalResultat( |
$this->getBdd(), |
$this->tables['index'], |
$this->requete_jointure, |
$this->requete_condition); |
$this->calculerTotalResultat(); |
$requete_limite = ''; |
if (($this->limite_requete['depart'] <= $this->total_resultat) ){ |
if ( $this->limite_requete['depart'] < $this->total_resultat ){ |
281,8 → 279,12 |
return $requete_limite; |
} |
|
static function retournerRequeteJointure($join) { |
return $join ? implode(' ', $join) : ''; |
public function retournerRequeteJointure() { |
$jointure = ''; |
if ($this->requete_jointure !== "") { |
$jointure = implode(' ', $this->requete_jointure); |
} |
return $jointure; |
} |
|
} |