47 public $errors = array();
72 public $table_element =
"c_price_global_variable";
92 public function create($user, $notrigger = 0)
99 $sql =
"INSERT INTO ".$this->db->prefix().$this->table_element.
" (";
100 $sql .=
"code, description, value";
101 $sql .=
") VALUES (";
102 $sql .=
" ".(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"''").
",";
104 $sql .=
" ".((float) $this->value);
110 $resql = $this->db->query($sql);
113 $this->errors[] =
"Error ".$this->db->lasterror();
117 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
125 //$result=$this->call_trigger('MYOBJECT_CREATE',$user);
126 //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
134 foreach ($this->errors as $errmsg) {
136 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
138 $this->db->rollback();
155 $sql =
"SELECT code, description, value";
156 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
157 $sql .=
" WHERE rowid = ".((int) $id);
160 $resql = $this->db->query($sql);
162 $obj = $this->db->fetch_object($resql);
165 $this->code = $obj->code;
167 $this->value = $obj->value;
174 $this->error =
"Error ".$this->db->lasterror();
186 public function update($user =
null, $notrigger = 0)
193 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
194 $sql .=
" code = ".(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"''").
",";
195 $sql .=
" description = ".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"''").
",";
196 $sql .=
" value = ".((float) $this->value);
197 $sql .=
" WHERE rowid = ".((int) $this->
id);
202 $resql = $this->db->query($sql);
205 $this->errors[] =
"Error ".$this->db->lasterror();
224 foreach ($this->errors as $errmsg) {
226 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
228 $this->db->rollback();
245 public function delete($rowid, $user, $notrigger = 0)
258 //$result=$this->call_trigger('MYOBJECT_DELETE',$user);
259 //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
266 $sql =
"DELETE FROM ".$this->db->prefix().$this->table_element;
267 $sql .=
" WHERE rowid = ".((int) $rowid);
270 $resql = $this->db->query($sql);
273 $this->errors[] =
"Error ".$this->db->lasterror();
279 foreach ($this->errors as $errmsg) {
281 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
283 $this->db->rollback();
315 if (isset($this->code)) {
316 $this->code = trim($this->code);
323 if (empty($this->value) || !is_numeric($this->value)) {
335 $sql =
"SELECT rowid, code, description, value";
336 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
337 $sql .=
" ORDER BY code";
340 $resql = $this->db->query($sql);
344 while ($record = $this->db->fetch_array($resql)) {
346 $variable_obj->id = $record[
"rowid"];
347 $variable_obj->code = $record[
"code"];
348 $variable_obj->description = $record[
"description"];
349 $variable_obj->value = $record[
"value"];
350 $variable_obj->checkParameters();
351 $retarray[] = $variable_obj;
354 $this->db->free($resql);
357 $this->error = $this->db->error();
Class for accessing price global variables table.
update($user=null, $notrigger=0)
Update object into database.
__construct($db)
Constructor.
listGlobalVariables()
List all price global variables.
checkParameters()
Checks if all parameters are in order.
create($user, $notrigger=0)
Create object into database.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
fetch($id)
Load object in memory from the database.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.