|
@@ -1684,6 +1684,10 @@ abstract class Question
|
|
|
|
|
|
}
|
|
|
|
|
|
+ if (api_get_configuration_value('allow_question_code') && api_is_platform_admin()) {
|
|
|
+ $form->addText('code', get_lang('QuestionCode'));
|
|
|
+ }
|
|
|
+
|
|
|
$form->addElement('html', '</div>');
|
|
|
|
|
|
if (!isset($_GET['fromExercise'])) {
|
|
@@ -1723,6 +1727,10 @@ abstract class Question
|
|
|
$defaults['questionCategory'] = $this->category;
|
|
|
$defaults['feedback'] = $this->feedback;
|
|
|
|
|
|
+ if (api_get_configuration_value('allow_question_code') && api_is_platform_admin()) {
|
|
|
+ $defaults['code'] = $this->code;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
if (isset($_GET['fromExercise'])) {
|
|
|
$form->setDefaults($defaults);
|
|
@@ -1755,6 +1763,10 @@ abstract class Question
|
|
|
if ($this->type != MEDIA_QUESTION) {
|
|
|
$this->save($exercise);
|
|
|
|
|
|
+ if (api_is_platform_admin()) {
|
|
|
+ $this->addCode($form->getSubmitValue('code'));
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
$exercise->addToList($this->id);
|
|
|
$exercise->update_question_positions();
|
|
@@ -2422,4 +2434,26 @@ abstract class Question
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * @param string $code
|
|
|
+ *
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function addCode($code)
|
|
|
+ {
|
|
|
+ if (api_get_configuration_value('allow_question_code') && !empty($this->id)) {
|
|
|
+ $code = Database::escape_string($code);
|
|
|
+ $table = Database::get_course_table(TABLE_QUIZ_QUESTION);
|
|
|
+ $sql = "UPDATE $table SET code = '$code'
|
|
|
+ WHERE iid = {$this->id} AND c_id = {$this->course['real_id']}";
|
|
|
+ Database::query($sql);
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
}
|