Add question code configuration "allow_question_code" see BT#15232 BT#15230

pull/2790/head
Julio Montoya 7 years ago
parent 38689ebae8
commit ee13775aa7
  1. 20
      main/exercise/export/aiken/aiken_classes.php
  2. 12
      main/exercise/export/aiken/aiken_import.inc.php
  3. 4
      main/install/configuration.dist.php

@ -32,6 +32,26 @@ class Aiken2Question extends Question
return $answer; return $answer;
} }
/**
* @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;
}
public function createAnswersForm($form) public function createAnswersForm($form)
{ {
return true; return true;

@ -191,9 +191,15 @@ function aiken_import_exercise($file)
if (isset($question_array['description'])) { if (isset($question_array['description'])) {
$question->updateDescription($question_array['description']); $question->updateDescription($question_array['description']);
} }
$type = $question->selectType(); $type = $question->selectType();
$question->type = constant($type); $question->type = constant($type);
$question->save($exercise); $question->save($exercise);
if (isset($question_array['code'])) {
$question->addCode($question_array['code']);
}
$last_question_id = $question->selectId(); $last_question_id = $question->selectId();
//3. Create answer //3. Create answer
$answer = new Answer($last_question_id); $answer = new Answer($last_question_id);
@ -297,11 +303,9 @@ function aiken_parse_file(&$exercise_info, $exercisePath, $file, $questionFile)
//weight for correct answer //weight for correct answer
$exercise_info['question'][$question_index]['weighting'][$correct_answer_index] = 1; $exercise_info['question'][$question_index]['weighting'][$correct_answer_index] = 1;
} elseif (preg_match('/^SCORE:\s?(.*)/', $info, $matches)) { } elseif (preg_match('/^SCORE:\s?(.*)/', $info, $matches)) {
//the correct answers
$correct_answer_index = array_search($matches[1], $answers_array);
$exercise_info['question'][$question_index]['score'] = (float) $matches[1]; $exercise_info['question'][$question_index]['score'] = (float) $matches[1];
//weight for correct answer } elseif (preg_match('/^CODE:\s?(.*)/', $info, $matches)) {
//$exercise_info['question'][$question_index]['weighting'][$correct_answer_index] = 1; $exercise_info['question'][$question_index]['code'] = $matches[1];
} elseif (preg_match('/^ANSWER_EXPLANATION:\s?(.*)/', $info, $matches)) { } elseif (preg_match('/^ANSWER_EXPLANATION:\s?(.*)/', $info, $matches)) {
//Comment of correct answer //Comment of correct answer
$correct_answer_index = array_search($matches[1], $answers_array); $correct_answer_index = array_search($matches[1], $answers_array);

@ -1067,6 +1067,10 @@ VALUES (2, 13, 'session_courses_read_only_mode', 'Lock Course In Session', 1, 1,
// Hide social media links // Hide social media links
//$_configuration['hide_social_media_links'] = false; //$_configuration['hide_social_media_links'] = false;
// Allow code field in exercise questions
//ALTER TABLE c_quiz_question ADD COLUMN code VARCHAR(255) NULL DEFAULT NULL;
// $_configuration['allow_question_code'] = false;
// ------ Custom DB changes (keep this at the end) // ------ Custom DB changes (keep this at the end)
// Add user activation by confirmation email // Add user activation by confirmation email
// This option prevents the new user to login in the platform if your account is not confirmed via email // This option prevents the new user to login in the platform if your account is not confirmed via email

Loading…
Cancel
Save