dolibarr 25.0.0-alpha
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-2026 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 unset($object->context['createfromclone']);
352
353 // End
354 if (!$error) {
355 $this->db->commit();
356 return $object;
357 } else {
358 $this->db->rollback();
359 return -1;
360 }
361 }
362
370 public function fetch($id, $ref = null)
371 {
372 $result = $this->fetchCommon($id, $ref);
373 if ($result > 0 && !empty($this->table_element_line)) {
374 $this->fetchLines();
375 }
376 return $result;
377 }
378
384 public function fetchLines()
385 {
386 $this->lines = array();
387
388 $result = $this->fetchLinesCommon();
389 return $result;
390 }
391
392
405 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
406 {
407 dol_syslog(__METHOD__, LOG_DEBUG);
408
409 $records = array();
410
411 $sql = 'SELECT ';
412 $sql .= $this->getFieldList('t');
413 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
414 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
415 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
416 } else {
417 $sql .= ' WHERE 1 = 1';
418 }
419
420 // Manage filter
421 $errormessage = '';
422 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
423 if ($errormessage) {
424 $this->errors[] = $errormessage;
425 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
426 return -1;
427 }
428
429 if (!empty($sortfield)) {
430 $sql .= $this->db->order($sortfield, $sortorder);
431 }
432 if (!empty($limit)) {
433 $sql .= ' '.$this->db->plimit($limit, $offset);
434 }
435
436 $resql = $this->db->query($sql);
437 if ($resql) {
438 $num = $this->db->num_rows($resql);
439 $i = 0;
440 while ($i < ($limit ? min($limit, $num) : $num)) {
441 $obj = $this->db->fetch_object($resql);
442
443 $record = new self($this->db);
444 $record->setVarsFromFetchObj($obj);
445
446 $records[$record->id] = $record;
447
448 $i++;
449 }
450 $this->db->free($resql);
451
452 return $records;
453 } else {
454 $this->errors[] = 'Error '.$this->db->lasterror();
455 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
456
457 return -1;
458 }
459 }
460
468 public function update(User $user, $notrigger = 0)
469 {
470 return $this->updateCommon($user, $notrigger);
471 }
472
480 public function delete(User $user, $notrigger = 0)
481 {
482 return $this->deleteCommon($user, $notrigger);
483 //return $this->deleteCommon($user, $notrigger, 1);
484 }
485
494 public function deleteLine(User $user, $idline, $notrigger = 0)
495 {
496 if ($this->status < 0) {
497 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
498 return -2;
499 }
500
501 return $this->deleteLineCommon($user, $idline, $notrigger);
502 }
503
504
512 public function validate($user, $notrigger = 0)
513 {
514 global $conf, $langs;
515
516 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
517
518 $error = 0;
519
520 // Protection
521 if ($this->status == self::STATUS_VALIDATED) {
522 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
523 return 0;
524 }
525
526
527
528 $now = dol_now();
529
530 $this->db->begin();
531
532 // Define new ref
533 if (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life
534 $num = $this->getNextNumRef();
535 } else {
536 $num = (string) $this->ref;
537 }
538 $this->newref = $num;
539
540 if (!empty($num)) {
541 // Validate
542 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
543 $sql .= " SET ref = '".$this->db->escape($num)."',";
544 $sql .= " status = ".self::STATUS_VALIDATED;
545 if (!empty($this->fields['date_validation'])) {
546 $sql .= ", date_validation = '".$this->db->idate($now)."'";
547 }
548 if (!empty($this->fields['fk_user_valid'])) { // @phan-suppress-current-line PhanTypeMismatchProperty
549 $sql .= ", fk_user_valid = ".((int) $user->id);
550 }
551 $sql .= " WHERE rowid = ".((int) $this->id);
552
553 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
554 $resql = $this->db->query($sql);
555 if (!$resql) {
556 dol_print_error($this->db);
557 $this->error = $this->db->lasterror();
558 $error++;
559 }
560
561 if (!$error && !$notrigger) {
562 // Call trigger
563 $result = $this->call_trigger('HRM_EVALUATION_VALIDATE', $user);
564 if ($result < 0) {
565 $error++;
566 }
567 // End call triggers
568 }
569 }
570
571 if (!$error) {
572 $this->oldref = $this->ref;
573
574 // Rename directory if dir was a temporary ref
575 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
576 // Now we rename also files into index
577 $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)."'";
578 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'evaluation/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
579 $resql = $this->db->query($sql);
580 if (!$resql) {
581 $error++;
582 $this->error = $this->db->lasterror();
583 }
584 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'evaluation/".$this->db->escape($this->newref)."'";
585 $sql .= " WHERE filepath = 'evaluation/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
586 $resql = $this->db->query($sql);
587 if (!$resql) {
588 $error++;
589 $this->error = $this->db->lasterror();
590 }
591
592 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
593 $oldref = dol_sanitizeFileName($this->ref);
594 $newref = dol_sanitizeFileName($num);
595 $dirsource = $conf->hrm->dir_output.'/evaluation/'.$oldref;
596 $dirdest = $conf->hrm->dir_output.'/evaluation/'.$newref;
597 if (!$error && file_exists($dirsource)) {
598 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
599
600 if (@rename($dirsource, $dirdest)) {
601 dol_syslog("Rename ok");
602 // Rename docs starting with $oldref with $newref
603 $listoffiles = dol_dir_list($conf->hrm->dir_output.'/evaluation/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
604 foreach ($listoffiles as $fileentry) {
605 $dirsource = $fileentry['name'];
606 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
607 $dirsource = $fileentry['path'].'/'.$dirsource;
608 $dirdest = $fileentry['path'].'/'.$dirdest;
609 @rename($dirsource, $dirdest);
610 }
611 }
612 }
613 }
614 }
615
616 // Set new ref and current status
617 if (!$error) {
618 $this->ref = $num;
619 $this->status = self::STATUS_VALIDATED;
620 }
621
622 if (!$error) {
623 $this->db->commit();
624 return 1;
625 } else {
626 $this->db->rollback();
627 return -1;
628 }
629 }
630
637 public function getLastEvaluationForUser($fk_user)
638 {
639 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."hrm_evaluation ";
640 $sql .= "WHERE fk_user=".((int) $fk_user)." ";
641 $sql .= "ORDER BY date_eval DESC ";
642 $sql .= "LIMIT 1 ";
643
644 $res = $this->db->query($sql);
645 if (!$res) {
646 dol_print_error($this->db);
647 }
648
649 $Tab = $this->db->fetch_object($res);
650
651 if (empty($Tab)) {
652 return null;
653 } else {
654 $evaluation = new Evaluation($this->db);
655 $evaluation->fetch($Tab->rowid);
656
657 return $evaluation;
658 }
659 }
660
661
669 public function setDraft($user, $notrigger = 0)
670 {
671 // Protection
672 if ($this->status <= self::STATUS_DRAFT) {
673 return 0;
674 }
675
676 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'HRM_EVALUATION_UNVALIDATE');
677 }
678
686 public function cancel($user, $notrigger = 0)
687 {
688 // Protection
689 if ($this->status != self::STATUS_VALIDATED) {
690 return 0;
691 }
692
693 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'HRM_EVALUATION_CANCEL');
694 }
695
703 public function reopen($user, $notrigger = 0)
704 {
705 // Protection
706 if ($this->status != self::STATUS_CANCELED) {
707 return 0;
708 }
709
710 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'HRM_EVALUATION_REOPEN');
711 }
712
723 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
724 {
725 global $conf, $langs, $hookmanager;
726
727 if (!empty($conf->dol_no_mouse_hover)) {
728 $notooltip = 1; // Force disable tooltips
729 }
730
731 $result = '';
732
733 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Evaluation").'</u>';
734 if (isset($this->status)) {
735 $label .= ' '.$this->getLibStatut(5);
736 }
737 $label .= '<br>';
738 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
739
740 $url = dol_buildpath('/hrm/evaluation_card.php', 1).'?id='.$this->id;
741
742 if ($option != 'nolink') {
743 // Add param to save lastsearch_values or not
744 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
745 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
746 $add_save_lastsearch_values = 1;
747 }
748 if ($add_save_lastsearch_values) {
749 $url .= '&save_lastsearch_values=1';
750 }
751 }
752
753 $linkclose = '';
754 if (empty($notooltip)) {
755 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
756 $label = $langs->trans("ShowEvaluation");
757 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
758 }
759 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
760 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
761 } else {
762 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
763 }
764
765 if ($option == 'nolink') {
766 $linkstart = '<span';
767 } else {
768 $linkstart = '<a href="'.$url.'"';
769 }
770 $linkstart .= $linkclose.'>';
771 if ($option == 'nolink') {
772 $linkend = '</span>';
773 } else {
774 $linkend = '</a>';
775 }
776
777 $result .= $linkstart;
778
779 if (empty($this->showphoto_on_popup)) {
780 if ($withpicto) {
781 $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);
782 }
783 } else {
784 if ($withpicto) {
785 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
786
787 list($class, $module) = explode('@', $this->picto);
788 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
789 $filearray = dol_dir_list($upload_dir, "files");
790 $filename = $filearray[0]['name'];
791 if (!empty($filename)) {
792 $pospoint = strpos($filearray[0]['name'], '.');
793
794 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.dol_substr($filename, 0, $pospoint).'_mini'.dol_substr($filename, $pospoint);
795 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
796 $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>';
797 } else {
798 $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>';
799 }
800
801 $result .= '</div>';
802 } else {
803 $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);
804 }
805 }
806 }
807
808 if ($withpicto != 2) {
809 $result .= $this->ref;
810 }
811
812 $result .= $linkend;
813 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
814
815 global $action, $hookmanager;
816 $hookmanager->initHooks(array('evaluationdao'));
817 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
818 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
819 if ($reshook > 0) {
820 $result = $hookmanager->resPrint;
821 } else {
822 $result .= $hookmanager->resPrint;
823 }
824
825 return $result;
826 }
827
834 public function getLibStatut($mode = 0)
835 {
836 return $this->LibStatut($this->status, $mode);
837 }
838
839 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
847 public function LibStatut($status, $mode = 0)
848 {
849 // phpcs:enable
850 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
851 global $langs;
852 //$langs->load("hrm");
853 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
854 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
855 $this->labelStatus[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Closed');
856 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
857 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
858 $this->labelStatusShort[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Closed');
859 }
860
861 $statusType = 'status'.$status;
862 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
863 if ($status == self::STATUS_CANCELED) {
864 $statusType = 'status6';
865 }
866
867 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
868 }
869
876 public function info($id)
877 {
878 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
879 $sql .= ' fk_user_creat, fk_user_modif';
880 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
881 $sql .= ' WHERE t.rowid = '.((int) $id);
882 $result = $this->db->query($sql);
883 if ($result) {
884 if ($this->db->num_rows($result)) {
885 $obj = $this->db->fetch_object($result);
886
887 $this->id = $obj->rowid;
888
889 $this->user_creation_id = $obj->fk_user_creat;
890 $this->user_modification_id = $obj->fk_user_modif;
891 $this->date_creation = $this->db->jdate($obj->datec);
892 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
893 }
894
895 $this->db->free($result);
896 } else {
897 dol_print_error($this->db);
898 }
899 }
900
907 public function initAsSpecimen()
908 {
909 // Set here init that are not commonf fields
910 // $this->property1 = ...
911 // $this->property2 = ...
912
913 return $this->initAsSpecimenCommon();
914 }
915
921 public function getLinesArray()
922 {
923 $this->lines = array();
924
925 $objectline = new EvaluationLine($this->db);
926 $result = $objectline->fetchAll('ASC', '', 0, 0, '(fk_evaluation:=:'.((int) $this->id).')');
927
928 if (is_numeric($result)) {
929 $this->setErrorsFromObject($objectline);
930 return $result;
931 } else {
932 $this->lines = $result;
933 return $this->lines;
934 }
935 }
936
942 public function getNextNumRef()
943 {
944 global $langs, $conf;
945 $langs->load("hrm");
946
947 if (!getDolGlobalString('HRMTEST_EVALUATION_ADDON')) {
948 $conf->global->HRMTEST_EVALUATION_ADDON = 'mod_evaluation_standard';
949 }
950
951 if (getDolGlobalString('HRMTEST_EVALUATION_ADDON')) {
952 $mybool = false;
953
954 $file = getDolGlobalString('HRMTEST_EVALUATION_ADDON') . ".php";
955 $classname = getDolGlobalString('HRMTEST_EVALUATION_ADDON');
956
957 // Include file with class
958 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
959 foreach ($dirmodels as $reldir) {
960 $dir = dol_buildpath($reldir."core/modules/hrm/");
961
962 // Load file with numbering class (if found)
963 $mybool = ((bool) @include_once $dir.$file) || $mybool;
964 }
965
966 if (!$mybool) {
967 dol_print_error(null, "Failed to include file ".$file);
968 return '';
969 }
970
971 if (class_exists($classname)) {
972 $obj = new $classname();
973 '@phan-var-force ModeleNumRefEvaluation $obj';
975 $numref = $obj->getNextValue($this);
976
977 if ($numref != '' && $numref != '-1') {
978 return $numref;
979 } else {
980 $this->error = $obj->error;
981 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
982 return "";
983 }
984 } else {
985 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
986 return "";
987 }
988 } else {
989 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
990 return "";
991 }
992 }
993
1005 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1006 {
1007 global $langs;
1008
1009 $result = 0;
1010
1011 $langs->load("hrm");
1012
1013 if (!dol_strlen($modele)) {
1014 $modele = 'standard_evaluation';
1015
1016 if (!empty($this->model_pdf)) {
1017 $modele = $this->model_pdf;
1018 } elseif (getDolGlobalString('EVALUATION_ADDON_PDF')) {
1019 $modele = getDolGlobalString('EVALUATION_ADDON_PDF');
1020 }
1021 }
1022
1023 $modelpath = "core/modules/hrm/doc/";
1024
1025 if (!empty($modele)) {
1026 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1027 }
1028
1029 return $result;
1030 }
1031
1039 public function getKanbanView($option = '', $arraydata = null)
1040 {
1041 global $selected, $langs;
1042
1043 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1044
1045 $return = '<div class="box-flex-item box-flex-grow-zero">';
1046 $return .= '<div class="info-box info-box-sm">';
1047 $return .= '<span class="info-box-icon bg-infobox-action">';
1048 $return .= img_picto('', $this->picto);
1049 $return .= '</span>';
1050 $return .= '<div class="info-box-content">';
1051 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->getNomUrl(1) . '</span>';
1052 $return .= '<input class="fright" id="cb'.$this->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1053 if (!empty($arraydata['user'])) {
1054 $return .= '<br><span class="info-box-label ">'.$arraydata['user'].'</span>';
1055 }
1056 if (!empty($arraydata['job'])) {
1057 $return .= '<br><span class="info-box-label ">'.$arraydata['job'].'</span>';
1058 }
1059 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
1060 $return .= '</div>';
1061 $return .= '</div>';
1062 $return .= '</div>';
1063 return $return;
1064 }
1065}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$object ref
Definition info.php:90
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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:169
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:66
dol_now($mode='gmt')
Return date for now.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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.