ILIAS  release_8 Revision v8.24
class.ilWikiStatGUI.php
Go to the documentation of this file.
1<?php
2
20
27{
29 protected ilCtrl $ctrl;
31 protected ilLanguage $lng;
33 protected int $wiki_id;
34 protected int $page_id;
35
36 public function __construct(
37 int $a_wiki_id,
38 ?int $a_page_id = null
39 ) {
40 global $DIC;
41
42 $this->ctrl = $DIC->ctrl();
43 $this->toolbar = $DIC->toolbar();
44 $this->lng = $DIC->language();
45 $this->tpl = $DIC["tpl"];
46 $this->wiki_id = $a_wiki_id;
47 $this->page_id = (int) $a_page_id;
48 $this->request = $DIC
49 ->wiki()
50 ->internal()
51 ->gui()
52 ->editing()
53 ->request();
54 }
55
56 public function executeCommand(): void
57 {
58 $ilCtrl = $this->ctrl;
59
60 $next_class = $ilCtrl->getNextClass($this);
61 $cmd = $ilCtrl->getCmd("view");
62
63 switch ($next_class) {
64 default:
65 $this->$cmd();
66 break;
67 }
68 }
69
70 protected function viewToolbar(
71 bool $a_is_initial = false
72 ): ?array {
73 $ilToolbar = $this->toolbar;
75 $ilCtrl = $this->ctrl;
76
77 $current_figure = $this->request->getStatFig();
78 $current_time_frame = $this->request->getStatTfr();
79 $current_scope = $this->request->getStatScp();
80
81 $view = new ilSelectInputGUI($lng->txt("wiki_stat_figure"), "fig");
82 $view->setOptions($this->page_id
85 if ($current_figure) {
86 $view->setValue($current_figure);
87 } elseif ($a_is_initial) {
88 // default
89 $current_figure = $this->page_id
92 }
93 $ilToolbar->addInputItem($view, true);
94
95 $options = array();
96 $lng->loadLanguageModule("dateplaner");
97 foreach (ilWikiStat::getAvailableMonths($this->wiki_id) as $month) {
98 $parts = explode("-", $month);
99 $options[$month] = ilCalendarUtil::_numericMonthToString((int) $parts[1]) .
100 " " . $parts[0];
101 }
102 krsort($options);
103
104 $tframe = new ilSelectInputGUI($lng->txt("month"), "tfr");
105 $tframe->setOptions($options);
106 if ($current_time_frame) {
107 $tframe->setValue($current_time_frame);
108 } elseif ($a_is_initial) {
109 $opt = array_keys($options);
110 $current_time_frame = array_shift($opt); // default
111 }
112 $ilToolbar->addInputItem($tframe, true);
113
114 $scope = new ilSelectInputGUI($lng->txt("wiki_stat_scope"), "scp");
115 $scope->setOptions(array(
116 1 => "1 " . $lng->txt("month"),
117 2 => "2 " . $lng->txt("months"),
118 3 => "3 " . $lng->txt("months"),
119 4 => "4 " . $lng->txt("months"),
120 5 => "5 " . $lng->txt("months"),
121 6 => "6 " . $lng->txt("months")
122 ));
123 if ($current_scope) {
124 $scope->setValue($current_scope);
125 } elseif ($a_is_initial) {
126 $current_scope = 1; // default
127 }
128 $ilToolbar->addInputItem($scope, true);
129
130 $ilToolbar->setFormAction($ilCtrl->getFormAction($this, "view"));
131 $ilToolbar->addFormButton($lng->txt("show"), "view");
132
133 if ($current_figure && $current_time_frame && $current_scope) {
134 $ilToolbar->addSeparator();
135 $ilToolbar->addFormButton($lng->txt("export"), "export");
136
137 return array(
138 "figure" => $current_figure,
139 "month" => $current_time_frame,
140 "scope" => $current_scope
141 );
142 }
143 return null;
144 }
145
146 protected function export(): void
147 {
148 $ilCtrl = $this->ctrl;
149
150 $params = $this->viewToolbar();
151 if ($params) {
152 // data
153
154 $tfr = explode("-", (string) $params["month"]);
155 $day_from = date("Y-m-d", mktime(0, 0, 1, $tfr[1] - ($params["scope"] - 1), 1, $tfr[0]));
156 $day_to = date("Y-m-d", mktime(0, 0, 1, $tfr[1] + 1, 0, $tfr[0]));
157 unset($tfr);
158
159 $chart_data = $this->getChartData($params["figure"], $params["scope"], $day_from, $day_to);
160
161
162 // excel
163
165 new ilDate($day_from, IL_CAL_DATE),
166 new ilDate($day_to, IL_CAL_DATE)
167 );
168
169 $filename = ilObject::_lookupTitle($this->wiki_id);
170 if ($this->page_id) {
171 $filename .= " - " . ilWikiPage::lookupTitle($this->page_id);
172 }
173 $filename .= " - " . ilWikiStat::getFigureTitle($params["figure"]) . " - " . $period;
174
175 $excel = new ilExcel();
176 $excel->addSheet($this->lng->txt("statistics"));
177
178 $row = 1;
179 foreach ($chart_data as $day => $value) {
180 $excel->setCell($row, 0, $day);
181 $excel->setCell($row++, 1, $value);
182 }
183
184 $excel->sendToClient($filename);
185 }
186
187 $ilCtrl->redirect($this, "view");
188 }
189
190 protected function initial(): void
191 {
192 $this->view(true);
193 }
194
195 protected function view(
196 bool $a_is_initial = false
197 ): void {
198 $tpl = $this->tpl;
200
201 $params = $this->viewToolbar($a_is_initial);
202 if (is_array($params)) {
203 // data
204
205 $tfr = explode("-", (string) $params["month"]);
206 $day_from = date("Y-m-d", mktime(0, 0, 1, $tfr[1] - ($params["scope"] - 1), 1, $tfr[0]));
207 $day_to = date("Y-m-d", mktime(0, 0, 1, $tfr[1] + 1, 0, $tfr[0]));
208 unset($tfr);
209
210 $chart_data = $this->getChartData($params["figure"], $params["scope"], $day_from, $day_to);
211 $list_data = $this->getListData();
212
213
214 // render
215
216 $vtpl = new ilTemplate("tpl.wiki_stat_list.html", true, true, "Modules/Wiki");
217
218 $chart_panel = ilPanelGUI::getInstance();
219
220 $vtpl->setVariable("CHART", $this->renderGraph($params["figure"], $chart_data));
221
222 $vtpl->setCurrentBlock("row_bl");
223 foreach ($list_data as $figure => $values) {
224 $vtpl->setVariable("FIGURE", $figure);
225 $vtpl->setVariable("YESTERDAY_VALUE", $values["yesterday"]);
226 $vtpl->setVariable("TODAY_VALUE", $values["today"]);
227 $vtpl->parseCurrentBlock();
228 }
229
230 $vtpl->setVariable("FIGURE_HEAD", $lng->txt("wiki_stat_figure"));
231 $vtpl->setVariable("YESTERDAY_HEAD", $lng->txt("yesterday"));
232 $vtpl->setVariable("TODAY_HEAD", $lng->txt("today"));
233
234 $chart_panel->setHeading($lng->txt("statistics"));
235 $chart_panel->setBody($vtpl->get());
236 $chart_panel->setHeadingStyle(ilPanelGUI::HEADING_STYLE_SUBHEADING);
237
238 $tpl->setContent($chart_panel->getHTML());
239 }
240 }
241
242 protected function getChartData(
243 int $a_figure,
244 int $a_scope,
245 string $a_from,
246 string $a_to
247 ): array {
248 $data = array();
249
250 $raw = $this->page_id
251 ? ilWikiStat::getFigureDataPage($this->wiki_id, $this->page_id, $a_figure, $a_from, $a_to)
252 : ilWikiStat::getFigureData($this->wiki_id, $a_figure, $a_from, $a_to);
253
254 $parts = explode("-", $a_from);
255 for ($loop = 0; $loop <= ($a_scope * 31); $loop++) {
256 $current_day = date("Y-m-d", mktime(0, 0, 1, $parts[1], $parts[2] + $loop, $parts[0]));
257 if ($current_day <= $a_to) {
258 $data[$current_day] = (float) ($raw[$current_day] ?? 0);
259 }
260 }
261
262 return $data;
263 }
264
265 protected function getListData(): array
266 {
267 $data = array();
268
269 $today = date("Y-m-d");
270 $yesterday = date("Y-m-d", strtotime("yesterday"));
271
272 $all = $this->page_id
275 foreach ($all as $figure => $title) {
276 if ($this->page_id) {
277 $tmp = ilWikiStat::getFigureDataPage($this->wiki_id, $this->page_id, $figure, $yesterday, $today);
278 } else {
279 $tmp = ilWikiStat::getFigureData($this->wiki_id, $figure, $yesterday, $today);
280 }
281 $data[$title] = array(
282 "yesterday" => (float) ($tmp[$yesterday] ?? 0),
283 "today" => (float) ($tmp[$today] ?? 0)
284 );
285 }
286
287 return $data;
288 }
289
290 protected function renderGraph(
291 int $a_figure,
292 array $a_data
293 ): string {
294 $scope = ceil(count($a_data) / 31);
295
297 $chart->setSize("100%", "400");
298 $chart->setColors(array("#C0E0FF"));
299
300 $legend = new ilChartLegend();
301 $chart->setLegend($legend);
302
303 // lines vs. bars
304 if (in_array($a_figure, array(
305 // wiki
318 // page
324 ), true)) {
325 $series = $chart->getDataInstance(ilChartGrid::DATA_LINES);
326 $series->setLineSteps(true);
327 $series->setFill(true, "#E0F0FF");
328 } else {
329 $series = $chart->getDataInstance(ilChartGrid::DATA_BARS);
330 $series->setBarOptions(round(10 / ($scope * 2)) / 10);
331 }
332 $series->setLabel(ilWikiStat::getFigureTitle($a_figure));
333
334 $labels = array();
335 $x = 0;
336 foreach ($a_data as $date => $value) {
337 $series->addPoint($x, $value);
338
339 $day = (int) substr($date, 8, 2);
340
341 // match scale to scope
342 if ($scope == 1) {
343 // daily
344 $labels[$x] = substr($date, 8, 2);
345 } elseif ($scope == 2) {
346 // weekly
347 if (!($x % 7)) {
348 $labels[$x] = substr($date, 8, 2) . "." . substr($date, 5, 2) . ".";
349 }
350 } elseif ($day === 1 || $day === 15 || $x === count($a_data) - 1) {
351 // 1st/15th
352 $labels[$x] = substr($date, 8, 2) . "." . substr($date, 5, 2) . ".";
353 }
354
355 $x++;
356 }
357
358 $chart->addData($series);
359 $chart->setTicks($labels, null, true);
360
361 // int vs. float (averages)
362 if (in_array($a_figure, array(
363 // wiki
376 // page
386 ), true)) {
387 $chart->setYAxisToInteger(true);
388 }
389
390 return $chart->getHTML();
391 }
392}
$filename
Definition: buildRTE.php:78
const IL_CAL_DATE
static _numericMonthToString(int $a_month, bool $a_long=true)
numeric month to string
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstanceByType(int $a_type, string $a_id)
const TYPE_GRID
Class ilCtrl provides processing control methods.
getNextClass($a_gui_class=null)
@inheritDoc
static formatPeriod(ilDateTime $start, ilDateTime $end, bool $a_skip_starting_day=false)
Format a period of two dates Shows: 14.
Class for single dates.
language handling
loadLanguageModule(string $a_module)
Load language module.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static _lookupTitle(int $obj_id)
const HEADING_STYLE_SUBHEADING
static getInstance()
This class represents a selection list property in a property form.
special template class to simplify handling of ITX/PEAR
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static lookupTitle(int $a_page_id)
Wiki statistics GUI class.
viewToolbar(bool $a_is_initial=false)
view(bool $a_is_initial=false)
EditingGUIRequest $request
ilGlobalTemplateInterface $tpl
ilToolbarGUI $toolbar
__construct(int $a_wiki_id, ?int $a_page_id=null)
getChartData(int $a_figure, int $a_scope, string $a_from, string $a_to)
renderGraph(int $a_figure, array $a_data)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const KEY_FIGURE_WIKI_PAGE_READ
const KEY_FIGURE_WIKI_NUM_RATING
const KEY_FIGURE_WIKI_DELETED_PAGES
const KEY_FIGURE_WIKI_WORDS
const KEY_FIGURE_WIKI_PAGE_EXTERNAL_LINKS
const KEY_FIGURE_WIKI_INTERNAL_LINKS
const KEY_FIGURE_WIKI_PAGE_RATINGS
const KEY_FIGURE_WIKI_WORDS_AVG
const KEY_FIGURE_WIKI_READ_PAGES
const KEY_FIGURE_WIKI_NEW_PAGES
const KEY_FIGURE_WIKI_EDIT_PAGES
const KEY_FIGURE_WIKI_EXTERNAL_LINKS_AVG
const KEY_FIGURE_WIKI_PAGE_CHANGES
const KEY_FIGURE_WIKI_INTERNAL_LINKS_AVG
static getFigureTitle(int $a_figure)
static getFigureOptionsPage()
static getFigureData(int $a_wiki_id, int $a_figure, string $a_from, string $a_to)
const KEY_FIGURE_WIKI_PAGE_INTERNAL_LINKS
const KEY_FIGURE_WIKI_FOOTNOTES
const KEY_FIGURE_WIKI_PAGE_USER_EDIT
static getFigureOptions()
static getAvailableMonths(int $a_wiki_id)
const KEY_FIGURE_WIKI_FOOTNOTES_AVG
static getFigureDataPage(int $a_wiki_id, int $a_page_id, int $a_figure, string $a_from, string $a_to)
const KEY_FIGURE_WIKI_EXTERNAL_LINKS
const KEY_FIGURE_WIKI_PAGE_FOOTNOTES
const KEY_FIGURE_WIKI_CHARS_AVG
const KEY_FIGURE_WIKI_PAGE_CHARS
const KEY_FIGURE_WIKI_USER_EDIT_PAGES
const KEY_FIGURE_WIKI_NUM_PAGES
const KEY_FIGURE_WIKI_CHARS
const KEY_FIGURE_WIKI_PAGE_WORDS
const KEY_FIGURE_WIKI_RATING_AVG
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
$scope
Definition: ltiregstart.php:53
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:64
$lng