ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilWikiStatGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once "Modules/Wiki/classes/class.ilWikiStat.php";
6
15{
16 protected $wiki_id; // [integer]
17 protected $page_id; // [integer]
18
19 public function __construct($a_wiki_id, $a_page_id = null)
20 {
21 $this->wiki_id = (int)$a_wiki_id;
22 $this->page_id = (int)$a_page_id;
23 }
24
25 public function executeCommand()
26 {
27 global $ilCtrl;
28
29 $next_class = $ilCtrl->getNextClass($this);
30 $cmd = $ilCtrl->getCmd("view");
31
32 switch($next_class)
33 {
34 default:
35 $this->$cmd();
36 break;
37 }
38 }
39
40 protected function viewToolbar($a_is_initial = false)
41 {
42 global $ilToolbar, $lng, $ilCtrl;
43
44 $current_figure = (int)$_POST["fig"];
45 $current_time_frame = (string)$_POST["tfr"];
46 $current_scope = (int)$_POST["scp"];
47
48 include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
49 $view = new ilSelectInputGUI($lng->txt("wiki_stat_figure"), "fig");
50 $view->setOptions($this->page_id
53 if($current_figure)
54 {
55 $view->setValue($current_figure);
56 }
57 else if($a_is_initial)
58 {
59 // default
60 $current_figure = $this->page_id
63 }
64 $ilToolbar->addInputItem($view, true);
65
66 $options = array();
67 include_once "Services/Calendar/classes/class.ilCalendarUtil.php";
68 $lng->loadLanguageModule("dateplaner");
69 foreach(ilWikiStat::getAvailableMonths($this->wiki_id) as $month)
70 {
71 $parts = explode("-", $month);
72 $options[$month] = ilCalendarUtil::_numericMonthToString((int)$parts[1]).
73 " ".$parts[0];
74 }
75 krsort($options);
76
77 $tframe = new ilSelectInputGUI($lng->txt("month"), "tfr");
78 $tframe->setOptions($options);
79 if($current_time_frame)
80 {
81 $tframe->setValue($current_time_frame);
82 }
83 else if($a_is_initial)
84 {
85 $current_time_frame = array_shift(array_keys($options)); // default
86 }
87 $ilToolbar->addInputItem($tframe, true);
88
89 $scope = new ilSelectInputGUI($lng->txt("wiki_stat_scope"), "scp");
90 $scope->setOptions(array(
91 1 => "1 ".$lng->txt("month"),
92 2 => "2 ".$lng->txt("months"),
93 3 => "3 ".$lng->txt("months"),
94 4 => "4 ".$lng->txt("months"),
95 5 => "5 ".$lng->txt("months"),
96 6 => "6 ".$lng->txt("months")
97 ));
98 if($current_scope)
99 {
100 $scope->setValue($current_scope);
101 }
102 else if($a_is_initial)
103 {
104 $current_scope = 1; // default
105 }
106 $ilToolbar->addInputItem($scope, true);
107
108 $ilToolbar->setFormAction($ilCtrl->getFormAction($this, "view"));
109 $ilToolbar->addFormButton($lng->txt("show"), "view");
110
111 if($current_figure && $current_time_frame && $current_scope)
112 {
113 $ilToolbar->addSeparator();
114 $ilToolbar->addFormButton($lng->txt("export"), "export");
115
116 return array(
117 "figure" => $current_figure,
118 "month" => $current_time_frame,
119 "scope" => $current_scope
120 );
121 }
122 }
123
124 protected function export()
125 {
126 global $ilCtrl;
127
128 $params = $this->viewToolbar();
129 if($params)
130 {
131 // data
132
133 $tfr = explode("-", (string)$params["month"]);
134 $day_from = date("Y-m-d", mktime(0, 0, 1, $tfr[1]-($params["scope"]-1), 1, $tfr[0]));
135 $day_to = date("Y-m-d", mktime(0, 0, 1, $tfr[1]+1, 0, $tfr[0]));
136 unset($tfr);
137
138 $chart_data = $this->getChartData($params["figure"], $params["scope"], $day_from, $day_to);
139
140
141 // excel
142
144 new ilDate($day_from, IL_CAL_DATE),
145 new ilDate($day_to, IL_CAL_DATE));
146
147 $filename = ilObject::_lookupTitle($this->wiki_id);
148 if($this->page_id)
149 {
150 $filename .= " - ".ilWikiPage::lookupTitle($this->page_id);
151 }
152 $filename .= " - ".ilWikiStat::getFigureTitle($params["figure"])." - ".$period;
153
154 include_once "./Services/Excel/classes/class.ilExcel.php";
155 $excel = new ilExcel();
156 $excel->addSheet($this->lng->txt("statistics"));
157
158 $row = 1;
159 foreach($chart_data as $day => $value)
160 {
161 $excel->setCell($row, 0, $day);
162 $excel->setCell($row++, 1, $value);
163 }
164
165 $excel->sendToClient($filename);
166 }
167
168 $ilCtrl->redirect($this, "view");
169 }
170
171 protected function initial()
172 {
173 $this->view(true);
174 }
175
176 protected function view($a_is_initial = false)
177 {
178 global $tpl, $lng;
179
180 $params = $this->viewToolbar($a_is_initial);
181 if(is_array($params))
182 {
183 // data
184
185 $tfr = explode("-", (string)$params["month"]);
186 $day_from = date("Y-m-d", mktime(0, 0, 1, $tfr[1]-($params["scope"]-1), 1, $tfr[0]));
187 $day_to = date("Y-m-d", mktime(0, 0, 1, $tfr[1]+1, 0, $tfr[0]));
188 unset($tfr);
189
190 $chart_data = $this->getChartData($params["figure"], $params["scope"], $day_from, $day_to);
191 $list_data = $this->getListData();
192
193
194 // render
195
196 $vtpl = new ilTemplate("tpl.wiki_stat_list.html", true, true, "Modules/Wiki");
197
198 include_once("./Services/UIComponent/Panel/classes/class.ilPanelGUI.php");
199 $chart_panel = ilPanelGUI::getInstance();
200
201 $vtpl->setVariable("CHART", $this->renderGraph($params["figure"], $chart_data));
202
203 $vtpl->setCurrentBlock("row_bl");
204 $counter = 0;
205 foreach($list_data as $figure => $values)
206 {
207 $day = (int)substr($day, 8);
208 $vtpl->setVariable("CSS_ROW", ($counter++%2) ? "tblrow1" : "tblrow2");
209 $vtpl->setVariable("FIGURE", $figure);
210 $vtpl->setVariable("YESTERDAY_VALUE", $values["yesterday"]);
211 $vtpl->setVariable("TODAY_VALUE", $values["today"]);
212 $vtpl->parseCurrentBlock();
213 }
214
215 $vtpl->setVariable("FIGURE_HEAD", $lng->txt("wiki_stat_figure"));
216 $vtpl->setVariable("YESTERDAY_HEAD", $lng->txt("yesterday"));
217 $vtpl->setVariable("TODAY_HEAD", $lng->txt("today"));
218
219 $chart_panel->setHeading($lng->txt("statistics"));
220 $chart_panel->setBody($vtpl->get());
221 $chart_panel->setHeadingStyle(ilPanelGUI::HEADING_STYLE_SUBHEADING);
222
223 $tpl->setContent($chart_panel->getHTML());
224 }
225 }
226
227 protected function getChartData($a_figure, $a_scope, $a_from, $a_to)
228 {
229 $data = array();
230
231 $raw = $this->page_id
232 ? ilWikiStat::getFigureDataPage($this->wiki_id, $this->page_id, $a_figure, $a_from, $a_to)
233 : ilWikiStat::getFigureData($this->wiki_id, $a_figure, $a_from, $a_to);
234
235 $parts = explode("-", $a_from);
236 for($loop = 0; $loop <= ($a_scope*31); $loop++)
237 {
238 $current_day = date("Y-m-d", mktime(0, 0, 1, $parts[1], $parts[2]+$loop, $parts[0]));
239 if($current_day <= $a_to)
240 {
241 $data[$current_day] = (float)$raw[$current_day];
242 }
243 }
244
245 return $data;
246 }
247
248 protected function getListData()
249 {
250 $data = array();
251
252 $today = date("Y-m-d");
253 $yesterday = date("Y-m-d", strtotime("yesterday"));
254
255 $all = $this->page_id
258 foreach($all as $figure => $title)
259 {
260 if($this->page_id)
261 {
262 $tmp = (array)ilWikiStat::getFigureDataPage($this->wiki_id, $this->page_id, $figure, $yesterday, $today);
263 }
264 else
265 {
266 $tmp = (array)ilWikiStat::getFigureData($this->wiki_id, $figure, $yesterday, $today);
267 }
268 $data[$title] = array(
269 "yesterday" => (float)$tmp[$yesterday],
270 "today" => (float)$tmp[$today]
271 );
272 }
273
274 return $data;
275 }
276
277 protected function renderGraph($a_figure, array $a_data)
278 {
279 $scope = ceil(sizeof($a_data)/31);
280
281 include_once "Services/Chart/classes/class.ilChartGrid.php";
283 $chart->setSize("100%", 400);
284 $chart->setColors(array("#C0E0FF"));
285
286 $legend = new ilChartLegend();
287 $chart->setLegend($legend);
288
289 // lines vs. bars
290 if(in_array($a_figure, array(
291 // wiki
304 // page
310 )))
311 {
312 $series = $chart->getDataInstance(ilChartGrid::DATA_LINES);
313 $series->setLineSteps(true);
314 $series->setFill(true, "#E0F0FF");
315 }
316 else
317 {
318 $series = $chart->getDataInstance(ilChartGrid::DATA_BARS);
319 $series->setBarOptions(round(10/($scope*2))/10);
320 }
321 $series->setLabel(ilWikiStat::getFigureTitle($a_figure));
322
323 $labels = array();
324 $x = 0;
325 foreach($a_data as $date => $value)
326 {
327 $series->addPoint($x, $value);
328
329 $day = (int)substr($date, 8, 2);
330
331 // match scale to scope
332 if($scope == 1)
333 {
334 // daily
335 $labels[$x] = substr($date, 8, 2);
336 }
337 elseif($scope == 2)
338 {
339 // weekly
340 if(!($x%7))
341 {
342 $labels[$x] = substr($date, 8, 2).".".substr($date, 5, 2).".";
343 }
344 }
345 else
346 {
347 // 1st/15th
348 if($day == 1 || $day == 15 || $x == sizeof($a_data)-1)
349 {
350 $labels[$x] = substr($date, 8, 2).".".substr($date, 5, 2).".";
351 }
352 }
353
354 $x++;
355 }
356
357 $chart->addData($series);
358 $chart->setTicks($labels, null, true);
359
360 // int vs. float (averages)
361 if(in_array($a_figure, array(
362 // wiki
375 // page
385 )))
386 {
387 $chart->setYAxisToInteger(true);
388 }
389
390 return $chart->getHTML();
391 }
392}
393
394?>
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
global $tpl
Definition: ilias.php:8
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATE
static _numericMonthToString($a_month, $a_long=true)
numeric month to string
static getInstanceByType($a_type, $a_id)
Get type instance.
const TYPE_GRID
static formatPeriod(ilDateTime $start, ilDateTime $end)
Format a period of two date Shows: 14.
Class for single dates.
static _lookupTitle($a_id)
lookup object title
const HEADING_STYLE_SUBHEADING
static getInstance()
Get instance.
This class represents a selection list property in a property form.
special template class to simplify handling of ITX/PEAR
Wiki statistics GUI class.
renderGraph($a_figure, array $a_data)
view($a_is_initial=false)
getChartData($a_figure, $a_scope, $a_from, $a_to)
__construct($a_wiki_id, $a_page_id=null)
viewToolbar($a_is_initial=false)
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
static getFigureDataPage($a_wiki_id, $a_page_id, $a_figure, $a_from, $a_to)
const KEY_FIGURE_WIKI_INTERNAL_LINKS
const KEY_FIGURE_WIKI_PAGE_RATINGS
static getAvailableMonths($a_wiki_id)
const KEY_FIGURE_WIKI_WORDS_AVG
static getFigureData($a_wiki_id, $a_figure, $a_from, $a_to)
const KEY_FIGURE_WIKI_READ_PAGES
const KEY_FIGURE_WIKI_NEW_PAGES
const KEY_FIGURE_WIKI_EDIT_PAGES
static getFigureTitle($a_figure)
const KEY_FIGURE_WIKI_EXTERNAL_LINKS_AVG
const KEY_FIGURE_WIKI_PAGE_CHANGES
const KEY_FIGURE_WIKI_INTERNAL_LINKS_AVG
static getFigureOptionsPage()
const KEY_FIGURE_WIKI_PAGE_INTERNAL_LINKS
const KEY_FIGURE_WIKI_FOOTNOTES
const KEY_FIGURE_WIKI_PAGE_USER_EDIT
static getFigureOptions()
const KEY_FIGURE_WIKI_FOOTNOTES_AVG
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
$counter
$x
Definition: example_009.php:98
$params
Definition: example_049.php:96
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:17
$cmd
Definition: sahs_server.php:35
if(!is_array($argv)) $options