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);
103 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
107 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
112 foreach ($this->errors as $errmsg) {
114 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
116 $this->db->rollback();
135 $this->error =
'ErrorWrongParameters';
139 $sql =
"SELECT title, expression";
140 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
141 $sql .=
" WHERE rowid = ".((int) $id);
144 $resql = $this->db->query($sql);
146 $obj = $this->db->fetch_object($resql);
149 $this->title = $obj->title;
150 $this->expression = $obj->expression;
156 $this->error =
"Error ".$this->db->lasterror();
170 $sql =
"SELECT rowid, title, expression";
171 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
172 $sql .=
" ORDER BY title";
175 $resql = $this->db->query($sql);
179 while ($record = $this->db->fetch_array($resql)) {
181 $price_expression_obj->id = $record[
"rowid"];
182 $price_expression_obj->title = $record[
"title"];
183 $price_expression_obj->expression = $record[
"expression"];
184 $retarray[] = $price_expression_obj;
187 $this->db->free($resql);
190 $this->error = $this->db->error();
206 $sql =
"SELECT rowid";
207 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
208 $sql .=
" WHERE title = '".$this->db->escape($title).
"'";
211 $resql = $this->db->query($sql);
213 $obj = $this->db->fetch_object($resql);
215 return (
int) $obj->rowid;
220 $this->error =
"Error ".$this->db->lasterror();
233 public function update($user = 0, $notrigger = 0)
238 if (isset($this->title)) {
239 $this->title = trim($this->title);
241 if (isset($this->expression)) {
242 $this->expression = trim($this->expression);
246 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
247 $sql .=
" title = ".(isset($this->title) ?
"'".$this->db->escape($this->title).
"'" :
"''").
",";
248 $sql .=
" expression = ".(isset($this->expression) ?
"'".$this->db->escape($this->expression).
"'" :
"''");
249 $sql .=
" WHERE rowid = ".((int) $this->
id);
254 $resql = $this->db->query($sql);
256 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
261 foreach ($this->errors as $errmsg) {
263 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
265 $this->db->rollback();
281 public function delete(
User $user, $notrigger = 0)
290 $sql =
"DELETE FROM ".$this->db->prefix().$this->table_element;
291 $sql .=
" WHERE rowid = ".((int) $rowid);
294 $resql = $this->db->query($sql);
296 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
302 foreach ($this->errors as $errmsg) {
304 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
306 $this->db->rollback();
323 $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.