dolibarr 21.0.0-alpha
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 $fk_user_creat;
140
144 public $fk_user_modif;
145
149 public $last_main_doc;
150
154 public $import_key;
155 // END MODULEBUILDER PROPERTIES
156
157
158
164 public function __construct(DoliDB $db)
165 {
166 global $conf, $langs;
167
168 $this->db = $db;
169
170 $this->ismultientitymanaged = 0;
171 $this->isextrafieldmanaged = 0;
172
173 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
174 $this->fields['rowid']['visible'] = 0;
175 }
176 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
177 $this->fields['entity']['enabled'] = 0;
178 }
179
180 // Unset fields that are disabled
181 foreach ($this->fields as $key => $val) {
182 if (isset($val['enabled']) && empty($val['enabled'])) {
183 unset($this->fields[$key]);
184 }
185 }
186
187 // Translate some data of arrayofkeyval
188 if (is_object($langs)) {
189 foreach ($this->fields as $key => $val) {
190 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
191 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
192 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
193 }
194 }
195 }
196 }
197 }
198
206 public function create(User $user, $notrigger = 0)
207 {
208 $resultcreate = $this->createCommon($user, $notrigger);
209
210 //$resultvalidate = $this->validate($user, $notrigger);
211
212 return $resultcreate;
213 }
214
222 public function createFromClone(User $user, $fromid)
223 {
224 global $langs, $extrafields;
225 $error = 0;
226
227 dol_syslog(__METHOD__, LOG_DEBUG);
228
229 $object = new self($this->db);
230
231 $this->db->begin();
232
233 // Load source object
234 $result = $object->fetchCommon($fromid);
235 if ($result > 0 && !empty($object->table_element_line)) {
236 $object->fetchLines();
237 }
238
239 // get lines so they will be clone
240 //foreach($this->lines as $line)
241 // $line->fetch_optionals();
242
243 // Reset some properties
244 unset($object->id);
245 unset($object->fk_user_creat);
246 unset($object->import_key);
247
248 // Clear fields
249 if (property_exists($object, 'ref')) {
250 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
251 }
252 if (property_exists($object, 'label')) {
253 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
254 }
255 if (property_exists($object, 'date_creation')) {
256 $object->date_creation = dol_now();
257 }
258 if (property_exists($object, 'date_modification')) {
259 $object->date_modification = null;
260 }
261 // ...
262 // Clear extrafields that are unique
263 if (is_array($object->array_options) && count($object->array_options) > 0) {
264 $extrafields->fetch_name_optionals_label($this->table_element);
265 foreach ($object->array_options as $key => $option) {
266 $shortkey = preg_replace('/options_/', '', $key);
267 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
268 //var_dump($key);
269 //var_dump($clonedObj->array_options[$key]); exit;
270 unset($object->array_options[$key]);
271 }
272 }
273 }
274
275 // Create clone
276 $object->context['createfromclone'] = 'createfromclone';
277 $result = $object->createCommon($user);
278 if ($result < 0) {
279 $error++;
280 $this->error = $object->error;
281 $this->errors = $object->errors;
282 }
283
284 if (!$error) {
285 // copy internal contacts
286 if ($this->copy_linked_contact($object, 'internal') < 0) {
287 $error++;
288 }
289 }
290
291 if (!$error) {
292 // copy external contacts if same company
293 if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
294 if ($this->copy_linked_contact($object, 'external') < 0) {
295 $error++;
296 }
297 }
298 }
299
300 unset($object->context['createfromclone']);
301
302 // End
303 if (!$error) {
304 $this->db->commit();
305 return $object;
306 } else {
307 $this->db->rollback();
308 return -1;
309 }
310 }
311
319 public function fetch($id, $ref = null)
320 {
321 $result = $this->fetchCommon($id, $ref);
322 if ($result > 0 && !empty($this->table_element_line)) {
323 $this->fetchLines();
324 }
325 return $result;
326 }
327
333 public function fetchLines()
334 {
335 $this->lines = array();
336
337 $result = $this->fetchLinesCommon();
338 return $result;
339 }
340
341
354 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
355 {
356 dol_syslog(__METHOD__, LOG_DEBUG);
357
358 $records = array();
359
360 $sql = 'SELECT ';
361 $sql .= $this->getFieldList('t');
362 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
363 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
364 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
365 } else {
366 $sql .= ' WHERE 1 = 1';
367 }
368
369 // Manage filter
370 $errormessage = '';
371 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
372 if ($errormessage) {
373 $this->errors[] = $errormessage;
374 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
375 return -1;
376 }
377
378 if (!empty($sortfield)) {
379 $sql .= $this->db->order($sortfield, $sortorder);
380 }
381 if (!empty($limit)) {
382 $sql .= $this->db->plimit($limit, $offset);
383 }
384
385 $resql = $this->db->query($sql);
386 if ($resql) {
387 $num = $this->db->num_rows($resql);
388 $i = 0;
389 while ($i < ($limit ? min($limit, $num) : $num)) {
390 $obj = $this->db->fetch_object($resql);
391
392 $record = new self($this->db);
393 $record->setVarsFromFetchObj($obj);
394
395 $records[$record->id] = $record;
396
397 $i++;
398 }
399 $this->db->free($resql);
400
401 return $records;
402 } else {
403 $this->errors[] = 'Error '.$this->db->lasterror();
404 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
405
406 return -1;
407 }
408 }
409
417 public function update(User $user, $notrigger = 0)
418 {
419 return $this->updateCommon($user, $notrigger);
420 }
421
429 public function delete(User $user, $notrigger = 0)
430 {
431 return $this->deleteCommon($user, $notrigger);
432 //return $this->deleteCommon($user, $notrigger, 1);
433 }
434
443 public function deleteLine(User $user, $idline, $notrigger = 0)
444 {
445 if ($this->status < 0) {
446 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
447 return -2;
448 }
449
450 return $this->deleteLineCommon($user, $idline, $notrigger);
451 }
452
453
464 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
465 {
466 global $conf, $langs, $hookmanager;
467
468 if (!empty($conf->dol_no_mouse_hover)) {
469 $notooltip = 1; // Force disable tooltips
470 }
471
472 $result = '';
473
474 /*$label = img_picto('', $this->picto).' <u>'.$langs->trans("MyObject").'</u>';
475 if (isset($this->status)) {
476 $label .= ' '.$this->getLibStatut(5);
477 }
478 $label .= '<br>';
479 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
480 */
481 $label = '';
482
483 //$url = dol_buildpath('/mymodule/myobject_card.php', 1).'?id='.$this->id;
484 $url = '';
485
486 if ($option != 'nolink') {
487 // Add param to save lastsearch_values or not
488 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
489 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
490 $add_save_lastsearch_values = 1;
491 }
492 if ($add_save_lastsearch_values) {
493 $url .= '&save_lastsearch_values=1';
494 }
495 }
496
497 $linkclose = '';
498 if (empty($notooltip)) {
499 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
500 $label = $langs->trans("ShowMyObject");
501 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
502 }
503 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
504 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
505 } else {
506 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
507 }
508
509 if ($option == 'nolink') {
510 $linkstart = '<span';
511 } else {
512 $linkstart = '<a href="'.$url.'"';
513 }
514 $linkstart .= $linkclose.'>';
515 if ($option == 'nolink') {
516 $linkend = '</span>';
517 } else {
518 $linkend = '</a>';
519 }
520
521 //$result .= $linkstart;
522 $result .= $this->label;
523 //$result .= $linkend;
524
525 global $action, $hookmanager;
526 $hookmanager->initHooks(array('cticketcategorydao'));
527 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
528 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
529 if ($reshook > 0) {
530 $result = $hookmanager->resPrint;
531 } else {
532 $result .= $hookmanager->resPrint;
533 }
534
535 return $result;
536 }
537
544 public function getLibStatut($mode = 0)
545 {
546 return $this->LibStatut($this->status, $mode);
547 }
548
549 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
557 public function LibStatut($status, $mode = 0)
558 {
559 // phpcs:enable
560 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
561 global $langs;
562 //$langs->load("mymodule@mymodule");
563 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
564 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
565 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
566 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
567 }
568
569 $statusType = 'status'.$status;
570 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
571 if ($status == self::STATUS_DISABLED) {
572 $statusType = 'status6';
573 }
574
575 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
576 }
577
584 public function info($id)
585 {
586 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
587 $sql .= ' fk_user_creat, fk_user_modif';
588 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
589 $sql .= ' WHERE t.rowid = '.((int) $id);
590 $result = $this->db->query($sql);
591 if ($result) {
592 if ($this->db->num_rows($result)) {
593 $obj = $this->db->fetch_object($result);
594
595 $this->id = $obj->rowid;
596
597 $this->user_creation_id = $obj->fk_user_creat;
598 $this->user_modification_id = $obj->fk_user_modif;
599 $this->date_creation = $this->db->jdate($obj->datec);
600 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
601 }
602
603 $this->db->free($result);
604 } else {
605 dol_print_error($this->db);
606 }
607 }
608
615 public function initAsSpecimen()
616 {
617 return $this->initAsSpecimenCommon();
618 }
619}
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:626
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.