knowledgemanagement_knowledgerecord.lib.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /* Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/knowledgemanagement/lib/knowledgemanagement_knowledgerecord.lib.php
  19. * \ingroup knowledgemanagement
  20. * \brief Library files with common functions for KnowledgeRecord
  21. */
  22. /**
  23. * Prepare array of tabs for KnowledgeRecord
  24. *
  25. * @param KnowledgeRecord $object KnowledgeRecord
  26. * @return array Array of tabs
  27. */
  28. function knowledgerecordPrepareHead($object)
  29. {
  30. global $db, $langs, $conf;
  31. $langs->load("knowledgemanagement");
  32. $h = 0;
  33. $head = array();
  34. $head[$h][0] = DOL_URL_ROOT.'/knowledgemanagement/knowledgerecord_card.php?id='.$object->id;
  35. $head[$h][1] = $langs->trans("KnowledgeRecord");
  36. $head[$h][2] = 'card';
  37. $h++;
  38. if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
  39. $nbNote = 0;
  40. if (!empty($object->note_private)) {
  41. $nbNote++;
  42. }
  43. if (!empty($object->note_public)) {
  44. $nbNote++;
  45. }
  46. $head[$h][0] = DOL_URL_ROOT.'/knowledgemanagement/knowledgerecord_note.php?id='.$object->id;
  47. $head[$h][1] = $langs->trans('Notes');
  48. if ($nbNote > 0) {
  49. $head[$h][1] .= (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? '<span class="badge marginleftonlyshort">'.$nbNote.'</span>' : '');
  50. }
  51. $head[$h][2] = 'note';
  52. $h++;
  53. }
  54. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  55. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  56. $upload_dir = $conf->knowledgemanagement->dir_output."/knowledgerecord/".dol_sanitizeFileName($object->ref);
  57. $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  58. $nbLinks = Link::count($db, $object->element, $object->id);
  59. $head[$h][0] = DOL_URL_ROOT.'/knowledgemanagement/knowledgerecord_document.php?id='.$object->id;
  60. $head[$h][1] = $langs->trans('Documents');
  61. if (($nbFiles + $nbLinks) > 0) {
  62. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
  63. }
  64. $head[$h][2] = 'document';
  65. $h++;
  66. $head[$h][0] = DOL_URL_ROOT.'/knowledgemanagement/knowledgerecord_agenda.php?id='.$object->id;
  67. $head[$h][1] = $langs->trans("Events");
  68. $head[$h][2] = 'agenda';
  69. $h++;
  70. // Show more tabs from modules
  71. // Entries must be declared in modules descriptor with line
  72. //$this->tabs = array(
  73. // 'entity:+tabname:Title:@knowledgemanagement:/knowledgemanagement/mypage.php?id=__ID__'
  74. //); // to add new tab
  75. //$this->tabs = array(
  76. // 'entity:-tabname:Title:@knowledgemanagement:/knowledgemanagement/mypage.php?id=__ID__'
  77. //); // to remove a tab
  78. complete_head_from_modules($conf, $langs, $object, $head, $h, 'knowledgerecord@knowledgemanagement');
  79. complete_head_from_modules($conf, $langs, $object, $head, $h, 'knowledgerecord@knowledgemanagement', 'remove');
  80. return $head;
  81. }