dolibarr 19.0.3
cticketcategory.class.php
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) ---Put here your own copyright and developer email---
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
25// Put here all includes required by your class file
26require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
27//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
28//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
29
34{
38 public $module = 'ticket';
39
43 public $element = 'cticketcategory';
44
48 public $table_element = 'c_ticket_category';
49
54 public $ismultientitymanaged = 0;
55
59 public $isextrafieldmanaged = 0;
60
64 public $picto = 'ticket';
65
66
67 const STATUS_DISABLED = 0;
68 const STATUS_ENABLED = 1;
69
70
97 // BEGIN MODULEBUILDER PROPERTIES
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),
113 );
114
118 public $rowid;
119
123 public $ref;
124
128 public $entity;
129
133 public $label;
134
138 public $amount;
139
143 public $status;
144
148 public $date_creation;
149
153 public $tms;
154
158 public $fk_user_creat;
159
163 public $fk_user_modif;
164
168 public $last_main_doc;
169
173 public $import_key;
174 // END MODULEBUILDER PROPERTIES
175
176
177
183 public function __construct(DoliDB $db)
184 {
185 global $conf, $langs;
186
187 $this->db = $db;
188
189 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
190 $this->fields['rowid']['visible'] = 0;
191 }
192 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
193 $this->fields['entity']['enabled'] = 0;
194 }
195
196 // Example to show how to set values of fields definition dynamically
197 /*if ($user->hasRight('mymodule', 'myobject', 'read')) {
198 $this->fields['myfield']['visible'] = 1;
199 $this->fields['myfield']['noteditable'] = 0;
200 }*/
201
202 // Unset fields that are disabled
203 foreach ($this->fields as $key => $val) {
204 if (isset($val['enabled']) && empty($val['enabled'])) {
205 unset($this->fields[$key]);
206 }
207 }
208
209 // Translate some data of arrayofkeyval
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);
215 }
216 }
217 }
218 }
219 }
220
228 public function create(User $user, $notrigger = false)
229 {
230 $resultcreate = $this->createCommon($user, $notrigger);
231
232 //$resultvalidate = $this->validate($user, $notrigger);
233
234 return $resultcreate;
235 }
236
244 public function createFromClone(User $user, $fromid)
245 {
246 global $langs, $extrafields;
247 $error = 0;
248
249 dol_syslog(__METHOD__, LOG_DEBUG);
250
251 $object = new self($this->db);
252
253 $this->db->begin();
254
255 // Load source object
256 $result = $object->fetchCommon($fromid);
257 if ($result > 0 && !empty($object->table_element_line)) {
258 $object->fetchLines();
259 }
260
261 // get lines so they will be clone
262 //foreach($this->lines as $line)
263 // $line->fetch_optionals();
264
265 // Reset some properties
266 unset($object->id);
267 unset($object->fk_user_creat);
268 unset($object->import_key);
269
270 // Clear fields
271 if (property_exists($object, 'ref')) {
272 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
273 }
274 if (property_exists($object, 'label')) {
275 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
276 }
277 if (property_exists($object, 'date_creation')) {
278 $object->date_creation = dol_now();
279 }
280 if (property_exists($object, 'date_modification')) {
281 $object->date_modification = null;
282 }
283 // ...
284 // Clear extrafields that are unique
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])) {
290 //var_dump($key);
291 //var_dump($clonedObj->array_options[$key]); exit;
292 unset($object->array_options[$key]);
293 }
294 }
295 }
296
297 // Create clone
298 $object->context['createfromclone'] = 'createfromclone';
299 $result = $object->createCommon($user);
300 if ($result < 0) {
301 $error++;
302 $this->error = $object->error;
303 $this->errors = $object->errors;
304 }
305
306 if (!$error) {
307 // copy internal contacts
308 if ($this->copy_linked_contact($object, 'internal') < 0) {
309 $error++;
310 }
311 }
312
313 if (!$error) {
314 // copy external contacts if same company
315 if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
316 if ($this->copy_linked_contact($object, 'external') < 0) {
317 $error++;
318 }
319 }
320 }
321
322 unset($object->context['createfromclone']);
323
324 // End
325 if (!$error) {
326 $this->db->commit();
327 return $object;
328 } else {
329 $this->db->rollback();
330 return -1;
331 }
332 }
333
341 public function fetch($id, $ref = null)
342 {
343 $result = $this->fetchCommon($id, $ref);
344 if ($result > 0 && !empty($this->table_element_line)) {
345 $this->fetchLines();
346 }
347 return $result;
348 }
349
355 public function fetchLines()
356 {
357 $this->lines = array();
358
359 $result = $this->fetchLinesCommon();
360 return $result;
361 }
362
363
375 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
376 {
377 dol_syslog(__METHOD__, LOG_DEBUG);
378
379 $records = array();
380
381 $sql = 'SELECT ';
382 $sql .= $this->getFieldList('t');
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).')';
386 } else {
387 $sql .= ' WHERE 1 = 1';
388 }
389 // Manage filter
390 $sqlwhere = array();
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)).")";
401 } else {
402 $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
403 }
404 }
405 }
406 if (count($sqlwhere) > 0) {
407 $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
408 }
409
410 if (!empty($sortfield)) {
411 $sql .= $this->db->order($sortfield, $sortorder);
412 }
413 if (!empty($limit)) {
414 $sql .= $this->db->plimit($limit, $offset);
415 }
416
417 $resql = $this->db->query($sql);
418 if ($resql) {
419 $num = $this->db->num_rows($resql);
420 $i = 0;
421 while ($i < ($limit ? min($limit, $num) : $num)) {
422 $obj = $this->db->fetch_object($resql);
423
424 $record = new self($this->db);
425 $record->setVarsFromFetchObj($obj);
426
427 $records[$record->id] = $record;
428
429 $i++;
430 }
431 $this->db->free($resql);
432
433 return $records;
434 } else {
435 $this->errors[] = 'Error '.$this->db->lasterror();
436 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
437
438 return -1;
439 }
440 }
441
449 public function update(User $user, $notrigger = false)
450 {
451 return $this->updateCommon($user, $notrigger);
452 }
453
461 public function delete(User $user, $notrigger = false)
462 {
463 return $this->deleteCommon($user, $notrigger);
464 //return $this->deleteCommon($user, $notrigger, 1);
465 }
466
475 public function deleteLine(User $user, $idline, $notrigger = false)
476 {
477 if ($this->status < 0) {
478 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
479 return -2;
480 }
481
482 return $this->deleteLineCommon($user, $idline, $notrigger);
483 }
484
485
496 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
497 {
498 global $conf, $langs, $hookmanager;
499
500 if (!empty($conf->dol_no_mouse_hover)) {
501 $notooltip = 1; // Force disable tooltips
502 }
503
504 $result = '';
505
506 /*$label = img_picto('', $this->picto).' <u>'.$langs->trans("MyObject").'</u>';
507 if (isset($this->status)) {
508 $label .= ' '.$this->getLibStatut(5);
509 }
510 $label .= '<br>';
511 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
512 */
513 $label = '';
514
515 //$url = dol_buildpath('/mymodule/myobject_card.php', 1).'?id='.$this->id;
516 $url = '';
517
518 if ($option != 'nolink') {
519 // Add param to save lastsearch_values or not
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;
523 }
524 if ($add_save_lastsearch_values) {
525 $url .= '&save_lastsearch_values=1';
526 }
527 }
528
529 $linkclose = '';
530 if (empty($notooltip)) {
531 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
532 $label = $langs->trans("ShowMyObject");
533 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
534 }
535 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
536 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
537 } else {
538 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
539 }
540
541 if ($option == 'nolink') {
542 $linkstart = '<span';
543 } else {
544 $linkstart = '<a href="'.$url.'"';
545 }
546 $linkstart .= $linkclose.'>';
547 if ($option == 'nolink') {
548 $linkend = '</span>';
549 } else {
550 $linkend = '</a>';
551 }
552
553 //$result .= $linkstart;
554 $result .= $this->label;
555 //$result .= $linkend;
556
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); // Note that $action and $object may have been modified by some hooks
561 if ($reshook > 0) {
562 $result = $hookmanager->resPrint;
563 } else {
564 $result .= $hookmanager->resPrint;
565 }
566
567 return $result;
568 }
569
576 public function getLibStatut($mode = 0)
577 {
578 return $this->LibStatut($this->status, $mode);
579 }
580
581 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
589 public function LibStatut($status, $mode = 0)
590 {
591 // phpcs:enable
592 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
593 global $langs;
594 //$langs->load("mymodule@mymodule");
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');
599 }
600
601 $statusType = 'status'.$status;
602 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
603 if ($status == self::STATUS_DISABLED) {
604 $statusType = 'status6';
605 }
606
607 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
608 }
609
616 public function info($id)
617 {
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);
623 if ($result) {
624 if ($this->db->num_rows($result)) {
625 $obj = $this->db->fetch_object($result);
626
627 $this->id = $obj->rowid;
628
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);
633 }
634
635 $this->db->free($result);
636 } else {
637 dol_print_error($this->db);
638 }
639 }
640
647 public function initAsSpecimen()
648 {
649 $this->initAsSpecimenCommon();
650 }
651}
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Definition security.php:604
Class for MyObject.
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.