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);
104 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
108 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
123 foreach ($this->errors as $errmsg) {
125 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
127 $this->db->rollback();
144 $sql =
"SELECT code, description, value";
145 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
146 $sql .=
" WHERE rowid = ".((int) $id);
149 $resql = $this->db->query($sql);
151 $obj = $this->db->fetch_object($resql);
154 $this->code = $obj->code;
156 $this->value = $obj->value;
163 $this->error =
"Error ".$this->db->lasterror();
175 public function update($user = 0, $notrigger = 0)
182 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
183 $sql .=
" code = ".(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"''").
",";
184 $sql .=
" description = ".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"''").
",";
185 $sql .=
" value = ".((float) $this->value);
186 $sql .=
" WHERE rowid = ".((int) $this->
id);
191 $resql = $this->db->query($sql);
193 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
212 foreach ($this->errors as $errmsg) {
214 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
216 $this->db->rollback();
233 public function delete($rowid, $user, $notrigger = 0)
252 $sql =
"DELETE FROM ".$this->db->prefix().$this->table_element;
253 $sql .=
" WHERE rowid = ".((int) $rowid);
256 $resql = $this->db->query($sql);
258 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
264 foreach ($this->errors as $errmsg) {
266 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
268 $this->db->rollback();
298 if (isset($this->code)) {
299 $this->code = trim($this->code);
306 if (empty($this->value) || !is_numeric($this->value)) {
318 $sql =
"SELECT rowid, code, description, value";
319 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
320 $sql .=
" ORDER BY code";
323 $resql = $this->db->query($sql);
327 while ($record = $this->db->fetch_array($resql)) {
329 $variable_obj->id = $record[
"rowid"];
330 $variable_obj->code = $record[
"code"];
331 $variable_obj->description = $record[
"description"];
332 $variable_obj->value = $record[
"value"];
333 $variable_obj->checkParameters();
334 $retarray[] = $variable_obj;
337 $this->db->free($resql);
340 $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.