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:(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 $note_public;
138 public $note_private;
142 public $fk_user_creat;
146 public $fk_user_modif;
150 public $import_key;
154 public $status;
158 public $date_eval;
162 public $fk_user;
166 public $fk_job;
167 // END MODULEBUILDER PROPERTIES
168
169
170 // If this object has a subtable with lines
171
175 public $table_element_line = 'hrm_evaluationdet';
176
180 public $fk_element = 'fk_evaluation';
181
185 public $class_element_line = 'EvaluationLine';
186
187 // /**
188 // * @var array List of child tables. To test if we can delete object.
189 // */
190 // protected $childtables = array();
191
197 protected $childtablesoncascade = array('@EvaluationLine:hrm/class/evaluationdet.class.php:fk_evaluation');
198
202 public $lines = array();
203
204
205
211 public function __construct(DoliDB $db)
212 {
213 global $conf, $langs, $user;
214
215 $this->db = $db;
216
217 $this->ismultientitymanaged = 0;
218 $this->isextrafieldmanaged = 1;
219
220 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
221 $this->fields['rowid']['visible'] = 0;
222 }
223 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
224 $this->fields['entity']['enabled'] = 0;
225 }
226
227 if (!$user->hasRight('hrm', 'evaluation', 'readall')) {
228 $this->fields['fk_user']['type'] .= ':rowid IN('.$this->db->sanitize(implode(", ", $user->getAllChildIds(1))).')';
229 }
230
231 $this->date_eval = dol_now();
232
233 // Unset fields that are disabled
234 foreach ($this->fields as $key => $val) {
235 if (isset($val['enabled']) && empty($val['enabled'])) {
236 unset($this->fields[$key]);
237 }
238 }
239
240 // Translate some data of arrayofkeyval
241 if (is_object($langs)) {
242 foreach ($this->fields as $key => $val) {
243 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
244 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
245 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
246 }
247 }
248 }
249 }
250 }
251
259 public function create(User $user, $notrigger = 0)
260 {
261 $resultcreate = $this->createCommon($user, $notrigger);
262
263 if ($resultcreate > 0) {
264 require_once DOL_DOCUMENT_ROOT . '/hrm/class/skillrank.class.php';
265 $skillRank = new SkillRank($this->db);
266 $TRequiredRanks = $skillRank->fetchAll('ASC', 't.rowid', 0, 0, '(fk_object:=:'.((int) $this->fk_job).") AND (objecttype:=:'job')");
267
268 if (is_array($TRequiredRanks) && !empty($TRequiredRanks)) {
269 $this->lines = array();
270 foreach ($TRequiredRanks as $required) {
271 $line = new EvaluationLine($this->db);
272 $line->fk_evaluation = $resultcreate;
273 $line->fk_skill = $required->fk_skill;
274 $line->required_rank = $required->rankorder;
275 $line->fk_rank = 0;
276
277 $res = $line->create($user, $notrigger);
278 if ($res > 0) {
279 $this->lines[] = $line;
280 }
281 }
282 }
283 }
284
285 return $resultcreate;
286 }
287
295 public function createFromClone(User $user, $fromid)
296 {
297 global $langs, $extrafields;
298 $error = 0;
299
300 dol_syslog(__METHOD__, LOG_DEBUG);
301
302 $object = new self($this->db);
303
304 $this->db->begin();
305
306 // Load source object
307 $result = $object->fetchCommon($fromid);
308 if ($result > 0 && !empty($object->table_element_line)) {
309 $object->fetchLines();
310 }
311
312 // get lines so they will be clone
313 //foreach($this->lines as $line)
314 // $line->fetch_optionals();
315
316 // Reset some properties
317 unset($object->id);
318 unset($object->fk_user_creat);
319 unset($object->import_key);
320
321 // Clear fields
322 if (property_exists($object, 'ref')) {
323 // @phan-suppress-next-line PhanTypeMismatchProperty
324 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
325 }
326 if (property_exists($object, 'label')) {
327 // @phan-suppress-next-line PhanTypeInvalidDimOffset
328 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
329 }
330 if (property_exists($object, 'status')) {
331 $object->status = self::STATUS_DRAFT;
332 }
333 if (property_exists($object, 'date_creation')) {
334 $object->date_creation = dol_now();
335 }
336 if (property_exists($object, 'date_modification')) {
337 $object->date_modification = null;
338 }
339 // ...
340 // Clear extrafields that are unique
341 if (is_array($object->array_options) && count($object->array_options) > 0) {
342 $extrafields->fetch_name_optionals_label($this->table_element);
343 foreach ($object->array_options as $key => $option) {
344 $shortkey = preg_replace('/options_/', '', $key);
345 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
346 //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
347 unset($object->array_options[$key]);
348 }
349 }
350 }
351
352 // Create clone
353 $object->context['createfromclone'] = 'createfromclone';
354 $result = $object->createCommon($user);
355 if ($result < 0) {
356 $error++;
358 }
359
360 if (!$error) {
361 // copy internal contacts
362 if ($this->copy_linked_contact($object, 'internal') < 0) {
363 $error++;
364 }
365 }
366
367 if (!$error) {
368 // copy external contacts if same company
369 if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
370 if ($this->copy_linked_contact($object, 'external') < 0) {
371 $error++;
372 }
373 }
374 }
375
376 unset($object->context['createfromclone']);
377
378 // End
379 if (!$error) {
380 $this->db->commit();
381 return $object;
382 } else {
383 $this->db->rollback();
384 return -1;
385 }
386 }
387
395 public function fetch($id, $ref = null)
396 {
397 $result = $this->fetchCommon($id, $ref);
398 if ($result > 0 && !empty($this->table_element_line)) {
399 $this->fetchLines();
400 }
401 return $result;
402 }
403
409 public function fetchLines()
410 {
411 $this->lines = array();
412
413 $result = $this->fetchLinesCommon();
414 return $result;
415 }
416
417
430 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
431 {
432 dol_syslog(__METHOD__, LOG_DEBUG);
433
434 $records = array();
435
436 $sql = 'SELECT ';
437 $sql .= $this->getFieldList('t');
438 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
439 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
440 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
441 } else {
442 $sql .= ' WHERE 1 = 1';
443 }
444
445 // Manage filter
446 $errormessage = '';
447 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
448 if ($errormessage) {
449 $this->errors[] = $errormessage;
450 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
451 return -1;
452 }
453
454 if (!empty($sortfield)) {
455 $sql .= $this->db->order($sortfield, $sortorder);
456 }
457 if (!empty($limit)) {
458 $sql .= ' '.$this->db->plimit($limit, $offset);
459 }
460
461 $resql = $this->db->query($sql);
462 if ($resql) {
463 $num = $this->db->num_rows($resql);
464 $i = 0;
465 while ($i < ($limit ? min($limit, $num) : $num)) {
466 $obj = $this->db->fetch_object($resql);
467
468 $record = new self($this->db);
469 $record->setVarsFromFetchObj($obj);
470
471 $records[$record->id] = $record;
472
473 $i++;
474 }
475 $this->db->free($resql);
476
477 return $records;
478 } else {
479 $this->errors[] = 'Error '.$this->db->lasterror();
480 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
481
482 return -1;
483 }
484 }
485
493 public function update(User $user, $notrigger = 0)
494 {
495 return $this->updateCommon($user, $notrigger);
496 }
497
505 public function delete(User $user, $notrigger = 0)
506 {
507 return $this->deleteCommon($user, $notrigger);
508 //return $this->deleteCommon($user, $notrigger, 1);
509 }
510
519 public function deleteLine(User $user, $idline, $notrigger = 0)
520 {
521 if ($this->status < 0) {
522 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
523 return -2;
524 }
525
526 return $this->deleteLineCommon($user, $idline, $notrigger);
527 }
528
529
537 public function validate($user, $notrigger = 0)
538 {
539 global $conf, $langs;
540
541 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
542
543 $error = 0;
544
545 // Protection
546 if ($this->status == self::STATUS_VALIDATED) {
547 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
548 return 0;
549 }
550
551
552
553 $now = dol_now();
554
555 $this->db->begin();
556
557 // Define new ref
558 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
559 $num = $this->getNextNumRef();
560 } else {
561 $num = $this->ref;
562 }
563 $this->newref = $num;
564
565 if (!empty($num)) {
566 // Validate
567 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
568 $sql .= " SET ref = '".$this->db->escape($num)."',";
569 $sql .= " status = ".self::STATUS_VALIDATED;
570 if (!empty($this->fields['date_validation'])) {
571 $sql .= ", date_validation = '".$this->db->idate($now)."'";
572 }
573 if (!empty($this->fields['fk_user_valid'])) { // @phan-suppress-current-line PhanTypeMismatchProperty
574 $sql .= ", fk_user_valid = ".((int) $user->id);
575 }
576 $sql .= " WHERE rowid = ".((int) $this->id);
577
578 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
579 $resql = $this->db->query($sql);
580 if (!$resql) {
581 dol_print_error($this->db);
582 $this->error = $this->db->lasterror();
583 $error++;
584 }
585
586 if (!$error && !$notrigger) {
587 // Call trigger
588 $result = $this->call_trigger('HRM_EVALUATION_VALIDATE', $user);
589 if ($result < 0) {
590 $error++;
591 }
592 // End call triggers
593 }
594 }
595
596 if (!$error) {
597 $this->oldref = $this->ref;
598
599 // Rename directory if dir was a temporary ref
600 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
601 // Now we rename also files into index
602 $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)."'";
603 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'evaluation/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
604 $resql = $this->db->query($sql);
605 if (!$resql) {
606 $error++;
607 $this->error = $this->db->lasterror();
608 }
609 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'evaluation/".$this->db->escape($this->newref)."'";
610 $sql .= " WHERE filepath = 'evaluation/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
611 $resql = $this->db->query($sql);
612 if (!$resql) {
613 $error++;
614 $this->error = $this->db->lasterror();
615 }
616
617 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
618 $oldref = dol_sanitizeFileName($this->ref);
619 $newref = dol_sanitizeFileName($num);
620 $dirsource = $conf->hrm->dir_output.'/evaluation/'.$oldref;
621 $dirdest = $conf->hrm->dir_output.'/evaluation/'.$newref;
622 if (!$error && file_exists($dirsource)) {
623 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
624
625 if (@rename($dirsource, $dirdest)) {
626 dol_syslog("Rename ok");
627 // Rename docs starting with $oldref with $newref
628 $listoffiles = dol_dir_list($conf->hrm->dir_output.'/evaluation/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
629 foreach ($listoffiles as $fileentry) {
630 $dirsource = $fileentry['name'];
631 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
632 $dirsource = $fileentry['path'].'/'.$dirsource;
633 $dirdest = $fileentry['path'].'/'.$dirdest;
634 @rename($dirsource, $dirdest);
635 }
636 }
637 }
638 }
639 }
640
641 // Set new ref and current status
642 if (!$error) {
643 $this->ref = $num;
644 $this->status = self::STATUS_VALIDATED;
645 }
646
647 if (!$error) {
648 $this->db->commit();
649 return 1;
650 } else {
651 $this->db->rollback();
652 return -1;
653 }
654 }
655
662 public function getLastEvaluationForUser($fk_user)
663 {
664 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."hrm_evaluation ";
665 $sql .= "WHERE fk_user=".((int) $fk_user)." ";
666 $sql .= "ORDER BY date_eval DESC ";
667 $sql .= "LIMIT 1 ";
668
669 $res = $this->db->query($sql);
670 if (!$res) {
671 dol_print_error($this->db);
672 }
673
674 $Tab = $this->db->fetch_object($res);
675
676 if (empty($Tab)) {
677 return null;
678 } else {
679 $evaluation = new Evaluation($this->db);
680 $evaluation->fetch($Tab->rowid);
681
682 return $evaluation;
683 }
684 }
685
686
694 public function setDraft($user, $notrigger = 0)
695 {
696 // Protection
697 if ($this->status <= self::STATUS_DRAFT) {
698 return 0;
699 }
700
701 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'HRM_EVALUATION_UNVALIDATE');
702 }
703
711 public function cancel($user, $notrigger = 0)
712 {
713 // Protection
714 if ($this->status != self::STATUS_VALIDATED) {
715 return 0;
716 }
717
718 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'HRM_EVALUATION_CANCEL');
719 }
720
728 public function reopen($user, $notrigger = 0)
729 {
730 // Protection
731 if ($this->status != self::STATUS_CANCELED) {
732 return 0;
733 }
734
735 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'HRM_EVALUATION_REOPEN');
736 }
737
748 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
749 {
750 global $conf, $langs, $hookmanager;
751
752 if (!empty($conf->dol_no_mouse_hover)) {
753 $notooltip = 1; // Force disable tooltips
754 }
755
756 $result = '';
757
758 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Evaluation").'</u>';
759 if (isset($this->status)) {
760 $label .= ' '.$this->getLibStatut(5);
761 }
762 $label .= '<br>';
763 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
764
765 $url = dol_buildpath('/hrm/evaluation_card.php', 1).'?id='.$this->id;
766
767 if ($option != 'nolink') {
768 // Add param to save lastsearch_values or not
769 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
770 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
771 $add_save_lastsearch_values = 1;
772 }
773 if ($add_save_lastsearch_values) {
774 $url .= '&save_lastsearch_values=1';
775 }
776 }
777
778 $linkclose = '';
779 if (empty($notooltip)) {
780 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
781 $label = $langs->trans("ShowEvaluation");
782 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
783 }
784 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
785 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
786 } else {
787 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
788 }
789
790 if ($option == 'nolink') {
791 $linkstart = '<span';
792 } else {
793 $linkstart = '<a href="'.$url.'"';
794 }
795 $linkstart .= $linkclose.'>';
796 if ($option == 'nolink') {
797 $linkend = '</span>';
798 } else {
799 $linkend = '</a>';
800 }
801
802 $result .= $linkstart;
803
804 if (empty($this->showphoto_on_popup)) {
805 if ($withpicto) {
806 $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);
807 }
808 } else {
809 if ($withpicto) {
810 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
811
812 list($class, $module) = explode('@', $this->picto);
813 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
814 $filearray = dol_dir_list($upload_dir, "files");
815 $filename = $filearray[0]['name'];
816 if (!empty($filename)) {
817 $pospoint = strpos($filearray[0]['name'], '.');
818
819 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
820 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
821 $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>';
822 } else {
823 $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>';
824 }
825
826 $result .= '</div>';
827 } else {
828 $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);
829 }
830 }
831 }
832
833 if ($withpicto != 2) {
834 $result .= $this->ref;
835 }
836
837 $result .= $linkend;
838 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
839
840 global $action, $hookmanager;
841 $hookmanager->initHooks(array('evaluationdao'));
842 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
843 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
844 if ($reshook > 0) {
845 $result = $hookmanager->resPrint;
846 } else {
847 $result .= $hookmanager->resPrint;
848 }
849
850 return $result;
851 }
852
859 public function getLibStatut($mode = 0)
860 {
861 return $this->LibStatut($this->status, $mode);
862 }
863
864 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
872 public function LibStatut($status, $mode = 0)
873 {
874 // phpcs:enable
875 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
876 global $langs;
877 //$langs->load("hrm");
878 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
879 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
880 $this->labelStatus[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Closed');
881 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
882 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
883 $this->labelStatusShort[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Closed');
884 }
885
886 $statusType = 'status'.$status;
887 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
888 if ($status == self::STATUS_CANCELED) {
889 $statusType = 'status6';
890 }
891
892 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
893 }
894
901 public function info($id)
902 {
903 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
904 $sql .= ' fk_user_creat, fk_user_modif';
905 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
906 $sql .= ' WHERE t.rowid = '.((int) $id);
907 $result = $this->db->query($sql);
908 if ($result) {
909 if ($this->db->num_rows($result)) {
910 $obj = $this->db->fetch_object($result);
911
912 $this->id = $obj->rowid;
913
914 $this->user_creation_id = $obj->fk_user_creat;
915 $this->user_modification_id = $obj->fk_user_modif;
916 $this->date_creation = $this->db->jdate($obj->datec);
917 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
918 }
919
920 $this->db->free($result);
921 } else {
922 dol_print_error($this->db);
923 }
924 }
925
932 public function initAsSpecimen()
933 {
934 // Set here init that are not commonf fields
935 // $this->property1 = ...
936 // $this->property2 = ...
937
938 return $this->initAsSpecimenCommon();
939 }
940
946 public function getLinesArray()
947 {
948 $this->lines = array();
949
950 $objectline = new EvaluationLine($this->db);
951 $result = $objectline->fetchAll('ASC', '', 0, 0, '(fk_evaluation:=:'.((int) $this->id).')');
952
953 if (is_numeric($result)) {
954 $this->setErrorsFromObject($objectline);
955 return $result;
956 } else {
957 $this->lines = $result;
958 return $this->lines;
959 }
960 }
961
967 public function getNextNumRef()
968 {
969 global $langs, $conf;
970 $langs->load("hrm");
971
972 if (!getDolGlobalString('HRMTEST_EVALUATION_ADDON')) {
973 $conf->global->HRMTEST_EVALUATION_ADDON = 'mod_evaluation_standard';
974 }
975
976 if (getDolGlobalString('HRMTEST_EVALUATION_ADDON')) {
977 $mybool = false;
978
979 $file = getDolGlobalString('HRMTEST_EVALUATION_ADDON') . ".php";
980 $classname = getDolGlobalString('HRMTEST_EVALUATION_ADDON');
981
982 // Include file with class
983 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
984 foreach ($dirmodels as $reldir) {
985 $dir = dol_buildpath($reldir."core/modules/hrm/");
986
987 // Load file with numbering class (if found)
988 $mybool = ((bool) @include_once $dir.$file) || $mybool;
989 }
990
991 if (!$mybool) {
992 dol_print_error(null, "Failed to include file ".$file);
993 return '';
994 }
995
996 if (class_exists($classname)) {
997 $obj = new $classname();
998 '@phan-var-force ModeleNumRefEvaluation $obj';
999 $numref = $obj->getNextValue($this);
1000
1001 if ($numref != '' && $numref != '-1') {
1002 return $numref;
1003 } else {
1004 $this->error = $obj->error;
1005 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1006 return "";
1007 }
1008 } else {
1009 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
1010 return "";
1011 }
1012 } else {
1013 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1014 return "";
1015 }
1016 }
1017
1029 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1030 {
1031 global $conf, $langs;
1032
1033 $result = 0;
1034
1035 $langs->load("hrm");
1036
1037 if (!dol_strlen($modele)) {
1038 $modele = 'standard';
1039
1040 if (!empty($this->model_pdf)) {
1041 $modele = $this->model_pdf;
1042 } elseif (getDolGlobalString('EVALUATION_ADDON_PDF')) {
1043 $modele = getDolGlobalString('EVALUATION_ADDON_PDF');
1044 }
1045 }
1046
1047 $modelpath = "core/modules/hrm/doc/";
1048
1049 if (!empty($modele)) {
1050 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1051 }
1052
1053 return $result;
1054 }
1055
1063 public function getKanbanView($option = '', $arraydata = null)
1064 {
1065 global $selected, $langs;
1066
1067 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1068
1069 $return = '<div class="box-flex-item box-flex-grow-zero">';
1070 $return .= '<div class="info-box info-box-sm">';
1071 $return .= '<span class="info-box-icon bg-infobox-action">';
1072 $return .= img_picto('', $this->picto);
1073 $return .= '</span>';
1074 $return .= '<div class="info-box-content">';
1075 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1) : $this->ref).'</span>';
1076 $return .= '<input class="fright" id="cb'.$this->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1077 if (!empty($arraydata['user'])) {
1078 $return .= '<br><span class="info-box-label ">'.$arraydata['user'].'</span>';
1079 }
1080 if (!empty($arraydata['job'])) {
1081 $return .= '<br><span class="info-box-label ">'.$arraydata['job'].'</span>';
1082 }
1083 if (method_exists($this, 'getLibStatut')) {
1084 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
1085 }
1086 $return .= '</div>';
1087 $return .= '</div>';
1088 $return .= '</div>';
1089 return $return;
1090 }
1091}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
$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 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:162
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 a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.