|
|
|
|
@ -37,31 +37,31 @@ abstract class Question |
|
|
|
|
public $questionTypeWithFeedback; |
|
|
|
|
public $extra; |
|
|
|
|
public $export = false; |
|
|
|
|
public 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( |
|
|
|
|
public static $questionTypes = [ |
|
|
|
|
UNIQUE_ANSWER => ['unique_answer.class.php', 'UniqueAnswer'], |
|
|
|
|
MULTIPLE_ANSWER => ['multiple_answer.class.php', 'MultipleAnswer'], |
|
|
|
|
FILL_IN_BLANKS => ['fill_blanks.class.php', 'FillBlanks'], |
|
|
|
|
MATCHING => ['matching.class.php', 'Matching'], |
|
|
|
|
FREE_ANSWER => ['freeanswer.class.php', 'FreeAnswer'], |
|
|
|
|
ORAL_EXPRESSION => ['oral_expression.class.php', 'OralExpression'], |
|
|
|
|
HOT_SPOT => ['hotspot.class.php', 'HotSpot'], |
|
|
|
|
HOT_SPOT_DELINEATION => ['hotspot.class.php', 'HotspotDelineation'], |
|
|
|
|
MULTIPLE_ANSWER_COMBINATION => ['multiple_answer_combination.class.php', 'MultipleAnswerCombination'], |
|
|
|
|
UNIQUE_ANSWER_NO_OPTION => ['unique_answer_no_option.class.php', 'UniqueAnswerNoOption'], |
|
|
|
|
MULTIPLE_ANSWER_TRUE_FALSE => ['multiple_answer_true_false.class.php', 'MultipleAnswerTrueFalse'], |
|
|
|
|
MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE => [ |
|
|
|
|
'multiple_answer_combination_true_false.class.php', |
|
|
|
|
'MultipleAnswerCombinationTrueFalse' |
|
|
|
|
), |
|
|
|
|
GLOBAL_MULTIPLE_ANSWER => array('global_multiple_answer.class.php', 'GlobalMultipleAnswer'), |
|
|
|
|
CALCULATED_ANSWER => array('calculated_answer.class.php', 'CalculatedAnswer'), |
|
|
|
|
], |
|
|
|
|
GLOBAL_MULTIPLE_ANSWER => ['global_multiple_answer.class.php', 'GlobalMultipleAnswer'], |
|
|
|
|
CALCULATED_ANSWER => ['calculated_answer.class.php', 'CalculatedAnswer'], |
|
|
|
|
UNIQUE_ANSWER_IMAGE => ['UniqueAnswerImage.php', 'UniqueAnswerImage'], |
|
|
|
|
DRAGGABLE => ['Draggable.php', 'Draggable'], |
|
|
|
|
MATCHING_DRAGGABLE => ['MatchingDraggable.php', 'MatchingDraggable'], |
|
|
|
|
//MEDIA_QUESTION => array('media_question.class.php' , 'MediaQuestion') |
|
|
|
|
ANNOTATION => ['Annotation.php', 'Annotation'], |
|
|
|
|
READING_COMPREHENSION => ['ReadingComprehension.php', 'ReadingComprehension'] |
|
|
|
|
); |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* constructor of the class |
|
|
|
|
@ -81,9 +81,9 @@ abstract class Question |
|
|
|
|
// This variable is used when loading an exercise like an scenario with |
|
|
|
|
// an special hotspot: final_overlap, final_missing, final_excess |
|
|
|
|
$this->extra = ''; |
|
|
|
|
$this->exerciseList = array(); |
|
|
|
|
$this->exerciseList = []; |
|
|
|
|
$this->course = api_get_course_info(); |
|
|
|
|
$this->category_list = array(); |
|
|
|
|
$this->category_list = []; |
|
|
|
|
$this->parent_id = 0; |
|
|
|
|
// See BT#12611 |
|
|
|
|
$this->questionTypeWithFeedback = [ |
|
|
|
|
@ -509,23 +509,26 @@ abstract class Question |
|
|
|
|
* in this version, a question can only have 1 category |
|
|
|
|
* if category is 0, then question has no category then delete the category entry |
|
|
|
|
* @param int $categoryId |
|
|
|
|
* @param int $courseId |
|
|
|
|
* @return bool |
|
|
|
|
* |
|
|
|
|
* @author Hubert Borderiou 12-10-2011 |
|
|
|
|
*/ |
|
|
|
|
public function saveCategory($categoryId) |
|
|
|
|
public function saveCategory($categoryId, $courseId = 0) |
|
|
|
|
{ |
|
|
|
|
$courseId = api_get_course_int_id(); |
|
|
|
|
$courseId = empty($courseId) ? api_get_course_int_id() : (int) $courseId; |
|
|
|
|
|
|
|
|
|
if (empty($courseId)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($categoryId <= 0) { |
|
|
|
|
$this->deleteCategory(); |
|
|
|
|
$this->deleteCategory($courseId); |
|
|
|
|
} else { |
|
|
|
|
// update or add category for a question |
|
|
|
|
$table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); |
|
|
|
|
$categoryId = intval($categoryId); |
|
|
|
|
$question_id = intval($this->id); |
|
|
|
|
$categoryId = (int) $categoryId; |
|
|
|
|
$question_id = (int) $this->id; |
|
|
|
|
$sql = "SELECT count(*) AS nb FROM $table |
|
|
|
|
WHERE |
|
|
|
|
question_id = $question_id AND |
|
|
|
|
@ -551,18 +554,25 @@ abstract class Question |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author hubert borderiou 12-10-2011 |
|
|
|
|
* @param int $courseId |
|
|
|
|
* delete any category entry for question id |
|
|
|
|
* delete the category for question |
|
|
|
|
* @return bool |
|
|
|
|
*/ |
|
|
|
|
public function deleteCategory() |
|
|
|
|
public function deleteCategory($courseId = 0) |
|
|
|
|
{ |
|
|
|
|
$courseId = empty($courseId) ? api_get_course_int_id() : (int) $courseId; |
|
|
|
|
$table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); |
|
|
|
|
$question_id = intval($this->id); |
|
|
|
|
$questionId = (int) $this->id; |
|
|
|
|
if (empty($courseId) || empty($questionId)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
$sql = "DELETE FROM $table |
|
|
|
|
WHERE |
|
|
|
|
question_id = $question_id AND |
|
|
|
|
c_id = ".api_get_course_int_id(); |
|
|
|
|
question_id = $questionId AND |
|
|
|
|
c_id = ".$courseId; |
|
|
|
|
Database::query($sql); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -599,7 +609,7 @@ abstract class Question |
|
|
|
|
*/ |
|
|
|
|
public function updateType($type) |
|
|
|
|
{ |
|
|
|
|
$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER); |
|
|
|
|
$table = Database::get_course_table(TABLE_QUIZ_ANSWER); |
|
|
|
|
$course_id = $this->course['real_id']; |
|
|
|
|
|
|
|
|
|
if (empty($course_id)) { |
|
|
|
|
@ -608,11 +618,11 @@ abstract class Question |
|
|
|
|
// if we really change the type |
|
|
|
|
if ($type != $this->type) { |
|
|
|
|
// if we don't change from "unique answer" to "multiple answers" (or conversely) |
|
|
|
|
if (!in_array($this->type, array(UNIQUE_ANSWER, MULTIPLE_ANSWER)) || |
|
|
|
|
!in_array($type, array(UNIQUE_ANSWER, MULTIPLE_ANSWER)) |
|
|
|
|
if (!in_array($this->type, [UNIQUE_ANSWER, MULTIPLE_ANSWER]) || |
|
|
|
|
!in_array($type, [UNIQUE_ANSWER, MULTIPLE_ANSWER]) |
|
|
|
|
) { |
|
|
|
|
// removes old answers |
|
|
|
|
$sql = "DELETE FROM $TBL_REPONSES |
|
|
|
|
$sql = "DELETE FROM $table |
|
|
|
|
WHERE c_id = $course_id AND question_id = ".intval($this->id); |
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
@ -1010,7 +1020,6 @@ abstract class Question |
|
|
|
|
if ($exercise->questionFeedbackEnabled) { |
|
|
|
|
$params['feedback'] = $this->feedback; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$this->id = Database::insert($TBL_QUESTIONS, $params); |
|
|
|
|
|
|
|
|
|
if ($this->id) { |
|
|
|
|
@ -1124,9 +1133,9 @@ abstract class Question |
|
|
|
|
if (Database::num_rows($res) > 0 || $addQs) { |
|
|
|
|
$di = new ChamiloIndexer(); |
|
|
|
|
if ($addQs) { |
|
|
|
|
$question_exercises = array((int) $exerciseId); |
|
|
|
|
$question_exercises = [(int) $exerciseId]; |
|
|
|
|
} else { |
|
|
|
|
$question_exercises = array(); |
|
|
|
|
$question_exercises = []; |
|
|
|
|
} |
|
|
|
|
isset($_POST['language']) ? $lang = Database::escape_string($_POST['language']) : $lang = 'english'; |
|
|
|
|
$di->connectDb(null, null, $lang); |
|
|
|
|
@ -1163,22 +1172,22 @@ abstract class Question |
|
|
|
|
$ic_slide->addValue("title", $this->question); |
|
|
|
|
$ic_slide->addCourseId($course_id); |
|
|
|
|
$ic_slide->addToolId(TOOL_QUIZ); |
|
|
|
|
$xapian_data = array( |
|
|
|
|
$xapian_data = [ |
|
|
|
|
SE_COURSE_ID => $course_id, |
|
|
|
|
SE_TOOL_ID => TOOL_QUIZ, |
|
|
|
|
SE_DATA => array( |
|
|
|
|
SE_DATA => [ |
|
|
|
|
'type' => SE_DOCTYPE_EXERCISE_QUESTION, |
|
|
|
|
'exercise_ids' => $question_exercises, |
|
|
|
|
'question_id' => (int) $this->id |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
SE_USER => (int) api_get_user_id(), |
|
|
|
|
); |
|
|
|
|
]; |
|
|
|
|
$ic_slide->xapian_data = serialize($xapian_data); |
|
|
|
|
$ic_slide->addValue("content", $this->description); |
|
|
|
|
|
|
|
|
|
//TODO: index answers, see also form validation on question_admin.inc.php |
|
|
|
|
|
|
|
|
|
$di->remove_document((int) $se_ref['search_did']); |
|
|
|
|
$di->remove_document($se_ref['search_did']); |
|
|
|
|
$di->addChunk($ic_slide); |
|
|
|
|
|
|
|
|
|
//index and return search engine document id |
|
|
|
|
@ -1233,7 +1242,6 @@ abstract class Question |
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -1389,7 +1397,6 @@ abstract class Question |
|
|
|
|
api_get_user_id() |
|
|
|
|
); |
|
|
|
|
$this->removePicture(); |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
// just removes the exercise from the list |
|
|
|
|
$this->removeFromList($deleteFromEx); |
|
|
|
|
@ -1412,17 +1419,17 @@ abstract class Question |
|
|
|
|
* Duplicates the question |
|
|
|
|
* |
|
|
|
|
* @author Olivier Brouckaert |
|
|
|
|
* @param array $course_info Course info of the destination course |
|
|
|
|
* @param array $courseInfo Course info of the destination course |
|
|
|
|
* @return false|string ID of the new question |
|
|
|
|
*/ |
|
|
|
|
public function duplicate($course_info = []) |
|
|
|
|
public function duplicate($courseInfo = []) |
|
|
|
|
{ |
|
|
|
|
if (empty($course_info)) { |
|
|
|
|
$course_info = $this->course; |
|
|
|
|
} else { |
|
|
|
|
$course_info = $course_info; |
|
|
|
|
$courseInfo = empty($courseInfo) ? $this->course : $courseInfo; |
|
|
|
|
|
|
|
|
|
if (empty($courseInfo)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION); |
|
|
|
|
$questionTable = Database::get_course_table(TABLE_QUIZ_QUESTION); |
|
|
|
|
$TBL_QUESTION_OPTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION); |
|
|
|
|
|
|
|
|
|
$question = $this->question; |
|
|
|
|
@ -1430,24 +1437,24 @@ abstract class Question |
|
|
|
|
$weighting = $this->weighting; |
|
|
|
|
$position = $this->position; |
|
|
|
|
$type = $this->type; |
|
|
|
|
$level = intval($this->level); |
|
|
|
|
$level = (int) $this->level; |
|
|
|
|
$extra = $this->extra; |
|
|
|
|
|
|
|
|
|
// Using the same method used in the course copy to transform URLs |
|
|
|
|
if ($this->course['id'] != $course_info['id']) { |
|
|
|
|
if ($this->course['id'] != $courseInfo['id']) { |
|
|
|
|
$description = DocumentManager::replaceUrlWithNewCourseCode( |
|
|
|
|
$description, |
|
|
|
|
$this->course['code'], |
|
|
|
|
$course_info['id'] |
|
|
|
|
$courseInfo['id'] |
|
|
|
|
); |
|
|
|
|
$question = DocumentManager::replaceUrlWithNewCourseCode( |
|
|
|
|
$question, |
|
|
|
|
$this->course['code'], |
|
|
|
|
$course_info['id'] |
|
|
|
|
$courseInfo['id'] |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$course_id = $course_info['real_id']; |
|
|
|
|
$course_id = $courseInfo['real_id']; |
|
|
|
|
|
|
|
|
|
// Read the source options |
|
|
|
|
$options = self::readQuestionOption($this->id, $this->course['real_id']); |
|
|
|
|
@ -1463,10 +1470,10 @@ abstract class Question |
|
|
|
|
'level' => $level, |
|
|
|
|
'extra' => $extra |
|
|
|
|
]; |
|
|
|
|
$newQuestionId = Database::insert($TBL_QUESTIONS, $params); |
|
|
|
|
$newQuestionId = Database::insert($questionTable, $params); |
|
|
|
|
|
|
|
|
|
if ($newQuestionId) { |
|
|
|
|
$sql = "UPDATE $TBL_QUESTIONS |
|
|
|
|
$sql = "UPDATE $questionTable |
|
|
|
|
SET id = iid |
|
|
|
|
WHERE iid = $newQuestionId"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
@ -1489,7 +1496,7 @@ abstract class Question |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Duplicates the picture of the hotspot |
|
|
|
|
$this->exportPicture($newQuestionId, $course_info); |
|
|
|
|
$this->exportPicture($newQuestionId, $courseInfo); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $newQuestionId; |
|
|
|
|
@ -1591,10 +1598,10 @@ abstract class Question |
|
|
|
|
$form->addElement('hidden', 'answerType', $answerType); |
|
|
|
|
|
|
|
|
|
// html editor |
|
|
|
|
$editorConfig = array( |
|
|
|
|
$editorConfig = [ |
|
|
|
|
'ToolbarSet' => 'TestQuestionDescription', |
|
|
|
|
'Height' => '150' |
|
|
|
|
); |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
if (!api_is_allowed_to_edit(null, true)) { |
|
|
|
|
$editorConfig['UserStatus'] = 'student'; |
|
|
|
|
@ -1637,7 +1644,7 @@ abstract class Question |
|
|
|
|
|
|
|
|
|
switch ($this->type) { |
|
|
|
|
case UNIQUE_ANSWER: |
|
|
|
|
$buttonGroup = array(); |
|
|
|
|
$buttonGroup = []; |
|
|
|
|
$buttonGroup[] = $form->addButtonSave( |
|
|
|
|
$text, |
|
|
|
|
'submitQuestion', |
|
|
|
|
@ -1656,7 +1663,7 @@ abstract class Question |
|
|
|
|
$form->addGroup($buttonGroup); |
|
|
|
|
break; |
|
|
|
|
case MULTIPLE_ANSWER: |
|
|
|
|
$buttonGroup = array(); |
|
|
|
|
$buttonGroup = []; |
|
|
|
|
$buttonGroup[] = $form->addButtonSave( |
|
|
|
|
$text, |
|
|
|
|
'submitQuestion', |
|
|
|
|
@ -1712,9 +1719,8 @@ abstract class Question |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// default values |
|
|
|
|
$defaults = array(); |
|
|
|
|
$defaults = []; |
|
|
|
|
$defaults['questionName'] = $this->question; |
|
|
|
|
$defaults['questionDescription'] = $this->description; |
|
|
|
|
$defaults['questionLevel'] = $this->level; |
|
|
|
|
@ -1790,10 +1796,10 @@ 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( |
|
|
|
|
$question_type_custom_list = [ |
|
|
|
|
UNIQUE_ANSWER => self::$questionTypes[UNIQUE_ANSWER], |
|
|
|
|
HOT_SPOT_DELINEATION => self::$questionTypes[HOT_SPOT_DELINEATION] |
|
|
|
|
); |
|
|
|
|
]; |
|
|
|
|
} else { |
|
|
|
|
unset($question_type_custom_list[HOT_SPOT_DELINEATION]); |
|
|
|
|
} |
|
|
|
|
@ -1887,12 +1893,12 @@ abstract class Question |
|
|
|
|
$table = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION); |
|
|
|
|
Database::delete( |
|
|
|
|
$table, |
|
|
|
|
array( |
|
|
|
|
'c_id = ? AND question_id = ?' => array( |
|
|
|
|
[ |
|
|
|
|
'c_id = ? AND question_id = ?' => [ |
|
|
|
|
$course_id, |
|
|
|
|
$question_id |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
] |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -1908,7 +1914,7 @@ abstract class Question |
|
|
|
|
$result = Database::update( |
|
|
|
|
$table, |
|
|
|
|
$params, |
|
|
|
|
array('c_id = ? AND id = ?' => array($course_id, $id)) |
|
|
|
|
['c_id = ? AND id = ?' => [$course_id, $id]] |
|
|
|
|
); |
|
|
|
|
return $result; |
|
|
|
|
} |
|
|
|
|
@ -1924,15 +1930,15 @@ abstract class Question |
|
|
|
|
$result = Database::select( |
|
|
|
|
'*', |
|
|
|
|
$table, |
|
|
|
|
array( |
|
|
|
|
'where' => array( |
|
|
|
|
'c_id = ? AND question_id = ?' => array( |
|
|
|
|
[ |
|
|
|
|
'where' => [ |
|
|
|
|
'c_id = ? AND question_id = ?' => [ |
|
|
|
|
$course_id, |
|
|
|
|
$question_id |
|
|
|
|
) |
|
|
|
|
), |
|
|
|
|
] |
|
|
|
|
], |
|
|
|
|
'order' => 'id ASC' |
|
|
|
|
) |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
return $result; |
|
|
|
|
@ -1982,12 +1988,14 @@ abstract class Question |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// display question category, if any |
|
|
|
|
$header = TestCategory::returnCategoryAndTitle($this->id); |
|
|
|
|
$header = ''; |
|
|
|
|
if ($exercise->display_category_name) { |
|
|
|
|
$header = TestCategory::returnCategoryAndTitle($this->id); |
|
|
|
|
} |
|
|
|
|
$show_media = null; |
|
|
|
|
if ($show_media) { |
|
|
|
|
$header .= $this->show_media_content(); |
|
|
|
|
} |
|
|
|
|
// ofaj |
|
|
|
|
$scoreCurrent = [ |
|
|
|
|
'used' => $score['score'], |
|
|
|
|
'missing' => $score['weight'] |
|
|
|
|
@ -1998,7 +2006,7 @@ abstract class Question |
|
|
|
|
// Do not show the description (the text to read) if the question is of type READING_COMPREHENSION |
|
|
|
|
$header .= Display::div( |
|
|
|
|
$this->description, |
|
|
|
|
array('class' => 'question_description') |
|
|
|
|
['class' => 'question_description'] |
|
|
|
|
); |
|
|
|
|
} else { |
|
|
|
|
if ($score['pass'] == true) { |
|
|
|
|
@ -2114,7 +2122,7 @@ abstract class Question |
|
|
|
|
$img = $explanation = null; |
|
|
|
|
eval('$img = '.$tabQuestionList[$type][1].'::$typePicture;'); |
|
|
|
|
eval('$explanation = get_lang('.$tabQuestionList[$type][1].'::$explanationLangVar);'); |
|
|
|
|
return array($img, $explanation); |
|
|
|
|
return [$img, $explanation]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -2124,29 +2132,29 @@ abstract class Question |
|
|
|
|
* |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
static function get_course_medias( |
|
|
|
|
public static function get_course_medias( |
|
|
|
|
$course_id, |
|
|
|
|
$start = 0, |
|
|
|
|
$limit = 100, |
|
|
|
|
$sidx = "question", |
|
|
|
|
$sord = "ASC", |
|
|
|
|
$where_condition = array() |
|
|
|
|
$where_condition = [] |
|
|
|
|
) { |
|
|
|
|
$table_question = Database::get_course_table(TABLE_QUIZ_QUESTION); |
|
|
|
|
$default_where = array( |
|
|
|
|
'c_id = ? AND parent_id = 0 AND type = ?' => array( |
|
|
|
|
$default_where = [ |
|
|
|
|
'c_id = ? AND parent_id = 0 AND type = ?' => [ |
|
|
|
|
$course_id, |
|
|
|
|
MEDIA_QUESTION |
|
|
|
|
) |
|
|
|
|
); |
|
|
|
|
] |
|
|
|
|
]; |
|
|
|
|
$result = Database::select( |
|
|
|
|
'*', |
|
|
|
|
$table_question, |
|
|
|
|
array( |
|
|
|
|
[ |
|
|
|
|
'limit' => " $start, $limit", |
|
|
|
|
'where' => $default_where, |
|
|
|
|
'order' => "$sidx $sord" |
|
|
|
|
) |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
return $result; |
|
|
|
|
@ -2158,20 +2166,20 @@ abstract class Question |
|
|
|
|
* |
|
|
|
|
* @return int |
|
|
|
|
*/ |
|
|
|
|
static function get_count_course_medias($course_id) |
|
|
|
|
public static function get_count_course_medias($course_id) |
|
|
|
|
{ |
|
|
|
|
$table_question = Database::get_course_table(TABLE_QUIZ_QUESTION); |
|
|
|
|
$result = Database::select( |
|
|
|
|
'count(*) as count', |
|
|
|
|
$table_question, |
|
|
|
|
array( |
|
|
|
|
'where' => array( |
|
|
|
|
'c_id = ? AND parent_id = 0 AND type = ?' => array( |
|
|
|
|
[ |
|
|
|
|
'where' => [ |
|
|
|
|
'c_id = ? AND parent_id = 0 AND type = ?' => [ |
|
|
|
|
$course_id, |
|
|
|
|
MEDIA_QUESTION, |
|
|
|
|
), |
|
|
|
|
) |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
] |
|
|
|
|
], |
|
|
|
|
'first' |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
@ -2188,7 +2196,7 @@ abstract class Question |
|
|
|
|
public static function prepare_course_media_select($course_id) |
|
|
|
|
{ |
|
|
|
|
$medias = self::get_course_medias($course_id); |
|
|
|
|
$media_list = array(); |
|
|
|
|
$media_list = []; |
|
|
|
|
$media_list[0] = get_lang('NoMedia'); |
|
|
|
|
|
|
|
|
|
if (!empty($medias)) { |
|
|
|
|
@ -2200,19 +2208,19 @@ abstract class Question |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @return integer[] |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
public static function get_default_levels() |
|
|
|
|
{ |
|
|
|
|
$select_level = array( |
|
|
|
|
$levels = [ |
|
|
|
|
1 => 1, |
|
|
|
|
2 => 2, |
|
|
|
|
3 => 3, |
|
|
|
|
4 => 4, |
|
|
|
|
5 => 5 |
|
|
|
|
); |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
return $select_level; |
|
|
|
|
return $levels; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -2237,20 +2245,20 @@ abstract class Question |
|
|
|
|
*/ |
|
|
|
|
public function swapSimpleAnswerTypes() |
|
|
|
|
{ |
|
|
|
|
$oppositeAnswers = array( |
|
|
|
|
$oppositeAnswers = [ |
|
|
|
|
UNIQUE_ANSWER => MULTIPLE_ANSWER, |
|
|
|
|
MULTIPLE_ANSWER => UNIQUE_ANSWER |
|
|
|
|
); |
|
|
|
|
]; |
|
|
|
|
$this->type = $oppositeAnswers[$this->type]; |
|
|
|
|
Database::update( |
|
|
|
|
Database::get_course_table(TABLE_QUIZ_QUESTION), |
|
|
|
|
array('type' => $this->type), |
|
|
|
|
array('c_id = ? AND id = ?' => array($this->course['real_id'], $this->id)) |
|
|
|
|
['type' => $this->type], |
|
|
|
|
['c_id = ? AND id = ?' => [$this->course['real_id'], $this->id]] |
|
|
|
|
); |
|
|
|
|
$answerClasses = array( |
|
|
|
|
$answerClasses = [ |
|
|
|
|
UNIQUE_ANSWER => 'UniqueAnswer', |
|
|
|
|
MULTIPLE_ANSWER => 'MultipleAnswer' |
|
|
|
|
); |
|
|
|
|
]; |
|
|
|
|
$swappedAnswer = new $answerClasses[$this->type]; |
|
|
|
|
foreach ($this as $key => $value) { |
|
|
|
|
$swappedAnswer->$key = $value; |
|
|
|
|
|