27require_once DOL_DOCUMENT_ROOT.
'/core/class/commondict.class.php';
40 public $code_departement;
73 public function create($user, $notrigger = 0)
77 if (empty($this->
id)) {
81 if (isset($this->code_departement)) {
82 $this->code_departement = trim($this->code_departement);
84 if (isset($this->
name)) {
87 if (isset($this->
active)) {
92 $sql =
"INSERT INTO ".$this->db->prefix().
"c_departements(";
94 $sql .=
"code_departement,";
98 $sql .= (int) $this->
id .
",";
99 $sql .=
" ".(!isset($this->code_departement) ?
'NULL' :
"'".$this->db->escape($this->code_departement).
"'").
",";
100 $sql .=
" ".(!isset($this->
name) ?
'NULL' :
"'".$this->db->escape($this->
name).
"'").
",";
101 $sql .=
" ".(!isset($this->
active) ?
'NULL' :
"'".$this->db->escape((
string) $this->
active).
"'");
106 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
107 $resql = $this->db->query($sql);
110 $this->errors[] =
"Error ".$this->db->lasterror();
114 $this->
id = $this->db->last_insert_id($this->db->prefix().
"c_departements");
119 foreach ($this->errors as $errmsg) {
120 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
121 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
123 $this->db->rollback();
139 public function fetch($id, $code =
'')
143 $sql .=
" t.code_departement,";
146 $sql .=
" FROM ".$this->db->prefix().
"c_departements as t";
148 $sql .=
" WHERE t.rowid = ".((int) $id);
150 $sql .=
" WHERE t.code_departement = '".$this->db->escape($code).
"'";
153 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
154 $resql = $this->db->query($sql);
156 if ($this->db->num_rows($resql)) {
157 $obj = $this->db->fetch_object($resql);
159 $this->
id = $obj->rowid;
160 $this->code_departement = $obj->code_departement;
161 $this->code = $obj->code_departement;
162 $this->nom = $obj->nom;
163 $this->
name = $obj->nom;
164 $this->
active = $obj->active;
166 $this->db->free($resql);
170 $this->error =
"Error ".$this->db->lasterror();
183 public function update($user =
null, $notrigger = 0)
188 if (isset($this->code_departement)) {
189 $this->code_departement = trim($this->code_departement);
191 if (isset($this->
name)) {
194 if (isset($this->
active)) {
199 if (empty($this->
name) && !empty($this->nom)) {
200 $this->
name = $this->nom;
204 $sql =
"UPDATE ".$this->db->prefix().
"c_departements SET";
205 $sql .=
" code_departement=".(isset($this->code_departement) ?
"'".$this->db->escape($this->code_departement).
"'" :
"null").
",";
206 $sql .=
" nom=".(isset($this->
name) ?
"'".$this->db->escape($this->
name).
"'" :
"null").
",";
207 $sql .=
" active=".(isset($this->
active) ? ((int) $this->
active) :
"null");
208 $sql .=
" WHERE rowid=".((int) $this->
id);
212 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
213 $resql = $this->db->query($sql);
216 $this->errors[] =
"Error ".$this->db->lasterror();
221 foreach ($this->errors as $errmsg) {
222 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
223 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
225 $this->db->rollback();
240 public function delete($user, $notrigger = 0)
244 $sql =
"DELETE FROM ".$this->db->prefix().
"c_departements";
245 $sql .=
" WHERE rowid=".((int) $this->
id);
249 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
250 $resql = $this->db->query($sql);
253 $this->errors[] =
"Error ".$this->db->lasterror();
258 foreach ($this->errors as $errmsg) {
259 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
260 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
262 $this->db->rollback();
280 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
283 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.