periodic_export.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. exit;
  4. $cidReset = true;
  5. require_once __DIR__.'/../inc/global.inc.php';
  6. api_protect_admin_script(true);
  7. api_set_more_memory_and_time_limits();
  8. $this_section = SECTION_PLATFORM_ADMIN;
  9. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('Administration')];
  10. $nameTools = get_lang('PeriodicExports');
  11. $export = '';
  12. Display::display_header($nameTools);
  13. echo Display::page_header($nameTools);
  14. $form = new FormValidator('special_exports', 'post');
  15. $form->addDateRangePicker('date', get_lang('Dates'));
  16. $form->addButtonSearch(get_lang('Search'));
  17. $form->display();
  18. if ($form->validate()) {
  19. $values = $form->getSubmitValues();
  20. $urlId = api_get_current_access_url_id();
  21. $startDate = $values['date_start'];
  22. $endDate = $values['date_end'];
  23. // Count active users in the platform
  24. $countUsers = UserManager::get_number_of_users(null, $urlId, 1);
  25. // Count user connected in those dates
  26. $connectedUsers = Statistics::getLoginCount($startDate, $endDate);
  27. $activeCourses = CourseManager::countActiveCourses($urlId);
  28. $totalCourses = CourseManager::count_courses($urlId);
  29. $total = Tracking::getTotalTimeSpentOnThePlatform();
  30. $now = api_get_utc_datetime();
  31. $beforeDateStart = new DateTime('-90 days', new DateTimeZone('UTC'));
  32. $end = $beforeDateStart->format('Y-m-d H:i:s');
  33. $thisTrimester = Tracking::getTotalTimeSpentOnThePlatform($end, $now);
  34. $beforeDateEnd = new DateTime('-180 days', new DateTimeZone('UTC'));
  35. $start = $beforeDateEnd->format('Y-m-d H:i:s');
  36. $lastTrimester = Tracking::getTotalTimeSpentOnThePlatform($start, $end);
  37. //var_dump($countUsers, $connectedUsers, $activeCourses, $totalCourses, $total, $thisTrimester, $lastTrimester);
  38. $courses = Statistics::getCoursesWithActivity($startDate, $endDate);
  39. $totalUsers = 0;
  40. $totalCertificates = 0;
  41. foreach ($courses as $courseId) {
  42. $courseInfo = api_get_course_info_by_id($courseId);
  43. $countUsers = CourseManager::get_user_list_from_course_code(
  44. $courseInfo['code'],
  45. 0,
  46. null,
  47. null,
  48. null,
  49. true
  50. );
  51. $totalUsers += $countUsers;
  52. $categories = Category::load(
  53. null,
  54. null,
  55. $courseInfo['code'],
  56. null,
  57. false,
  58. 0
  59. );
  60. $category = null;
  61. $certificateCount = 0;
  62. if (!empty($categories)) {
  63. $category = current($categories);
  64. // @todo use count
  65. $certificateCount = count(GradebookUtils::get_list_users_certificates($categoryId));
  66. $totalCertificates += $certificateCount;
  67. }
  68. }
  69. $totalUsersCourses = CourseManager::totalSubscribedUsersInCourses($urlId);
  70. }
  71. Display::display_footer();