Minor - cosmetic changes

skala
Julio Montoya 12 years ago
parent 6815f0d9c2
commit cc33865c9e
  1. 409
      main/exercice/question.class.php
  2. 124
      main/exercice/question_admin.inc.php
  3. 616
      main/exercice/unique_answer.class.php

@ -1,11 +1,11 @@
<?php
/* For licensing terms, see /license.txt */
/**
* File containing the Question class.
* File containing the Question class.
* @package chamilo.exercise
* @author Olivier Brouckaert
* @author Julio Montoya <gugli100@gmail.com> lot of bug fixes
* Modified by hubert.borderiou@grenet.fr - add question categories
* Modified by hubert.borderiou@grenet.fr - add question categories
*/
/**
* Code
@ -67,25 +67,22 @@ abstract class Question
public $editionMode = 'normal';
static $questionTypes = array(
UNIQUE_ANSWER => array('unique_answer.class.php', 'UniqueAnswer'),
MULTIPLE_ANSWER => array('multiple_answer.class.php', 'MultipleAnswer'),
FILL_IN_BLANKS => array('fill_blanks.class.php', 'FillBlanks'),
MATCHING => array('matching.class.php', 'Matching'),
FREE_ANSWER => array('freeanswer.class.php', 'FreeAnswer'),
ORAL_EXPRESSION => array('oral_expression.class.php', 'OralExpression'),
HOT_SPOT => array('hotspot.class.php', 'HotSpot'),
HOT_SPOT_DELINEATION => array('hotspot.class.php', 'HotspotDelineation'),
MULTIPLE_ANSWER_COMBINATION => array('multiple_answer_combination.class.php', 'MultipleAnswerCombination'),
UNIQUE_ANSWER_NO_OPTION => array('unique_answer_no_option.class.php', 'UniqueAnswerNoOption'),
MULTIPLE_ANSWER_TRUE_FALSE => array('multiple_answer_true_false.class.php', 'MultipleAnswerTrueFalse'),
MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE => array(
'multiple_answer_combination_true_false.class.php',
'MultipleAnswerCombinationTrueFalse'
),
GLOBAL_MULTIPLE_ANSWER => array('global_multiple_answer.class.php', 'GlobalMultipleAnswer'),
MEDIA_QUESTION => array('media_question.class.php', 'MediaQuestion'),
UNIQUE_ANSWER_IMAGE => array('unique_answer_image.class.php', 'UniqueAnswerImage'),
DRAGGABLE => array('draggable.class.php', 'Draggable')
UNIQUE_ANSWER => array('unique_answer.class.php', 'UniqueAnswer'),
MULTIPLE_ANSWER => array('multiple_answer.class.php', 'MultipleAnswer'),
FILL_IN_BLANKS => array('fill_blanks.class.php', 'FillBlanks'),
MATCHING => array('matching.class.php', 'Matching'),
FREE_ANSWER => array('freeanswer.class.php', 'FreeAnswer'),
ORAL_EXPRESSION => array('oral_expression.class.php', 'OralExpression'),
HOT_SPOT => array('hotspot.class.php', 'HotSpot'),
HOT_SPOT_DELINEATION => array('hotspot.class.php', 'HotspotDelineation'),
MULTIPLE_ANSWER_COMBINATION => array('multiple_answer_combination.class.php', 'MultipleAnswerCombination' ),
UNIQUE_ANSWER_NO_OPTION => array('unique_answer_no_option.class.php', 'UniqueAnswerNoOption'),
MULTIPLE_ANSWER_TRUE_FALSE => array('multiple_answer_true_false.class.php', 'MultipleAnswerTrueFalse'),
MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE => array('multiple_answer_combination_true_false.class.php', 'MultipleAnswerCombinationTrueFalse'),
GLOBAL_MULTIPLE_ANSWER => array('global_multiple_answer.class.php', 'GlobalMultipleAnswer'),
MEDIA_QUESTION => array('media_question.class.php', 'MediaQuestion'),
UNIQUE_ANSWER_IMAGE => array('unique_answer_image.class.php', 'UniqueAnswerImage'),
DRAGGABLE => array('draggable.class.php', 'Draggable')
);
/**
@ -95,19 +92,19 @@ abstract class Question
*/
public function Question()
{
$this->id = 0;
$this->question = '';
$this->description = '';
$this->weighting = 0;
$this->position = 1;
$this->picture = '';
$this->level = 1;
$this->extra = ''; // This variable is used when loading an exercise like an scenario with an special hotspot: final_overlap, final_missing, final_excess
$this->exerciseList = array();
$this->course = api_get_course_info();
$this->id = 0;
$this->question = '';
$this->description = '';
$this->weighting = 0;
$this->position = 1;
$this->picture = '';
$this->level = 1;
$this->extra = ''; // This variable is used when loading an exercise like an scenario with an special hotspot: final_overlap, final_missing, final_excess
$this->exerciseList = array();
$this->course = api_get_course_info();
$this->category_list = array();
$this->parent_id = 0;
$this->editionMode = 'normal';
$this->parent_id = 0;
$this->editionMode = 'normal';
}
public function getIsContent()
@ -122,10 +119,11 @@ abstract class Question
/**
* @param string $title
* @param int $course_id
* @param int $course_id
* @return mixed|bool
*/
public function readByTitle($title, $course_id = null) {
public function readByTitle($title, $course_id = null)
{
if (!empty($course_id)) {
$course_info = api_get_course_info_by_id($course_id);
} else {
@ -134,13 +132,15 @@ abstract class Question
$course_id = $course_info['real_id'];
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$title = Database::escape_string($title);
$sql = "SELECT iid FROM $TBL_QUESTIONS WHERE question = '$title' AND c_id = $course_id ";
$result = Database::query($sql);
$title = Database::escape_string($title);
$sql = "SELECT iid FROM $TBL_QUESTIONS WHERE question = '$title' AND c_id = $course_id ";
$result = Database::query($sql);
if (Database::num_rows($result)) {
$row = Database::fetch_array($result);
return self::read($row['iid'], $course_id);
}
return false;
}
@ -167,7 +167,7 @@ abstract class Question
return false;
}
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$sql = "SELECT * FROM $TBL_QUESTIONS WHERE iid = $id AND c_id = $course_id";
@ -180,20 +180,20 @@ abstract class Question
$objQuestion = Question::getInstance($object->type);
if (!empty($objQuestion)) {
$objQuestion->id = $id;
$objQuestion->question = $object->question;
$objQuestion->description = $object->description;
$objQuestion->weighting = $object->ponderation;
$objQuestion->position = $object->position;
$objQuestion->type = $object->type;
$objQuestion->picture = $object->picture;
$objQuestion->level = (int)$object->level;
$objQuestion->extra = $object->extra;
$objQuestion->course = $course_info;
$objQuestion->parent_id = $object->parent_id;
$objQuestion->id = $id;
$objQuestion->question = $object->question;
$objQuestion->description = $object->description;
$objQuestion->weighting = $object->ponderation;
$objQuestion->position = $object->position;
$objQuestion->type = $object->type;
$objQuestion->picture = $object->picture;
$objQuestion->level = (int)$object->level;
$objQuestion->extra = $object->extra;
$objQuestion->course = $course_info;
$objQuestion->parent_id = $object->parent_id;
$objQuestion->category_list = Testcategory::getCategoryForQuestion($id);
$sql = "SELECT exercice_id FROM $TBL_EXERCICE_QUESTION WHERE c_id = $course_id AND question_id = $id";
$sql = "SELECT exercice_id FROM $TBL_EXERCICE_QUESTION WHERE c_id = $course_id AND question_id = $id";
$result_exercise_list = Database::query($sql);
// fills the array with the exercises which this question is in
@ -349,6 +349,7 @@ abstract class Question
{
$this->course = api_get_course_info_by_id($course_id);
}
/**
* changes the question title
*
@ -423,13 +424,14 @@ abstract class Question
* @param - int $in_positive
* @author - Julio Montoya - Adding multiple cat support
*/
function saveCategories($category_list) {
function saveCategories($category_list)
{
$course_id = $this->course['real_id'];
if (!empty($category_list)) {
$this->deleteCategory();
$TBL_QUESTION_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
$category_list = array_filter($category_list);
$category_list = array_filter($category_list);
// update or add category for a question
foreach ($category_list as $category_id) {
@ -438,9 +440,9 @@ abstract class Question
}
$category_id = intval($category_id);
$question_id = Database::escape_string($this->id);
$sql = "SELECT count(*) AS nb FROM $TBL_QUESTION_REL_CATEGORY WHERE category_id = $category_id AND question_id = $question_id AND c_id=".$course_id;
$res = Database::query($sql);
$row = Database::fetch_array($res);
$sql = "SELECT count(*) AS nb FROM $TBL_QUESTION_REL_CATEGORY WHERE category_id = $category_id AND question_id = $question_id AND c_id=".$course_id;
$res = Database::query($sql);
$row = Database::fetch_array($res);
if ($row['nb'] > 0) {
//DO nothing
//$sql = "UPDATE $TBL_QUESTION_REL_CATEGORY SET category_id = $category_id WHERE question_id=$question_id AND c_id=".api_get_course_int_id();
@ -467,16 +469,19 @@ abstract class Question
// update or add category for a question
$TBL_QUESTION_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
$category_id = Database::escape_string($in_category);
$question_id = Database::escape_string($this->id);
$sql = "SELECT count(*) AS nb FROM $TBL_QUESTION_REL_CATEGORY WHERE question_id= $question_id AND c_id=".api_get_course_int_id();
$res = Database::query($sql);
$row = Database::fetch_array($res);
$category_id = Database::escape_string($in_category);
$question_id = Database::escape_string($this->id);
$sql = "SELECT count(*) AS nb FROM $TBL_QUESTION_REL_CATEGORY WHERE question_id= $question_id AND c_id=".api_get_course_int_id(
);
$res = Database::query($sql);
$row = Database::fetch_array($res);
if ($row['nb'] > 0) {
$sql = "UPDATE $TBL_QUESTION_REL_CATEGORY SET category_id= $category_id WHERE question_id=$question_id AND c_id=".api_get_course_int_id();
$sql = "UPDATE $TBL_QUESTION_REL_CATEGORY SET category_id= $category_id WHERE question_id=$question_id AND c_id=".api_get_course_int_id(
);
$res = Database::query($sql);
} else {
$sql = "INSERT INTO $TBL_QUESTION_REL_CATEGORY VALUES (".api_get_course_int_id().", $question_id, $category_id)";
$sql = "INSERT INTO $TBL_QUESTION_REL_CATEGORY VALUES (".api_get_course_int_id(
).", $question_id, $category_id)";
$res = Database::query($sql);
}
}
@ -488,11 +493,12 @@ abstract class Question
* @param : none
* delte the category for question
*/
function deleteCategory() {
$course_id = $this->course['real_id'];
function deleteCategory()
{
$course_id = $this->course['real_id'];
$TBL_QUESTION_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
$question_id = Database::escape_string($this->id);
$sql = "DELETE FROM $TBL_QUESTION_REL_CATEGORY WHERE question_id = $question_id AND c_id = ".$course_id;
$question_id = Database::escape_string($this->id);
$sql = "DELETE FROM $TBL_QUESTION_REL_CATEGORY WHERE question_id = $question_id AND c_id = ".$course_id;
Database::query($sql);
}
@ -528,7 +534,7 @@ abstract class Question
function updateType($type)
{
$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
$course_id = $this->course['real_id'];
$course_id = $this->course['real_id'];
if (empty($course_id)) {
$course_id = api_get_course_int_id();
@ -570,18 +576,18 @@ abstract class Question
if (mkdir($picturePath, api_get_permissions_for_new_directories())) {
// document path
$documentPath = api_get_path(SYS_COURSE_PATH).$this->course['path']."/document";
$path = str_replace($documentPath, '', $picturePath);
$title_path = basename($picturePath);
$doc_id = FileManager::add_document($this->course, $path, 'folder', 0, $title_path);
$path = str_replace($documentPath, '', $picturePath);
$title_path = basename($picturePath);
$doc_id = FileManager::add_document($this->course, $path, 'folder', 0, $title_path);
api_item_property_update($this->course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', api_get_user_id());
}
}
// if the question has got an ID
if ($this->id) {
$extension = pathinfo($PictureName, PATHINFO_EXTENSION);
$extension = pathinfo($PictureName, PATHINFO_EXTENSION);
$this->picture = 'quiz-'.$this->id.'.jpg';
$o_img = new Image($Picture);
$o_img = new Image($Picture);
$o_img->send_image($picturePath.'/'.$this->picture, -1, 'jpg');
$document_id = FileManager::add_document(
$this->course,
@ -622,8 +628,8 @@ abstract class Question
$my_image = new Image($picturePath.'/'.$this->picture);
$current_image_size = $my_image->get_image_size();
$current_width = $current_image_size['width'];
$current_height = $current_image_size['height'];
$current_width = $current_image_size['width'];
$current_height = $current_image_size['height'];
if ($current_width < $Max && $current_height < $Max) {
return true;
@ -634,28 +640,28 @@ abstract class Question
// Resize according to height.
if ($Dimension == "height") {
$resize_scale = $current_height / $Max;
$new_height = $Max;
$new_width = ceil($current_width / $resize_scale);
$new_height = $Max;
$new_width = ceil($current_width / $resize_scale);
}
// Resize according to width
if ($Dimension == "width") {
$resize_scale = $current_width / $Max;
$new_width = $Max;
$new_height = ceil($current_height / $resize_scale);
$new_width = $Max;
$new_height = ceil($current_height / $resize_scale);
}
// Resize according to height or width, both should not be larger than $Max after resizing.
if ($Dimension == "any") {
if ($current_height > $current_width || $current_height == $current_width) {
$resize_scale = $current_height / $Max;
$new_height = $Max;
$new_width = ceil($current_width / $resize_scale);
$new_height = $Max;
$new_width = ceil($current_width / $resize_scale);
}
if ($current_height < $current_width) {
$resize_scale = $current_width / $Max;
$new_width = $Max;
$new_height = ceil($current_height / $resize_scale);
$new_width = $Max;
$new_height = ceil($current_height / $resize_scale);
}
}
@ -682,7 +688,7 @@ abstract class Question
// if the question has got an ID and if the picture exists
if ($this->id) {
$picture = $this->picture;
$picture = $this->picture;
$this->picture = '';
return @unlink($picturePath.'/'.$picture) ? true : false;
@ -700,17 +706,17 @@ abstract class Question
*/
function exportPicture($questionId, $course_info)
{
$course_id = $course_info['real_id'];
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$course_id = $course_info['real_id'];
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$destination_path = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/document/images';
$source_path = api_get_path(SYS_COURSE_PATH).$this->course['path'].'/document/images';
$source_path = api_get_path(SYS_COURSE_PATH).$this->course['path'].'/document/images';
// if the question has got an ID and if the picture exists
if ($this->id && !empty($this->picture)) {
$picture = explode('.', $this->picture);
$picture = explode('.', $this->picture);
$extension = $picture[sizeof($picture) - 1];
$picture = 'quiz-'.$questionId.'.'.$extension;
$result = @copy($source_path.'/'.$this->picture, $destination_path.'/'.$picture) ? true : false;
$picture = 'quiz-'.$questionId.'.'.$extension;
$result = @copy($source_path.'/'.$this->picture, $destination_path.'/'.$picture) ? true : false;
//If copy was correct then add to the database
if ($result) {
$sql = "UPDATE $TBL_QUESTIONS SET picture='".Database::escape_string(
@ -755,7 +761,7 @@ abstract class Question
{
global $picturePath;
$PictureName = explode('.', $PictureName);
$Extension = $PictureName[sizeof($PictureName) - 1];
$Extension = $PictureName[sizeof($PictureName) - 1];
// saves the picture into a temporary file
@move_uploaded_file($Picture, $picturePath.'/tmp.'.$Extension);
@ -816,18 +822,18 @@ abstract class Question
function save($exerciseId = 0)
{
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$id = $this->id;
$question = $this->question;
$description = $this->description;
$weighting = $this->weighting;
$position = $this->position;
$type = $this->type;
$picture = $this->picture;
$level = $this->level;
$extra = $this->extra;
$c_id = $this->course['real_id'];
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$id = $this->id;
$question = $this->question;
$description = $this->description;
$weighting = $this->weighting;
$position = $this->position;
$type = $this->type;
$picture = $this->picture;
$level = $this->level;
$extra = $this->extra;
$c_id = $this->course['real_id'];
$category_list = $this->category_list;
// Question already exists
@ -857,16 +863,16 @@ abstract class Question
}
} else {
// Creates a new question
$sql = "SELECT max(position) FROM $TBL_QUESTIONS as question, $TBL_EXERCICE_QUESTION as test_question
$sql = "SELECT max(position) FROM $TBL_QUESTIONS as question, $TBL_EXERCICE_QUESTION as test_question
WHERE question.id = test_question.question_id AND
test_question.exercice_id = '".Database::escape_string($exerciseId)."' AND
question.c_id = $c_id AND
test_question.c_id = $c_id ";
$result = Database::query($sql);
$result = Database::query($sql);
$current_position = Database::result($result, 0, 0);
$this->updatePosition($current_position + 1);
$position = $this->position;
$sql = "INSERT INTO $TBL_QUESTIONS (c_id, question, description, ponderation, position, type, picture, extra, level, parent_id) VALUES ( ".
$sql = "INSERT INTO $TBL_QUESTIONS (c_id, question, description, ponderation, position, type, picture, extra, level, parent_id) VALUES ( ".
" $c_id, ".
" '".Database::escape_string($question)."', ".
" '".Database::escape_string($description)."', ".
@ -887,15 +893,19 @@ abstract class Question
// If hotspot, create first answer
if ($type == HOT_SPOT || $type == HOT_SPOT_ORDER) {
$TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER);
$sql = "INSERT INTO $TBL_ANSWERS (c_id, question_id , answer , correct , comment , ponderation , position , hotspot_coordinates , hotspot_type )
VALUES (".$c_id.", '".Database::escape_string($this->id)."', '', NULL , '', '10' , '1', '0;0|0|0', 'square')";
$sql = "INSERT INTO $TBL_ANSWERS (c_id, question_id , answer , correct , comment , ponderation , position , hotspot_coordinates , hotspot_type )
VALUES (".$c_id.", '".Database::escape_string(
$this->id
)."', '', NULL , '', '10' , '1', '0;0|0|0', 'square')";
Database::query($sql);
}
if ($type == HOT_SPOT_DELINEATION) {
$TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER);
$sql = "INSERT INTO $TBL_ANSWERS (c_id, question_id , answer , correct , comment , ponderation , position , hotspot_coordinates , hotspot_type )
VALUES (".$c_id.", '".Database::escape_string($this->id)."', '', NULL , '', '10' , '1', '0;0|0|0', 'delineation')";
$sql = "INSERT INTO $TBL_ANSWERS (c_id, question_id , answer , correct , comment , ponderation , position , hotspot_coordinates , hotspot_type )
VALUES (".$c_id.", '".Database::escape_string(
$this->id
)."', '', NULL , '', '10' , '1', '0;0|0|0', 'delineation')";
Database::query($sql);
}
@ -979,15 +989,15 @@ abstract class Question
$ic_slide->addValue("title", $this->question);
$ic_slide->addCourseId($course_id);
$ic_slide->addToolId(TOOL_QUIZ);
$xapian_data = array(
$xapian_data = array(
SE_COURSE_ID => $course_id,
SE_TOOL_ID => TOOL_QUIZ,
SE_DATA => array(
'type' => SE_DOCTYPE_EXERCISE_QUESTION,
SE_TOOL_ID => TOOL_QUIZ,
SE_DATA => array(
'type' => SE_DOCTYPE_EXERCISE_QUESTION,
'exercise_ids' => $question_exercises,
'question_id' => (int)$this->id
'question_id' => (int)$this->id
),
SE_USER => (int)api_get_user_id(),
SE_USER => (int)api_get_user_id(),
);
$ic_slide->xapian_data = serialize($xapian_data);
$ic_slide->addValue("content", $this->description);
@ -1050,11 +1060,11 @@ abstract class Question
function addToList($exerciseId, $fromSave = false)
{
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$id = $this->id;
$id = $this->id;
// checks if the exercise ID is not in the list
if (!in_array($exerciseId, $this->exerciseList)) {
$this->exerciseList[] = $exerciseId;
$new_exercise = new Exercise();
$new_exercise = new Exercise();
$new_exercise->read($exerciseId);
$count = $new_exercise->selectNbrQuestions();
$count++;
@ -1132,9 +1142,9 @@ abstract class Question
{
$course_id = api_get_course_int_id();
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
$TBL_QUIZ_QUESTION_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
$id = $this->id;
@ -1208,16 +1218,16 @@ abstract class Question
} else {
$course_info = $course_info;
}
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TBL_QUESTION_OPTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
$question = $this->question;
$question = $this->question;
$description = $this->description;
$weighting = $this->weighting;
$position = $this->position;
$type = $this->type;
$level = intval($this->level);
$extra = $this->extra;
$weighting = $this->weighting;
$position = $this->position;
$type = $this->type;
$level = intval($this->level);
$extra = $this->extra;
//Using the same method used in the course copy to transform URLs
@ -1227,7 +1237,7 @@ abstract class Question
$this->course['id'],
$course_info['id']
);
$question = DocumentManager::replace_urls_inside_content_html_from_copy_course(
$question = DocumentManager::replace_urls_inside_content_html_from_copy_course(
$question,
$this->course['id'],
$course_info['id']
@ -1240,16 +1250,16 @@ abstract class Question
$options = self::readQuestionOption($this->id, $this->course['real_id']);
//Inserting in the new course db / or the same course db
$params = array(
'c_id' => $course_id,
'question' => $question,
$params = array(
'c_id' => $course_id,
'question' => $question,
'description' => $description,
'ponderation' => $this->weighting,
'position' => $this->position,
'type' => $this->type,
'level' => $this->level,
'extra' => $this->extra,
'parent_id' => $this->parent_id,
'position' => $this->position,
'type' => $this->type,
'level' => $this->level,
'extra' => $this->extra,
'parent_id' => $this->parent_id,
);
$new_question_id = Database::insert($TBL_QUESTIONS, $params);
@ -1257,7 +1267,7 @@ abstract class Question
//Saving the quiz_options
foreach ($options as $item) {
$item['question_id'] = $new_question_id;
$item['c_id'] = $course_id;
$item['c_id'] = $course_id;
unset($item['iid']);
Database::insert($TBL_QUESTION_OPTIONS, $item);
}
@ -1270,20 +1280,24 @@ abstract class Question
return $new_question_id;
}
function get_categories_from_question() {
function get_categories_from_question()
{
return Testcategory::getCategoryForQuestion($this->id);
}
function duplicate_category_question($question_id, $course_id) {
$question = Question::read($question_id, $course_id);
function duplicate_category_question($question_id, $course_id)
{
$question = Question::read($question_id, $course_id);
$categories = $this->get_categories_from_question();
if (!empty($categories)) {
$question->saveCategories($categories);
}
}
function get_question_type_name() {
function get_question_type_name()
{
$key = self::$questionTypes[$this->type];
return get_lang($key[1]);
}
@ -1333,7 +1347,8 @@ abstract class Question
* A subclass can redifine this function to add fields...
* @param FormValidator $form the formvalidator instance (by reference)
*/
function createForm(&$form, $fck_config = 0) {
function createForm(&$form, $fck_config = 0)
{
$url = api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?1=1';
echo ' <style>
.media { display:none;}
@ -1497,7 +1512,13 @@ abstract class Question
echo '<script>$(function() { '.$trigger.' });</script>';
}
$form->addElement('select', 'questionCategory', get_lang('Category'), array(), array('id' => 'category_id'));
$form->addElement(
'select',
'questionCategory',
get_lang('Category'),
array(),
array('id' => 'category_id')
);
// Categories
//$tabCat = Testcategory::getCategoriesIdAndName();
@ -1537,12 +1558,12 @@ abstract class Question
// default values
$defaults = array();
$defaults['questionName'] = $this->question;
$defaults = array();
$defaults['questionName'] = $this->question;
$defaults['questionDescription'] = $this->description;
$defaults['questionLevel'] = $this->level;
$defaults['questionCategory'] = $this->category_list;
$defaults['parent_id'] = $this->parent_id;
$defaults['questionLevel'] = $this->level;
$defaults['questionCategory'] = $this->category_list;
$defaults['parent_id'] = $this->parent_id;
//Came from he question pool
if (isset($_GET['fromExercise'])) {
@ -1601,7 +1622,7 @@ abstract class Question
static function display_type_menu($objExercise)
{
$feedback_type = $objExercise->feedback_type;
$exerciseId = $objExercise->id;
$exerciseId = $objExercise->id;
// 1. by default we show all the question types
$question_type_custom_list = self::get_question_type_list();
@ -1612,7 +1633,7 @@ abstract class Question
if ($feedback_type == 1) {
//2. but if it is a feedback DIRECT we only show the UNIQUE_ANSWER type that is currently available
$question_type_custom_list = array(
UNIQUE_ANSWER => self::$questionTypes[UNIQUE_ANSWER],
UNIQUE_ANSWER => self::$questionTypes[UNIQUE_ANSWER],
HOT_SPOT_DELINEATION => self::$questionTypes[HOT_SPOT_DELINEATION]
);
} else {
@ -1636,7 +1657,13 @@ abstract class Question
$img = $img['filename'].'_na.'.$img['extension'];
echo Display::return_icon($img, $explanation, array(), ICON_SIZE_BIG);
} else {
echo '<a href="admin.php?'.api_get_cidreq().'&newQuestion=yes&answerType='.$i.'&exerciseId='.$exerciseId.'">'.Display::return_icon($img, $explanation, array(), ICON_SIZE_BIG).'</a>';
echo '<a href="admin.php?'.api_get_cidreq(
).'&newQuestion=yes&answerType='.$i.'&exerciseId='.$exerciseId.'">'.Display::return_icon(
$img,
$explanation,
array(),
ICON_SIZE_BIG
).'</a>';
}
echo '</div>';
echo '</li>';
@ -1663,10 +1690,10 @@ abstract class Question
static function saveQuestionOption($question_id, $name, $course_id, $position = 0)
{
$TBL_EXERCICE_QUESTION_OPTION = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
$params['question_id'] = intval($question_id);
$params['name'] = $name;
$params['position'] = $position;
$params['c_id'] = $course_id;
$params['question_id'] = intval($question_id);
$params['name'] = $name;
$params['position'] = $position;
$params['c_id'] = $course_id;
//$result = self::readQuestionOption($question_id, $course_id);
$last_id = Database::insert($TBL_EXERCICE_QUESTION_OPTION, $params);
@ -1685,7 +1712,7 @@ abstract class Question
static function updateQuestionOption($id, $params, $course_id)
{
$TBL_EXERCICE_QUESTION_OPTION = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
$result = Database::update(
$result = Database::update(
$TBL_EXERCICE_QUESTION_OPTION,
$params,
array('c_id = ? AND id = ?' => array($course_id, $id))
@ -1694,16 +1721,26 @@ abstract class Question
return $result;
}
static function readQuestionOption($question_id, $course_id) {
static function readQuestionOption($question_id, $course_id)
{
$TBL_EXERCICE_QUESTION_OPTION = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
$result = Database::select('*', $TBL_EXERCICE_QUESTION_OPTION, array('where' => array('c_id = ? AND question_id = ?' => array($course_id, $question_id)), 'order' => 'iid ASC'));
$result = Database::select(
'*',
$TBL_EXERCICE_QUESTION_OPTION,
array(
'where' => array('c_id = ? AND question_id = ?' => array($course_id, $question_id)),
'order' => 'iid ASC'
)
);
if (!empty($result)) {
$new_result = array();
foreach ($result as $item) {
$new_result[$item['iid']] = $item;
}
return $new_result;
}
return array();
}
@ -1723,19 +1760,19 @@ abstract class Question
$counter_label = intval($counter);
}
$score_label = get_lang('Wrong');
$class = 'error';
$class = 'error';
if ($score['pass'] == true) {
$score_label = get_lang('Correct');
$class = 'success';
$class = 'success';
}
if ($this->type == FREE_ANSWER || $this->type == ORAL_EXPRESSION) {
if ($score['revised'] == true) {
$score_label = get_lang('Revised');
$class = '';
$class = '';
} else {
$score_label = get_lang('NotRevised');
$class = 'error';
$class = 'error';
}
}
$question_title = $this->question;
@ -1747,7 +1784,10 @@ abstract class Question
}
$header .= Display::page_subheader2($counter_label.". ".$question_title);
//$header .= Display::div('<div class="rib rib-'.$class.'"><h3>'.$score_label.'</h3></div> <h4>'.($score['result']).' </h4><h5 class="'.$class.'">'.$score['result'].' </h5>', array('class'=>'ribbon'));
$header .= Display::div('<div class="rib rib-'.$class.'"><h3>'.$score_label.'</h3></div> <h4>'.$score['result'].' </h4>', array('class' => 'ribbon'));
$header .= Display::div(
'<div class="rib rib-'.$class.'"><h3>'.$score_label.'</h3></div> <h4>'.$score['result'].' </h4>',
array('class' => 'ribbon')
);
$header .= Display::div($this->description, array('id' => 'question_description'));
return $header;
@ -1765,36 +1805,38 @@ abstract class Question
{
$course_id = api_get_course_int_id();
$tbl_quiz_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
$tbl_quiz_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
$tbl_quiz_rel_question = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$quiz_id = intval($quiz_id);
$quiz_id = intval($quiz_id);
$max_score = (float)$max_score;
$type = intval($type);
$level = intval($level);
$type = intval($type);
$level = intval($level);
// Get the max position
$sql = "SELECT max(position) as max_position"
$sql = "SELECT max(position) as max_position"
." FROM $tbl_quiz_question q INNER JOIN $tbl_quiz_rel_question r"
." ON q.iid = r.question_id"
." AND exercice_id = $quiz_id AND q.c_id = $course_id AND r.c_id = $course_id";
$rs_max = Database::query($sql);
$row_max = Database::fetch_object($rs_max);
$rs_max = Database::query($sql);
$row_max = Database::fetch_object($rs_max);
$max_position = $row_max->max_position + 1;
// Insert the new question
$sql = "INSERT INTO $tbl_quiz_question (c_id, question, ponderation, position, type, level)
VALUES ($course_id, '".Database::escape_string($question_name)."', '$max_score', $max_position, $type, $level)";
VALUES ($course_id, '".Database::escape_string(
$question_name
)."', '$max_score', $max_position, $type, $level)";
Database::query($sql);
// Get the question ID
$question_id = Database::get_last_insert_id();
// Get the max question_order
$sql = "SELECT max(question_order) as max_order "
$sql = "SELECT max(question_order) as max_order "
."FROM $tbl_quiz_rel_question WHERE c_id = $course_id AND exercice_id = $quiz_id ";
$rs_max_order = Database::query($sql);
$rs_max_order = Database::query($sql);
$row_max_order = Database::fetch_object($rs_max_order);
$max_order = $row_max_order->max_order + 1;
$max_order = $row_max_order->max_order + 1;
// Attach questions to quiz
$sql = "INSERT INTO $tbl_quiz_rel_question (c_id, question_id, exercice_id, question_order)"
." VALUES($course_id, $question_id, $quiz_id, $max_order)";
@ -1832,7 +1874,7 @@ abstract class Question
$where_condition = array()
) {
$table_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
$default_where = array('c_id = ? AND parent_id = 0 AND type = ?' => array($course_id, MEDIA_QUESTION));
$default_where = array('c_id = ? AND parent_id = 0 AND type = ?' => array($course_id, MEDIA_QUESTION));
if (!empty($where_condition)) {
//$where_condition
}
@ -1856,7 +1898,7 @@ abstract class Question
static function get_count_course_medias($course_id)
{
$table_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
$result = Database::select(
$result = Database::select(
'count(*) as count',
$table_question,
array('where' => array('c_id = ? AND parent_id = 0 AND type = ?' => array($course_id, MEDIA_QUESTION))),
@ -1872,8 +1914,8 @@ abstract class Question
static function prepare_course_media_select($course_id)
{
$medias = self::get_course_medias($course_id);
$media_list = array();
$medias = self::get_course_medias($course_id);
$media_list = array();
$media_list[0] = get_lang('NoMedia');
if (!empty($medias)) {
@ -1903,7 +1945,7 @@ abstract class Question
$html = null;
if ($this->parent_id != 0) {
$parent_question = Question::read($this->parent_id);
$html = $parent_question->show_media_content();
$html = $parent_question->show_media_content();
} else {
$html .= Display::page_subheader($this->selectTitle());
$html .= $this->selectDescription();
@ -1912,9 +1954,12 @@ abstract class Question
return $html;
}
static function question_type_no_review() {
static function question_type_no_review()
{
return array(
HOT_SPOT, HOT_SPOT_ORDER, HOT_SPOT_DELINEATION
HOT_SPOT,
HOT_SPOT_ORDER,
HOT_SPOT_DELINEATION
);
}
}

@ -1,12 +1,12 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This script allows to manage the statements of questions.
* It is included from the script admin.php
* @package chamilo.exercise
* @author Olivier Brouckaert
* @author Julio Montoya
*/
* This script allows to manage the statements of questions.
* It is included from the script admin.php
* @package chamilo.exercise
* @author Olivier Brouckaert
* @author Julio Montoya
*/
/**
* Code
*/
@ -15,86 +15,86 @@ $course_id = api_get_course_int_id();
// INIT QUESTION
if (isset($_GET['editQuestion'])) {
$objQuestion = Question::read ($_GET['editQuestion']);
$action = api_get_self()."?".api_get_cidreq()."&myid=1&modifyQuestion=".$modifyQuestion."&editQuestion=".$objQuestion->id."&exerciseId=$exerciseId";
$objQuestion = Question::read($_GET['editQuestion']);
$action = api_get_self()."?".api_get_cidreq(
)."&myid=1&modifyQuestion=".$modifyQuestion."&editQuestion=".$objQuestion->id."&exerciseId=$exerciseId";
} else {
$objQuestion = Question :: getInstance($_REQUEST['answerType']);
$action = api_get_self()."?".api_get_cidreq()."&modifyQuestion=".$modifyQuestion."&newQuestion=".$newQuestion."&exerciseId=$exerciseId";
$objQuestion = Question :: getInstance($_REQUEST['answerType']);
$action = api_get_self()."?".api_get_cidreq(
)."&modifyQuestion=".$modifyQuestion."&newQuestion=".$newQuestion."&exerciseId=$exerciseId";
}
if (is_object($objQuestion)) {
//Form creation
$form = new FormValidator('question_admin_form','post', $action);
if (isset($_GET['editQuestion'])) {
$class="btn save";
$text=get_lang('ModifyQuestion');
//$type = Security::remove_XSS($_GET['type']); already loaded in admin.php
} else {
$class="btn add";
$text=get_lang('AddQuestionToExercise');
//$type = $_REQUEST['answerType']; //already loaded in admin.php
}
//Form creation
$form = new FormValidator('question_admin_form', 'post', $action);
if (isset($_GET['editQuestion'])) {
$class = "btn save";
$text = get_lang('ModifyQuestion');
} else {
$class = "btn add";
$text = get_lang('AddQuestionToExercise');
}
$types_information = Question::get_question_type_list();
$form_title_extra = get_lang($types_information[$type][1]);
$types_information = Question::get_question_type_list();
$form_title_extra = get_lang($types_information[$type][1]);
// form title
$form->addElement('header', $text.': '.$form_title_extra);
// form title
$form->addElement('header', $text.': '.$form_title_extra);
if ($fastEdition) {
$form->setAllowRichEditorInForm(false);
$form->setAllowedRichEditorList(array('questionDescription'));
}
// question form elements
$objQuestion->createForm($form);
// question form elements
$objQuestion->createForm($form);
// answer form elements
$objQuestion->createAnswersForm($form);
// answer form elements
$objQuestion->createAnswersForm($form);
// this variable $show_quiz_edition comes from admin.php blocks the exercise/quiz modifications
if ($objExercise->edit_exercise_in_lp == false) {
$form->freeze();
}
// this variable $show_quiz_edition comes from admin.php blocks the exercise/quiz modifications
if ($objExercise->edit_exercise_in_lp == false) {
$form->freeze();
}
// FORM VALIDATION
// FORM VALIDATION
if (isset($_POST['submitQuestion']) && $form->validate()) {
if (isset($_POST['submitQuestion']) && $form->validate()) {
// question
$objQuestion->processCreation($form, $objExercise);
// Question
$objQuestion->processCreation($form, $objExercise);
// answers
$objQuestion->processAnswersCreation($form, $nb_answers);
// Answers
$objQuestion->processAnswersCreation($form, $nb_answers);
// TODO: maybe here is the better place to index this tool, including answers text
// redirect
if ($objQuestion -> type != HOT_SPOT && $objQuestion -> type != HOT_SPOT_DELINEATION) {
if(isset($_GET['editQuestion'])) {
echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&message=ItemUpdated"</script>';
} else {
//New question
echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&message=ItemAdded"</script>';
}
} else {
echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&hotspotadmin='.$objQuestion->id.'"</script>';
}
} else {
// redirect
if ($objQuestion->type != HOT_SPOT && $objQuestion->type != HOT_SPOT_DELINEATION) {
if (isset($_GET['editQuestion'])) {
echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&message=ItemUpdated"</script>';
} else {
//New question
echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&message=ItemAdded"</script>';
}
} else {
echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&hotspotadmin='.$objQuestion->id.'"</script>';
}
} else {
if (isset($questionName)) {
echo '<h3>'.$questionName.'</h3>';
echo '<h3>'.$questionName.'</h3>';
}
if(!empty($pictureName)){
echo '<img src="../document/download.php?doc_url=%2Fimages%2F'.$pictureName.'" border="0">';
}
if(!empty($msgErr)) {
Display::display_normal_message($msgErr); //main API
}
// display the form
$form->display();
}
if (!empty($pictureName)) {
echo '<img src="../document/download.php?doc_url=%2Fimages%2F'.$pictureName.'" border="0">';
}
if (!empty($msgErr)) {
Display::display_normal_message($msgErr); //main API
}
// display the form
$form->display();
}
}

@ -2,76 +2,78 @@
/* For licensing terms, see /license.txt */
/**
* File containing the UNIQUE_ANSWER class.
* @package chamilo.exercise
* @author Eric Marguin
* File containing the UNIQUE_ANSWER class.
* @package chamilo.exercise
* @author Eric Marguin
*/
/**
* Code
*/
/**
CLASS UNIQUE_ANSWER
CLASS UNIQUE_ANSWER
*
* This class allows to instantiate an object of type UNIQUE_ANSWER (MULTIPLE CHOICE, UNIQUE ANSWER),
* extending the class question
* This class allows to instantiate an object of type UNIQUE_ANSWER (MULTIPLE CHOICE, UNIQUE ANSWER),
* extending the class question
*
* @author Eric Marguin
* @author Julio Montoya
* @package chamilo.exercise
* @author Eric Marguin
* @author Julio Montoya
* @package chamilo.exercise
**/
class UniqueAnswer extends Question
{
static $typePicture = 'mcua.gif';
static $explanationLangVar = 'UniqueSelect';
/**
* Constructor
*/
function UniqueAnswer() {
//this is highly important
parent::question();
$this -> type = UNIQUE_ANSWER;
$this -> isContent = $this-> getIsContent();
}
/**
* function which redifines Question::createAnswersForm
* @param the formvalidator instance
* @param the answers number to display
*/
function createAnswersForm ($form) {
// Getting the exercise list
$obj_ex = $_SESSION['objExercise'];
$editor_config = array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '125');
//this line define how many question by default appear when creating a choice question
$nb_answers = isset($_POST['nb_answers']) ? (int) $_POST['nb_answers'] : 4; // The previous default value was 2. See task #1759.
$nb_answers += (isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0));
/*
Types of Feedback
$feedback_option[0]=get_lang('Feedback');
$feedback_option[1]=get_lang('DirectFeedback');
$feedback_option[2]=get_lang('NoFeedback');
*/
$feedback_title='';
$comment_title='';
if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_END) {
$comment_title = '<th>'.get_lang('Comment').'</th>';
} elseif ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
static $typePicture = 'mcua.gif';
static $explanationLangVar = 'UniqueSelect';
/**
* Constructor
*/
function UniqueAnswer()
{
//this is highly important
parent::question();
$this->type = UNIQUE_ANSWER;
$this->isContent = $this->getIsContent();
}
/**
* function which redifines Question::createAnswersForm
* @param the formvalidator instance
* @param the answers number to display
*/
function createAnswersForm($form)
{
// Getting the exercise list
$obj_ex = $_SESSION['objExercise'];
$editor_config = array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '125');
//this line define how many question by default appear when creating a choice question
$nb_answers = isset($_POST['nb_answers']) ? (int)$_POST['nb_answers'] : 4; // The previous default value was 2. See task #1759.
$nb_answers += (isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0));
/*
Types of Feedback
$feedback_option[0]=get_lang('Feedback');
$feedback_option[1]=get_lang('DirectFeedback');
$feedback_option[2]=get_lang('NoFeedback');
*/
$feedback_title = '';
$comment_title = '';
if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_END) {
$comment_title = '<th>'.get_lang('Comment').'</th>';
} elseif ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
//Scenario
$editor_config['Width'] = '250';
$editor_config['Height'] = '110';
$comment_title = '<th width="500px" >'.get_lang('Comment').'</th>';
$feedback_title = '<th width="350px" >'.get_lang('Scenario').'</th>';
}
$editor_config['Width'] = '250';
$editor_config['Height'] = '110';
$comment_title = '<th width="500px" >'.get_lang('Comment').'</th>';
$feedback_title = '<th width="350px" >'.get_lang('Scenario').'</th>';
}
$html='<table class="data_table">
$html = '<table class="data_table">
<tr style="text-align: center;">
<th width="10px">
'.get_lang('Number').'
@ -89,66 +91,66 @@ class UniqueAnswer extends Question
</th>
</tr>';
$form -> addElement ('label', get_lang('Answers').'<br /> <img src="../img/fill_field.png">', $html);
$defaults = array();
$correct = 0;
if(!empty($this -> id)) {
$answer = new Answer($this -> id);
$answer -> read();
if(count($answer->nbrAnswers)>0 && !$form->isSubmitted()) {
$nb_answers = $answer->nbrAnswers;
}
}
$form -> addElement('hidden', 'nb_answers');
//Feedback SELECT
$question_list = $obj_ex->selectQuestionList();
$select_question=array();
$select_question[0] = get_lang('SelectTargetQuestion');
require_once '../newscorm/learnpathList.class.php';
if (is_array($question_list)) {
foreach ($question_list as $key=>$questionid) {
//To avoid warning messages
if (!is_numeric($questionid)) {
continue;
}
$question = Question::read($questionid);
if($question) {
$select_question[$questionid] = 'Q'.$key.' :'.Text::cut($question->selectTitle(),20);
$form->addElement('label', get_lang('Answers').'<br /> <img src="../img/fill_field.png">', $html);
$defaults = array();
$correct = 0;
if (!empty($this->id)) {
$answer = new Answer($this->id);
$answer->read();
if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) {
$nb_answers = $answer->nbrAnswers;
}
}
$form->addElement('hidden', 'nb_answers');
//Feedback SELECT
$question_list = $obj_ex->selectQuestionList();
$select_question = array();
$select_question[0] = get_lang('SelectTargetQuestion');
require_once '../newscorm/learnpathList.class.php';
if (is_array($question_list)) {
foreach ($question_list as $key => $questionid) {
//To avoid warning messages
if (!is_numeric($questionid)) {
continue;
}
$question = Question::read($questionid);
if ($question) {
$select_question[$questionid] = 'Q'.$key.' :'.Text::cut($question->selectTitle(), 20);
}
}
}
$select_question[-1] = get_lang('ExitTest');
}
}
$select_question[-1] = get_lang('ExitTest');
$list = new LearnpathList(api_get_user_id());
$flat_list = $list->get_flat_list();
$select_lp_id=array();
$select_lp_id[0]=get_lang('SelectTargetLP');
$list = new LearnpathList(api_get_user_id());
$flat_list = $list->get_flat_list();
$select_lp_id = array();
$select_lp_id[0] = get_lang('SelectTargetLP');
foreach ($flat_list as $id => $details) {
$select_lp_id[$id] = Text::cut($details['lp_name'], 20);
}
foreach ($flat_list as $id => $details) {
$select_lp_id[$id] = Text::cut($details['lp_name'], 20);
}
$temp_scenario = array();
$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', '<tr>');
for ($i = 1; $i <= $nb_answers; ++$i) {
$form->addElement('html', '<tr>');
if (isset($answer) && is_object($answer)) {
$answer_id = $answer->getRealAnswerIdFromList($i);
if ($answer->correct[$answer_id]) {
$correct = $i;
}
$defaults['answer['.$i.']'] = $answer->answer[$answer_id];
$defaults['comment['.$i.']'] = $answer->comment[$answer_id];
$defaults['answer['.$i.']'] = $answer->answer[$answer_id];
$defaults['comment['.$i.']'] = $answer->comment[$answer_id];
$defaults['weighting['.$i.']'] = Text::float_format($answer->weighting[$answer_id], 1);
$item_list = explode('@@', $answer->destination[$answer_id]);
@ -158,41 +160,56 @@ class UniqueAnswer extends Question
$list_dest = $item_list[2];
$url = $item_list[3];
if ($try==0) {
if ($try == 0) {
$try_result = 0;
} else {
$try_result = 1;
}
if ($url==0) {
$url_result='';
if ($url == 0) {
$url_result = '';
} else {
$url_result = $url;
}
$temp_scenario['url'.$i] = $url_result;
$temp_scenario['try'.$i] = $try_result;
$temp_scenario['lp'.$i] = $lp;
$temp_scenario['destination'.$i]= $list_dest;
$temp_scenario['url'.$i] = $url_result;
$temp_scenario['try'.$i] = $try_result;
$temp_scenario['lp'.$i] = $lp;
$temp_scenario['destination'.$i] = $list_dest;
} else {
$defaults['answer[1]'] = get_lang('DefaultUniqueAnswer1');
$defaults['weighting[1]'] = 10;
$defaults['answer[2]'] = get_lang('DefaultUniqueAnswer2');
$defaults['weighting[2]'] = 0;
$defaults['answer[1]'] = get_lang('DefaultUniqueAnswer1');
$defaults['weighting[1]'] = 10;
$defaults['answer[2]'] = get_lang('DefaultUniqueAnswer2');
$defaults['weighting[2]'] = 0;
$temp_scenario['destination'.$i] = array('0');
$temp_scenario['lp'.$i] = array('0');
$temp_scenario['lp'.$i] = array('0');
}
$defaults['scenario'] = $temp_scenario;
$renderer = $form->defaultRenderer();
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter['.$i.']');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer['.$i.']');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment['.$i.']');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'weighting['.$i.']');
$answer_number = $form->addElement('text', 'counter['.$i.']',null,' value = "'.$i.'"');
$renderer->setElementTemplate(
'<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>',
'correct'
);
$renderer->setElementTemplate(
'<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>',
'counter['.$i.']'
);
$renderer->setElementTemplate(
'<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>',
'answer['.$i.']'
);
$renderer->setElementTemplate(
'<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>',
'comment['.$i.']'
);
$renderer->setElementTemplate(
'<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>',
'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;"');
@ -202,209 +219,252 @@ class UniqueAnswer extends Question
if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_END) {
// feedback
$form->addElement('html_editor', 'comment['.$i.']', null, 'style="vertical-align:middle"', $editor_config);
$form->addElement(
'html_editor',
'comment['.$i.']',
null,
'style="vertical-align:middle"',
$editor_config
);
} elseif ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
$form->addElement('html_editor', 'comment['.$i.']', null, 'style="vertical-align:middle"', $editor_config);
$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')));
$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('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}', 'scenario');
$renderer->setElementTemplate(
'<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}',
'scenario'
);
}
$form->addElement('text', 'weighting['.$i.']', null, array('class' => "span1", 'value' => '0'));
$form->addElement ('html', '</tr>');
$form->addElement('html', '</tr>');
}
$form -> addElement ('html', '</table>');
$form -> addElement ('html', '<br />');
$form->addElement('html', '</table>');
$form->addElement('html', '<br />');
$navigator_info = api_get_navigator();
$navigator_info = api_get_navigator();
global $text, $class;
global $text, $class;
//ie6 fix
if ($obj_ex->edit_exercise_in_lp == true) {
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','submitQuestion',$text, 'class="'.$class.'"');
} else {
//ie6 fix
if ($obj_ex->edit_exercise_in_lp == true) {
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', 'submitQuestion', $text, 'class="'.$class.'"');
} else {
//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.'"');
}
}
$renderer->setElementTemplate('{element}&nbsp;','submitQuestion');
$renderer->setElementTemplate('{element}&nbsp;','lessAnswers');
$renderer->setElementTemplate('{element}&nbsp;','moreAnswers');
$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.'"');
}
}
$renderer->setElementTemplate('{element}&nbsp;', 'submitQuestion');
$renderer->setElementTemplate('{element}&nbsp;', 'lessAnswers');
$renderer->setElementTemplate('{element}&nbsp;', 'moreAnswers');
$form->addElement('html', '</div></div>');
//We check the first radio button to be sure a radio button will be check
if ($correct==0) {
$correct=1;
}
$defaults['correct'] = $correct;
if (!empty($this -> id)) {
$form -> setDefaults($defaults);
} else {
if ($this -> isContent == 1) {
$form -> setDefaults($defaults);
}
}
$form->setConstants(array('nb_answers' => $nb_answers));
}
/**
* abstract function which creates the form to create / edit the answers of the question
* @param the formvalidator instance
* @param the answers number to display
*/
function processAnswersCreation($form) {
$questionWeighting = $nbrGoodAnswers = 0;
$correct = $form -> getSubmitValue('correct');
$objAnswer = new Answer($this->id);
$nb_answers = $form->getSubmitValue('nb_answers');
for ($i=1 ; $i <= $nb_answers ; $i++) {
$answer = trim($form -> getSubmitValue('answer['.$i.']'));
$comment = trim($form -> getSubmitValue('comment['.$i.']'));
$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];
$lp = $scenario['lp'.$i];
$destination = $scenario['destination'.$i];
$url = trim($scenario['url'.$i]);
/*
How we are going to parse the destination value
here we parse the destination value which is a string
1@@3@@2;4;4;@@http://www.chamilo.org
where: try_again@@lp_id@@selected_questions@@url
try_again = is 1 || 0
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) {
$destination_str.=$destination_id.';';
}*/
$goodAnswer = ($correct == $i) ? true : false;
if ($goodAnswer) {
$nbrGoodAnswers++;
$weighting = abs($weighting);
if($weighting > 0) {
//We check the first radio button to be sure a radio button will be check
if ($correct == 0) {
$correct = 1;
}
$defaults['correct'] = $correct;
if (!empty($this->id)) {
$form->setDefaults($defaults);
} else {
if ($this->isContent == 1) {
$form->setDefaults($defaults);
}
}
$form->setConstants(array('nb_answers' => $nb_answers));
}
/**
* abstract function which creates the form to create / edit the answers of the question
* @param the formvalidator instance
* @param the answers number to display
*/
function processAnswersCreation($form)
{
$questionWeighting = $nbrGoodAnswers = 0;
$correct = $form->getSubmitValue('correct');
$objAnswer = new Answer($this->id);
$nb_answers = $form->getSubmitValue('nb_answers');
for ($i = 1; $i <= $nb_answers; $i++) {
$answer = trim($form->getSubmitValue('answer['.$i.']'));
$comment = trim($form->getSubmitValue('comment['.$i.']'));
$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];
$lp = $scenario['lp'.$i];
$destination = $scenario['destination'.$i];
$url = trim($scenario['url'.$i]);
/*
How we are going to parse the destination value
here we parse the destination value which is a string
1@@3@@2;4;4;@@http://www.chamilo.org
where: try_again@@lp_id@@selected_questions@@url
try_again = is 1 || 0
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) {
$destination_str.=$destination_id.';';
}*/
$goodAnswer = ($correct == $i) ? true : false;
if ($goodAnswer) {
$nbrGoodAnswers++;
$weighting = abs($weighting);
if ($weighting > 0) {
$questionWeighting += $weighting;
}
}
}
if (empty($try)) {
$try = 0;
if (empty($try)) {
$try = 0;
}
if (empty($lp)) {
$lp = 0;
}
if (empty($lp)) {
$lp = 0;
}
if (empty($destination)) {
$destination=0;
}
if (empty($destination)) {
$destination = 0;
}
if ($url=='') {
$url=0;
}
if ($url == '') {
$url = 0;
}
//1@@1;2;@@2;4;4;@@http://www.chamilo.org
$dest = $try.'@@'.$lp.'@@'.$destination.'@@'.$url;
$objAnswer->createAnswer($answer, $goodAnswer, $comment, $weighting, $i, null, null, $dest);
//1@@1;2;@@2;4;4;@@http://www.chamilo.org
$dest = $try.'@@'.$lp.'@@'.$destination.'@@'.$url;
$objAnswer->createAnswer($answer, $goodAnswer, $comment, $weighting, $i, null, null, $dest);
}
// saves the answers into the data base
// saves the answers into the data base
$objAnswer->save();
// sets the total weighting of the question
$this->updateWeighting($questionWeighting);
$this->save();
}
}
function return_header($feedback_type = null, $counter = null, $score = null, $show_media = false) {
$header = parent::return_header($feedback_type, $counter, $score, $show_media);
$header .= '<table class="'.$this->question_table_class .'">
function return_header($feedback_type = null, $counter = null, $score = null, $show_media = false)
{
$header = parent::return_header($feedback_type, $counter, $score, $show_media);
$header .= '<table class="'.$this->question_table_class.'">
<tr>
<th>'.get_lang("Choice").'</th>
<th>'. get_lang("ExpectedChoice").'</th>
<th>'. get_lang("Answer").'</th>';
if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {
$header .= '<th>'.get_lang("Comment").'</th>';
} else {
$header .= '<th>&nbsp;</th>';
}
<th>'.get_lang("ExpectedChoice").'</th>
<th>'.get_lang("Answer").'</th>';
if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {
$header .= '<th>'.get_lang("Comment").'</th>';
} else {
$header .= '<th>&nbsp;</th>';
}
$header .= '</tr>';
return $header;
}
/**
* Create database record for the given answer
* @param int The answer ID (technically 1 is OK if you don't know)
* @param int The question this answer is attached to
* @param string The answer itself
* @param string The answer comment (shown as feedback if enabled)
* @param float Score given by this answer if selected (can be negative)
* @param int Whether this answer is considered correct (1) or not (0)
* @param int The course ID - if not provided, will be guessed from the context
* @return void
* @assert (1,null,'a','',1,1,null) === false
* @assert (1,1,'','',1,1,null) === false
*/
function create_answer($id=1, $question_id, $answer_title, $comment = '', $score = 0, $correct = 0, $course_id = null) {
/**
* Create database record for the given answer
* @param int The answer ID (technically 1 is OK if you don't know)
* @param int The question this answer is attached to
* @param string The answer itself
* @param string The answer comment (shown as feedback if enabled)
* @param float Score given by this answer if selected (can be negative)
* @param int Whether this answer is considered correct (1) or not (0)
* @param int The course ID - if not provided, will be guessed from the context
* @return void
* @assert (1,null,'a','',1,1,null) === false
* @assert (1,1,'','',1,1,null) === false
*/
function create_answer(
$id = 1,
$question_id,
$answer_title,
$comment = '',
$score = 0,
$correct = 0,
$course_id = null
) {
if (empty($question_id) or empty($answer_title)) {
return false;
}
$tbl_quiz_answer = Database::get_course_table(TABLE_QUIZ_ANSWER);
$tbl_quiz_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
if (empty($course_id)) {
$course_id = api_get_course_int_id();
}
$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
$tbl_quiz_answer = Database::get_course_table(TABLE_QUIZ_ANSWER);
$tbl_quiz_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
if (empty($course_id)) {
$course_id = api_get_course_int_id();
}
$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, question_id,answer,correct,comment,ponderation,position,destination)"
."VALUES ($course_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) {
."$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 iid = ".$question_id;
$rs = Database::query($sql);
return $rs;
$rs = Database::query($sql);
return $rs;
}
}
}
}
Loading…
Cancel
Save