You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.3 KiB

  1. <?php
  2. /**
  3. * @package Widgets
  4. *
  5. * @file Statistics.php
  6. * This file is part of MOVIM.
  7. *
  8. * @brief The administration widget.
  9. *
  10. * @author Timothée Jaussoin <edhelas@gmail.com>
  11. * *
  12. * Copyright (C)2014 MOVIM project
  13. *
  14. * See COPYING for licensing information.
  15. */
  16. use Modl\SessionxDAO;
  17. class Statistics extends WidgetBase
  18. {
  19. function load()
  20. {
  21. }
  22. function display()
  23. {
  24. $sd = new SessionxDAO;
  25. $this->view->assign('sessions', $sd->getAll());
  26. $cd = new \Modl\ConfigDAO();
  27. $config = $cd->get();
  28. $this->view->assign('hash', $config->password);
  29. $tmp = array();
  30. foreach(scandir(USERS_PATH) as $f) {
  31. if(is_dir(USERS_PATH.'/'.$f)) {
  32. $time = filemtime(USERS_PATH.'/'.$f.'/index.html');
  33. if($time) {
  34. array_push($tmp, $time);
  35. }
  36. }
  37. }
  38. sort($tmp);
  39. $days = array();
  40. $pattern = "Y-m";
  41. foreach($tmp as $k => $time) {
  42. $key = date($pattern, $time);
  43. if(isset($days[$key])) {
  44. $days[$key]++;
  45. } else {
  46. $days[$key] = 1;
  47. }
  48. }
  49. $this->renderTimeLineChart($days, $this->__('statistics.monthly_sub'), "monthly.png");
  50. $sum = 0;
  51. foreach($days as $key => $value) {
  52. $sum = $sum + $value;
  53. $days[$key] = $sum;
  54. }
  55. $this->renderTimeLineChart($days, $this->__('statistics.monthly_sub_cum'), "monthly_cumulated.png");
  56. }
  57. private function renderTimeLineChart($data, $title, $filename)
  58. {
  59. $chart = new Libchart\View\Chart\LineChart(750, 450);
  60. $dataSet = new Libchart\Model\XYDataSet();
  61. foreach($data as $key => $value) {
  62. $dataSet->addPoint(new Libchart\Model\Point($key, $value));
  63. }
  64. $chart->setDataSet($dataSet);
  65. $chart->setTitle($title);
  66. $chart->render(CACHE_PATH.$filename);
  67. $this->view->assign('cache_path', BASE_URI.'cache/');
  68. }
  69. public function ajaxGetSessions($hashs)
  70. {
  71. $sd = new SessionxDAO;
  72. $sessions = $sd->getAll();
  73. }
  74. function getTime($date)
  75. {
  76. return prepareDate(strtotime($date));
  77. }
  78. }