26require_once DOL_DOCUMENT_ROOT.
'/core/class/commondict.class.php';
43 public $code_departement;
76 public function create($user, $notrigger = 0)
81 if (isset($this->code_departement)) {
82 $this->code_departement = trim($this->code_departement);
84 if (isset($this->nom)) {
85 $this->nom = trim($this->nom);
87 if (isset($this->active)) {
88 $this->active = (int) $this->active;
95 $sql =
"INSERT INTO ".$this->db->prefix().
"c_departements(";
97 $sql .=
"code_departement,";
100 $sql .=
") VALUES (";
101 $sql .=
" ".(!isset($this->rowid) ?
'NULL' :
"'".$this->db->escape((
string) $this->rowid).
"'").
",";
102 $sql .=
" ".(!isset($this->code_departement) ?
'NULL' :
"'".$this->db->escape($this->code_departement).
"'").
",";
103 $sql .=
" ".(!isset($this->nom) ?
'NULL' :
"'".$this->db->escape($this->nom).
"'").
",";
104 $sql .=
" ".(!isset($this->active) ?
'NULL' :
"'".$this->db->escape((
string) $this->active).
"'");
109 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
110 $resql = $this->db->query($sql);
113 $this->errors[] =
"Error ".$this->db->lasterror();
117 $this->
id = $this->db->last_insert_id($this->db->prefix().
"c_departements");
122 foreach ($this->errors as $errmsg) {
123 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
124 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
126 $this->db->rollback();
142 public function fetch($id, $code =
'')
146 $sql .=
" t.code_departement,";
149 $sql .=
" FROM ".$this->db->prefix().
"c_departements as t";
151 $sql .=
" WHERE t.rowid = ".((int) $id);
153 $sql .=
" WHERE t.code_departement = '".$this->db->escape($code).
"'";
156 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
157 $resql = $this->db->query($sql);
159 if ($this->db->num_rows($resql)) {
160 $obj = $this->db->fetch_object($resql);
162 $this->
id = $obj->rowid;
163 $this->code_departement = $obj->code_departement;
164 $this->code = $obj->code_departement;
165 $this->nom = $obj->nom;
166 $this->
name = $obj->nom;
167 $this->active = $obj->active;
169 $this->db->free($resql);
173 $this->error =
"Error ".$this->db->lasterror();
186 public function update($user =
null, $notrigger = 0)
191 if (isset($this->code_departement)) {
192 $this->code_departement = trim($this->code_departement);
194 if (isset($this->
name)) {
197 if (isset($this->active)) {
198 $this->active = (int) $this->active;
202 if (empty($this->
name) && !empty($this->nom)) {
203 $this->
name = $this->nom;
207 $sql =
"UPDATE ".$this->db->prefix().
"c_departements SET";
208 $sql .=
" code_departement=".(isset($this->code_departement) ?
"'".$this->db->escape($this->code_departement).
"'" :
"null").
",";
209 $sql .=
" nom=".(isset($this->
name) ?
"'".$this->db->escape($this->
name).
"'" :
"null").
",";
210 $sql .=
" active=".(isset($this->active) ? ((int) $this->active) :
"null");
211 $sql .=
" WHERE rowid=".((int) $this->
id);
215 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
216 $resql = $this->db->query($sql);
219 $this->errors[] =
"Error ".$this->db->lasterror();
224 foreach ($this->errors as $errmsg) {
225 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
226 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
228 $this->db->rollback();
243 public function delete($user, $notrigger = 0)
247 $sql =
"DELETE FROM ".$this->db->prefix().
"c_departements";
248 $sql .=
" WHERE rowid=".((int) $this->
id);
252 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
253 $resql = $this->db->query($sql);
256 $this->errors[] =
"Error ".$this->db->lasterror();
261 foreach ($this->errors as $errmsg) {
262 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
263 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
265 $this->db->rollback();
283 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
286 return $langs->trans($this->
name);
Parent class of all other dictionary classes.
Class to manage dictionary States (used by imports)
fetch($id, $code='')
Load object in memory from database.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
create($user, $notrigger=0)
Create object into database.
__construct($db)
Constructor.
update($user=null, $notrigger=0)
Update object into database.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db name
Only used if Module[ID]Name translation string is not found.