Injecting Exercise object inside the answer

skala
Julio Montoya 12 years ago
parent 576207bb99
commit bd7165f071
  1. 2
      main/exercice/admin.php
  2. 19
      main/exercice/answer.class.php
  3. 4
      main/exercice/answer_admin.inc.php
  4. 4
      main/exercice/draggable.class.php

@ -256,7 +256,7 @@ if (!empty($clone_question) && !empty($objExercise->id)) {
$new_question_obj->addToList($exerciseId);
// This should be moved to the duplicate function
$new_answer_obj = new Answer($clone_question);
$new_answer_obj = new Answer($clone_question, null, $objExercise);
$new_answer_obj->read();
$new_answer_obj->duplicate($new_id);

@ -47,8 +47,10 @@ class Answer
*
* @author Olivier Brouckaert
* @param integer Question ID that answers belong to
* @param int course id
* @param \Exercise
*/
public function Answer($questionId, $course_id = null)
public function Answer($questionId, $course_id = null, $exercise = null)
{
$this->questionId = intval($questionId);
$this->answer = array();
@ -72,16 +74,13 @@ class Answer
$this->course = $course_info;
$this->course_id = $course_info['real_id'];
// fills arrays
$objExercise = new Exercise($this->course_id);
$exerciseId = isset($_REQUEST['exerciseId']) ? $_REQUEST['exerciseId'] : null;
if ($exerciseId) {
$objExercise->read($exerciseId);
if ($objExercise->random_answers == '1') {
$this->readOrderedBy('rand()', ''); // randomize answers
if (isset($exercise)) {
if ($exercise->random_answers == '1') {
// Randomize answers.
$this->readOrderedBy('rand()', '');
} else {
$this->read(); // natural order
// Normal order
$this->read();
}
} else {
$this->read();

@ -55,7 +55,7 @@ if ($modifyIn) {
// construction of the duplicated Answers
$objAnswer = new Answer($questionId);
$objAnswer = new Answer($questionId, null, $objExercise);
}
if ($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER || $answerType == MULTIPLE_ANSWER_COMBINATION || $answerType == GLOBAL_MULTIPLE_ANSWER) {
$correct = unserialize($correct);
@ -510,7 +510,7 @@ if ($modifyAnswers) {
}
// construction of the Answer object
$objAnswer = new Answer($questionId);
$objAnswer = new Answer($questionId, null, $objExercise);
Session::write('objAnswer', $objAnswer);
if ($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER || $answerType == GLOBAL_MULTIPLE_ANSWER) {

@ -33,7 +33,7 @@ class Draggable extends Matching
}
/**
* function which redifines Question::createAnswersForm
* Function which redefines Question::createAnswersForm
* @param the formvalidator instance
*/
public function createAnswersForm($form)
@ -60,7 +60,7 @@ class Draggable extends Matching
} else {
if (!empty($this->id)) {
$answer = new Answer($this->id);
$answer = new Answer($this->id, api_get_course_int_id());
$answer->read();
if (count($answer->nbrAnswers) > 0) {
$nb_matches = $nb_options = 0;

Loading…
Cancel
Save