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