document_quota.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Document quota management script.
  5. *
  6. * @package chamilo.document
  7. */
  8. use Chamilo\CoreBundle\Framework\Container;
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. api_protect_course_script(true);
  11. if (!api_is_allowed_to_edit(null, true)) {
  12. api_not_allowed(true);
  13. }
  14. $current_course_tool = TOOL_DOCUMENT;
  15. $this_section = SECTION_COURSES;
  16. $tool_name = get_lang('Space Available');
  17. $interbreadcrumb[] = ['url' => 'document.php', 'name' => get_lang('Documents')];
  18. $htmlHeadXtra[] = api_get_js('jqplot/jquery.jqplot.js');
  19. $htmlHeadXtra[] = api_get_js('jqplot/plugins/jqplot.pieRenderer.js');
  20. $htmlHeadXtra[] = api_get_js('jqplot/plugins/jqplot.donutRenderer.js');
  21. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/jqplot/jquery.jqplot.css');
  22. $courseId = api_get_course_int_id();
  23. $sessionId = api_get_session_id();
  24. $groupId = api_get_group_id();
  25. $userId = api_get_user_id();
  26. $userInfo = api_get_user_info($userId);
  27. $session = [];
  28. $user_name = $userInfo['complete_name'];
  29. $course_list = SessionManager::get_course_list_by_session_id($sessionId);
  30. $session_list = SessionManager::get_session_by_course($courseId);
  31. $total_quota_bytes = DocumentManager::get_course_quota();
  32. $repo = Container::getDocumentRepository();
  33. $quota_bytes = $repo->getTotalSpace($courseId);
  34. $quotaPercentage = round($quota_bytes / $total_quota_bytes, 2) * 100;
  35. $session[] = [get_lang('Course').' ('.format_file_size($quota_bytes).')', $quotaPercentage];
  36. $used_quota_bytes = $quota_bytes;
  37. if (!empty($session_list)) {
  38. foreach ($session_list as $session_data) {
  39. $quotaPercentage = 0;
  40. $quota_bytes = $repo->getTotalSpace($courseId, null, $session_data['id']);
  41. if (!empty($quota_bytes)) {
  42. $quotaPercentage = round($quota_bytes / $total_quota_bytes, 2) * 100;
  43. }
  44. if ($sessionId == $session_data['id']) {
  45. $session_data['name'] = $session_data['name'].' * ';
  46. }
  47. $used_quota_bytes += $quota_bytes;
  48. $session[] = [
  49. addslashes(get_lang('Session').': '.$session_data['name']).' ('.format_file_size($quota_bytes).')',
  50. $quotaPercentage,
  51. ];
  52. }
  53. }
  54. $group_list = GroupManager::get_groups();
  55. if (!empty($group_list)) {
  56. $repo = Container::getDocumentRepository();
  57. foreach ($group_list as $group_data) {
  58. $quotaPercentage = 0;
  59. $my_group_id = $group_data['id'];
  60. $quota_bytes = $repo->getTotalSpace($courseId, $my_group_id, 0);
  61. if (!empty($quota_bytes)) {
  62. $quotaPercentage = round($quota_bytes / $total_quota_bytes, 2) * 100;
  63. }
  64. if ($groupId == $my_group_id) {
  65. $group_data['name'] = $group_data['name'].' * ';
  66. }
  67. $used_quota_bytes += $quota_bytes;
  68. $session[] = [
  69. addslashes(get_lang('Group').': '.$group_data['name']).' ('.format_file_size($quota_bytes).')',
  70. $quotaPercentage,
  71. ];
  72. }
  73. }
  74. // Showing weight of documents uploaded by user
  75. $document_list = DocumentManager::getAllDocumentData(api_get_course_info());
  76. if (!empty($document_list)) {
  77. foreach ($document_list as $document_data) {
  78. if ($document_data['creator_id'] == api_get_user_id() && $document_data['filetype'] === 'file') {
  79. $quota_bytes += $document_data['size'];
  80. }
  81. }
  82. if ($quota_bytes != 0) {
  83. $quotaPercentage = round($quota_bytes / $total_quota_bytes, 2) * 100;
  84. }
  85. $session[] = [
  86. addslashes(get_lang('Trainer').': '.$user_name).' ('.format_file_size($quota_bytes).')',
  87. $quotaPercentage,
  88. ];
  89. //if a sesson is active
  90. if ($sessionId != 0) {
  91. if (!empty($course_list)) {
  92. $total_courses_quota = 0;
  93. $total_quota_bytes = 0;
  94. if (is_array($course_list) && !empty($course_list)) {
  95. foreach ($course_list as $course_data) {
  96. $total_quota_bytes += DocumentManager::get_course_quota($course_data['id']);
  97. }
  98. }
  99. if ($quota_bytes != 0) {
  100. $quotaPercentage = round($quota_bytes / $total_quota_bytes, 2) * 100;
  101. }
  102. }
  103. $session[] = [addslashes(sprintf(get_lang('TrainerXInSession'), $user_name)), $quotaPercentage];
  104. }
  105. }
  106. $quotaPercentage = round(($total_quota_bytes - $used_quota_bytes) / $total_quota_bytes, 2) * 100;
  107. $session[] = [
  108. addslashes(get_lang('Space Available')).' ('.format_file_size(
  109. $total_quota_bytes - $used_quota_bytes
  110. ).') ',
  111. $quotaPercentage,
  112. ];
  113. $quota_data = json_encode($session);
  114. $htmlHeadXtra[] = "<script>
  115. $(function() {
  116. var data = ".$quota_data.";
  117. var plot1 = jQuery.jqplot('chart1', [data], {
  118. seriesDefaults: {
  119. // Make this a pie chart
  120. renderer: jQuery.jqplot.PieRenderer,
  121. rendererOptions: {
  122. // Put data labels on the pie slices.
  123. // By default, labels show the percentage of the slice.
  124. showDataLabels: true
  125. }
  126. },
  127. legend: { show:true, location: 'e' }
  128. });
  129. });
  130. </script>";
  131. $tpl = new Template($tool_name);
  132. $content = Display::page_subheader(get_lang('Space Available')).'<div id="chart1"></div>';
  133. $tpl->assign('content', $content);
  134. $tpl->display_one_col_template();