45 public $errors = array();
64 public $table_element =
"c_price_global_variable";
84 public function create($user, $notrigger = 0)
91 $sql =
"INSERT INTO ".$this->db->prefix().$this->table_element.
" (";
92 $sql .=
"code, description, value";
94 $sql .=
" ".(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"''").
",";
96 $sql .=
" ".((float) $this->value);
102 $resql = $this->db->query($sql);
105 $this->errors[] =
"Error ".$this->db->lasterror();
109 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
124 foreach ($this->errors as $errmsg) {
126 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
128 $this->db->rollback();
145 $sql =
"SELECT code, description, value";
146 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
147 $sql .=
" WHERE rowid = ".((int) $id);
150 $resql = $this->db->query($sql);
152 $obj = $this->db->fetch_object($resql);
155 $this->code = $obj->code;
157 $this->value = $obj->value;
164 $this->error =
"Error ".$this->db->lasterror();
176 public function update($user = 0, $notrigger = 0)
183 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
184 $sql .=
" code = ".(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"''").
",";
185 $sql .=
" description = ".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"''").
",";
186 $sql .=
" value = ".((float) $this->value);
187 $sql .=
" WHERE rowid = ".((int) $this->
id);
192 $resql = $this->db->query($sql);
195 $this->errors[] =
"Error ".$this->db->lasterror();
214 foreach ($this->errors as $errmsg) {
216 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
218 $this->db->rollback();
235 public function delete($rowid, $user, $notrigger = 0)
254 $sql =
"DELETE FROM ".$this->db->prefix().$this->table_element;
255 $sql .=
" WHERE rowid = ".((int) $rowid);
258 $resql = $this->db->query($sql);
261 $this->errors[] =
"Error ".$this->db->lasterror();
267 foreach ($this->errors as $errmsg) {
269 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
271 $this->db->rollback();
301 if (isset($this->code)) {
302 $this->code = trim($this->code);
309 if (empty($this->value) || !is_numeric($this->value)) {
321 $sql =
"SELECT rowid, code, description, value";
322 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
323 $sql .=
" ORDER BY code";
326 $resql = $this->db->query($sql);
330 while ($record = $this->db->fetch_array($resql)) {
332 $variable_obj->id = $record[
"rowid"];
333 $variable_obj->code = $record[
"code"];
334 $variable_obj->description = $record[
"description"];
335 $variable_obj->value = $record[
"value"];
336 $variable_obj->checkParameters();
337 $retarray[] = $variable_obj;
340 $this->db->free($resql);
343 $this->error = $this->db->error();
Class for accesing price global variables table.
__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.
update($user=0, $notrigger=0)
Update object into database.
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.