WIP - Improve gradebook list see BT#13099

pull/2487/head
jmontoyaa 8 years ago
parent 07b0dc8dcd
commit f2d2c569ad
  1. 116
      main/admin/gradebook_dependency.php
  2. 32
      main/gradebook/lib/be/category.class.php
  3. 24
      main/template/default/admin/gradebook_dependency.tpl

@ -54,13 +54,23 @@ if (empty($dependencies)) {
$content = '';
$courseList = [];
/*$mandatoryList = api_get_configuration_value('gradebook_dependency_mandatory_courses');
$mandatoryList = isset($mandatoryList['courses']) ? $mandatoryList['courses'] : [];*/
$userResult = [];
$mandatoryList = api_get_configuration_value('gradebook_dependency_mandatory_courses');
$mandatoryList = isset($mandatoryList['courses']) ? $mandatoryList['courses'] : [];
$mandatoryListCompleteList = [];
foreach ($mandatoryList as $courseMandatoryId) {
$mandatoryListCompleteList[] = api_get_course_info_by_id($courseMandatoryId);
}
$totalDependencies = count($dependencies);
$min = $categoryObj->getMinimumToValidate();
$userResult = [];
$dependencyList = [];
foreach ($dependencies as $courseId) {
$courseInfo = api_get_course_info_by_id($courseId);
$dependencyList[$courseId] = api_get_course_info_by_id($courseId);
}
$courseUserLoaded = [];
foreach ($dependencyList as $courseId => $courseInfo) {
$courseCode = $courseInfo['code'];
$subCategory = Category::load(null, null, $courseCode);
/** @var Category $subCategory */
@ -68,30 +78,109 @@ foreach ($dependencies as $courseId) {
if (empty($subCategory)) {
continue;
}
$userList = CourseManager::get_student_list_from_course_code($courseCode);
$users = [];
foreach ($userList as $user) {
$userId = $user['user_id'];
if ($userId != 37056) {
//continue;
}
$userInfo = api_get_user_info($userId);
$courseId = $courseInfo['real_id'];
$userCourseList = CourseManager::get_courses_list_by_user_id($userId);
$userCourseListCode = array_column($userCourseList, 'code');
if (!isset($userResult[$userId]['result_mandatory_20'])) {
$userResult[$userId]['result_mandatory_20'] = 0;
}
if (!isset($userResult[$userId]['result_not_mandatory_80'])) {
$userResult[$userId]['result_not_mandatory_80'] = 0;
}
foreach ($userCourseList as $courseItem) {
$myCourseCode = $courseItem['code'];
$myCourseId = $courseItem['real_id'];
if (in_array($myCourseId, $dependencies)) {
continue;
}
if (isset($courseUserLoaded[$userId][$myCourseId])) {
continue;
} else {
$courseUserLoaded[$userId][$myCourseId] = true;
}
//var_dump($myCourseCode);
$courseCategory = Category::load(
null,
null,
$myCourseCode
);
$courseCategory = isset($courseCategory[0]) ? $courseCategory[0] : [];
$userResult[$userId]['result_out_dependencies'][$myCourseCode] = false;
if (!empty($courseCategory)) {
$result = Category::userFinishedCourse(
$userId,
$courseCategory,
true
);
$userResult[$userId]['result_out_dependencies'][$myCourseCode] = $result;
if (in_array($myCourseId, $mandatoryList)) {
if ($userResult[$userId]['result_mandatory_20'] < 20 && $result) {
$userResult[$userId]['result_mandatory_20'] += 10;
}
} else {
if ($userResult[$userId]['result_not_mandatory_80'] < 80 && $result) {
$userResult[$userId]['result_not_mandatory_80'] += 10;
// var_dump($userResult[$userId]['result_80'] );
}
}
}
}
$result = Category::userFinishedCourse(
$userId,
$subCategory,
true
);
$userInfo['result'] = $result;
//$users[] = $userInfo;
$userResult[$userId]['result'][$courseCode] = $result;
$userResult[$userId]['result_dependencies'][$courseCode] = $result;
$userResult[$userId]['user_info'] = $userInfo;
}
foreach ($userResult as $userId => &$userData) {
$userData['final_result'] = count(array_filter($userData['result'])) == $totalDependencies;
//var_dump("$courseCode : $result");
if (in_array($courseId, $mandatoryList)) {
if ($userResult[$userId]['result_mandatory_20'] < 20 && $result) {
$userResult[$userId]['result_mandatory_20'] += 10;
}
} else {
if ($userResult[$userId]['result_not_mandatory_80'] < 80 && $result) {
$userResult[$userId]['result_not_mandatory_80'] += 10;
//var_dump($userResult[$userId]['result_80'] );
}
}
}
//$courseInfo['users'] = $users;
//$courseInfo['is_mandatory'] = in_array($courseCode, $mandatoryList);
$courseList[] = $courseInfo;
}
foreach ($userResult as $userId => &$userData) {
$courseListPassed = count(array_filter($userData['result_out_dependencies']));
$total =
count(array_filter($userData['result_dependencies'])) +
$courseListPassed
;
$userData['course_list_passed'] = $courseListPassed;
$userData['course_list'] = count($userData['result_out_dependencies']);
$userData['final_result'] = $total >= $min;
}
$tpl->assign('current_url', $currentUrl);
$tpl->assign(
'actions',
@ -102,6 +191,9 @@ $tpl->assign(
)
);
$tpl->assign('mandatory_courses', $mandatoryListCompleteList);
$tpl->assign('min_to_validate', $min);
$tpl->assign('gradebook_category', $category);
$tpl->assign('courses', $courseList);
$tpl->assign('users', $userResult);

@ -1880,19 +1880,17 @@ class Category implements GradebookItem
$sessionId = 0
) {
$evals = array();
if (empty($course_code)) {
$course_code = api_get_course_id();
}
if (empty($sessionId)) {
$sessionId = api_get_session_id();
}
$course_code = empty($course_code) ? $this->get_course_code() : $course_code;
$sessionId = empty($sessionId) ? $this->get_session_id() : $sessionId;
// 1 student
if (isset($studentId) && !empty($studentId)) {
// Special case: this is the root
if ($this->id == 0) {
$evals = Evaluation::get_evaluations_with_result_for_student(0, $studentId);
$evals = Evaluation::get_evaluations_with_result_for_student(
0,
$studentId
);
} else {
$evals = Evaluation::load(
null,
@ -1917,7 +1915,9 @@ class Category implements GradebookItem
$this->id,
null
);
} elseif (isset($this->course_code) && !empty($this->course_code)) {
} elseif (isset($this->course_code) &&
!empty($this->course_code)
) {
// inside a course
$evals = Evaluation::load(
null,
@ -1986,13 +1986,8 @@ class Category implements GradebookItem
) {
$links = array();
if (empty($course_code)) {
$course_code = api_get_course_id();
}
if (empty($sessionId)) {
$sessionId = api_get_session_id();
}
$course_code = empty($course_code) ? $this->get_course_code() : $course_code;
$sessionId = empty($sessionId) ? $this->get_session_id() : $sessionId;
// no links in root or course independent categories
if ($this->id == 0) {
@ -2502,7 +2497,9 @@ class Category implements GradebookItem
if (empty($category)) {
return 0;
}
$courseEvaluations = $category->get_evaluations($userId, true);
$courseEvaluations = $category->get_evaluations(
$userId, true
);
$courseLinks = $category->get_links($userId, true);
$evaluationsAndLinks = array_merge($courseEvaluations, $courseLinks);
$categoryScore = 0;
@ -2556,4 +2553,5 @@ class Category implements GradebookItem
{
$this->studentList = $list;
}
}

@ -7,6 +7,14 @@
({{ gradebook_category.courseCode }})
{% endif %}
</h3>
{{ 'MinimumGradebookToValidate' | get_lang }} : {{ min_to_validate }}
<br />
{{ 'MandatoryCourses' | get_lang }}
{% for course in mandatory_courses %}
<th>
{{ course.title }} ({{ course.code }})
</th>
{% endfor %}
<hr>
<table class="table">
<thead class="title">
@ -17,6 +25,9 @@
{{ course.title }} ({{ course.code }})
</th>
{% endfor %}
<th>{{ 'RestCoursesSubscribed' | get_lang }}</th>
<th>{{ 'Progress' | get_lang }} Max 20 (Mandatory courses)</th>
<th>{{ 'Progress' | get_lang }} Max 80 (Rest of courses)</th>
<th>{{ 'Total' | get_lang }}</th>
</tr>
</thead>
@ -26,12 +37,23 @@
{% for course in courses %}
<td>
{% if user.result[course.code] %}
{% if user.result_dependencies[course.code] %}
<img src="{{ 'check-circle.png'|icon(22) }}" />
{% endif %}
</td>
{% endfor %}
<td>
{{ user.course_list_passed }} / {{ user.course_list }}
</td>
<td>
{{ user.result_mandatory_20 }}
</td>
<td>
{{ user.result_not_mandatory_80 }}
</td>
<td>
{% if user.final_result %}
<img src="{{ 'check-circle.png'|icon(22) }}" />

Loading…
Cancel
Save