evaluation.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once __DIR__.'/../../main/inc/global.inc.php';
  4. api_protect_teacher_script();
  5. api_protect_course_script();
  6. $exerciseId = isset($_REQUEST['exercise']) ? (int) $_REQUEST['exercise'] : 0;
  7. if (empty($exerciseId)) {
  8. echo Display::return_message(get_lang('You are not allowed to see this page. Either your connection has expired or you are trying to access a page for which you do not have the sufficient privileges.'), 'error');
  9. exit;
  10. }
  11. $exercise = new Exercise();
  12. if (!$exercise->read($exerciseId, false)) {
  13. echo Display::return_message(get_lang('Test not found or not visible'), 'error');
  14. exit;
  15. }
  16. $plugin = QuestionOptionsEvaluationPlugin::create();
  17. if ($plugin->get('enable') !== 'true') {
  18. echo Display::return_message(get_lang('You are not allowed to see this page. Either your connection has expired or you are trying to access a page for which you do not have the sufficient privileges.'), 'error');
  19. exit;
  20. }
  21. $formEvaluation = new FormValidator('evaluation');
  22. $formEvaluation
  23. ->addRadio(
  24. 'formula',
  25. $plugin->get_lang('EvaluationFormula'),
  26. [
  27. -1 => $plugin->get_lang('NoFormula'),
  28. 0 => $plugin->get_lang('RecalculateQuestionScores'),
  29. 1 => $plugin->get_lang('Formula1'),
  30. 2 => $plugin->get_lang('Formula2'),
  31. 3 => $plugin->get_lang('Formula3'),
  32. ]
  33. )
  34. ->setColumnsSize([4, 7, 1]);
  35. $formEvaluation->addButtonSave(get_lang('Save'))->setColumnsSize([4, 7, 1]);
  36. $formEvaluation->addHidden('exercise', $exerciseId);
  37. if ($formEvaluation->validate()) {
  38. $exercise->read($exerciseId, true);
  39. $values = $formEvaluation->exportValues();
  40. $formula = isset($values['formula']) ? (int) $values['formula'] : 0;
  41. $plugin->saveFormulaForExercise($formula, $exercise);
  42. Display::addFlash(
  43. Display::return_message(
  44. sprintf($plugin->get_lang('FormulaSavedForExerciseX'), $exercise->selectTitle(true)),
  45. 'success'
  46. )
  47. );
  48. header(
  49. 'Location: '.api_get_path(WEB_CODE_PATH).'exercise/exercise.php?'.api_get_cidreq()."&exerciseId=$exerciseId"
  50. );
  51. exit;
  52. }
  53. $formEvaluation->setDefaults(['formula' => $plugin->getFormulaForExercise($exercise->iId)]);
  54. echo Display::return_message(
  55. $plugin->get_lang('QuizQuestionsScoreRulesTitleConfirm'),
  56. 'warning'
  57. );
  58. $formEvaluation->display();