27require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
39 public $element =
'defaultvalues';
44 public $table_element =
'default_values';
81 public $fields = array(
82 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
83 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 15,
'index' => 1),
84 'type' => array(
'type' =>
'varchar(10)',
'label' =>
'Type',
'enabled' => 1,
'visible' => -1,
'position' => 20),
85 'user_id' => array(
'type' =>
'integer',
'label' =>
'Userid',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 25),
86 'page' => array(
'type' =>
'varchar(255)',
'label' =>
'RelativeURL',
'enabled' => 1,
'visible' => -1,
'position' => 30),
87 'param' => array(
'type' =>
'varchar(255)',
'label' =>
'Field',
'enabled' => 1,
'visible' => -1,
'position' => 35),
88 'value' => array(
'type' =>
'varchar(128)',
'label' =>
'Value',
'enabled' => 1,
'visible' => -1,
'position' => 40),
134 global
$conf, $langs;
138 $this->ismultientitymanaged = 1;
139 $this->isextrafieldmanaged = 0;
142 $this->fields[
'rowid'][
'visible'] = 0;
144 if (!isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
145 $this->fields[
'entity'][
'enabled'] = 0;
149 foreach ($this->fields as $key => $val) {
150 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
151 unset($this->fields[$key]);
156 if (is_object($langs)) {
157 foreach ($this->fields as $key => $val) {
158 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
159 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
160 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
188 global $langs, $extrafields;
198 $result =
$object->fetchCommon($fromid);
204 $object->context[
'createfromclone'] =
'createfromclone';
205 $result =
$object->createCommon($user);
209 $this->errors =
$object->errors;
212 unset(
$object->context[
'createfromclone']);
219 $this->db->rollback();
248 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
256 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
257 $sql .=
" WHERE 1 = 1";
260 if (is_array($filter)) {
262 if (count($filter) > 0) {
263 foreach ($filter as $key => $value) {
264 if ($key ==
't.rowid' || ($key ==
't.entity' && !is_array($value)) || ($key ==
't.user_id' && !is_array($value))) {
265 $sqlwhere[] = $key.
" = ".((int) $value);
266 } elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key][
'type'], array(
'date',
'datetime',
'timestamp'))) {
267 $sqlwhere[] = $key.
" = '".$this->db->idate($value).
"'";
268 } elseif ($key ==
't.page' || $key ==
't.param' || $key ==
't.type') {
269 $sqlwhere[] = $key.
" = '".$this->db->escape($value).
"'";
270 } elseif (is_array($value)) {
271 $sqlwhere[] = $key.
" IN (".$this->db->sanitize(implode(
',', $value)).
")";
273 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
277 if (count($sqlwhere) > 0) {
278 $sql .=
' AND ('.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere).
')';
288 $this->errors[] = $errormessage;
289 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
293 if (!empty($sortfield)) {
294 $sql .= $this->db->order($sortfield, $sortorder);
296 if (!empty($limit)) {
297 $sql .= $this->db->plimit($limit, $offset);
300 $resql = $this->db->query($sql);
302 $num = $this->db->num_rows($resql);
304 while ($i < ($limit ? min($limit, $num) : $num)) {
305 $obj = $this->db->fetch_object($resql);
307 $record =
new self($this->db);
308 $record->setVarsFromFetchObj($obj);
310 $records[$record->id] = $record;
314 $this->db->free($resql);
318 $this->errors[] =
'Error '.$this->db->lasterror();
319 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
344 public function delete(
User $user, $notrigger = 0)
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Parent class of all other business classes (invoices, contracts, proposals, orders,...
createCommon(User $user, $notrigger=0)
Create object in the database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
updateCommon(User $user, $notrigger=0)
Update object into database.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
fetch($id)
Load object in memory from the database.
createFromClone(User $user, $fromid)
Clone an object into another one.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
create(User $user, $notrigger=0)
Create object into database.
update(User $user, $notrigger=0)
Update 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.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...