dolibarr  21.0.0-alpha
hrm_evaluation.lib.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
3  * Copyright (C) 2021 Greg Rastklan <greg.rastklan@atm-consulting.fr>
4  * Copyright (C) 2021 Jean-Pascal BOUDET <jean-pascal.boudet@atm-consulting.fr>
5  * Copyright (C) 2021 Grégory BLEMAND <gregory.blemand@atm-consulting.fr>
6  * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
35 {
36  global $db, $langs, $conf;
37 
38  $langs->load("hrm");
39 
40  $h = 0;
41  $head = array();
42 
43  $head[$h][0] = dol_buildpath("/hrm/evaluation_card.php", 1).'?id='.$object->id;
44  $head[$h][1] = $langs->trans("EvaluationCard");
45  $head[$h][2] = 'card';
46  $h++;
47 
48  if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
49  $nbNote = 0;
50  if (!empty($object->note_private)) {
51  $nbNote++;
52  }
53  if (!empty($object->note_public)) {
54  $nbNote++;
55  }
56  $head[$h][0] = dol_buildpath('/hrm/evaluation_note.php', 1).'?id='.$object->id;
57  $head[$h][1] = $langs->trans('Notes');
58  if ($nbNote > 0) {
59  $head[$h][1] .= (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') ? '<span class="badge marginleftonlyshort">'.$nbNote.'</span>' : '');
60  }
61  $head[$h][2] = 'note';
62  $h++;
63  }
64 
65  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
66  require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
67  $upload_dir = $conf->hrm->dir_output."/evaluation/".dol_sanitizeFileName($object->ref);
68  $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
69  $nbLinks = Link::count($db, $object->element, $object->id);
70  $head[$h][0] = dol_buildpath("/hrm/evaluation_document.php", 1).'?id='.$object->id;
71  $head[$h][1] = $langs->trans('Documents');
72  if (($nbFiles + $nbLinks) > 0) {
73  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
74  }
75  $head[$h][2] = 'document';
76  $h++;
77 
78  $head[$h][0] = dol_buildpath("/hrm/evaluation_agenda.php", 1).'?id='.$object->id;
79  $head[$h][1] = $langs->trans("Events");
80  $head[$h][2] = 'agenda';
81  $h++;
82 
83  // Show more tabs from modules
84  // Entries must be declared in modules descriptor with line
85  //$this->tabs = array(
86  // 'entity:+tabname:Title:@hrm:/hrm/mypage.php?id=__ID__'
87  //); // to add new tab
88  //$this->tabs = array(
89  // 'entity:-tabname:Title:@hrm:/hrm/mypage.php?id=__ID__'
90  //); // to remove a tab
91  complete_head_from_modules($conf, $langs, $object, $head, $h, 'evaluation@hrm');
92 
93  complete_head_from_modules($conf, $langs, $object, $head, $h, 'evaluation@hrm', 'remove');
94 
95  return $head;
96 }
97 
101 function GetLegendSkills()
102 {
103  global $langs;
104  $legendSkills = '<div style="font-style:italic;">
105  ' . $langs->trans('legend') . '
106  <table class="border" width="100%">
107  <tr>
108  <td><span style="vertical-align:middle" class="toohappy diffnote little"></span>
109  ' . $langs->trans('CompetenceAcquiredByOneOrMore') . '</td>
110  </tr>
111  <tr>
112  <td><span style="vertical-align:middle" class="veryhappy diffnote little"></span>
113  ' . $langs->trans('MaxlevelGreaterThan') . '</td>
114  </tr>
115  <tr>
116  <td><span style="vertical-align:middle" class="happy diffnote little"></span>
117  ' . $langs->trans('MaxLevelEqualTo') . '</td>
118  </tr>
119  <tr>
120  <td><span style="vertical-align:middle" class="sad diffnote little"></span>
121  ' . $langs->trans('MaxLevelLowerThan') . '</td>
122  </tr>
123  <tr>
124  <td><span style="vertical-align:middle" class="toosad diffnote little"></span>
125  ' . $langs->trans('SkillNotAcquired') . '</td>
126  </tr>
127  </table>
128 </div>';
129  return $legendSkills;
130 }
131 
136 function getRankOrderResults($obj)
137 {
138  global $langs;
139 
140  $results = array(
141  'greater' => array(
142  'title' => $langs->trans('MaxlevelGreaterThanShort'),
143  'style' => 'background-color: #c3e6cb; border:5px solid #3097D1; color: #555; font-weight: 700;'
144  ),
145  'equal' => array(
146  'title' => $langs->trans('MaxLevelEqualToShort'),
147  'style' => 'background-color: #c3e6cb; color: #555; font-weight: 700;'
148  ),
149  'lesser' => array(
150  'title' => $langs->trans('MaxLevelLowerThanShort'),
151  'style' => 'background-color: #bd4147; color: #FFFFFF; font-weight: 700;'
152  )
153  );
154  $key = '';
155  if ($obj->rankorder > $obj->required_rank) {
156  $key = 'greater';
157  } elseif ($obj->rankorder == $obj->required_rank) {
158  $key = 'equal';
159  } elseif ($obj->rankorder < $obj->required_rank) {
160  $key = 'lesser';
161  }
162  return '<span title="'.dol_escape_htmltag($obj->label).': ' .$results[$key]['title']. '" class="radio_js_bloc_number TNote_1" style="' . dol_escape_htmltag($results[$key]['style']) . '">' . dol_trunc($obj->label, 4).'</span>';
163 }
164 
171 function getGroupedEval($objects)
172 {
173  if (count($objects) < 0 || !is_array($objects)) {
174  return -1;
175  }
176  // grouped $object by ref
177  $grouped = [];
178  foreach ($objects as $object) {
179  $ref = $object->ref;
180  if (!isset($grouped[$ref])) {
181  $grouped[$ref] = [];
182  }
183  $grouped[$ref][] = $object;
184  }
185  $newArray = [];
186  foreach ($grouped as $refs => $objects) {
187  if (count($objects) > 1) {
188  $newArray[$refs] = $objects;
189  }
190  }
191  $combinedArray = [];
192  foreach ($grouped as $refs => $objects) {
193  if (count($objects) == 1) {
194  $combinedArray[] = $objects[0];
195  }
196  }
197  $resultArray = array_merge($combinedArray, array_values($newArray));
198  return $resultArray;
199 }
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
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
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_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
evaluationPrepareHead($object)
Prepare array of tabs for Evaluation.
GetLegendSkills()
getRankOrderResults($obj)
getGroupedEval($objects)
Grouped rows with same ref in array.