27require_once DOL_DOCUMENT_ROOT.
'/core/class/commondict.class.php';
38 public $element =
'ctyperesource';
43 public $table_element =
'c_type_resource';
48 public $lines = array();
77 if (isset($this->code)) {
78 $this->code = trim($this->code);
80 if (isset($this->label)) {
81 $this->label = trim($this->label);
83 if (isset($this->active)) {
84 $this->active = trim($this->active);
88 $sql =
'INSERT INTO '.$this->db->prefix().$this->table_element.
'(';
93 $sql .=
' '.(!isset($this->code) ?
'NULL' :
"'".$this->db->escape($this->code).
"'").
',';
94 $sql .=
' '.(!isset($this->label) ?
'NULL' :
"'".$this->db->escape($this->label).
"'").
',';
95 $sql .=
' '.(!isset($this->active) ?
'NULL' : $this->active);
100 $resql = $this->db->query($sql);
103 $this->errors[] =
'Error '.$this->db->lasterror();
104 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
108 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
123 $this->db->rollback();
142 public function fetch($id, $code =
'', $label =
'')
151 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
153 $sql .=
" WHERE t.id = ".((int) $id);
155 $sql .=
" WHERE t.code = '".$this->db->escape($code).
"'";
157 $sql .=
" WHERE t.label = '".$this->db->escape($label).
"'";
160 $resql = $this->db->query($sql);
162 $numrows = $this->db->num_rows($resql);
164 $obj = $this->db->fetch_object($resql);
166 $this->
id = $obj->rowid;
168 $this->code = $obj->code;
169 $this->label = $obj->label;
170 $this->active = $obj->active;
179 $this->db->free($resql);
187 $this->errors[] =
'Error '.$this->db->lasterror();
188 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
206 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
215 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
219 if (count($filter) > 0) {
220 foreach ($filter as $key => $value) {
221 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
225 if (count($sqlwhere) > 0) {
226 $sql .=
' WHERE '.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere);
228 if (!empty($sortfield)) {
229 $sql .= $this->db->order($sortfield, $sortorder);
231 if (!empty($limit)) {
232 $sql .= $this->db->plimit($limit, $offset);
235 $resql = $this->db->query($sql);
237 $num = $this->db->num_rows($resql);
239 while ($obj = $this->db->fetch_object($resql)) {
240 $line =
new self($this->db);
242 $line->id = $obj->rowid;
244 $line->code = $obj->code;
245 $line->label = $obj->label;
246 $line->active = $obj->active;
248 $this->db->free($resql);
252 $this->errors[] =
'Error '.$this->db->lasterror();
253 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
275 if (isset($this->code)) {
276 $this->code = trim($this->code);
278 if (isset($this->label)) {
279 $this->label = trim($this->label);
281 if (isset($this->active)) {
282 $this->active = trim($this->active);
289 $sql =
'UPDATE '.$this->db->prefix().$this->table_element.
' SET';
290 $sql .=
' code = '.(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"null").
',';
291 $sql .=
' label = '.(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
',';
292 $sql .=
' active = '.(isset($this->active) ? $this->active :
"null");
293 $sql .=
' WHERE rowid='.((int) $this->
id);
297 $resql = $this->db->query($sql);
300 $this->errors[] =
'Error '.$this->db->lasterror();
301 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
316 $this->db->rollback();
334 public function delete(
User $user, $notrigger =
false)
355 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element;
356 $sql .=
' WHERE rowid='.((int) $this->
id);
358 $resql = $this->db->query($sql);
361 $this->errors[] =
'Error '.$this->db->lasterror();
362 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
368 $this->db->rollback();
395 $object->fetch($fromid);
403 $object->context[
'createfromclone'] =
'createfromclone';
404 $result = $object->create($user);
409 $this->errors = $object->errors;
410 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
413 unset($object->context[
'createfromclone']);
421 $this->db->rollback();
Parent class of all other dictionary classes.
update(User $user, $notrigger=false)
Update object into database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load object in memory from the database.
fetch($id, $code='', $label='')
Load object in memory from the database.
__construct(DoliDB $db)
Constructor.
create(User $user, $notrigger=false)
Create object into database.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
Class to manage Dolibarr database access.
Class to manage Dolibarr users.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.