Fixed issue preventing global category to appear on inter-course linking of questions - refs BT#6917

skala
Yannick Warnier 12 years ago
parent 8eb7af0b00
commit 9f4b9c71e3
  1. 38
      main/exercice/question.class.php
  2. 17
      main/exercice/testcategory.class.php
  3. 1
      src/ChamiloLMS/Controller/ExerciseController.php

@ -2700,4 +2700,42 @@ abstract class Question
}
return $result;
}
/**
* Makes a question valid inside a global category in another course as well
* This might be used in combination with the ExerciseController::reuseQuestionAction()
* to make sure the "linked" question also has the global category
* Before this function, the only problematic bit was that copying a question
* didn't copy the reference to this question in the c_quiz_question_rel_category table,
* making the question itself in the new course appear without category
*
* This might get deprecated if we start using c_id = 0 in the c_quiz_question_rel_category
*/
function enableGlobalCategoryInNewCourse($questionId, $courseIdDest) {
$questionRelCategoryTable = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
$categoryTable = Database::get_course_table(TABLE_QUIZ_CATEGORY);
$questionId = intval($questionId);
$courseIdDest = intval($courseIdDest);
// First check whether the category is global: if it's not, we don't need to do anything
$sql = "SELECT iid, c_id, question_id, category_id FROM $questionRelCategoryTable WHERE question_id = $questionId";
$res = Database::query($sql);
if (Database::num_rows($res) < 1) {
return false;
}
$origCats = array();
$destCats = array();
while ($row = Database::fetch_assoc($res)) {
$g = Testcategory::isGlobal($row['category_id']);
if ($g) {
$origCats[] = $row['category_id'];
if ($row['c_id'] == $courseIdDest) {
$destCats[] = $row['category_id'];
}
}
}
$diff = array_diff($origCats,$destCats);
foreach ($diff as $cat) {
$sql = "INSERT INTO $questionRelCategoryTable (c_id, question_id, category_id) VALUES ($courseIdDest, $questionId, $cat)";
Database::query($sql);
}
}
}

@ -1286,4 +1286,21 @@ class Testcategory
// setting the rules
$form->addRule('category_name', get_lang('ThisFieldIsRequired'), 'required');
}
/**
* Checks whether a category is global or not
* @param Category ID
* @return bool True if it is global, false otherwise
* @assert (0) == false
*/
function isGlobal($categoryId) {
$categoryTable = Database::get_course_table(TABLE_QUIZ_CATEGORY);
$sql = "SELECT parent_id, c_id FROM $categoryTable WHERE iid = $categoryId";
$res = Database::query($sql);
if (Database::num_rows($res) < 1) {
return false;
}
$row = Database::fetch_assoc($res);
$global = ($row['c_id'] == 0 ? true : false);
return $global;
}
}

@ -86,6 +86,7 @@ class ExerciseController extends CommonController
// adds the question ID represented by $recup into the list of questions for the current exercise
$objExercise->addToList($questionId);
$question->enableGlobalCategoryInNewCourse($questionId, $objExercise->course_id);
Session::write('objExercise', $objExercise);
/*$params = array(
'cidReq' => api_get_course_id(),

Loading…
Cancel
Save