45 public $errors = array();
58 public $table_element =
"c_price_expression";
78 public function create($user, $notrigger = 0)
83 if (isset($this->title)) {
84 $this->title = trim($this->title);
86 if (isset($this->expression)) {
87 $this->expression = trim($this->expression);
91 $sql =
"INSERT INTO ".$this->db->prefix().$this->table_element.
" (";
92 $sql .=
"title, expression";
94 $sql .=
" ".(isset($this->title) ?
"'".$this->db->escape($this->title).
"'" :
"''").
",";
95 $sql .=
" ".(isset($this->expression) ?
"'".$this->db->escape($this->expression).
"'" :
"''");
101 $resql = $this->db->query($sql);
104 $this->errors[] =
"Error ".$this->db->lasterror();
108 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
113 foreach ($this->errors as $errmsg) {
115 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
117 $this->db->rollback();
136 $this->error =
'ErrorWrongParameters';
140 $sql =
"SELECT title, expression";
141 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
142 $sql .=
" WHERE rowid = ".((int) $id);
145 $resql = $this->db->query($sql);
147 $obj = $this->db->fetch_object($resql);
150 $this->title = $obj->title;
151 $this->expression = $obj->expression;
157 $this->error =
"Error ".$this->db->lasterror();
171 $sql =
"SELECT rowid, title, expression";
172 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
173 $sql .=
" ORDER BY title";
176 $resql = $this->db->query($sql);
180 while ($record = $this->db->fetch_array($resql)) {
182 $price_expression_obj->id = $record[
"rowid"];
183 $price_expression_obj->title = $record[
"title"];
184 $price_expression_obj->expression = $record[
"expression"];
185 $retarray[] = $price_expression_obj;
188 $this->db->free($resql);
191 $this->error = $this->db->error();
207 $sql =
"SELECT rowid";
208 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
209 $sql .=
" WHERE title = '".$this->db->escape($title).
"'";
212 $resql = $this->db->query($sql);
214 $obj = $this->db->fetch_object($resql);
216 return (
int) $obj->rowid;
221 $this->error =
"Error ".$this->db->lasterror();
234 public function update($user = 0, $notrigger = 0)
239 if (isset($this->title)) {
240 $this->title = trim($this->title);
242 if (isset($this->expression)) {
243 $this->expression = trim($this->expression);
247 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
248 $sql .=
" title = ".(isset($this->title) ?
"'".$this->db->escape($this->title).
"'" :
"''").
",";
249 $sql .=
" expression = ".(isset($this->expression) ?
"'".$this->db->escape($this->expression).
"'" :
"''");
250 $sql .=
" WHERE rowid = ".((int) $this->
id);
255 $resql = $this->db->query($sql);
258 $this->errors[] =
"Error ".$this->db->lasterror();
263 foreach ($this->errors as $errmsg) {
265 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
267 $this->db->rollback();
283 public function delete(
User $user, $notrigger = 0)
292 $sql =
"DELETE FROM ".$this->db->prefix().$this->table_element;
293 $sql .=
" WHERE rowid = ".((int) $rowid);
296 $resql = $this->db->query($sql);
299 $this->errors[] =
"Error ".$this->db->lasterror();
305 foreach ($this->errors as $errmsg) {
307 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
309 $this->db->rollback();
326 $this->expression =
'';
Class for accesing price expression table.
update($user=0, $notrigger=0)
Update object into database.
find_title($title)
Returns any existing rowid with specified title.
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.
create($user, $notrigger=0)
Create object into database.
list_price_expression()
List all price expressions.
__construct($db)
Constructor.
Class to manage Dolibarr users.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.