Skip to content

Commit 37f7235

Browse files
committed
Add setting "gradebook_badge_sidebar" see BT#13099
- Generate a sidebar menu to show badges.
1 parent 9477626 commit 37f7235

File tree

3 files changed

+147
-21
lines changed

3 files changed

+147
-21
lines changed

main/install/configuration.dist.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,12 @@
596596
/*$_configuration['gradebook_dependency_mandatory_courses'] = [
597597
'courses' => [1, 2]
598598
];*/
599+
// Gradebook id list needed to build the gradebook sidebar see BT#13099
600+
/*
601+
$_configuration['gradebook_badge_sidebar'] = [
602+
'gradebooks' => [1, 2, 3]
603+
];*/
604+
599605
// Show language selector in main menu an update the language in the user's
600606
// profile.
601607
//$_configuration['show_language_selector_in_menu'] = false;

main/template/default/layout/layout_2_col.tpl

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
<!-- end block course -->
139139
{% endif %}
140140

141-
{% if grade_book_result_validate is defined %}
141+
{% if grade_book_sidebar %}
142142
<div class="panel-group" id="skill" role="tablist" aria-multiselectable="true">
143143
<div class="panel panel-default" id="gradebook_block">
144144
<div class="panel-heading" role="tab">
@@ -152,14 +152,17 @@
152152
<div class="panel-body">
153153
<ul class="list-group">
154154
<li class="list-group-item {{ item.class }}">
155-
<span class="item-icon">
156-
{{ 'Completed' | get_lang }} :
157-
{% if grade_book_result_completed == true %}
158-
{{ 'Yes' | get_lang }}
159-
{% else %}
160-
{{ 'No' | get_lang }}
161-
{% endif %}
162-
</span>
155+
{{ 'Progress' | get_lang }} : {{ grade_book_progress }} %
156+
<br />
157+
{% for badge in grade_book_badge_list %}
158+
{{ badge.name }} -
159+
{% if badge.finished %}
160+
Yes
161+
{% else %}
162+
No
163+
{% endif %}
164+
<br />
165+
{% endfor %}
163166
</li>
164167
</ul>
165168
</div>

user_portal.php

Lines changed: 129 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ function changeMyCoursesView(inView) {
297297
}
298298
}
299299

