ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilWikiStat.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 
82 {
83  const EVENT_PAGE_CREATED = 1;
84  const EVENT_PAGE_UPDATED = 2;
85  const EVENT_PAGE_READ = 3;
86  const EVENT_PAGE_DELETED = 4;
87  const EVENT_PAGE_RATING = 5;
88 
111 
122 
123  //
124  // WRITE
125  //
126 
135  public static function handleEvent($a_event, ilWikiPage $a_page_obj, $a_user_id = null, array $a_additional_data = null)
136  {
137  global $DIC;
138 
139  $ilUser = $DIC->user();
140 
141  if (!$a_user_id) {
142  $a_user_id = $ilUser->getId();
143  }
144  if (!$a_user_id || $a_user_id == ANONYMOUS_USER_ID) {
145  return;
146  }
147 
148  switch ((int) $a_event) {
149  case self::EVENT_PAGE_CREATED:
150  self::handlePageCreated($a_page_obj, $a_user_id);
151  break;
152 
153  case self::EVENT_PAGE_UPDATED:
154  self::handlePageUpdated($a_page_obj, $a_user_id, $a_additional_data);
155  break;
156 
157  case self::EVENT_PAGE_READ:
158  self::handlePageRead($a_page_obj, $a_user_id);
159  break;
160 
161  case self::EVENT_PAGE_DELETED:
162  self::handlePageDeletion($a_page_obj, $a_user_id);
163  break;
164 
165  case self::EVENT_PAGE_RATING:
166  self::handlePageRating($a_page_obj, $a_user_id);
167  break;
168 
169  default:
170  return;
171  }
172  }
173 
179  protected static function getTimestamp()
180  {
181  return date("Y-m-d H:00:00");
182  }
183 
194  protected static function writeData($a_table, array $a_primary, array $a_values)
195  {
196  global $DIC;
197 
198  $ilDB = $DIC->database();
199 
200  $tstamp = self::getTimestamp();
201  $a_primary["ts"] = array("timestamp", $tstamp);
202 
203  $ilAtomQuery = $ilDB->buildAtomQuery();
204  $ilAtomQuery->addTableLock($a_table);
205 
206  $ilAtomQuery->addQueryCallable(
207  function (ilDBInterface $ilDB) use ($a_table, $a_primary, $a_values, $tstamp, &$is_update) {
208  $primary = array();
209  foreach ($a_primary as $column => $value) {
210  $primary[] = $column . " = " . $ilDB->quote($value[1], $value[0]);
211  }
212  $primary = implode(" AND ", $primary);
213 
214  $set = $ilDB->query("SELECT ts FROM " . $a_table .
215  " WHERE " . $primary);
216 
217  $is_update = (bool) $ilDB->numRows($set);
218 
219  // update (current timeframe)
220  if ($is_update) {
221  $values = array();
222  foreach ($a_values as $column => $value) {
223  if ($value[0] == "increment") {
224  $values[] = $column . " = " . $column . "+1";
225  } elseif ($value[0] == "decrement") {
226  $values[] = $column . " = " . $column . "-1";
227  } else {
228  $values[] = $column . " = " . $ilDB->quote($value[1], $value[0]);
229  }
230  }
231  $values = implode(", ", $values);
232 
233  $sql = "UPDATE " . $a_table .
234  " SET " . $values .
235  " WHERE " . $primary;
236  }
237  // insert (no entry yet for current time frame)
238  else {
239  $a_values = array_merge($a_primary, $a_values);
240  $a_values["ts_day"] = array("text", substr($tstamp, 0, 10));
241  $a_values["ts_hour"] = array("integer", (int) substr($tstamp, 11, 2));
242 
243  $values = array();
244  foreach ($a_values as $column => $value) {
245  $columns[] = $column;
246  if ($value[0] == "increment") {
247  $value[0] = "integer";
248  } elseif ($value[0] == "decrement") {
249  $value[0] = "integer";
250  $value[1] = 0;
251  }
252  $values[] = $ilDB->quote($value[1], $value[0]);
253  }
254  $values = implode(", ", $values);
255  $columns = implode(", ", $columns);
256 
257  $sql = "INSERT INTO " . $a_table .
258  " (" . $columns . ")" .
259  " VALUES (" . $values . ")";
260  }
261  $ilDB->manipulate($sql);
262  }
263  );
264  $ilAtomQuery->run();
265 
266  return $is_update;
267  }
268 
275  protected static function writeStat($a_wiki_id, $a_values)
276  {
277  $primary = array(
278  "wiki_id" => array("integer", $a_wiki_id)
279  );
280  self::writeData("wiki_stat", $primary, $a_values);
281  }
282 
290  protected static function writeStatPage($a_wiki_id, $a_page_id, $a_values)
291  {
292  $primary = array(
293  "wiki_id" => array("integer", $a_wiki_id),
294  "page_id" => array("integer", $a_page_id),
295  );
296  self::writeData("wiki_stat_page", $primary, $a_values);
297  }
298 
307  protected static function writeStatPageUser($a_wiki_id, $a_page_id, $a_user_id, $a_values)
308  {
309  $primary = array(
310  "wiki_id" => array("integer", $a_wiki_id),
311  "page_id" => array("integer", $a_page_id),
312  "user_id" => array("integer", $a_user_id)
313  );
314  self::writeData("wiki_stat_page_user", $primary, $a_values);
315  }
316 
324  protected static function writeStatUser($a_wiki_id, $a_user_id, $a_values)
325  {
326  $primary = array(
327  "wiki_id" => array("integer", $a_wiki_id),
328  "user_id" => array("integer", $a_user_id)
329  );
330  self::writeData("wiki_stat_user", $primary, $a_values);
331  }
332 
339  protected static function countPages($a_wiki_id)
340  {
341  return sizeof(ilWikiPage::getAllWikiPages($a_wiki_id));
342  }
343 
351  protected static function getAverageRating($a_wiki_id, $a_page_id = null)
352  {
353  include_once "Services/Rating/classes/class.ilRating.php";
354 
355  if (!$a_page_id) {
357  $a_wiki_id,
358  "wiki"
359  );
360  } else {
362  $a_wiki_id,
363  "wiki",
364  $a_page_id,
365  "wpg"
366  );
367  }
368  }
369 
376  public static function handlePageCreated(ilWikiPage $a_page_obj, $a_user_id)
377  {
378  // wiki: num_pages (count)
379  self::writeStat(
380  $a_page_obj->getWikiId(),
381  array(
382  "num_pages" => array("integer", self::countPages($a_page_obj->getWikiId())),
383  "del_pages" => array("integer", 0),
384  "avg_rating" => array("integer", 0)
385  )
386  );
387 
388  // user: new_pages+1
389  self::writeStatUser(
390  $a_page_obj->getWikiId(),
391  $a_user_id,
392  array(
393  "new_pages" => array("increment", 1)
394  )
395  );
396  }
397 
405  public static function handlePageUpdated(ilWikiPage $a_page_obj, $a_user_id, array $a_page_data = null)
406  {
407  // page_user: changes+1
408  self::writeStatPageUser(
409  $a_page_obj->getWikiId(),
410  $a_page_obj->getId(),
411  $a_user_id,
412  array(
413  "changes" => array("increment", 1)
414  )
415  );
416 
417  // page: see ilWikiPage::afterUpdate()
418  $values = array(
419  "int_links" => array("integer", $a_page_data["int_links"]),
420  "ext_links" => array("integer", $a_page_data["ext_links"]),
421  "footnotes" => array("integer", $a_page_data["footnotes"]),
422  "num_words" => array("integer", $a_page_data["num_words"]),
423  "num_chars" => array("integer", $a_page_data["num_chars"]),
424  "num_ratings" => array("integer", 0),
425  "avg_rating" => array("integer", 0)
426  );
427  self::writeStatPage($a_page_obj->getWikiId(), $a_page_obj->getId(), $values);
428  }
429 
436  public static function handlePageRead(ilWikiPage $a_page_obj, $a_user_id)
437  {
438  // page_user: read_events+1
439  self::writeStatPageUser(
440  $a_page_obj->getWikiId(),
441  $a_page_obj->getId(),
442  $a_user_id,
443  array(
444  "read_events" => array("increment", 1)
445  )
446  );
447  }
448 
455  public static function handlePageDeletion(ilWikiPage $a_page_obj, $a_user_id)
456  {
457  global $DIC;
458 
459  $ilDB = $DIC->database();
460 
461  // copy last entry to have deletion timestamp
462  $sql = "SELECT * " .
463  " FROM wiki_stat_page" .
464  " WHERE wiki_id = " . $ilDB->quote($a_page_obj->getWikiId(), "integer") .
465  " AND page_id = " . $ilDB->quote($a_page_obj->getId(), "integer") .
466  " ORDER BY ts DESC";
467  $ilDB->setLimit(1);
468  $set = $ilDB->query($sql);
469 
470  // #15748
471  if ($ilDB->numRows($set)) {
472  $data = $ilDB->fetchAssoc($set);
473 
474  // see self::handlePageUpdated()
475  $values = array(
476  "int_links" => array("integer", $data["int_links"]),
477  "ext_links" => array("integer", $data["ext_links"]),
478  "footnotes" => array("integer", $data["footnotes"]),
479  "num_words" => array("integer", $data["num_words"]),
480  "num_chars" => array("integer", $data["num_chars"]),
481  "num_ratings" => array("integer", $data["num_ratings"]),
482  "avg_rating" => array("integer", $data["avg_rating"]),
483  );
484  self::writeStatPage((int) $a_page_obj->getWikiId(), $a_page_obj->getId(), $values);
485  }
486 
487  // mark all page entries as deleted
488  $ilDB->manipulate("UPDATE wiki_stat_page" .
489  " SET deleted = " . $ilDB->quote(1, "integer") .
490  " WHERE page_id = " . $ilDB->quote($a_page_obj->getId(), "integer") .
491  " AND wiki_id = " . $ilDB->quote($a_page_obj->getWikiId(), "integer"));
492 
493  // wiki: del_pages+1, num_pages (count), avg_rating
494  $rating = self::getAverageRating($a_page_obj->getWikiId());
495  self::writeStat(
496  $a_page_obj->getWikiId(),
497  array(
498  "del_pages" => array("increment", 1),
499  "num_pages" => array("integer", self::countPages($a_page_obj->getWikiId())),
500  "avg_rating" => array("integer", $rating["avg"] * 100)
501  )
502  );
503  }
504 
511  public static function handlePageRating(ilWikiPage $a_page_obj, $a_user_id)
512  {
513  // do page first!
514  $rating = self::getAverageRating($a_page_obj->getWikiId(), $a_page_obj->getId());
515 
516  // wiki_stat_page: num_ratings, avg_rating
517  self::writeStatPage(
518  $a_page_obj->getWikiId(),
519  $a_page_obj->getId(),
520  array(
521  "num_ratings" => array("integer", $rating["cnt"]),
522  "avg_rating" => array("integer", $rating["avg"] * 100),
523  )
524  );
525 
526  $rating = self::getAverageRating($a_page_obj->getWikiId());
527 
528  // wiki_stat: avg_rating
529  $is_update = self::writeStat(
530  $a_page_obj->getWikiId(),
531  array(
532  "avg_rating" => array("integer", $rating["avg"] * 100)
533  )
534  );
535 
536  if (!$is_update) {
537  // wiki: num_pages (count)
538  self::writeStat(
539  $a_page_obj->getWikiId(),
540  array(
541  "num_pages" => array("integer", self::countPages($a_page_obj->getWikiId()))
542  )
543  );
544  }
545  }
546 
547 
548  //
549  // READ HELPER
550  //
551 
552  protected static function getWikiAggr($a_wiki_id, $a_day_from, $a_day_to, $a_table, $a_field, $a_aggr_value, $a_sub_field = null, $a_sub_id = null, $a_build_full_period = false)
553  {
554  global $DIC;
555 
556  $ilDB = $DIC->database();
557 
558  $res = array();
559  $deleted = null;
560 
561  $sql = "SELECT ts_day, " . sprintf($a_aggr_value, $a_field) . " " . $a_field;
562  if ($a_table == "wiki_stat_page" && $a_sub_field) {
563  $sql .= ", MAX(deleted) deleted";
564  }
565  $sql .= " FROM " . $a_table .
566  " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
567  " AND ts_day >= " . $ilDB->quote($a_day_from, "text") .
568  " AND ts_day <= " . $ilDB->quote($a_day_to, "text");
569  if (!$a_build_full_period) {
570  // to build full period data we need all values in DB
571  $sql .= " AND " . $a_field . " > " . $ilDB->quote(0, "integer") .
572  " AND " . $a_field . " IS NOT NULL";
573  }
574  if ($a_sub_field) {
575  $sql .= " AND " . $a_sub_field . " = " . $ilDB->quote($a_sub_id, "integer");
576  }
577  $sql .= " GROUP BY ts_day" .
578  " ORDER BY ts_day";
579  $set = $ilDB->query($sql);
580  while ($row = $ilDB->fetchAssoc($set)) {
581  $res[$row["ts_day"]] = $row[$a_field];
582 
583  $deleted = max($row["deleted"], $deleted);
584  }
585 
586  if ($a_build_full_period) {
587  $period_first = $a_day_from;
588  $period_last = $a_day_to;
589 
590  // check if sub was deleted in period
591  if ($a_table == "wiki_stat_page" && $a_sub_field && $deleted) {
592  $sql = "SELECT MAX(ts_day) last_day, MIN(ts_day) first_day" .
593  " FROM " . $a_table .
594  " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
595  " AND " . $a_sub_field . " = " . $ilDB->quote($a_sub_id, "integer");
596  $set = $ilDB->query($sql);
597  $row = $ilDB->fetchAssoc($set);
598  $last_day = $row["last_day"];
599  if ($last_day < $period_last) {
600  $period_last = $last_day;
601  }
602  $first_day = $row["first_day"];
603  if ($first_day > $period_first) {
604  $period_first = $first_day;
605  }
606  }
607 
608  $last_before_period = null;
609  if (!$res[$a_day_from]) {
610  $last_before_period = self::getWikiLast($a_wiki_id, $a_day_from, $a_table, $a_field, $a_sub_field, $a_sub_id);
611  }
612 
613  // no need to allow zero here as we are not building averages
614  self::buildFullPeriodData($res, $period_first, $period_last, $last_before_period);
615  }
616 
617  return $res;
618  }
619 
620  protected static function getWikiLast($a_wiki_id, $a_day_from, $a_table, $a_field, $a_sub_field = null, $a_sub_id = null)
621  {
622  global $DIC;
623 
624  $ilDB = $DIC->database();
625 
626  // get last existing value before period (zero is valid)
627  $sql = "SELECT MAX(" . $a_field . ") latest" .
628  " FROM " . $a_table .
629  " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
630  " AND ts_day < " . $ilDB->quote($a_day_from, "text");
631  if ($a_sub_field) {
632  $sql .= " AND " . $a_sub_field . " = " . $ilDB->quote($a_sub_id, "integer");
633  }
634  $sql .= " GROUP BY ts_day" .
635  " ORDER BY ts_day DESC";
636  $ilDB->setLimit(1);
637  $set = $ilDB->query($sql);
638  $last_before_period = $ilDB->fetchAssoc($set);
639  return $last_before_period["latest"];
640  }
641 
642  protected static function getWikiAggrSub($a_wiki_id, $a_day_from, $a_day_to, $a_table, $a_field, $a_aggr_by, $a_aggr_value, $a_aggr_sub, $a_sub_field = null, $a_sub_id = null, $a_build_full_period = false)
643  {
644  global $DIC;
645 
646  $ilDB = $DIC->database();
647 
648  $res = array();
649 
650  if (!$a_build_full_period) {
651  $sql = "SELECT ts_day, " . sprintf($a_aggr_value, $a_field) . " " . $a_field .
652  " FROM (" .
653  // subquery to build average per $a_aggr_by
654  " SELECT ts_day, " . sprintf($a_aggr_sub, $a_field) . " " . $a_field .
655  " FROM " . $a_table .
656  " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
657  " AND ts_day >= " . $ilDB->quote($a_day_from, "text") .
658  " AND ts_day <= " . $ilDB->quote($a_day_to, "text") .
659  " AND " . $a_field . " > " . $ilDB->quote(0, "integer") .
660  " AND " . $a_field . " IS NOT NULL";
661  if ($a_sub_field) {
662  $sql .= " AND " . $a_sub_field . " = " . $ilDB->quote($a_sub_id, "integer");
663  }
664  $sql .= " GROUP BY ts_day, " . $a_aggr_by .
665  ") aggr_sub" .
666  " GROUP BY ts_day" .
667  " ORDER BY ts_day";
668  $set = $ilDB->query($sql);
669  while ($row = $ilDB->fetchAssoc($set)) {
670  $res[$row["ts_day"]] = $row[$a_field];
671  }
672  } else {
673  $tmp = $all_aggr_ids = $deleted_in_period = $first_day_in_period = array();
674 
675  if ($a_table != "wiki_stat_page") {
676  echo "can only build full period averages for wiki_stat_page";
677  exit();
678  }
679 
680  // as current period can be totally empty, gather existing subs
681  $sql = " SELECT *" .
682  " FROM (" .
683  " SELECT " . $a_aggr_by . ", MAX(deleted) deleted, MAX(ts_day) last_day, MIN(ts_day) first_day" .
684  " FROM " . $a_table .
685  " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
686  " GROUP BY " . $a_aggr_by .
687  ") aggr_sub" .
688  " WHERE first_day <= " . $ilDB->quote($a_day_to, "text") . // not created after period
689  " AND (last_day >= " . $ilDB->quote($a_day_from, "text") . // (deleted in/after period
690  " OR deleted = " . $ilDB->quote(0, "integer") . ")"; // or still existing)
691  $set = $ilDB->query($sql);
692  while ($row = $ilDB->fetchAssoc($set)) {
693  $all_aggr_ids[] = $row[$a_aggr_by];
694 
695  // if deleted in period we need the last day
696  if ($row["deleted"] && $row["last_day"] < $a_day_to) {
697  $deleted_in_period[$row[$a_aggr_by]] = $row["last_day"];
698  }
699  // if created in period we need the first day
700  if ($row["first_day"] > $a_day_from) {
701  $first_day_in_period[$row[$a_aggr_by]] = $row["first_day"];
702  }
703  }
704 
705  // we need to build average manually after completing period data (zero is valid)
706  $sql = " SELECT ts_day, " . $a_aggr_by . ", " . sprintf($a_aggr_sub, $a_field) . " " . $a_field .
707  " FROM " . $a_table .
708  " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
709  " AND ts_day >= " . $ilDB->quote($a_day_from, "text") .
710  " AND ts_day <= " . $ilDB->quote($a_day_to, "text");
711  $sql .= " GROUP BY ts_day, " . $a_aggr_by;
712  $set = $ilDB->query($sql);
713  while ($row = $ilDB->fetchAssoc($set)) {
714  if (!in_array($row[$a_aggr_by], $all_aggr_ids)) {
715  var_dump("unexpected wiki_stat_page_entry", $row);
716  }
717  $tmp[$row[$a_aggr_by]][$row["ts_day"]] = $row[$a_field];
718  }
719 
720  // build full period for each sub
721  foreach ($all_aggr_ids as $aggr_by_id) {
722  // last of entry of sub is before period
723  if (!is_array($tmp[$aggr_by_id])) {
724  $tmp[$aggr_by_id] = array();
725  }
726 
727  // get last value before period to add missing entries in period
728  $last_before_period = null;
729  if (!$tmp[$aggr_by_id][$a_day_from]) {
730  $last_before_period = self::getWikiLast($a_wiki_id, $a_day_from, $a_table, $a_field, $a_aggr_by, $aggr_by_id);
731  }
732 
733  // if sub was created in period (see above), shorten period accordingly
734  $first_period_day = isset($first_day_in_period[$aggr_by_id])
735  ? $first_day_in_period[$aggr_by_id]
736  : $a_day_from;
737 
738  // if sub was deleted in period (see above), shorten period accordingly
739  $last_period_day = isset($deleted_in_period[$aggr_by_id])
740  ? $deleted_in_period[$aggr_by_id]
741  : $a_day_to;
742 
743  // allow zero as we need to correct number of valid subs per day (see below - AVG)
744  self::buildFullPeriodData($tmp[$aggr_by_id], $first_period_day, $last_period_day, $last_before_period, true);
745 
746  // distribute sub to days
747  foreach ($tmp[$aggr_by_id] as $day => $value) {
748  $res[$day][$aggr_by_id] = $value;
749  }
750  }
751 
752  // build average over subs
753  foreach ($res as $day => $values) {
754  switch ($a_aggr_value) {
755  case "AVG(%s)":
756  $res[$day] = array_sum($values) / sizeof($values);
757  break;
758 
759  case "SUM(%s)":
760  $res[$day] = array_sum($values);
761  break;
762 
763  default:
764  var_dump("unsupport aggr " . $a_aggr_value);
765  break;
766  }
767  }
768  }
769 
770  return $res;
771  }
772 
773  protected static function buildFullPeriodData(array &$a_res, $a_day_from, $a_day_to, $a_last_before_period, $a_allow_zero = false)
774  {
775  // build full data for period
776  $safety = 0;
777  $last = null;
778  $today = date("Y-m-d");
779  $current = explode("-", $a_day_from);
780  $current = date("Y-m-d", mktime(0, 0, 1, $current[1], $current[2], $current[0]));
781  while ($current <= $a_day_to &&
782  ++$safety < 1000) {
783  if (!isset($a_res[$current])) {
784  if ($current <= $today) {
785  // last existing value in period
786  if ($last !== null) {
787  $a_res[$current] = $last;
788  }
789  // last existing value before period
790  elseif ($a_last_before_period || $a_allow_zero) {
791  $a_res[$current] = $a_last_before_period;
792  }
793  }
794  } else {
795  $last = $a_res[$current];
796  }
797 
798  $current = explode("-", $current);
799  $current = date("Y-m-d", mktime(0, 0, 1, $current[1], $current[2] + 1, $current[0]));
800  }
801  }
802 
803 
804  //
805  // READ WIKI
806  //
807 
808  protected static function getWikiNumPages($a_wiki_id, $a_day_from, $a_day_to)
809  {
810  return self::getWikiAggr($a_wiki_id, $a_day_from, $a_day_to, "wiki_stat", "num_pages", "MAX(%s)", null, null, true);
811  }
812 
813  protected static function getWikiNewPagesSum($a_wiki_id, $a_day_from, $a_day_to)
814  {
815  return self::getWikiAggr($a_wiki_id, $a_day_from, $a_day_to, "wiki_stat_user", "new_pages", "SUM(%s)");
816  }
817 
818  protected static function getWikiNewPagesAvg($a_wiki_id, $a_day_from, $a_day_to)
819  {
820  return self::getWikiAggrSub($a_wiki_id, $a_day_from, $a_day_to, "wiki_stat_user", "new_pages", "user_id", "AVG(%s)", "SUM(%s)");
821  }
822 
823  protected static function getWikiDeletedPages($a_wiki_id, $a_day_from, $a_day_to)
824  {
825  return self::getWikiAggr($a_wiki_id, $a_day_from, $a_day_to, "wiki_stat", "del_pages", "SUM(%s)");
826  }
827 
828  protected static function getWikiReadPages($a_wiki_id, $a_day_from, $a_day_to)
829  {
830  return self::getWikiAggr($a_wiki_id, $a_day_from, $a_day_to, "wiki_stat_page_user", "read_events", "SUM(%s)");
831  }
832 
833  protected static function getWikiEditPagesSum($a_wiki_id, $a_day_from, $a_day_to)
834  {
835  global $DIC;
836 
837  $ilDB = $DIC->database();
838 
839  $res = array();
840 
841  $sql = "SELECT ts_day, COUNT(DISTINCT(page_id)) num_changed_pages" .
842  " FROM wiki_stat_page_user" .
843  " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
844  " AND ts_day >= " . $ilDB->quote($a_day_from, "text") .
845  " AND ts_day <= " . $ilDB->quote($a_day_to, "text") .
846  " AND changes > " . $ilDB->quote(0, "integer") .
847  " AND changes IS NOT NULL" .
848  " GROUP BY ts_day" .
849  " ORDER BY ts_day";
850  $set = $ilDB->query($sql);
851  while ($row = $ilDB->fetchAssoc($set)) {
852  $res[$row["ts_day"]] = $row["num_changed_pages"];
853  }
854 
855  return $res;
856  }
857 
858  protected static function getWikiEditPagesAvg($a_wiki_id, $a_day_from, $a_day_to)
859  {
860  global $DIC;
861 
862  $ilDB = $DIC->database();
863 
864  $res = array();
865 
866  $sql = "SELECT ts_day, AVG(num_changed_pages) num_changed_pages" .
867  " FROM (" .
868  // subquery to build average per user
869  " SELECT ts_day, COUNT(DISTINCT(page_id)) num_changed_pages" .
870  " FROM wiki_stat_page_user" .
871  " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
872  " AND ts_day >= " . $ilDB->quote($a_day_from, "text") .
873  " AND ts_day <= " . $ilDB->quote($a_day_to, "text") .
874  " AND changes > " . $ilDB->quote(0, "integer") .
875  " AND changes IS NOT NULL" .
876  " GROUP BY ts_day, user_id" .
877  ") aggr_user" .
878  " GROUP BY ts_day" .
879  " ORDER BY ts_day";
880  $set = $ilDB->query($sql);
881  while ($row = $ilDB->fetchAssoc($set)) {
882  $res[$row["ts_day"]] = $row["num_changed_pages"];
883  }
884 
885  return $res;
886  }
887 
888  protected static function getWikiUserEditPages($a_wiki_id, $a_day_from, $a_day_to, $a_sub_field = null, $a_sub_id = null)
889  {
890  global $DIC;
891 
892  $ilDB = $DIC->database();
893 
894  $res = array();
895 
896  $sql = "SELECT ts_day, COUNT(DISTINCT(user_id)) num_changed_users" .
897  " FROM wiki_stat_page_user" .
898  " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
899  " AND ts_day >= " . $ilDB->quote($a_day_from, "text") .
900  " AND ts_day <= " . $ilDB->quote($a_day_to, "text") .
901  " AND changes > " . $ilDB->quote(0, "integer") .
902  " AND changes IS NOT NULL";
903  if ($a_sub_field) {
904  $sql .= " AND " . $a_sub_field . " = " . $ilDB->quote($a_sub_id, "integer");
905  }
906  $sql .= " GROUP BY ts_day" .
907  " ORDER BY ts_day";
908  $set = $ilDB->query($sql);
909  while ($row = $ilDB->fetchAssoc($set)) {
910  $res[$row["ts_day"]] = $row["num_changed_users"];
911  }
912 
913  return $res;
914  }
915 
916  protected static function getWikiUserEditPagesAvg($a_wiki_id, $a_day_from, $a_day_to)
917  {
918  global $DIC;
919 
920  $ilDB = $DIC->database();
921 
922  $res = array();
923 
924  $sql = "SELECT ts_day, AVG(num_changed_users) num_changed_users" .
925  " FROM (" .
926  // subquery to build average per page
927  " SELECT ts_day, COUNT(DISTINCT(user_id)) num_changed_users" .
928  " FROM wiki_stat_page_user" .
929  " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
930  " AND ts_day >= " . $ilDB->quote($a_day_from, "text") .
931  " AND ts_day <= " . $ilDB->quote($a_day_to, "text") .
932  " AND changes > " . $ilDB->quote(0, "integer") .
933  " AND changes IS NOT NULL" .
934  " GROUP BY ts_day, page_id" .
935  ") aggr_user" .
936  " GROUP BY ts_day" .
937  " ORDER BY ts_day";
938  $set = $ilDB->query($sql);
939  while ($row = $ilDB->fetchAssoc($set)) {
940  $res[$row["ts_day"]] = $row["num_changed_users"];
941  }
942 
943  return $res;
944  }
945 
946  protected static function getWikiNumRating($a_wiki_id, $a_day_from, $a_day_to)
947  {
948  return self::getWikiAggr($a_wiki_id, $a_day_from, $a_day_to, "wiki_stat_page", "num_ratings", "SUM(%s)");
949  }
950 
951  protected static function getWikiNumRatingAvg($a_wiki_id, $a_day_from, $a_day_to)
952  {
953  return self::getWikiAggrSub($a_wiki_id, $a_day_from, $a_day_to, "wiki_stat_page", "num_ratings", "page_id", "AVG(%s)", "SUM(%s)");
954  }
955 
956  protected static function getWikiRatingAvg($a_wiki_id, $a_day_from, $a_day_to)
957  {
958  $res = self::getWikiAggr($a_wiki_id, $a_day_from, $a_day_to, "wiki_stat", "avg_rating", "AVG(%s)");
959 
960  foreach (array_keys($res) as $day) {
961  // int-to-float
962  $res[$day] = $res[$day] / 100;
963  }
964 
965  return $res;
966  }
967 
968  protected static function getWikiInternalLinks($a_wiki_id, $a_day_from, $a_day_to)
969  {
970  return self::getWikiAggrSub($a_wiki_id, $a_day_from, $a_day_to, "wiki_stat_page", "int_links", "page_id", "SUM(%s)", "MAX(%s)", null, null, true);
971  }
972 
973  protected static function getWikiInternalLinksAvg($a_wiki_id, $a_day_from, $a_day_to)
974  {
975  return self::getWikiAggrSub($a_wiki_id, $a_day_from, $a_day_to, "wiki_stat_page", "int_links", "page_id", "AVG(%s)", "MAX(%s)", null, null, true);
976  }
977 
978  protected static function getWikiExternalLinks($a_wiki_id, $a_day_from, $a_day_to)
979  {
980  return self::getWikiAggrSub($a_wiki_id, $a_day_from, $a_day_to, "wiki_stat_page", "ext_links", "page_id", "SUM(%s)", "MAX(%s)", null, null, true);
981  }
982 
983  protected static function getWikiExternalLinksAvg($a_wiki_id, $a_day_from, $a_day_to)
984  {
985  return self::getWikiAggrSub($a_wiki_id, $a_day_from, $a_day_to, "wiki_stat_page", "ext_links", "page_id", "AVG(%s)", "MAX(%s)", null, null, true);
986  }
987 
988  protected static function getWikiWords($a_wiki_id, $a_day_from, $a_day_to)
989  {
990  return self::getWikiAggrSub($a_wiki_id, $a_day_from, $a_day_to, "wiki_stat_page", "num_words", "page_id", "SUM(%s)", "MAX(%s)", null, null, true);
991  }
992 
993  protected static function getWikiWordsAvg($a_wiki_id, $a_day_from, $a_day_to)
994  {
995  return self::getWikiAggrSub($a_wiki_id, $a_day_from, $a_day_to, "wiki_stat_page", "num_words", "page_id", "AVG(%s)", "MAX(%s)", null, null, true);
996  }
997 
998  protected static function getWikiCharacters($a_wiki_id, $a_day_from, $a_day_to)
999  {
1000  return self::getWikiAggrSub($a_wiki_id, $a_day_from, $a_day_to, "wiki_stat_page", "num_chars", "page_id", "SUM(%s)", "MAX(%s)", null, null, true);
1001  }
1002 
1003  protected static function getWikiCharactersAvg($a_wiki_id, $a_day_from, $a_day_to)
1004  {
1005  return self::getWikiAggrSub($a_wiki_id, $a_day_from, $a_day_to, "wiki_stat_page", "num_chars", "page_id", "AVG(%s)", "MAX(%s)", null, null, true);
1006  }
1007 
1008  protected static function getWikiFootnotes($a_wiki_id, $a_day_from, $a_day_to)
1009  {
1010  return self::getWikiAggrSub($a_wiki_id, $a_day_from, $a_day_to, "wiki_stat_page", "footnotes", "page_id", "SUM(%s)", "MAX(%s)", null, null, true);
1011  }
1012 
1013  protected static function getWikiFootnotesAvg($a_wiki_id, $a_day_from, $a_day_to)
1014  {
1015  return self::getWikiAggrSub($a_wiki_id, $a_day_from, $a_day_to, "wiki_stat_page", "footnotes", "page_id", "AVG(%s)", "MAX(%s)", null, null, true);
1016  }
1017 
1018 
1019  //
1020  // READ PAGE
1021  //
1022 
1023  protected static function getWikiPageChanges($a_wiki_id, $a_page_id, $a_day_from, $a_day_to)
1024  {
1025  return self::getWikiAggr($a_wiki_id, $a_day_from, $a_day_to, "wiki_stat_page_user", "changes", "SUM(%s)", "page_id", $a_page_id);
1026  }
1027 
1028  protected static function getWikiPageChangesAvg($a_wiki_id, $a_page_id, $a_day_from, $a_day_to)
1029  {
1030  return self::getWikiAggrSub($a_wiki_id, $a_day_from, $a_day_to, "wiki_stat_page_user", "changes", "user_id", "AVG(%s)", "SUM(%s)", "page_id", $a_page_id);
1031  }
1032 
1033  protected static function getWikiPageUserEdit($a_wiki_id, $a_page_id, $a_day_from, $a_day_to)
1034  {
1035  return self::getWikiUserEditPages($a_wiki_id, $a_day_from, $a_day_to, "page_id", $a_page_id);
1036  }
1037 
1038  protected static function getWikiPageRead($a_wiki_id, $a_page_id, $a_day_from, $a_day_to)
1039  {
1040  return self::getWikiAggr($a_wiki_id, $a_day_from, $a_day_to, "wiki_stat_page_user", "read_events", "SUM(%s)", "page_id", $a_page_id);
1041  }
1042 
1043  protected static function getWikiPageInternalLinks($a_wiki_id, $a_page_id, $a_day_from, $a_day_to)
1044  {
1045  return self::getWikiAggr($a_wiki_id, $a_day_from, $a_day_to, "wiki_stat_page", "int_links", "MAX(%s)", "page_id", $a_page_id, true);
1046  }
1047 
1048  protected static function getWikiPageExternalLinks($a_wiki_id, $a_page_id, $a_day_from, $a_day_to)
1049  {
1050  return self::getWikiAggr($a_wiki_id, $a_day_from, $a_day_to, "wiki_stat_page", "ext_links", "MAX(%s)", "page_id", $a_page_id, true);
1051  }
1052 
1053  protected static function getWikiPageWords($a_wiki_id, $a_page_id, $a_day_from, $a_day_to)
1054  {
1055  return self::getWikiAggr($a_wiki_id, $a_day_from, $a_day_to, "wiki_stat_page", "num_words", "MAX(%s)", "page_id", $a_page_id, true);
1056  }
1057 
1058  protected static function getWikiPageCharacters($a_wiki_id, $a_page_id, $a_day_from, $a_day_to)
1059  {
1060  return self::getWikiAggr($a_wiki_id, $a_day_from, $a_day_to, "wiki_stat_page", "num_chars", "MAX(%s)", "page_id", $a_page_id, true);
1061  }
1062 
1063  protected static function getWikiPageFootnotes($a_wiki_id, $a_page_id, $a_day_from, $a_day_to)
1064  {
1065  return self::getWikiAggr($a_wiki_id, $a_day_from, $a_day_to, "wiki_stat_page", "footnotes", "MAX(%s)", "page_id", $a_page_id, true);
1066  }
1067 
1068  protected static function getWikiPageRatings($a_wiki_id, $a_page_id, $a_day_from, $a_day_to)
1069  {
1070  return self::getWikiAggr($a_wiki_id, $a_day_from, $a_day_to, "wiki_stat_page", "num_ratings", "SUM(%s)", "page_id", $a_page_id);
1071  }
1072 
1073 
1074  //
1075  // GUI HELPER
1076  //
1077 
1078  public static function getAvailableMonths($a_wiki_id)
1079  {
1080  global $DIC;
1081 
1082  $ilDB = $DIC->database();
1083 
1084  $res = array();
1085 
1086  // because of read_events this db table is updated most often
1087  $set = $ilDB->query("SELECT DISTINCT(SUBSTR(ts_day, 1, 7)) " . $ilDB->quoteIdentifier("month") .
1088  " FROM wiki_stat_page_user" .
1089  " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
1090  " AND ts_day IS NOT NULL");
1091  while ($row = $ilDB->fetchAssoc($set)) {
1092  $res[] = $row["month"];
1093  }
1094 
1095  return $res;
1096  }
1097 
1098  public static function getFigures()
1099  {
1100  return array(
1101  self::KEY_FIGURE_WIKI_NUM_PAGES
1102  ,self::KEY_FIGURE_WIKI_NEW_PAGES
1103  ,self::KEY_FIGURE_WIKI_NEW_PAGES_AVG
1104  ,self::KEY_FIGURE_WIKI_EDIT_PAGES
1105  ,self::KEY_FIGURE_WIKI_EDIT_PAGES_AVG
1106  ,self::KEY_FIGURE_WIKI_DELETED_PAGES
1107  ,self::KEY_FIGURE_WIKI_READ_PAGES
1108  ,self::KEY_FIGURE_WIKI_USER_EDIT_PAGES
1109  ,self::KEY_FIGURE_WIKI_USER_EDIT_PAGES_AVG
1110  ,self::KEY_FIGURE_WIKI_NUM_RATING
1111  ,self::KEY_FIGURE_WIKI_NUM_RATING_AVG
1112  ,self::KEY_FIGURE_WIKI_RATING_AVG
1113  ,self::KEY_FIGURE_WIKI_INTERNAL_LINKS
1114  ,self::KEY_FIGURE_WIKI_INTERNAL_LINKS_AVG
1115  ,self::KEY_FIGURE_WIKI_EXTERNAL_LINKS
1116  ,self::KEY_FIGURE_WIKI_EXTERNAL_LINKS_AVG
1117  ,self::KEY_FIGURE_WIKI_WORDS
1118  ,self::KEY_FIGURE_WIKI_WORDS_AVG
1119  ,self::KEY_FIGURE_WIKI_CHARS
1120  ,self::KEY_FIGURE_WIKI_CHARS_AVG
1121  ,self::KEY_FIGURE_WIKI_FOOTNOTES
1122  ,self::KEY_FIGURE_WIKI_FOOTNOTES_AVG
1123  );
1124  }
1125 
1126  public static function getFiguresPage()
1127  {
1128  return array(
1129  self::KEY_FIGURE_WIKI_PAGE_CHANGES
1130  ,self::KEY_FIGURE_WIKI_PAGE_CHANGES_AVG
1131  ,self::KEY_FIGURE_WIKI_PAGE_USER_EDIT
1132  ,self::KEY_FIGURE_WIKI_PAGE_READ
1133  ,self::KEY_FIGURE_WIKI_PAGE_INTERNAL_LINKS
1134  ,self::KEY_FIGURE_WIKI_PAGE_EXTERNAL_LINKS
1135  ,self::KEY_FIGURE_WIKI_PAGE_WORDS
1136  ,self::KEY_FIGURE_WIKI_PAGE_CHARS
1137  ,self::KEY_FIGURE_WIKI_PAGE_FOOTNOTES
1138  ,self::KEY_FIGURE_WIKI_PAGE_RATINGS
1139  );
1140  }
1141 
1142  public static function getFigureTitle($a_figure)
1143  {
1144  global $DIC;
1145 
1146  $lng = $DIC->language();
1147 
1148  $map = array(
1149  // wiki
1150  self::KEY_FIGURE_WIKI_NUM_PAGES => $lng->txt("wiki_stat_num_pages")
1151  ,self::KEY_FIGURE_WIKI_NEW_PAGES => $lng->txt("wiki_stat_new_pages")
1152  ,self::KEY_FIGURE_WIKI_NEW_PAGES_AVG => $lng->txt("wiki_stat_new_pages_avg")
1153  ,self::KEY_FIGURE_WIKI_EDIT_PAGES => $lng->txt("wiki_stat_edit_pages")
1154  ,self::KEY_FIGURE_WIKI_EDIT_PAGES_AVG => $lng->txt("wiki_stat_edit_pages_avg")
1155  ,self::KEY_FIGURE_WIKI_DELETED_PAGES => $lng->txt("wiki_stat_deleted_pages")
1156  ,self::KEY_FIGURE_WIKI_READ_PAGES => $lng->txt("wiki_stat_read_pages")
1157  ,self::KEY_FIGURE_WIKI_USER_EDIT_PAGES => $lng->txt("wiki_stat_user_edit_pages")
1158  ,self::KEY_FIGURE_WIKI_USER_EDIT_PAGES_AVG => $lng->txt("wiki_stat_user_edit_pages_avg")
1159  ,self::KEY_FIGURE_WIKI_NUM_RATING => $lng->txt("wiki_stat_num_rating")
1160  ,self::KEY_FIGURE_WIKI_NUM_RATING_AVG => $lng->txt("wiki_stat_num_rating_avg")
1161  ,self::KEY_FIGURE_WIKI_RATING_AVG => $lng->txt("wiki_stat_rating_avg")
1162  ,self::KEY_FIGURE_WIKI_INTERNAL_LINKS => $lng->txt("wiki_stat_internal_links")
1163  ,self::KEY_FIGURE_WIKI_INTERNAL_LINKS_AVG => $lng->txt("wiki_stat_internal_links_avg")
1164  ,self::KEY_FIGURE_WIKI_EXTERNAL_LINKS => $lng->txt("wiki_stat_external_links")
1165  ,self::KEY_FIGURE_WIKI_EXTERNAL_LINKS_AVG => $lng->txt("wiki_stat_external_links_avg")
1166  ,self::KEY_FIGURE_WIKI_WORDS => $lng->txt("wiki_stat_words")
1167  ,self::KEY_FIGURE_WIKI_WORDS_AVG => $lng->txt("wiki_stat_words_avg")
1168  ,self::KEY_FIGURE_WIKI_CHARS => $lng->txt("wiki_stat_chars")
1169  ,self::KEY_FIGURE_WIKI_CHARS_AVG => $lng->txt("wiki_stat_chars_avg")
1170  ,self::KEY_FIGURE_WIKI_FOOTNOTES => $lng->txt("wiki_stat_footnotes")
1171  ,self::KEY_FIGURE_WIKI_FOOTNOTES_AVG => $lng->txt("wiki_stat_footnotes_avg")
1172  // page
1173  ,self::KEY_FIGURE_WIKI_PAGE_CHANGES => $lng->txt("wiki_stat_page_changes")
1174  ,self::KEY_FIGURE_WIKI_PAGE_CHANGES_AVG => $lng->txt("wiki_stat_page_changes_avg")
1175  ,self::KEY_FIGURE_WIKI_PAGE_USER_EDIT => $lng->txt("wiki_stat_page_user_edit")
1176  ,self::KEY_FIGURE_WIKI_PAGE_READ => $lng->txt("wiki_stat_page_read")
1177  ,self::KEY_FIGURE_WIKI_PAGE_INTERNAL_LINKS => $lng->txt("wiki_stat_page_internal_links")
1178  ,self::KEY_FIGURE_WIKI_PAGE_EXTERNAL_LINKS => $lng->txt("wiki_stat_page_external_links")
1179  ,self::KEY_FIGURE_WIKI_PAGE_WORDS => $lng->txt("wiki_stat_page_words")
1180  ,self::KEY_FIGURE_WIKI_PAGE_CHARS => $lng->txt("wiki_stat_page_characters")
1181  ,self::KEY_FIGURE_WIKI_PAGE_FOOTNOTES => $lng->txt("wiki_stat_page_footnotes")
1182  ,self::KEY_FIGURE_WIKI_PAGE_RATINGS => $lng->txt("wiki_stat_page_ratings")
1183  );
1184 
1185  return $map[$a_figure];
1186  }
1187 
1188  public static function getFigureData($a_wiki_id, $a_figure, $a_from, $a_to)
1189  {
1190  switch ($a_figure) {
1191  case self::KEY_FIGURE_WIKI_NUM_PAGES:
1192  return self::getWikiNumPages($a_wiki_id, $a_from, $a_to);
1193 
1194  case self::KEY_FIGURE_WIKI_NEW_PAGES:
1195  return self::getWikiNewPagesSum($a_wiki_id, $a_from, $a_to);
1196 
1197  case self::KEY_FIGURE_WIKI_NEW_PAGES_AVG:
1198  return self::getWikiNewPagesAvg($a_wiki_id, $a_from, $a_to);
1199 
1200  case self::KEY_FIGURE_WIKI_EDIT_PAGES:
1201  return self::getWikiEditPagesSum($a_wiki_id, $a_from, $a_to);
1202 
1203  case self::KEY_FIGURE_WIKI_EDIT_PAGES_AVG:
1204  return self::getWikiEditPagesAvg($a_wiki_id, $a_from, $a_to);
1205 
1206  case self::KEY_FIGURE_WIKI_DELETED_PAGES:
1207  return self::getWikiDeletedPages($a_wiki_id, $a_from, $a_to);
1208 
1209  case self::KEY_FIGURE_WIKI_READ_PAGES:
1210  return self::getWikiReadPages($a_wiki_id, $a_from, $a_to);
1211 
1212  case self::KEY_FIGURE_WIKI_USER_EDIT_PAGES:
1213  return self::getWikiUserEditPages($a_wiki_id, $a_from, $a_to);
1214 
1215  case self::KEY_FIGURE_WIKI_USER_EDIT_PAGES_AVG:
1216  return self::getWikiUserEditPages($a_wiki_id, $a_from, $a_to);
1217 
1218  case self::KEY_FIGURE_WIKI_NUM_RATING:
1219  return self::getWikiNumRating($a_wiki_id, $a_from, $a_to);
1220 
1221  case self::KEY_FIGURE_WIKI_NUM_RATING_AVG:
1222  return self::getWikiNumRatingAvg($a_wiki_id, $a_from, $a_to);
1223 
1224  case self::KEY_FIGURE_WIKI_RATING_AVG:
1225  return self::getWikiRatingAvg($a_wiki_id, $a_from, $a_to);
1226 
1227  case self::KEY_FIGURE_WIKI_INTERNAL_LINKS:
1228  return self::getWikiInternalLinks($a_wiki_id, $a_from, $a_to);
1229 
1230  case self::KEY_FIGURE_WIKI_INTERNAL_LINKS_AVG:
1231  return self::getWikiInternalLinksAvg($a_wiki_id, $a_from, $a_to);
1232 
1233  case self::KEY_FIGURE_WIKI_EXTERNAL_LINKS:
1234  return self::getWikiExternalLinks($a_wiki_id, $a_from, $a_to);
1235 
1236  case self::KEY_FIGURE_WIKI_EXTERNAL_LINKS_AVG:
1237  return self::getWikiExternalLinksAvg($a_wiki_id, $a_from, $a_to);
1238 
1239  case self::KEY_FIGURE_WIKI_WORDS:
1240  return self::getWikiWords($a_wiki_id, $a_from, $a_to);
1241 
1242  case self::KEY_FIGURE_WIKI_WORDS_AVG:
1243  return self::getWikiWordsAvg($a_wiki_id, $a_from, $a_to);
1244 
1245  case self::KEY_FIGURE_WIKI_CHARS:
1246  return self::getWikiCharacters($a_wiki_id, $a_from, $a_to);
1247 
1248  case self::KEY_FIGURE_WIKI_CHARS_AVG:
1249  return self::getWikiCharactersAvg($a_wiki_id, $a_from, $a_to);
1250 
1251  case self::KEY_FIGURE_WIKI_FOOTNOTES:
1252  return self::getWikiFootnotes($a_wiki_id, $a_from, $a_to);
1253 
1254  case self::KEY_FIGURE_WIKI_FOOTNOTES_AVG:
1255  return self::getWikiFootnotesAvg($a_wiki_id, $a_from, $a_to);
1256  }
1257  }
1258 
1259  public static function getFigureDataPage($a_wiki_id, $a_page_id, $a_figure, $a_from, $a_to)
1260  {
1261  switch ($a_figure) {
1262  case self::KEY_FIGURE_WIKI_PAGE_CHANGES:
1263  return self::getWikiPageChanges($a_wiki_id, $a_page_id, $a_from, $a_to);
1264 
1265  case self::KEY_FIGURE_WIKI_PAGE_CHANGES_AVG:
1266  return self::getWikiPageChangesAvg($a_wiki_id, $a_page_id, $a_from, $a_to);
1267 
1268  case self::KEY_FIGURE_WIKI_PAGE_USER_EDIT:
1269  return self::getWikiPageUserEdit($a_wiki_id, $a_page_id, $a_from, $a_to);
1270 
1271  case self::KEY_FIGURE_WIKI_PAGE_READ:
1272  return self::getWikiPageRead($a_wiki_id, $a_page_id, $a_from, $a_to);
1273 
1274  case self::KEY_FIGURE_WIKI_PAGE_INTERNAL_LINKS:
1275  return self::getWikiPageInternalLinks($a_wiki_id, $a_page_id, $a_from, $a_to);
1276 
1277  case self::KEY_FIGURE_WIKI_PAGE_EXTERNAL_LINKS:
1278  return self::getWikiPageExternalLinks($a_wiki_id, $a_page_id, $a_from, $a_to);
1279 
1280  case self::KEY_FIGURE_WIKI_PAGE_FOOTNOTES:
1281  return self::getWikiPageFootnotes($a_wiki_id, $a_page_id, $a_from, $a_to);
1282 
1283  case self::KEY_FIGURE_WIKI_PAGE_WORDS:
1284  return self::getWikiPageWords($a_wiki_id, $a_page_id, $a_from, $a_to);
1285 
1286  case self::KEY_FIGURE_WIKI_PAGE_CHARS:
1287  return self::getWikiPageCharacters($a_wiki_id, $a_page_id, $a_from, $a_to);
1288 
1289  case self::KEY_FIGURE_WIKI_PAGE_RATINGS:
1290  return self::getWikiPageRatings($a_wiki_id, $a_page_id, $a_from, $a_to);
1291  }
1292  }
1293 
1294  public static function getFigureOptions()
1295  {
1296  $res = array();
1297 
1298  foreach (self::getFigures() as $figure) {
1299  $res[$figure] = self::getFigureTitle($figure);
1300  }
1301 
1302  return $res;
1303  }
1304 
1305  public static function getFigureOptionsPage()
1306  {
1307  $res = array();
1308 
1309  foreach (self::getFiguresPage() as $figure) {
1310  $res[$figure] = self::getFigureTitle($figure);
1311  }
1312 
1313  return $res;
1314  }
1315 }
const KEY_FIGURE_WIKI_PAGE_USER_EDIT
static getFigures()
static getWikiInternalLinksAvg($a_wiki_id, $a_day_from, $a_day_to)
static getWikiWords($a_wiki_id, $a_day_from, $a_day_to)
const KEY_FIGURE_WIKI_NUM_RATING
const KEY_FIGURE_WIKI_WORDS
static writeStat($a_wiki_id, $a_values)
Write data to wiki_stat.
const KEY_FIGURE_WIKI_FOOTNOTES
const KEY_FIGURE_WIKI_USER_EDIT_PAGES
static getWikiPageChanges($a_wiki_id, $a_page_id, $a_day_from, $a_day_to)
const KEY_FIGURE_WIKI_PAGE_RATINGS
getWikiId()
Get Wiki Object Id.
const KEY_FIGURE_WIKI_USER_EDIT_PAGES_AVG
const KEY_FIGURE_WIKI_PAGE_READ
static getWikiFootnotesAvg($a_wiki_id, $a_day_from, $a_day_to)
const KEY_FIGURE_WIKI_FOOTNOTES_AVG
static getWikiPageWords($a_wiki_id, $a_page_id, $a_day_from, $a_day_to)
global $DIC
Definition: saml.php:7
static getWikiEditPagesAvg($a_wiki_id, $a_day_from, $a_day_to)
const KEY_FIGURE_WIKI_NEW_PAGES_AVG
const KEY_FIGURE_WIKI_PAGE_INTERNAL_LINKS
static getWikiExternalLinksAvg($a_wiki_id, $a_day_from, $a_day_to)
const KEY_FIGURE_WIKI_INTERNAL_LINKS
static getWikiCharacters($a_wiki_id, $a_day_from, $a_day_to)
const KEY_FIGURE_WIKI_NUM_RATING_AVG
const KEY_FIGURE_WIKI_NUM_PAGES
static writeStatPageUser($a_wiki_id, $a_page_id, $a_user_id, $a_values)
Write data to wiki_stat_page_user.
static buildFullPeriodData(array &$a_res, $a_day_from, $a_day_to, $a_last_before_period, $a_allow_zero=false)
const KEY_FIGURE_WIKI_PAGE_CHARS
const KEY_FIGURE_WIKI_PAGE_EXTERNAL_LINKS
static getWikiPageRead($a_wiki_id, $a_page_id, $a_day_from, $a_day_to)
static getWikiLast($a_wiki_id, $a_day_from, $a_table, $a_field, $a_sub_field=null, $a_sub_id=null)
static getFigureData($a_wiki_id, $a_figure, $a_from, $a_to)
static getWikiPageRatings($a_wiki_id, $a_page_id, $a_day_from, $a_day_to)
const KEY_FIGURE_WIKI_EXTERNAL_LINKS_AVG
static getWikiUserEditPagesAvg($a_wiki_id, $a_day_from, $a_day_to)
static getWikiAggr($a_wiki_id, $a_day_from, $a_day_to, $a_table, $a_field, $a_aggr_value, $a_sub_field=null, $a_sub_id=null, $a_build_full_period=false)
const KEY_FIGURE_WIKI_PAGE_FOOTNOTES
const EVENT_PAGE_READ
static getWikiDeletedPages($a_wiki_id, $a_day_from, $a_day_to)
static getWikiNewPagesAvg($a_wiki_id, $a_day_from, $a_day_to)
static getWikiRatingAvg($a_wiki_id, $a_day_from, $a_day_to)
static handlePageRead(ilWikiPage $a_page_obj, $a_user_id)
Handle wiki page read.
static getWikiPageFootnotes($a_wiki_id, $a_page_id, $a_day_from, $a_day_to)
static getWikiPageUserEdit($a_wiki_id, $a_page_id, $a_day_from, $a_day_to)
static getWikiExternalLinks($a_wiki_id, $a_day_from, $a_day_to)
const KEY_FIGURE_WIKI_EXTERNAL_LINKS
numRows($query_result)
static handlePageRating(ilWikiPage $a_page_obj, $a_user_id)
Handle wiki page rating.
static getWikiEditPagesSum($a_wiki_id, $a_day_from, $a_day_to)
static getTimestamp()
Get current time frame (hourly)
static getAverageRating($a_wiki_id, $a_page_id=null)
Get average rating for wiki or wiki page.
quote($value, $type)
static getWikiNumRating($a_wiki_id, $a_day_from, $a_day_to)
static getWikiNewPagesSum($a_wiki_id, $a_day_from, $a_day_to)
static getWikiNumRatingAvg($a_wiki_id, $a_day_from, $a_day_to)
foreach($_POST as $key=> $value) $res
static getWikiPageExternalLinks($a_wiki_id, $a_page_id, $a_day_from, $a_day_to)
$lng
static countPages($a_wiki_id)
Count pages in wiki.
$values
static getFiguresPage()
static getFigureDataPage($a_wiki_id, $a_page_id, $a_figure, $a_from, $a_to)
static getFigureOptions()
static writeData($a_table, array $a_primary, array $a_values)
Write data to DB.
static handlePageCreated(ilWikiPage $a_page_obj, $a_user_id)
Handle wiki page creation.
const KEY_FIGURE_WIKI_INTERNAL_LINKS_AVG
$ilUser
Definition: imgupload.php:18
const EVENT_PAGE_RATING
const EVENT_PAGE_CREATED
Class ilWikiPage.
static getOverallRatingForObject($a_obj_id, $a_obj_type, $a_sub_obj_id=null, $a_sub_obj_type=null, $a_category_id=null)
Get overall rating for an object.
const KEY_FIGURE_WIKI_RATING_AVG
const KEY_FIGURE_WIKI_EDIT_PAGES_AVG
Wiki statistics class.
static handleEvent($a_event, ilWikiPage $a_page_obj, $a_user_id=null, array $a_additional_data=null)
Handle wiki page event.
static getWikiPageChangesAvg($a_wiki_id, $a_page_id, $a_day_from, $a_day_to)
const KEY_FIGURE_WIKI_CHARS
static getAllWikiPages($a_wiki_id)
Get all pages of wiki.
static writeStatUser($a_wiki_id, $a_user_id, $a_values)
Write to wiki_stat_user.
static getWikiPageInternalLinks($a_wiki_id, $a_page_id, $a_day_from, $a_day_to)
$row
exit
Definition: backend.php:16
static getWikiNumPages($a_wiki_id, $a_day_from, $a_day_to)
static getFigureTitle($a_figure)
static getWikiReadPages($a_wiki_id, $a_day_from, $a_day_to)
static handlePageDeletion(ilWikiPage $a_page_obj, $a_user_id)
Handle wiki page deletion.
const KEY_FIGURE_WIKI_NEW_PAGES
static handlePageUpdated(ilWikiPage $a_page_obj, $a_user_id, array $a_page_data=null)
Handle wiki page update.
global $ilDB
query($query)
Run a (read-only) Query on the database.
const KEY_FIGURE_WIKI_EDIT_PAGES
const KEY_FIGURE_WIKI_CHARS_AVG
static getWikiInternalLinks($a_wiki_id, $a_day_from, $a_day_to)
const KEY_FIGURE_WIKI_PAGE_WORDS
static writeStatPage($a_wiki_id, $a_page_id, $a_values)
Write data to wiki_stat_page.
static getFigureOptionsPage()
static getWikiCharactersAvg($a_wiki_id, $a_day_from, $a_day_to)
static getWikiUserEditPages($a_wiki_id, $a_day_from, $a_day_to, $a_sub_field=null, $a_sub_id=null)
if(! $in) $columns
Definition: Utf8Test.php:45
static getWikiWordsAvg($a_wiki_id, $a_day_from, $a_day_to)
const KEY_FIGURE_WIKI_READ_PAGES
const KEY_FIGURE_WIKI_WORDS_AVG
manipulate($query)
Run a (write) Query on the database.
static getWikiPageCharacters($a_wiki_id, $a_page_id, $a_day_from, $a_day_to)
static getAvailableMonths($a_wiki_id)
static getWikiFootnotes($a_wiki_id, $a_day_from, $a_day_to)
const KEY_FIGURE_WIKI_DELETED_PAGES
const KEY_FIGURE_WIKI_PAGE_CHANGES
static getWikiAggrSub($a_wiki_id, $a_day_from, $a_day_to, $a_table, $a_field, $a_aggr_by, $a_aggr_value, $a_aggr_sub, $a_sub_field=null, $a_sub_id=null, $a_build_full_period=false)
const KEY_FIGURE_WIKI_PAGE_CHANGES_AVG
const EVENT_PAGE_DELETED
$data
Definition: bench.php:6
const EVENT_PAGE_UPDATED