|
2 | 2 | /* For licensing terms, see /license.txt */ |
3 | 3 |
|
4 | 4 | use ChamiloSession as Session; |
| 5 | +use Doctrine\Common\Collections\Criteria; |
5 | 6 |
|
6 | 7 | /** |
7 | 8 | * This is the index file displayed when a user is logged in on Chamilo. |
@@ -276,6 +277,118 @@ function changeMyCoursesView(inView) { |
276 | 277 | if ($myCourseListAsCategory) { |
277 | 278 | $controller->tpl->assign('header', get_lang('MyCourses')); |
278 | 279 | } |
| 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 | + |
279 | 392 | $controller->tpl->display_two_col_template(); |
280 | 393 |
|
281 | 394 | // Deleting the session_id. |
|
0 commit comments