dolibarr 23.0.3
evaluation.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
4 * Copyright (C) 2021 Greg Rastklan <greg.rastklan@atm-consulting.fr>
5 * Copyright (C) 2021 Jean-Pascal BOUDET <jean-pascal.boudet@atm-consulting.fr>
6 * Copyright (C) 2021 Grégory BLEMAND <gregory.blemand@atm-consulting.fr>
7 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Put here all includes required by your class file
31require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
32require_once DOL_DOCUMENT_ROOT . '/hrm/class/evaluationdet.class.php';
33
34
39{
43 public $module = 'hrm';
44
48 public $element = 'evaluation';
49
53 public $table_element = 'hrm_evaluation';
54
58 public $picto = 'label';
59
60
61 const STATUS_DRAFT = 0;
62 const STATUS_VALIDATED = 1;
63 const STATUS_CANCELED = 9;
64 const STATUS_CLOSED = 6;
65
66
93 // BEGIN MODULEBUILDER PROPERTIES
97 public $fields = array(
98 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'css' => 'left', 'comment' => "Id"),
99 'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'position' => 20, 'notnull' => 1, 'visible' => 4, 'noteditable' => 1, 'default' => '(PROV)', 'index' => 1, 'searchall' => 1, 'showoncombobox' => 1, 'comment' => "Reference of object"),
100 'label' => array('type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'position' => 30, 'notnull' => 0, 'visible' => 1, 'searchall' => 1, 'css' => 'minwidth300', 'cssview' => 'wordbreak', 'showoncombobox' => 2,),
101 'description' => array('type' => 'text', 'label' => 'Description', 'enabled' => 1, 'position' => 60, 'notnull' => 0, 'visible' => 3,),
102 'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'position' => 61, 'notnull' => 0, 'visible' => 0,),
103 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'position' => 62, 'notnull' => 0, 'visible' => 0,),
104 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 500, 'notnull' => 1, 'visible' => -2,),
105 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 501, 'notnull' => 0, 'visible' => -2,),
106 'fk_user_creat' => array('type' => 'integer:User:user/class/user.class.php:0', 'label' => 'UserAuthor', 'enabled' => 1, 'position' => 510, 'notnull' => 1, 'visible' => -2, 'foreignkey' => 'user.rowid',),
107 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php:0', 'label' => 'UserModif', 'enabled' => 1, 'position' => 511, 'notnull' => -1, 'visible' => -2,),
108 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'position' => 1000, 'notnull' => -1, 'visible' => -2,),
109 'status' => array('type' => 'smallint', 'label' => 'Status', 'enabled' => 1, 'position' => 1000, 'notnull' => 1, 'default' => '0', 'visible' => 5, 'index' => 1, 'arrayofkeyval' => array(0 => 'Draft', 1 => 'Validated', 6 => 'Closed'),),
110 'date_eval' => array('type' => 'date', 'label' => 'DateEval', 'enabled' => 1, 'position' => 502, 'notnull' => 1, 'visible' => 1,),
111 'fk_user' => array('type' => 'integer:User:user/class/user.class.php:0:(t.statut:!=:0)', 'label' => 'Employee', 'enabled' => 1, 'position' => 504, 'notnull' => 1, 'visible' => 1, 'picto' => 'user', 'css' => 'maxwidth300 widthcentpercentminusxx', 'csslist' => 'tdoverflowmax150'),
112 'fk_job' => array('type' => 'integer:Job:/hrm/class/job.class.php', 'label' => 'JobProfile', 'enabled' => 1, 'position' => 505, 'notnull' => 1, 'visible' => 1, 'picto' => 'jobprofile', 'css' => 'maxwidth300 widthcentpercentminusxx', 'csslist' => 'tdoverflowmax150'),
113 'model_pdf' => array('type' => 'varchar(255)', 'label' => 'Model pdf', 'enabled' => 1, 'visible' => 0, 'position' => 1010),
114 );
118 public $rowid;
122 public $ref;
126 public $label;
130 public $description;
134 public $fk_user_creat;
138 public $fk_user_modif;
142 public $import_key;
146 public $status;
150 public $date_eval;
154 public $fk_user;
158 public $fk_job;
159 // END MODULEBUILDER PROPERTIES
160
161
162 // If this object has a subtable with lines
163
167 public $table_element_line = 'hrm_evaluationdet';
168
172 public $fk_element = 'fk_evaluation';
173
177 public $class_element_line = 'EvaluationLine';
178
179 // /**
180 // * @var array List of child tables. To test if we can delete object.
181 // */
182 // protected $childtables = array();
183
189 protected $childtablesoncascade = array('@EvaluationLine:hrm/class/evaluationdet.class.php:fk_evaluation');
190
194 public $lines = array();
195
196
197
203 public function __construct(DoliDB $db)
204 {
205 global $langs, $user;
206
207 $this->db = $db;
208
209 $this->ismultientitymanaged = 0;
210 $this->isextrafieldmanaged = 1;
211
212 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
213 $this->fields['rowid']['visible'] = 0;
214 }
215 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
216 $this->fields['entity']['enabled'] = 0;
217 }
218
219 if (!$user->hasRight('hrm', 'evaluation', 'readall')) {
220 $this->fields['fk_user']['type'] .= ' AND (t.rowid:IN:'.$this->db->sanitize(implode(",", $user->getAllChildIds(1))) .')';
221 }
222
223 $this->date_eval = dol_now();
224
225 // Unset fields that are disabled
226 foreach ($this->fields as $key => $val) {
227 if (isset($val['enabled']) && empty($val['enabled'])) {
228 unset($this->fields[$key]);
229 }
230 }
231
232 // Translate some data of arrayofkeyval
233 if (is_object($langs)) {
234 foreach ($this->fields as $key => $val) {
235 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
236 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
237 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
238 }
239 }
240 }
241 }
242 }
243
251 public function create(User $user, $notrigger = 0)
252 {
253 $resultcreate = $this->createCommon($user, $notrigger);
254
255 if ($resultcreate > 0) {
256 require_once DOL_DOCUMENT_ROOT . '/hrm/class/skillrank.class.php';
257 $skillRank = new SkillRank($this->db);
258 $TRequiredRanks = $skillRank->fetchAll('ASC', 't.rowid', 0, 0, '(fk_object:=:'.((int) $this->fk_job).") AND (objecttype:=:'job')");
259
260 if (is_array($TRequiredRanks) && !empty($TRequiredRanks)) {
261 $this->lines = array();
262 foreach ($TRequiredRanks as $required) {
263 $line = new EvaluationLine($this->db);
264 $line->fk_evaluation = $resultcreate;
265 $line->fk_skill = $required->fk_skill;
266 $line->required_rank = $required->rankorder;
267 $line->fk_rank = 0;
268
269 $res = $line->create($user, $notrigger);
270 if ($res > 0) {
271 $this->lines[] = $line;
272 }
273 }
274 }
275 }
276
277 return $resultcreate;
278 }
279
287 public function createFromClone(User $user, $fromid)
288 {
289 global $langs, $extrafields;
290 $error = 0;
291
292 dol_syslog(__METHOD__, LOG_DEBUG);
293
294 $object = new self($this->db);
295
296 $this->db->begin();
297
298 // Load source object
299 $result = $object->fetchCommon($fromid);
300 if ($result > 0 && !empty($object->table_element_line)) {
301 $object->fetchLines();
302 }
303
304 // get lines so they will be clone
305 //foreach($this->lines as $line)
306 // $line->fetch_optionals();
307
308 // Reset some properties
309 unset($object->id);
310 unset($object->fk_user_creat);
311 unset($object->import_key);
312
313 // Clear fields
314 if (!empty($object->ref)) {
315 // @phan-suppress-next-line PhanTypeMismatchProperty
316 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
317 }
318 if (!empty($object->label)) {
319 $object->label = $langs->trans("CopyOf")." ".$object->label;
320 }
321 $object->status = self::STATUS_DRAFT;
322 $object->date_creation = dol_now();
323
324 // Clear extrafields that are unique
325 if (is_array($object->array_options) && count($object->array_options) > 0) {
326 $extrafields->fetch_name_optionals_label($this->table_element);
327 foreach ($object->array_options as $key => $option) {
328 $shortkey = preg_replace('/options_/', '', $key);
329 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
330 //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
331 unset($object->array_options[$key]);
332 }
333 }
334 }
335
336 // Create clone
337 $object->context['createfromclone'] = 'createfromclone';
338 $result = $object->createCommon($user);
339 if ($result < 0) {
340 $error++;
342 }
343
344 if (!$error) {
345 // copy internal contacts
346 if ($this->copy_linked_contact($object, 'internal') < 0) {
347 $error++;
348 }
349 }
350
351 if (!$error) {
352 // copy external contacts if same company
353 if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
354 if ($this->copy_linked_contact($object, 'external') < 0) {
355 $error++;
356 }
357 }
358 }
359
360 unset($object->context['createfromclone']);
361
362 // End
363 if (!$error) {
364 $this->db->commit();
365 return $object;
366 } else {
367 $this->db->rollback();
368 return -1;
369 }
370 }
371
379 public function fetch($id, $ref = null)
380 {
381 $result = $this->fetchCommon($id, $ref);
382 if ($result > 0 && !empty($this->table_element_line)) {
383 $this->fetchLines();
384 }
385 return $result;
386 }
387
393 public function fetchLines()
394 {
395 $this->lines = array();
396
397 $result = $this->fetchLinesCommon();
398 return $result;
399 }
400
401
414 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
415 {
416 dol_syslog(__METHOD__, LOG_DEBUG);
417
418 $records = array();
419
420 $sql = 'SELECT ';
421 $sql .= $this->getFieldList('t');
422 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
423 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
424 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
425 } else {
426 $sql .= ' WHERE 1 = 1';
427 }
428
429 // Manage filter
430 $errormessage = '';
431 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
432 if ($errormessage) {
433 $this->errors[] = $errormessage;
434 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
435 return -1;
436 }
437
438 if (!empty($sortfield)) {
439 $sql .= $this->db->order($sortfield, $sortorder);
440 }
441 if (!empty($limit)) {
442 $sql .= ' '.$this->db->plimit($limit, $offset);
443 }
444
445 $resql = $this->db->query($sql);
446 if ($resql) {
447 $num = $this->db->num_rows($resql);
448 $i = 0;
449 while ($i < ($limit ? min($limit, $num) : $num)) {
450 $obj = $this->db->fetch_object($resql);
451
452 $record = new self($this->db);
453 $record->setVarsFromFetchObj($obj);
454
455 $records[$record->id] = $record;
456
457 $i++;
458 }
459 $this->db->free($resql);
460
461 return $records;
462 } else {
463 $this->errors[] = 'Error '.$this->db->lasterror();
464 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
465
466 return -1;
467 }
468 }
469
477 public function update(User $user, $notrigger = 0)
478 {
479 return $this->updateCommon($user, $notrigger);
480 }
481
489 public function delete(User $user, $notrigger = 0)
490 {
491 return $this->deleteCommon($user, $notrigger);
492 //return $this->deleteCommon($user, $notrigger, 1);
493 }
494
503 public function deleteLine(User $user, $idline, $notrigger = 0)
504 {
505 if ($this->status < 0) {
506 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
507 return -2;
508 }
509
510 return $this->deleteLineCommon($user, $idline, $notrigger);
511 }
512
513
521 public function validate($user, $notrigger = 0)
522 {
523 global $conf, $langs;
524
525 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
526
527 $error = 0;
528
529 // Protection
530 if ($this->status == self::STATUS_VALIDATED) {
531 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
532 return 0;
533 }
534
535
536
537 $now = dol_now();
538
539 $this->db->begin();
540
541 // Define new ref
542 if (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life
543 $num = $this->getNextNumRef();
544 } else {
545 $num = (string) $this->ref;
546 }
547 $this->newref = $num;
548
549 if (!empty($num)) {
550 // Validate
551 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
552 $sql .= " SET ref = '".$this->db->escape($num)."',";
553 $sql .= " status = ".self::STATUS_VALIDATED;
554 if (!empty($this->fields['date_validation'])) {
555 $sql .= ", date_validation = '".$this->db->idate($now)."'";
556 }
557 if (!empty($this->fields['fk_user_valid'])) { // @phan-suppress-current-line PhanTypeMismatchProperty
558 $sql .= ", fk_user_valid = ".((int) $user->id);
559 }
560 $sql .= " WHERE rowid = ".((int) $this->id);
561
562 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
563 $resql = $this->db->query($sql);
564 if (!$resql) {
565 dol_print_error($this->db);
566 $this->error = $this->db->lasterror();
567 $error++;
568 }
569
570 if (!$error && !$notrigger) {
571 // Call trigger
572 $result = $this->call_trigger('HRM_EVALUATION_VALIDATE', $user);
573 if ($result < 0) {
574 $error++;
575 }
576 // End call triggers
577 }
578 }
579
580 if (!$error) {
581 $this->oldref = $this->ref;
582
583 // Rename directory if dir was a temporary ref
584 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
585 // Now we rename also files into index
586 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'evaluation/".$this->db->escape($this->newref)."'";
587 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'evaluation/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
588 $resql = $this->db->query($sql);
589 if (!$resql) {
590 $error++;
591 $this->error = $this->db->lasterror();
592 }
593 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'evaluation/".$this->db->escape($this->newref)."'";
594 $sql .= " WHERE filepath = 'evaluation/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
595 $resql = $this->db->query($sql);
596 if (!$resql) {
597 $error++;
598 $this->error = $this->db->lasterror();
599 }
600
601 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
602 $oldref = dol_sanitizeFileName($this->ref);
603 $newref = dol_sanitizeFileName($num);
604 $dirsource = $conf->hrm->dir_output.'/evaluation/'.$oldref;
605 $dirdest = $conf->hrm->dir_output.'/evaluation/'.$newref;
606 if (!$error && file_exists($dirsource)) {
607 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
608
609 if (@rename($dirsource, $dirdest)) {
610 dol_syslog("Rename ok");
611 // Rename docs starting with $oldref with $newref
612 $listoffiles = dol_dir_list($conf->hrm->dir_output.'/evaluation/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
613 foreach ($listoffiles as $fileentry) {
614 $dirsource = $fileentry['name'];
615 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
616 $dirsource = $fileentry['path'].'/'.$dirsource;
617 $dirdest = $fileentry['path'].'/'.$dirdest;
618 @rename($dirsource, $dirdest);
619 }
620 }
621 }
622 }
623 }
624
625 // Set new ref and current status
626 if (!$error) {
627 $this->ref = $num;
628 $this->status = self::STATUS_VALIDATED;
629 }
630
631 if (!$error) {
632 $this->db->commit();
633 return 1;
634 } else {
635 $this->db->rollback();
636 return -1;
637 }
638 }
639
646 public function getLastEvaluationForUser($fk_user)
647 {
648 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."hrm_evaluation ";
649 $sql .= "WHERE fk_user=".((int) $fk_user)." ";
650 $sql .= "ORDER BY date_eval DESC ";
651 $sql .= "LIMIT 1 ";
652
653 $res = $this->db->query($sql);
654 if (!$res) {
655 dol_print_error($this->db);
656 }
657
658 $Tab = $this->db->fetch_object($res);
659
660 if (empty($Tab)) {
661 return null;
662 } else {
663 $evaluation = new Evaluation($this->db);
664 $evaluation->fetch($Tab->rowid);
665
666 return $evaluation;
667 }
668 }
669
670
678 public function setDraft($user, $notrigger = 0)
679 {
680 // Protection
681 if ($this->status <= self::STATUS_DRAFT) {
682 return 0;
683 }
684
685 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'HRM_EVALUATION_UNVALIDATE');
686 }
687
695 public function cancel($user, $notrigger = 0)
696 {
697 // Protection
698 if ($this->status != self::STATUS_VALIDATED) {
699 return 0;
700 }
701
702 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'HRM_EVALUATION_CANCEL');
703 }
704
712 public function reopen($user, $notrigger = 0)
713 {
714 // Protection
715 if ($this->status != self::STATUS_CANCELED) {
716 return 0;
717 }
718
719 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'HRM_EVALUATION_REOPEN');
720 }
721
732 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
733 {
734 global $conf, $langs, $hookmanager;
735
736 if (!empty($conf->dol_no_mouse_hover)) {
737 $notooltip = 1; // Force disable tooltips
738 }
739
740 $result = '';
741
742 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Evaluation").'</u>';
743 if (isset($this->status)) {
744 $label .= ' '.$this->getLibStatut(5);
745 }
746 $label .= '<br>';
747 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
748
749 $url = dol_buildpath('/hrm/evaluation_card.php', 1).'?id='.$this->id;
750
751 if ($option != 'nolink') {
752 // Add param to save lastsearch_values or not
753 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
754 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
755 $add_save_lastsearch_values = 1;
756 }
757 if ($add_save_lastsearch_values) {
758 $url .= '&save_lastsearch_values=1';
759 }
760 }
761
762 $linkclose = '';
763 if (empty($notooltip)) {
764 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
765 $label = $langs->trans("ShowEvaluation");
766 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
767 }
768 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
769 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
770 } else {
771 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
772 }
773
774 if ($option == 'nolink') {
775 $linkstart = '<span';
776 } else {
777 $linkstart = '<a href="'.$url.'"';
778 }
779 $linkstart .= $linkclose.'>';
780 if ($option == 'nolink') {
781 $linkend = '</span>';
782 } else {
783 $linkend = '</a>';
784 }
785
786 $result .= $linkstart;
787
788 if (empty($this->showphoto_on_popup)) {
789 if ($withpicto) {
790 $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);
791 }
792 } else {
793 if ($withpicto) {
794 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
795
796 list($class, $module) = explode('@', $this->picto);
797 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
798 $filearray = dol_dir_list($upload_dir, "files");
799 $filename = $filearray[0]['name'];
800 if (!empty($filename)) {
801 $pospoint = strpos($filearray[0]['name'], '.');
802
803 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
804 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
805 $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>';
806 } else {
807 $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>';
808 }
809
810 $result .= '</div>';
811 } else {
812 $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);
813 }
814 }
815 }
816
817 if ($withpicto != 2) {
818 $result .= $this->ref;
819 }
820
821 $result .= $linkend;
822 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
823
824 global $action, $hookmanager;
825 $hookmanager->initHooks(array('evaluationdao'));
826 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
827 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
828 if ($reshook > 0) {
829 $result = $hookmanager->resPrint;
830 } else {
831 $result .= $hookmanager->resPrint;
832 }
833
834 return $result;
835 }
836
843 public function getLibStatut($mode = 0)
844 {
845 return $this->LibStatut($this->status, $mode);
846 }
847
848 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
856 public function LibStatut($status, $mode = 0)
857 {
858 // phpcs:enable
859 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
860 global $langs;
861 //$langs->load("hrm");
862 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
863 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
864 $this->labelStatus[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Closed');
865 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
866 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
867 $this->labelStatusShort[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Closed');
868 }
869
870 $statusType = 'status'.$status;
871 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
872 if ($status == self::STATUS_CANCELED) {
873 $statusType = 'status6';
874 }
875
876 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
877 }
878
885 public function info($id)
886 {
887 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
888 $sql .= ' fk_user_creat, fk_user_modif';
889 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
890 $sql .= ' WHERE t.rowid = '.((int) $id);
891 $result = $this->db->query($sql);
892 if ($result) {
893 if ($this->db->num_rows($result)) {
894 $obj = $this->db->fetch_object($result);
895
896 $this->id = $obj->rowid;
897
898 $this->user_creation_id = $obj->fk_user_creat;
899 $this->user_modification_id = $obj->fk_user_modif;
900 $this->date_creation = $this->db->jdate($obj->datec);
901 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
902 }
903
904 $this->db->free($result);
905 } else {
906 dol_print_error($this->db);
907 }
908 }
909
916 public function initAsSpecimen()
917 {
918 // Set here init that are not commonf fields
919 // $this->property1 = ...
920 // $this->property2 = ...
921
922 return $this->initAsSpecimenCommon();
923 }
924
930 public function getLinesArray()
931 {
932 $this->lines = array();
933
934 $objectline = new EvaluationLine($this->db);
935 $result = $objectline->fetchAll('ASC', '', 0, 0, '(fk_evaluation:=:'.((int) $this->id).')');
936
937 if (is_numeric($result)) {
938 $this->setErrorsFromObject($objectline);
939 return $result;
940 } else {
941 $this->lines = $result;
942 return $this->lines;
943 }
944 }
945
951 public function getNextNumRef()
952 {
953 global $langs, $conf;
954 $langs->load("hrm");
955
956 if (!getDolGlobalString('HRMTEST_EVALUATION_ADDON')) {
957 $conf->global->HRMTEST_EVALUATION_ADDON = 'mod_evaluation_standard';
958 }
959
960 if (getDolGlobalString('HRMTEST_EVALUATION_ADDON')) {
961 $mybool = false;
962
963 $file = getDolGlobalString('HRMTEST_EVALUATION_ADDON') . ".php";
964 $classname = getDolGlobalString('HRMTEST_EVALUATION_ADDON');
965
966 // Include file with class
967 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
968 foreach ($dirmodels as $reldir) {
969 $dir = dol_buildpath($reldir."core/modules/hrm/");
970
971 // Load file with numbering class (if found)
972 $mybool = ((bool) @include_once $dir.$file) || $mybool;
973 }
974
975 if (!$mybool) {
976 dol_print_error(null, "Failed to include file ".$file);
977 return '';
978 }
979
980 if (class_exists($classname)) {
981 $obj = new $classname();
982 '@phan-var-force ModeleNumRefEvaluation $obj';
984 $numref = $obj->getNextValue($this);
985
986 if ($numref != '' && $numref != '-1') {
987 return $numref;
988 } else {
989 $this->error = $obj->error;
990 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
991 return "";
992 }
993 } else {
994 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
995 return "";
996 }
997 } else {
998 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
999 return "";
1000 }
1001 }
1002
1014 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1015 {
1016 global $langs;
1017
1018 $result = 0;
1019
1020 $langs->load("hrm");
1021
1022 if (!dol_strlen($modele)) {
1023 $modele = 'standard_evaluation';
1024
1025 if (!empty($this->model_pdf)) {
1026 $modele = $this->model_pdf;
1027 } elseif (getDolGlobalString('EVALUATION_ADDON_PDF')) {
1028 $modele = getDolGlobalString('EVALUATION_ADDON_PDF');
1029 }
1030 }
1031
1032 $modelpath = "core/modules/hrm/doc/";
1033
1034 if (!empty($modele)) {
1035 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1036 }
1037
1038 return $result;
1039 }
1040
1048 public function getKanbanView($option = '', $arraydata = null)
1049 {
1050 global $selected, $langs;
1051
1052 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1053
1054 $return = '<div class="box-flex-item box-flex-grow-zero">';
1055 $return .= '<div class="info-box info-box-sm">';
1056 $return .= '<span class="info-box-icon bg-infobox-action">';
1057 $return .= img_picto('', $this->picto);
1058 $return .= '</span>';
1059 $return .= '<div class="info-box-content">';
1060 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->getNomUrl(1) . '</span>';
1061 $return .= '<input class="fright" id="cb'.$this->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1062 if (!empty($arraydata['user'])) {
1063 $return .= '<br><span class="info-box-label ">'.$arraydata['user'].'</span>';
1064 }
1065 if (!empty($arraydata['job'])) {
1066 $return .= '<br><span class="info-box-label ">'.$arraydata['job'].'</span>';
1067 }
1068 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
1069 $return .= '</div>';
1070 $return .= '</div>';
1071 $return .= '</div>';
1072 return $return;
1073 }
1074}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$object ref
Definition info.php:90
Parent class of all other business classes (invoices, contracts, proposals, orders,...
deleteLineCommon(User $user, $idline, $notrigger=0)
Delete a line of object in database.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
setErrorsFromObject($object)
setErrorsFromObject
createCommon(User $user, $notrigger=0)
Create object in the database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
updateCommon(User $user, $notrigger=0)
Update object into database.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
fetchLinesCommon($morewhere='', $noextrafields=0)
Load object in memory from the database.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
Class to manage Dolibarr database access.
Class for Evaluation.
getLinesArray()
Create an array of lines.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
fetchLines()
Load object lines in memory from the database.
cancel($user, $notrigger=0)
Set cancel status.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
createFromClone(User $user, $fromid)
Clone an object into another one.
fetch($id, $ref=null)
Load object in memory from the database.
LibStatut($status, $mode=0)
Return the status.
validate($user, $notrigger=0)
Validate object.
__construct(DoliDB $db)
Constructor.
reopen($user, $notrigger=0)
Set back to validated status.
info($id)
Load the info information in the object.
getLastEvaluationForUser($fk_user)
Get the last evaluation by date for the user assigned.
create(User $user, $notrigger=0)
Create object into database.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
getLibStatut($mode=0)
Return the label of the status.
deleteLine(User $user, $idline, $notrigger=0)
Delete a line of object in database.
setDraft($user, $notrigger=0)
Set draft status.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
update(User $user, $notrigger=0)
Update object into database.
Class for EvaluationLine.
Class for SkillRank.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:171
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:64
dol_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.