dolibarr 21.0.0-beta
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 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 17, 'notnull' => 0, 'visible' => -2,),
109 'import_key' => array('type' => 'varchar(14)', 'label' => 'import_key', 'enabled' => 1, 'position' => 15, 'notnull' => 0, 'visible' => -1,),
110 'fk_element' => array('type' => 'integer', 'label' => 'fk_element', 'enabled' => 1, 'position' => 2, 'notnull' => 1, 'visible' => -1,),
111 'elementtype' => array('type' => 'varchar(32)', 'label' => 'elementtype', 'enabled' => 1, 'position' => 3, 'notnull' => 1, 'visible' => -1,),
112 'element_date' => array('type' => 'date', 'label' => 'element_date', 'enabled' => 1, 'position' => 4, 'notnull' => 0, 'visible' => -1,),
113 'element_datehour' => array('type' => 'datetime', 'label' => 'element_datehour', 'enabled' => 1, 'position' => 5, 'notnull' => 0, 'visible' => -1,),
114 'element_date_withhour' => array('type' => 'integer', 'label' => 'element_date_withhour', 'enabled' => 1, 'position' => 6, 'notnull' => 0, 'visible' => -1,),
115 'element_duration' => array('type' => 'double', 'label' => 'element_duration', 'enabled' => 1, 'position' => 7, 'notnull' => 0, 'visible' => -1,),
116 'fk_product' => array('type' => 'integer', 'label' => 'fk_product', 'enabled' => 1, 'position' => 8, 'notnull' => 0, 'visible' => -1,),
117 'fk_user' => array('type' => 'integer', 'label' => 'fk_user', 'enabled' => 1, 'position' => 9, 'notnull' => 0, 'visible' => -1,),
118 'thm' => array('type' => 'double(24,8)', 'label' => 'thm', 'enabled' => 1, 'position' => 10, 'notnull' => 0, 'visible' => -1,),
119 'invoice_id' => array('type' => 'integer', 'label' => 'invoice_id', 'enabled' => 1, 'position' => 11, 'notnull' => 0, 'visible' => -1, 'default' => 'NULL',),
120 'invoice_line_id' => array('type' => 'integer', 'label' => 'invoice_line_id', 'enabled' => 1, 'position' => 12, 'notnull' => 0, 'visible' => -1, 'default' => 'NULL',),
121 'intervention_id' => array('type' => 'integer', 'label' => 'intervention_id', 'enabled' => 1, 'position' => 13, 'notnull' => 0, 'visible' => -1, 'default' => 'NULL',),
122 'intervention_line_id' => array('type' => 'integer', 'label' => 'intervention_line_id', 'enabled' => 1, 'position' => 14, 'notnull' => 0, 'visible' => -1, 'default' => 'NULL',),
123 'datec' => array('type' => 'datetime', 'label' => 'datec', 'enabled' => 1, 'position' => 16, 'notnull' => 0, 'visible' => -1,),
124 'note' => array('type' => 'text', 'label' => 'note', 'enabled' => 1, 'position' => 18, 'notnull' => 0, 'visible' => -1,),
125 );
129 public $rowid;
133 public $import_key;
137 public $fk_element;
141 public $elementtype;
145 public $element_date;
149 public $element_datehour;
153 public $element_date_withhour;
157 public $element_duration;
161 public $fk_product;
165 public $fk_user;
169 public $thm;
173 public $invoice_id;
177 public $invoice_line_id;
181 public $intervention_id;
185 public $intervention_line_id;
189 public $datec;
193 public $note;
194 // END MODULEBUILDER PROPERTIES
195
201 public function __construct(DoliDB $db)
202 {
203 global $langs;
204
205 $this->db = $db;
206
207 $this->ismultientitymanaged = 0;
208 $this->isextrafieldmanaged = 0;
209
210 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid']) && !empty($this->fields['ref'])) { // @phan-suppress-current-line PhanTypeMismatchProperty
211 $this->fields['rowid']['visible'] = 0;
212 }
213 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
214 $this->fields['entity']['enabled'] = 0;
215 }
216
217 // Example to show how to set values of fields definition dynamically
218 /*if ($user->rights->timespent->timespent->read) {
219 $this->fields['myfield']['visible'] = 1;
220 $this->fields['myfield']['noteditable'] = 0;
221 }*/
222
223 // Unset fields that are disabled
224 foreach ($this->fields as $key => $val) {
225 if (isset($val['enabled']) && empty($val['enabled'])) {
226 unset($this->fields[$key]);
227 }
228 }
229
230 // Translate some data of arrayofkeyval
231 if (is_object($langs)) {
232 foreach ($this->fields as $key => $val) {
233 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
234 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
235 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
236 }
237 }
238 }
239 }
240 }
241
249 public function create(User $user, $notrigger = 0)
250 {
251 $resultcreate = $this->createCommon($user, $notrigger);
252
253 //$resultvalidate = $this->validate($user, $notrigger);
254
255 return $resultcreate;
256 }
257
265 public function createFromClone(User $user, $fromid)
266 {
267 global $langs, $extrafields;
268 $error = 0;
269
270 dol_syslog(__METHOD__, LOG_DEBUG);
271
272 $object = new self($this->db);
273
274 $this->db->begin();
275
276 // Load source object
277 $result = $object->fetchCommon($fromid);
278
279 // Reset some properties
280 unset($object->id);
281 unset($object->fk_user_creat);
282 unset($object->import_key);
283
284 // Clear fields
285 if (property_exists($object, 'ref')) {
286 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
287 }
288 if (property_exists($object, 'label')) {
289 // @phan-suppress-next-line PhanUndeclaredProperty
290 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
291 }
292 if (property_exists($object, 'status')) {
293 $object->status = self::STATUS_DRAFT;
294 }
295 if (property_exists($object, 'date_creation')) {
296 $object->date_creation = dol_now();
297 }
298 if (property_exists($object, 'date_modification')) {
299 $object->date_modification = null;
300 }
301 // ...
302 // Clear extrafields that are unique
303 if (is_array($object->array_options) && count($object->array_options) > 0) {
304 $extrafields->fetch_name_optionals_label($this->table_element);
305 foreach ($object->array_options as $key => $option) {
306 $shortkey = preg_replace('/options_/', '', $key);
307 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
308 //var_dump($key);
309 //var_dump($clonedObj->array_options[$key]); exit;
310 unset($object->array_options[$key]);
311 }
312 }
313 }
314
315 // Create clone
316 $object->context['createfromclone'] = 'createfromclone';
317 $result = $object->createCommon($user);
318 if ($result < 0) {
319 $error++;
320 $this->error = $object->error;
321 $this->errors = $object->errors;
322 }
323
324 if (!$error) {
325 // copy internal contacts
326 if ($this->copy_linked_contact($object, 'internal') < 0) {
327 $error++;
328 }
329 }
330
331 if (!$error) {
332 // copy external contacts if same company @phan-suppress-next-line PHanUndeclaredProperty
333 if (!empty($object->socid) && property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
334 if ($this->copy_linked_contact($object, 'external') < 0) {
335 $error++;
336 }
337 }
338 }
339
340 unset($object->context['createfromclone']);
341
342 // End
343 if (!$error) {
344 $this->db->commit();
345 return $object;
346 } else {
347 $this->db->rollback();
348 return -1;
349 }
350 }
351
359 public function fetch($id, $ref = null)
360 {
361 $result = $this->fetchCommon($id, $ref);
362
363 return $result;
364 }
365
378 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
379 {
380 global $conf;
381
382 dol_syslog(__METHOD__, LOG_DEBUG);
383
384 $records = array();
385
386 $sql = "SELECT ";
387 $sql .= $this->getFieldList('t');
388 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
389 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
390 $sql .= " WHERE t.entity IN (".getEntity($this->element).")";
391 } else {
392 $sql .= " WHERE 1 = 1";
393 }
394
395 // Manage filter
396 $errormessage = '';
397 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
398 if ($errormessage) {
399 $this->errors[] = $errormessage;
400 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
401 return -1;
402 }
403
404 if (!empty($sortfield)) {
405 $sql .= $this->db->order($sortfield, $sortorder);
406 }
407 if (!empty($limit)) {
408 $sql .= $this->db->plimit($limit, $offset);
409 }
410
411 $resql = $this->db->query($sql);
412 if ($resql) {
413 $num = $this->db->num_rows($resql);
414 $i = 0;
415 while ($i < ($limit ? min($limit, $num) : $num)) {
416 $obj = $this->db->fetch_object($resql);
417
418 $record = new self($this->db);
419 $record->setVarsFromFetchObj($obj);
420
421 $records[$record->id] = $record;
422
423 $i++;
424 }
425 $this->db->free($resql);
426
427 return $records;
428 } else {
429 $this->errors[] = 'Error '.$this->db->lasterror();
430 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
431
432 return -1;
433 }
434 }
435
443 public function update(User $user, $notrigger = 0)
444 {
445 return $this->updateCommon($user, $notrigger);
446 }
447
455 public function delete(User $user, $notrigger = 0)
456 {
457 return $this->deleteCommon($user, $notrigger);
458 //return $this->deleteCommon($user, $notrigger, 1);
459 }
460
469 public function deleteLine(User $user, $idline, $notrigger = 0)
470 {
471 if ($this->status < 0) {
472 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
473 return -2;
474 }
475
476 return $this->deleteLineCommon($user, $idline, $notrigger);
477 }
478
479
487 public function validate($user, $notrigger = 0)
488 {
489 global $conf, $langs;
490
491 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
492
493 $error = 0;
494
495 // Protection
496 if ($this->status == self::STATUS_VALIDATED) {
497 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
498 return 0;
499 }
500
501 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->timespent->write))
502 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->timespent->timespent_advance->validate))))
503 {
504 $this->error='NotEnoughPermissions';
505 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
506 return -1;
507 }*/
508
509 $now = dol_now();
510
511 $this->db->begin();
512
513 // Define new ref
514 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
515 $num = $this->getNextNumRef();
516 } else {
517 $num = $this->ref;
518 }
519 $this->newref = $num;
520
521 if (!empty($num)) {
522 // Validate
523 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
524 $sql .= " SET ref = '".$this->db->escape($num)."',";
525 $sql .= " status = ".self::STATUS_VALIDATED;
526 if (!empty($this->fields['date_validation'])) {
527 $sql .= ", date_validation = '".$this->db->idate($now)."'";
528 }
529 if (!empty($this->fields['fk_user_valid'])) {
530 $sql .= ", fk_user_valid = ".((int) $user->id);
531 }
532 $sql .= " WHERE rowid = ".((int) $this->id);
533
534 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
535 $resql = $this->db->query($sql);
536 if (!$resql) {
537 dol_print_error($this->db);
538 $this->error = $this->db->lasterror();
539 $error++;
540 }
541
542 if (!$error && !$notrigger) {
543 // Call trigger
544 $result = $this->call_trigger('timespent_VALIDATE', $user);
545 if ($result < 0) {
546 $error++;
547 }
548 // End call triggers
549 }
550 }
551
552 if (!$error) {
553 $this->oldref = $this->ref;
554
555 // Rename directory if dir was a temporary ref
556 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
557 // Now we rename also files into index
558 $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)."'";
559 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'timespent/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
560 $resql = $this->db->query($sql);
561 if (!$resql) {
562 $error++;
563 $this->error = $this->db->lasterror();
564 }
565 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'timespent/".$this->db->escape($this->newref)."'";
566 $sql .= " WHERE filepath = 'timespent/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
567 $resql = $this->db->query($sql);
568 if (!$resql) {
569 $error++;
570 $this->error = $this->db->lasterror();
571 }
572
573 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
574 $oldref = dol_sanitizeFileName($this->ref);
575 $newref = dol_sanitizeFileName($num);
576 $dirsource = $conf->timespent->dir_output.'/timespent/'.$oldref;
577 $dirdest = $conf->timespent->dir_output.'/timespent/'.$newref;
578 if (!$error && file_exists($dirsource)) {
579 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
580
581 if (@rename($dirsource, $dirdest)) {
582 dol_syslog("Rename ok");
583 // Rename docs starting with $oldref with $newref
584 $listoffiles = dol_dir_list($conf->timespent->dir_output.'/timespent/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
585 foreach ($listoffiles as $fileentry) {
586 $dirsource = $fileentry['name'];
587 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
588 $dirsource = $fileentry['path'].'/'.$dirsource;
589 $dirdest = $fileentry['path'].'/'.$dirdest;
590 @rename($dirsource, $dirdest);
591 }
592 }
593 }
594 }
595 }
596
597 // Set new ref and current status
598 if (!$error) {
599 $this->ref = $num;
600 $this->status = self::STATUS_VALIDATED;
601 }
602
603 if (!$error) {
604 $this->db->commit();
605 return 1;
606 } else {
607 $this->db->rollback();
608 return -1;
609 }
610 }
611
612
620 public function setDraft($user, $notrigger = 0)
621 {
622 // Protection
623 if ($this->status <= self::STATUS_DRAFT) {
624 return 0;
625 }
626
627 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->write))
628 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->timespent_advance->validate))))
629 {
630 $this->error='Permission denied';
631 return -1;
632 }*/
633
634 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'timespent_UNVALIDATE');
635 }
636
644 public function cancel($user, $notrigger = 0)
645 {
646 // Protection
647 if ($this->status != self::STATUS_VALIDATED) {
648 return 0;
649 }
650
651 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->write))
652 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->timespent_advance->validate))))
653 {
654 $this->error='Permission denied';
655 return -1;
656 }*/
657
658 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'timespent_CANCEL');
659 }
660
668 public function reopen($user, $notrigger = 0)
669 {
670 // Protection
671 if ($this->status == self::STATUS_VALIDATED) {
672 return 0;
673 }
674
675 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->write))
676 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->timespent_advance->validate))))
677 {
678 $this->error='Permission denied';
679 return -1;
680 }*/
681
682 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'timespent_REOPEN');
683 }
684
691 public function getTooltipContentArray($params)
692 {
693 global $conf, $langs, $user;
694
695 $datas = [];
696
697 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
698 return ['optimize' => $langs->trans("ShowTimeSpent")];
699 }
700 $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans("TimeSpent").'</u>';
701 if (isset($this->status)) {
702 $datas['picto'] .= ' '.$this->getLibStatut(5);
703 }
704 $datas['ref'] .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
705
706 return $datas;
707 }
708
719 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
720 {
721 global $conf, $langs, $hookmanager;
722
723 if (!empty($conf->dol_no_mouse_hover)) {
724 $notooltip = 1; // Force disable tooltips
725 }
726
727 $result = '';
728 $params = [
729 'id' => $this->id,
730 'objecttype' => $this->element,
731 'option' => $option,
732 ];
733 $classfortooltip = 'classfortooltip';
734 $dataparams = '';
735 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
736 $classfortooltip = 'classforajaxtooltip';
737 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
738 $label = '';
739 } else {
740 $label = implode($this->getTooltipContentArray($params));
741 }
742
743 $url = dol_buildpath('/timespent/timespent_card.php', 1).'?id='.$this->id;
744
745 if ($option != 'nolink') {
746 // Add param to save lastsearch_values or not
747 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
748 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
749 $add_save_lastsearch_values = 1;
750 }
751 if ($url && $add_save_lastsearch_values) {
752 $url .= '&save_lastsearch_values=1';
753 }
754 }
755
756 $linkclose = '';
757 if (empty($notooltip)) {
758 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
759 $label = $langs->trans("ShowTimeSpent");
760 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
761 }
762 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
763 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
764 } else {
765 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
766 }
767
768 if ($option == 'nolink' || empty($url)) {
769 $linkstart = '<span';
770 } else {
771 $linkstart = '<a href="'.$url.'"';
772 }
773 $linkstart .= $linkclose.'>';
774 if ($option == 'nolink' || empty($url)) {
775 $linkend = '</span>';
776 } else {
777 $linkend = '</a>';
778 }
779
780 $result .= $linkstart;
781
782 if (empty($this->showphoto_on_popup)) {
783 if ($withpicto) {
784 $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);
785 }
786 } else {
787 if ($withpicto) {
788 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
789
790 list($class, $module) = explode('@', $this->picto);
791 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
792 $filearray = dol_dir_list($upload_dir, "files");
793 $filename = $filearray[0]['name'];
794 if (!empty($filename)) {
795 $pospoint = strpos($filearray[0]['name'], '.');
796
797 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
798 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
799 $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>';
800 } else {
801 $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>';
802 }
803
804 $result .= '</div>';
805 } else {
806 $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);
807 }
808 }
809 }
810
811 if ($withpicto != 2) {
812 $result .= $this->ref;
813 }
814
815 $result .= $linkend;
816 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
817
818 global $action, $hookmanager;
819 $hookmanager->initHooks(array($this->element.'dao'));
820 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
821 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
822 if ($reshook > 0) {
823 $result = $hookmanager->resPrint;
824 } else {
825 $result .= $hookmanager->resPrint;
826 }
827
828 return $result;
829 }
830
838 public function getKanbanView($option = '', $arraydata = null)
839 {
840 global $conf, $langs;
841
842 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
843
844 $return = '<div class="box-flex-item box-flex-grow-zero">';
845 $return .= '<div class="info-box info-box-sm">';
846 $return .= '<span class="info-box-icon bg-infobox-action">';
847 $return .= img_picto('', $this->picto);
848 $return .= '</span>';
849 $return .= '<div class="info-box-content">';
850 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
851 if ($selected >= 0) {
852 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
853 }
854 if (property_exists($this, 'label')) {
855 $return .= ' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.'</div>';
856 }
857 if (property_exists($this, 'amount')) {
858 $return .= '<br>';
859 // @phan-suppress-next-line PhanUndeclaredProperty
860 $return .= '<span class="info-box-label amount">'.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency).'</span>';
861 }
862 if (method_exists($this, 'getLibStatut')) {
863 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(5).'</div>';
864 }
865 $return .= '</div>';
866 $return .= '</div>';
867 $return .= '</div>';
868
869 return $return;
870 }
871
878 public function getLabelStatus($mode = 0)
879 {
880 return $this->LibStatut($this->status, $mode);
881 }
882
889 public function getLibStatut($mode = 0)
890 {
891 return $this->LibStatut($this->status, $mode);
892 }
893
894 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
902 public function LibStatut($status, $mode = 0)
903 {
904 // phpcs:enable
905 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
906 global $langs;
907 //$langs->load("timespent@timespent");
908 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
909 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
910 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
911 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
912 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
913 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
914 }
915
916 $statusType = 'status'.$status;
917 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
918 if ($status == self::STATUS_CANCELED) {
919 $statusType = 'status6';
920 }
921
922 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
923 }
924
931 public function info($id)
932 {
933 $sql = "SELECT rowid,";
934 $sql .= " date_creation as datec, tms as datem,";
935 $sql .= " fk_user_creat, fk_user_modif";
936 $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
937 $sql .= " WHERE t.rowid = ".((int) $id);
938
939 $result = $this->db->query($sql);
940 if ($result) {
941 if ($this->db->num_rows($result)) {
942 $obj = $this->db->fetch_object($result);
943
944 $this->id = $obj->rowid;
945
946 $this->user_creation_id = $obj->fk_user_creat;
947 $this->user_modification_id = $obj->fk_user_modif;
948 $this->date_creation = $this->db->jdate($obj->datec);
949 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
950 }
951
952 $this->db->free($result);
953 } else {
954 dol_print_error($this->db);
955 }
956 }
957
964 public function initAsSpecimen()
965 {
966 // Set here init that are not common fields
967 // $this->property1 = ...
968 // $this->property2 = ...
969
970 return $this->initAsSpecimenCommon();
971 }
972
978 public function getNextNumRef()
979 {
980 global $langs, $conf;
981 $langs->load("timespent@timespent");
982
983 if (!getDolGlobalString('TIMESPENT_timespent_ADDON')) {
984 $conf->global->TIMESPENT_timespent_ADDON = 'mod_timespent_standard';
985 }
986
987 if (getDolGlobalString('TIMESPENT_timespent_ADDON')) {
988 $mybool = false;
989
990 $file = getDolGlobalString('TIMESPENT_timespent_ADDON') . ".php";
991 $classname = getDolGlobalString('TIMESPENT_timespent_ADDON');
992
993 // Include file with class
994 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
995 foreach ($dirmodels as $reldir) {
996 $dir = dol_buildpath($reldir."core/modules/timespent/");
997
998 // Load file with numbering class (if found)
999 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1000 }
1001
1002 if (!$mybool) {
1003 dol_print_error(null, "Failed to include file ".$file);
1004 return '';
1005 }
1006
1007 if (class_exists($classname)) {
1008 $obj = new $classname();
1009 '@phan-var-force CommonNumRefGenerator $obj';
1010 $numref = $obj->getNextValue($this);
1011
1012 if ($numref != '' && $numref != '-1') {
1013 return $numref;
1014 } else {
1015 $this->error = $obj->error;
1016 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1017 return "";
1018 }
1019 } else {
1020 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
1021 return "";
1022 }
1023 } else {
1024 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1025 return "";
1026 }
1027 }
1028
1040 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1041 {
1042 global $conf, $langs;
1043
1044 $result = 0;
1045 $includedocgeneration = 0;
1046
1047 $langs->load("timespent@timespent");
1048
1049 if (!dol_strlen($modele)) {
1050 $modele = 'standard_timespent';
1051
1052 if (!empty($this->model_pdf)) {
1053 $modele = $this->model_pdf;
1054 } elseif (getDolGlobalString('timespent_ADDON_PDF')) {
1055 $modele = getDolGlobalString('timespent_ADDON_PDF');
1056 }
1057 }
1058
1059 $modelpath = "core/modules/timespent/doc/";
1060
1061 if ($includedocgeneration && !empty($modele)) {
1062 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1063 }
1064
1065 return $result;
1066 }
1067}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
$object ref
Definition info.php:89
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_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (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_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79