38 public $element =
'ctyperesource';
43 public $table_element =
'c_type_resource';
48 public $lines = array();
86 if (isset($this->code)) {
87 $this->code = trim($this->code);
89 if (isset($this->
label)) {
92 if (isset($this->active)) {
93 $this->active = trim($this->active);
102 $sql =
'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element .
'(';
109 $sql .=
') VALUES (';
111 $sql .=
' '.(! isset($this->code)?
'NULL':
"'".$this->db->escape($this->code).
"'").
',';
112 $sql .=
' '.(! isset($this->
label)?
'NULL':
"'".$this->db->escape($this->
label).
"'").
',';
113 $sql .=
' '.(! isset($this->active)?
'NULL':$this->active);
120 $resql = $this->db->query($sql);
123 $this->errors[] =
'Error ' . $this->db->lasterror();
124 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
128 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element);
143 $this->db->rollback();
162 public function fetch($id,$code=
'',$label=
'')
174 $sql .=
' FROM ' . MAIN_DB_PREFIX . $this->table_element .
' as t';
175 if ($id) $sql.=
" WHERE t.id = ".$id;
176 elseif ($code) $sql.=
" WHERE t.code = '".$this->db->escape($code).
"'";
177 elseif ($label) $sql.=
" WHERE t.label = '".$this->db->escape($label).
"'";
180 $resql = $this->db->query($sql);
182 $numrows = $this->db->num_rows(
$resql);
184 $obj = $this->db->fetch_object(
$resql);
186 $this->
id = $obj->rowid;
188 $this->code = $obj->code;
189 $this->
label = $obj->label;
190 $this->active = $obj->active;
207 $this->errors[] =
'Error ' . $this->db->lasterror();
208 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
226 public function fetchAll($sortorder=
'', $sortfield=
'', $limit=0, $offset=0, array $filter = array(), $filtermode=
'AND')
238 $sql .=
' FROM ' . MAIN_DB_PREFIX . $this->table_element.
' as t';
242 if (count($filter) > 0) {
243 foreach ($filter as $key => $value) {
244 $sqlwhere [] = $key .
' LIKE \'%' . $this->db->escape($value) .
'%\'';
248 if (count($sqlwhere) > 0) {
249 $sql .=
' WHERE ' . implode(
' '.$filtermode.
' ', $sqlwhere);
251 if (!empty($sortfield)) {
252 $sql .= $this->db->order($sortfield,$sortorder);
254 if (!empty($limit)) {
255 $sql .=
' ' . $this->db->plimit($limit, $offset);
258 $resql = $this->db->query($sql);
260 $num = $this->db->num_rows(
$resql);
262 while ($obj = $this->db->fetch_object(
$resql)) {
263 $line =
new self($this->db);
265 $line->id = $obj->rowid;
267 $line->code = $obj->code;
268 $line->label = $obj->label;
269 $line->active = $obj->active;
275 $this->errors[] =
'Error ' . $this->db->lasterror();
276 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
298 if (isset($this->code)) {
299 $this->code = trim($this->code);
301 if (isset($this->
label)) {
304 if (isset($this->active)) {
305 $this->active = trim($this->active);
312 $sql =
'UPDATE ' . MAIN_DB_PREFIX . $this->table_element .
' SET';
314 $sql .=
' code = '.(isset($this->code)?
"'".$this->db->escape($this->code).
"'":
"null").
',';
315 $sql .=
' label = '.(isset($this->
label)?
"'".$this->db->escape($this->
label).
"'":
"null").
',';
316 $sql .=
' active = '.(isset($this->active)?$this->active:
"null");
319 $sql .=
' WHERE rowid=' . $this->id;
323 $resql = $this->db->query($sql);
326 $this->errors[] =
'Error ' . $this->db->lasterror();
327 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
342 $this->db->rollback();
360 public function delete(
User $user, $notrigger =
false)
381 $sql =
'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element;
382 $sql .=
' WHERE rowid=' . $this->id;
384 $resql = $this->db->query($sql);
387 $this->errors[] =
'Error ' . $this->db->lasterror();
388 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
394 $this->db->rollback();
422 $object->fetch($fromid);
430 $object->context[
'createfromclone'] =
'createfromclone';
431 $result = $object->create($user);
436 $this->errors = $object->errors;
437 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
440 unset($object->context[
'createfromclone']);
448 $this->db->rollback();
print $object label
hash of file content (md5_file(dol_osencode($destfull))
update(User $user, $notrigger=false)
Update object into database.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
__construct(DoliDB $db)
Constructor.
Class to manage Dolibarr users.
Class to manage Dolibarr database access.
create(User $user, $notrigger=false)
Create object into database.
createFromClone($fromid)
Load an object from its id and create a new one in database.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
fetch($id, $code='', $label='')
Load object in memory from the database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load object in memory from the database.