dolibarr 22.0.5
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-2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.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 = 'timespent';
41
45 public $element = 'timespent';
46
50 public $table_element = 'element_time';
51
55 public $picto = 'fa-file';
56
57
58 const STATUS_DRAFT = 0;
59 const STATUS_VALIDATED = 1;
60 const STATUS_CANCELED = 9;
61
62
102 // BEGIN MODULEBUILDER PROPERTIES
106 public $fields = array(
107 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'css' => 'left', 'comment' => "Id"),
108 'ref_ext' => array('type' => 'varchar(255)', 'label' => 'RefExt', 'enabled' => 1, 'visible' => 0, 'position' => 20),
109 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 17, 'notnull' => 0, 'visible' => -2,),
110 'import_key' => array('type' => 'varchar(14)', 'label' => 'import_key', 'enabled' => 1, 'position' => 15, 'notnull' => 0, 'visible' => -1,),
111 'fk_element' => array('type' => 'integer', 'label' => 'fk_element', 'enabled' => 1, 'position' => 2, 'notnull' => 1, 'visible' => -1,),
112 'elementtype' => array('type' => 'varchar(32)', 'label' => 'elementtype', 'enabled' => 1, 'position' => 3, 'notnull' => 1, 'visible' => -1,),
113 'element_date' => array('type' => 'date', 'label' => 'element_date', 'enabled' => 1, 'position' => 4, 'notnull' => 0, 'visible' => -1,),
114 'element_datehour' => array('type' => 'datetime', 'label' => 'element_datehour', 'enabled' => 1, 'position' => 5, 'notnull' => 0, 'visible' => -1,),
115 'element_date_withhour' => array('type' => 'integer', 'label' => 'element_date_withhour', 'enabled' => 1, 'position' => 6, 'notnull' => 0, 'visible' => -1,),
116 'element_duration' => array('type' => 'double', 'label' => 'element_duration', 'enabled' => 1, 'position' => 7, 'notnull' => 0, 'visible' => -1,),
117 'fk_product' => array('type' => 'integer', 'label' => 'fk_product', 'enabled' => 1, 'position' => 8, 'notnull' => 0, 'visible' => -1,),
118 'fk_user' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'fk_user', 'enabled' => 1, 'position' => 9, 'notnull' => 0, 'visible' => -1,),
119 'thm' => array('type' => 'double(24,8)', 'label' => 'thm', 'enabled' => 1, 'position' => 10, 'notnull' => 0, 'visible' => -1,),
120 'invoice_id' => array('type' => 'integer', 'label' => 'invoice_id', 'enabled' => 1, 'position' => 11, 'notnull' => 0, 'visible' => -1, 'default' => 'NULL',),
121 'invoice_line_id' => array('type' => 'integer', 'label' => 'invoice_line_id', 'enabled' => 1, 'position' => 12, 'notnull' => 0, 'visible' => -1, 'default' => 'NULL',),
122 'intervention_id' => array('type' => 'integer', 'label' => 'intervention_id', 'enabled' => 1, 'position' => 13, 'notnull' => 0, 'visible' => -1, 'default' => 'NULL',),
123 'intervention_line_id' => array('type' => 'integer', 'label' => 'intervention_line_id', 'enabled' => 1, 'position' => 14, 'notnull' => 0, 'visible' => -1, 'default' => 'NULL',),
124 'datec' => array('type' => 'datetime', 'label' => 'datec', 'enabled' => 1, 'position' => 16, 'notnull' => 0, 'visible' => -1,),
125 'note' => array('type' => 'text', 'label' => 'note', 'enabled' => 1, 'position' => 18, 'notnull' => 0, 'visible' => -1,),
126 );
127
131 public $rowid;
132
136 public $import_key;
137
141 public $fk_element;
142
146 public $elementtype;
147
151 public $element_date;
152
156 public $element_datehour;
157
161 public $element_date_withhour;
162
166 public $element_duration;
167
171 public $fk_product;
172
176 public $fk_user;
177
181 public $thm;
182
186 public $invoice_id;
187
191 public $invoice_line_id;
192
196 public $intervention_id;
197
201 public $intervention_line_id;
202
206 public $datec;
207
211 public $note;
212 // END MODULEBUILDER PROPERTIES
213
219 public function __construct(DoliDB $db)
220 {
221 global $langs;
222
223 $this->db = $db;
224
225 $this->ismultientitymanaged = 0;
226 $this->isextrafieldmanaged = 0;
227
228 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid']) && !empty($this->fields['ref'])) { // @phan-suppress-current-line PhanTypeMismatchProperty
229 $this->fields['rowid']['visible'] = 0;
230 }
231 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
232 $this->fields['entity']['enabled'] = 0;
233 }
234
235 // Example to show how to set values of fields definition dynamically
236 /*if ($user->rights->timespent->timespent->read) {
237 $this->fields['myfield']['visible'] = 1;
238 $this->fields['myfield']['noteditable'] = 0;
239 }*/
240
241 // Unset fields that are disabled
242 foreach ($this->fields as $key => $val) {
243 if (isset($val['enabled']) && empty($val['enabled'])) {
244 unset($this->fields[$key]);
245 }
246 }
247
248 // Translate some data of arrayofkeyval
249 if (is_object($langs)) {
250 foreach ($this->fields as $key => $val) {
251 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
252 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
253 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
254 }
255 }
256 }
257 }
258 }
259
267 public function create(User $user, $notrigger = 0)
268 {
269 $resultcreate = $this->createCommon($user, $notrigger);
270
271 //$resultvalidate = $this->validate($user, $notrigger);
272
273 return $resultcreate;
274 }
275
283 public function createFromClone(User $user, $fromid)
284 {
285 global $extrafields;
286
287 $error = 0;
288
289 dol_syslog(__METHOD__, LOG_DEBUG);
290
291 $object = new self($this->db);
292
293 $this->db->begin();
294
295 // Load source object
296 $result = $object->fetchCommon($fromid);
297
298 // Reset some properties
299 unset($object->id);
300 unset($object->fk_user_creat);
301 unset($object->user_creation_id);
302 unset($object->import_key);
303
304 // Clear fields
305 if (property_exists($object, 'ref')) {
306 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
307 }
308 if (property_exists($object, 'status')) {
309 $object->status = self::STATUS_DRAFT;
310 }
311 if (property_exists($object, 'date_creation')) {
312 $object->date_creation = dol_now();
313 }
314 if (property_exists($object, 'date_modification')) {
315 $object->date_modification = null;
316 }
317 // ...
318 // Clear extrafields that are unique
319 if (is_array($object->array_options) && count($object->array_options) > 0) {
320 $extrafields->fetch_name_optionals_label($this->table_element);
321 foreach ($object->array_options as $key => $option) {
322 $shortkey = preg_replace('/options_/', '', $key);
323 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
324 //var_dump($key);
325 //var_dump($clonedObj->array_options[$key]); exit;
326 unset($object->array_options[$key]);
327 }
328 }
329 }
330
331 // Create clone
332 $object->context['createfromclone'] = 'createfromclone';
333 $result = $object->createCommon($user);
334 if ($result < 0) {
335 $error++;
336 $this->error = $object->error;
337 $this->errors = $object->errors;
338 }
339
340 if (!$error) {
341 // copy internal contacts
342 if ($this->copy_linked_contact($object, 'internal') < 0) {
343 $error++;
344 }
345 }
346
347 if (!$error) {
348 // copy external contacts if same company @phan-suppress-next-line PHanUndeclaredProperty
349 if (!empty($object->socid) && property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
350 if ($this->copy_linked_contact($object, 'external') < 0) {
351 $error++;
352 }
353 }
354 }
355
356 unset($object->context['createfromclone']);
357
358 // End
359 if (!$error) {
360 $this->db->commit();
361 return $object;
362 } else {
363 $this->db->rollback();
364 return -1;
365 }
366 }
367
375 public function fetch($id, $ref = null)
376 {
377 $result = $this->fetchCommon($id, $ref);
378
379 return $result;
380 }
381
394 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
395 {
396 global $conf;
397
398 dol_syslog(__METHOD__, LOG_DEBUG);
399
400 $records = array();
401
402 $sql = "SELECT ";
403 $sql .= $this->getFieldList('t');
404 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
405 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
406 $sql .= " WHERE t.entity IN (".getEntity($this->element).")";
407 } else {
408 $sql .= " WHERE 1 = 1";
409 }
410
411 // Manage filter
412 $errormessage = '';
413 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
414 if ($errormessage) {
415 $this->errors[] = $errormessage;
416 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
417 return -1;
418 }
419
420 if (!empty($sortfield)) {
421 $sql .= $this->db->order($sortfield, $sortorder);
422 }
423 if (!empty($limit)) {
424 $sql .= $this->db->plimit($limit, $offset);
425 }
426
427 $resql = $this->db->query($sql);
428 if ($resql) {
429 $num = $this->db->num_rows($resql);
430 $i = 0;
431 while ($i < ($limit ? min($limit, $num) : $num)) {
432 $obj = $this->db->fetch_object($resql);
433
434 $record = new self($this->db);
435 $record->setVarsFromFetchObj($obj);
436
437 $records[$record->id] = $record;
438
439 $i++;
440 }
441 $this->db->free($resql);
442
443 return $records;
444 } else {
445 $this->errors[] = 'Error '.$this->db->lasterror();
446 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
447
448 return -1;
449 }
450 }
451
459 public function update(User $user, $notrigger = 0)
460 {
461 return $this->updateCommon($user, $notrigger);
462 }
463
471 public function delete(User $user, $notrigger = 0)
472 {
473 return $this->deleteCommon($user, $notrigger);
474 //return $this->deleteCommon($user, $notrigger, 1);
475 }
476
485 public function deleteLine(User $user, $idline, $notrigger = 0)
486 {
487 if ($this->status < 0) {
488 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
489 return -2;
490 }
491
492 return $this->deleteLineCommon($user, $idline, $notrigger);
493 }
494
495
503 public function validate($user, $notrigger = 0)
504 {
505 global $conf, $langs;
506
507 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
508
509 $error = 0;
510
511 // Protection
512 if ($this->status == self::STATUS_VALIDATED) {
513 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
514 return 0;
515 }
516
517 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->timespent->write))
518 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->timespent->timespent_advance->validate))))
519 {
520 $this->error='NotEnoughPermissions';
521 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
522 return -1;
523 }*/
524
525 $now = dol_now();
526
527 $this->db->begin();
528
529 // Define new ref
530 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
531 $num = $this->getNextNumRef();
532 } else {
533 $num = $this->ref;
534 }
535 $this->newref = $num;
536
537 if (!empty($num)) {
538 // Validate
539 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
540 $sql .= " SET ref = '".$this->db->escape($num)."',";
541 $sql .= " status = ".self::STATUS_VALIDATED;
542 if (!empty($this->fields['date_validation'])) {
543 $sql .= ", date_validation = '".$this->db->idate($now)."'";
544 }
545 if (!empty($this->fields['fk_user_valid'])) {
546 $sql .= ", fk_user_valid = ".((int) $user->id);
547 }
548 $sql .= " WHERE rowid = ".((int) $this->id);
549
550 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
551 $resql = $this->db->query($sql);
552 if (!$resql) {
553 dol_print_error($this->db);
554 $this->error = $this->db->lasterror();
555 $error++;
556 }
557
558 if (!$error && !$notrigger) {
559 // Call trigger
560 $result = $this->call_trigger('timespent_VALIDATE', $user);
561 if ($result < 0) {
562 $error++;
563 }
564 // End call triggers
565 }
566 }
567
568 if (!$error) {
569 $this->oldref = $this->ref;
570
571 // Rename directory if dir was a temporary ref
572 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
573 // Now we rename also files into index
574 $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)."'";
575 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'timespent/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
576 $resql = $this->db->query($sql);
577 if (!$resql) {
578 $error++;
579 $this->error = $this->db->lasterror();
580 }
581 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'timespent/".$this->db->escape($this->newref)."'";
582 $sql .= " WHERE filepath = 'timespent/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
583 $resql = $this->db->query($sql);
584 if (!$resql) {
585 $error++;
586 $this->error = $this->db->lasterror();
587 }
588
589 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
590 $oldref = dol_sanitizeFileName($this->ref);
591 $newref = dol_sanitizeFileName($num);
592 $dirsource = $conf->timespent->dir_output.'/timespent/'.$oldref;
593 $dirdest = $conf->timespent->dir_output.'/timespent/'.$newref;
594 if (!$error && file_exists($dirsource)) {
595 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
596
597 if (@rename($dirsource, $dirdest)) {
598 dol_syslog("Rename ok");
599 // Rename docs starting with $oldref with $newref
600 $listoffiles = dol_dir_list($conf->timespent->dir_output.'/timespent/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
601 foreach ($listoffiles as $fileentry) {
602 $dirsource = $fileentry['name'];
603 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
604 $dirsource = $fileentry['path'].'/'.$dirsource;
605 $dirdest = $fileentry['path'].'/'.$dirdest;
606 @rename($dirsource, $dirdest);
607 }
608 }
609 }
610 }
611 }
612
613 // Set new ref and current status
614 if (!$error) {
615 $this->ref = $num;
616 $this->status = self::STATUS_VALIDATED;
617 }
618
619 if (!$error) {
620 $this->db->commit();
621 return 1;
622 } else {
623 $this->db->rollback();
624 return -1;
625 }
626 }
627
628
636 public function setDraft($user, $notrigger = 0)
637 {
638 // Protection
639 if ($this->status <= self::STATUS_DRAFT) {
640 return 0;
641 }
642
643 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->write))
644 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->timespent_advance->validate))))
645 {
646 $this->error='Permission denied';
647 return -1;
648 }*/
649
650 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'timespent_UNVALIDATE');
651 }
652
660 public function cancel($user, $notrigger = 0)
661 {
662 // Protection
663 if ($this->status != self::STATUS_VALIDATED) {
664 return 0;
665 }
666
667 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->write))
668 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->timespent_advance->validate))))
669 {
670 $this->error='Permission denied';
671 return -1;
672 }*/
673
674 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'timespent_CANCEL');
675 }
676
684 public function reopen($user, $notrigger = 0)
685 {
686 // Protection
687 if ($this->status == self::STATUS_VALIDATED) {
688 return 0;
689 }
690
691 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->write))
692 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->timespent_advance->validate))))
693 {
694 $this->error='Permission denied';
695 return -1;
696 }*/
697
698 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'timespent_REOPEN');
699 }
700
707 public function getTooltipContentArray($params)
708 {
709 global $conf, $langs, $user;
710
711 $datas = [];
712
713 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
714 return ['optimize' => $langs->trans("ShowTimeSpent")];
715 }
716 $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans("TimeSpent").'</u>';
717 if (isset($this->status)) {
718 $datas['picto'] .= ' '.$this->getLibStatut(5);
719 }
720 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
721
722 return $datas;
723 }
724
735 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
736 {
737 global $conf, $langs, $hookmanager;
738
739 if (!empty($conf->dol_no_mouse_hover)) {
740 $notooltip = 1; // Force disable tooltips
741 }
742
743 $result = '';
744 $params = [
745 'id' => $this->id,
746 'objecttype' => $this->element,
747 'option' => $option,
748 ];
749 $classfortooltip = 'classfortooltip';
750 $dataparams = '';
751 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
752 $classfortooltip = 'classforajaxtooltip';
753 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
754 $label = '';
755 } else {
756 $label = implode($this->getTooltipContentArray($params));
757 }
758
759 $url = dol_buildpath('/timespent/timespent_card.php', 1).'?id='.$this->id;
760
761 if ($option != 'nolink') {
762 // Add param to save lastsearch_values or not
763 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
764 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
765 $add_save_lastsearch_values = 1;
766 }
767 if ($url && $add_save_lastsearch_values) {
768 $url .= '&save_lastsearch_values=1';
769 }
770 }
771
772 $linkclose = '';
773 if (empty($notooltip)) {
774 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
775 $label = $langs->trans("ShowTimeSpent");
776 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
777 }
778 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
779 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
780 } else {
781 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
782 }
783
784 if ($option == 'nolink' || empty($url)) {
785 $linkstart = '<span';
786 } else {
787 $linkstart = '<a href="'.$url.'"';
788 }
789 $linkstart .= $linkclose.'>';
790 if ($option == 'nolink' || empty($url)) {
791 $linkend = '</span>';
792 } else {
793 $linkend = '</a>';
794 }
795
796 $result .= $linkstart;
797
798 if (empty($this->showphoto_on_popup)) {
799 if ($withpicto) {
800 $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);
801 }
802 } else {
803 if ($withpicto) {
804 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
805
806 list($class, $module) = explode('@', $this->picto);
807 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
808 $filearray = dol_dir_list($upload_dir, "files");
809 $filename = $filearray[0]['name'];
810 if (!empty($filename)) {
811 $pospoint = strpos($filearray[0]['name'], '.');
812
813 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
814 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
815 $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>';
816 } else {
817 $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>';
818 }
819
820 $result .= '</div>';
821 } else {
822 $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);
823 }
824 }
825 }
826
827 if ($withpicto != 2) {
828 $result .= $this->ref;
829 }
830
831 $result .= $linkend;
832 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
833
834 global $action, $hookmanager;
835 $hookmanager->initHooks(array($this->element.'dao'));
836 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
837 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
838 if ($reshook > 0) {
839 $result = $hookmanager->resPrint;
840 } else {
841 $result .= $hookmanager->resPrint;
842 }
843
844 return $result;
845 }
846
854 public function getKanbanView($option = '', $arraydata = null)
855 {
856 global $conf, $langs;
857
858 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
859
860 $return = '<div class="box-flex-item box-flex-grow-zero">';
861 $return .= '<div class="info-box info-box-sm">';
862 $return .= '<span class="info-box-icon bg-infobox-action">';
863 $return .= img_picto('', $this->picto);
864 $return .= '</span>';
865 $return .= '<div class="info-box-content">';
866 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
867 if ($selected >= 0) {
868 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
869 }
870 if (property_exists($this, 'label')) {
871 $return .= ' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.'</div>';
872 }
873 if (property_exists($this, 'amount')) {
874 $return .= '<br>';
875 // @phan-suppress-next-line PhanUndeclaredProperty
876 $return .= '<span class="info-box-label amount">'.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency).'</span>';
877 }
878 if (method_exists($this, 'getLibStatut')) {
879 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(5).'</div>';
880 }
881 $return .= '</div>';
882 $return .= '</div>';
883 $return .= '</div>';
884
885 return $return;
886 }
887
894 public function getLabelStatus($mode = 0)
895 {
896 return $this->LibStatut($this->status, $mode);
897 }
898
905 public function getLibStatut($mode = 0)
906 {
907 return $this->LibStatut($this->status, $mode);
908 }
909
910 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
918 public function LibStatut($status, $mode = 0)
919 {
920 // phpcs:enable
921 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
922 global $langs;
923 //$langs->load("timespent@timespent");
924 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
925 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
926 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
927 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
928 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
929 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
930 }
931
932 $statusType = 'status'.$status;
933 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
934 if ($status == self::STATUS_CANCELED) {
935 $statusType = 'status6';
936 }
937
938 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
939 }
940
947 public function info($id)
948 {
949 $sql = "SELECT rowid,";
950 $sql .= " date_creation as datec, tms as datem,";
951 $sql .= " fk_user_creat, fk_user_modif";
952 $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
953 $sql .= " WHERE t.rowid = ".((int) $id);
954
955 $result = $this->db->query($sql);
956 if ($result) {
957 if ($this->db->num_rows($result)) {
958 $obj = $this->db->fetch_object($result);
959
960 $this->id = $obj->rowid;
961
962 $this->user_creation_id = $obj->fk_user_creat;
963 $this->user_modification_id = $obj->fk_user_modif;
964 $this->date_creation = $this->db->jdate($obj->datec);
965 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
966 }
967
968 $this->db->free($result);
969 } else {
970 dol_print_error($this->db);
971 }
972 }
973
980 public function initAsSpecimen()
981 {
982 // Set here init that are not common fields
983 // $this->property1 = ...
984 // $this->property2 = ...
985
986 return $this->initAsSpecimenCommon();
987 }
988
994 public function getNextNumRef()
995 {
996 global $langs, $conf;
997 $langs->load("timespent@timespent");
998
999 if (!getDolGlobalString('TIMESPENT_timespent_ADDON')) {
1000 $conf->global->TIMESPENT_timespent_ADDON = 'mod_timespent_standard';
1001 }
1002
1003 if (getDolGlobalString('TIMESPENT_timespent_ADDON')) {
1004 $mybool = false;
1005
1006 $file = getDolGlobalString('TIMESPENT_timespent_ADDON') . ".php";
1007 $classname = getDolGlobalString('TIMESPENT_timespent_ADDON');
1008
1009 // Include file with class
1010 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1011 foreach ($dirmodels as $reldir) {
1012 $dir = dol_buildpath($reldir."core/modules/timespent/");
1013
1014 // Load file with numbering class (if found)
1015 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1016 }
1017
1018 if (!$mybool) {
1019 dol_print_error(null, "Failed to include file ".$file);
1020 return '';
1021 }
1022
1023 if (class_exists($classname)) {
1024 $obj = new $classname();
1025 '@phan-var-force CommonNumRefGenerator $obj';
1026 $numref = $obj->getNextValue($this);
1027
1028 if ($numref != '' && $numref != '-1') {
1029 return $numref;
1030 } else {
1031 $this->error = $obj->error;
1032 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1033 return "";
1034 }
1035 } else {
1036 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
1037 return "";
1038 }
1039 } else {
1040 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1041 return "";
1042 }
1043 }
1044
1056 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1057 {
1058 global $conf, $langs;
1059
1060 $result = 0;
1061 $includedocgeneration = 0;
1062
1063 $langs->load("timespent@timespent");
1064
1065 if (!dol_strlen($modele)) {
1066 $modele = 'standard_timespent';
1067
1068 if (!empty($this->model_pdf)) {
1069 $modele = $this->model_pdf;
1070 } elseif (getDolGlobalString('timespent_ADDON_PDF')) {
1071 $modele = getDolGlobalString('timespent_ADDON_PDF');
1072 }
1073 }
1074
1075 $modelpath = "core/modules/timespent/doc/";
1076
1077 if ($includedocgeneration && !empty($modele)) {
1078 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1079 }
1080
1081 return $result;
1082 }
1083}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
$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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
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:63
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_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
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...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79