gradebook_edit_result.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script.
  5. *
  6. * @package chamilo.gradebook
  7. */
  8. require_once __DIR__.'/../inc/global.inc.php';
  9. api_block_anonymous_users();
  10. GradebookUtils::block_students();
  11. $select_eval = (int) $_GET['selecteval'];
  12. if (empty($select_eval)) {
  13. api_not_allowed();
  14. }
  15. $resultedit = Result::load(null, null, $select_eval);
  16. $evaluation = Evaluation::load($select_eval);
  17. $evaluation[0]->check_lock_permissions();
  18. $courseInfo = api_get_course_info();
  19. $sessionId = api_get_session_id();
  20. $edit_result_form = new EvalForm(
  21. EvalForm::TYPE_ALL_RESULTS_EDIT,
  22. $evaluation[0],
  23. $resultedit,
  24. 'edit_result_form',
  25. null,
  26. api_get_self().'?selecteval='.$select_eval.'&'.api_get_cidreq()
  27. );
  28. if ($edit_result_form->validate()) {
  29. $values = $edit_result_form->exportValues();
  30. $scores = $values['score'];
  31. $bestResult = 0;
  32. $scoreFinalList = [];
  33. foreach ($scores as $userId => $score) {
  34. /** @var array $resultedit */
  35. $resultedit = Result::load($userId);
  36. /** @var Result $result */
  37. $result = $resultedit[0];
  38. if (empty($score)) {
  39. $score = 0;
  40. }
  41. $scoreFinalList[$result->get_user_id()] = $score;
  42. if ($score > $bestResult) {
  43. $bestResult = $score;
  44. }
  45. $score = api_number_format($score, api_get_setting('gradebook_number_decimals'));
  46. $result->set_score($score);
  47. $result->save();
  48. $allowMultipleAttempts = api_get_configuration_value('gradebook_multiple_evaluation_attempts');
  49. if ($allowMultipleAttempts) {
  50. $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_RESULT_ATTEMPT);
  51. $now = api_get_utc_datetime();
  52. $params = [
  53. 'result_id' => $result->get_id(),
  54. 'score' => $score,
  55. 'comment' => '',
  56. 'created_at' => $now,
  57. 'updated_at' => $now,
  58. ];
  59. Database::insert($table, $params);
  60. }
  61. }
  62. Display::addFlash(Display::return_message(get_lang('All results have been edited')));
  63. header('Location: gradebook_view_result.php?selecteval='.$select_eval.'&'.api_get_cidreq());
  64. exit;
  65. }
  66. $table = $edit_result_form->toHtml();
  67. $interbreadcrumb[] = [
  68. 'url' => Category::getUrl(),
  69. 'name' => get_lang('Assessments'),
  70. ];
  71. $interbreadcrumb[] = [
  72. 'url' => 'gradebook_view_result.php?selecteval='.$select_eval.'&'.api_get_cidreq(),
  73. 'name' => get_lang('Assessment details'),
  74. ];
  75. Display::display_header(get_lang('Grade learners'));
  76. DisplayGradebook::display_header_result($evaluation[0], null, 0, 0);
  77. echo $table;
  78. Display :: display_footer();