28,8 → 28,11 |
$this->dao_table_nom = $tn; |
} |
// Correspondance |
function getCorrespondance() |
function getCorrespondance($champ = null) |
{ |
if (!is_null($champ)) { |
return $this->dao_correspondance[$champ]; |
} |
return $this->dao_correspondance; |
} |
function setCorrespondance($c) |
49,7 → 52,7 |
if ($instancier) { |
foreach ($this->getCorrespondance() as $champ => $attribut) { |
if (isset($donnees[$champ]) && !is_null($donnees[$champ])) { |
$methode = 'set'.str_replace(' ', '', ucwords(str_replace('_', ' ', $attribut))); |
$methode = $this->donnerMethodeSetAvecAttribut($attribut); |
$this->$methode($donnees[$champ]); |
} |
} |
57,7 → 60,7 |
$Objet = new $classe; |
foreach ($this->getCorrespondance() as $champ => $attribut) { |
if (isset($donnees[$champ]) && !is_null($donnees[$champ])) { |
$methode = 'set'.str_replace(' ', '', ucwords(str_replace('_', ' ', $attribut))); |
$methode = $this->donnerMethodeSetAvecAttribut($attribut); |
$Objet->$methode($donnees[$champ]); |
} |
} |
66,7 → 69,7 |
} else if ($donnees instanceof $classe) { |
$enregistrement = array(); |
foreach ($this->getCorrespondance() as $champ => $attribut) { |
$methode = 'get'.str_replace(' ', '', ucwords(str_replace('_', ' ', $attribut))); |
$methode = $this->donnerMethodeGetAvecAttribut($attribut); |
if (method_exists($donnees, $methode)) { |
if (!is_null($donnees->$methode())) { |
$enregistrement[$champ] = $donnees->$methode(); |
76,6 → 79,22 |
return $enregistrement; |
} |
} |
private function donnerMethodeGetAvecAttribut($attribut) |
{ |
return 'get'.str_replace(' ', '', ucwords(str_replace('_', ' ', $attribut))); |
} |
private function donnerMethodeGetAvecChamp($champ) |
{ |
return 'get'.str_replace(' ', '', ucwords(str_replace('_', ' ', $this->getCorrespondance($champ)))); |
} |
private function donnerMethodeSetAvecAttribut($attribut) |
{ |
return 'set'.str_replace(' ', '', ucwords(str_replace('_', ' ', $attribut))); |
} |
private function donnerMethodeSetAvecChamp($champ) |
{ |
return 'set'.str_replace(' ', '', ucwords(str_replace('_', ' ', $this->getCorrespondance($champ)))); |
} |
|
/** |
* Ajouter un enregistrement dans la base de données. |
113,9 → 132,10 |
|
/** |
* Modifier un enregistrement dans la base de données. |
* @return true si ok, false si aucun enregistrement effectué |
* @param object l'ancien objet contenant les valeurs de clés primaires non modifiées. Laissé vide si on ne modifie pas les clés. |
* @return true si ok, false si aucun enregistrement effectué. |
*/ |
public function modifier() |
public function modifier($Ancien = null) |
{ |
$enregistrement = $this->basculerEnregistrementObjet($this); |
$sql_where = ''; |
124,10 → 144,17 |
if (!is_numeric($val)) { |
$val = '"'.$val.'"'; |
} |
$sql_set .= $champ.' = '.$val.', '; |
$classe = get_class($this); |
if ($Ancien instanceof $classe) { |
$methode = $this->donnerMethodeGetAvecChamp($champ); |
$val = $Ancien->$methode(); |
if (!is_numeric($val)) { |
$val = '"'.$val.'"'; |
} |
} |
if (preg_match('/_id_/', $champ)) { |
$sql_where .= $champ.' = '.$val.' AND '; |
} else { |
$sql_set .= $champ.' = '.$val.', '; |
} |
} |
$sql_set = trim($sql_set, ', ').' '; |