46 public $errors = array();
66 public $table_element =
"c_price_expression";
91 if (isset($this->title)) {
92 $this->title = trim($this->title);
94 if (isset($this->expression)) {
95 $this->expression = trim($this->expression);
99 $sql =
"INSERT INTO ".$this->db->prefix().$this->table_element.
" (";
100 $sql .=
"title, expression";
101 $sql .=
") VALUES (";
102 $sql .=
" ".(isset($this->title) ?
"'".$this->db->escape($this->title).
"'" :
"''").
",";
103 $sql .=
" ".(isset($this->expression) ?
"'".$this->db->escape($this->expression).
"'" :
"''");
109 $resql = $this->db->query($sql);
112 $this->errors[] =
"Error ".$this->db->lasterror();
116 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
121 foreach ($this->errors as $errmsg) {
123 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
125 $this->db->rollback();
144 $this->error =
'ErrorWrongParameters';
148 $sql =
"SELECT title, expression";
149 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
150 $sql .=
" WHERE rowid = ".((int) $id);
153 $resql = $this->db->query($sql);
155 $obj = $this->db->fetch_object($resql);
158 $this->title = $obj->title;
159 $this->expression = $obj->expression;
165 $this->error =
"Error ".$this->db->lasterror();
179 $sql =
"SELECT rowid, title, expression";
180 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
181 $sql .=
" ORDER BY title";
184 $resql = $this->db->query($sql);
188 while ($record = $this->db->fetch_array($resql)) {
190 $price_expression_obj->id = $record[
"rowid"];
191 $price_expression_obj->title = $record[
"title"];
192 $price_expression_obj->expression = $record[
"expression"];
193 $retarray[] = $price_expression_obj;
196 $this->db->free($resql);
199 $this->error = $this->db->error();
215 $sql =
"SELECT rowid";
216 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
217 $sql .=
" WHERE title = '".$this->db->escape($title).
"'";
220 $resql = $this->db->query($sql);
222 $obj = $this->db->fetch_object($resql);
224 return (
int) $obj->rowid;
229 $this->error =
"Error ".$this->db->lasterror();
247 if (isset($this->title)) {
248 $this->title = trim($this->title);
250 if (isset($this->expression)) {
251 $this->expression = trim($this->expression);
255 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
256 $sql .=
" title = ".(isset($this->title) ?
"'".$this->db->escape($this->title).
"'" :
"''").
",";
257 $sql .=
" expression = ".(isset($this->expression) ?
"'".$this->db->escape($this->expression).
"'" :
"''");
258 $sql .=
" WHERE rowid = ".((int) $this->
id);
263 $resql = $this->db->query($sql);
266 $this->errors[] =
"Error ".$this->db->lasterror();
271 foreach ($this->errors as $errmsg) {
273 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
275 $this->db->rollback();
291 public function delete(
User $user, $notrigger = 0)
300 $sql =
"DELETE FROM ".$this->db->prefix().$this->table_element;
301 $sql .=
" WHERE rowid = ".((int) $rowid);
304 $resql = $this->db->query($sql);
307 $this->errors[] =
"Error ".$this->db->lasterror();
313 foreach ($this->errors as $errmsg) {
315 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
317 $this->db->rollback();
334 $this->expression =
'';
Class for accessing price expression table.
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.
create(User $user, $notrigger=0)
Create object into database.
fetch($id)
Load object in memory from the database.
update(User $user, $notrigger=0)
Update 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.