| Conditions | 106 |
| Paths | > 20000 |
| Total Lines | 659 |
| Code Lines | 419 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 170 | public function get_table_data($from = 1, $per_page = null, $column = null, $direction = null, $sort = null) |
||
| 171 | { |
||
| 172 | //variables load in index.php |
||
| 173 | global $certificate_min_score; |
||
| 174 | // determine sorting type |
||
| 175 | $col_adjust = api_is_allowed_to_edit() ? 1 : 0; |
||
| 176 | // By id |
||
| 177 | $this->column = 5; |
||
| 178 | |||
| 179 | switch ($this->column) { |
||
| 180 | // Type |
||
| 181 | case (0 + $col_adjust): |
||
| 182 | $sorting = GradebookDataGenerator::GDG_SORT_TYPE; |
||
| 183 | break; |
||
| 184 | case (1 + $col_adjust): |
||
| 185 | $sorting = GradebookDataGenerator::GDG_SORT_NAME; |
||
| 186 | break; |
||
| 187 | case (2 + $col_adjust): |
||
| 188 | $sorting = GradebookDataGenerator::GDG_SORT_DESCRIPTION; |
||
| 189 | break; |
||
| 190 | case (3 + $col_adjust): |
||
| 191 | $sorting = GradebookDataGenerator::GDG_SORT_WEIGHT; |
||
| 192 | break; |
||
| 193 | case (4 + $col_adjust): |
||
| 194 | $sorting = GradebookDataGenerator::GDG_SORT_DATE; |
||
| 195 | break; |
||
| 196 | case (5 + $col_adjust): |
||
| 197 | $sorting = GradebookDataGenerator::GDG_SORT_ID; |
||
| 198 | break; |
||
| 199 | } |
||
| 200 | |||
| 201 | if ($this->direction == 'DESC') { |
||
| 202 | $sorting |= GradebookDataGenerator::GDG_SORT_DESC; |
||
| 203 | } else { |
||
| 204 | $sorting |= GradebookDataGenerator::GDG_SORT_ASC; |
||
| 205 | } |
||
| 206 | |||
| 207 | // Status of user in course. |
||
| 208 | $user_id = $this->userId; |
||
| 209 | $course_code = api_get_course_id(); |
||
| 210 | $session_id = api_get_session_id(); |
||
| 211 | |||
| 212 | if (empty($session_id)) { |
||
| 213 | $statusToFilter = STUDENT; |
||
| 214 | } else { |
||
| 215 | $statusToFilter = 0; |
||
| 216 | } |
||
| 217 | |||
| 218 | if (empty($this->studentList)) { |
||
| 219 | $studentList = CourseManager::get_user_list_from_course_code( |
||
| 220 | $course_code, |
||
| 221 | $session_id, |
||
| 222 | null, |
||
| 223 | null, |
||
| 224 | $statusToFilter |
||
| 225 | ); |
||
| 226 | $this->studentList = $studentList; |
||
| 227 | } |
||
| 228 | |||
| 229 | $this->datagen->userId = $this->userId; |
||
| 230 | $data_array = $this->datagen->get_data( |
||
| 231 | $sorting, |
||
| 232 | $from, |
||
| 233 | $this->per_page, |
||
| 234 | false, |
||
| 235 | $this->studentList |
||
| 236 | ); |
||
| 237 | |||
| 238 | // generate the data to display |
||
| 239 | $sortable_data = array(); |
||
| 240 | $weight_total_links = 0; |
||
| 241 | $main_cat = Category::load( |
||
| 242 | null, |
||
| 243 | null, |
||
| 244 | $course_code, |
||
| 245 | null, |
||
| 246 | null, |
||
| 247 | $session_id, |
||
| 248 | 'ORDER BY id' |
||
| 249 | ); |
||
| 250 | |||
| 251 | $total_categories_weight = 0; |
||
| 252 | $scoredisplay = ScoreDisplay::instance(); |
||
| 253 | |||
| 254 | $totalUserResult = [0, 0]; |
||
| 255 | $totalBest = [0, 0]; |
||
| 256 | $totalAverage = [0, 0]; |
||
| 257 | |||
| 258 | $type = 'detail'; |
||
| 259 | if ($this->exportToPdf) { |
||
| 260 | $type = 'simple'; |
||
| 261 | } |
||
| 262 | |||
| 263 | $model = ExerciseLib::getCourseScoreModel(); |
||
| 264 | |||
| 265 | // Categories. |
||
| 266 | if (!empty($data_array)) { |
||
| 267 | foreach ($data_array as $data) { |
||
| 268 | // list of items inside the gradebook (exercises, lps, forums, etc) |
||
| 269 | $row = array(); |
||
| 270 | |||
| 271 | /** @var AbstractLink $item */ |
||
| 272 | $item = $mainCategory = $data[0]; |
||
| 273 | |||
| 274 | //if the item is invisible, wrap it in a span with class invisible |
||
| 275 | $invisibility_span_open = api_is_allowed_to_edit() && $item->is_visible() == '0' ? '<span class="text-muted">' : ''; |
||
| 276 | $invisibility_span_close = api_is_allowed_to_edit() && $item->is_visible() == '0' ? '</span>' : ''; |
||
| 277 | |||
| 278 | // Id |
||
| 279 | if ($this->teacherView) { |
||
| 280 | if ($this->exportToPdf == false) { |
||
| 281 | $row[] = $this->build_id_column($item); |
||
| 282 | } |
||
| 283 | } |
||
| 284 | |||
| 285 | // Type. |
||
| 286 | $row[] = $this->build_type_column($item); |
||
| 287 | |||
| 288 | // Name. |
||
| 289 | if (get_class($item) == 'Category') { |
||
| 290 | $row[] = $invisibility_span_open.'<strong>'.$item->get_name().'</strong>'.$invisibility_span_close; |
||
| 291 | $main_categories[$item->get_id()]['name'] = $item->get_name(); |
||
| 292 | } else { |
||
| 293 | $name = $this->build_name_link($item, $type); |
||
| 294 | $row[] = $invisibility_span_open.$name.$invisibility_span_close; |
||
| 295 | $main_categories[$item->get_id()]['name'] = $name; |
||
| 296 | } |
||
| 297 | |||
| 298 | $this->dataForGraph['categories'][] = $item->get_name(); |
||
| 299 | |||
| 300 | $main_categories[$item->get_id()]['weight'] = $item->get_weight(); |
||
| 301 | $total_categories_weight += $item->get_weight(); |
||
| 302 | |||
| 303 | // Description. |
||
| 304 | if ($this->exportToPdf == false) { |
||
| 305 | $row[] = $invisibility_span_open.$data[2].$invisibility_span_close; |
||
| 306 | } |
||
| 307 | |||
| 308 | // Weight. |
||
| 309 | $weight = $scoredisplay->display_score( |
||
| 310 | array( |
||
| 311 | $data['3'], |
||
| 312 | $this->currentcat->get_weight() |
||
| 313 | ), |
||
| 314 | SCORE_SIMPLE, |
||
| 315 | SCORE_BOTH, |
||
| 316 | true |
||
| 317 | ); |
||
| 318 | |||
| 319 | if ($this->teacherView) { |
||
| 320 | $row[] = $invisibility_span_open. |
||
| 321 | Display::tag('p', $weight, array('class' => 'score')). |
||
| 322 | $invisibility_span_close; |
||
| 323 | } else { |
||
| 324 | $row[] = $invisibility_span_open.$weight.$invisibility_span_close; |
||
| 325 | } |
||
| 326 | |||
| 327 | $category_weight = $item->get_weight(); |
||
| 328 | $mainCategoryWeight = $main_cat[0]->get_weight(); |
||
| 329 | |||
| 330 | if ($this->teacherView) { |
||
| 331 | $weight_total_links += $data[3]; |
||
| 332 | } else { |
||
| 333 | $cattotal = Category::load($_GET['selectcat']); |
||
| 334 | $scoretotal = $cattotal[0]->calc_score($this->userId); |
||
| 335 | } |
||
| 336 | |||
| 337 | // Edit (for admins). |
||
| 338 | if ($this->teacherView) { |
||
| 339 | $cat = new Category(); |
||
| 340 | $show_message = $cat->show_message_resource_delete($item->get_course_code()); |
||
| 341 | if ($show_message === false) { |
||
| 342 | $row[] = $this->build_edit_column($item); |
||
| 343 | } |
||
| 344 | } else { |
||
| 345 | $score = $item->calc_score($this->userId); |
||
| 346 | |||
| 347 | if (!empty($score[1])) { |
||
| 348 | $completeScore = $scoredisplay->display_score($score, SCORE_DIV_PERCENT); |
||
| 349 | $score = $score[0] / $score[1] * $item->get_weight(); |
||
| 350 | $score = $scoredisplay->display_score(array($score, null), SCORE_SIMPLE); |
||
| 351 | $scoreToDisplay = Display::tip($score, $completeScore); |
||
| 352 | } else { |
||
| 353 | $scoreToDisplay = '-'; |
||
| 354 | $categoryScore = null; |
||
| 355 | } |
||
| 356 | |||
| 357 | // Students get the results and certificates columns |
||
| 358 | if (1) { |
||
| 359 | $value_data = isset($data[4]) ? $data[4] : null; |
||
| 360 | $best = isset($data['best']) ? $data['best'] : null; |
||
| 361 | $average = isset($data['average']) ? $data['average'] : null; |
||
| 362 | $ranking = isset($data['ranking']) ? $data['ranking'] : null; |
||
| 363 | |||
| 364 | $totalResult = [ |
||
| 365 | $data['result_score'][0], |
||
| 366 | $data['result_score'][1], |
||
| 367 | ]; |
||
| 368 | |||
| 369 | $totalUserResult[0] += $totalResult[0] / ($totalResult[1] ?: 1) * $data[3]; |
||
| 370 | $totalUserResult[1] += $data[3]; |
||
| 371 | |||
| 372 | $totalBest = [ |
||
| 373 | $scoredisplay->format_score($totalBest[0] + $data['best_score'][0]), |
||
| 374 | $scoredisplay->format_score($totalBest[1] + $data['best_score'][1]), |
||
| 375 | ]; |
||
| 376 | |||
| 377 | $totalAverage = [ |
||
| 378 | $data['average_score'][0], |
||
| 379 | $data['average_score'][1], |
||
| 380 | ]; |
||
| 381 | |||
| 382 | // Student result |
||
| 383 | if (empty($model)) { |
||
| 384 | $row[] = $value_data; |
||
| 385 | } else { |
||
| 386 | $row[] = ExerciseLib::show_score( |
||
| 387 | $data['result_score'][0], |
||
| 388 | $data['result_score'][1] |
||
| 389 | ); |
||
| 390 | } |
||
| 391 | $totalResultAverageValue = strip_tags( |
||
| 392 | $scoredisplay->display_score( |
||
| 393 | $totalResult, |
||
| 394 | SCORE_AVERAGE |
||
| 395 | ) |
||
| 396 | ); |
||
| 397 | |||
| 398 | $this->dataForGraph['my_result'][] = floatval($totalResultAverageValue); |
||
| 399 | $this->dataForGraph['my_result_no_float'][] = $data['result_score'][0]; |
||
| 400 | $totalAverageValue = strip_tags($scoredisplay->display_score($totalAverage, SCORE_AVERAGE)); |
||
| 401 | $this->dataForGraph['average'][] = floatval($totalAverageValue); |
||
| 402 | |||
| 403 | if (empty($model)) { |
||
| 404 | // Ranking |
||
| 405 | $row[] = $ranking; |
||
| 406 | // Best |
||
| 407 | $row[] = $best; |
||
| 408 | // Average |
||
| 409 | $row[] = $average; |
||
| 410 | } |
||
| 411 | |||
| 412 | if (get_class($item) == 'Category') { |
||
| 413 | if ($this->exportToPdf == false) { |
||
| 414 | $row[] = $this->build_edit_column($item); |
||
| 415 | } |
||
| 416 | } |
||
| 417 | } else { |
||
| 418 | $row[] = $scoreToDisplay; |
||
| 419 | |||
| 420 | if (!empty($this->cats)) { |
||
| 421 | if ($this->exportToPdf == false) { |
||
| 422 | $row[] = $this->build_edit_column($item); |
||
| 423 | } |
||
| 424 | } |
||
| 425 | } |
||
| 426 | } |
||
| 427 | |||
| 428 | // Category added. |
||
| 429 | $sortable_data[] = $row; |
||
| 430 | |||
| 431 | // Loading children |
||
| 432 | if (get_class($item) == 'Category') { |
||
| 433 | $course_code = api_get_course_id(); |
||
| 434 | $session_id = api_get_session_id(); |
||
| 435 | $parent_id = $item->get_id(); |
||
| 436 | $cats = Category::load( |
||
| 437 | $parent_id, |
||
| 438 | null, |
||
| 439 | null, |
||
| 440 | null, |
||
| 441 | null, |
||
| 442 | null |
||
| 443 | ); |
||
| 444 | |||
| 445 | if (isset($cats[0])) { |
||
| 446 | $allcat = $cats[0]->get_subcategories($this->userId, $course_code, $session_id); |
||
| 447 | $alleval = $cats[0]->get_evaluations($this->userId); |
||
| 448 | $alllink = $cats[0]->get_links($this->userId); |
||
| 449 | |||
| 450 | $sub_cat_info = new GradebookDataGenerator($allcat, $alleval, $alllink); |
||
| 451 | $sub_cat_info->userId = $user_id; |
||
| 452 | |||
| 453 | $data_array2 = $sub_cat_info->get_data( |
||
| 454 | $sorting, |
||
| 455 | $from, |
||
| 456 | $this->per_page, |
||
| 457 | false, |
||
| 458 | $this->studentList |
||
| 459 | ); |
||
| 460 | $total_weight = 0; |
||
| 461 | |||
| 462 | // Links. |
||
| 463 | foreach ($data_array2 as $data) { |
||
| 464 | $row = array(); |
||
| 465 | $item = $data[0]; |
||
| 466 | |||
| 467 | //if the item is invisible, wrap it in a span with class invisible |
||
| 468 | $invisibility_span_open = api_is_allowed_to_edit() && $item->is_visible() == '0' ? '<span class="text-muted">' : ''; |
||
| 469 | $invisibility_span_close = api_is_allowed_to_edit() && $item->is_visible() == '0' ? '</span>' : ''; |
||
| 470 | |||
| 471 | if (isset($item)) { |
||
| 472 | $main_categories[$parent_id]['children'][$item->get_id()]['name'] = $item->get_name(); |
||
| 473 | $main_categories[$parent_id]['children'][$item->get_id()]['weight'] = $item->get_weight(); |
||
| 474 | } |
||
| 475 | |||
| 476 | if ($this->teacherView) { |
||
| 477 | if ($this->exportToPdf == false) { |
||
| 478 | $row[] = $this->build_id_column($item); |
||
| 479 | } |
||
| 480 | } |
||
| 481 | |||
| 482 | // Type |
||
| 483 | $row[] = $this->build_type_column($item, array('style' => 'padding-left:5px')); |
||
| 484 | |||
| 485 | // Name. |
||
| 486 | $row[] = $invisibility_span_open." ". |
||
| 487 | $this->build_name_link($item, $type).$invisibility_span_close; |
||
| 488 | |||
| 489 | // Description. |
||
| 490 | if ($this->exportToPdf == false) { |
||
| 491 | $row[] = $invisibility_span_open.$data[2].$invisibility_span_close; |
||
| 492 | } |
||
| 493 | |||
| 494 | $weight = $data[3]; |
||
| 495 | $total_weight += $weight; |
||
| 496 | |||
| 497 | // Weight |
||
| 498 | $row[] = $invisibility_span_open.$weight.$invisibility_span_close; |
||
| 499 | |||
| 500 | if ($this->teacherView) { |
||
| 501 | //$weight_total_links += intval($data[3]); |
||
| 502 | } else { |
||
| 503 | $cattotal = Category::load($_GET['selectcat']); |
||
| 504 | $scoretotal = $cattotal[0]->calc_score($this->userId); |
||
| 505 | } |
||
| 506 | |||
| 507 | // Admins get an edit column. |
||
| 508 | if (api_is_allowed_to_edit(null, true) && |
||
| 509 | isset($_GET['user_id']) == false && |
||
| 510 | (isset($_GET['action']) && $_GET['action'] != 'export_all' || !isset($_GET['action'])) |
||
| 511 | ) { |
||
| 512 | $cat = new Category(); |
||
| 513 | $show_message = $cat->show_message_resource_delete($item->get_course_code()); |
||
| 514 | if ($show_message === false) { |
||
| 515 | if ($this->exportToPdf == false) { |
||
| 516 | $row[] = $this->build_edit_column($item); |
||
| 517 | } |
||
| 518 | } |
||
| 519 | } else { |
||
| 520 | // Students get the results and certificates columns |
||
| 521 | $eval_n_links = array_merge($alleval, $alllink); |
||
| 522 | |||
| 523 | if (count($eval_n_links) > 0) { |
||
| 524 | $value_data = isset($data[4]) ? $data[4] : null; |
||
| 525 | if (!is_null($value_data)) { |
||
| 526 | //$score = $item->calc_score(api_get_user_id()); |
||
| 527 | //$new_score = $data[3] * $score[0] / $score[1]; |
||
| 528 | //$new_score = floatval(number_format($new_score, api_get_setting('gradebook_number_decimals'))); |
||
| 529 | |||
| 530 | // Result |
||
| 531 | $row[] = $value_data; |
||
| 532 | $best = isset($data['best']) ? $data['best'] : null; |
||
| 533 | $average = isset($data['average']) ? $data['average'] : null; |
||
| 534 | $ranking = isset($data['ranking']) ? $data['ranking'] : null; |
||
| 535 | |||
| 536 | // Ranking |
||
| 537 | $row[] = $ranking; |
||
| 538 | // Best |
||
| 539 | $row[] = $best; |
||
| 540 | // Average |
||
| 541 | $row[] = $average; |
||
| 542 | } |
||
| 543 | } |
||
| 544 | |||
| 545 | if (!empty($cats)) { |
||
| 546 | if ($this->exportToPdf == false) { |
||
| 547 | $row[] = null; |
||
| 548 | } |
||
| 549 | } |
||
| 550 | } |
||
| 551 | |||
| 552 | if ($this->exportToPdf == false) { |
||
| 553 | $row['child_of'] = $parent_id; |
||
| 554 | } |
||
| 555 | $sortable_data[] = $row; |
||
| 556 | } |
||
| 557 | |||
| 558 | // "Warning row" |
||
| 559 | if (!empty($data_array)) { |
||
| 560 | if ($this->teacherView) { |
||
| 561 | // Compare the category weight to the sum of all weights inside the category |
||
| 562 | if (intval($total_weight) == $category_weight) { |
||
| 563 | $label = null; |
||
| 564 | $total = GradebookUtils::score_badges( |
||
| 565 | array( |
||
| 566 | $total_weight.' / '.$category_weight, |
||
| 567 | '100' |
||
| 568 | ) |
||
| 569 | ); |
||
| 570 | } else { |
||
| 571 | $label = Display::return_icon( |
||
| 572 | 'warning.png', |
||
| 573 | sprintf(get_lang('TotalWeightMustBeX'), $category_weight) |
||
| 574 | ); |
||
| 575 | $total = Display::badge($total_weight.' / '.$category_weight, 'warning'); |
||
| 576 | } |
||
| 577 | $row = array( |
||
| 578 | null, |
||
| 579 | null, |
||
| 580 | " <h5>".get_lang('SubTotal').'</h5>', |
||
| 581 | null, |
||
| 582 | $total.' '.$label, |
||
| 583 | 'child_of' => $parent_id |
||
| 584 | ); |
||
| 585 | $sortable_data[] = $row; |
||
| 586 | } |
||
| 587 | } |
||
| 588 | } |
||
| 589 | } |
||
| 590 | } |
||
| 591 | } //end looping categories |
||
| 592 | |||
| 593 | $main_weight = 0; |
||
| 594 | if (count($main_cat) > 1) { |
||
| 595 | /** @var Category $myCat */ |
||
| 596 | foreach ($main_cat as $myCat) { |
||
| 597 | $myParentId = $myCat->get_parent_id(); |
||
| 598 | if ($myParentId == 0) { |
||
| 599 | $main_weight = intval($myCat->get_weight()); |
||
| 600 | } |
||
| 601 | } |
||
| 602 | } |
||
| 603 | |||
| 604 | if ($this->teacherView) { |
||
| 605 | // Total for teacher. |
||
| 606 | if (count($main_cat) > 1) { |
||
| 607 | if (intval($total_categories_weight) == $main_weight) { |
||
| 608 | $total = GradebookUtils::score_badges( |
||
| 609 | array( |
||
| 610 | $total_categories_weight.' / '.$main_weight, |
||
| 611 | '100' |
||
| 612 | ) |
||
| 613 | ); |
||
| 614 | } else { |
||
| 615 | $total = Display::badge($total_categories_weight.' / '.$main_weight, 'warning'); |
||
| 616 | } |
||
| 617 | $row = array( |
||
| 618 | null, |
||
| 619 | null, |
||
| 620 | '<strong>'.get_lang('Total').'</strong>', |
||
| 621 | null, |
||
| 622 | $total |
||
| 623 | ); |
||
| 624 | $sortable_data[] = $row; |
||
| 625 | } |
||
| 626 | } else { |
||
| 627 | // Total for student. |
||
| 628 | if (count($main_cat) > 1) { |
||
| 629 | $weights = []; |
||
| 630 | foreach ($main_categories as $cat) { |
||
| 631 | $weights[] = $cat['weight']; |
||
| 632 | } |
||
| 633 | $main_weight = intval($main_cat[0]->get_weight()); |
||
| 634 | $global = null; |
||
| 635 | $average = null; |
||
| 636 | $myTotal = 0; |
||
| 637 | |||
| 638 | foreach ($this->dataForGraph['my_result_no_float'] as $result) { |
||
| 639 | $myTotal += $scoredisplay->format_score($result); |
||
| 640 | } |
||
| 641 | |||
| 642 | $totalResult[0] = $myTotal; |
||
| 643 | // Overwrite main weight |
||
| 644 | $totalResult[1] = $main_weight; |
||
| 645 | $totalResult = $scoredisplay->display_score( |
||
| 646 | $totalResult, |
||
| 647 | SCORE_DIV |
||
| 648 | ); |
||
| 649 | |||
| 650 | $totalRanking = array(); |
||
| 651 | $invalidateRanking = true; |
||
| 652 | $average = 0; |
||
| 653 | foreach ($this->studentList as $student) { |
||
| 654 | $score = $main_cat[0]->calc_score($student['user_id']); |
||
| 655 | if (!empty($score[0])) { |
||
| 656 | $invalidateRanking = false; |
||
| 657 | } |
||
| 658 | $totalRanking[$student['user_id']] = $score[0]; |
||
| 659 | $average += $score[0]; |
||
| 660 | } |
||
| 661 | |||
| 662 | $totalRanking = AbstractLink::getCurrentUserRanking($user_id, $totalRanking); |
||
| 663 | |||
| 664 | $totalRanking = $scoredisplay->display_score( |
||
| 665 | $totalRanking, |
||
| 666 | SCORE_DIV, |
||
| 667 | SCORE_BOTH, |
||
| 668 | true |
||
| 669 | ); |
||
| 670 | |||
| 671 | if ($invalidateRanking) { |
||
| 672 | $totalRanking = null; |
||
| 673 | } |
||
| 674 | |||
| 675 | // Overwrite main weight |
||
| 676 | $totalBest[1] = $main_weight; |
||
| 677 | |||
| 678 | $totalBest = $scoredisplay->display_score( |
||
| 679 | $totalBest, |
||
| 680 | SCORE_DIV, |
||
| 681 | SCORE_BOTH, |
||
| 682 | true |
||
| 683 | ); |
||
| 684 | |||
| 685 | // Overwrite main weight |
||
| 686 | $totalAverage[0] = $average / count($this->studentList); |
||
| 687 | $totalAverage[1] = $main_weight; |
||
| 688 | |||
| 689 | $totalAverage = $scoredisplay->display_score( |
||
| 690 | $totalAverage, |
||
| 691 | SCORE_DIV, |
||
| 692 | SCORE_BOTH, |
||
| 693 | true |
||
| 694 | ); |
||
| 695 | |||
| 696 | if ($this->exportToPdf) { |
||
| 697 | $row = array( |
||
| 698 | null, |
||
| 699 | '<h3>'.get_lang('Total').'</h3>', |
||
| 700 | $main_weight, |
||
| 701 | $totalResult, |
||
| 702 | $totalRanking, |
||
| 703 | $totalBest, |
||
| 704 | $totalAverage |
||
| 705 | ); |
||
| 706 | } else { |
||
| 707 | $row = array( |
||
| 708 | null, |
||
| 709 | '<h3>'.get_lang('Total').'</h3>', |
||
| 710 | null, |
||
| 711 | $main_weight, |
||
| 712 | $totalResult, |
||
| 713 | $totalRanking, |
||
| 714 | $totalBest, |
||
| 715 | $totalAverage |
||
| 716 | ); |
||
| 717 | } |
||
| 718 | |||
| 719 | $sortable_data[] = $row; |
||
| 720 | } |
||
| 721 | } |
||
| 722 | |||
| 723 | // Warning messages |
||
| 724 | $view = isset($_GET['view']) ? $_GET['view'] : null; |
||
| 725 | |||
| 726 | if ($this->teacherView) { |
||
| 727 | if (isset($_GET['selectcat']) && |
||
| 728 | $_GET['selectcat'] > 0 && |
||
| 729 | $view <> 'presence' |
||
| 730 | ) { |
||
| 731 | $id_cat = intval($_GET['selectcat']); |
||
| 732 | $category = Category::load($id_cat); |
||
| 733 | $weight_category = intval($this->build_weight($category[0])); |
||
| 734 | $course_code = $this->build_course_code($category[0]); |
||
| 735 | $weight_total_links = round($weight_total_links); |
||
| 736 | |||
| 737 | if ($weight_total_links > $weight_category || |
||
| 738 | $weight_total_links < $weight_category || |
||
| 739 | $weight_total_links > $weight_category |
||
| 740 | ) { |
||
| 741 | $warning_message = sprintf(get_lang('TotalWeightMustBeX'), $weight_category); |
||
| 742 | $modify_icons = '<a href="gradebook_edit_cat.php?editcat='.$id_cat.'&cidReq='.$course_code.'&id_session='.api_get_session_id().'">'. |
||
| 743 | Display::return_icon('edit.png', $warning_message, array(), ICON_SIZE_SMALL).'</a>'; |
||
| 744 | $warning_message .= $modify_icons; |
||
| 745 | echo Display::return_message($warning_message, 'warning', false); |
||
| 746 | } |
||
| 747 | |||
| 748 | $content_html = DocumentManager::replace_user_info_into_html( |
||
| 749 | api_get_user_id(), |
||
| 750 | $course_code, |
||
| 751 | api_get_session_id() |
||
| 752 | ); |
||
| 753 | |||
| 754 | if (!empty($content_html)) { |
||
| 755 | $new_content = explode('</head>', $content_html['content']); |
||
| 756 | } |
||
| 757 | |||
| 758 | if (empty($new_content[0])) { |
||
| 759 | // Set default certificate |
||
| 760 | $courseData = api_get_course_info($course_code); |
||
| 761 | DocumentManager::generateDefaultCertificate($courseData); |
||
| 762 | } |
||
| 763 | } |
||
| 764 | |||
| 765 | if (empty($_GET['selectcat'])) { |
||
| 766 | $categories = Category::load(); |
||
| 767 | $weight_categories = $certificate_min_scores = $course_codes = array(); |
||
| 768 | foreach ($categories as $category) { |
||
| 769 | $course_code_category = $this->build_course_code($category); |
||
| 770 | if (!empty($course_code)) { |
||
| 771 | if ($course_code_category == $course_code) { |
||
| 772 | $weight_categories[] = intval($this->build_weight($category)); |
||
| 773 | $certificate_min_scores[] = intval($this->build_certificate_min_score($category)); |
||
| 774 | $course_codes[] = $course_code; |
||
| 775 | break; |
||
| 776 | } |
||
| 777 | } else { |
||
| 778 | $weight_categories[] = intval($this->build_weight($category)); |
||
| 779 | $certificate_min_scores[] = intval($this->build_certificate_min_score($category)); |
||
| 780 | $course_codes[] = $course_code_category; |
||
| 781 | } |
||
| 782 | } |
||
| 783 | |||
| 784 | if (is_array($weight_categories) && |
||
| 785 | is_array($certificate_min_scores) && |
||
| 786 | is_array($course_codes) |
||
| 787 | ) { |
||
| 788 | $warning_message = ''; |
||
| 789 | for ($x = 0; $x < count($weight_categories); $x++) { |
||
| 790 | $weight_category = intval($weight_categories[$x]); |
||
| 791 | $certificate_min_score = intval($certificate_min_scores[$x]); |
||
| 792 | $course_code = $course_codes[$x]; |
||
| 793 | |||
| 794 | if (empty($certificate_min_score) || |
||
| 795 | ($certificate_min_score > $weight_category) |
||
| 796 | ) { |
||
| 797 | $warning_message .= $course_code.' - '.get_lang('CertificateMinimunScoreIsRequiredAndMustNotBeMoreThan').' '.$weight_category.'<br />'; |
||
| 798 | } |
||
| 799 | } |
||
| 800 | |||
| 801 | if (!empty($warning_message)) { |
||
| 802 | echo Display::return_message($warning_message, 'warning', false); |
||
| 803 | } |
||
| 804 | } |
||
| 805 | } |
||
| 806 | } |
||
| 807 | |||
| 808 | if (!$this->teacherView) { |
||
| 809 | $rowTotal = []; |
||
| 810 | $rowTotal[] = ' '; |
||
| 811 | $rowTotal[] = get_lang('FinalScore'); |
||
| 812 | |||
| 813 | if (!$this->exportToPdf) { |
||
| 814 | $rowTotal[] = ' '; |
||
| 815 | } |
||
| 816 | $rowTotal[] = ' '; |
||
| 817 | $rowTotal[] = $scoredisplay->display_score( |
||
| 818 | $totalUserResult, |
||
| 819 | SCORE_DIV_PERCENT_WITH_CUSTOM |
||
| 820 | ); |
||
| 821 | $rowTotal[] = ' '; |
||
| 822 | $rowTotal[] = ' '; |
||
| 823 | $rowTotal[] = ' '; |
||
| 824 | |||
| 825 | $sortable_data[] = $rowTotal; |
||
| 826 | } |
||
| 827 | |||
| 828 | return $sortable_data; |
||
| 829 | } |
||
| 1120 |