1 | <?php |
||
2 | /* For licensing terms, see /license.txt */ |
||
3 | |||
4 | require_once __DIR__.'/../../main/inc/global.inc.php'; |
||
5 | |||
6 | api_protect_teacher_script(); |
||
7 | api_protect_course_script(); |
||
8 | |||
9 | $exerciseId = isset($_REQUEST['exercise']) ? (int) $_REQUEST['exercise'] : 0; |
||
10 | |||
11 | if (empty($exerciseId)) { |
||
12 | echo Display::return_message(get_lang('NotAllowed'), 'error'); |
||
13 | |||
14 | exit; |
||
15 | } |
||
16 | |||
17 | $exercise = new Exercise(); |
||
18 | |||
19 | if (!$exercise->read($exerciseId, false)) { |
||
20 | echo Display::return_message(get_lang('ExerciseNotFound'), 'error'); |
||
21 | |||
22 | exit; |
||
23 | } |
||
24 | |||
25 | $plugin = QuestionOptionsEvaluationPlugin::create(); |
||
26 | |||
27 | if ($plugin->get('enable') !== 'true') { |
||
28 | echo Display::return_message(get_lang('NotAllowed'), 'error'); |
||
29 | |||
30 | exit; |
||
31 | } |
||
32 | |||
33 | $formEvaluation = new FormValidator('evaluation'); |
||
34 | $formEvaluation |
||
35 | ->addRadio( |
||
36 | 'formula', |
||
37 | $plugin->get_lang('EvaluationFormula'), |
||
38 | [ |
||
39 | -1 => $plugin->get_lang('NoFormula'), |
||
40 | 0 => $plugin->get_lang('RecalculateQuestionScores'), |
||
41 | 1 => $plugin->get_lang('Formula1'), |
||
42 | 2 => $plugin->get_lang('Formula2'), |
||
43 | 3 => $plugin->get_lang('Formula3'), |
||
44 | ] |
||
45 | ) |
||
46 | ->setColumnsSize([4, 7, 1]); |
||
47 | $formEvaluation->addButtonSave(get_lang('Save'))->setColumnsSize([4, 7, 1]); |
||
48 | $formEvaluation->addHidden('exercise', $exerciseId); |
||
49 | |||
50 | if ($formEvaluation->validate()) { |
||
51 | $exercise->read($exerciseId, true); |
||
52 | $values = $formEvaluation->exportValues(); |
||
53 | $formula = isset($values['formula']) ? (int) $values['formula'] : 0; |
||
54 | $plugin->saveFormulaForExercise($formula, $exercise); |
||
55 | Display::addFlash( |
||
56 | Display::return_message( |
||
57 | sprintf($plugin->get_lang('FormulaSavedForExerciseX'), $exercise->selectTitle(true)), |
||
58 | 'success' |
||
59 | ) |
||
60 | ); |
||
61 | |||
62 | header( |
||
63 | 'Location: '.api_get_path(WEB_CODE_PATH).'exercise/exercise.php?'.api_get_cidreq()."&exerciseId=$exerciseId" |
||
64 | ); |
||
65 | exit; |
||
66 | } |
||
67 | |||
68 | $formEvaluation->setDefaults(['formula' => $plugin->getFormulaForExercise($exercise->iId)]); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
69 | |||
70 | echo Display::return_message( |
||
71 | $plugin->get_lang('QuizQuestionsScoreRulesTitleConfirm'), |
||
72 | 'warning' |
||
73 | ); |
||
74 | $formEvaluation->display(); |
||
75 |