Skip to content

Commit 4c08b6b

Browse files
committed
Add 'config gradebook_dependency_mandatory_courses' see BT#13099
- Minor - rename function shows_all_information_an_category to showAllCategoryInfo.
1 parent 44f4bf0 commit 4c08b6b

File tree

7 files changed

+205
-24
lines changed

7 files changed

+205
-24
lines changed

main/gradebook/gradebook_edit_all.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393

9494
$my_category = array();
9595
$cat = new Category();
96-
$my_category = $cat->shows_all_information_an_category($my_selectcat);
96+
$my_category = $cat->showAllCategoryInfo($my_selectcat);
9797

9898
$original_total = $my_category['weight'];
9999
$masked_total = $parent_cat[0]->get_weight();

main/gradebook/lib/be/category.class.php

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -815,15 +815,14 @@ public function show_message_resource_delete($course_id)
815815
/**
816816
* Shows all information of an category
817817
*/
818-
public function shows_all_information_an_category($categoryId = '')
818+
public function showAllCategoryInfo($categoryId = '')
819819
{
820820
if ($categoryId == '') {
821821
return null;
822822
} else {
823823
$table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
824-
$sql = 'SELECT name,description,user_id,course_code,parent_id,weight,visible,certif_min_score,session_id, generate_certificates, is_requirement
825-
FROM '.$table.' c
826-
WHERE c.id='.intval($categoryId);
824+
$sql = 'SELECT * FROM '.$table.'
825+
WHERE id = '.intval($categoryId);
827826
$result = Database::query($sql);
828827
$row = Database::fetch_array($result, 'ASSOC');
829828

@@ -2171,7 +2170,10 @@ public static function generateUserCertificate(
21712170
// Do not remove this the gradebook/lib/fe/gradebooktable.class.php
21722171
// file load this variable as a global
21732172
$scoredisplay = ScoreDisplay::instance();
2174-
$my_score_in_gradebook = $scoredisplay->display_score($scoretotal, SCORE_SIMPLE);
2173+
$my_score_in_gradebook = $scoredisplay->display_score(
2174+
$scoretotal,
2175+
SCORE_SIMPLE
2176+
);
21752177
$userFinishedCourse = self::userFinishedCourse(
21762178
$user_id,
21772179
$cats_course[0],
@@ -2185,7 +2187,10 @@ public static function generateUserCertificate(
21852187
return false;
21862188
}
21872189

2188-
$skillToolEnabled = Skill::hasAccessToUserSkill(api_get_user_id(), $user_id);
2190+
$skillToolEnabled = Skill::hasAccessToUserSkill(
2191+
api_get_user_id(),
2192+
$user_id
2193+
);
21892194
$userHasSkills = false;
21902195

21912196
if ($skillToolEnabled) {
@@ -2198,7 +2203,11 @@ public static function generateUserCertificate(
21982203
);
21992204

22002205
$objSkillRelUser = new SkillRelUser();
2201-
$userSkills = $objSkillRelUser->get_user_skills($user_id, $courseId, $sessionId);
2206+
$userSkills = $objSkillRelUser->get_user_skills(
2207+
$user_id,
2208+
$courseId,
2209+
$sessionId
2210+
);
22022211
$userHasSkills = !empty($userSkills);
22032212

22042213
if (!$category->getGenerateCertificates() && $userHasSkills) {
@@ -2380,7 +2389,7 @@ public static function deleteAllCertificates($catId)
23802389
* To check by the category ID
23812390
* @param string $courseCode Optional. The course code
23822391
* @param int $sessionId Optional. The session ID
2383-
* @param boolean $recalcutateScore Whether recalculate the score
2392+
* @param boolean $recalculateScore Whether recalculate the score
23842393
* @return boolean
23852394
*/
23862395
public static function userFinishedCourse(
@@ -2389,7 +2398,7 @@ public static function userFinishedCourse(
23892398
$categoryId = 0,
23902399
$courseCode = null,
23912400
$sessionId = 0,
2392-
$recalcutateScore = false
2401+
$recalculateScore = false
23932402
) {
23942403
if (is_null($category) && empty($categoryId)) {
23952404
return false;
@@ -2421,7 +2430,7 @@ public static function userFinishedCourse(
24212430
$category->get_id(),
24222431
$courseCode,
24232432
$sessionId,
2424-
$recalcutateScore
2433+
$recalculateScore
24252434
);
24262435

24272436
$minCertificateScore = $category->get_certificate_min_score();
@@ -2447,7 +2456,12 @@ public static function getCurrentScore(
24472456
$recalculate = false
24482457
) {
24492458
if ($recalculate) {
2450-
return self::calculateCurrentScore($userId, $categoryId, $courseCode, $sessionId);
2459+
return self::calculateCurrentScore(
2460+
$userId,
2461+
$categoryId,
2462+
$courseCode,
2463+
$sessionId
2464+
);
24512465
}
24522466

24532467
$resultData = Database::select(
@@ -2478,8 +2492,12 @@ public static function getCurrentScore(
24782492
* @param int $sessionId Optional. The session id
24792493
* @return float The score
24802494
*/
2481-
private static function calculateCurrentScore($userId, $categoryId, $courseCode, $sessionId)
2482-
{
2495+
private static function calculateCurrentScore(
2496+
$userId,
2497+
$categoryId,
2498+
$courseCode,
2499+
$sessionId
2500+
) {
24832501
$cats_course = self::load(
24842502
$categoryId,
24852503
null,

main/gradebook/lib/fe/displaygradebook.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ public static function header(
356356
Display::return_icon('new_folder.png', get_lang('AddGradebook'), array(), ICON_SIZE_MEDIUM).'</a></td>';
357357
}
358358
if ($selectcat != '0') {
359-
$my_category = $catobj->shows_all_information_an_category($catobj->get_id());
359+
$my_category = $catobj->showAllCategoryInfo($catobj->get_id());
360360
if ($my_api_cidreq == '') {
361361
$my_api_cidreq = 'cidReq='.$my_category['course_code'];
362362
}
@@ -400,6 +400,15 @@ public static function header(
400400
"gradebook_display_summary.php?$my_api_cidreq&selectcat=".$selectcat
401401
);
402402

403+
$allow = api_get_configuration_value('gradebook_custom_student_report');
404+
if ($allow) {
405+
$actionsLeft .= Display::url(
406+
get_lang('GenerateCustomReport'),
407+
api_get_path(WEB_AJAX_PATH)."gradebook.ajax.php?$my_api_cidreq&a=generate_custom_report",
408+
['class' => 'btn btn-default ajax']
409+
);
410+
}
411+
403412
// Right icons
404413
$actionsRight = '<a href="gradebook_edit_cat.php?editcat='.$catobj->get_id().'&amp;cidReq='.$catobj->get_course_code().'&id_session='.$catobj->get_session_id().'">'.
405414
Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_MEDIUM).'</a>';

main/inc/lib/userportal.lib.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,8 +1142,11 @@ private static function returnRightBlockItems(array $items)
11421142
* @param string $categoryCodeFilter
11431143
* @return string
11441144
*/
1145-
public function returnCoursesAndSessions($user_id, $showSessions = true, $categoryCodeFilter = '')
1146-
{
1145+
public function returnCoursesAndSessions(
1146+
$user_id,
1147+
$showSessions = true,
1148+
$categoryCodeFilter = ''
1149+
) {
11471150
$gameModeIsActive = api_get_setting('gamification_mode');
11481151
$listCourse = '';
11491152
$specialCourseList = '';
@@ -1172,6 +1175,7 @@ public function returnCoursesAndSessions($user_id, $showSessions = true, $catego
11721175
$studentInfoProgress = (!empty($studentInfo['progress']) && $studentInfo['progress'] === true);
11731176
$studentInfoScore = (!empty($studentInfo['score']) && $studentInfo['score'] === true);
11741177
$studentInfoCertificate = (!empty($studentInfo['certificate']) && $studentInfo['certificate'] === true);
1178+
$courseCompleteList = [];
11751179

11761180
// If we're not in the history view...
11771181
if (!isset($_GET['history'])) {
@@ -1319,17 +1323,15 @@ public function returnCoursesAndSessions($user_id, $showSessions = true, $catego
13191323
$courses['not_category'][$key]['student_info']['certificate'] = null;
13201324

13211325
if (isset($category[0])) {
1326+
$certificateAvailable = $category[0]->is_certificate_available($user_id);
13221327
if ($viewGrid == 'true') {
1323-
if ($category[0]->is_certificate_available($user_id)) {
1328+
if ($certificateAvailable) {
13241329
$courses['not_category'][$key]['student_info']['certificate'] = get_lang('Yes');
13251330
} else {
13261331
$courses['not_category'][$key]['student_info']['certificate'] = get_lang('No');
13271332
}
13281333
} else {
1329-
if ($category[0]->is_certificate_available(
1330-
$user_id
1331-
)
1332-
) {
1334+
if ($certificateAvailable) {
13331335
$courses['not_category'][$key]['student_info']['certificate'] = Display::label(
13341336
get_lang('Yes'),
13351337
'success'
@@ -1389,6 +1391,7 @@ public function returnCoursesAndSessions($user_id, $showSessions = true, $catego
13891391
$listCourse .= $this->tpl->fetch(
13901392
$this->tpl->get_template($coursesWithoutCategoryTemplate)
13911393
);
1394+
$courseCompleteList = $courses['in_category'] + $courses['not_category'];
13921395
}
13931396

13941397
$courseCount = count($specialCourses) + count($courses['in_category']) + count($courses['not_category']);
@@ -1797,6 +1800,8 @@ public function returnCoursesAndSessions($user_id, $showSessions = true, $catego
17971800
}
17981801

17991802
return [
1803+
'courses' => $courseCompleteList,
1804+
'sessions' => $session_categories,
18001805
'html' => trim($specialCourseList.$sessions_with_category.$sessions_with_no_category.$listCourse),
18011806
'session_count' => $sessionCount,
18021807
'course_count' => $courseCount
@@ -2012,6 +2017,8 @@ public function returnCoursesAndSessionsViewBySession($user_id)
20122017

20132018
return [
20142019
'html' => $html,
2020+
'sessions' => $session_categories,
2021+
'courses' => $listCoursesInfo,
20152022
'session_count' => $sessionCount,
20162023
'course_count' => $courseCount
20172024
];
@@ -2251,10 +2258,9 @@ private static function getSimpleSessionDetails($coachName, $dates, $duration =
22512258
* @param $userId
22522259
* @return array
22532260
*/
2254-
public static function returnCourseCategoryListFromUser($userId)
2261+
public function returnCourseCategoryListFromUser($userId)
22552262
{
22562263
$sessionCount = 0;
2257-
22582264
$courseList = CourseManager::get_courses_list_by_user_id($userId);
22592265
$categoryCodes = CourseManager::getCourseCategoriesFromCourseList($courseList);
22602266
$categories = [];

main/install/configuration.dist.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,3 +583,7 @@
583583
// ALTER TABLE gradebook_category ADD COLUMN depends TEXT DEFAULT NULL;
584584
// ALTER TABLE gradebook_category ADD COLUMN minimum_to_validate INT DEFAULT NULL;
585585
// $_configuration['gradebook_dependency'] = false;
586+
// Courses id list to check in the gradebook sidebar see BT#13099
587+
$_configuration['gradebook_dependency_mandatory_courses'] = [
588+
'courses' => [1, 2]
589+
];

main/template/default/layout/layout_2_col.tpl

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

141+
{% if grade_book_result_validate is defined %}
142+
<div class="panel-group" id="skill" role="tablist" aria-multiselectable="true">
143+
<div class="panel panel-default" id="gradebook_block">
144+
<div class="panel-heading" role="tab">
145+
<h4 class="panel-title">
146+
<a role="button" data-toggle="collapse" data-parent="#skill" href="#skillCollapse" aria-expanded="true" aria-controls="skillCollapse">
147+
{{ 'Gradebook' | get_lang }}
148+
</a>
149+
</h4>
150+
</div>
151+
<div style="" aria-expanded="true" id="skillCollapse" class="panel-collapse collapse in" role="tabpanel">
152+
<div class="panel-body">
153+
<ul class="list-group">
154+
<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>
163+
</li>
164+
</ul>
165+
</div>
166+
</div>
167+
</div>
168+
</div>
169+
170+
{% endif %}
171+
141172
{% if skills_block %}
142173
<!-- block skills -->
143174
<div class="panel-group" id="skill" role="tablist" aria-multiselectable="true">

user_portal.php

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/* For licensing terms, see /license.txt */
33

44
use ChamiloSession as Session;
5+
use Doctrine\Common\Collections\Criteria;
56

67
/**
78
* This is the index file displayed when a user is logged in on Chamilo.
@@ -276,6 +277,118 @@ function changeMyCoursesView(inView) {
276277
if ($myCourseListAsCategory) {
277278
$controller->tpl->assign('header', get_lang('MyCourses'));
278279
}
280+
281+
$allow = api_get_configuration_value('gradebook_dependency');
282+
283+
if (!empty($courseAndSessions['courses']) && $allow) {
284+
$courseList = api_get_configuration_value('gradebook_dependency_mandatory_courses');
285+
$courseList = isset($courseList['courses']) ? $courseList['courses'] : [];
286+
$mandatoryCourse = [];
287+
if (!empty($courseList)) {
288+
foreach ($courseList as $courseId) {
289+
$courseInfo = api_get_course_info_by_id($courseId);
290+
$mandatoryCourse[] = $courseInfo['code'];
291+
}
292+
}
293+
294+
// @todo improve calls of course info
295+
$subscribedCourses = $courseAndSessions['courses'];
296+
$mainCategoryList = [];
297+
foreach ($subscribedCourses as $courseInfo) {
298+
$courseCode = $courseInfo['course_code'];
299+
$categories = Category::load(null, null, $courseCode);
300+
/** @var Category $category */
301+
$category = $categories[0];
302+
$mainCategoryList[]= $category;
303+
}
304+
305+
$total = [];
306+
foreach ($mainCategoryList as $category) {
307+
$parentScore = Category::getCurrentScore(
308+
$userId,
309+
$category->get_id(),
310+
$category->get_course_code(),
311+
0,
312+
true
313+
);
314+
315+
$dependencies = $category->getCourseListDependency();
316+
$children = [];
317+
$totalScoreWithChildren = 0;
318+
if (!empty($dependencies)) {
319+
foreach ($dependencies as $courseId) {
320+
$courseInfo = api_get_course_info_by_id($courseId);
321+
$courseCode = $courseInfo['code'];
322+
$categories = Category::load(null, null, $courseCode);
323+
/** @var Category $subCategory */
324+
$subCategory = $categories[0];
325+
$score = Category::getCurrentScore(
326+
$userId,
327+
$subCategory->get_id(),
328+
$subCategory->get_course_code(),
329+
0,
330+
true
331+
);
332+
$totalScoreWithChildren += $score;
333+
$children[$subCategory->get_course_code()] = ['score' => $score];
334+
}
335+
}
336+
$totalScoreWithChildren += $parentScore;
337+
$totalScoreWithChildrenAverage = $parentScore;
338+
if (!empty($children)) {
339+
$totalScoreWithChildrenAverage = $totalScoreWithChildren / (1 + count($children));
340+
}
341+
342+
$total[$category->get_course_code()] = [
343+
'score' => $parentScore,
344+
'total_score_with_children' => api_number_format($totalScoreWithChildrenAverage),
345+
'children' => $children
346+
];
347+
}
348+
349+
$finalScore = 0;
350+
$customTotalPercentage = 0;
351+
$maxPercentage = 80;
352+
$maxCustomPercentageCounter = 0;
353+
$validatedCoursesPercentage = 0;
354+
foreach ($total as $courseCode => $data) {
355+
$totalScoreWithChildren = $data['total_score_with_children'];
356+
if (in_array($courseCode, $mandatoryCourse)) {
357+
if ($totalScoreWithChildren == 100) {
358+
$finalScore = 0;
359+
$customTotalPercentage += 10;
360+
$validatedCoursesPercentage += 10;
361+
break;
362+
}
363+
} else {
364+
$maxCustomPercentageCounter++;
365+
if ($customTotalPercentage < $maxPercentage &&
366+
$totalScoreWithChildren == 100
367+
) {
368+
$customTotalPercentage += 10;
369+
}
370+
}
371+
$finalScore += $totalScoreWithChildren;
372+
}
373+
374+
$completed = false;
375+
if ($validatedCoursesPercentage == 20 && $customTotalPercentage == 80) {
376+
$completed = true;
377+
}
378+
379+
$controller->tpl->assign(
380+
'grade_book_result_validate',
381+
$validatedCoursesPercentage
382+
);
383+
$controller->tpl->assign('grade_book_result_completed', $completed);
384+
/*if ($finalScore > 0) {
385+
$finalScore = (int) $finalScore / count($total);
386+
if ($finalScore == 100) {
387+
$completed = true;
388+
}
389+
}*/
390+
}
391+
279392
$controller->tpl->display_two_col_template();
280393

281394
// Deleting the session_id.

0 commit comments

Comments
 (0)