dolibarr 20.0.2
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 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2024 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', '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 );
114 public $rowid;
115 public $ref;
116 public $label;
117 public $description;
118 public $note_public;
119 public $note_private;
120 public $date_creation;
121 public $fk_user_creat;
122 public $fk_user_modif;
123 public $import_key;
124 public $status;
125 public $date_eval;
126 public $fk_user;
127 public $fk_job;
128 // END MODULEBUILDER PROPERTIES
129
130
131 // If this object has a subtable with lines
132
136 public $table_element_line = 'hrm_evaluationdet';
137
141 public $fk_element = 'fk_evaluation';
142
146 public $class_element_line = 'EvaluationLine';
147
148 // /**
149 // * @var array List of child tables. To test if we can delete object.
150 // */
151 // protected $childtables = array();
152
158 protected $childtablesoncascade = array('@EvaluationLine:hrm/class/evaluationdet.class.php:fk_evaluation');
159
163 public $lines = array();
164
165
166
172 public function __construct(DoliDB $db)
173 {
174 global $conf, $langs, $user;
175
176 $this->db = $db;
177
178 $this->ismultientitymanaged = 0;
179 $this->isextrafieldmanaged = 1;
180
181 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
182 $this->fields['rowid']['visible'] = 0;
183 }
184 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
185 $this->fields['entity']['enabled'] = 0;
186 }
187
188 if (!$user->hasRight('hrm', 'evaluation', 'readall')) {
189 $this->fields['fk_user']['type'] .= ':rowid IN('.$this->db->sanitize(implode(", ", $user->getAllChildIds(1))).')';
190 }
191
192 $this->date_eval = dol_now();
193
194 // Unset fields that are disabled
195 foreach ($this->fields as $key => $val) {
196 if (isset($val['enabled']) && empty($val['enabled'])) {
197 unset($this->fields[$key]);
198 }
199 }
200
201 // Translate some data of arrayofkeyval
202 if (is_object($langs)) {
203 foreach ($this->fields as $key => $val) {
204 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
205 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
206 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
207 }
208 }
209 }
210 }
211 }
212
220 public function create(User $user, $notrigger = 0)
221 {
222 $resultcreate = $this->createCommon($user, $notrigger);
223
224 if ($resultcreate > 0) {
225 require_once DOL_DOCUMENT_ROOT . '/hrm/class/skillrank.class.php';
226 $skillRank = new SkillRank($this->db);
227 $TRequiredRanks = $skillRank->fetchAll('ASC', 't.rowid', 0, 0, '(fk_object:=:'.((int) $this->fk_job).") AND (objecttype:=:'job')");
228
229 if (is_array($TRequiredRanks) && !empty($TRequiredRanks)) {
230 $this->lines = array();
231 foreach ($TRequiredRanks as $required) {
232 $line = new EvaluationLine($this->db);
233 $line->fk_evaluation = $resultcreate;
234 $line->fk_skill = $required->fk_skill;
235 $line->required_rank = $required->rankorder;
236 $line->fk_rank = 0;
237
238 $res = $line->create($user, $notrigger);
239 if ($res > 0) {
240 $this->lines[] = $line;
241 }
242 }
243 }
244 }
245
246 return $resultcreate;
247 }
248
256 public function createFromClone(User $user, $fromid)
257 {
258 global $langs, $extrafields;
259 $error = 0;
260
261 dol_syslog(__METHOD__, LOG_DEBUG);
262
263 $object = new self($this->db);
264
265 $this->db->begin();
266
267 // Load source object
268 $result = $object->fetchCommon($fromid);
269 if ($result > 0 && !empty($object->table_element_line)) {
270 $object->fetchLines();
271 }
272
273 // get lines so they will be clone
274 //foreach($this->lines as $line)
275 // $line->fetch_optionals();
276
277 // Reset some properties
278 unset($object->id);
279 unset($object->fk_user_creat);
280 unset($object->import_key);
281
282 // Clear fields
283 if (property_exists($object, 'ref')) {
284 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
285 }
286 if (property_exists($object, 'label')) {
287 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
288 }
289 if (property_exists($object, 'status')) {
290 $object->status = self::STATUS_DRAFT;
291 }
292 if (property_exists($object, 'date_creation')) {
293 $object->date_creation = dol_now();
294 }
295 if (property_exists($object, 'date_modification')) {
296 $object->date_modification = null;
297 }
298 // ...
299 // Clear extrafields that are unique
300 if (is_array($object->array_options) && count($object->array_options) > 0) {
301 $extrafields->fetch_name_optionals_label($this->table_element);
302 foreach ($object->array_options as $key => $option) {
303 $shortkey = preg_replace('/options_/', '', $key);
304 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
305 //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
306 unset($object->array_options[$key]);
307 }
308 }
309 }
310
311 // Create clone
312 $object->context['createfromclone'] = 'createfromclone';
313 $result = $object->createCommon($user);
314 if ($result < 0) {
315 $error++;
317 }
318
319 if (!$error) {
320 // copy internal contacts
321 if ($this->copy_linked_contact($object, 'internal') < 0) {
322 $error++;
323 }
324 }
325
326 if (!$error) {
327 // copy external contacts if same company
328 if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
329 if ($this->copy_linked_contact($object, 'external') < 0) {
330 $error++;
331 }
332 }
333 }
334
335 unset($object->context['createfromclone']);
336
337 // End
338 if (!$error) {
339 $this->db->commit();
340 return $object;
341 } else {
342 $this->db->rollback();
343 return -1;
344 }
345 }
346
354 public function fetch($id, $ref = null)
355 {
356 $result = $this->fetchCommon($id, $ref);
357 if ($result > 0 && !empty($this->table_element_line)) {
358 $this->fetchLines();
359 }
360 return $result;
361 }
362
368 public function fetchLines()
369 {
370 $this->lines = array();
371
372 $result = $this->fetchLinesCommon();
373 return $result;
374 }
375
376
389 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
390 {
391 dol_syslog(__METHOD__, LOG_DEBUG);
392
393 $records = array();
394
395 $sql = 'SELECT ';
396 $sql .= $this->getFieldList('t');
397 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
398 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
399 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
400 } else {
401 $sql .= ' WHERE 1 = 1';
402 }
403
404 // Manage filter
405 $errormessage = '';
406 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
407 if ($errormessage) {
408 $this->errors[] = $errormessage;
409 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
410 return -1;
411 }
412
413 if (!empty($sortfield)) {
414 $sql .= $this->db->order($sortfield, $sortorder);
415 }
416 if (!empty($limit)) {
417 $sql .= ' '.$this->db->plimit($limit, $offset);
418 }
419
420 $resql = $this->db->query($sql);
421 if ($resql) {
422 $num = $this->db->num_rows($resql);
423 $i = 0;
424 while ($i < ($limit ? min($limit, $num) : $num)) {
425 $obj = $this->db->fetch_object($resql);
426
427 $record = new self($this->db);
428 $record->setVarsFromFetchObj($obj);
429
430 $records[$record->id] = $record;
431
432 $i++;
433 }
434 $this->db->free($resql);
435
436 return $records;
437 } else {
438 $this->errors[] = 'Error '.$this->db->lasterror();
439 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
440
441 return -1;
442 }
443 }
444
452 public function update(User $user, $notrigger = 0)
453 {
454 return $this->updateCommon($user, $notrigger);
455 }
456
464 public function delete(User $user, $notrigger = 0)
465 {
466 return $this->deleteCommon($user, $notrigger);
467 //return $this->deleteCommon($user, $notrigger, 1);
468 }
469
478 public function deleteLine(User $user, $idline, $notrigger = 0)
479 {
480 if ($this->status < 0) {
481 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
482 return -2;
483 }
484
485 return $this->deleteLineCommon($user, $idline, $notrigger);
486 }
487
488
496 public function validate($user, $notrigger = 0)
497 {
498 global $conf, $langs;
499
500 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
501
502 $error = 0;
503
504 // Protection
505 if ($this->status == self::STATUS_VALIDATED) {
506 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
507 return 0;
508 }
509
510
511
512 $now = dol_now();
513
514 $this->db->begin();
515
516 // Define new ref
517 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
518 $num = $this->getNextNumRef();
519 } else {
520 $num = $this->ref;
521 }
522 $this->newref = $num;
523
524 if (!empty($num)) {
525 // Validate
526 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
527 $sql .= " SET ref = '".$this->db->escape($num)."',";
528 $sql .= " status = ".self::STATUS_VALIDATED;
529 if (!empty($this->fields['date_validation'])) {
530 $sql .= ", date_validation = '".$this->db->idate($now)."'";
531 }
532 if (!empty($this->fields['fk_user_valid'])) {
533 $sql .= ", fk_user_valid = ".((int) $user->id);
534 }
535 $sql .= " WHERE rowid = ".((int) $this->id);
536
537 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
538 $resql = $this->db->query($sql);
539 if (!$resql) {
540 dol_print_error($this->db);
541 $this->error = $this->db->lasterror();
542 $error++;
543 }
544
545 if (!$error && !$notrigger) {
546 // Call trigger
547 $result = $this->call_trigger('HRM_EVALUATION_VALIDATE', $user);
548 if ($result < 0) {
549 $error++;
550 }
551 // End call triggers
552 }
553 }
554
555 if (!$error) {
556 $this->oldref = $this->ref;
557
558 // Rename directory if dir was a temporary ref
559 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
560 // Now we rename also files into index
561 $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)."'";
562 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'evaluation/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
563 $resql = $this->db->query($sql);
564 if (!$resql) {
565 $error++;
566 $this->error = $this->db->lasterror();
567 }
568 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'evaluation/".$this->db->escape($this->newref)."'";
569 $sql .= " WHERE filepath = 'evaluation/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
570 $resql = $this->db->query($sql);
571 if (!$resql) {
572 $error++;
573 $this->error = $this->db->lasterror();
574 }
575
576 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
577 $oldref = dol_sanitizeFileName($this->ref);
578 $newref = dol_sanitizeFileName($num);
579 $dirsource = $conf->hrm->dir_output.'/evaluation/'.$oldref;
580 $dirdest = $conf->hrm->dir_output.'/evaluation/'.$newref;
581 if (!$error && file_exists($dirsource)) {
582 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
583
584 if (@rename($dirsource, $dirdest)) {
585 dol_syslog("Rename ok");
586 // Rename docs starting with $oldref with $newref
587 $listoffiles = dol_dir_list($conf->hrm->dir_output.'/evaluation/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
588 foreach ($listoffiles as $fileentry) {
589 $dirsource = $fileentry['name'];
590 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
591 $dirsource = $fileentry['path'].'/'.$dirsource;
592 $dirdest = $fileentry['path'].'/'.$dirdest;
593 @rename($dirsource, $dirdest);
594 }
595 }
596 }
597 }
598 }
599
600 // Set new ref and current status
601 if (!$error) {
602 $this->ref = $num;
603 $this->status = self::STATUS_VALIDATED;
604 }
605
606 if (!$error) {
607 $this->db->commit();
608 return 1;
609 } else {
610 $this->db->rollback();
611 return -1;
612 }
613 }
614
621 public function getLastEvaluationForUser($fk_user)
622 {
623 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."hrm_evaluation ";
624 $sql .= "WHERE fk_user=".((int) $fk_user)." ";
625 $sql .= "ORDER BY date_eval DESC ";
626 $sql .= "LIMIT 1 ";
627
628 $res = $this->db->query($sql);
629 if (!$res) {
630 dol_print_error($this->db);
631 }
632
633 $Tab = $this->db->fetch_object($res);
634
635 if (empty($Tab)) {
636 return null;
637 } else {
638 $evaluation = new Evaluation($this->db);
639 $evaluation->fetch($Tab->rowid);
640
641 return $evaluation;
642 }
643 }
644
645
653 public function setDraft($user, $notrigger = 0)
654 {
655 // Protection
656 if ($this->status <= self::STATUS_DRAFT) {
657 return 0;
658 }
659
660 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'HRM_EVALUATION_UNVALIDATE');
661 }
662
670 public function cancel($user, $notrigger = 0)
671 {
672 // Protection
673 if ($this->status != self::STATUS_VALIDATED) {
674 return 0;
675 }
676
677 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'HRM_EVALUATION_CANCEL');
678 }
679
687 public function reopen($user, $notrigger = 0)
688 {
689 // Protection
690 if ($this->status != self::STATUS_CANCELED) {
691 return 0;
692 }
693
694 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'HRM_EVALUATION_REOPEN');
695 }
696
707 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
708 {
709 global $conf, $langs, $hookmanager;
710
711 if (!empty($conf->dol_no_mouse_hover)) {
712 $notooltip = 1; // Force disable tooltips
713 }
714
715 $result = '';
716
717 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Evaluation").'</u>';
718 if (isset($this->status)) {
719 $label .= ' '.$this->getLibStatut(5);
720 }
721 $label .= '<br>';
722 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
723
724 $url = dol_buildpath('/hrm/evaluation_card.php', 1).'?id='.$this->id;
725
726 if ($option != 'nolink') {
727 // Add param to save lastsearch_values or not
728 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
729 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
730 $add_save_lastsearch_values = 1;
731 }
732 if ($add_save_lastsearch_values) {
733 $url .= '&save_lastsearch_values=1';
734 }
735 }
736
737 $linkclose = '';
738 if (empty($notooltip)) {
739 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
740 $label = $langs->trans("ShowEvaluation");
741 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
742 }
743 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
744 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
745 } else {
746 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
747 }
748
749 if ($option == 'nolink') {
750 $linkstart = '<span';
751 } else {
752 $linkstart = '<a href="'.$url.'"';
753 }
754 $linkstart .= $linkclose.'>';
755 if ($option == 'nolink') {
756 $linkend = '</span>';
757 } else {
758 $linkend = '</a>';
759 }
760
761 $result .= $linkstart;
762
763 if (empty($this->showphoto_on_popup)) {
764 if ($withpicto) {
765 $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);
766 }
767 } else {
768 if ($withpicto) {
769 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
770
771 list($class, $module) = explode('@', $this->picto);
772 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
773 $filearray = dol_dir_list($upload_dir, "files");
774 $filename = $filearray[0]['name'];
775 if (!empty($filename)) {
776 $pospoint = strpos($filearray[0]['name'], '.');
777
778 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
779 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
780 $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>';
781 } else {
782 $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>';
783 }
784
785 $result .= '</div>';
786 } else {
787 $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);
788 }
789 }
790 }
791
792 if ($withpicto != 2) {
793 $result .= $this->ref;
794 }
795
796 $result .= $linkend;
797 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
798
799 global $action, $hookmanager;
800 $hookmanager->initHooks(array('evaluationdao'));
801 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
802 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
803 if ($reshook > 0) {
804 $result = $hookmanager->resPrint;
805 } else {
806 $result .= $hookmanager->resPrint;
807 }
808
809 return $result;
810 }
811
818 public function getLibStatut($mode = 0)
819 {
820 return $this->LibStatut($this->status, $mode);
821 }
822
823 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
831 public function LibStatut($status, $mode = 0)
832 {
833 // phpcs:enable
834 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
835 global $langs;
836 //$langs->load("hrm");
837 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
838 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
839 $this->labelStatus[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Closed');
840 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
841 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
842 $this->labelStatusShort[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Closed');
843 }
844
845 $statusType = 'status'.$status;
846 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
847 if ($status == self::STATUS_CANCELED) {
848 $statusType = 'status6';
849 }
850
851 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
852 }
853
860 public function info($id)
861 {
862 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
863 $sql .= ' fk_user_creat, fk_user_modif';
864 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
865 $sql .= ' WHERE t.rowid = '.((int) $id);
866 $result = $this->db->query($sql);
867 if ($result) {
868 if ($this->db->num_rows($result)) {
869 $obj = $this->db->fetch_object($result);
870
871 $this->id = $obj->rowid;
872
873 $this->user_creation_id = $obj->fk_user_creat;
874 $this->user_modification_id = $obj->fk_user_modif;
875 $this->date_creation = $this->db->jdate($obj->datec);
876 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
877 }
878
879 $this->db->free($result);
880 } else {
881 dol_print_error($this->db);
882 }
883 }
884
891 public function initAsSpecimen()
892 {
893 // Set here init that are not commonf fields
894 // $this->property1 = ...
895 // $this->property2 = ...
896
897 return $this->initAsSpecimenCommon();
898 }
899
905 public function getLinesArray()
906 {
907 $this->lines = array();
908
909 $objectline = new EvaluationLine($this->db);
910 $result = $objectline->fetchAll('ASC', '', 0, 0, '(fk_evaluation:=:'.((int) $this->id).')');
911
912 if (is_numeric($result)) {
913 $this->setErrorsFromObject($objectline);
914 return $result;
915 } else {
916 $this->lines = $result;
917 return $this->lines;
918 }
919 }
920
926 public function getNextNumRef()
927 {
928 global $langs, $conf;
929 $langs->load("hrm");
930
931 if (!getDolGlobalString('HRMTEST_EVALUATION_ADDON')) {
932 $conf->global->HRMTEST_EVALUATION_ADDON = 'mod_evaluation_standard';
933 }
934
935 if (getDolGlobalString('HRMTEST_EVALUATION_ADDON')) {
936 $mybool = false;
937
938 $file = getDolGlobalString('HRMTEST_EVALUATION_ADDON') . ".php";
939 $classname = getDolGlobalString('HRMTEST_EVALUATION_ADDON');
940
941 // Include file with class
942 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
943 foreach ($dirmodels as $reldir) {
944 $dir = dol_buildpath($reldir."core/modules/hrm/");
945
946 // Load file with numbering class (if found)
947 $mybool = ((bool) @include_once $dir.$file) || $mybool;
948 }
949
950 if ($mybool === false) {
951 dol_print_error(null, "Failed to include file ".$file);
952 return '';
953 }
954
955 if (class_exists($classname)) {
956 $obj = new $classname();
957 $numref = $obj->getNextValue($this);
958
959 if ($numref != '' && $numref != '-1') {
960 return $numref;
961 } else {
962 $this->error = $obj->error;
963 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
964 return "";
965 }
966 } else {
967 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
968 return "";
969 }
970 } else {
971 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
972 return "";
973 }
974 }
975
987 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
988 {
989 global $conf, $langs;
990
991 $result = 0;
992
993 $langs->load("hrm");
994
995 if (!dol_strlen($modele)) {
996 $modele = 'standard';
997
998 if (!empty($this->model_pdf)) {
999 $modele = $this->model_pdf;
1000 } elseif (getDolGlobalString('EVALUATION_ADDON_PDF')) {
1001 $modele = getDolGlobalString('EVALUATION_ADDON_PDF');
1002 }
1003 }
1004
1005 $modelpath = "core/modules/hrm/doc/";
1006
1007 if (!empty($modele)) {
1008 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1009 }
1010
1011 return $result;
1012 }
1013
1021 public function getKanbanView($option = '', $arraydata = null)
1022 {
1023 global $selected, $langs;
1024
1025 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1026
1027 $return = '<div class="box-flex-item box-flex-grow-zero">';
1028 $return .= '<div class="info-box info-box-sm">';
1029 $return .= '<span class="info-box-icon bg-infobox-action">';
1030 $return .= img_picto('', $this->picto);
1031 $return .= '</span>';
1032 $return .= '<div class="info-box-content">';
1033 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1) : $this->ref).'</span>';
1034 $return .= '<input class="fright" id="cb'.$this->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1035 if (!empty($arraydata['user'])) {
1036 $return .= '<br><span class="info-box-label ">'.$arraydata['user'].'</span>';
1037 }
1038 if (!empty($arraydata['job'])) {
1039 $return .= '<br><span class="info-box-label ">'.$arraydata['job'].'</span>';
1040 }
1041 if (method_exists($this, 'getLibStatut')) {
1042 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
1043 }
1044 $return .= '</div>';
1045 $return .= '</div>';
1046 $return .= '</div>';
1047 return $return;
1048 }
1049}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition security.php:637
$object ref
Definition info.php:79
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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
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.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
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 clicable 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.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:63
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.