dolibarr 20.0.0
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Put here all includes required by your class file
28require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
29//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
30//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
31
36{
40 public $module = 'ticket';
41
45 public $element = 'cticketcategory';
46
50 public $table_element = 'c_ticket_category';
51
55 public $picto = 'ticket';
56
57
58 const STATUS_DISABLED = 0;
59 const STATUS_ENABLED = 1;
60
61
88 // BEGIN MODULEBUILDER PROPERTIES
92 public $fields = array(
93 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 10),
94 'entity' => array('type' => 'integer', 'label' => 'Entity', 'default' => '1', 'enabled' => 1, 'visible' => -2, 'position' => 15, 'index' => 1),
95 'code' => array('type' => 'varchar(32)', 'label' => 'Code', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 20),
96 'pos' => array('type' => 'integer', 'label' => 'Pos', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 25),
97 'label' => array('type' => 'varchar(128)', 'label' => 'Label', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 30, 'showoncombobox' => 1),
98 'active' => array('type' => 'integer', 'label' => 'Active', 'enabled' => 1, 'visible' => -1, 'position' => 35),
99 'use_default' => array('type' => 'integer', 'label' => 'Usedefault', 'enabled' => 1, 'visible' => -1, 'position' => 40),
100 'description' => array('type' => 'varchar(255)', 'label' => 'Description', 'enabled' => 1, 'visible' => -1, 'position' => 45),
101 'fk_parent' => array('type' => 'integer', 'label' => 'Fkparent', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 50),
102 'force_severity' => array('type' => 'varchar(32)', 'label' => 'Forceseverity', 'enabled' => 1, 'visible' => -1, 'position' => 55),
103 'public' => array('type' => 'integer', 'label' => 'Public', 'enabled' => 1, 'visible' => -1, 'position' => 60),
104 );
105
109 public $rowid;
110
114 public $ref;
115
119 public $entity;
120
124 public $label;
125
129 public $amount;
130
134 public $status;
135
139 public $date_creation;
140
144 public $fk_user_creat;
145
149 public $fk_user_modif;
150
154 public $last_main_doc;
155
159 public $import_key;
160 // END MODULEBUILDER PROPERTIES
161
162
163
169 public function __construct(DoliDB $db)
170 {
171 global $conf, $langs;
172
173 $this->db = $db;
174
175 $this->ismultientitymanaged = 0;
176 $this->isextrafieldmanaged = 0;
177
178 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
179 $this->fields['rowid']['visible'] = 0;
180 }
181 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
182 $this->fields['entity']['enabled'] = 0;
183 }
184
185 // Unset fields that are disabled
186 foreach ($this->fields as $key => $val) {
187 if (isset($val['enabled']) && empty($val['enabled'])) {
188 unset($this->fields[$key]);
189 }
190 }
191
192 // Translate some data of arrayofkeyval
193 if (is_object($langs)) {
194 foreach ($this->fields as $key => $val) {
195 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
196 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
197 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
198 }
199 }
200 }
201 }
202 }
203
211 public function create(User $user, $notrigger = 0)
212 {
213 $resultcreate = $this->createCommon($user, $notrigger);
214
215 //$resultvalidate = $this->validate($user, $notrigger);
216
217 return $resultcreate;
218 }
219
227 public function createFromClone(User $user, $fromid)
228 {
229 global $langs, $extrafields;
230 $error = 0;
231
232 dol_syslog(__METHOD__, LOG_DEBUG);
233
234 $object = new self($this->db);
235
236 $this->db->begin();
237
238 // Load source object
239 $result = $object->fetchCommon($fromid);
240 if ($result > 0 && !empty($object->table_element_line)) {
241 $object->fetchLines();
242 }
243
244 // get lines so they will be clone
245 //foreach($this->lines as $line)
246 // $line->fetch_optionals();
247
248 // Reset some properties
249 unset($object->id);
250 unset($object->fk_user_creat);
251 unset($object->import_key);
252
253 // Clear fields
254 if (property_exists($object, 'ref')) {
255 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
256 }
257 if (property_exists($object, 'label')) {
258 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
259 }
260 if (property_exists($object, 'date_creation')) {
261 $object->date_creation = dol_now();
262 }
263 if (property_exists($object, 'date_modification')) {
264 $object->date_modification = null;
265 }
266 // ...
267 // Clear extrafields that are unique
268 if (is_array($object->array_options) && count($object->array_options) > 0) {
269 $extrafields->fetch_name_optionals_label($this->table_element);
270 foreach ($object->array_options as $key => $option) {
271 $shortkey = preg_replace('/options_/', '', $key);
272 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
273 //var_dump($key);
274 //var_dump($clonedObj->array_options[$key]); exit;
275 unset($object->array_options[$key]);
276 }
277 }
278 }
279
280 // Create clone
281 $object->context['createfromclone'] = 'createfromclone';
282 $result = $object->createCommon($user);
283 if ($result < 0) {
284 $error++;
285 $this->error = $object->error;
286 $this->errors = $object->errors;
287 }
288
289 if (!$error) {
290 // copy internal contacts
291 if ($this->copy_linked_contact($object, 'internal') < 0) {
292 $error++;
293 }
294 }
295
296 if (!$error) {
297 // copy external contacts if same company
298 if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
299 if ($this->copy_linked_contact($object, 'external') < 0) {
300 $error++;
301 }
302 }
303 }
304
305 unset($object->context['createfromclone']);
306
307 // End
308 if (!$error) {
309 $this->db->commit();
310 return $object;
311 } else {
312 $this->db->rollback();
313 return -1;
314 }
315 }
316
324 public function fetch($id, $ref = null)
325 {
326 $result = $this->fetchCommon($id, $ref);
327 if ($result > 0 && !empty($this->table_element_line)) {
328 $this->fetchLines();
329 }
330 return $result;
331 }
332
338 public function fetchLines()
339 {
340 $this->lines = array();
341
342 $result = $this->fetchLinesCommon();
343 return $result;
344 }
345
346
359 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
360 {
361 dol_syslog(__METHOD__, LOG_DEBUG);
362
363 $records = array();
364
365 $sql = 'SELECT ';
366 $sql .= $this->getFieldList('t');
367 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
368 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
369 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
370 } else {
371 $sql .= ' WHERE 1 = 1';
372 }
373
374 // Manage filter
375 $errormessage = '';
376 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
377 if ($errormessage) {
378 $this->errors[] = $errormessage;
379 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
380 return -1;
381 }
382
383 if (!empty($sortfield)) {
384 $sql .= $this->db->order($sortfield, $sortorder);
385 }
386 if (!empty($limit)) {
387 $sql .= $this->db->plimit($limit, $offset);
388 }
389
390 $resql = $this->db->query($sql);
391 if ($resql) {
392 $num = $this->db->num_rows($resql);
393 $i = 0;
394 while ($i < ($limit ? min($limit, $num) : $num)) {
395 $obj = $this->db->fetch_object($resql);
396
397 $record = new self($this->db);
398 $record->setVarsFromFetchObj($obj);
399
400 $records[$record->id] = $record;
401
402 $i++;
403 }
404 $this->db->free($resql);
405
406 return $records;
407 } else {
408 $this->errors[] = 'Error '.$this->db->lasterror();
409 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
410
411 return -1;
412 }
413 }
414
422 public function update(User $user, $notrigger = 0)
423 {
424 return $this->updateCommon($user, $notrigger);
425 }
426
434 public function delete(User $user, $notrigger = 0)
435 {
436 return $this->deleteCommon($user, $notrigger);
437 //return $this->deleteCommon($user, $notrigger, 1);
438 }
439
448 public function deleteLine(User $user, $idline, $notrigger = 0)
449 {
450 if ($this->status < 0) {
451 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
452 return -2;
453 }
454
455 return $this->deleteLineCommon($user, $idline, $notrigger);
456 }
457
458
469 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
470 {
471 global $conf, $langs, $hookmanager;
472
473 if (!empty($conf->dol_no_mouse_hover)) {
474 $notooltip = 1; // Force disable tooltips
475 }
476
477 $result = '';
478
479 /*$label = img_picto('', $this->picto).' <u>'.$langs->trans("MyObject").'</u>';
480 if (isset($this->status)) {
481 $label .= ' '.$this->getLibStatut(5);
482 }
483 $label .= '<br>';
484 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
485 */
486 $label = '';
487
488 //$url = dol_buildpath('/mymodule/myobject_card.php', 1).'?id='.$this->id;
489 $url = '';
490
491 if ($option != 'nolink') {
492 // Add param to save lastsearch_values or not
493 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
494 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
495 $add_save_lastsearch_values = 1;
496 }
497 if ($add_save_lastsearch_values) {
498 $url .= '&save_lastsearch_values=1';
499 }
500 }
501
502 $linkclose = '';
503 if (empty($notooltip)) {
504 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
505 $label = $langs->trans("ShowMyObject");
506 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
507 }
508 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
509 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
510 } else {
511 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
512 }
513
514 if ($option == 'nolink') {
515 $linkstart = '<span';
516 } else {
517 $linkstart = '<a href="'.$url.'"';
518 }
519 $linkstart .= $linkclose.'>';
520 if ($option == 'nolink') {
521 $linkend = '</span>';
522 } else {
523 $linkend = '</a>';
524 }
525
526 //$result .= $linkstart;
527 $result .= $this->label;
528 //$result .= $linkend;
529
530 global $action, $hookmanager;
531 $hookmanager->initHooks(array('cticketcategorydao'));
532 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
533 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
534 if ($reshook > 0) {
535 $result = $hookmanager->resPrint;
536 } else {
537 $result .= $hookmanager->resPrint;
538 }
539
540 return $result;
541 }
542
549 public function getLibStatut($mode = 0)
550 {
551 return $this->LibStatut($this->status, $mode);
552 }
553
554 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
562 public function LibStatut($status, $mode = 0)
563 {
564 // phpcs:enable
565 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
566 global $langs;
567 //$langs->load("mymodule@mymodule");
568 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
569 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
570 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
571 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
572 }
573
574 $statusType = 'status'.$status;
575 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
576 if ($status == self::STATUS_DISABLED) {
577 $statusType = 'status6';
578 }
579
580 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
581 }
582
589 public function info($id)
590 {
591 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
592 $sql .= ' fk_user_creat, fk_user_modif';
593 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
594 $sql .= ' WHERE t.rowid = '.((int) $id);
595 $result = $this->db->query($sql);
596 if ($result) {
597 if ($this->db->num_rows($result)) {
598 $obj = $this->db->fetch_object($result);
599
600 $this->id = $obj->rowid;
601
602 $this->user_creation_id = $obj->fk_user_creat;
603 $this->user_modification_id = $obj->fk_user_modif;
604 $this->date_creation = $this->db->jdate($obj->datec);
605 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
606 }
607
608 $this->db->free($result);
609 } else {
610 dol_print_error($this->db);
611 }
612 }
613
620 public function initAsSpecimen()
621 {
622 return $this->initAsSpecimenCommon();
623 }
624}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition security.php:636
Class for MyObject.
deleteLine(User $user, $idline, $notrigger=0)
Delete a line of object in database.
info($id)
Load the info information in the object.
createFromClone(User $user, $fromid)
Clone an object into another one.
update(User $user, $notrigger=0)
Update object into database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
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.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
fetch($id, $ref=null)
Load object in memory from the database.
create(User $user, $notrigger=0)
Create object into database.
__construct(DoliDB $db)
Constructor.
fetchLines()
Load object lines in memory from the database.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
deleteLineCommon(User $user, $idline, $notrigger=0)
Delete a line of object in database.
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.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
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.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
Class to manage Dolibarr database access.
Class to manage Dolibarr users.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.