dolibarr 20.0.0
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 *
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
26require_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
27
32{
36 public $boxcode = "box_last_knowledgerecord";
37
41 public $boximg = "knowledgemanagement";
42
46 public $boxlabel;
47
51 public $depends = array("knowledgemanagement");
52
58 public function __construct($db, $param = '')
59 {
60 global $langs;
61 $langs->loadLangs(array("boxes", "languages"));
62 $this->db = $db;
63
64 $this->boxlabel = $langs->transnoentitiesnoconv("BoxLastKnowledgerecord");
65 }
66
73 public function loadBox($max = 5)
74 {
75 global $user, $langs;
76
77 $this->max = $max;
78
79 require_once DOL_DOCUMENT_ROOT."/knowledgemanagement/class/knowledgerecord.class.php";
80
81 $text = $langs->trans("BoxLastKnowledgerecordDescription", $max);
82 $this->info_box_head = array(
83 'text' => $text.'<a class="paddingleft" href="'.DOL_URL_ROOT.'/knowledgemanagement/knowledgerecord_list.php?sortfield=t.tms&sortorder=DESC"><span class="badge">...</span></a>',
84 //'limit' => dol_strlen($text),
85 );
86
87 $this->info_box_contents[0][0] = array(
88 'td' => 'class="left"',
89 'text' => $langs->trans("BoxLastKnowledgerecordContent"),
90 );
91
92 if ($user->hasRight('knowledgemanagement', 'knowledgerecord', 'read')) {
93 $sql = 'SELECT k.rowid as id, k.date_creation, k.ref, k.lang, k.question, k.status as status';
94 $sql .= " FROM ".MAIN_DB_PREFIX."knowledgemanagement_knowledgerecord as k";
95 $sql .= " WHERE k.entity IN (".getEntity('knowledgemanagement').")";
96
97 if ($user->socid) {
98 $sql .= " AND k.fk_soc= ".((int) $user->socid);
99 }
100
101 $sql.= " AND k.status > 0";
102
103 $sql .= " ORDER BY k.date_creation DESC, k.rowid DESC ";
104 $sql .= $this->db->plimit($max, 0);
105
106 $resql = $this->db->query($sql);
107 if ($resql) {
108 $num = $this->db->num_rows($resql);
109
110 $i = 0;
111
112 while ($i < $num) {
113 $objp = $this->db->fetch_object($resql);
114
115 $datec = $this->db->jdate($objp->date_creation);
116
117 $knowledgerecord = new KnowledgeRecord($this->db);
118 $knowledgerecord->id = $objp->id;
119 $knowledgerecord->date_creation = $objp->date_creation;
120 $knowledgerecord->ref = $objp->ref;
121 $knowledgerecord->status = $objp->status;
122 $knowledgerecord->question = $objp->question;
123
124 $r = 0;
125
126 // Ticket
127 $this->info_box_contents[$i][$r] = array(
128 'td' => 'class="nowraponall"',
129 'text' => $knowledgerecord->getNomUrl(1),
130 'asis' => 1
131 );
132 $r++;
133
134 // Question
135 $this->info_box_contents[$i][$r] = array(
136 'td' => 'class="tdoverflowmax200"',
137 'text' => '<span title="'.dol_escape_htmltag($objp->question).'">'.dol_escape_htmltag($objp->question).'</span>',
138 'url' => DOL_URL_ROOT."/knowledgemanagement/knowledgerecord_card.php?id=".urlencode($objp->id),
139 );
140 $r++;
141
142 // Language
143 $labellang = ($objp->lang ? $langs->trans('Language_'.$objp->lang) : '');
144 $this->info_box_contents[$i][$r] = array(
145 'td' => 'class="tdoverflowmax100"',
146 'text' => picto_from_langcode($objp->lang, 'class="paddingrightonly saturatemedium opacitylow"') . $labellang,
147 'asis' => 1,
148 );
149 $r++;
150
151 // Date creation
152 $this->info_box_contents[$i][$r] = array(
153 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateCreation").': '.dol_print_date($datec, 'dayhour', 'tzuserrel')).'"',
154 'text' => dol_print_date($datec, 'dayhour', 'tzuserrel'),
155 );
156 $r++;
157
158 // Statut
159 $this->info_box_contents[$i][$r] = array(
160 'td' => 'class="right nowraponall"',
161 'text' => $knowledgerecord->getLibStatut(3),
162 );
163 $r++;
164
165 $i++;
166 }
167
168 if ($num == 0) {
169 $this->info_box_contents[$i][0] = array(
170 'td' => '',
171 'text' => '<span class="opacitymedium">'.$langs->trans("BoxLastTicketNoRecordedTickets").'</span>',
172 );
173 }
174 } else {
175 dol_print_error($this->db);
176 }
177 } else {
178 $this->info_box_contents[0][0] = array(
179 'td' => '',
180 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>',
181 );
182 }
183 }
184
193 public function showBox($head = null, $contents = null, $nooutput = 0)
194 {
195 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
196 }
197}
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...