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 // @phan-suppress-next-line PhanTypeInvalidDimOffset
254 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
255 }
256 if (property_exists($object, 'date_creation')) {
257 $object->date_creation = dol_now();
258 }
259 if (property_exists($object, 'date_modification')) {
260 $object->date_modification = null;
261 }
262 // ...
263 // Clear extrafields that are unique
264 if (is_array($object->array_options) && count($object->array_options) > 0) {
265 $extrafields->fetch_name_optionals_label($this->table_element);
266 foreach ($object->array_options as $key => $option) {
267 $shortkey = preg_replace('/options_/', '', $key);
268 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
269 //var_dump($key);
270 //var_dump($clonedObj->array_options[$key]); exit;
271 unset($object->array_options[$key]);
272 }
273 }
274 }
275
276 // Create clone
277 $object->context['createfromclone'] = 'createfromclone';
278 $result = $object->createCommon($user);
279 if ($result < 0) {
280 $error++;
281 $this->error = $object->error;
282 $this->errors = $object->errors;
283 }
284
285 if (!$error) {
286 // copy internal contacts
287 if ($this->copy_linked_contact($object, 'internal') < 0) {
288 $error++;
289 }
290 }
291
292 if (!$error) {
293 // copy external contacts if same company
294 if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
295 if ($this->copy_linked_contact($object, 'external') < 0) {
296 $error++;
297 }
298 }
299 }
300
301 unset($object->context['createfromclone']);
302
303 // End
304 if (!$error) {
305 $this->db->commit();
306 return $object;
307 } else {
308 $this->db->rollback();
309 return -1;
310 }
311 }
312
320 public function fetch($id, $ref = null)
321 {
322 $result = $this->fetchCommon($id, $ref);
323 if ($result > 0 && !empty($this->table_element_line)) {
324 $this->fetchLines();
325 }
326 return $result;
327 }
328
334 public function fetchLines()
335 {
336 $this->lines = array();
337
338 $result = $this->fetchLinesCommon();
339 return $result;
340 }
341
342
355 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
356 {
357 dol_syslog(__METHOD__, LOG_DEBUG);
358
359 $records = array();
360
361 $sql = 'SELECT ';
362 $sql .= $this->getFieldList('t');
363 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
364 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
365 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
366 } else {
367 $sql .= ' WHERE 1 = 1';
368 }
369
370 // Manage filter
371 $errormessage = '';
372 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
373 if ($errormessage) {
374 $this->errors[] = $errormessage;
375 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
376 return -1;
377 }
378
379 if (!empty($sortfield)) {
380 $sql .= $this->db->order($sortfield, $sortorder);
381 }
382 if (!empty($limit)) {
383 $sql .= $this->db->plimit($limit, $offset);
384 }
385
386 $resql = $this->db->query($sql);
387 if ($resql) {
388 $num = $this->db->num_rows($resql);
389 $i = 0;
390 while ($i < ($limit ? min($limit, $num) : $num)) {
391 $obj = $this->db->fetch_object($resql);
392
393 $record = new self($this->db);
394 $record->setVarsFromFetchObj($obj);
395
396 $records[$record->id] = $record;
397
398 $i++;
399 }
400 $this->db->free($resql);
401
402 return $records;
403 } else {
404 $this->errors[] = 'Error '.$this->db->lasterror();
405 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
406
407 return -1;
408 }
409 }
410
418 public function update(User $user, $notrigger = 0)
419 {
420 return $this->updateCommon($user, $notrigger);
421 }
422
430 public function delete(User $user, $notrigger = 0)
431 {
432 return $this->deleteCommon($user, $notrigger);
433 //return $this->deleteCommon($user, $notrigger, 1);
434 }
435
444 public function deleteLine(User $user, $idline, $notrigger = 0)
445 {
446 if ($this->status < 0) {
447 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
448 return -2;
449 }
450
451 return $this->deleteLineCommon($user, $idline, $notrigger);
452 }
453
454
465 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
466 {
467 global $conf, $langs, $hookmanager;
468
469 if (!empty($conf->dol_no_mouse_hover)) {
470 $notooltip = 1; // Force disable tooltips
471 }
472
473 $result = '';
474
475 /*$label = img_picto('', $this->picto).' <u>'.$langs->trans("MyObject").'</u>';
476 if (isset($this->status)) {
477 $label .= ' '.$this->getLibStatut(5);
478 }
479 $label .= '<br>';
480 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
481 */
482 $label = '';
483
484 //$url = dol_buildpath('/mymodule/myobject_card.php', 1).'?id='.$this->id;
485 $url = '';
486
487 if ($option != 'nolink') {
488 // Add param to save lastsearch_values or not
489 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
490 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
491 $add_save_lastsearch_values = 1;
492 }
493 if ($add_save_lastsearch_values) {
494 $url .= '&save_lastsearch_values=1';
495 }
496 }
497
498 $linkclose = '';
499 if (empty($notooltip)) {
500 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
501 $label = $langs->trans("ShowMyObject");
502 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
503 }
504 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
505 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
506 } else {
507 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
508 }
509
510 if ($option == 'nolink') {
511 $linkstart = '<span';
512 } else {
513 $linkstart = '<a href="'.$url.'"';
514 }
515 $linkstart .= $linkclose.'>';
516 if ($option == 'nolink') {
517 $linkend = '</span>';
518 } else {
519 $linkend = '</a>';
520 }
521
522 //$result .= $linkstart;
523 $result .= $this->label;
524 //$result .= $linkend;
525
526 global $action, $hookmanager;
527 $hookmanager->initHooks(array('cticketcategorydao'));
528 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
529 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
530 if ($reshook > 0) {
531 $result = $hookmanager->resPrint;
532 } else {
533 $result .= $hookmanager->resPrint;
534 }
535
536 return $result;
537 }
538
545 public function getLibStatut($mode = 0)
546 {
547 return $this->LibStatut($this->status, $mode);
548 }
549
550 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
558 public function LibStatut($status, $mode = 0)
559 {
560 // phpcs:enable
561 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
562 global $langs;
563 //$langs->load("mymodule@mymodule");
564 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
565 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
566 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
567 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
568 }
569
570 $statusType = 'status'.$status;
571 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
572 if ($status == self::STATUS_DISABLED) {
573 $statusType = 'status6';
574 }
575
576 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
577 }
578
585 public function info($id)
586 {
587 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
588 $sql .= ' fk_user_creat, fk_user_modif';
589 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
590 $sql .= ' WHERE t.rowid = '.((int) $id);
591 $result = $this->db->query($sql);
592 if ($result) {
593 if ($this->db->num_rows($result)) {
594 $obj = $this->db->fetch_object($result);
595
596 $this->id = $obj->rowid;
597
598 $this->user_creation_id = $obj->fk_user_creat;
599 $this->user_modification_id = $obj->fk_user_modif;
600 $this->date_creation = $this->db->jdate($obj->datec);
601 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
602 }
603
604 $this->db->free($result);
605 } else {
606 dol_print_error($this->db);
607 }
608 }
609
616 public function initAsSpecimen()
617 {
618 return $this->initAsSpecimenCommon();
619 }
620}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:162
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 a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.