26require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
38 public $element =
'defaultvalues';
43 public $table_element =
'default_values';
49 public $ismultientitymanaged = 1;
54 public $isextrafieldmanaged = 0;
91 public $fields = array(
92 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
93 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>15,
'index'=>1),
94 'type' =>array(
'type'=>
'varchar(10)',
'label'=>
'Type',
'enabled'=>1,
'visible'=>-1,
'position'=>20),
95 'user_id' =>array(
'type'=>
'integer',
'label'=>
'Userid',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>25),
96 'page' =>array(
'type'=>
'varchar(255)',
'label'=>
'RelativeURL',
'enabled'=>1,
'visible'=>-1,
'position'=>30),
97 'param' =>array(
'type'=>
'varchar(255)',
'label'=>
'Field',
'enabled'=>1,
'visible'=>-1,
'position'=>35),
98 'value' =>array(
'type'=>
'varchar(128)',
'label'=>
'Value',
'enabled'=>1,
'visible'=>-1,
'position'=>40),
144 global $conf, $langs;
149 $this->fields[
'rowid'][
'visible'] = 0;
151 if (!isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
152 $this->fields[
'entity'][
'enabled'] = 0;
156 foreach ($this->fields as $key => $val) {
157 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
158 unset($this->fields[$key]);
163 if (is_object($langs)) {
164 foreach ($this->fields as $key => $val) {
165 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
166 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
167 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
195 global $langs, $extrafields;
200 $object =
new self($this->db);
205 $result = $object->fetchCommon($fromid);
211 $object->context[
'createfromclone'] =
'createfromclone';
212 $result = $object->createCommon($user);
215 $this->error = $object->error;
216 $this->errors = $object->errors;
219 unset($object->context[
'createfromclone']);
226 $this->db->rollback();
254 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
264 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
265 $sql .=
" WHERE 1 = 1";
268 if (count($filter) > 0) {
269 foreach ($filter as $key => $value) {
270 if ($key ==
't.rowid' || ($key ==
't.entity' && !is_array($value)) || ($key ==
't.user_id' && !is_array($value))) {
271 $sqlwhere[] = $key.
" = ".((int) $value);
272 } elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key][
'type'], array(
'date',
'datetime',
'timestamp'))) {
273 $sqlwhere[] = $key.
" = '".$this->db->idate($value).
"'";
274 } elseif ($key ==
't.page' || $key ==
't.param' || $key ==
't.type') {
275 $sqlwhere[] = $key.
" = '".$this->db->escape($value).
"'";
276 } elseif ($key ==
'customsql') {
277 $sqlwhere[] = $value;
278 } elseif (is_array($value)) {
279 $sqlwhere[] = $key.
" IN (".$this->db->sanitize(implode(
',', $value)).
")";
281 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
285 if (count($sqlwhere) > 0) {
286 $sql .=
' AND ('.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere).
')';
289 if (!empty($sortfield)) {
290 $sql .= $this->db->order($sortfield, $sortorder);
292 if (!empty($limit)) {
293 $sql .= $this->db->plimit($limit, $offset);
296 $resql = $this->db->query($sql);
298 $num = $this->db->num_rows($resql);
300 while ($i < ($limit ? min($limit, $num) : $num)) {
301 $obj = $this->db->fetch_object($resql);
303 $record =
new self($this->db);
304 $record->setVarsFromFetchObj($obj);
306 $records[$record->id] = $record;
310 $this->db->free($resql);
314 $this->errors[] =
'Error '.$this->db->lasterror();
315 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
340 public function delete(
User $user, $notrigger =
false)
Parent class of all other business classes (invoices, contracts, proposals, orders,...
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
updateCommon(User $user, $notrigger=false)
Update object into database.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
fetch($id)
Load object in memory from the database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
createFromClone(User $user, $fromid)
Clone an object into another one.
update(User $user, $notrigger=false)
Update object into database.
create(User $user, $notrigger=false)
Create object into database.
__construct(DoliDB $db)
Constructor.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
Class to manage Dolibarr database access.
Class to manage Dolibarr users.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.