diff --git a/main/exercice/exercise.class.php b/main/exercice/exercise.class.php
index dbf53f1d72..6b95fb623d 100644
--- a/main/exercice/exercise.class.php
+++ b/main/exercice/exercise.class.php
@@ -3387,12 +3387,12 @@ class Exercise {
';
$open_question_list = null;
-
- $msg = str_replace("#email#", $user_info['email'],$msg);
+
+ $msg = str_replace("#email#", $user_info['email'],$msg);
$msg1 = str_replace("#exercise#", $this->exercise, $msg);
$msg = str_replace("#firstName#", $user_info['firstname'],$msg1);
$msg1 = str_replace("#lastName#", $user_info['lastname'],$msg);
-
+
$msg = str_replace("#course#", $courseInfo['name'],$msg1);
if ($origin != 'learnpath') {
@@ -3402,20 +3402,20 @@ class Exercise {
$msg1 = str_replace("#url#", $url_email, $msg);
$mail_content = $msg1;
$subject = get_lang('ExerciseAttempted');
-
+
$teachers = array();
if (api_get_session_id()) {
$teachers = CourseManager::get_coach_list_from_course_code($coursecode, api_get_session_id());
} else {
$teachers = CourseManager::get_teacher_list_from_course_code($coursecode);
}
-
+
if (!empty($teachers)) {
foreach ($teachers as $user_id => $teacher_data) {
MessageManager::send_message_simple($user_id, $subject, $mail_content);
}
}
-
+
}
/**
@@ -3628,22 +3628,35 @@ class Exercise {
* @todo this was function was added due the import exercise via CSV
* @return int New exercise ID
*/
- function create_quiz ($title, $expired_time = 0, $type = 2, $random = 0, $active = 1, $results_disabled = 0, $max_attempt = 0, $feedback = 3) {
+ public function createExercise(
+ $title,
+ $expired_time = 0,
+ $type = 2,
+ $random = 0,
+ $active = 1,
+ $results_disabled = 0,
+ $max_attempt = 0,
+ $feedback = 3,
+ $propagateNegative = 0
+ ) {
$tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
- $expired_time = filter_var($expired_time,FILTER_SANITIZE_NUMBER_INT);
- $type = filter_var($type,FILTER_SANITIZE_NUMBER_INT);
- $random = filter_var($random,FILTER_SANITIZE_NUMBER_INT);
- $active = filter_var($active,FILTER_SANITIZE_NUMBER_INT);
- $results_disabled = filter_var($results_disabled,FILTER_SANITIZE_NUMBER_INT);
- $max_attempt = filter_var($max_attempt,FILTER_SANITIZE_NUMBER_INT);
- $feedback = filter_var($feedback,FILTER_SANITIZE_NUMBER_INT);
- $sid = api_get_session_id();
+ $type = intval($type);
+ $random = intval($random);
+ $active = intval($active);
+ $results_disabled = intval($results_disabled);
+ $max_attempt = intval($max_attempt);
+ $feedback = intval($feedback);
+ $expired_time = intval($expired_time);
+ $title = Database::escape_string($title);
+ $propagateNegative = intval($propagateNegative);
+ $sessionId = api_get_session_id();
$course_id = api_get_course_int_id();
// Save a new quiz
- $sql = "INSERT INTO $tbl_quiz (c_id, title,type,random,active,results_disabled, max_attempt,start_time,end_time,feedback_type,expired_time, session_id) ".
- " VALUES('$course_id', '".Database::escape_string($title)."',$type,$random,$active, $results_disabled,$max_attempt,'','',$feedback,$expired_time,$sid)";
- $rs = Database::query($sql);
- $quiz_id = Database::get_last_insert_id();
+ $sql = "INSERT INTO $tbl_quiz (c_id, title, type, random, active, results_disabled, max_attempt, start_time,end_time,feedback_type,expired_time, session_id, propagate_neg) ".
+ " VALUES('$course_id', '".$title."', $type, $random, $active, $results_disabled, $max_attempt,'','', $feedback, $expired_time, $sessionId, $propagateNegative)";
+ Database::query($sql);
+ $quiz_id = Database::insert_id();
+
return $quiz_id;
}
@@ -3660,15 +3673,26 @@ class Exercise {
public function get_exercise_result($exe_id) {
$result = array();
$track_exercise_info = get_exercise_track_exercise_info($exe_id);
+
if (!empty($track_exercise_info)) {
+ $totalScore = 0;
$objExercise = new Exercise();
$objExercise->read($track_exercise_info['exe_exo_id']);
if (!empty($track_exercise_info['data_tracking'])) {
$question_list = explode(',', $track_exercise_info['data_tracking']);
}
foreach ($question_list as $questionId) {
- $question_result = $objExercise->manage_answer($exe_id, $questionId, '','exercise_show', array(), false, true, false, $objExercise->selectPropagateNeg());
- $questionScore = $question_result['score'];
+ $question_result = $objExercise->manage_answer(
+ $exe_id,
+ $questionId,
+ '',
+ 'exercise_show',
+ array(),
+ false,
+ true,
+ false,
+ $objExercise->selectPropagateNeg()
+ );
$totalScore += $question_result['score'];
}
diff --git a/main/exercice/unique_answer.class.php b/main/exercice/unique_answer.class.php
index b6050b0fc1..9c69e0cf64 100644
--- a/main/exercice/unique_answer.class.php
+++ b/main/exercice/unique_answer.class.php
@@ -10,8 +10,6 @@
* Code
*/
-if(!class_exists('UniqueAnswer')):
-
/**
CLASS UNIQUE_ANSWER
*
@@ -23,15 +21,16 @@ if(!class_exists('UniqueAnswer')):
* @package chamilo.exercise
**/
-class UniqueAnswer extends Question {
-
+class UniqueAnswer extends Question
+{
static $typePicture = 'mcua.gif';
static $explanationLangVar = 'UniqueSelect';
/**
* Constructor
*/
- function UniqueAnswer() {
+ function UniqueAnswer()
+ {
//this is highly important
parent::question();
$this -> type = UNIQUE_ANSWER;
@@ -39,11 +38,12 @@ class UniqueAnswer extends Question {
}
/**
- * function which redifines Question::createAnswersForm
+ * function which redefines Question::createAnswersForm
* @param the formvalidator instance
* @param the answers number to display
*/
- function createAnswersForm ($form) {
+ function createAnswersForm ($form)
+ {
// Getting the exercise list
$obj_ex = $_SESSION['objExercise'];
@@ -89,11 +89,11 @@ class UniqueAnswer extends Question {
'.$feedback_title.'
'.get_lang('Weighting').'
- |
+
';
$form -> addElement ('label', get_lang('Answers').'
', $html);
-
+
$defaults = array();
$correct = 0;
if(!empty($this -> id)) {
@@ -110,7 +110,7 @@ class UniqueAnswer extends Question {
$select_question=array();
$select_question[0] = get_lang('SelectTargetQuestion');
- require_once '../newscorm/learnpathList.class.php';
+ require_once '../newscorm/learnpathList.class.php';
if (is_array($question_list)) {
foreach ($question_list as $key=>$questionid) {
//To avoid warning messages
@@ -133,14 +133,14 @@ class UniqueAnswer extends Question {
}
$temp_scenario = array();
-
+
if ($nb_answers < 1) {
$nb_answers = 1;
Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
- }
+ }
for ($i = 1 ; $i <= $nb_answers ; ++$i) {
- $form -> addElement ('html', '');
+ $form -> addElement ('html', '
');
if (isset($answer) && is_object($answer)) {
if ($answer -> correct[$i]) {
$correct = $i;
@@ -183,67 +183,67 @@ class UniqueAnswer extends Question {
$defaults['scenario'] = $temp_scenario;
$renderer = $form->defaultRenderer();
-
- $renderer->setElementTemplate('{error} {element} | ', 'correct');
- $renderer->setElementTemplate('{error} {element} | ', 'counter['.$i.']');
- $renderer->setElementTemplate('{error} {element} | ', 'answer['.$i.']');
+
+ $renderer->setElementTemplate('{error} {element} | ', 'correct');
+ $renderer->setElementTemplate('{error} {element} | ', 'counter['.$i.']');
+ $renderer->setElementTemplate('{error} {element} | ', 'answer['.$i.']');
$renderer->setElementTemplate('{error} {element} | ', 'comment['.$i.']');
- $renderer->setElementTemplate('{error} {element} | ', 'weighting['.$i.']');
-
+ $renderer->setElementTemplate('{error} {element} | ', 'weighting['.$i.']');
+
$answer_number = $form->addElement('text', 'counter['.$i.']',null,' value = "'.$i.'"');
$answer_number->freeze();
$form->addElement('radio', 'correct', null, null, $i, 'class="checkbox" style="margin-left: 0em;"');
$form->addElement('html_editor', 'answer['.$i.']', null, 'style="vertical-align:middle"', $editor_config);
-
+
$form->addRule('answer['.$i.']', get_lang('ThisFieldIsRequired'), 'required');
if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
$form->addElement('html_editor', 'comment['.$i.']', null, 'style="vertical-align:middle"', $editor_config);
// Direct feedback
-
+
//Adding extra feedback fields
$group = array();
$group['try'.$i] = $form->createElement('checkbox', 'try'.$i, null , get_lang('TryAgain'));
$group['lp'.$i] = $form->createElement('select', 'lp'.$i, get_lang('SeeTheory').': ', $select_lp_id);
$group['destination'.$i]= $form->createElement('select', 'destination'.$i, get_lang('GoToQuestion').': ' , $select_question);
$group['url'.$i] = $form->createElement('text', 'url'.$i, get_lang('Other').': ', array('class'=>'span2', 'placeholder' => get_lang('Other')));
- $form->addGroup($group, 'scenario');
-
- $renderer->setElementTemplate('{error} {element}', 'scenario');
-
+ $form->addGroup($group, 'scenario');
+
+ $renderer->setElementTemplate(' | {error} {element}', 'scenario');
+
}
else {
$form->addElement('html_editor', 'comment['.$i.']', null, 'style="vertical-align:middle"', $editor_config);
}
- $form->addElement('text', 'weighting['.$i.']', null, array('class' => "span1", 'value' => '0'));
- $form->addElement ('html', ' |
');
+ $form->addElement('text', 'weighting['.$i.']', null, array('class' => "span1", 'value' => '0'));
+ $form->addElement ('html', '');
}
$form -> addElement ('html', '');
- $form -> addElement ('html', '
');
-
+ $form -> addElement ('html', '
');
+
$navigator_info = api_get_navigator();
global $text, $class;
-
+
//ie6 fix
if ($obj_ex->edit_exercise_in_lp == true) {
- if ($navigator_info['name']=='Internet Explorer' && $navigator_info['version']=='6') {
+ if ($navigator_info['name']=='Internet Explorer' && $navigator_info['version']=='6') {
$form->addElement('submit', 'lessAnswers', get_lang('LessAnswer'),'class="btn minus"');
- $form->addElement('submit', 'moreAnswers', get_lang('PlusAnswer'),'class="btn plus"');
+ $form->addElement('submit', 'moreAnswers', get_lang('PlusAnswer'),'class="btn plus"');
$form->addElement('submit','submitQuestion',$text, 'class="'.$class.'"');
} else {
- //setting the save button here and not in the question class.php
+ //setting the save button here and not in the question class.php
$form->addElement('style_submit_button', 'lessAnswers', get_lang('LessAnswer'),'class="btn minus"');
- $form->addElement('style_submit_button', 'moreAnswers', get_lang('PlusAnswer'),'class="btn plus"');
- $form->addElement('style_submit_button', 'submitQuestion',$text, 'class="'.$class.'"');
+ $form->addElement('style_submit_button', 'moreAnswers', get_lang('PlusAnswer'),'class="btn plus"');
+ $form->addElement('style_submit_button', 'submitQuestion',$text, 'class="'.$class.'"');
}
}
$renderer->setElementTemplate('{element} ','submitQuestion');
$renderer->setElementTemplate('{element} ','lessAnswers');
$renderer->setElementTemplate('{element} ','moreAnswers');
-
+
$form->addElement('html', '');
//We check the first radio button to be sure a radio button will be check
@@ -265,13 +265,13 @@ class UniqueAnswer extends Question {
/**
* abstract function which creates the form to create / edit the answers of the question
- * @param the formvalidator instance
+ * @param FormValidator $form
* @param the answers number to display
*/
- function processAnswersCreation($form) {
-
+ function processAnswersCreation($form)
+ {
$questionWeighting = $nbrGoodAnswers = 0;
- $correct = $form -> getSubmitValue('correct');
+ $correct = $form->getSubmitValue('correct');
$objAnswer = new Answer($this->id);
$nb_answers = $form->getSubmitValue('nb_answers');
@@ -281,11 +281,11 @@ class UniqueAnswer extends Question {
$weighting = trim($form -> getSubmitValue('weighting['.$i.']'));
$scenario = $form -> getSubmitValue('scenario');
-
+
//$list_destination = $form -> getSubmitValue('destination'.$i);
//$destination_str = $form -> getSubmitValue('destination'.$i);
- $try = $scenario['try'.$i];
+ $try = $scenario['try'.$i];
$lp = $scenario['lp'.$i];
$destination = $scenario['destination'.$i];
$url = trim($scenario['url'.$i]);
@@ -302,7 +302,7 @@ class UniqueAnswer extends Question {
lp_id = id of a learning path (0 if dont select)
selected_questions= ids of questions
url= an url
-
+
$destination_str='';
foreach ($list_destination as $destination_id)
{
@@ -330,16 +330,16 @@ class UniqueAnswer extends Question {
if (empty($destination)) {
$destination=0;
}
-
+
if ($url=='') {
$url=0;
}
//1@@1;2;@@2;4;4;@@http://www.chamilo.org
- $dest = $try.'@@'.$lp.'@@'.$destination.'@@'.$url;
+ $dest = $try.'@@'.$lp.'@@'.$destination.'@@'.$url;
$objAnswer->createAnswer($answer, $goodAnswer, $comment, $weighting, $i, null, null, $dest);
}
-
+
// saves the answers into the data base
$objAnswer->save();
@@ -347,45 +347,57 @@ class UniqueAnswer extends Question {
$this->updateWeighting($questionWeighting);
$this->save();
}
-
- function return_header($feedback_type = null, $counter = null, $score = null) {
+
+ function return_header($feedback_type = null, $counter = null, $score = null)
+ {
$header = parent::return_header($feedback_type, $counter, $score);
- $header .= '
+ $header .= '
| '.get_lang("Choice").' |
'. get_lang("ExpectedChoice").' |
- '. get_lang("Answer").' | ';
+ '. get_lang("Answer").' | ';
$header .= ''.get_lang("Comment").' | ';
$header .= '
';
- return $header;
+
+ return $header;
}
-
- function create_answer($id, $question_id, $answer_title, $comment, $score = 0, $correct = 0) {
- $tbl_quiz_answer = Database::get_course_table(TABLE_QUIZ_ANSWER);
- $tbl_quiz_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
- $course_id = api_get_course_int_id();
- $position = 1;
- $question_id = filter_var($question_id,FILTER_SANITIZE_NUMBER_INT);
- $score = filter_var($score,FILTER_SANITIZE_NUMBER_FLOAT);
- $correct = filter_var($correct,FILTER_SANITIZE_NUMBER_INT);
- // Get the max position
- $sql = "SELECT max(position) as max_position FROM $tbl_quiz_answer "
- ." WHERE c_id = $course_id AND question_id = $question_id";
- $rs_max = Database::query($sql);
- $row_max = Database::fetch_object($rs_max);
- $position = $row_max->max_position + 1;
- // Insert a new answer
- $sql = "INSERT INTO $tbl_quiz_answer "
- ."(c_id, id, question_id,answer,correct,comment,ponderation,position,destination)"
- ."VALUES ($course_id, $id,$question_id,'".Database::escape_string($answer_title)."',"
- ."$correct,'".Database::escape_string($comment)."',$score,$position, "
- ." '0@@0@@0@@0')";
- $rs = Database::query($sql);
- if ($correct) {
- $sql = "UPDATE $tbl_quiz_question "
- ." SET ponderation = (ponderation + $score) WHERE c_id = $course_id AND id = ".$question_id;
- $rs = Database::query($sql);
+
+ /**
+ * @param int $id
+ * @param int $question_id
+ * @param string $title
+ * @param string $comment
+ * @param float $score
+ * @param int $correct
+ */
+ function addAnswer($id, $question_id, $title, $comment, $score = 0, $correct = 0)
+ {
+ $tbl_quiz_answer = Database::get_course_table(TABLE_QUIZ_ANSWER);
+ $tbl_quiz_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
+ $course_id = api_get_course_int_id();
+ $question_id = intval($question_id);
+ $score = floatval($score);
+ $correct = intval($correct);
+ $title = Database::escape_string($title);
+ $comment = Database::escape_string($comment);
+ // Get the max position.
+ $sql = "SELECT max(position) as max_position
+ FROM $tbl_quiz_answer
+ WHERE
+ c_id = $course_id AND
+ question_id = $question_id";
+ $rs_max = Database::query($sql);
+ $row_max = Database::fetch_object($rs_max);
+ $position = $row_max->max_position + 1;
+ // Insert a new answer
+ $sql = "INSERT INTO $tbl_quiz_answer (c_id, id, question_id,answer,correct,comment,ponderation,position,destination)
+ VALUES ($course_id, $id, $question_id, '".$title."', $correct, '".$comment."', '$score', $position, '0@@0@@0@@0')";
+ Database::query($sql);
+ if ($correct) {
+ $sql = "UPDATE $tbl_quiz_question
+ SET ponderation = (ponderation + $score)
+ WHERE c_id = $course_id AND id = ".$question_id;
+ Database::query($sql);
+ }
}
- }
}
-endif;
diff --git a/main/exercice/upload_exercise.php b/main/exercice/upload_exercise.php
index 924cad9878..6c724e8bca 100644
--- a/main/exercice/upload_exercise.php
+++ b/main/exercice/upload_exercise.php
@@ -32,13 +32,13 @@ $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
if (!$is_allowed_to_edit) {
api_not_allowed(true);
}
-
// setting the tabs
$this_section = SECTION_COURSES;
-$htmlHeadXtra[] = "";
@@ -48,41 +48,34 @@ lp_upload_quiz_action_handling();
$interbreadcrumb[]= array ("url"=>"exercice.php", "name"=> get_lang('Exercices'));
// Display the header
-if ($origin != 'learnpath') {
- //so we are not in learnpath tool
- Display :: display_header(get_lang('ImportExcelQuiz'), 'Exercises');
- if (isset ($_GET['message'])) {
- if (in_array($_GET['message'], array ('ExerciseEdited'))) {
- Display :: display_confirmation_message(get_lang($_GET['message']));
- }
+
+Display :: display_header(get_lang('ImportExcelQuiz'), 'Exercises');
+
+if (isset($_GET['message'])) {
+ if (in_array($_GET['message'], array('ExerciseEdited'))) {
+ Display :: display_confirmation_message(get_lang($_GET['message']));
}
-} else {
- echo '';
}
+
// display the actions
echo '';
echo lp_upload_quiz_actions();
echo '
';
-// start the content div
-echo '';
// the main content
lp_upload_quiz_main();
-// close the content div
-echo '
';
-
function lp_upload_quiz_actions() {
- $lp_id = Security::remove_XSS($_GET['lp_id']);
- $return = "";
- $return .= ''.Display::return_icon('back.png', get_lang('BackToExercisesList'),'',ICON_SIZE_MEDIUM).'';
+ $return = ''.
+ Display::return_icon('back.png', get_lang('BackToExercisesList'),'',ICON_SIZE_MEDIUM).'';
return $return;
}
function lp_upload_quiz_secondary_actions() {
$lp_id = Security::remove_XSS($_GET['lp_id']);
$return = '';
- $return.='' . Display :: return_icon('reporting32.png', get_lang('Tracking')) . get_lang('Tracking') . '';
+ $return .= '' .
+ Display :: return_icon('reporting32.png', get_lang('Tracking')) . get_lang('Tracking') . '';
return $return;
}
@@ -91,15 +84,24 @@ function lp_upload_quiz_main() {
// variable initialisation
$lp_id = Security::remove_XSS($_GET['lp_id']);
- $form = new FormValidator('upload', 'POST', api_get_self() . '?' . api_get_cidreq() . '&lp_id=' . $lp_id, '', array('enctype' => 'multipart/form-data'));
+ $form = new FormValidator('upload', 'POST', api_get_self() . '?' . api_get_cidreq() . '&lp_id='.$lp_id, '', array('enctype' => 'multipart/form-data'));
$form->addElement('header', get_lang('ImportExcelQuiz'));
$form->addElement('file', 'user_upload_quiz', get_lang('FileUpload'));
- $link = ''.Display::return_icon('export_excel.png', get_lang('DownloadExcelTemplate'),null,16).get_lang('DownloadExcelTemplate');
-
+ $link = ''.
+ Display::return_icon('export_excel.png', get_lang('DownloadExcelTemplate')).get_lang('DownloadExcelTemplate').'';
$form->addElement('advanced_settings', $link);
- //button send document
+ $form->addElement('checkbox', 'user_custom_score', null, get_lang('UseCustomScoreForAllQuestions'), array('id'=> 'user_custom_score'));
+
+ $form->addElement('html', '');
+ $form->addElement('text', 'correct_score', get_lang('CorrectScore'));
+ $form->addElement('text', 'incorrect_score', get_lang('IncorrectScore'));
+ $form->addElement('html', '
');
+
+ $form->addRule('user_upload_quiz', get_lang('ThisFieldIsRequired'), 'required');
+
+ $form->add_progress_bar();
$form->addElement('style_submit_button', 'submit_upload_quiz', get_lang('Send'), 'class="upload"');
// Display the upload field
@@ -110,16 +112,21 @@ function lp_upload_quiz_main() {
* Handles a given Excel spreadsheets as in the template provided
*/
function lp_upload_quiz_action_handling() {
- global $_course, $debug;
+ global $debug;
+ $_course = api_get_course_info();
+
if (!isset($_POST['submit_upload_quiz'])) {
return;
}
+
// Get the extension of the document.
$path_info = pathinfo($_FILES['user_upload_quiz']['name']);
+
// Check if the document is an Excel document
if ($path_info['extension'] != 'xls') {
return;
}
+
// Read the Excel document
$data = new Spreadsheet_Excel_Reader();
// Set output Encoding.
@@ -127,6 +134,17 @@ function lp_upload_quiz_action_handling() {
// Reading the xls document.
$data->read($_FILES['user_upload_quiz']['tmp_name']);
+ $correctScore = isset($_POST['correct_score']) ? $_POST['correct_score'] : null;
+ $incorrectScore = isset($_POST['incorrect_score']) ? $_POST['incorrect_score'] : null;
+ $useCustomScore = isset($_POST['user_custom_score']) ? true : false;
+
+ $propagateNegative = 0;
+ if ($useCustomScore && !empty($incorrectScore)) {
+ if ($incorrectScore < 0) {
+ $propagateNegative = 1;
+ }
+ }
+
// Variables
$quiz_index = 0;
$question_title_index = array();
@@ -137,7 +155,7 @@ function lp_upload_quiz_action_handling() {
$feedback_false_index = array();
$number_questions = 0;
$question_description_index = array();
- // Reading all the first column items sequencially to create breakpoints
+ // Reading all the first column items sequentially to create breakpoints
for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
if ($data->sheets[0]['cells'][$i][1] == 'Quiz' && $i == 1) {
$quiz_index = $i; // Quiz title position, only occurs once
@@ -155,18 +173,18 @@ function lp_upload_quiz_action_handling() {
} elseif ($data->sheets[0]['cells'][$i][1] == 'EnrichQuestion') {
$question_description_index[] = $i;
}
-
}
+
// Variables
$quiz = array();
$question = array();
- $answer = array();
$new_answer = array();
$score_list = array();
$feedback_true_list = array();
$feedback_false_list = array();
$question_description = array();
- // Get questions
+
+ // Getting questions.
$k = $z = $q = $l = $m = 0;
for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
if (is_array($data->sheets[0]['cells'][$i])) {
@@ -183,22 +201,28 @@ function lp_upload_quiz_action_handling() {
$column_data = '';
}
// Fill quiz data
- if ($quiz_index == $i) { // The title always in the first position
+ if ($quiz_index == $i) {
+ // The title always in the first position
$quiz = $column_data;
} elseif (in_array($i, $question_title_index)) {
- $question[$k] = $column_data; //a complete line where 1st column is 'Question'
+ //a complete line where 1st column is 'Question'
+ $question[$k] = $column_data;
$k++;
} elseif (in_array($i, $score_index)) {
- $score_list[$z] = $column_data; //a complete line where 1st column is 'Score'
+ //a complete line where 1st column is 'Score'
+ $score_list[$z] = $column_data;
$z++;
} elseif (in_array($i, $feedback_true_index)) {
- $feedback_true_list[$q] = $column_data;//a complete line where 1st column is 'FeedbackTrue'
+ //a complete line where 1st column is 'FeedbackTrue'
+ $feedback_true_list[$q] = $column_data;
$q++;
} elseif (in_array($i, $feedback_false_index)) {
- $feedback_false_list[$l] = $column_data;//a complete line where 1st column is 'FeedbackFalse' for wrong answers
+ //a complete line where 1st column is 'FeedbackFalse' for wrong answers
+ $feedback_false_list[$l] = $column_data;
$l++;
} elseif (in_array($i, $question_description_index)) {
- $question_description[$m] = $column_data; //a complete line where 1st column is 'EnrichQuestion'
+ //a complete line where 1st column is 'EnrichQuestion'
+ $question_description[$m] = $column_data;
$m++;
}
}
@@ -223,49 +247,67 @@ function lp_upload_quiz_action_handling() {
}
}
- $quiz_title = $quiz[2]; // Quiz title
+ // Quiz title.
+ $quiz_title = $quiz[2];
if ($quiz_title != '') {
// Variables
$type = 2;
$random = $active = $results = $max_attempt = $expired_time = 0;
- //make sure feedback is enabled (3 to disable), otherwise the fields
+ // Make sure feedback is enabled (3 to disable), otherwise the fields
// added to the XLS are not shown, which is confusing
$feedback = 0;
+
// Quiz object
- $quiz_object = new Exercise();
- $quiz_id = $quiz_object->create_quiz($quiz_title, $expired_time, $type, $random, $active, $results, $max_attempt, $feedback);
+ $exercise = new Exercise();
+ //
+ $quiz_id = $exercise->createExercise(
+ $quiz_title,
+ $expired_time,
+ $type,
+ $random,
+ $active,
+ $results,
+ $max_attempt,
+ $feedback,
+ $propagateNegative
+ );
if ($quiz_id) {
// insert into the item_property table
api_item_property_update($_course, TOOL_QUIZ, $quiz_id, 'QuizAdded', api_get_user_id());
- // Import questions
+ // Import questions.
for ($i = 0; $i < $number_questions; $i++) {
- // Create questions
-
-
- $question_title = $question[$i][2]; // Question name
+ // Question name
+ $question_title = $question[$i][2];
$question_description_text = "";
if (isset($question_description[$i][2])) {
- $question_description_text = "".$question_description[$i][2]."
"; // Question description, if any
+ // Question description.
+ $question_description_text = "".$question_description[$i][2]."
";
}
// Unique answers are the only question types available for now
// through xls-format import
- $unique_answer = new UniqueAnswer();
+ $uniqueAnswer = new UniqueAnswer();
if ($question_title != '') {
- $question_id = $unique_answer->create_question($quiz_id, $question_title, $question_description_text);
+ $question_id = $uniqueAnswer->create_question(
+ $quiz_id,
+ $question_title,
+ $question_description_text
+ );
}
+
if (is_array($new_answer[$i])) {
$id = 1;
$answers_data = $new_answer[$i];
+
foreach ($answers_data as $answer_data) {
$answer = $answer_data[2];
$correct = 0;
$score = 0;
- $comment = '';
+
if (strtolower($answer_data[3]) == 'x') {
$correct = 1;
$score = $score_list[$i][3];
@@ -273,15 +315,25 @@ function lp_upload_quiz_action_handling() {
} else {
$comment = $feedback_false_list[$i][2];
}
- /*
- if ($id == 1) {
- $comment = $feedback_true_list[$i][2];
- } elseif ($id == 2) {
- $comment = $feedback_false_list[$i][2];
+
+ if ($useCustomScore) {
+ if ($correct) {
+ $score = $correctScore;
+ } else {
+ $score = $incorrectScore;
+ }
}
- */
- // Create answer
- $unique_answer->create_answer($id, $question_id, $answer, $comment, $score, $correct);
+
+ // Add answer.
+ $uniqueAnswer->addAnswer(
+ $id,
+ $question_id,
+ $answer,
+ $comment,
+ $score,
+ $correct
+ );
+
$id++;
}
}
@@ -306,22 +358,21 @@ function lp_upload_quiz_action_handling() {
Session::erase('lpobject');
} else {
$_SESSION['oLP'] = $oLP;
- $lp_found = true;
}
}
}
- if (isset($_SESSION['oLP']) && isset($_GET['lp_id'])) {
+ if (isset($_SESSION['oLP']) && isset($_GET['lp_id'])) {
$previous = $_SESSION['oLP']->select_previous_item_id();
$parent = 0;
// Add a Quiz as Lp Item
- $_SESSION['oLP']->add_item($parent, $previous, TOOL_QUIZ, $quiz_id, ($quiz_title), '');
+ $_SESSION['oLP']->add_item($parent, $previous, TOOL_QUIZ, $quiz_id, $quiz_title, '');
// Redirect to home page for add more content
- header('location: ../newscorm/lp_controller.php?' . api_get_cidreq() . '&action=add_item&type=step&lp_id=' . Security::remove_XSS($_GET['lp_id']).'&session_id='.api_get_session_id());
+ header('location: ../newscorm/lp_controller.php?'.api_get_cidreq().'&action=add_item&type=step&lp_id='.Security::remove_XSS($_GET['lp_id']));
exit;
} else {
// header('location: exercice.php?' . api_get_cidreq());
- echo '';
+ echo '';
}
}
}