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')
385 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
386 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
387 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
389 $sql .=
' WHERE 1 = 1';
393 if (count($filter) > 0) {
394 foreach ($filter as $key => $value) {
395 if ($key ==
't.rowid') {
396 $sqlwhere[] = $key.
" = ".((int) $value);
397 } elseif (in_array($this->fields[$key][
'type'], array(
'date',
'datetime',
'timestamp'))) {
398 $sqlwhere[] = $key.
" = '".$this->db->idate($value).
"'";
399 } elseif ($key ==
'customsql') {
400 $sqlwhere[] = $value;
401 } elseif (strpos($value,
'%') ===
false) {
402 $sqlwhere[] = $key.
" IN (".$this->db->sanitize($this->db->escape($value)).
")";
404 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
408 if (count($sqlwhere) > 0) {
409 $sql .=
' AND ('.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere).
')';
412 if (!empty($sortfield)) {
413 $sql .= $this->db->order($sortfield, $sortorder);
415 if (!empty($limit)) {
416 $sql .= $this->db->plimit($limit, $offset);
419 $resql = $this->db->query($sql);
421 $num = $this->db->num_rows($resql);
423 while ($i < ($limit ? min($limit, $num) : $num)) {
424 $obj = $this->db->fetch_object($resql);
426 $record =
new self($this->db);
427 $record->setVarsFromFetchObj($obj);
429 $records[$record->id] = $record;
433 $this->db->free($resql);
437 $this->errors[] =
'Error '.$this->db->lasterror();
438 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
463 public function delete(
User $user, $notrigger =
false)
479 if ($this->status < 0) {
480 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
498 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
500 global $conf, $langs, $hookmanager;
502 if (!empty($conf->dol_no_mouse_hover)) {
520 if ($option !=
'nolink') {
522 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
523 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
524 $add_save_lastsearch_values = 1;
526 if ($add_save_lastsearch_values) {
527 $url .=
'&save_lastsearch_values=1';
532 if (empty($notooltip)) {
534 $label = $langs->trans(
"ShowMyObject");
535 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
537 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
538 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
540 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
543 if ($option ==
'nolink') {
544 $linkstart =
'<span';
546 $linkstart =
'<a href="'.$url.
'"';
548 $linkstart .= $linkclose.
'>';
549 if ($option ==
'nolink') {
550 $linkend =
'</span>';
556 $result .= $this->label;
559 global $action, $hookmanager;
560 $hookmanager->initHooks(array(
'cticketcategorydao'));
561 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
562 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
564 $result = $hookmanager->resPrint;
566 $result .= $hookmanager->resPrint;
580 return $this->
LibStatut($this->status, $mode);
594 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
597 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
598 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
599 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
600 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
603 $statusType =
'status'.$status;
605 if ($status == self::STATUS_DISABLED) {
606 $statusType =
'status6';
609 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
620 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
621 $sql .=
' fk_user_creat, fk_user_modif';
622 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
623 $sql .=
' WHERE t.rowid = '.((int) $id);
624 $result = $this->db->query($sql);
626 if ($this->db->num_rows($result)) {
627 $obj = $this->db->fetch_object($result);
628 $this->
id = $obj->rowid;
631 $this->user_creation_id = $obj->fk_user_creat;
632 $this->user_modification_id = $obj->fk_user_modif;
633 $this->date_creation = $this->db->jdate($obj->datec);
634 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
637 $this->db->free($result);
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.
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the 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='')
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.