dolibarr 23.0.3
timespent.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-2025 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
5 * Copyright (C) 2024-2025 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
34{
38 public $module = 'timespent';
39
43 public $element = 'timespent';
44
48 public $table_element = 'element_time';
49
53 public $picto = 'fa-file';
54
55
56 const STATUS_DRAFT = 0;
57 const STATUS_VALIDATED = 1;
58 const STATUS_CANCELED = 9;
59
60
100 // BEGIN MODULEBUILDER PROPERTIES
104 public $fields = array(
105 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'css' => 'left', 'comment' => "Id"),
106 'ref_ext' => array('type' => 'varchar(255)', 'label' => 'RefExt', 'enabled' => 1, 'visible' => 0, 'position' => 20),
107 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 17, 'notnull' => 0, 'visible' => -2,),
108 'import_key' => array('type' => 'varchar(14)', 'label' => 'import_key', 'enabled' => 1, 'position' => 15, 'notnull' => 0, 'visible' => -1,),
109 'fk_element' => array('type' => 'integer', 'label' => 'fk_element', 'enabled' => 1, 'position' => 2, 'notnull' => 1, 'visible' => -1,),
110 'elementtype' => array('type' => 'varchar(32)', 'label' => 'elementtype', 'enabled' => 1, 'position' => 3, 'notnull' => 1, 'visible' => -1,),
111 'element_date' => array('type' => 'date', 'label' => 'element_date', 'enabled' => 1, 'position' => 4, 'notnull' => 0, 'visible' => -1,),
112 'element_datehour' => array('type' => 'datetime', 'label' => 'element_datehour', 'enabled' => 1, 'position' => 5, 'notnull' => 0, 'visible' => -1,),
113 'element_date_withhour' => array('type' => 'integer', 'label' => 'element_date_withhour', 'enabled' => 1, 'position' => 6, 'notnull' => 0, 'visible' => -1,),
114 'element_duration' => array('type' => 'double', 'label' => 'element_duration', 'enabled' => 1, 'position' => 7, 'notnull' => 0, 'visible' => -1,),
115 'fk_product' => array('type' => 'integer', 'label' => 'fk_product', 'enabled' => 1, 'position' => 8, 'notnull' => 0, 'visible' => -1,),
116 'fk_user' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'fk_user', 'enabled' => 1, 'position' => 9, 'notnull' => 0, 'visible' => -1,),
117 'thm' => array('type' => 'double(24,8)', 'label' => 'thm', 'enabled' => 1, 'position' => 10, 'notnull' => 0, 'visible' => -1,),
118 'invoice_id' => array('type' => 'integer', 'label' => 'invoice_id', 'enabled' => 1, 'position' => 11, 'notnull' => 0, 'visible' => -1, 'default' => 'NULL',),
119 'invoice_line_id' => array('type' => 'integer', 'label' => 'invoice_line_id', 'enabled' => 1, 'position' => 12, 'notnull' => 0, 'visible' => -1, 'default' => 'NULL',),
120 'intervention_id' => array('type' => 'integer', 'label' => 'intervention_id', 'enabled' => 1, 'position' => 13, 'notnull' => 0, 'visible' => -1, 'default' => 'NULL',),
121 'intervention_line_id' => array('type' => 'integer', 'label' => 'intervention_line_id', 'enabled' => 1, 'position' => 14, 'notnull' => 0, 'visible' => -1, 'default' => 'NULL',),
122 'datec' => array('type' => 'datetime', 'label' => 'datec', 'enabled' => 1, 'position' => 16, 'notnull' => 0, 'visible' => -1,),
123 'note' => array('type' => 'text', 'label' => 'note', 'enabled' => 1, 'position' => 18, 'notnull' => 0, 'visible' => -1,),
124 );
125
129 public $rowid;
130
134 public $import_key;
135
139 public $fk_element;
140
144 public $elementtype;
145
149 public $element_date;
150
154 public $element_datehour;
155
159 public $element_date_withhour;
160
164 public $element_duration;
165
169 public $fk_product;
170
174 public $fk_user;
175
179 public $thm;
180
184 public $invoice_id;
185
189 public $invoice_line_id;
190
194 public $intervention_id;
195
199 public $intervention_line_id;
200
204 public $datec;
205
209 public $note;
210 // END MODULEBUILDER PROPERTIES
211
217 public function __construct(DoliDB $db)
218 {
219 global $langs;
220
221 $this->db = $db;
222
223 $this->ismultientitymanaged = 0;
224 $this->isextrafieldmanaged = 0;
225
226 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid']) && !empty($this->fields['ref'])) { // @phan-suppress-current-line PhanTypeMismatchProperty
227 $this->fields['rowid']['visible'] = 0;
228 }
229 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
230 $this->fields['entity']['enabled'] = 0;
231 }
232
233 // Example to show how to set values of fields definition dynamically
234 /*if ($user->rights->timespent->timespent->read) {
235 $this->fields['myfield']['visible'] = 1;
236 $this->fields['myfield']['noteditable'] = 0;
237 }*/
238
239 // Unset fields that are disabled
240 foreach ($this->fields as $key => $val) {
241 if (isset($val['enabled']) && empty($val['enabled'])) {
242 unset($this->fields[$key]);
243 }
244 }
245
246 // Translate some data of arrayofkeyval
247 if (is_object($langs)) {
248 foreach ($this->fields as $key => $val) {
249 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
250 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
251 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
252 }
253 }
254 }
255 }
256 }
257
265 public function create(User $user, $notrigger = 0)
266 {
267 $resultcreate = $this->createCommon($user, $notrigger);
268
269 //$resultvalidate = $this->validate($user, $notrigger);
270
271 return $resultcreate;
272 }
273
281 public function createFromClone(User $user, $fromid)
282 {
283 global $extrafields;
284
285 $error = 0;
286
287 dol_syslog(__METHOD__, LOG_DEBUG);
288
289 $object = new self($this->db);
290
291 $this->db->begin();
292
293 // Load source object
294 $result = $object->fetchCommon($fromid);
295
296 // Reset some properties
297 unset($object->id);
298 unset($object->fk_user_creat);
299 unset($object->user_creation_id);
300 unset($object->import_key);
301
302 // Clear fields
303 if (property_exists($object, 'ref')) {
304 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
305 }
306 if (property_exists($object, 'status')) {
307 $object->status = self::STATUS_DRAFT;
308 }
309 if (property_exists($object, 'date_creation')) {
310 $object->date_creation = dol_now();
311 }
312 if (property_exists($object, 'date_modification')) {
313 $object->date_modification = null;
314 }
315 // ...
316 // Clear extrafields that are unique
317 if (is_array($object->array_options) && count($object->array_options) > 0) {
318 $extrafields->fetch_name_optionals_label($this->table_element);
319 foreach ($object->array_options as $key => $option) {
320 $shortkey = preg_replace('/options_/', '', $key);
321 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
322 //var_dump($key);
323 //var_dump($clonedObj->array_options[$key]); exit;
324 unset($object->array_options[$key]);
325 }
326 }
327 }
328
329 // Create clone
330 $object->context['createfromclone'] = 'createfromclone';
331 $result = $object->createCommon($user);
332 if ($result < 0) {
333 $error++;
334 $this->error = $object->error;
335 $this->errors = $object->errors;
336 }
337
338 if (!$error) {
339 // copy internal contacts
340 if ($this->copy_linked_contact($object, 'internal') < 0) {
341 $error++;
342 }
343 }
344
345 unset($object->context['createfromclone']);
346
347 // End
348 if (!$error) {
349 $this->db->commit();
350 return $object;
351 } else {
352 $this->db->rollback();
353 return -1;
354 }
355 }
356
364 public function fetch($id, $ref = null)
365 {
366 $result = $this->fetchCommon($id, $ref);
367
368 return $result;
369 }
370
383 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
384 {
385 global $conf;
386
387 dol_syslog(__METHOD__, LOG_DEBUG);
388
389 $records = array();
390
391 $sql = "SELECT ";
392 $sql .= $this->getFieldList('t');
393 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
394 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
395 $sql .= " WHERE t.entity IN (".getEntity($this->element).")";
396 } else {
397 $sql .= " WHERE 1 = 1";
398 }
399
400 // Manage filter
401 $errormessage = '';
402 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
403 if ($errormessage) {
404 $this->errors[] = $errormessage;
405 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
406 return -1;
407 }
408
409 if (!empty($sortfield)) {
410 $sql .= $this->db->order($sortfield, $sortorder);
411 }
412 if (!empty($limit)) {
413 $sql .= $this->db->plimit($limit, $offset);
414 }
415
416 $resql = $this->db->query($sql);
417 if ($resql) {
418 $num = $this->db->num_rows($resql);
419 $i = 0;
420 while ($i < ($limit ? min($limit, $num) : $num)) {
421 $obj = $this->db->fetch_object($resql);
422
423 $record = new self($this->db);
424 $record->setVarsFromFetchObj($obj);
425
426 $records[$record->id] = $record;
427
428 $i++;
429 }
430 $this->db->free($resql);
431
432 return $records;
433 } else {
434 $this->errors[] = 'Error '.$this->db->lasterror();
435 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
436
437 return -1;
438 }
439 }
440
448 public function update(User $user, $notrigger = 0)
449 {
450 return $this->updateCommon($user, $notrigger);
451 }
452
460 public function delete(User $user, $notrigger = 0)
461 {
462 return $this->deleteCommon($user, $notrigger);
463 //return $this->deleteCommon($user, $notrigger, 1);
464 }
465
474 public function deleteLine(User $user, $idline, $notrigger = 0)
475 {
476 if ($this->status < 0) {
477 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
478 return -2;
479 }
480
481 return $this->deleteLineCommon($user, $idline, $notrigger);
482 }
483
484
492 public function validate($user, $notrigger = 0)
493 {
494 global $conf, $langs;
495
496 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
497
498 $error = 0;
499
500 // Protection
501 if ($this->status == self::STATUS_VALIDATED) {
502 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
503 return 0;
504 }
505
506 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->timespent->write))
507 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->timespent->timespent_advance->validate))))
508 {
509 $this->error='NotEnoughPermissions';
510 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
511 return -1;
512 }*/
513
514 $now = dol_now();
515
516 $this->db->begin();
517
518 // Define new ref
519 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
520 $num = $this->getNextNumRef();
521 } else {
522 $num = (string) $this->ref;
523 }
524 $this->newref = $num;
525
526 if (!empty($num)) {
527 // Validate
528 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
529 $sql .= " SET ref = '".$this->db->escape($num)."',";
530 $sql .= " status = ".self::STATUS_VALIDATED;
531 if (!empty($this->fields['date_validation'])) {
532 $sql .= ", date_validation = '".$this->db->idate($now)."'";
533 }
534 if (!empty($this->fields['fk_user_valid'])) {
535 $sql .= ", fk_user_valid = ".((int) $user->id);
536 }
537 $sql .= " WHERE rowid = ".((int) $this->id);
538
539 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
540 $resql = $this->db->query($sql);
541 if (!$resql) {
542 dol_print_error($this->db);
543 $this->error = $this->db->lasterror();
544 $error++;
545 }
546
547 if (!$error && !$notrigger) {
548 // Call trigger
549 $result = $this->call_trigger('timespent_VALIDATE', $user);
550 if ($result < 0) {
551 $error++;
552 }
553 // End call triggers
554 }
555 }
556
557 if (!$error) {
558 $this->oldref = (string) $this->ref;
559
560 // Rename directory if dir was a temporary ref
561 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
562 // Now we rename also files into index
563 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'timespent/".$this->db->escape($this->newref)."'";
564 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'timespent/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
565 $resql = $this->db->query($sql);
566 if (!$resql) {
567 $error++;
568 $this->error = $this->db->lasterror();
569 }
570 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'timespent/".$this->db->escape($this->newref)."'";
571 $sql .= " WHERE filepath = 'timespent/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
572 $resql = $this->db->query($sql);
573 if (!$resql) {
574 $error++;
575 $this->error = $this->db->lasterror();
576 }
577
578 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
579 $oldref = dol_sanitizeFileName($this->ref);
580 $newref = dol_sanitizeFileName($num);
581 $dirsource = $conf->timespent->dir_output.'/timespent/'.$oldref;
582 $dirdest = $conf->timespent->dir_output.'/timespent/'.$newref;
583 if (!$error && file_exists($dirsource)) {
584 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
585
586 if (@rename($dirsource, $dirdest)) {
587 dol_syslog("Rename ok");
588 // Rename docs starting with $oldref with $newref
589 $listoffiles = dol_dir_list($conf->timespent->dir_output.'/timespent/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
590 foreach ($listoffiles as $fileentry) {
591 $dirsource = $fileentry['name'];
592 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
593 $dirsource = $fileentry['path'].'/'.$dirsource;
594 $dirdest = $fileentry['path'].'/'.$dirdest;
595 @rename($dirsource, $dirdest);
596 }
597 }
598 }
599 }
600 }
601
602 // Set new ref and current status
603 if (!$error) {
604 $this->ref = $num;
605 $this->status = self::STATUS_VALIDATED;
606 }
607
608 if (!$error) {
609 $this->db->commit();
610 return 1;
611 } else {
612 $this->db->rollback();
613 return -1;
614 }
615 }
616
617
625 public function setDraft($user, $notrigger = 0)
626 {
627 // Protection
628 if ($this->status <= self::STATUS_DRAFT) {
629 return 0;
630 }
631
632 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->write))
633 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->timespent_advance->validate))))
634 {
635 $this->error='Permission denied';
636 return -1;
637 }*/
638
639 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'timespent_UNVALIDATE');
640 }
641
649 public function cancel($user, $notrigger = 0)
650 {
651 // Protection
652 if ($this->status != self::STATUS_VALIDATED) {
653 return 0;
654 }
655
656 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->write))
657 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->timespent_advance->validate))))
658 {
659 $this->error='Permission denied';
660 return -1;
661 }*/
662
663 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'timespent_CANCEL');
664 }
665
673 public function reopen($user, $notrigger = 0)
674 {
675 // Protection
676 if ($this->status == self::STATUS_VALIDATED) {
677 return 0;
678 }
679
680 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->write))
681 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->timespent_advance->validate))))
682 {
683 $this->error='Permission denied';
684 return -1;
685 }*/
686
687 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'timespent_REOPEN');
688 }
689
696 public function getTooltipContentArray($params)
697 {
698 global $conf, $langs, $user;
699
700 $datas = [];
701
702 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
703 return ['optimize' => $langs->trans("ShowTimeSpent")];
704 }
705 $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans("TimeSpent").'</u>';
706 if (isset($this->status)) {
707 $datas['picto'] .= ' '.$this->getLibStatut(5);
708 }
709 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
710
711 return $datas;
712 }
713
724 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
725 {
726 global $conf, $langs, $hookmanager;
727
728 if (!empty($conf->dol_no_mouse_hover)) {
729 $notooltip = 1; // Force disable tooltips
730 }
731
732 $result = '';
733 $params = [
734 'id' => $this->id,
735 'objecttype' => $this->element,
736 'option' => $option,
737 ];
738 $classfortooltip = 'classfortooltip';
739 $dataparams = '';
740 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
741 $classfortooltip = 'classforajaxtooltip';
742 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
743 $label = '';
744 } else {
745 $label = implode($this->getTooltipContentArray($params));
746 }
747
748 $url = dol_buildpath('/timespent/timespent_card.php', 1).'?id='.$this->id;
749
750 if ($option != 'nolink') {
751 // Add param to save lastsearch_values or not
752 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
753 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
754 $add_save_lastsearch_values = 1;
755 }
756 if ($url && $add_save_lastsearch_values) {
757 $url .= '&save_lastsearch_values=1';
758 }
759 }
760
761 $linkclose = '';
762 if (empty($notooltip)) {
763 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
764 $label = $langs->trans("ShowTimeSpent");
765 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
766 }
767 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
768 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
769 } else {
770 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
771 }
772
773 if ($option == 'nolink' || empty($url)) {
774 $linkstart = '<span';
775 } else {
776 $linkstart = '<a href="'.$url.'"';
777 }
778 $linkstart .= $linkclose.'>';
779 if ($option == 'nolink' || empty($url)) {
780 $linkend = '</span>';
781 } else {
782 $linkend = '</a>';
783 }
784
785 $result .= $linkstart;
786
787 if (empty($this->showphoto_on_popup)) {
788 if ($withpicto) {
789 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : $dataparams.' class="'.(($withpicto != 2) ? 'paddingright ' : '').$classfortooltip.'"'), 0, 0, $notooltip ? 0 : 1);
790 }
791 } else {
792 if ($withpicto) {
793 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
794
795 list($class, $module) = explode('@', $this->picto);
796 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
797 $filearray = dol_dir_list($upload_dir, "files");
798 $filename = $filearray[0]['name'];
799 if (!empty($filename)) {
800 $pospoint = strpos($filearray[0]['name'], '.');
801
802 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
803 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
804 $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>';
805 } else {
806 $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>';
807 }
808
809 $result .= '</div>';
810 } else {
811 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
812 }
813 }
814 }
815
816 if ($withpicto != 2) {
817 $result .= $this->ref;
818 }
819
820 $result .= $linkend;
821 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
822
823 global $action, $hookmanager;
824 $hookmanager->initHooks(array($this->element.'dao'));
825 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
826 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
827 if ($reshook > 0) {
828 $result = $hookmanager->resPrint;
829 } else {
830 $result .= $hookmanager->resPrint;
831 }
832
833 return $result;
834 }
835
843 public function getKanbanView($option = '', $arraydata = null)
844 {
845 global $conf, $langs;
846
847 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
848
849 $return = '<div class="box-flex-item box-flex-grow-zero">';
850 $return .= '<div class="info-box info-box-sm">';
851 $return .= '<span class="info-box-icon bg-infobox-action">';
852 $return .= img_picto('', $this->picto);
853 $return .= '</span>';
854 $return .= '<div class="info-box-content">';
855 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
856 if ($selected >= 0) {
857 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
858 }
859 if (property_exists($this, 'label')) {
860 $return .= ' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.'</div>';
861 }
862 if (property_exists($this, 'amount')) {
863 $return .= '<br>';
864 // @phan-suppress-next-line PhanUndeclaredProperty
865 $return .= '<span class="info-box-label amount">'.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency).'</span>';
866 }
867 if (method_exists($this, 'getLibStatut')) {
868 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(5).'</div>';
869 }
870 $return .= '</div>';
871 $return .= '</div>';
872 $return .= '</div>';
873
874 return $return;
875 }
876
883 public function getLabelStatus($mode = 0)
884 {
885 return $this->LibStatut($this->status, $mode);
886 }
887
894 public function getLibStatut($mode = 0)
895 {
896 return $this->LibStatut($this->status, $mode);
897 }
898
899 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
907 public function LibStatut($status, $mode = 0)
908 {
909 // phpcs:enable
910 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
911 global $langs;
912 //$langs->load("timespent@timespent");
913 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
914 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
915 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
916 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
917 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
918 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
919 }
920
921 $statusType = 'status'.$status;
922 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
923 if ($status == self::STATUS_CANCELED) {
924 $statusType = 'status6';
925 }
926
927 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
928 }
929
936 public function info($id)
937 {
938 $sql = "SELECT rowid,";
939 $sql .= " date_creation as datec, tms as datem,";
940 $sql .= " fk_user_creat, fk_user_modif";
941 $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
942 $sql .= " WHERE t.rowid = ".((int) $id);
943
944 $result = $this->db->query($sql);
945 if ($result) {
946 if ($this->db->num_rows($result)) {
947 $obj = $this->db->fetch_object($result);
948
949 $this->id = $obj->rowid;
950
951 $this->user_creation_id = $obj->fk_user_creat;
952 $this->user_modification_id = $obj->fk_user_modif;
953 $this->date_creation = $this->db->jdate($obj->datec);
954 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
955 }
956
957 $this->db->free($result);
958 } else {
959 dol_print_error($this->db);
960 }
961 }
962
969 public function initAsSpecimen()
970 {
971 // Set here init that are not common fields
972 // $this->property1 = ...
973 // $this->property2 = ...
974
975 return $this->initAsSpecimenCommon();
976 }
977
983 public function getNextNumRef()
984 {
985 global $langs, $conf;
986 $langs->load("timespent@timespent");
987
988 if (!getDolGlobalString('TIMESPENT_timespent_ADDON')) {
989 $conf->global->TIMESPENT_timespent_ADDON = 'mod_timespent_standard';
990 }
991
992 if (getDolGlobalString('TIMESPENT_timespent_ADDON')) {
993 $mybool = false;
994
995 $file = getDolGlobalString('TIMESPENT_timespent_ADDON') . ".php";
996 $classname = getDolGlobalString('TIMESPENT_timespent_ADDON');
997
998 // Include file with class
999 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1000 foreach ($dirmodels as $reldir) {
1001 $dir = dol_buildpath($reldir."core/modules/timespent/");
1002
1003 // Load file with numbering class (if found)
1004 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1005 }
1006
1007 if (!$mybool) {
1008 dol_print_error(null, "Failed to include file ".$file);
1009 return '';
1010 }
1011
1012 if (class_exists($classname)) {
1013 $obj = new $classname();
1014 '@phan-var-force CommonNumRefGenerator $obj';
1015 $numref = $obj->getNextValue($this);
1016
1017 if ($numref != '' && $numref != '-1') {
1018 return $numref;
1019 } else {
1020 $this->error = $obj->error;
1021 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1022 return "";
1023 }
1024 } else {
1025 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
1026 return "";
1027 }
1028 } else {
1029 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1030 return "";
1031 }
1032 }
1033
1045 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1046 {
1047 global $conf, $langs;
1048
1049 $result = 0;
1050 $includedocgeneration = 0;
1051
1052 $langs->load("timespent@timespent");
1053
1054 if (!dol_strlen($modele)) {
1055 $modele = 'standard_timespent';
1056
1057 if (!empty($this->model_pdf)) {
1058 $modele = $this->model_pdf;
1059 } elseif (getDolGlobalString('timespent_ADDON_PDF')) {
1060 $modele = getDolGlobalString('timespent_ADDON_PDF');
1061 }
1062 }
1063
1064 $modelpath = "core/modules/timespent/doc/";
1065
1066 if ($includedocgeneration && !empty($modele)) {
1067 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1068 }
1069
1070 return $result;
1071 }
1072}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$object ref
Definition info.php:90
Parent class of all other business classes (invoices, contracts, proposals, orders,...
deleteLineCommon(User $user, $idline, $notrigger=0)
Delete a line of object in database.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
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.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
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 for TimeSpent.
validate($user, $notrigger=0)
Validate object.
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.
setDraft($user, $notrigger=0)
Set draft status.
getTooltipContentArray($params)
getTooltipContentArray
cancel($user, $notrigger=0)
Set cancel status.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
deleteLine(User $user, $idline, $notrigger=0)
Delete a line of object in database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
getLabelStatus($mode=0)
Return the label of the status.
__construct(DoliDB $db)
Constructor.
getLibStatut($mode=0)
Return the label of the status.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
reopen($user, $notrigger=0)
Set back to validated status.
createFromClone(User $user, $fromid)
Clone an object into another one.
info($id)
Load the info information in the object.
LibStatut($status, $mode=0)
Return the status.
update(User $user, $notrigger=0)
Update object into database.
create(User $user, $notrigger=0)
Create object into database.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
getKanbanView($option='', $arraydata=null)
Return a thumb for kanban views.
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:171
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:64
dol_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(getDolGlobalString( 'TAKEPOS_SHOW_CUSTOMER')) print $langs trans('Date')." left Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right PaymentTypeShortLIQ right SELECT p pos_change as p datep as p p num_paiement as f pf amount as amount
Definition receipt.php:466