box_last_modified_knowledgerecord.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php
  2. /*
  3. * Copyright (C) 2013-2016 Jean-François FERRY <hello@librethic.io>
  4. * Copyright (C) 2016 Christophe Battarel <christophe@altairis.fr>
  5. * Copyright (C) 2018-2023 Frédéric France <frederic.france@netlogic.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 htdocs/core/boxes/box_last_modified_knowledgerecord.php
  22. * \ingroup knowledgerecord
  23. * \brief This box shows latest created knowledgerecords
  24. */
  25. require_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
  26. /**
  27. * Class to manage the box
  28. */
  29. class box_last_modified_knowledgerecord extends ModeleBoxes
  30. {
  31. /**
  32. * @var string boxcode
  33. */
  34. public $boxcode = "box_last_modified_knowledgerecord";
  35. /**
  36. * @var string box img
  37. */
  38. public $boximg = "knowledgemanagement";
  39. /**
  40. * @var string boc label
  41. */
  42. public $boxlabel;
  43. /**
  44. * @var array box dependancies
  45. */
  46. public $depends = array("knowledgemanagement");
  47. /**
  48. * @var DoliDB Database handler.
  49. */
  50. public $db;
  51. /**
  52. * @var string param
  53. */
  54. public $param;
  55. /**
  56. * @var array box info heads
  57. */
  58. public $info_box_head = array();
  59. /**
  60. * @var array box info content
  61. */
  62. public $info_box_contents = array();
  63. /**
  64. * Constructor
  65. * @param DoliDB $db Database handler
  66. * @param string $param More parameters
  67. */
  68. public function __construct($db, $param = '')
  69. {
  70. global $langs;
  71. $langs->loadLangs(array("boxes", "knowledgemanagement", "languages"));
  72. $this->db = $db;
  73. $this->boxlabel = $langs->transnoentitiesnoconv("BoxLastModifiedKnowledgerecord");
  74. }
  75. /**
  76. * Load data into info_box_contents array to show array later.
  77. *
  78. * @param int $max Maximum number of records to load
  79. * @return void
  80. */
  81. public function loadBox($max = 5)
  82. {
  83. global $user, $langs;
  84. $this->max = $max;
  85. require_once DOL_DOCUMENT_ROOT."/knowledgemanagement/class/knowledgerecord.class.php";
  86. $text = $langs->trans("BoxLastModifiedKnowledgerecordDescription", $max);
  87. $this->info_box_head = array(
  88. 'text' => $text,
  89. 'limit' => dol_strlen($text),
  90. );
  91. $this->info_box_contents[0][0] = array(
  92. 'td' => 'class="left"',
  93. 'text' => $langs->trans("BoxLastKnowledgerecordContent"),
  94. );
  95. if ($user->hasRight('knowledgemanagement', 'knowledgerecord', 'read')) {
  96. $sql = 'SELECT k.rowid as id, k.date_creation, k.ref, k.lang, k.question, k.status as status';
  97. $sql .= " FROM ".MAIN_DB_PREFIX."knowledgemanagement_knowledgerecord as k";
  98. $sql .= " WHERE k.entity IN (".getEntity('knowledgemanagement').")";
  99. if ($user->socid) {
  100. $sql .= " AND k.fk_soc= ".((int) $user->socid);
  101. }
  102. $sql.= " AND k.status > 0";
  103. $sql .= " ORDER BY k.tms DESC, k.rowid DESC ";
  104. $sql .= $this->db->plimit($max, 0);
  105. $resql = $this->db->query($sql);
  106. if ($resql) {
  107. $num = $this->db->num_rows($resql);
  108. $i = 0;
  109. while ($i < $num) {
  110. $objp = $this->db->fetch_object($resql);
  111. $datec = $this->db->jdate($objp->date_creation);
  112. $knowledgerecord = new KnowledgeRecord($this->db);
  113. $knowledgerecord->id = $objp->id;
  114. $knowledgerecord->date_creation = $objp->date_creation;
  115. $knowledgerecord->ref = $objp->ref;
  116. $knowledgerecord->status = $objp->status;
  117. $knowledgerecord->question = $objp->question;
  118. $r = 0;
  119. // Ticket
  120. $this->info_box_contents[$i][$r] = array(
  121. 'td' => 'class="nowraponall"',
  122. 'text' => $knowledgerecord->getNomUrl(1),
  123. 'asis' => 1
  124. );
  125. $r++;
  126. // Question
  127. $this->info_box_contents[$i][$r] = array(
  128. 'td' => 'class="tdoverflowmax200"',
  129. 'text' => '<span title="'.dol_escape_htmltag($objp->question).'">'.dol_escape_htmltag($objp->question).'</span>',
  130. 'url' => DOL_URL_ROOT."/knowledgemanagement/knowledgerecord_card.php?id=".urlencode($objp->id),
  131. );
  132. $r++;
  133. // Language
  134. $labellang = ($objp->lang ? $langs->trans('Language_'.$objp->lang) : '');
  135. $this->info_box_contents[$i][$r] = array(
  136. 'td' => 'class="tdoverflowmax100"',
  137. 'text' => picto_from_langcode($objp->lang, 'class="paddingrightonly saturatemedium opacitylow"') . $labellang,
  138. 'asis' => 1,
  139. );
  140. $r++;
  141. // Date creation
  142. $this->info_box_contents[$i][$r] = array(
  143. 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateCreation").': '.dol_print_date($datec, 'dayhour', 'tzuserrel')).'"',
  144. 'text' => dol_print_date($datec, 'dayhour', 'tzuserrel'),
  145. );
  146. $r++;
  147. // Statut
  148. $this->info_box_contents[$i][$r] = array(
  149. 'td' => 'class="right nowraponall"',
  150. 'text' => $knowledgerecord->getLibStatut(3),
  151. );
  152. $r++;
  153. $i++;
  154. }
  155. if ($num == 0) {
  156. $this->info_box_contents[$i][0] = array(
  157. 'td' => '',
  158. 'text' => '<span class="opacitymedium">'.$langs->trans("BoxLastTicketNoRecordedTickets").'</span>',
  159. );
  160. }
  161. } else {
  162. dol_print_error($this->db);
  163. }
  164. } else {
  165. $this->info_box_contents[0][0] = array(
  166. 'td' => '',
  167. 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>',
  168. );
  169. }
  170. }
  171. /**
  172. * Method to show box
  173. *
  174. * @param array $head Array with properties of box title
  175. * @param array $contents Array with properties of box lines
  176. * @param int $nooutput No print, only return string
  177. * @return string
  178. */
  179. public function showBox($head = null, $contents = null, $nooutput = 0)
  180. {
  181. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  182. }
  183. }