Skip to content

Commit 709740f

Browse files
committed
Add question code in question edition (admin only) see BT#15230
1 parent d209d18 commit 709740f

File tree

3 files changed

+40
-21
lines changed

3 files changed

+40
-21
lines changed

main/exercise/export/aiken/aiken_classes.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,6 @@ public function setAnswer()
3232
return $answer;
3333
}
3434

35-
/**
36-
* @param string $code
37-
*
38-
* @return bool
39-
*/
40-
public function addCode($code)
41-
{
42-
if (api_get_configuration_value('allow_question_code') && !empty($this->id)) {
43-
$code = Database::escape_string($code);
44-
$table = Database::get_course_table(TABLE_QUIZ_QUESTION);
45-
$sql = "UPDATE $table SET code = '$code'
46-
WHERE iid = {$this->id} AND c_id = {$this->course['real_id']}";
47-
Database::query($sql);
48-
49-
return true;
50-
}
51-
52-
return false;
53-
}
54-
5535
public function createAnswersForm($form)
5636
{
5737
return true;

main/exercise/question.class.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,6 +1684,10 @@ public function createForm(&$form, $exercise)
16841684
//$form->addElement('select', 'parent_id', get_lang('AttachToMedia'), $course_medias);
16851685
}
16861686

1687+
if (api_get_configuration_value('allow_question_code') && api_is_platform_admin()) {
1688+
$form->addText('code', get_lang('QuestionCode'));
1689+
}
1690+
16871691
$form->addElement('html', '</div>');
16881692

16891693
if (!isset($_GET['fromExercise'])) {
@@ -1723,6 +1727,10 @@ public function createForm(&$form, $exercise)
17231727
$defaults['questionCategory'] = $this->category;
17241728
$defaults['feedback'] = $this->feedback;
17251729

1730+
if (api_get_configuration_value('allow_question_code') && api_is_platform_admin()) {
1731+
$defaults['code'] = $this->code;
1732+
}
1733+
17261734
// Came from he question pool
17271735
if (isset($_GET['fromExercise'])) {
17281736
$form->setDefaults($defaults);
@@ -1755,6 +1763,10 @@ public function processCreation($form, $exercise)
17551763
if ($this->type != MEDIA_QUESTION) {
17561764
$this->save($exercise);
17571765

1766+
if (api_is_platform_admin()) {
1767+
$this->addCode($form->getSubmitValue('code'));
1768+
}
1769+
17581770
// modify the exercise
17591771
$exercise->addToList($this->id);
17601772
$exercise->update_question_positions();
@@ -2422,4 +2434,26 @@ private function resizePicture($Dimension, $Max)
24222434

24232435
return false;
24242436
}
2437+
2438+
2439+
/**
2440+
* @param string $code
2441+
*
2442+
* @return bool
2443+
*/
2444+
public function addCode($code)
2445+
{
2446+
if (api_get_configuration_value('allow_question_code') && !empty($this->id)) {
2447+
$code = Database::escape_string($code);
2448+
$table = Database::get_course_table(TABLE_QUIZ_QUESTION);
2449+
$sql = "UPDATE $table SET code = '$code'
2450+
WHERE iid = {$this->id} AND c_id = {$this->course['real_id']}";
2451+
Database::query($sql);
2452+
2453+
return true;
2454+
}
2455+
2456+
return false;
2457+
}
2458+
24252459
}

main/exercise/question_admin.inc.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,13 @@
3535
$typesInformation = Question::get_question_type_list();
3636
$form_title_extra = isset($typesInformation[$type][1]) ? get_lang($typesInformation[$type][1]) : null;
3737

38+
$code = '';
39+
if (isset($objQuestion->code) && !empty($objQuestion->code)) {
40+
$code = ' ('.$objQuestion->code.')';
41+
}
42+
3843
// form title
39-
$form->addHeader($text.': '.$form_title_extra);
44+
$form->addHeader($text.': '.$form_title_extra.$code);
4045

4146
// question form elements
4247
$objQuestion->createForm($form, $objExercise);

0 commit comments

Comments
 (0)