Fixing question pool for orphan questions

skala
Julio Montoya 12 years ago
parent e21432f003
commit 78438d3b76
  1. 70
      main/exercice/question.class.php
  2. 1
      src/ChamiloLMS/Controller/ExerciseController.php

@ -2054,7 +2054,12 @@ abstract class Question
/**
* Get all questions
* @param array $options
* @param Application $app
* @param $categoryId
* @param $exerciseId
* @param $courseId
* @param $options
* @param bool $get_count
* @return array
*/
public static function getQuestions($app, $categoryId, $exerciseId, $courseId, $options, $get_count = false)
@ -2064,22 +2069,20 @@ abstract class Question
$questionPoolFields = array(
'question_session_id' => array(
'innerjoin' => " INNER JOIN ".Database::get_course_table(TABLE_QUIZ_TEST_QUESTION)." as quiz_rel_question_session ON (quiz_rel_question_session.question_id = s.iid)
INNER JOIN ".Database::get_course_table(TABLE_QUIZ_TEST)." as quizsession ON (quizsession.iid = quiz_rel_question_session.exercice_id)
INNER JOIN ".Database::get_main_table(TABLE_MAIN_SESSION)." session ON (session.id = quizsession.session_id)",
INNER JOIN ".Database::get_course_table(TABLE_QUIZ_TEST)." as quizsession ON (quizsession.iid = quiz_rel_question_session.exercice_id)
INNER JOIN ".Database::get_main_table(TABLE_MAIN_SESSION)." session ON (session.id = quizsession.session_id)",
'where' => 'session_id',
'inject_fields' => 'session.name as question_session_id, ',
),
'question_category_id' => array(
'innerjoin' => " INNER JOIN ".Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY)." as quiz_rel_cat ON (quiz_rel_cat.question_id = s.iid)
INNER JOIN ".Database::get_course_table(TABLE_QUIZ_CATEGORY)." as cat ON (cat.iid = quiz_rel_cat.category_id)
",
INNER JOIN ".Database::get_course_table(TABLE_QUIZ_CATEGORY)." as cat ON (cat.iid = quiz_rel_cat.category_id)",
'where' => 'quiz_rel_cat.category_id',
'inject_fields' => 'cat.title as question_category_id, ',
),
'question_exercise_id' => array(
'innerjoin' => " INNER JOIN ".Database::get_course_table(TABLE_QUIZ_TEST_QUESTION)." as quiz_rel_question ON (quiz_rel_question.question_id = s.iid)
INNER JOIN ".Database::get_course_table(TABLE_QUIZ_TEST)." as quizexercise ON (quizexercise.iid = quiz_rel_question.exercice_id)
",
INNER JOIN ".Database::get_course_table(TABLE_QUIZ_TEST)." as quizexercise ON (quizexercise.iid = quiz_rel_question.exercice_id) ",
'where' => 'quiz_rel_question.exercice_id',
'inject_fields' => 'quizexercise.title as question_exercise_id, ',
),
@ -2098,12 +2101,37 @@ abstract class Question
)
);
// Checking if you're looking for orphan questions.
$isOrphanQuestion = false;
if (isset($options['question'])) {
foreach ($options['question'] as $option) {
if (isset($option['field']) && $option['field'] == 'question_exercise_id') {
if ($option['data'] == 0) {
$isOrphanQuestion = true;
break;
}
}
}
}
// Special case for orphan questions.
if ($isOrphanQuestion) {
$questionPoolFields['question_exercise_id'] = array(
'innerjoin' => " LEFT JOIN ".Database::get_course_table(TABLE_QUIZ_TEST_QUESTION)." as quiz_rel_question ON (quiz_rel_question.question_id = s.iid)
LEFT JOIN ".Database::get_course_table(TABLE_QUIZ_TEST)." as quizexercise ON (quizexercise.iid = quiz_rel_question.exercice_id) ",
'where' => 'quiz_rel_question.exercice_id',
'inject_fields' => 'quizexercise.title as question_exercise_id, ',
);
}
$inject_extra_fields = null;
$inject_joins = null;
$where = $options['where'];
$newQuestionPoolField = array();
if (isset($options['question'])) {
foreach ($options['question'] as $question) {
if (isset($questionPoolFields[$question['field']])) {
@ -2115,6 +2143,7 @@ abstract class Question
$inject_question_fields = null;
$questionPoolFields = $newQuestionPoolField;
// Injecting inner joins.
foreach ($questionPoolFields as $field => $option) {
$where = str_replace($field, $option['where'], $where);
if (isset($option['innerjoin']) && !empty($option['innerjoin'])) {
@ -2162,10 +2191,18 @@ abstract class Question
$where .= " AND exercice_id = $exerciseId ";
}*/
// Orphan questions
if ($isOrphanQuestion) {
//$exerciseRelQuestionTable = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
//$extraCondition .= " INNER JOIN $exerciseRelQuestionTable e ON (s.iid = e.question_id)";
$where .= " OR quizexercise.active = -1 OR quiz_rel_question.exercice_id IS NULL";
}
if (!empty($courseId)) {
$courseId = intval($courseId);
$where .= " AND s.c_id = $courseId ";
}
//var_dump($inject_joins);
$query = " $select FROM $questionTable s $inject_joins $extraCondition WHERE 1=1 $where $inject_where $order $limit";
//echo $query.'<br />';
@ -2197,9 +2234,7 @@ abstract class Question
//var_dump($exerciseId);
// Including actions
foreach ($questions as &$question) {
if (empty($exerciseId)) {
// View.
$actions = Display::url(
$previewIcon,
@ -2221,9 +2256,7 @@ abstract class Question
)
)
);
} else {
// View.
$actions = Display::url(
$previewIcon,
@ -2313,7 +2346,7 @@ abstract class Question
// type
if (empty($courseCode)) {
// Session
// Session.
$sessionList = SessionManager::get_sessions_by_general_coach(api_get_user_id());
$fields = array();
if (!empty($sessionList)) {
@ -2332,7 +2365,7 @@ abstract class Question
);
}
// Courses
// Courses.
$courseList = CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id());
if (!empty($courseList)) {
@ -2354,7 +2387,7 @@ abstract class Question
$courseList = array(api_get_course_info());
}
// Categories
// Categories.
$string = null;
if (!empty($courseList)) {
@ -2399,7 +2432,7 @@ abstract class Question
$course = api_get_course_int_id();
$sessionId = api_get_session_id();
// Exercises
// Exercises.
$exerciseList = ExerciseLib::get_all_exercises_for_course_id($sessionId, $course);
if (!empty($exerciseList)) {
@ -2419,8 +2452,7 @@ abstract class Question
);
}
// Question type
// Question type.
$questionList = Question::get_question_type_list();
if (!empty($questionList)) {
@ -2439,7 +2471,7 @@ abstract class Question
);
}
// Difficult
// Difficult.
$levels = Question::get_default_levels();
if (!empty($levels)) {
@ -2467,7 +2499,6 @@ abstract class Question
if (!empty($fields)) {
foreach ($fields as $field) {
$search_options = array();
$type = 'text';
if (in_array($field['field_type'], array(ExtraField::FIELD_TYPE_SELECT, ExtraField::FIELD_TYPE_DOUBLE_SELECT))) {
@ -2492,7 +2523,6 @@ abstract class Question
'searchoptions' => $search_options
);
$columns[] = $field['field_display_text'];
$rules[] = array(
'field' => 'question_'.$field['field_variable'],
'op' => 'eq'

@ -150,7 +150,6 @@ class ExerciseController extends CommonController
$questionColumns = \Question::getQuestionColumns($cidReq);
//$questionColumns = \Question::getQuestionColumns($cidReq, null, null, true);
$columnModel = $questionColumns['column_model'];
$columns = $questionColumns['columns'];
$rules = $questionColumns['rules'];

Loading…
Cancel
Save