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