dolibarr 18.0.6
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 Frédéric France <frederic.france@netlogic.fr>
4 * Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Put here all includes required by your class file
27require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
28//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
29//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
30
35{
39 public $module = 'timespent';
40
44 public $element = 'timespent';
45
49 public $table_element = 'element_time';
50
55 public $ismultientitymanaged = 0;
56
60 public $isextrafieldmanaged = 0;
61
65 public $picto = 'fa-file';
66
67
68 const STATUS_DRAFT = 0;
69 const STATUS_VALIDATED = 1;
70 const STATUS_CANCELED = 9;
71
72
112 // BEGIN MODULEBUILDER PROPERTIES
116 public $fields=array(
117 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
118 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>17, 'notnull'=>0, 'visible'=>-2,),
119 'import_key' => array('type'=>'varchar(14)', 'label'=>'import_key', 'enabled'=>'1', 'position'=>15, 'notnull'=>0, 'visible'=>-1,),
120 'fk_element' => array('type'=>'integer', 'label'=>'fk_element', 'enabled'=>'1', 'position'=>2, 'notnull'=>1, 'visible'=>-1,),
121 'elementtype' => array('type'=>'varchar(32)', 'label'=>'elementtype', 'enabled'=>'1', 'position'=>3, 'notnull'=>1, 'visible'=>-1,),
122 'element_date' => array('type'=>'date', 'label'=>'element_date', 'enabled'=>'1', 'position'=>4, 'notnull'=>0, 'visible'=>-1,),
123 'element_datehour' => array('type'=>'datetime', 'label'=>'element_datehour', 'enabled'=>'1', 'position'=>5, 'notnull'=>0, 'visible'=>-1,),
124 'element_date_withhour' => array('type'=>'integer', 'label'=>'element_date_withhour', 'enabled'=>'1', 'position'=>6, 'notnull'=>0, 'visible'=>-1,),
125 'element_duration' => array('type'=>'double', 'label'=>'element_duration', 'enabled'=>'1', 'position'=>7, 'notnull'=>0, 'visible'=>-1,),
126 'fk_product' => array('type'=>'integer', 'label'=>'fk_product', 'enabled'=>'1', 'position'=>8, 'notnull'=>0, 'visible'=>-1,),
127 'fk_user' => array('type'=>'integer', 'label'=>'fk_user', 'enabled'=>'1', 'position'=>9, 'notnull'=>0, 'visible'=>-1,),
128 'thm' => array('type'=>'double(24,8)', 'label'=>'thm', 'enabled'=>'1', 'position'=>10, 'notnull'=>0, 'visible'=>-1,),
129 'invoice_id' => array('type'=>'integer', 'label'=>'invoice_id', 'enabled'=>'1', 'position'=>11, 'notnull'=>0, 'visible'=>-1, 'default'=>'NULL',),
130 'invoice_line_id' => array('type'=>'integer', 'label'=>'invoice_line_id', 'enabled'=>'1', 'position'=>12, 'notnull'=>0, 'visible'=>-1, 'default'=>'NULL',),
131 'intervention_id' => array('type'=>'integer', 'label'=>'intervention_id', 'enabled'=>'1', 'position'=>13, 'notnull'=>0, 'visible'=>-1, 'default'=>'NULL',),
132 'intervention_line_id' => array('type'=>'integer', 'label'=>'intervention_line_id', 'enabled'=>'1', 'position'=>14, 'notnull'=>0, 'visible'=>-1, 'default'=>'NULL',),
133 'datec' => array('type'=>'datetime', 'label'=>'datec', 'enabled'=>'1', 'position'=>16, 'notnull'=>0, 'visible'=>-1,),
134 'note' => array('type'=>'text', 'label'=>'note', 'enabled'=>'1', 'position'=>18, 'notnull'=>0, 'visible'=>-1,),
135 );
136 public $rowid;
137 public $tms;
138 public $import_key;
139 public $fk_element;
140 public $elementtype;
141 public $element_date;
142 public $element_datehour;
143 public $element_date_withhour;
144 public $element_duration;
145 public $fk_product;
146 public $fk_user;
147 public $thm;
148 public $invoice_id;
149 public $invoice_line_id;
150 public $intervention_id;
151 public $intervention_line_id;
152 public $datec;
153 public $note;
154 // END MODULEBUILDER PROPERTIES
155
156
157 // If this object has a subtable with lines
158
159 // /**
160 // * @var string Name of subtable line
161 // */
162 // public $table_element_line = 'timespent_timespentline';
163
164 // /**
165 // * @var string Field with ID of parent key if this object has a parent
166 // */
167 // public $fk_element = 'fk_timespent';
168
169 // /**
170 // * @var string Name of subtable class that manage subtable lines
171 // */
172 // public $class_element_line = 'TimeSpentline';
173
174 // /**
175 // * @var array List of child tables. To test if we can delete object.
176 // */
177 // protected $childtables = array();
178
179 // /**
180 // * @var array List of child tables. To know object to delete on cascade.
181 // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
182 // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
183 // */
184 // protected $childtablesoncascade = array('timespent_timespentdet');
185
186 // /**
187 // * @var TimeSpentLine[] Array of subtable lines
188 // */
189 // public $lines = array();
190
191
192
198 public function __construct(DoliDB $db)
199 {
200 global $conf, $langs;
201
202 $this->db = $db;
203
204 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid']) && !empty($this->fields['ref'])) {
205 $this->fields['rowid']['visible'] = 0;
206 }
207 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
208 $this->fields['entity']['enabled'] = 0;
209 }
210
211 // Example to show how to set values of fields definition dynamically
212 /*if ($user->rights->timespent->timespent->read) {
213 $this->fields['myfield']['visible'] = 1;
214 $this->fields['myfield']['noteditable'] = 0;
215 }*/
216
217 // Unset fields that are disabled
218 foreach ($this->fields as $key => $val) {
219 if (isset($val['enabled']) && empty($val['enabled'])) {
220 unset($this->fields[$key]);
221 }
222 }
223
224 // Translate some data of arrayofkeyval
225 if (is_object($langs)) {
226 foreach ($this->fields as $key => $val) {
227 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
228 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
229 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
230 }
231 }
232 }
233 }
234 }
235
243 public function create(User $user, $notrigger = false)
244 {
245 $resultcreate = $this->createCommon($user, $notrigger);
246
247 //$resultvalidate = $this->validate($user, $notrigger);
248
249 return $resultcreate;
250 }
251
259 public function createFromClone(User $user, $fromid)
260 {
261 global $langs, $extrafields;
262 $error = 0;
263
264 dol_syslog(__METHOD__, LOG_DEBUG);
265
266 $object = new self($this->db);
267
268 $this->db->begin();
269
270 // Load source object
271 $result = $object->fetchCommon($fromid);
272 if ($result > 0 && !empty($object->table_element_line)) {
273 $object->fetchLines();
274 }
275
276 // get lines so they will be clone
277 //foreach($this->lines as $line)
278 // $line->fetch_optionals();
279
280 // Reset some properties
281 unset($object->id);
282 unset($object->fk_user_creat);
283 unset($object->import_key);
284
285 // Clear fields
286 if (property_exists($object, 'ref')) {
287 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
288 }
289 if (property_exists($object, 'label')) {
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
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 if ($result > 0 && !empty($this->table_element_line)) {
363 $this->fetchLines();
364 }
365 return $result;
366 }
367
373 public function fetchLines()
374 {
375 $this->lines = array();
376
377 $result = $this->fetchLinesCommon();
378 return $result;
379 }
380
381
393 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
394 {
395 global $conf;
396
397 dol_syslog(__METHOD__, LOG_DEBUG);
398
399 $records = array();
400
401 $sql = "SELECT ";
402 $sql .= $this->getFieldList('t');
403 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
404 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
405 $sql .= " WHERE t.entity IN (".getEntity($this->element).")";
406 } else {
407 $sql .= " WHERE 1 = 1";
408 }
409 // Manage filter
410 $sqlwhere = array();
411 if (count($filter) > 0) {
412 foreach ($filter as $key => $value) {
413 if ($key == 't.rowid') {
414 $sqlwhere[] = $key." = ".((int) $value);
415 } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
416 $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
417 } elseif ($key == 'customsql') {
418 $sqlwhere[] = $value;
419 } elseif (strpos($value, '%') === false) {
420 $sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
421 } else {
422 $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
423 }
424 }
425 }
426 if (count($sqlwhere) > 0) {
427 $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
428 }
429
430 if (!empty($sortfield)) {
431 $sql .= $this->db->order($sortfield, $sortorder);
432 }
433 if (!empty($limit)) {
434 $sql .= $this->db->plimit($limit, $offset);
435 }
436
437 $resql = $this->db->query($sql);
438 if ($resql) {
439 $num = $this->db->num_rows($resql);
440 $i = 0;
441 while ($i < ($limit ? min($limit, $num) : $num)) {
442 $obj = $this->db->fetch_object($resql);
443
444 $record = new self($this->db);
445 $record->setVarsFromFetchObj($obj);
446
447 $records[$record->id] = $record;
448
449 $i++;
450 }
451 $this->db->free($resql);
452
453 return $records;
454 } else {
455 $this->errors[] = 'Error '.$this->db->lasterror();
456 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
457
458 return -1;
459 }
460 }
461
469 public function update(User $user, $notrigger = false)
470 {
471 return $this->updateCommon($user, $notrigger);
472 }
473
481 public function delete(User $user, $notrigger = false)
482 {
483 return $this->deleteCommon($user, $notrigger);
484 //return $this->deleteCommon($user, $notrigger, 1);
485 }
486
495 public function deleteLine(User $user, $idline, $notrigger = false)
496 {
497 if ($this->status < 0) {
498 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
499 return -2;
500 }
501
502 return $this->deleteLineCommon($user, $idline, $notrigger);
503 }
504
505
513 public function validate($user, $notrigger = 0)
514 {
515 global $conf, $langs;
516
517 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
518
519 $error = 0;
520
521 // Protection
522 if ($this->status == self::STATUS_VALIDATED) {
523 dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
524 return 0;
525 }
526
527 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->timespent->write))
528 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->timespent->timespent_advance->validate))))
529 {
530 $this->error='NotEnoughPermissions';
531 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
532 return -1;
533 }*/
534
535 $now = dol_now();
536
537 $this->db->begin();
538
539 // Define new ref
540 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
541 $num = $this->getNextNumRef();
542 } else {
543 $num = $this->ref;
544 }
545 $this->newref = $num;
546
547 if (!empty($num)) {
548 // Validate
549 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
550 $sql .= " SET ref = '".$this->db->escape($num)."',";
551 $sql .= " status = ".self::STATUS_VALIDATED;
552 if (!empty($this->fields['date_validation'])) {
553 $sql .= ", date_validation = '".$this->db->idate($now)."'";
554 }
555 if (!empty($this->fields['fk_user_valid'])) {
556 $sql .= ", fk_user_valid = ".((int) $user->id);
557 }
558 $sql .= " WHERE rowid = ".((int) $this->id);
559
560 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
561 $resql = $this->db->query($sql);
562 if (!$resql) {
563 dol_print_error($this->db);
564 $this->error = $this->db->lasterror();
565 $error++;
566 }
567
568 if (!$error && !$notrigger) {
569 // Call trigger
570 $result = $this->call_trigger('timespent_VALIDATE', $user);
571 if ($result < 0) {
572 $error++;
573 }
574 // End call triggers
575 }
576 }
577
578 if (!$error) {
579 $this->oldref = $this->ref;
580
581 // Rename directory if dir was a temporary ref
582 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
583 // Now we rename also files into index
584 $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)."'";
585 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'timespent/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
586 $resql = $this->db->query($sql);
587 if (!$resql) {
588 $error++; $this->error = $this->db->lasterror();
589 }
590 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'timespent/".$this->db->escape($this->newref)."'";
591 $sql .= " WHERE filepath = 'timespent/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
592 $resql = $this->db->query($sql);
593 if (!$resql) {
594 $error++; $this->error = $this->db->lasterror();
595 }
596
597 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
598 $oldref = dol_sanitizeFileName($this->ref);
599 $newref = dol_sanitizeFileName($num);
600 $dirsource = $conf->timespent->dir_output.'/timespent/'.$oldref;
601 $dirdest = $conf->timespent->dir_output.'/timespent/'.$newref;
602 if (!$error && file_exists($dirsource)) {
603 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
604
605 if (@rename($dirsource, $dirdest)) {
606 dol_syslog("Rename ok");
607 // Rename docs starting with $oldref with $newref
608 $listoffiles = dol_dir_list($conf->timespent->dir_output.'/timespent/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
609 foreach ($listoffiles as $fileentry) {
610 $dirsource = $fileentry['name'];
611 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
612 $dirsource = $fileentry['path'].'/'.$dirsource;
613 $dirdest = $fileentry['path'].'/'.$dirdest;
614 @rename($dirsource, $dirdest);
615 }
616 }
617 }
618 }
619 }
620
621 // Set new ref and current status
622 if (!$error) {
623 $this->ref = $num;
624 $this->status = self::STATUS_VALIDATED;
625 }
626
627 if (!$error) {
628 $this->db->commit();
629 return 1;
630 } else {
631 $this->db->rollback();
632 return -1;
633 }
634 }
635
636
644 public function setDraft($user, $notrigger = 0)
645 {
646 // Protection
647 if ($this->status <= self::STATUS_DRAFT) {
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_DRAFT, $notrigger, 'timespent_UNVALIDATE');
659 }
660
668 public function cancel($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_CANCELED, $notrigger, 'timespent_CANCEL');
683 }
684
692 public function reopen($user, $notrigger = 0)
693 {
694 // Protection
695 if ($this->status == self::STATUS_VALIDATED) {
696 return 0;
697 }
698
699 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->write))
700 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->timespent->timespent_advance->validate))))
701 {
702 $this->error='Permission denied';
703 return -1;
704 }*/
705
706 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'timespent_REOPEN');
707 }
708
715 public function getTooltipContentArray($params)
716 {
717 global $conf, $langs, $user;
718
719 $datas = [];
720
721 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
722 return ['optimize' => $langs->trans("ShowTimeSpent")];
723 }
724 $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans("TimeSpent").'</u>';
725 if (isset($this->status)) {
726 $datas['picto'] .= ' '.$this->getLibStatut(5);
727 }
728 $datas['ref'] .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
729
730 return $datas;
731 }
732
743 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
744 {
745 global $conf, $langs, $hookmanager;
746
747 if (!empty($conf->dol_no_mouse_hover)) {
748 $notooltip = 1; // Force disable tooltips
749 }
750
751 $result = '';
752 $params = [
753 'id' => $this->id,
754 'objecttype' => $this->element,
755 'option' => $option,
756 ];
757 $classfortooltip = 'classfortooltip';
758 $dataparams = '';
759 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
760 $classfortooltip = 'classforajaxtooltip';
761 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
762 $label = '';
763 } else {
764 $label = implode($this->getTooltipContentArray($params));
765 }
766
767 $url = dol_buildpath('/timespent/timespent_card.php', 1).'?id='.$this->id;
768
769 if ($option != 'nolink') {
770 // Add param to save lastsearch_values or not
771 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
772 if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
773 $add_save_lastsearch_values = 1;
774 }
775 if ($url && $add_save_lastsearch_values) {
776 $url .= '&save_lastsearch_values=1';
777 }
778 }
779
780 $linkclose = '';
781 if (empty($notooltip)) {
782 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
783 $label = $langs->trans("ShowTimeSpent");
784 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
785 }
786 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
787 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
788 } else {
789 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
790 }
791
792 if ($option == 'nolink' || empty($url)) {
793 $linkstart = '<span';
794 } else {
795 $linkstart = '<a href="'.$url.'"';
796 }
797 $linkstart .= $linkclose.'>';
798 if ($option == 'nolink' || empty($url)) {
799 $linkend = '</span>';
800 } else {
801 $linkend = '</a>';
802 }
803
804 $result .= $linkstart;
805
806 if (empty($this->showphoto_on_popup)) {
807 if ($withpicto) {
808 $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);
809 }
810 } else {
811 if ($withpicto) {
812 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
813
814 list($class, $module) = explode('@', $this->picto);
815 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
816 $filearray = dol_dir_list($upload_dir, "files");
817 $filename = $filearray[0]['name'];
818 if (!empty($filename)) {
819 $pospoint = strpos($filearray[0]['name'], '.');
820
821 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
822 if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
823 $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>';
824 } else {
825 $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>';
826 }
827
828 $result .= '</div>';
829 } else {
830 $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);
831 }
832 }
833 }
834
835 if ($withpicto != 2) {
836 $result .= $this->ref;
837 }
838
839 $result .= $linkend;
840 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
841
842 global $action, $hookmanager;
843 $hookmanager->initHooks(array($this->element.'dao'));
844 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
845 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
846 if ($reshook > 0) {
847 $result = $hookmanager->resPrint;
848 } else {
849 $result .= $hookmanager->resPrint;
850 }
851
852 return $result;
853 }
854
862 public function getKanbanView($option = '', $arraydata = null)
863 {
864 global $conf, $langs;
865
866 //$selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
867
868 $return = '<div class="box-flex-item box-flex-grow-zero">';
869 $return .= '<div class="info-box info-box-sm">';
870 $return .= '<span class="info-box-icon bg-infobox-action">';
871 $return .= img_picto('', $this->picto);
872 $return .= '</span>';
873 $return .= '<div class="info-box-content">';
874 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
875 //$return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
876
877 if (property_exists($this, 'label')) {
878 $return .= ' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.'</div>';
879 }
880 if (property_exists($this, 'amount')) {
881 $return .= '<br>';
882 $return .= '<span class="info-box-label amount">'.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency).'</span>';
883 }
884 if (method_exists($this, 'getLibStatut')) {
885 $return .= '<br><div class="info-box-status margintoponly">'.$this->getLibStatut(5).'</div>';
886 }
887 $return .= '</div>';
888 $return .= '</div>';
889 $return .= '</div>';
890
891 return $return;
892 }
893
900 public function getLabelStatus($mode = 0)
901 {
902 return $this->LibStatut($this->status, $mode);
903 }
904
911 public function getLibStatut($mode = 0)
912 {
913 return $this->LibStatut($this->status, $mode);
914 }
915
916 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
924 public function LibStatut($status, $mode = 0)
925 {
926 // phpcs:enable
927 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
928 global $langs;
929 //$langs->load("timespent@timespent");
930 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
931 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
932 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
933 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
934 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
935 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
936 }
937
938 $statusType = 'status'.$status;
939 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
940 if ($status == self::STATUS_CANCELED) {
941 $statusType = 'status6';
942 }
943
944 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
945 }
946
953 public function info($id)
954 {
955 $sql = "SELECT rowid,";
956 $sql .= " date_creation as datec, tms as datem,";
957 $sql .= " fk_user_creat, fk_user_modif";
958 $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
959 $sql .= " WHERE t.rowid = ".((int) $id);
960
961 $result = $this->db->query($sql);
962 if ($result) {
963 if ($this->db->num_rows($result)) {
964 $obj = $this->db->fetch_object($result);
965
966 $this->id = $obj->rowid;
967
968 $this->user_creation_id = $obj->fk_user_creat;
969 $this->user_modification_id = $obj->fk_user_modif;
970 if (!empty($obj->fk_user_valid)) {
971 $this->user_validation_id = $obj->fk_user_valid;
972 }
973 $this->date_creation = $this->db->jdate($obj->datec);
974 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
975 if (!empty($obj->datev)) {
976 $this->date_validation = empty($obj->datev) ? '' : $this->db->jdate($obj->datev);
977 }
978 }
979
980 $this->db->free($result);
981 } else {
982 dol_print_error($this->db);
983 }
984 }
985
992 public function initAsSpecimen()
993 {
994 // Set here init that are not commonf fields
995 // $this->property1 = ...
996 // $this->property2 = ...
997
998 $this->initAsSpecimenCommon();
999 }
1000
1006 public function getLinesArray()
1007 {
1008 $this->lines = array();
1009
1010 $objectline = new TimeSpentLine($this->db);
1011 $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_timespent = '.((int) $this->id)));
1012
1013 if (is_numeric($result)) {
1014 $this->error = $objectline->error;
1015 $this->errors = $objectline->errors;
1016 return $result;
1017 } else {
1018 $this->lines = $result;
1019 return $this->lines;
1020 }
1021 }
1022
1028 public function getNextNumRef()
1029 {
1030 global $langs, $conf;
1031 $langs->load("timespent@timespent");
1032
1033 if (empty($conf->global->TIMESPENT_timespent_ADDON)) {
1034 $conf->global->TIMESPENT_timespent_ADDON = 'mod_timespent_standard';
1035 }
1036
1037 if (!empty($conf->global->TIMESPENT_timespent_ADDON)) {
1038 $mybool = false;
1039
1040 $file = $conf->global->TIMESPENT_timespent_ADDON.".php";
1041 $classname = $conf->global->TIMESPENT_timespent_ADDON;
1042
1043 // Include file with class
1044 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1045 foreach ($dirmodels as $reldir) {
1046 $dir = dol_buildpath($reldir."core/modules/timespent/");
1047
1048 // Load file with numbering class (if found)
1049 $mybool |= @include_once $dir.$file;
1050 }
1051
1052 if ($mybool === false) {
1053 dol_print_error('', "Failed to include file ".$file);
1054 return '';
1055 }
1056
1057 if (class_exists($classname)) {
1058 $obj = new $classname();
1059 $numref = $obj->getNextValue($this);
1060
1061 if ($numref != '' && $numref != '-1') {
1062 return $numref;
1063 } else {
1064 $this->error = $obj->error;
1065 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1066 return "";
1067 }
1068 } else {
1069 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
1070 return "";
1071 }
1072 } else {
1073 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1074 return "";
1075 }
1076 }
1077
1089 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1090 {
1091 global $conf, $langs;
1092
1093 $result = 0;
1094 $includedocgeneration = 0;
1095
1096 $langs->load("timespent@timespent");
1097
1098 if (!dol_strlen($modele)) {
1099 $modele = 'standard_timespent';
1100
1101 if (!empty($this->model_pdf)) {
1102 $modele = $this->model_pdf;
1103 } elseif (!empty($conf->global->timespent_ADDON_PDF)) {
1104 $modele = $conf->global->timespent_ADDON_PDF;
1105 }
1106 }
1107
1108 $modelpath = "core/modules/timespent/doc/";
1109
1110 if ($includedocgeneration && !empty($modele)) {
1111 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1112 }
1113
1114 return $result;
1115 }
1116
1124 public function doScheduledJob()
1125 {
1126 //global $conf, $langs;
1127
1128 //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1129
1130 $error = 0;
1131 $this->output = '';
1132 $this->error = '';
1133
1134 dol_syslog(__METHOD__, LOG_DEBUG);
1135
1136 $now = dol_now();
1137
1138 $this->db->begin();
1139
1140 // ...
1141
1142 $this->db->commit();
1143
1144 return $error;
1145 }
1146}
$object ref
Definition info.php:78
Parent class of all other business classes (invoices, contracts, proposals, orders,...
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
updateCommon(User $user, $notrigger=false)
Update object into database.
fetchLinesCommon($morewhere='')
Load object in memory from the 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.
fetchLines()
Load object lines in memory from the database.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly 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=false)
Delete a line of object in database.
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $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=false)
Update object into database.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
create(User $user, $notrigger=false)
Create object into database.
getKanbanView($option='', $arraydata=null)
Return a thumb for kanban views.
getLinesArray()
Create an array of lines.
Class to manage Dolibarr users.
dol_dir_list($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:62
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.