hrm_skillrank.lib.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. /**
  21. * \file lib/hrm_skillrank.lib.php
  22. * \ingroup hrm
  23. * \brief Library files with common functions for SkillRank
  24. */
  25. /**
  26. * Prepare array of tabs for SkillRank
  27. *
  28. * @param SkillRank $object SkillRank
  29. * @return array Array of tabs
  30. */
  31. function skillrankPrepareHead($object)
  32. {
  33. global $db, $langs, $conf;
  34. $langs->load("hrm");
  35. $h = 0;
  36. $head = array();
  37. $head[$h][0] = dol_buildpath("/hrm/skillrank_card.php", 1).'?id='.$object->id;
  38. $head[$h][1] = $langs->trans("Card");
  39. $head[$h][2] = 'card';
  40. $h++;
  41. if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
  42. $nbNote = 0;
  43. if (!empty($object->note_private)) {
  44. $nbNote++;
  45. }
  46. if (!empty($object->note_public)) {
  47. $nbNote++;
  48. }
  49. $head[$h][0] = dol_buildpath('/hrm/skillrank_note.php', 1).'?id='.$object->id;
  50. $head[$h][1] = $langs->trans('Notes');
  51. if ($nbNote > 0) {
  52. $head[$h][1] .= (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? '<span class="badge marginleftonlyshort">'.$nbNote.'</span>' : '');
  53. }
  54. $head[$h][2] = 'note';
  55. $h++;
  56. }
  57. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  58. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  59. $upload_dir = $conf->hrm->dir_output."/skillrank/".dol_sanitizeFileName($object->ref);
  60. $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  61. $nbLinks = Link::count($db, $object->element, $object->id);
  62. $head[$h][0] = dol_buildpath("/hrm/skillrank_document.php", 1).'?id='.$object->id;
  63. $head[$h][1] = $langs->trans('Documents');
  64. if (($nbFiles + $nbLinks) > 0) {
  65. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
  66. }
  67. $head[$h][2] = 'document';
  68. $h++;
  69. $head[$h][0] = dol_buildpath("/hrm/skillrank_agenda.php", 1).'?id='.$object->id;
  70. $head[$h][1] = $langs->trans("Events");
  71. $head[$h][2] = 'agenda';
  72. $h++;
  73. // Show more tabs from modules
  74. // Entries must be declared in modules descriptor with line
  75. //$this->tabs = array(
  76. // 'entity:+tabname:Title:@hrm:/hrm/mypage.php?id=__ID__'
  77. //); // to add new tab
  78. //$this->tabs = array(
  79. // 'entity:-tabname:Title:@hrm:/hrm/mypage.php?id=__ID__'
  80. //); // to remove a tab
  81. complete_head_from_modules($conf, $langs, $object, $head, $h, 'skillrank@hrm');
  82. complete_head_from_modules($conf, $langs, $object, $head, $h, 'skillrank@hrm', 'remove');
  83. return $head;
  84. }
  85. /**
  86. * Used to print ranks of a skill into several case, view or edit pour js necessary to select a rank
  87. *
  88. * @param int $selected_rank rank we want to preselect
  89. * @param int $fk_skill id of skill we display ranks
  90. * @param string $inputname html name of input
  91. * @param string $mode view or edit
  92. *
  93. * @return string string result
  94. */
  95. function displayRankInfos($selected_rank, $fk_skill, $inputname = 'TNote', $mode = 'view')
  96. {
  97. global $db, $conf, $langs;
  98. require_once DOL_DOCUMENT_ROOT . '/hrm/class/skill.class.php';
  99. require_once DOL_DOCUMENT_ROOT . '/hrm/class/skilldet.class.php';
  100. // On charge les différentes notes possibles pour la compétence $fk_skill
  101. $skilldet = new Skilldet($db);
  102. $Lines = $skilldet->fetchAll('ASC', 'rankorder', 0, 0, array('customsql'=>'fk_skill = '.$fk_skill));
  103. if (!is_array($Lines) && $Lines<0) {
  104. setEventMessages($skilldet->error, $skilldet->errors, 'errors');
  105. }
  106. if (empty($Lines)) return $langs->trans('SkillHasNoLines');
  107. $ret = '<!-- field jquery --><span title="'.$langs->trans('NA').'" class="radio_js_bloc_number '.$inputname.'_'.$fk_skill.(empty($selected_rank) ? ' selected' : '').'">0</span>';
  108. if (is_array($Lines) && !empty($Lines)) {
  109. foreach ($Lines as $line) {
  110. $MaxNumberSkill = isset($conf->global->HRM_MAXRANK) ? $conf->global->HRM_MAXRANK : Skill::DEFAULT_MAX_RANK_PER_SKILL;
  111. if ($line->rankorder > $MaxNumberSkill) {
  112. continue;
  113. }
  114. $ret .= '<span title="' . $line->description . '" class="radio_js_bloc_number ' . $inputname . '_' . $line->fk_skill;
  115. $ret .= $line->rankorder == $selected_rank ? ' selected' : '';
  116. $ret .= '">' . $line->rankorder . '</span>';
  117. }
  118. if ($mode == 'edit') {
  119. $ret .= '
  120. <input type="hidden" id="' . $inputname . '_' . $fk_skill . '" name="' . $inputname . '[' . $fk_skill . ']" value="' . $selected_rank . '">
  121. <script type="text/javascript">
  122. $(document).ready(function(){
  123. $(".radio_js_bloc_number").tooltip();
  124. var error,same;
  125. $(".' . $inputname . '_' . $fk_skill . '").on("click",function(){
  126. same=false;
  127. val = $(this).html();
  128. if($(this).hasClass("selected"))same=true;
  129. $(".' . $inputname . '_' . $fk_skill . '").removeClass("selected");
  130. if(same)
  131. {
  132. $("#' . $inputname . '_' . $fk_skill . '").val("");
  133. }else {
  134. $(this).addClass("selected");
  135. $("#' . $inputname . '_' . $fk_skill . '").val(val);
  136. }
  137. });
  138. });
  139. </script>';
  140. }
  141. }
  142. return $ret;
  143. }