dolibarr 21.0.0-beta
box_last_knowledgerecord.php
Go to the documentation of this file.
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 * 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
27require_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
28
33{
37 public $boxcode = "box_last_knowledgerecord";
38
42 public $boximg = "knowledgemanagement";
43
47 public $boxlabel;
48
52 public $depends = array("knowledgemanagement");
53
59 public function __construct($db, $param = '')
60 {
61 global $langs;
62 $langs->loadLangs(array("boxes", "languages"));
63 $this->db = $db;
64
65 $this->boxlabel = $langs->transnoentitiesnoconv("BoxLastKnowledgerecord");
66 }
67
74 public function loadBox($max = 5)
75 {
76 global $user, $langs;
77
78 $this->max = $max;
79
80 require_once DOL_DOCUMENT_ROOT."/knowledgemanagement/class/knowledgerecord.class.php";
81
82 $text = $langs->trans("BoxLastKnowledgerecordDescription", $max);
83 $this->info_box_head = array(
84 'text' => $text.'<a class="paddingleft" href="'.DOL_URL_ROOT.'/knowledgemanagement/knowledgerecord_list.php?sortfield=t.tms&sortorder=DESC"><span class="badge">...</span></a>',
85 //'limit' => dol_strlen($text),
86 );
87
88 $this->info_box_contents[0][0] = array(
89 'td' => 'class="left"',
90 'text' => $langs->trans("BoxLastKnowledgerecordContent"),
91 );
92
93 if ($user->hasRight('knowledgemanagement', 'knowledgerecord', 'read')) {
94 $sql = 'SELECT k.rowid as id, k.date_creation, k.ref, k.lang, k.question, k.status as status';
95 $sql .= " FROM ".MAIN_DB_PREFIX."knowledgemanagement_knowledgerecord as k";
96 $sql .= " WHERE k.entity IN (".getEntity('knowledgemanagement').")";
97
98 if ($user->socid) {
99 $sql .= " AND k.fk_soc= ".((int) $user->socid);
100 }
101
102 $sql .= " AND k.status > 0";
103
104 $sql .= " ORDER BY k.date_creation DESC, k.rowid DESC ";
105 $sql .= $this->db->plimit($max, 0);
106
107 $resql = $this->db->query($sql);
108 if ($resql) {
109 $num = $this->db->num_rows($resql);
110
111 $i = 0;
112
113 while ($i < $num) {
114 $objp = $this->db->fetch_object($resql);
115
116 $datec = $this->db->jdate($objp->date_creation);
117
118 $knowledgerecord = new KnowledgeRecord($this->db);
119 $knowledgerecord->id = $objp->id;
120 $knowledgerecord->date_creation = $objp->date_creation;
121 $knowledgerecord->ref = $objp->ref;
122 $knowledgerecord->status = $objp->status;
123 $knowledgerecord->question = $objp->question;
124
125 $r = 0;
126
127 // Ticket
128 $this->info_box_contents[$i][$r] = array(
129 'td' => 'class="nowraponall"',
130 'text' => $knowledgerecord->getNomUrl(1),
131 'asis' => 1
132 );
133 $r++;
134
135 // Question
136 $this->info_box_contents[$i][$r] = array(
137 'td' => 'class="tdoverflowmax200"',
138 'text' => '<span title="'.dol_escape_htmltag($objp->question).'">'.dol_escape_htmltag($objp->question).'</span>',
139 'url' => DOL_URL_ROOT."/knowledgemanagement/knowledgerecord_card.php?id=".urlencode($objp->id),
140 );
141 $r++;
142
143 // Language
144 $labellang = ($objp->lang ? $langs->trans('Language_'.$objp->lang) : '');
145 $this->info_box_contents[$i][$r] = array(
146 'td' => 'class="tdoverflowmax100"',
147 'text' => picto_from_langcode($objp->lang, 'class="paddingrightonly saturatemedium opacitylow"') . $labellang,
148 'asis' => 1,
149 );
150 $r++;
151
152 // Date creation
153 $this->info_box_contents[$i][$r] = array(
154 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateCreation").': '.dol_print_date($datec, 'dayhour', 'tzuserrel')).'"',
155 'text' => dol_print_date($datec, 'dayhour', 'tzuserrel'),
156 );
157 $r++;
158
159 // Statut
160 $this->info_box_contents[$i][$r] = array(
161 'td' => 'class="right nowraponall"',
162 'text' => $knowledgerecord->getLibStatut(3),
163 );
164 $r++;
165
166 $i++;
167 }
168
169 if ($num == 0) {
170 $this->info_box_contents[$i][0] = array(
171 'td' => '',
172 'text' => '<span class="opacitymedium">'.$langs->trans("BoxLastTicketNoRecordedTickets").'</span>',
173 );
174 }
175 } else {
176 dol_print_error($this->db);
177 }
178 } else {
179 $this->info_box_contents[0][0] = array(
180 'td' => '',
181 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>',
182 );
183 }
184 }
185
186
187
196 public function showBox($head = null, $contents = null, $nooutput = 0)
197 {
198 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
199 }
200}
Class for KnowledgeRecord.
Class ModeleBoxes.
__construct($db, $param='')
Constructor.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
loadBox($max=5)
Load data into info_box_contents array to show array later.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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...