dolibarr  16.0.5
hrm_skillrank.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  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
33 function skillrankPrepareHead($object)
34 {
35  global $db, $langs, $conf;
36 
37  $langs->load("hrm");
38 
39  $h = 0;
40  $head = array();
41 
42  $head[$h][0] = dol_buildpath("/hrm/skillrank_card.php", 1).'?id='.$object->id;
43  $head[$h][1] = $langs->trans("Card");
44  $head[$h][2] = 'card';
45  $h++;
46 
47  if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
48  $nbNote = 0;
49  if (!empty($object->note_private)) {
50  $nbNote++;
51  }
52  if (!empty($object->note_public)) {
53  $nbNote++;
54  }
55  $head[$h][0] = dol_buildpath('/hrm/skillrank_note.php', 1).'?id='.$object->id;
56  $head[$h][1] = $langs->trans('Notes');
57  if ($nbNote > 0) {
58  $head[$h][1] .= (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? '<span class="badge marginleftonlyshort">'.$nbNote.'</span>' : '');
59  }
60  $head[$h][2] = 'note';
61  $h++;
62  }
63 
64  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
65  require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
66  $upload_dir = $conf->hrm->dir_output."/skillrank/".dol_sanitizeFileName($object->ref);
67  $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
68  $nbLinks = Link::count($db, $object->element, $object->id);
69  $head[$h][0] = dol_buildpath("/hrm/skillrank_document.php", 1).'?id='.$object->id;
70  $head[$h][1] = $langs->trans('Documents');
71  if (($nbFiles + $nbLinks) > 0) {
72  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
73  }
74  $head[$h][2] = 'document';
75  $h++;
76 
77  $head[$h][0] = dol_buildpath("/hrm/skillrank_agenda.php", 1).'?id='.$object->id;
78  $head[$h][1] = $langs->trans("Events");
79  $head[$h][2] = 'agenda';
80  $h++;
81 
82  // Show more tabs from modules
83  // Entries must be declared in modules descriptor with line
84  //$this->tabs = array(
85  // 'entity:+tabname:Title:@hrm:/hrm/mypage.php?id=__ID__'
86  //); // to add new tab
87  //$this->tabs = array(
88  // 'entity:-tabname:Title:@hrm:/hrm/mypage.php?id=__ID__'
89  //); // to remove a tab
90  complete_head_from_modules($conf, $langs, $object, $head, $h, 'skillrank@hrm');
91 
92  complete_head_from_modules($conf, $langs, $object, $head, $h, 'skillrank@hrm', 'remove');
93 
94  return $head;
95 }
96 
107 function displayRankInfos($selected_rank, $fk_skill, $inputname = 'TNote', $mode = 'view')
108 {
109  global $db, $conf, $langs;
110 
111  require_once DOL_DOCUMENT_ROOT . '/hrm/class/skill.class.php';
112  require_once DOL_DOCUMENT_ROOT . '/hrm/class/skilldet.class.php';
113 
114  // On charge les différentes notes possibles pour la compétence $fk_skill
115  $skilldet = new Skilldet($db);
116  $Lines = $skilldet->fetchAll('ASC', 'rankorder', 0, 0, array('customsql'=>'fk_skill = '.$fk_skill));
117 
118  if (!is_array($Lines) && $Lines<0) {
119  setEventMessages($skilldet->error, $skilldet->errors, 'errors');
120  }
121  if (empty($Lines)) return $langs->trans('SkillHasNoLines');
122 
123  $ret = '<!-- field jquery --><span title="'.$langs->trans('NA').'" class="radio_js_bloc_number '.$inputname.'_'.$fk_skill.(empty($selected_rank) ? ' selected' : '').'">0</span>';
124  if (is_array($Lines) && !empty($Lines)) {
125  foreach ($Lines as $line) {
126  $MaxNumberSkill = isset($conf->global->HRM_MAXRANK) ? $conf->global->HRM_MAXRANK : Skill::DEFAULT_MAX_RANK_PER_SKILL;
127  if ($line->rankorder > $MaxNumberSkill) {
128  continue;
129  }
130 
131  $ret .= '<span title="' . $line->description . '" class="radio_js_bloc_number ' . $inputname . '_' . $line->fk_skill;
132  $ret .= $line->rankorder == $selected_rank ? ' selected' : '';
133  $ret .= '">' . $line->rankorder . '</span>';
134  }
135 
136  if ($mode == 'edit') {
137  $ret .= '
138  <input type="hidden" id="' . $inputname . '_' . $fk_skill . '" name="' . $inputname . '[' . $fk_skill . ']" value="' . $selected_rank . '">
139  <script type="text/javascript">
140  $(document).ready(function(){
141  $(".radio_js_bloc_number").tooltip();
142  var error,same;
143  $(".' . $inputname . '_' . $fk_skill . '").on("click",function(){
144  same=false;
145  val = $(this).html();
146  if($(this).hasClass("selected"))same=true;
147  $(".' . $inputname . '_' . $fk_skill . '").removeClass("selected");
148  if(same)
149  {
150  $("#' . $inputname . '_' . $fk_skill . '").val("");
151  }else {
152  $(this).addClass("selected");
153  $("#' . $inputname . '_' . $fk_skill . '").val(val);
154  }
155  });
156 
157  });
158  </script>';
159  }
160  }
161 
162  return $ret;
163 }
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
skillrankPrepareHead
skillrankPrepareHead($object)
Prepare array of tabs for SkillRank.
Definition: hrm_skillrank.lib.php:33
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
dol_dir_list
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
complete_head_from_modules
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
Definition: functions.lib.php:9038
Skilldet
Class for Skilldet.
Definition: skilldet.class.php:36
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
displayRankInfos
displayRankInfos($selected_rank, $fk_skill, $inputname='TNote', $mode='view')
Used to print ranks of a skill into several case, view or edit pour js necessary to select a rank.
Definition: hrm_skillrank.lib.php:107