300-
// @todo improve calls of course info
300+
301+
// @todo improve calls of course info
301302
$subscribedCourses = !empty($courseAndSessions['courses']) ? $courseAndSessions['courses'] : [];
302303
$mainCategoryList = [];
303304
foreach ($subscribedCourses as $courseInfo) {
@@ -309,6 +310,77 @@ function changeMyCoursesView(inView) {
309310
$mainCategoryList[] = $category;
310311
}
311312
}
313+
314+
$result = [];
315+
$result20 = 0;
316+
$result80 = 0;
317+
/** @var Category $category */
318+
foreach ($mainCategoryList as $category) {
319+
$userFinished = Category::userFinishedCourse(
320+
$userId,
321+
$category,
322+
true
323+
);
324+
325+
if ($userFinished) {
326+
if (in_array($category->get_course_code(), $mandatoryCourse)) {
327+
if ($result20 < 20) {
328+
$result20 += 10;
329+
}
330+
} else {
331+
if ($result80 < 80) {
332+
$result80 += 10;
333+
}
334+
}
335+
}
336+
}
337+
338+
$finalResult = $result20 + $result80;
339+
340+
$gradeBookList = api_get_configuration_value('gradebook_badge_sidebar');
341+
$gradeBookList = isset($gradeBookList['gradebooks']) ? $gradeBookList['gradebooks'] : [];
342+
$badgeList = [];
343+
foreach ($gradeBookList as $id) {
344+
$categories = Category::load($id);
345+
/** @var Category $category */
346+
$category = !empty($categories[0]) ? $categories[0] : [];
347+
$badgeList[$id]['name'] = $category->get_name();
348+
$badgeList[$id]['finished'] = false;
349+
if (!empty($category)) {
350+
$userFinished = Category::userFinishedCourse(
351+
$userId,
352+
$category,
353+
true
354+
);
355+
if ($userFinished) {
356+
$badgeList[$id]['finished'] = true;
357+
}
358+
}
359+
}
360+
/*
361+
362+
$categoriesNoCourseList = Category::load(null, null, '');
363+
$courseList = api_get_configuration_value('gradebook_dependency_mandatory_courses');
364+
$courseList = isset($courseList['courses']) ? $courseList['courses'] : [];
365+
$mandatoryCourse = [];
366+
if (!empty($courseList)) {
367+
foreach ($courseList as $courseId) {
368+
$courseInfo = api_get_course_info_by_id($courseId);
369+
$mandatoryCourse[] = $courseInfo['code'];
370+
}
371+
}
372+
373+
// @todo improve calls of course info
374+
$subscribedCourses = !empty($courseAndSessions['courses']) ? $courseAndSessions['courses'] : [];
375+
$mainCategoryList = [];
376+
foreach ($subscribedCourses as $courseInfo) {
377+
$courseCode = $courseInfo['code'];
378+
$categories = Category::load(null, null, $courseCode);
379+
$category = !empty($categories[0]) ? $categories[0] : [];
380+
if (!empty($category)) {
381+
$mainCategoryList[] = $category;
382+
}
383+
}
312384
$total = [];
313385
foreach ($mainCategoryList as $category) {
314386
$parentScore = Category::getCurrentScore(
@@ -325,7 +397,6 @@ function changeMyCoursesView(inView) {
325397
$courseInfo = api_get_course_info_by_id($courseId);
326398
$courseCode = $courseInfo['code'];
327399
$categories = Category::load(null, null, $courseCode);
328-
/** @var Category $subCategory */
329400
$subCategory = !empty($categories[0]) ? $categories[0] : null;
330401
if (!empty($subCategory)) {
331402
$score = Category::getCurrentScore(
@@ -352,20 +423,61 @@ function changeMyCoursesView(inView) {
352423
];
353424
}
354425
426+
$countTotalGradeBookValidated = 0;
427+
foreach ($total as $courseCode => $data) {
428+
$totalScoreWithChildren = $data['total_score_with_children'];
429+
if ($totalScoreWithChildren == 100) {
430+
$countTotalGradeBookValidated++;
431+
}
432+
}
433+
434+
355435
$finalScore = 0;
356436
$customTotalPercentage = 0;
357437
$maxPercentage = 80;
358438
$maxCustomPercentageCounter = 0;
359439
$validatedCoursesPercentage = 0;
440+
$resultPerCategory = [];
360441
361-
$countValidated = 0;
362-
foreach ($total as $courseCode => $data) {
363-
$totalScoreWithChildren = $data['total_score_with_children'];
364-
if ($totalScoreWithChildren == 100) {
365-
$countValidated++;
442+
$mandatoryPercentage = 0;
443+
$nonMandatoryPercentage = 0;
444+
445+
foreach ($categoriesNoCourseList as $category) {
446+
$dependencies = $category->getCourseListDependency();
447+
$minValidated = $category->getMinimumToValidate();
448+
$resultPerCategory[$category->get_id()] = '';
449+
$subTotal = 0;
450+
if (!empty($dependencies)) {
451+
foreach ($dependencies as $courseId) {
452+
$courseInfo = api_get_course_info_by_id($courseId);
453+
$courseCode = $courseInfo['code'];
454+
if (in_array($courseCode, $mandatoryCourse)) {
455+
if ($mandatoryPercentage <= 20) {
456+
$mandatoryPercentage += 10;
457+
}
458+
} else {
459+
if ($nonMandatoryPercentage <= 80) {
460+
$nonMandatoryPercentage += 10;
461+
}
462+
}
463+
if (isset($total[$courseCode])) {
464+
$subTotal += $total[$courseCode]['total_score_with_children'];
465+
}
466+
}
467+
468+
if ($minValidated < $countTotalGradeBookValidated) {
469+
$subTotal = 0;
470+
}
471+
$resultPerCategory[$category->get_id()] = $subTotal;
366472
}
367-
}
368473
474+
$completed = false;
475+
if ($mandatoryPercentage == 20 && $nonMandatoryPercentage == 80) {
476+
$completed = true;
477+
}
478+
}*/
479+
480+
/*
369481
foreach ($total as $courseCode => $data) {
370482
$totalScoreWithChildren = $data['total_score_with_children'];
371483
if ($data['min_validated'] < $countValidated) {
@@ -393,14 +505,19 @@ function changeMyCoursesView(inView) {
393505
$completed = false;
394506
if ($validatedCoursesPercentage == 20 && $customTotalPercentage == 80) {
395507
$completed = true;
396-
}
508+
}*/
509+
510+
$controller->tpl->assign(
511+
'grade_book_sidebar',
512+
true
513+
);
397514

398515
$controller->tpl->assign(
399-
'grade_book_result_validate',
400-
$validatedCoursesPercentage
516+
'grade_book_progress',
517+
$finalResult
401518
);
402519

403-
$controller->tpl->assign('grade_book_result_completed', $completed);
520+
$controller->tpl->assign('grade_book_badge_list', $badgeList);
404521
/*if ($finalScore > 0) {
405522
$finalScore = (int) $finalScore / count($total);
406523
if ($finalScore == 100) {

0 commit comments

Comments
 (0)