dolibarr 25.0.0-alpha
triggerhistory.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2023-2026 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2025 Alice Adminson <myemail@mycompany.com>
5 * Copyright (C) 2026 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 = 'webhook';
41
45 public $element = 'webhook_triggerhistory';
46
50 public $table_element = 'webhook_history';
51
55 //public $element_for_permission = 'webhook';
56
60 public $picto = 'fa-calendar-alt';
61
62
63 const STATUS_SUCCESS = 1;
64 const STATUS_ERROR = -1;
65
109 // BEGIN MODULEBUILDER PROPERTIES
114 public $fields = array(
115 "rowid" => array("type" => "integer", "label" => "TechnicalID", "enabled" => 1, 'position' => 1, 'notnull' => 1, "visible" => 1, "noteditable" => 1, "index" => 1, "css" => "left", "comment" => "Id"),
116 "fk_target" => array("type" => "integer:target:webhook/class/target.class.php:0:(status:=:1)", "label" => "Target", "enabled" => 1, 'position' => 5, 'notnull' => 1, "visible" => 1),
117 "trigger_code" => array("type" => "varchar(128)", "label" => "TriggerCode", "enabled" => 1, 'position' => 8, 'notnull' => 1, "visible" => 1),
118 "url" => array("type" => "varchar(255)", "label" => "Url", "enabled" => 1, 'position' => 15, 'notnull' => 1, "visible" => 1, 'csslist' => "small tdoverflowmax150"),
119 "trigger_data" => array("type" => "text", "label" => "TriggerData", "enabled" => 1, 'position' => 20, 'notnull' => 1, "visible" => 1, "csslist" => "small tdoverflowmax300"),
120 "note_private" => array("type" => "text", "label" => "NotePrivate", "enabled" => 1, 'position' => 62, 'notnull' => 0, "visible" => 0, "cssview" => "wordbreak", "validate" => 1),
121 "date_creation" => array("type" => "datetime", "label" => "DateCreation", "enabled" => 1, 'position' => 500, 'notnull' => 1, "visible" => -2),
122 "tms" => array("type" => "timestamp", "label" => "DateModification", "enabled" => 1, 'position' => 501, 'notnull' => 0, "visible" => -2),
123 "fk_user_creat" => array("type" => "integer:User:user/class/user.class.php", "label" => "UserAuthor", "picto" => "user", "enabled" => 1, 'position' => 510, 'notnull' => 1, "visible" => -2, "csslist" => "tdoverflowmax150"),
124 "import_key" => array("type" => "varchar(14)", "label" => "ImportId", "enabled" => 1, 'position' => 1000, 'notnull' => -1, "visible" => -2,),
125 "status" => array("type" => "integer", "label" => "Status", "enabled" => 1, "position" => 2000, "notnull" => 1, 'default' => '1', "visible" => 1, "index" => 1, "arrayofkeyval" => array("1" => "Success", "-1" => "Error"), "validate" => 1),
126 "error_message" => array("type" => "text", "label" => "ErrorMessage", "enabled" => 1, 'position' => 50, 'notnull' => 0, "visible" => 1, "csslist" => "small tdoverflowmax150"),
127 );
131 public $rowid;
135 public $note_public;
139 public $note_private;
143 public $date_creation;
147 public $tms;
151 public $fk_user_creat;
155 public $import_key;
159 public $status;
163 public $trigger_data;
167 public $fk_target;
171 public $url;
175 public $trigger_code;
179 public $error_messsage;
180 // END MODULEBUILDER PROPERTIES
181
182
183 // If this object has a subtable with lines
184
185 // /**
186 // * @var string Name of subtable line
187 // */
188 // public $table_element_line = 'webhook_historyline';
189
190 // /**
191 // * @var string Field name with ID of parent key if this object has a parent, Or Field name of in child tables to link to this record.
192 // */
193 // public $fk_element = 'fk_history';
194
195 // /**
196 // * @var string Name of subtable class that manage subtable lines
197 // */
198 // public $class_element_line = 'Historyline';
199
200 // /**
201 // * @var array List of child tables. To test if we can delete object.
202 // */
203 // protected $childtables = array('mychildtable' => array('name'=>'', 'fk_element'=>'fk_history'));
204
205 // /**
206 // * @var array List of child tables. To know object to delete on cascade.
207 // * If name matches '@ClassName:FilePathClass:ParentFkFieldName' (the recommended mode) it will
208 // * call method ClassName->deleteByParentField(parentId, 'ParentFkFieldName') to fetch and delete child object.
209 // * Using an array like childtables should not be implemented because a child may have other child, so we must only use the method that call deleteByParentField().
210 // */
211 // protected $childtablesoncascade = array('webhook_historydet');
212
213 // /**
214 // * @var HistoryLine[] Array of subtable lines
215 // */
216 // public $lines = array();
217
218
219
225 public function __construct(DoliDB $db)
226 {
227 global $langs;
228
229 $this->db = $db;
230 $this->ismultientitymanaged = 0;
231 $this->isextrafieldmanaged = 1;
232
233 if (!getDolGlobalInt('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid']) && !empty($this->fields['ref'])) {
234 $this->fields['rowid']['visible'] = 0;
235 }
236 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
237 $this->fields['entity']['enabled'] = 0;
238 }
239
240 // Example to show how to set values of fields definition dynamically
241 /*if ($user->hasRight('webhook', 'triggerhistory', 'read')) {
242 $this->fields['myfield']['visible'] = 1;
243 $this->fields['myfield']['noteditable'] = 0;
244 }*/
245
246 // Unset fields that are disabled
247 foreach ($this->fields as $key => $val) {
248 if (isset($val['enabled']) && empty($val['enabled'])) {
249 unset($this->fields[$key]);
250 }
251 }
252
253 // Translate some data of arrayofkeyval
254 if (is_object($langs)) {
255 foreach ($this->fields as $key => $val) {
256 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
257 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
258 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
259 }
260 }
261 }
262 }
263 }
264
272 public function create(User $user, $notrigger = 0)
273 {
274 $result = $this->createCommon($user, $notrigger);
275
276 // uncomment lines below if you want to validate object after creation
277 // if ($result > 0) {
278 // $this->fetch($this->id); // needed to retrieve some fields (ie date_creation for masked ref)
279 // $resultupdate = $this->validate($user, $notrigger);
280 // if ($resultupdate < 0) { return $resultupdate; }
281 // }
282
283 return $result;
284 }
285
295 public function fetch($id, $ref = null, $noextrafields = 0, $nolines = 0)
296 {
297 $result = $this->fetchCommon($id, $ref, '', $noextrafields);
298 if ($result > 0 && !empty($this->table_element_line) && empty($nolines)) {
299 $this->fetchLines($noextrafields);
300 }
301 return $result;
302 }
303
310 public function fetchLines($noextrafields = 0)
311 {
312 $this->lines = array();
313
314 $result = $this->fetchLinesCommon('', $noextrafields);
315 return $result;
316 }
317
318
333 public function fetchAll($sortorder = '', $sortfield = '', $limit = 1000, $offset = 0, string $filter = '', $filtermode = 'AND')
334 {
335 dol_syslog(__METHOD__, LOG_DEBUG);
336
337 $records = array();
338
339 $sql = "SELECT ";
340 $sql .= $this->getFieldList('t');
341 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
342 if ($this->isextrafieldmanaged == 1) {
343 $sql .= " LEFT JOIN ".$this->db->prefix().$this->table_element."_extrafields as te ON te.fk_object = t.rowid";
344 }
345 if ($this->ismultientitymanaged == 1) {
346 $sql .= " WHERE t.entity IN (".getEntity($this->element).")";
347 } else {
348 $sql .= " WHERE 1 = 1";
349 }
350
351 // Manage filter
352 $errormessage = '';
353 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
354 if ($errormessage) {
355 $this->errors[] = $errormessage;
356 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
357 return -1;
358 }
359
360 if (!empty($sortfield)) {
361 $sql .= $this->db->order($sortfield, $sortorder);
362 }
363 if (!empty($limit)) {
364 $sql .= $this->db->plimit($limit, $offset);
365 }
366
367 $resql = $this->db->query($sql);
368 if ($resql) {
369 $num = $this->db->num_rows($resql);
370 $i = 0;
371 while ($i < ($limit ? min($limit, $num) : $num)) {
372 $obj = $this->db->fetch_object($resql);
373
374 $record = new self($this->db);
375 $record->setVarsFromFetchObj($obj);
376
377 if (!empty($record->isextrafieldmanaged)) {
378 $record->fetch_optionals();
379 }
380
381 $records[$record->id] = $record;
382
383 $i++;
384 }
385 $this->db->free($resql);
386
387 return $records;
388 } else {
389 $this->errors[] = 'Error '.$this->db->lasterror();
390 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
391
392 return -1;
393 }
394 }
395
403 public function update(User $user, $notrigger = 0)
404 {
405 return $this->updateCommon($user, $notrigger);
406 }
407
415 public function delete(User $user, $notrigger = 0)
416 {
417 return $this->deleteCommon($user, $notrigger);
418 //return $this->deleteCommon($user, $notrigger, 1);
419 }
420
429 public function deleteLine(User $user, $idline, $notrigger = 0)
430 {
431 if ($this->status < 0) {
432 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
433 return -2;
434 }
435
436 return $this->deleteLineCommon($user, $idline, $notrigger);
437 }
438
446 public function setDraft($user, $notrigger = 0)
447 {
448 // Protection
449 if ($this->status <= self::STATUS_SUCCESS) {
450 return 0;
451 }
452
453 /* if (! ((!getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('webhook','write'))
454 || (getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('webhook','webhook_advance','validate'))))
455 {
456 $this->error='Permission denied';
457 return -1;
458 }*/
459
460 return $this->setStatusCommon($user, self::STATUS_ERROR, $notrigger, 'WEBHOOK_MYOBJECT_UNVALIDATE');
461 }
462
470 public function cancel($user, $notrigger = 0)
471 {
472 // Protection
473 if ($this->status != self::STATUS_SUCCESS) {
474 return 0;
475 }
476
477 /* if (! ((!getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('webhook','write'))
478 || (getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('webhook','webhook_advance','validate'))))
479 {
480 $this->error='Permission denied';
481 return -1;
482 }*/
483
484 return $this->setStatusCommon($user, self::STATUS_ERROR, $notrigger, 'WEBHOOK_MYOBJECT_CANCEL');
485 }
486
494 public function reopen($user, $notrigger = 0)
495 {
496 // Protection
497 if ($this->status == self::STATUS_SUCCESS) {
498 return 0;
499 }
500
501 /*if (! ((!getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('webhook','write'))
502 || (getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('webhook','webhook_advance','validate'))))
503 {
504 $this->error='Permission denied';
505 return -1;
506 }*/
507
508 return $this->setStatusCommon($user, self::STATUS_SUCCESS, $notrigger, 'WEBHOOK_MYOBJECT_REOPEN');
509 }
510
518 public function getTooltipContentArray($params)
519 {
520 global $langs;
521
522 $datas = [];
523
524 if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) {
525 return ['optimize' => $langs->trans("ShowTriggerHistory")];
526 }
527 $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans("").'</u>';
528 $datas['picto'] .= ' '.$this->getLibStatut(5);
529 return $datas;
530 }
531
542 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
543 {
544 global $conf, $langs, $hookmanager;
545
546 if (!empty($conf->dol_no_mouse_hover)) {
547 $notooltip = 1; // Force disable tooltips
548 }
549
550 $result = '';
551 $params = [
552 'id' => (string) $this->id,
553 'objecttype' => $this->element.($this->module ? '@'.$this->module : ''),
554 'option' => $option,
555 ];
556 $classfortooltip = 'classfortooltip';
557 $dataparams = '';
558 $label = img_picto('', $this->picto).' <u>'.$langs->trans("TriggerHistory").'</u>';
559 $label .= ' '.$this->getLibStatut(5);
560 $label .= '<br>';
561 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
562
563 $baseurl = DOL_URL_ROOT.'/webhook/triggerhistory_card.php';
564 $query = ['id' => $this->id];
565 if ($option !== 'nolink') {
566 // Add param to save lastsearch_values or not
567 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
568 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
569 $add_save_lastsearch_values = 1;
570 }
571 if ($add_save_lastsearch_values) {
572 $query += ['save_lastsearch_values' => 1];
573 }
574 }
575 $url = dolBuildUrl($baseurl, $query);
576
577 $linkclose = '';
578 if (empty($notooltip)) {
579 if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) {
580 $label = $langs->trans("ShowTriggerHistory");
581 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
582 }
583 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
584 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
585 } else {
586 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
587 }
588
589 if ($option == 'nolink') {
590 $linkstart = '<span';
591 } else {
592 $linkstart = '<a href="'.$url.'"';
593 }
594 $linkstart .= $linkclose.'>';
595 if ($option == 'nolink') {
596 $linkend = '</span>';
597 } else {
598 $linkend = '</a>';
599 }
600
601 $result .= $linkstart;
602
603 if (empty($this->showphoto_on_popup)) {
604 if ($withpicto) {
605 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
606 }
607 } else {
608 if ($withpicto) {
609 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
610
611 list($class, $module) = explode('@', $this->picto);
612 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
613 $filearray = dol_dir_list($upload_dir, "files");
614 $filename = $filearray[0]['name'];
615 if (!empty($filename)) {
616 $pospoint = strpos($filearray[0]['name'], '.');
617
618 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.dol_substr($filename, 0, $pospoint).'_mini'.dol_substr($filename, $pospoint);
619 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
620 $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref"><img class="photo'.$module.'" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div></div>';
621 } else {
622 $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photouserphoto userphoto" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div>';
623 }
624
625 $result .= '</div>';
626 } else {
627 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
628 }
629 }
630 }
631
632 if ($withpicto != 2) {
633 $result .= $this->ref;
634 }
635
636 $result .= $linkend;
637 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
638
639 global $action, $hookmanager;
640 $hookmanager->initHooks(array($this->element.'dao'));
641 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
642 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
643 if ($reshook > 0) {
644 $result = $hookmanager->resPrint;
645 } else {
646 $result .= $hookmanager->resPrint;
647 }
648
649 return $result;
650 }
651
659 public function getKanbanView($option = '', $arraydata = null)
660 {
661 global $conf, $langs;
662
663 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
664
665 $return = '<div class="box-flex-item box-flex-grow-zero">';
666 $return .= '<div class="info-box info-box-sm">';
667 $return .= '<span class="info-box-icon bg-infobox-action">';
668 $return .= img_picto('', $this->picto);
669 $return .= '</span>';
670 $return .= '<div class="info-box-content">';
671 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.$this->getNomUrl().'</span>';
672 if ($selected >= 0) {
673 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
674 }
675 if (is_object($this->thirdparty)) {
676 $return .= '<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).'</div>';
677 }
678 /*if (property_exists($this, 'amount')) {
679 $return .= '<br>';
680 $return .= '<span class="info-box-label amount">'.price($this->amount, 0, $langs, 1, -1, -1, getDolCurrency()).'</span>';
681 }*/
682 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
683 $return .= '</div>';
684 $return .= '</div>';
685 $return .= '</div>';
686
687 return $return;
688 }
689
696 public function getLabelStatus($mode = 0)
697 {
698 return $this->LibStatut($this->status, $mode);
699 }
700
707 public function getLibStatut($mode = 0)
708 {
709 return $this->LibStatut($this->status, $mode);
710 }
711
712 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
720 public function LibStatut($status, $mode = 0)
721 {
722 // phpcs:enable
723 if (is_null($status)) {
724 return '';
725 }
726
727 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
728 global $langs;
729 //$langs->load("webhook@webhook");
730 $this->labelStatus[self::STATUS_SUCCESS] = $langs->transnoentitiesnoconv('Success');
731 $this->labelStatus[self::STATUS_ERROR] = $langs->transnoentitiesnoconv('Error');
732 $this->labelStatusShort[self::STATUS_SUCCESS] = $langs->transnoentitiesnoconv('Success');
733 $this->labelStatusShort[self::STATUS_ERROR] = $langs->transnoentitiesnoconv('Error');
734 }
735
736 $statusType = 'status'.$status;
737 if ($status == self::STATUS_SUCCESS) {
738 $statusType = 'status4';
739 }
740 if ($status == self::STATUS_ERROR) {
741 $statusType = 'status8';
742 }
743
744 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
745 }
746
753 public function info($id)
754 {
755 $sql = "SELECT rowid,";
756 $sql .= " date_creation as datec, tms as datem";
757 if (!empty($this->fields['date_validation'])) {
758 $sql .= ", date_validation as datev";
759 }
760 if (!empty($this->fields['fk_user_creat'])) {
761 $sql .= ", fk_user_creat";
762 }
763 if (!empty($this->fields['fk_user_modif'])) {
764 $sql .= ", fk_user_modif";
765 }
766 if (!empty($this->fields['fk_user_valid'])) {
767 $sql .= ", fk_user_valid";
768 }
769 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
770 $sql .= " WHERE t.rowid = ".((int) $id);
771
772 $result = $this->db->query($sql);
773 if ($result) {
774 if ($this->db->num_rows($result)) {
775 $obj = $this->db->fetch_object($result);
776
777 $this->id = $obj->rowid;
778
779 if (!empty($this->fields['fk_user_creat'])) {
780 $this->user_creation_id = $obj->fk_user_creat;
781 }
782 if (!empty($this->fields['fk_user_modif'])) {
783 $this->user_modification_id = $obj->fk_user_modif;
784 }
785 if (!empty($this->fields['fk_user_valid'])) {
786 $this->user_validation_id = $obj->fk_user_valid;
787 }
788 $this->date_creation = $this->db->jdate($obj->datec);
789 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
790 if (!empty($obj->datev)) {
791 $this->date_validation = empty($obj->datev) ? '' : $this->db->jdate($obj->datev);
792 }
793 }
794
795 $this->db->free($result);
796 } else {
797 dol_print_error($this->db);
798 }
799 }
800
807 public function initAsSpecimen()
808 {
809 // Set here init that are not commonf fields
810 // $this->property1 = ...
811 // $this->property2 = ...
812
813 return $this->initAsSpecimenCommon();
814 }
815
821 public function getLinesArray()
822 {
823 $this->lines = array();
824
825 $objectline = new HistoryLine($this->db);
826 $result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_history:=:'.((int) $this->id).')');
827
828 if (is_numeric($result)) {
829 $this->setErrorsFromObject($objectline);
830 return $result;
831 } else {
832 $this->lines = $result;
833 return $this->lines;
834 }
835 }
836
846 public function validateField($fields, $fieldKey, $fieldValue)
847 {
848 // Add your own validation rules here.
849 // ...
850
851 return parent::validateField($fields, $fieldKey, $fieldValue);
852 }
853
861 public function doScheduledJob()
862 {
863 //global $conf, $langs;
864
865 //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlogfile.log';
866
867 $error = 0;
868 $this->output = '';
869 $this->error = '';
870
871 dol_syslog(__METHOD__." start", LOG_INFO);
872
873 $now = dol_now();
874
875 $this->db->begin();
876
877 // ...
878
879 $this->db->commit();
880
881 dol_syslog(__METHOD__." end", LOG_INFO);
882
883 return $error;
884 }
885}
886
887
888require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
889
894{
895 // To complete with content of an object HistoryLine
896 // We should have a field rowid, fk_history and position
897
902 public $parent_element = ''; // Example: '' or 'triggerhistory'
903
908 public $fk_parent_attribute = ''; // Example: '' or 'fk_history'
909
915 public function __construct(DoliDB $db)
916 {
917 $this->db = $db;
918
919 $this->isextrafieldmanaged = 0;
920 }
921}
$object ref
Definition info.php:90
deleteLineCommon(User $user, $idline, $notrigger=0)
Delete a line of object in database.
setErrorsFromObject($object)
setErrorsFromObject
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.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
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.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage Dolibarr database access.
Class HistoryLine.
$parent_element
To overload.
$fk_parent_attribute
To overload.
__construct(DoliDB $db)
Constructor.
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
initAsSpecimen()
Initialize object with example values Id must be 0 if object instance is a specimen.
cancel($user, $notrigger=0)
Set cancel status.
$fields
'type' field format: 'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortf...
getLinesArray()
Create an array of lines.
getTooltipContentArray($params)
getTooltipContentArray
LibStatut($status, $mode=0)
Return the label of a given status.
getLabelStatus($mode=0)
Return the label of the status.
getKanbanView($option='', $arraydata=null)
Return a thumb for kanban views.
__construct(DoliDB $db)
Constructor.
fetch($id, $ref=null, $noextrafields=0, $nolines=0)
Load object in memory from the database.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
update(User $user, $notrigger=0)
Update object into database.
reopen($user, $notrigger=0)
Set back to validated status.
fetchAll($sortorder='', $sortfield='', $limit=1000, $offset=0, string $filter='', $filtermode='AND')
Load list of objects in memory from the database.
deleteLine(User $user, $idline, $notrigger=0)
Delete a line of object in database.
getLibStatut($mode=0)
Return the label of the status.
setDraft($user, $notrigger=0)
Set draft status.
create(User $user, $notrigger=0)
Create object into database.
validateField($fields, $fieldKey, $fieldValue)
Return validation test result for a field.
fetchLines($noextrafields=0)
Load object lines in memory from the database.
info($id)
Load the info information in the object.
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:169
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:65
dol_now($mode='gmt')
Return date for now.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.