36 public $element =
'ctyperesource';
41 public $table_element =
'c_type_resource';
46 public $lines = array();
84 if (isset($this->
code)) {
87 if (isset($this->label)) {
88 $this->label = trim($this->label);
90 if (isset($this->active)) {
91 $this->active = trim($this->active);
95 $sql =
'INSERT INTO '.$this->db->prefix().$this->table_element.
'(';
100 $sql .=
' '.(!isset($this->
code) ?
'NULL' :
"'".$this->db->escape($this->
code).
"'").
',';
101 $sql .=
' '.(!isset($this->label) ?
'NULL' :
"'".$this->db->escape($this->label).
"'").
',';
102 $sql .=
' '.(!isset($this->active) ?
'NULL' : $this->active);
110 $this->errors[] =
'Error '.$this->db->lasterror();
111 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
115 $this->
id = $this->
db->last_insert_id($this->
db->prefix().$this->table_element);
130 $this->
db->rollback();
149 public function fetch($id, $code =
'', $label =
'')
158 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
160 $sql .=
" WHERE t.id = ".((int) $id);
162 $sql .=
" WHERE t.code = '".$this->db->escape($code).
"'";
164 $sql .=
" WHERE t.label = '".$this->db->escape($label).
"'";
169 $numrows = $this->
db->num_rows(
$resql);
171 $obj = $this->
db->fetch_object(
$resql);
173 $this->
id = $obj->rowid;
175 $this->
code = $obj->code;
176 $this->label = $obj->label;
177 $this->active = $obj->active;
194 $this->errors[] =
'Error '.$this->db->lasterror();
195 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
213 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
222 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
226 if (count($filter) > 0) {
227 foreach ($filter as $key => $value) {
228 $sqlwhere[] = $key.
" LIKE '%".$this->
db->escape($value).
"%'";
232 if (count($sqlwhere) > 0) {
233 $sql .=
' WHERE '.implode(
' '.$this->
db->escape($filtermode).
' ', $sqlwhere);
235 if (!empty($sortfield)) {
236 $sql .= $this->
db->order($sortfield, $sortorder);
238 if (!empty($limit)) {
239 $sql .= $this->
db->plimit($limit, $offset);
246 while ($obj = $this->
db->fetch_object(
$resql)) {
247 $line =
new self($this->db);
249 $line->id = $obj->rowid;
251 $line->code = $obj->code;
252 $line->label = $obj->label;
253 $line->active = $obj->active;
259 $this->errors[] =
'Error '.$this->db->lasterror();
260 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
282 if (isset($this->
code)) {
285 if (isset($this->label)) {
286 $this->label = trim($this->label);
288 if (isset($this->active)) {
289 $this->active = trim($this->active);
296 $sql =
'UPDATE '.$this->db->prefix().$this->table_element.
' SET';
297 $sql .=
' code = '.(isset($this->
code) ?
"'".$this->db->escape($this->
code).
"'" :
"null").
',';
298 $sql .=
' label = '.(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
',';
299 $sql .=
' active = '.(isset($this->active) ? $this->active :
"null");
300 $sql .=
' WHERE rowid='.((int) $this->
id);
307 $this->errors[] =
'Error '.$this->db->lasterror();
308 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
323 $this->
db->rollback();
341 public function delete(
User $user, $notrigger =
false)
362 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element;
363 $sql .=
' WHERE rowid='.((int) $this->
id);
368 $this->errors[] =
'Error '.$this->db->lasterror();
369 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
375 $this->
db->rollback();
402 $object->fetch($fromid);
410 $object->context[
'createfromclone'] =
'createfromclone';
411 $result = $object->create($user);
416 $this->errors = $object->errors;
417 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
420 unset($object->context[
'createfromclone']);
428 $this->
db->rollback();
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.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db
API class for accounts.
print *****$script_file(".$version.") pid code
! Closing after partial payment: discount_vat, badcustomer or badsupplier, bankcharge,...