gradebook_dependency.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Entity\GradebookCategory;
  4. require_once __DIR__.'/../inc/global.inc.php';
  5. api_protect_admin_script();
  6. $allow = api_get_configuration_value('gradebook_dependency');
  7. if ($allow == false) {
  8. api_not_allowed(true);
  9. }
  10. $categoryId = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 1;
  11. $em = Database::getManager();
  12. $repo = $em->getRepository('ChamiloCoreBundle:GradebookCategory');
  13. /** @var GradebookCategory $category */
  14. $category = $repo->find($categoryId);
  15. if (!$category) {
  16. api_not_allowed(true);
  17. }
  18. $categoryObj = Category::load($categoryId);
  19. /** @var Category $categoryObj */
  20. $categoryObj = $categoryObj[0];
  21. $dependencies = $categoryObj->getCourseListDependency();
  22. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
  23. $currentUrl = api_get_self().'?';
  24. $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
  25. $interbreadcrumb[] = [
  26. 'url' => api_get_path(WEB_CODE_PATH).'admin/gradebook_list.php',
  27. 'name' => get_lang('Assessments'),
  28. ];
  29. $tpl = new Template(get_lang('Course list'));
  30. $toolbar = Display::url(
  31. Display::return_icon('back.png', get_lang('Add'), [], ICON_SIZE_MEDIUM),
  32. api_get_path(WEB_CODE_PATH).'admin/gradebook_list.php'
  33. );
  34. if (empty($dependencies)) {
  35. Display::addFlash(
  36. Display::return_message(get_lang('ThisAssessmentsDoesntHaveDependencies'))
  37. );
  38. }
  39. $content = '';
  40. $courseList = [];
  41. $mandatoryList = api_get_configuration_value('gradebook_dependency_mandatory_courses');
  42. $mandatoryList = isset($mandatoryList['courses']) ? $mandatoryList['courses'] : [];
  43. $mandatoryListCompleteList = [];
  44. foreach ($mandatoryList as $courseMandatoryId) {
  45. $mandatoryListCompleteList[] = api_get_course_info_by_id($courseMandatoryId);
  46. }
  47. $totalDependencies = count($dependencies);
  48. $min = $categoryObj->getMinimumToValidate();
  49. $gradeBooksToValidateInDependence = $categoryObj->getGradeBooksToValidateInDependence();
  50. $userResult = [];
  51. $dependencyList = [];
  52. foreach ($dependencies as $courseId) {
  53. $dependencyList[$courseId] = api_get_course_info_by_id($courseId);
  54. }
  55. $courseUserLoaded = [];
  56. foreach ($dependencyList as $courseId => $courseInfo) {
  57. $courseCode = $courseInfo['code'];
  58. $subCategory = Category::load(null, null, $courseCode);
  59. /** @var Category $subCategory */
  60. $subCategory = $subCategory ? $subCategory[0] : [];
  61. if (empty($subCategory)) {
  62. continue;
  63. }
  64. $userList = CourseManager::get_student_list_from_course_code($courseCode);
  65. foreach ($userList as $user) {
  66. $userId = $user['user_id'];
  67. $userInfo = api_get_user_info($userId);
  68. $courseId = $courseInfo['real_id'];
  69. $userCourseList = CourseManager::get_courses_list_by_user_id(
  70. $userId,
  71. false,
  72. false,
  73. true,
  74. [],
  75. false
  76. );
  77. $userCourseListCode = array_column($userCourseList, 'code');
  78. if (!isset($userResult[$userId]['result_mandatory_20'])) {
  79. $userResult[$userId]['result_mandatory_20'] = 0;
  80. }
  81. if (!isset($userResult[$userId]['result_not_mandatory_80'])) {
  82. $userResult[$userId]['result_not_mandatory_80'] = 0;
  83. }
  84. foreach ($userCourseList as $courseItem) {
  85. $myCourseCode = $courseItem['code'];
  86. $myCourseId = $courseItem['real_id'];
  87. if (in_array($myCourseId, $dependencies)) {
  88. continue;
  89. }
  90. if (isset($courseUserLoaded[$userId][$myCourseId])) {
  91. continue;
  92. } else {
  93. $courseUserLoaded[$userId][$myCourseId] = true;
  94. }
  95. $courseCategory = Category::load(
  96. null,
  97. null,
  98. $myCourseCode
  99. );
  100. $courseCategory = isset($courseCategory[0]) ? $courseCategory[0] : [];
  101. $userResult[$userId]['result_out_dependencies'][$myCourseCode] = false;
  102. if (!empty($courseCategory)) {
  103. $result = Category::userFinishedCourse(
  104. $userId,
  105. $courseCategory,
  106. true
  107. );
  108. $userResult[$userId]['result_out_dependencies'][$myCourseCode] = $result;
  109. if (in_array($myCourseId, $mandatoryList)) {
  110. if ($userResult[$userId]['result_mandatory_20'] < 20 && $result) {
  111. $userResult[$userId]['result_mandatory_20'] += 10;
  112. }
  113. } else {
  114. if ($userResult[$userId]['result_not_mandatory_80'] < 80 && $result) {
  115. $userResult[$userId]['result_not_mandatory_80'] += 10;
  116. // var_dump($userResult[$userId]['result_80'] );
  117. }
  118. }
  119. }
  120. }
  121. $result = Category::userFinishedCourse(
  122. $userId,
  123. $subCategory,
  124. true
  125. );
  126. $userResult[$userId]['result_dependencies'][$courseCode] = $result;
  127. $userResult[$userId]['user_info'] = $userInfo;
  128. if (in_array($courseId, $mandatoryList)) {
  129. if ($userResult[$userId]['result_mandatory_20'] < 20 && $result) {
  130. $userResult[$userId]['result_mandatory_20'] += 10;
  131. }
  132. } else {
  133. if ($userResult[$userId]['result_not_mandatory_80'] < 80 && $result) {
  134. $userResult[$userId]['result_not_mandatory_80'] += 10;
  135. }
  136. }
  137. }
  138. $courseList[] = $courseInfo;
  139. }
  140. foreach ($userResult as $userId => &$userData) {
  141. $courseListPassedOutDependency = count(array_filter($userData['result_out_dependencies']));
  142. $courseListPassedDependency = count(array_filter($userData['result_dependencies']));
  143. $total = $courseListPassedDependency + $courseListPassedOutDependency;
  144. $userData['course_list_passed_out_dependency'] = $courseListPassedOutDependency;
  145. $userData['course_list_passed_out_dependency_count'] = count($userData['result_out_dependencies']);
  146. // Min req must apply + mandatory should be 20
  147. //$userData['final_result'] = $total >= $min && $userData['result_mandatory_20'] == 20;
  148. //$userData['final_result'] = $total >= $min && $courseListPassedDependency == $totalDependencies;
  149. $userData['final_result'] = $total >= $min && $courseListPassedDependency >= $gradeBooksToValidateInDependence;
  150. }
  151. $tpl->assign('current_url', $currentUrl);
  152. $tpl->assign(
  153. 'actions',
  154. Display::toolbarAction(
  155. 'toolbar',
  156. [$toolbar],
  157. [1, 4]
  158. )
  159. );
  160. $tpl->assign('mandatory_courses', $mandatoryListCompleteList);
  161. $tpl->assign('min_to_validate', $min);
  162. $tpl->assign('gradebook_category', $category);
  163. $tpl->assign('courses', $courseList);
  164. $tpl->assign('users', $userResult);
  165. $layout = $tpl->get_template('admin/gradebook_dependency.tpl');
  166. $tpl->display($layout);