Subversion Repositories Applications.gtt

Rev

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

Rev 14 Rev 48
Line 26... Line 26...
26
	function setTableNom($tn)
26
	function setTableNom($tn)
27
	{
27
	{
28
		$this->dao_table_nom = $tn;
28
		$this->dao_table_nom = $tn;
29
	}
29
	}
30
	// Correspondance
30
	// Correspondance
31
	function getCorrespondance()
31
	function getCorrespondance($champ = null)
32
	{
32
	{
-
 
33
		if (!is_null($champ)) {
-
 
34
			return $this->dao_correspondance[$champ];
-
 
35
		}
33
		return $this->dao_correspondance;
36
		return $this->dao_correspondance;
34
	}
37
	}
35
	function setCorrespondance($c)
38
	function setCorrespondance($c)
36
	{
39
	{
37
		$this->dao_correspondance = $c;
40
		$this->dao_correspondance = $c;
Line 47... Line 50...
47
		$classe = get_class($this);
50
		$classe = get_class($this);
48
		if (is_array($donnees)) {
51
		if (is_array($donnees)) {
49
			if ($instancier) {
52
			if ($instancier) {
50
				foreach ($this->getCorrespondance() as $champ => $attribut) {
53
				foreach ($this->getCorrespondance() as $champ => $attribut) {
51
					if (isset($donnees[$champ]) && !is_null($donnees[$champ])) {
54
					if (isset($donnees[$champ]) && !is_null($donnees[$champ])) {
52
						$methode = 'set'.str_replace(' ', '', ucwords(str_replace('_', ' ', $attribut)));
55
						$methode = $this->donnerMethodeSetAvecAttribut($attribut);
53
						$this->$methode($donnees[$champ]);
56
						$this->$methode($donnees[$champ]);
54
					}
57
					}
55
				}
58
				}
56
			} else {
59
			} else {
57
				$Objet = new $classe;
60
				$Objet = new $classe;
58
				foreach ($this->getCorrespondance() as $champ => $attribut) {
61
				foreach ($this->getCorrespondance() as $champ => $attribut) {
59
					if (isset($donnees[$champ]) && !is_null($donnees[$champ])) {
62
					if (isset($donnees[$champ]) && !is_null($donnees[$champ])) {
60
						$methode = 'set'.str_replace(' ', '', ucwords(str_replace('_', ' ', $attribut)));
63
						$methode = $this->donnerMethodeSetAvecAttribut($attribut);
61
						$Objet->$methode($donnees[$champ]);
64
						$Objet->$methode($donnees[$champ]);
62
					}
65
					}
63
				}
66
				}
64
				return $Objet;
67
				return $Objet;
65
			}
68
			}
66
		} else if ($donnees instanceof $classe) {
69
		} else if ($donnees instanceof $classe) {
67
			$enregistrement = array();
70
			$enregistrement = array();
68
			foreach ($this->getCorrespondance() as $champ => $attribut) {
71
			foreach ($this->getCorrespondance() as $champ => $attribut) {
69
				$methode = 'get'.str_replace(' ', '', ucwords(str_replace('_', ' ', $attribut)));
72
				$methode = $this->donnerMethodeGetAvecAttribut($attribut);
70
				if (method_exists($donnees, $methode)) {
73
				if (method_exists($donnees, $methode)) {
71
					if (!is_null($donnees->$methode())) {
74
					if (!is_null($donnees->$methode())) {
72
				 		$enregistrement[$champ] = $donnees->$methode();
75
				 		$enregistrement[$champ] = $donnees->$methode();
73
					}
76
					}
74
				}
77
				}
75
			}
78
			}
76
			return $enregistrement;
79
			return $enregistrement;
77
		}
80
		}
78
	}
81
	}
-
 
82
	private function donnerMethodeGetAvecAttribut($attribut)
-
 
83
	{
-
 
84
		return 'get'.str_replace(' ', '', ucwords(str_replace('_', ' ', $attribut)));
-
 
85
	}
-
 
86
	private function donnerMethodeGetAvecChamp($champ)
-
 
87
	{
-
 
88
		return 'get'.str_replace(' ', '', ucwords(str_replace('_', ' ', $this->getCorrespondance($champ))));
-
 
89
	}
-
 
90
	private function donnerMethodeSetAvecAttribut($attribut)
-
 
91
	{
-
 
92
		return 'set'.str_replace(' ', '', ucwords(str_replace('_', ' ', $attribut)));
-
 
93
	}
-
 
94
	private function donnerMethodeSetAvecChamp($champ)
-
 
95
	{
-
 
96
		return 'set'.str_replace(' ', '', ucwords(str_replace('_', ' ', $this->getCorrespondance($champ))));
-
 
97
	}
Line 79... Line 98...
79
 
98
 
80
	/**
99
	/**
81
	* Ajouter un enregistrement dans la base de données.
100
	* Ajouter un enregistrement dans la base de données.
82
	* @return true si ok, false si aucun enregistrement effectué
101
	* @return true si ok, false si aucun enregistrement effectué
Line 111... Line 130...
111
		}
130
		}
112
	}
131
	}
Line 113... Line 132...
113
 
132
 
114
	/**
133
	/**
-
 
134
	* Modifier un enregistrement dans la base de données.
115
	* Modifier un enregistrement dans la base de données.
135
	* @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.
116
	* @return true si ok, false si aucun enregistrement effectué
136
	* @return true si ok, false si aucun enregistrement effectué.
117
	*/
137
	*/
118
	public function modifier()
138
	public function modifier($Ancien = null)
119
	{
139
	{
120
		$enregistrement = $this->basculerEnregistrementObjet($this);
140
		$enregistrement = $this->basculerEnregistrementObjet($this);
121
		$sql_where = '';
141
		$sql_where = '';
122
		$sql_set = '';
142
		$sql_set = '';
123
		foreach($enregistrement as $champ => $val) {
143
		foreach($enregistrement as $champ => $val) {
124
			if (!is_numeric($val)) {
144
			if (!is_numeric($val)) {
125
				$val = '"'.$val.'"';
145
				$val = '"'.$val.'"';
-
 
146
			}
-
 
147
			$sql_set .= $champ.' = '.$val.', ';
-
 
148
			$classe = get_class($this);
-
 
149
			if ($Ancien instanceof $classe) {
-
 
150
				$methode = $this->donnerMethodeGetAvecChamp($champ);
-
 
151
				$val = $Ancien->$methode();
-
 
152
				if (!is_numeric($val)) {
-
 
153
					$val = '"'.$val.'"';
-
 
154
				}
126
			}
155
			}
127
			if (preg_match('/_id_/', $champ)) {
156
			if (preg_match('/_id_/', $champ)) {
128
				$sql_where .= $champ.' = '.$val.' AND ';
-
 
129
			} else {
-
 
130
				$sql_set .= $champ.' = '.$val.', ';
157
				$sql_where .= $champ.' = '.$val.' AND ';
131
			}
158
			}
132
		}
159
		}
133
		$sql_set = trim($sql_set, ', ').' ';
160
		$sql_set = trim($sql_set, ', ').' ';
134
		$sql_where = trim($sql_where, ' AND ').' ';
161
		$sql_where = trim($sql_where, ' AND ').' ';