@@ -297,7 +297,8 @@ function changeMyCoursesView(inView) {
297
297
}
298
298
}
299
299
300
- // @todo improve calls of course info
300
+
301
+ // @todo improve calls of course info
301
302
$ subscribedCourses = !empty ($ courseAndSessions ['courses ' ]) ? $ courseAndSessions ['courses ' ] : [];
302
303
$ mainCategoryList = [];
303
304
foreach ($ subscribedCourses as $ courseInfo ) {
@@ -309,6 +310,77 @@ function changeMyCoursesView(inView) {
309
310
$ mainCategoryList [] = $ category ;
310
311
}
311
312
}
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
+ }
312
384
$total = [];
313
385
foreach ($mainCategoryList as $category) {
314
386
$parentScore = Category::getCurrentScore(
@@ -325,7 +397,6 @@ function changeMyCoursesView(inView) {
325
397
$courseInfo = api_get_course_info_by_id($courseId);
326
398
$courseCode = $courseInfo['code'];
327
399
$categories = Category::load(null, null, $courseCode);
328
- /** @var Category $subCategory */
329
400
$subCategory = !empty($categories[0]) ? $categories[0] : null;
330
401
if (!empty($subCategory)) {
331
402
$score = Category::getCurrentScore(
@@ -352,20 +423,61 @@ function changeMyCoursesView(inView) {
352
423
];
353
424
}
354
425
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
+
355
435
$finalScore = 0;
356
436
$customTotalPercentage = 0;
357
437
$maxPercentage = 80;
358
438
$maxCustomPercentageCounter = 0;
359
439
$validatedCoursesPercentage = 0;
440
+ $resultPerCategory = [];
360
441
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;
366
472
}
367
- }
368
473
474
+ $completed = false;
475
+ if ($mandatoryPercentage == 20 && $nonMandatoryPercentage == 80) {
476
+ $completed = true;
477
+ }
478
+ }*/
479
+
480
+ /*
369
481
foreach ($total as $courseCode => $data) {
370
482
$totalScoreWithChildren = $data['total_score_with_children'];
371
483
if ($data['min_validated'] < $countValidated) {
@@ -393,14 +505,19 @@ function changeMyCoursesView(inView) {
393
505
$completed = false;
394
506
if ($validatedCoursesPercentage == 20 && $customTotalPercentage == 80) {
395
507
$completed = true;
396
- }
508
+ }*/
509
+
510
+ $ controller ->tpl ->assign (
511
+ 'grade_book_sidebar ' ,
512
+ true
513
+ );
397
514
398
515
$ controller ->tpl ->assign (
399
- 'grade_book_result_validate ' ,
400
- $ validatedCoursesPercentage
516
+ 'grade_book_progress ' ,
517
+ $ finalResult
401
518
);
402
519
403
- $ controller ->tpl ->assign ('grade_book_result_completed ' , $ completed );
520
+ $ controller ->tpl ->assign ('grade_book_badge_list ' , $ badgeList );
404
521
/*if ($finalScore > 0) {
405
522
$finalScore = (int) $finalScore / count($total);
406
523
if ($finalScore == 100) {
0 commit comments