| Conditions | 72 |
| Paths | > 20000 |
| Total Lines | 328 |
| Code Lines | 234 |
| 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:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
| 1 | <?php |
||
| 263 | public static function header( |
||
| 264 | $catobj, |
||
| 265 | $showtree, |
||
| 266 | $selectcat, |
||
| 267 | $is_course_admin, |
||
| 268 | $is_platform_admin, |
||
| 269 | $simple_search_form, |
||
| 270 | $show_add_qualification = true, |
||
| 271 | $show_add_link = true, |
||
| 272 | $certificateLinkInfo = [] |
||
| 273 | ) { |
||
| 274 | $userId = api_get_user_id(); |
||
| 275 | $courseId = api_get_course_int_id(); |
||
| 276 | $sessionId = api_get_session_id(); |
||
| 277 | if (!$is_course_admin) { |
||
| 278 | $model = ExerciseLib::getCourseScoreModel(); |
||
| 279 | if (!empty($model)) { |
||
| 280 | return ''; |
||
| 281 | } |
||
| 282 | } |
||
| 283 | |||
| 284 | // Student. |
||
| 285 | $status = CourseManager::getUserInCourseStatus($userId, $courseId); |
||
| 286 | $sessionStatus = 0; |
||
| 287 | |||
| 288 | if (!empty($sessionId)) { |
||
| 289 | $sessionStatus = SessionManager::get_user_status_in_course_session( |
||
| 290 | $userId, |
||
| 291 | $courseId, |
||
| 292 | $sessionId |
||
| 293 | ); |
||
| 294 | } |
||
| 295 | |||
| 296 | $objcat = new Category(); |
||
| 297 | $course_id = CourseManager::get_course_by_category($selectcat); |
||
| 298 | $message_resource = $objcat->show_message_resource_delete($course_id); |
||
| 299 | $grade_model_id = $catobj->get_grade_model_id(); |
||
| 300 | $header = null; |
||
| 301 | if (isset($catobj) && !empty($catobj)) { |
||
| 302 | $categories = Category::load( |
||
| 303 | null, |
||
| 304 | null, |
||
| 305 | null, |
||
| 306 | $catobj->get_id(), |
||
| 307 | null, |
||
| 308 | $sessionId |
||
| 309 | ); |
||
| 310 | } |
||
| 311 | |||
| 312 | if (!$is_course_admin && (1 != $status || 0 == $sessionStatus) && 0 != $selectcat) { |
||
| 313 | $catcourse = Category::load($catobj->get_id()); |
||
| 314 | /** @var Category $category */ |
||
| 315 | $category = $catcourse[0]; |
||
| 316 | $main_weight = $category->get_weight(); |
||
| 317 | $scoredisplay = ScoreDisplay::instance(); |
||
| 318 | $allevals = $category->get_evaluations($userId, true); |
||
| 319 | $alllinks = $category->get_links($userId, true); |
||
| 320 | $allEvalsLinks = array_merge($allevals, $alllinks); |
||
| 321 | $item_value_total = 0; |
||
| 322 | $scoreinfo = null; |
||
| 323 | |||
| 324 | for ($count = 0; $count < count($allEvalsLinks); $count++) { |
||
| 325 | $item = $allEvalsLinks[$count]; |
||
| 326 | $score = $item->calc_score($userId); |
||
| 327 | if (!empty($score)) { |
||
| 328 | $divide = 0 == $score[1] ? 1 : $score[1]; |
||
| 329 | $item_value = $score[0] / $divide * $item->get_weight(); |
||
| 330 | $item_value_total += $item_value; |
||
| 331 | } |
||
| 332 | } |
||
| 333 | |||
| 334 | $item_total = $main_weight; |
||
| 335 | $total_score = [$item_value_total, $item_total]; |
||
| 336 | $scorecourse_display = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT); |
||
| 337 | |||
| 338 | if ('0' == !$catobj->get_id() && !isset($_GET['studentoverview']) && !isset($_GET['search'])) { |
||
| 339 | $additionalButtons = null; |
||
| 340 | if (!empty($certificateLinkInfo)) { |
||
| 341 | $additionalButtons .= '<div class="btn-group pull-right">'; |
||
| 342 | $additionalButtons .= isset($certificateLinkInfo['certificate_link']) ? $certificateLinkInfo['certificate_link'] : ''; |
||
| 343 | $additionalButtons .= isset($certificateLinkInfo['badge_link']) ? $certificateLinkInfo['badge_link'] : ''; |
||
| 344 | $additionalButtons .= '</div>'; |
||
| 345 | } |
||
| 346 | $scoreinfo .= '<strong>'.sprintf(get_lang('Total: %s'), $scorecourse_display.$additionalButtons).'</strong>'; |
||
| 347 | } |
||
| 348 | echo Display::return_message($scoreinfo, 'normal', false); |
||
| 349 | } |
||
| 350 | |||
| 351 | // show navigation tree and buttons? |
||
| 352 | if ('1' == $showtree || isset($_GET['studentoverview'])) { |
||
| 353 | $header = '<div class="actions"><table>'; |
||
| 354 | $header .= '<tr>'; |
||
| 355 | if ('0' == !$selectcat) { |
||
| 356 | $header .= '<td><a href="'.api_get_self().'?selectcat='.$catobj->get_parent_id().'">'. |
||
| 357 | Display::return_icon( |
||
| 358 | 'back.png', |
||
| 359 | get_lang('Back to').' '.get_lang('Main folder'), |
||
| 360 | '', |
||
| 361 | ICON_SIZE_MEDIUM |
||
| 362 | ). |
||
| 363 | '</a></td>'; |
||
| 364 | } |
||
| 365 | $header .= '<td>'.get_lang('Current course').'</td>'. |
||
| 366 | '<td><form name="selector"><select name="selectcat" onchange="document.selector.submit()">'; |
||
| 367 | $cats = Category::load(); |
||
| 368 | |||
| 369 | $tree = $cats[0]->get_tree(); |
||
| 370 | unset($cats); |
||
| 371 | $line = null; |
||
| 372 | foreach ($tree as $cat) { |
||
| 373 | for ($i = 0; $i < $cat[2]; $i++) { |
||
| 374 | $line .= '—'; |
||
| 375 | } |
||
| 376 | $line = isset($line) ? $line : ''; |
||
| 377 | if (isset($_GET['selectcat']) && $_GET['selectcat'] == $cat[0]) { |
||
| 378 | $header .= '<option selected value='.$cat[0].'>'.$line.' '.$cat[1].'</option>'; |
||
| 379 | } else { |
||
| 380 | $header .= '<option value='.$cat[0].'>'.$line.' '.$cat[1].'</option>'; |
||
| 381 | } |
||
| 382 | $line = ''; |
||
| 383 | } |
||
| 384 | $header .= '</select></form></td>'; |
||
| 385 | if (!empty($simple_search_form) && false === $message_resource) { |
||
| 386 | $header .= '<td style="vertical-align: top;">'.$simple_search_form->toHtml().'</td>'; |
||
| 387 | } else { |
||
| 388 | $header .= '<td></td>'; |
||
| 389 | } |
||
| 390 | if (!($is_course_admin && |
||
| 391 | false === $message_resource && |
||
| 392 | isset($_GET['selectcat']) && 0 != $_GET['selectcat']) && |
||
| 393 | isset($_GET['studentoverview']) |
||
| 394 | ) { |
||
| 395 | $header .= '<td style="vertical-align: top;"> |
||
| 396 | <a href="'.api_get_self().'?'.api_get_cidreq().'&studentoverview=&exportpdf=&selectcat='.$catobj->get_id().'" target="_blank"> |
||
| 397 | '.Display::return_icon('pdf.png', get_lang('Export to PDF'), [], ICON_SIZE_MEDIUM).' |
||
| 398 | '.get_lang('Export to PDF').'</a>'; |
||
| 399 | } |
||
| 400 | $header .= '</td></tr>'; |
||
| 401 | $header .= '</table></div>'; |
||
| 402 | } |
||
| 403 | |||
| 404 | // for course admin & platform admin add item buttons are added to the header |
||
| 405 | $actionsLeft = ''; |
||
| 406 | $actionsRight = ''; |
||
| 407 | $my_api_cidreq = api_get_cidreq(); |
||
| 408 | $isCoach = api_is_coach(api_get_session_id(), api_get_course_int_id()); |
||
| 409 | $accessToRead = api_is_allowed_to_edit(null, true) || $isCoach; |
||
| 410 | $accessToEdit = api_is_allowed_to_edit(null, true); |
||
| 411 | $courseCode = api_get_course_id(); |
||
| 412 | |||
| 413 | if ($accessToRead) { |
||
| 414 | $my_category = $catobj->showAllCategoryInfo($catobj->get_id()); |
||
| 415 | if ('0' != $selectcat && $accessToEdit) { |
||
| 416 | if ('' == $my_api_cidreq) { |
||
| 417 | $my_api_cidreq = 'cidReq='.$my_category['course_code']; |
||
| 418 | } |
||
| 419 | if ($show_add_link && !$message_resource) { |
||
| 420 | $actionsLeft .= '<a href="gradebook_add_eval.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'" >'. |
||
| 421 | Display::return_icon('new_evaluation.png', get_lang('Add classroom activity'), '', |
||
| 422 | ICON_SIZE_MEDIUM).'</a>'; |
||
| 423 | $cats = Category::load($selectcat); |
||
| 424 | |||
| 425 | if (null != $cats[0]->get_course_code() && !$message_resource) { |
||
| 426 | $actionsLeft .= '<a href="gradebook_add_link.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'. |
||
| 427 | Display::return_icon('new_online_evaluation.png', get_lang('Add online activity'), '', |
||
| 428 | ICON_SIZE_MEDIUM).'</a>'; |
||
| 429 | } else { |
||
| 430 | $actionsLeft .= '<a href="gradebook_add_link_select_course.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'. |
||
| 431 | Display::return_icon('new_online_evaluation.png', get_lang('Add online activity'), '', |
||
| 432 | ICON_SIZE_MEDIUM).'</a>'; |
||
| 433 | } |
||
| 434 | } |
||
| 435 | } |
||
| 436 | if ((empty($grade_model_id) || -1 == $grade_model_id) && $accessToEdit) { |
||
| 437 | $actionsLeft .= '<a href="gradebook_add_cat.php?'.api_get_cidreq().'&selectcat='.$catobj->get_id().'">'. |
||
| 438 | Display::return_icon( |
||
| 439 | 'new_folder.png', |
||
| 440 | get_lang('Add assessment'), |
||
| 441 | [], |
||
| 442 | ICON_SIZE_MEDIUM |
||
| 443 | ).'</a></td>'; |
||
| 444 | } |
||
| 445 | |||
| 446 | if ('0' != $selectcat && $accessToRead) { |
||
| 447 | if (!$message_resource) { |
||
| 448 | $actionsLeft .= '<a href="gradebook_flatview.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'. |
||
| 449 | Display::return_icon('statistics.png', get_lang('List View'), '', ICON_SIZE_MEDIUM).'</a>'; |
||
| 450 | |||
| 451 | if (1 == $my_category['generate_certificates']) { |
||
| 452 | $actionsLeft .= Display::url( |
||
| 453 | Display::return_icon( |
||
| 454 | 'certificate_list.png', |
||
| 455 | get_lang('See list of learner certificates'), |
||
| 456 | '', |
||
| 457 | ICON_SIZE_MEDIUM |
||
| 458 | ), |
||
| 459 | "gradebook_display_certificate.php?$my_api_cidreq&cat_id=".$selectcat |
||
| 460 | ); |
||
| 461 | } |
||
| 462 | |||
| 463 | $actionsLeft .= Display::url( |
||
| 464 | Display::return_icon( |
||
| 465 | 'user.png', |
||
| 466 | get_lang('Students list report'), |
||
| 467 | '', |
||
| 468 | ICON_SIZE_MEDIUM |
||
| 469 | ), |
||
| 470 | "gradebook_display_summary.php?$my_api_cidreq&selectcat=".$selectcat |
||
| 471 | ); |
||
| 472 | |||
| 473 | $allow = api_get_configuration_value('gradebook_custom_student_report'); |
||
| 474 | if ($allow) { |
||
| 475 | $actionsLeft .= Display::url( |
||
| 476 | get_lang('Generate custom report'), |
||
| 477 | api_get_path(WEB_AJAX_PATH)."gradebook.ajax.php?$my_api_cidreq&a=generate_custom_report", |
||
| 478 | ['class' => 'btn btn-default ajax'] |
||
| 479 | ); |
||
| 480 | } |
||
| 481 | |||
| 482 | // Right icons |
||
| 483 | if ($accessToEdit) { |
||
| 484 | $actionsRight = '<a href="gradebook_edit_cat.php?editcat='.$catobj->get_id( |
||
| 485 | ).'&cidReq='.$catobj->get_course_code().'&id_session='.$catobj->get_session_id().'">'. |
||
| 486 | Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_MEDIUM).'</a>'; |
||
| 487 | |||
| 488 | if ('true' == api_get_plugin_setting('customcertificate', 'enable_plugin_customcertificate') && |
||
| 489 | 1 == api_get_course_setting('customcertificate_course_enable') |
||
| 490 | ) { |
||
| 491 | $actionsRight .= '<a href="'.api_get_path( |
||
| 492 | WEB_PLUGIN_PATH |
||
| 493 | ).'customcertificate/src/index.php?'. |
||
| 494 | $my_api_cidreq.'&origin=gradebook&selectcat='.$catobj->get_id().'">'. |
||
| 495 | Display::return_icon( |
||
| 496 | 'certificate.png', |
||
| 497 | get_lang('Attach certificate'), |
||
| 498 | '', |
||
| 499 | ICON_SIZE_MEDIUM |
||
| 500 | ).'</a>'; |
||
| 501 | } else { |
||
| 502 | $actionsRight .= '<a href="'.api_get_path(WEB_CODE_PATH). |
||
| 503 | 'document/document.php?curdirpath=/certificates&'. |
||
| 504 | $my_api_cidreq.'&origin=gradebook&selectcat='.$catobj->get_id().'">'. |
||
| 505 | Display::return_icon( |
||
| 506 | 'certificate.png', |
||
| 507 | get_lang('Attach certificate'), |
||
| 508 | '', |
||
| 509 | ICON_SIZE_MEDIUM |
||
| 510 | ).'</a>'; |
||
| 511 | } |
||
| 512 | |||
| 513 | if (empty($categories)) { |
||
| 514 | $actionsRight .= '<a href="gradebook_edit_all.php?id_session='.api_get_session_id( |
||
| 515 | ).'&'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'. |
||
| 516 | Display::return_icon( |
||
| 517 | 'percentage.png', |
||
| 518 | get_lang('Weight in Report'), |
||
| 519 | '', |
||
| 520 | ICON_SIZE_MEDIUM |
||
| 521 | ).'</a>'; |
||
| 522 | } |
||
| 523 | $score_display_custom = api_get_setting('gradebook_score_display_custom'); |
||
| 524 | if ('true' == api_get_setting('teachers_can_change_score_settings') && |
||
| 525 | 'true' == $score_display_custom |
||
| 526 | ) { |
||
| 527 | $actionsRight .= '<a href="gradebook_scoring_system.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'. |
||
| 528 | Display::return_icon('ranking.png', get_lang('Skills ranking'), '', ICON_SIZE_MEDIUM).'</a>'; |
||
| 529 | } |
||
| 530 | } |
||
| 531 | } |
||
| 532 | } |
||
| 533 | } elseif (isset($_GET['search'])) { |
||
| 534 | echo $header = '<b>'.get_lang('Search results').' :</b>'; |
||
| 535 | } |
||
| 536 | |||
| 537 | $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh( |
||
| 538 | api_get_user_id(), |
||
| 539 | api_get_course_info() |
||
| 540 | ); |
||
| 541 | |||
| 542 | if ($isDrhOfCourse) { |
||
| 543 | $actionsLeft .= '<a href="gradebook_flatview.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'. |
||
| 544 | Display::return_icon( |
||
| 545 | 'statistics.png', |
||
| 546 | get_lang('List View'), |
||
| 547 | '', |
||
| 548 | ICON_SIZE_MEDIUM |
||
| 549 | ). |
||
| 550 | '</a>'; |
||
| 551 | } |
||
| 552 | |||
| 553 | if ($isCoach || api_is_allowed_to_edit(null, true)) { |
||
| 554 | echo $toolbar = Display::toolbarAction( |
||
| 555 | 'gradebook-actions', |
||
| 556 | [$actionsLeft, $actionsRight] |
||
| 557 | ); |
||
| 558 | } |
||
| 559 | |||
| 560 | if ($accessToEdit || api_is_allowed_to_edit(null, true)) { |
||
| 561 | $weight = intval($catobj->get_weight()) > 0 ? $catobj->get_weight() : 0; |
||
| 562 | $weight = '<strong>'.get_lang('Total weight').' : </strong>'.$weight; |
||
| 563 | $min_certification = intval($catobj->getCertificateMinScore() > 0) ? $catobj->getCertificateMinScore() : 0; |
||
| 564 | |||
| 565 | if (!empty($min_certification)) { |
||
| 566 | $model = ExerciseLib::getCourseScoreModel(); |
||
| 567 | if (!empty($model)) { |
||
| 568 | $defaultCertification = api_number_format($min_certification, 2); |
||
| 569 | $questionWeighting = $catobj->get_weight(); |
||
| 570 | foreach ($model['score_list'] as $item) { |
||
| 571 | $i = api_number_format($item['score_to_qualify'] / 100 * $questionWeighting, 2); |
||
| 572 | $model = ExerciseLib::getModelStyle($item, $i); |
||
| 573 | if ($defaultCertification == $i) { |
||
| 574 | $min_certification = $model; |
||
| 575 | break; |
||
| 576 | } |
||
| 577 | } |
||
| 578 | } |
||
| 579 | } |
||
| 580 | |||
| 581 | $min_certification = get_lang('Minimum certification score').' : '.$min_certification; |
||
| 582 | $edit_icon = '<a href="gradebook_edit_cat.php?editcat='.$catobj->get_id().'&cidReq='.$catobj->get_course_code().'&id_session='.$catobj->get_session_id().'">'. |
||
| 583 | Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL).'</a>'; |
||
| 584 | |||
| 585 | $msg = $weight.' - '.$min_certification.$edit_icon; |
||
| 586 | //@todo show description |
||
| 587 | $description = (('' == $catobj->get_description() || is_null($catobj->get_description())) ? '' : '<strong>'.get_lang('Assessment description').'</strong>'.': '.$catobj->get_description()); |
||
| 588 | echo Display::return_message($msg, 'normal', false); |
||
| 589 | if (!empty($description)) { |
||
| 590 | echo Display::div($description, []); |
||
| 591 | } |
||
| 704 |