26require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
38 public $module =
'ticket';
43 public $element =
'cticketcategory';
48 public $table_element =
'c_ticket_category';
54 public $ismultientitymanaged = 0;
59 public $isextrafieldmanaged = 0;
64 public $picto =
'ticket';
67 const STATUS_DISABLED = 0;
68 const STATUS_ENABLED = 1;
101 public $fields=array(
102 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
103 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>-2,
'position'=>15,
'index'=>1),
104 'code' =>array(
'type'=>
'varchar(32)',
'label'=>
'Code',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>20),
105 'pos' =>array(
'type'=>
'integer',
'label'=>
'Pos',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>25),
106 'label' =>array(
'type'=>
'varchar(128)',
'label'=>
'Label',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>30,
'showoncombobox'=>1),
107 'active' =>array(
'type'=>
'integer',
'label'=>
'Active',
'enabled'=>1,
'visible'=>-1,
'position'=>35),
108 'use_default' =>array(
'type'=>
'integer',
'label'=>
'Usedefault',
'enabled'=>1,
'visible'=>-1,
'position'=>40),
109 'description' =>array(
'type'=>
'varchar(255)',
'label'=>
'Description',
'enabled'=>1,
'visible'=>-1,
'position'=>45),
110 'fk_parent' =>array(
'type'=>
'integer',
'label'=>
'Fkparent',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>50),
111 'force_severity' =>array(
'type'=>
'varchar(32)',
'label'=>
'Forceseverity',
'enabled'=>1,
'visible'=>-1,
'position'=>55),
112 'public' =>array(
'type'=>
'integer',
'label'=>
'Public',
'enabled'=>1,
'visible'=>-1,
'position'=>60),
148 public $date_creation;
158 public $fk_user_creat;
163 public $fk_user_modif;
168 public $last_main_doc;
185 global $conf, $langs;
190 $this->fields[
'rowid'][
'visible'] = 0;
192 if (!isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
193 $this->fields[
'entity'][
'enabled'] = 0;
203 foreach ($this->fields as $key => $val) {
204 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
205 unset($this->fields[$key]);
210 if (is_object($langs)) {
211 foreach ($this->fields as $key => $val) {
212 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
213 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
214 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
234 return $resultcreate;
246 global $langs, $extrafields;
251 $object =
new self($this->db);
256 $result = $object->fetchCommon($fromid);
257 if ($result > 0 && !empty($object->table_element_line)) {
258 $object->fetchLines();
267 unset($object->fk_user_creat);
268 unset($object->import_key);
271 if (property_exists($object,
'ref')) {
272 $object->ref = empty($this->fields[
'ref'][
'default']) ?
"Copy_Of_".$object->ref : $this->fields[
'ref'][
'default'];
274 if (property_exists($object,
'label')) {
275 $object->label = empty($this->fields[
'label'][
'default']) ? $langs->trans(
"CopyOf").
" ".$object->label : $this->fields[
'label'][
'default'];
277 if (property_exists($object,
'date_creation')) {
278 $object->date_creation =
dol_now();
280 if (property_exists($object,
'date_modification')) {
281 $object->date_modification =
null;
285 if (is_array($object->array_options) && count($object->array_options) > 0) {
286 $extrafields->fetch_name_optionals_label($this->table_element);
287 foreach ($object->array_options as $key => $option) {
288 $shortkey = preg_replace(
'/options_/',
'', $key);
289 if (!empty($extrafields->attributes[$this->table_element][
'unique'][$shortkey])) {
292 unset($object->array_options[$key]);
298 $object->context[
'createfromclone'] =
'createfromclone';
299 $result = $object->createCommon($user);
302 $this->error = $object->error;
303 $this->errors = $object->errors;
315 if (property_exists($this,
'fk_soc') && $this->fk_soc == $object->socid) {
322 unset($object->context[
'createfromclone']);
329 $this->db->rollback();
341 public function fetch($id, $ref =
null)
344 if ($result > 0 && !empty($this->table_element_line)) {
357 $this->lines = array();
375 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
383 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
384 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
385 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
387 $sql .=
' WHERE 1 = 1';
391 if (count($filter) > 0) {
392 foreach ($filter as $key => $value) {
393 if ($key ==
't.rowid') {
394 $sqlwhere[] = $key.
" = ".((int) $value);
395 } elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key][
'type'], array(
'date',
'datetime',
'timestamp'))) {
396 $sqlwhere[] = $key.
" = '".$this->db->idate($value).
"'";
397 } elseif ($key ==
'customsql') {
398 $sqlwhere[] = $value;
399 } elseif (strpos($value,
'%') ===
false) {
400 $sqlwhere[] = $key.
" IN (".$this->db->sanitize($this->db->escape($value)).
")";
402 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
406 if (count($sqlwhere) > 0) {
407 $sql .=
' AND ('.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere).
')';
410 if (!empty($sortfield)) {
411 $sql .= $this->db->order($sortfield, $sortorder);
413 if (!empty($limit)) {
414 $sql .= $this->db->plimit($limit, $offset);
417 $resql = $this->db->query($sql);
419 $num = $this->db->num_rows($resql);
421 while ($i < ($limit ? min($limit, $num) : $num)) {
422 $obj = $this->db->fetch_object($resql);
424 $record =
new self($this->db);
425 $record->setVarsFromFetchObj($obj);
427 $records[$record->id] = $record;
431 $this->db->free($resql);
435 $this->errors[] =
'Error '.$this->db->lasterror();
436 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
461 public function delete(
User $user, $notrigger =
false)
478 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
496 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
498 global $conf, $langs, $hookmanager;
500 if (!empty($conf->dol_no_mouse_hover)) {
518 if ($option !=
'nolink') {
520 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
521 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
522 $add_save_lastsearch_values = 1;
524 if ($add_save_lastsearch_values) {
525 $url .=
'&save_lastsearch_values=1';
530 if (empty($notooltip)) {
532 $label = $langs->trans(
"ShowMyObject");
533 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
535 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
536 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
538 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
541 if ($option ==
'nolink') {
542 $linkstart =
'<span';
544 $linkstart =
'<a href="'.$url.
'"';
546 $linkstart .= $linkclose.
'>';
547 if ($option ==
'nolink') {
548 $linkend =
'</span>';
554 $result .= $this->label;
557 global $action, $hookmanager;
558 $hookmanager->initHooks(array(
'cticketcategorydao'));
559 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
560 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
562 $result = $hookmanager->resPrint;
564 $result .= $hookmanager->resPrint;
592 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
595 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
596 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
597 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
598 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
601 $statusType =
'status'.$status;
603 if ($status == self::STATUS_DISABLED) {
604 $statusType =
'status6';
607 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
618 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
619 $sql .=
' fk_user_creat, fk_user_modif';
620 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
621 $sql .=
' WHERE t.rowid = '.((int) $id);
622 $result = $this->db->query($sql);
624 if ($this->db->num_rows($result)) {
625 $obj = $this->db->fetch_object($result);
627 $this->
id = $obj->rowid;
629 $this->user_creation_id = $obj->fk_user_creat;
630 $this->user_modification_id = $obj->fk_user_modif;
631 $this->date_creation = $this->db->jdate($obj->datec);
632 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
635 $this->db->free($result);
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
info($id)
Load the info information in the object.
createFromClone(User $user, $fromid)
Clone an object into another one.
getLibStatut($mode=0)
Return the label of the status.
LibStatut($status, $mode=0)
Return the status.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
update(User $user, $notrigger=false)
Update object into database.
create(User $user, $notrigger=false)
Create object into database.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
fetch($id, $ref=null)
Load object in memory from the database.
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
__construct(DoliDB $db)
Constructor.
fetchLines()
Load object lines 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.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
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.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
updateCommon(User $user, $notrigger=false)
Update object into database.
fetchLinesCommon($morewhere='', $noextrafields=0)
Load object in memory from the database.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
Class to manage Dolibarr database access.
Class to manage Dolibarr users.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_now($mode='auto')
Return date for now.
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.