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