Fixing orphan questions bugs see BT#5854

1.9.x
Julio Montoya 12 years ago
parent 61310d72bd
commit 48fc6231b1
  1. 146
      main/coursecopy/classes/CourseBuilder.class.php
  2. 41
      main/coursecopy/classes/CourseRecycler.class.php
  3. 150
      main/exercice/question_pool.php

@ -29,7 +29,8 @@ require_once 'Attendance.class.php';
* @author Bart Mollet <bart.mollet@hogent.be> * @author Bart Mollet <bart.mollet@hogent.be>
* @package chamilo.backup * @package chamilo.backup
*/ */
class CourseBuilder { class CourseBuilder
{
/** Course */ /** Course */
public $course; public $course;
@ -59,8 +60,9 @@ class CourseBuilder {
/** /**
* Create a new CourseBuilder * Create a new CourseBuilder
*/ */
function __construct($type='', $course = null) { public function __construct($type='', $course = null)
global $_course; {
$_course = api_get_course_info();
if (!empty($course['official_code'])){ if (!empty($course['official_code'])){
$_course = $course; $_course = $course;
@ -80,7 +82,8 @@ class CourseBuilder {
* *
* @param type $array * @param type $array
*/ */
function set_tools_to_build($array) { function set_tools_to_build($array)
{
$this->tools_to_build = $array; $this->tools_to_build = $array;
} }
@ -88,7 +91,8 @@ class CourseBuilder {
* *
* @param type $array * @param type $array
*/ */
function set_tools_specific_id_list($array) { function set_tools_specific_id_list($array)
{
$this->specific_id_list = $array; $this->specific_id_list = $array;
} }
@ -96,7 +100,8 @@ class CourseBuilder {
* Get the created course * Get the created course
* @return course The course * @return course The course
*/ */
function get_course() { function get_course()
{
return $this->course; return $this->course;
} }
@ -108,7 +113,8 @@ class CourseBuilder {
* @param bool true if you want to get the elements that exists in the course and * @param bool true if you want to get the elements that exists in the course and
* in the session, (session_id = 0 or session_id = X) * in the session, (session_id = 0 or session_id = X)
*/ */
function build($session_id = 0, $course_code = '', $with_base_content = false) { function build($session_id = 0, $course_code = '', $with_base_content = false)
{
$table_link = Database :: get_course_table(TABLE_LINKED_RESOURCES); $table_link = Database :: get_course_table(TABLE_LINKED_RESOURCES);
$table_properties = Database :: get_course_table(TABLE_ITEM_PROPERTY); $table_properties = Database :: get_course_table(TABLE_ITEM_PROPERTY);
@ -117,35 +123,8 @@ class CourseBuilder {
foreach ($this->tools_to_build as $tool) { foreach ($this->tools_to_build as $tool) {
$function_build = 'build_'.$tool; $function_build = 'build_'.$tool;
$this->$function_build($session_id, $course_code, $with_base_content, $this->specific_id_list[$tool]); $specificIdList = isset($this->specific_id_list[$tool]) ? $this->specific_id_list[$tool] : null;
} $this->$function_build($session_id, $course_code, $with_base_content, $specificIdList);
if (!empty($session_id) && !empty($course_code)) {
/*$this->build_documents($session_id, $course_code, $with_base_content);
$this->build_quizzes($session_id, $course_code, $with_base_content);
$this->build_glossary($session_id, $course_code, $with_base_content);
$this->build_learnpaths($session_id, $course_code,$with_base_content);
$this->build_links($session_id, $course_code, $with_base_content);
$this->build_course_descriptions($session_id, $course_code, $with_base_content);
$this->build_wiki($session_id, $course_code, $with_base_content);
//$this->build_thematic($session_id, $course_code, $with_base_content);
$this->build_thematic();
$this->build_attendance();*/
} else {
/*$this->build_events();
$this->build_announcements();
$this->build_links();
$this->build_tool_intro();
$this->build_documents();
$this->build_course_descriptions();
$this->build_wiki();
$this->build_quizzes();
$this->build_learnpaths();
$this->build_surveys();
$this->build_glossary();
$this->build_thematic();
$this->build_attendance();*/
} }
//TABLE_LINKED_RESOURCES is the "resource" course table, which is deprecated, apparently //TABLE_LINKED_RESOURCES is the "resource" course table, which is deprecated, apparently
@ -180,7 +159,8 @@ class CourseBuilder {
/** /**
* Build the documents * Build the documents
*/ */
function build_documents($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array()) { function build_documents($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
{
$course_info = api_get_course_info($course_code); $course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id']; $course_id = $course_info['real_id'];
@ -265,7 +245,8 @@ class CourseBuilder {
/** /**
* Build the forums * Build the forums
*/ */
function build_forums($session_id = 0, $course_code = null, $with_base_content = false, $id_list = array()) { function build_forums($session_id = 0, $course_code = null, $with_base_content = false, $id_list = array())
{
$course_info = api_get_course_info($course_code); $course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id']; $course_id = $course_info['real_id'];
@ -283,7 +264,8 @@ class CourseBuilder {
/** /**
* Build a forum-category * Build a forum-category
*/ */
function build_forum_category($session_id = 0, $course_code = null, $with_base_content = false, $id_list = array()) { function build_forum_category($session_id = 0, $course_code = null, $with_base_content = false, $id_list = array())
{
$table = Database :: get_course_table(TABLE_FORUM_CATEGORY); $table = Database :: get_course_table(TABLE_FORUM_CATEGORY);
$course_info = api_get_course_info($course_code); $course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id']; $course_id = $course_info['real_id'];
@ -299,7 +281,8 @@ class CourseBuilder {
/** /**
* Build the forum-topics * Build the forum-topics
*/ */
function build_forum_topics($session_id = 0, $course_code = null, $with_base_content = false, $id_list = array()) { function build_forum_topics($session_id = 0, $course_code = null, $with_base_content = false, $id_list = array())
{
$table = Database :: get_course_table(TABLE_FORUM_THREAD); $table = Database :: get_course_table(TABLE_FORUM_THREAD);
$course_info = api_get_course_info($course_code); $course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id']; $course_id = $course_info['real_id'];
@ -317,7 +300,8 @@ class CourseBuilder {
* Build the forum-posts * Build the forum-posts
* TODO: All tree structure of posts should be built, attachments for example. * TODO: All tree structure of posts should be built, attachments for example.
*/ */
function build_forum_posts($thread_id = null, $forum_id = null, $only_first_post = false) { function build_forum_posts($thread_id = null, $forum_id = null, $only_first_post = false)
{
$table = Database :: get_course_table(TABLE_FORUM_POST); $table = Database :: get_course_table(TABLE_FORUM_POST);
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$sql = "SELECT * FROM $table WHERE c_id = $course_id "; $sql = "SELECT * FROM $table WHERE c_id = $course_id ";
@ -337,7 +321,8 @@ class CourseBuilder {
/** /**
* Build the links * Build the links
*/ */
function build_links($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array()) { function build_links($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
{
$course_info = api_get_course_info($course_code); $course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id']; $course_id = $course_info['real_id'];
@ -382,7 +367,8 @@ class CourseBuilder {
/** /**
* Build tool intro * Build tool intro
*/ */
function build_tool_intro($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array()) { function build_tool_intro($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
{
$table = Database :: get_course_table(TABLE_TOOL_INTRO); $table = Database :: get_course_table(TABLE_TOOL_INTRO);
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$sql = "SELECT * FROM $table WHERE c_id = $course_id "; $sql = "SELECT * FROM $table WHERE c_id = $course_id ";
@ -396,7 +382,8 @@ class CourseBuilder {
/** /**
* Build a link category * Build a link category
*/ */
function build_link_category($id, $course_code = '') { function build_link_category($id, $course_code = '')
{
$course_info = api_get_course_info($course_code); $course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id']; $course_id = $course_info['real_id'];
@ -415,7 +402,8 @@ class CourseBuilder {
/** /**
* Build the Quizzes * Build the Quizzes
*/ */
function build_quizzes($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array()) { function build_quizzes($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
{
$course_info = api_get_course_info($course_code); $course_info = api_get_course_info($course_code);
$table_qui = Database :: get_course_table(TABLE_QUIZ_TEST); $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
$table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION); $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
@ -463,7 +451,8 @@ class CourseBuilder {
/** /**
* Build the Quiz-Questions * Build the Quiz-Questions
*/ */
function build_quiz_questions($course_code = null) { function build_quiz_questions($course_code = null)
{
$course_info = api_get_course_info($course_code); $course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id']; $course_id = $course_info['real_id'];
@ -474,12 +463,14 @@ class CourseBuilder {
// Building normal tests. // Building normal tests.
$sql = "SELECT * FROM $table_que WHERE c_id = $course_id "; $sql = "SELECT * FROM $table_que WHERE c_id = $course_id ";
$db_result = Database::query($sql);
$db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) { while ($obj = Database::fetch_object($db_result)) {
$question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture, $obj->level, $obj->extra); $question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture, $obj->level, $obj->extra);
$sql = 'SELECT * FROM '.$table_ans.' WHERE c_id = '.$course_id.' AND question_id = '.$obj->id; $sql = 'SELECT * FROM '.$table_ans.' WHERE c_id = '.$course_id.' AND question_id = '.$obj->id;
$db_result2 = Database::query($sql); $db_result2 = Database::query($sql);
while ($obj2 = Database::fetch_object($db_result2)) { while ($obj2 = Database::fetch_object($db_result2)) {
$question->add_answer($obj2->id, $obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type); $question->add_answer($obj2->id, $obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type);
if ($obj->type == MULTIPLE_ANSWER_TRUE_FALSE) { if ($obj->type == MULTIPLE_ANSWER_TRUE_FALSE) {
@ -498,21 +489,38 @@ class CourseBuilder {
// Building a fictional test for collecting orphan questions. // Building a fictional test for collecting orphan questions.
$build_orphan_questions = !empty($_POST['recycle_option']); // When a course is emptied this option should be activated (true). $build_orphan_questions = !empty($_POST['recycle_option']); // When a course is emptied this option should be activated (true).
$sql = "SELECT questions.* //1st union gets the orphan questions from deleted exercises
FROM $table_que as questions //2nd union gets the orphan questions from question that were deleted in a exercise.
LEFT JOIN $table_rel as quizz_questions $sql = " (
ON (questions.id = quizz_questions.question_id AND questions.c_id = $course_id AND quizz_questions.c_id = $course_id) SELECT question_id, q.* FROM $table_que q INNER JOIN $table_rel r
LEFT JOIN $table_qui as exercices ON (q.c_id = r.c_id AND q.id = r.question_id)
ON (exercice_id = exercices.id AND exercices.c_id = $course_id AND questions.c_id = $course_id) INNER JOIN $table_qui ex
WHERE questions.c_id = $course_id AND ON (ex.id = r.exercice_id AND ex.c_id = r.c_id )
exercices.c_id = $course_id AND WHERE ex.c_id = $course_id AND ex.active = '-1'
(quizz_questions.exercice_id IS NULL OR exercices.active = -1) "; // active = -1 means "deleted" test. )
UNION
(
SELECT question_id, q.* FROM $table_que q left
OUTER JOIN $table_rel r
ON (q.c_id = r.c_id AND q.id = r.question_id)
WHERE q.c_id = $course_id AND r.question_id is null
)
UNION
(
SELECT question_id, q.* FROM $table_que q
INNER JOIN $table_rel r
ON (q.c_id = r.c_id AND q.id = r.question_id)
WHERE r.c_id = $course_id AND (r.exercice_id = '-1' OR r.exercice_id = '0')
)
";
$db_result = Database::query($sql); $db_result = Database::query($sql);
if (Database::num_rows($db_result) > 0) { if (Database::num_rows($db_result) > 0) {
$build_orphan_questions = true; $build_orphan_questions = true;
$orphanQuestionIds = array();
while ($obj = Database::fetch_object($db_result)) { while ($obj = Database::fetch_object($db_result)) {
//Avoid adding the same question twice //Avoid adding the same question twice
$obj->id = $obj->question_id;
if (!isset($this->course->resources[$obj->id])) { if (!isset($this->course->resources[$obj->id])) {
$question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level, $obj->extra); $question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level, $obj->extra);
$sql = "SELECT * FROM $table_ans WHERE c_id = $course_id AND question_id = ".$obj->id; $sql = "SELECT * FROM $table_ans WHERE c_id = $course_id AND question_id = ".$obj->id;
@ -521,6 +529,7 @@ class CourseBuilder {
while ($obj2 = Database::fetch_object($db_result2)) { while ($obj2 = Database::fetch_object($db_result2)) {
$question->add_answer($obj2->id, $obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type); $question->add_answer($obj2->id, $obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type);
} }
$orphanQuestionIds[] = $obj->id;
} }
$this->course->add_resource($question); $this->course->add_resource($question);
} }
@ -530,16 +539,26 @@ class CourseBuilder {
if ($build_orphan_questions) { if ($build_orphan_questions) {
$obj = array( $obj = array(
'id' => -1, 'id' => -1,
'title' => get_lang('OrphanQuestions', '') 'title' => get_lang('OrphanQuestions', ''),
'type' => 2
); );
$this->course->add_resource(new Quiz((object)$obj)); $newQuiz = new Quiz((object)$obj);
var_dump($orphanQuestionIds);
if (!empty($orphanQuestionIds)) {
foreach ($orphanQuestionIds as $index => $orphanId) {
$order = $index + 1;
$newQuiz->add_question($orphanId, $order);
}
}
$this->course->add_resource($newQuiz);
} }
} }
/** /**
* Build the orphan questions * Build the orphan questions
*/ */
function build_quiz_orphan_questions() { function build_quiz_orphan_questions()
{
$table_qui = Database :: get_course_table(TABLE_QUIZ_TEST); $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
$table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION); $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
$table_que = Database :: get_course_table(TABLE_QUIZ_QUESTION); $table_que = Database :: get_course_table(TABLE_QUIZ_QUESTION);
@ -562,13 +581,11 @@ class CourseBuilder {
if (Database::num_rows($db_result) > 0) { if (Database::num_rows($db_result) > 0) {
$orphan_questions = new Quiz(-1, get_lang('OrphanQuestions', ''), '', 0, 0, 1, '', 0); // Tjis is the fictional test for collecting orphan questions. $orphan_questions = new Quiz(-1, get_lang('OrphanQuestions', ''), '', 0, 0, 1, '', 0); // Tjis is the fictional test for collecting orphan questions.
$this->course->add_resource($orphan_questions); $this->course->add_resource($orphan_questions);
while ($obj = Database::fetch_object($db_result)) while ($obj = Database::fetch_object($db_result)) {
{
$question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level,$obj->extra); $question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level,$obj->extra);
$sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.$obj->id; $sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.$obj->id;
$db_result2 = Database::query($sql); $db_result2 = Database::query($sql);
while ($obj2 = Database::fetch_object($db_result2)) while ($obj2 = Database::fetch_object($db_result2)) {
{
$question->add_answer($obj2->id, $obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type); $question->add_answer($obj2->id, $obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type);
} }
$this->course->add_resource($question); $this->course->add_resource($question);
@ -579,7 +596,8 @@ class CourseBuilder {
/** /**
* Build the Surveys * Build the Surveys
*/ */
function build_surveys($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array()) { function build_surveys($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
{
$table_survey = Database :: get_course_table(TABLE_SURVEY); $table_survey = Database :: get_course_table(TABLE_SURVEY);
$table_question = Database :: get_course_table(TABLE_SURVEY_QUESTION); $table_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();

@ -303,7 +303,8 @@ class CourseRecycler
/** /**
* Recycle quizzes - doesn't remove the questions and their answers, as they might still be used later * Recycle quizzes - doesn't remove the questions and their answers, as they might still be used later
*/ */
function recycle_quizzes() { function recycle_quizzes()
{
if ($this->course->has_resources(RESOURCE_QUIZ)) { if ($this->course->has_resources(RESOURCE_QUIZ)) {
$table_qui_que = Database :: get_course_table(TABLE_QUIZ_QUESTION); $table_qui_que = Database :: get_course_table(TABLE_QUIZ_QUESTION);
$table_qui_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER); $table_qui_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
@ -319,7 +320,7 @@ class CourseRecycler
// This value is set in CourseBuilder::quiz_build_questions() // This value is set in CourseBuilder::quiz_build_questions()
$delete_orphan_questions = in_array(-1, $ids); $delete_orphan_questions = in_array(-1, $ids);
$ids = implode(',', $ids); $ids = implode(',', $ids);
if (!empty($ids)) { if (!empty($ids)) {
// Deletion of the tests first. Questions in these tests are // Deletion of the tests first. Questions in these tests are
// not deleted and become orphan at this point // not deleted and become orphan at this point
@ -331,19 +332,29 @@ class CourseRecycler
// Identifying again and deletion of the orphan questions, if it was desired. // Identifying again and deletion of the orphan questions, if it was desired.
if ($delete_orphan_questions) { if ($delete_orphan_questions) {
$sql = 'SELECT questions.id '.
' FROM '.$table_qui_que.' as questions '. $sql = " (
' LEFT JOIN '.$table_rel.' as quizz_questions '. SELECT q.id, ex.c_id FROM $table_qui_que q
' ON questions.id=quizz_questions.question_id '. INNER JOIN $table_rel r
' LEFT JOIN '.$table_qui.' as exercices '. ON (q.c_id = r.c_id AND q.id = r.question_id)
' ON exercice_id=exercices.id '. INNER JOIN $table_qui ex
' WHERE '. ON (ex.id = r.exercice_id AND ex.c_id = r.c_id)
' questions.c_id = '.$this->course_id.' AND '. WHERE ex.c_id = ".$this->course_id." AND (ex.active = '-1' OR ex.id = '-1')
' quizz_questions.c_id = '.$this->course_id.' AND '. )
' exercices.c_id = '.$this->course_id.' AND '. UNION
' quizz_questions.exercice_id IS NULL OR '. (
' exercices.active = -1'; SELECT q.id, r.c_id FROM $table_qui_que q
// active = -1 means "deleted" test. LEFT OUTER JOIN $table_rel r
ON (q.c_id = r.c_id AND q.id = r.question_id)
WHERE q.c_id = ".$this->course_id." AND r.question_id is null
)
UNION
(
SELECT q.id, r.c_id FROM $table_qui_que q
INNER JOIN $table_rel r
ON (q.c_id = r.c_id AND q.id = r.question_id)
WHERE r.c_id = ".$this->course_id." AND (r.exercice_id = '-1' OR r.exercice_id = '0')
)";
$db_result = Database::query($sql); $db_result = Database::query($sql);
if (Database::num_rows($db_result) > 0) { if (Database::num_rows($db_result) > 0) {
$orphan_ids = array(); $orphan_ids = array();

@ -27,7 +27,7 @@ require_once 'exercise.lib.php';
$this_section = SECTION_COURSES; $this_section = SECTION_COURSES;
$is_allowedToEdit=api_is_allowed_to_edit(null,true); $is_allowedToEdit = api_is_allowed_to_edit(null,true);
if (empty($delete)) { if (empty($delete)) {
$delete = intval($_GET['delete']); $delete = intval($_GET['delete']);
@ -112,7 +112,7 @@ if ($is_allowedToEdit) {
// destruction of the Question object // destruction of the Question object
unset($new_question_obj); unset($new_question_obj);
unset($old_question_obj); unset($old_question_obj);
if (!$objExcercise instanceOf Exercise) { if (!$objExercise instanceOf Exercise) {
$objExercise = new Exercise(); $objExercise = new Exercise();
$objExercise->read($fromExercise); $objExercise->read($fromExercise);
} }
@ -142,7 +142,7 @@ if ($is_allowedToEdit) {
// destruction of the Question object // destruction of the Question object
unset($objQuestionTmp); unset($objQuestionTmp);
if (!$objExcercise instanceOf Exercise) { if (!$objExercise instanceOf Exercise) {
$objExercise = new Exercise(); $objExercise = new Exercise();
$objExercise->read($fromExercise); $objExercise->read($fromExercise);
} }
@ -162,22 +162,6 @@ if ($is_allowedToEdit) {
$current_course = api_get_course_info(); $current_course = api_get_course_info();
foreach ($question_data as $old_question_id) { foreach ($question_data as $old_question_id) {
/*
$recup = intval($recup);
// if the question exists
if($objQuestionTmp = Question :: read($recup)) {
// adds the exercise ID represented by $fromExercise into the list of exercises for the current question
$objQuestionTmp->addToList($fromExercise);
}
// destruction of the Question object
unset($objQuestionTmp);
if(!$objExcercise instanceOf Exercise) {
$objExercise = new Exercise();
$objExercise->read($fromExercise);
}
// adds the question ID represented by $recup into the list of questions for the current exercise
$objExercise->addToList($recup);
*/
//Reading the source question //Reading the source question
$old_question_obj = Question::read($old_question_id, $origin_course_id); $old_question_obj = Question::read($old_question_id, $origin_course_id);
@ -202,7 +186,7 @@ if ($is_allowedToEdit) {
unset($new_question_obj); unset($new_question_obj);
unset($old_question_obj); unset($old_question_obj);
if (!$objExcercise instanceOf Exercise) { if (!$objExercise instanceOf Exercise) {
$objExercise = new Exercise(); $objExercise = new Exercise();
$objExercise->read($fromExercise); $objExercise->read($fromExercise);
} }
@ -210,8 +194,6 @@ if ($is_allowedToEdit) {
} }
} }
Session::write('objExercise',$objExercise); Session::write('objExercise',$objExercise);
// header("Location: admin.php?".api_get_cidreq()."&exerciseId=$fromExercise");
// exit();
} }
} }
@ -231,7 +213,7 @@ if (!$is_allowedToEdit) {
$confirmYourChoice = addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)); $confirmYourChoice = addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset));
$htmlHeadXtra[] = " $htmlHeadXtra[] = "
<script type='text/javascript'> <script>
function submit_form(obj) { function submit_form(obj) {
document.question_pool.submit(); document.question_pool.submit();
} }
@ -261,8 +243,7 @@ echo '<div class="actions">';
if (isset($fromExercise) && $fromExercise > 0) { if (isset($fromExercise) && $fromExercise > 0) {
echo '<a href="admin.php?'.api_get_cidreq().'&exerciseId='.$fromExercise.'">'.Display::return_icon('back.png', get_lang('GoBackToQuestionList'),'',ICON_SIZE_MEDIUM).'</a>'; echo '<a href="admin.php?'.api_get_cidreq().'&exerciseId='.$fromExercise.'">'.Display::return_icon('back.png', get_lang('GoBackToQuestionList'),'',ICON_SIZE_MEDIUM).'</a>';
$titleAdd = get_lang('AddQuestionToTest'); $titleAdd = get_lang('AddQuestionToTest');
} } else {
else {
echo '<a href="exercice.php?'.api_get_cidReq().'">'.Display::return_icon('back.png', get_lang('BackToExercisesList'),'',ICON_SIZE_MEDIUM).'</a>'; echo '<a href="exercice.php?'.api_get_cidReq().'">'.Display::return_icon('back.png', get_lang('BackToExercisesList'),'',ICON_SIZE_MEDIUM).'</a>';
echo "<a href='admin.php?exerciseId=0'>".Display::return_icon('add_question.gif', get_lang('NewQu'), '', 32)."</a>"; echo "<a href='admin.php?exerciseId=0'>".Display::return_icon('add_question.gif', get_lang('NewQu'), '', 32)."</a>";
$titleAdd = get_lang('ManageAllQuestions'); $titleAdd = get_lang('ManageAllQuestions');
@ -429,21 +410,18 @@ if ($exerciseId > 0) {
$TBL_QUESTIONS qu $TBL_QUESTIONS qu
$from $from
WHERE WHERE
qt.question_id=qu.id qt.question_id = qu.id
AND qt.exercice_id=$exerciseId AND qt.exercice_id=$exerciseId
AND qt.c_id=$selected_course AND qt.c_id=$selected_course
AND qu.c_id=$selected_course AND qu.c_id=$selected_course
$where $where
ORDER BY ORDER BY question_order";
question_order";
$result=Database::query($sql); $result=Database::query($sql);
while($row = Database::fetch_array($result, 'ASSOC')) { while($row = Database::fetch_array($result, 'ASSOC')) {
$main_question_list[] = $row; $main_question_list[] = $row;
} }
} elseif ($exerciseId == -1) { } elseif ($exerciseId == -1) {
// // If we have selected the option 'Orphan questions' in the list-box 'Filter'
// if we have selected the option 'Orphan questions' in the list-box 'Filter'
//
$level_where = ''; $level_where = '';
$from = ''; $from = '';
if (isset($courseCategoryId) && $courseCategoryId > 0) { if (isset($courseCategoryId) && $courseCategoryId > 0) {
@ -457,22 +435,47 @@ if ($exerciseId > 0) {
if (isset($answerType) && $answerType >0 -1 ) { if (isset($answerType) && $answerType >0 -1 ) {
$answer_where = ' AND type='.$answerType; $answer_where = ' AND type='.$answerType;
} }
$sql = "SELECT DISTINCT * FROM $TBL_QUESTIONS qu $from WHERE qu.c_id=$selected_course AND qu.id NOT IN (SELECT question_id FROM $TBL_EXERCICE_QUESTION WHERE c_id=$selected_course ) $level_where $answer_where"; /*$sql = "SELECT DISTINCT * FROM $TBL_QUESTIONS qu $from
WHERE qu.c_id = $selected_course AND qu.id NOT IN (
SELECT question_id FROM $TBL_EXERCICE_QUESTION
WHERE c_id=$selected_course
) $level_where $answer_where";*/
// @todo fix this query with the new id field
$sql = " (
SELECT q.* FROM $TBL_QUESTIONS q INNER JOIN $TBL_EXERCICE_QUESTION r
ON (q.c_id = r.c_id AND q.id = r.question_id)
INNER JOIN $TBL_EXERCICES ex
ON (ex.id = r.exercice_id AND ex.c_id = r.c_id ) $from
WHERE ex.c_id = '$selected_course' AND ex.active = '-1' $level_where $answer_where
)
UNION
(
SELECT q.* FROM $TBL_QUESTIONS q
LEFT OUTER JOIN $TBL_EXERCICE_QUESTION r
ON (q.c_id = r.c_id AND q.id = r.question_id)
WHERE q.c_id = '$selected_course' AND r.question_id is null $level_where $answer_where
)
UNION
(
SELECT q.* FROM $TBL_QUESTIONS q
INNER JOIN $TBL_EXERCICE_QUESTION r
ON (q.c_id = r.c_id AND q.id = r.question_id)
WHERE r.c_id = '$selected_course' AND (r.exercice_id = '-1' OR r.exercice_id = '0') $level_where $answer_where
)";
$result = Database::query($sql); $result = Database::query($sql);
while($row = Database::fetch_array($result, 'ASSOC')) { while($row = Database::fetch_array($result, 'ASSOC')) {
$main_question_list[] = $row; $main_question_list[] = $row;
} }
} } else {
else {
//
// All tests for selected course // All tests for selected course
// // If we have not selected any option in the list-box 'Filter'
// if we have not selected any option in the list-box 'Filter'
$filter = ''; $filter = '';
$from = ''; $from = '';
if (isset($courseCategoryId) && $courseCategoryId > 0) { if (isset($courseCategoryId) && $courseCategoryId > 0) {
$from = ", $TBL_COURSE_REL_CATEGORY crc "; $from = ", $TBL_COURSE_REL_CATEGORY crc ";
$filter .= " AND crc.c_id=$selected_course AND crc.question_id=qu.id AND crc.category_id=$courseCategoryId"; $filter .= " AND crc.c_id = $selected_course AND crc.question_id = qu.id AND crc.category_id = $courseCategoryId";
} }
if (isset($exerciseLevel) && $exerciseLevel != -1) { if (isset($exerciseLevel) && $exerciseLevel != -1) {
$filter .= ' AND level='.$exerciseLevel.' '; $filter .= ' AND level='.$exerciseLevel.' ';
@ -480,14 +483,6 @@ else {
if (isset($answerType) && $answerType > 0) { if (isset($answerType) && $answerType > 0) {
$filter .= ' AND qu.type='.$answerType.' '; $filter .= ' AND qu.type='.$answerType.' ';
} }
// // why these lines ?
// if ($objExercise->feedback_type != EXERCISE_FEEDBACK_TYPE_DIRECT) {
// $filter .= ' AND qu.type <> '.HOT_SPOT_DELINEATION.' ';
// }
// // fwhy
//
// if in session
//
if (!empty($session_id) && $session_id != '-1') { if (!empty($session_id) && $session_id != '-1') {
$main_question_list = array(); $main_question_list = array();
if (!empty($course_list)) if (!empty($course_list))
@ -541,8 +536,14 @@ else {
else { else {
// //
// All tests for the course selected, not in session // All tests for the course selected, not in session
// $sql = "SELECT DISTINCT qu.id, question, qu.type, level, q.session_id
$sql = "SELECT DISTINCT qu.id, question, qu.type, level, q.session_id FROM $TBL_QUESTIONS as qu, $TBL_EXERCICE_QUESTION as qt, $TBL_EXERCICES as q $from WHERE qu.c_id=$selected_course AND qt.c_id=$selected_course AND q.c_id=$selected_course AND qu.id = qt.question_id AND q.id = qt.exercice_id $filter ORDER BY session_id ASC"; FROM $TBL_QUESTIONS as qu, $TBL_EXERCICE_QUESTION as qt, $TBL_EXERCICES as q $from
WHERE qu.c_id = $selected_course AND
qt.c_id = $selected_course AND
q.c_id = $selected_course AND
qu.id = qt.question_id AND
q.id = qt.exercice_id $filter
ORDER BY session_id ASC";
$result = Database::query($sql); $result = Database::query($sql);
while($row = Database::fetch_array($result, 'ASSOC')) { while($row = Database::fetch_array($result, 'ASSOC')) {
$main_question_list[] = $row; $main_question_list[] = $row;
@ -578,31 +579,26 @@ if ($fromExercise <= 0) { // NOT IN A TEST - IN THE COURSE
$actionIcon1 = "edit"; $actionIcon1 = "edit";
$actionIcon2 = "delete"; $actionIcon2 = "delete";
$questionTagA = 1; // we are in the course, question title can be a link to the question edit page $questionTagA = 1; // we are in the course, question title can be a link to the question edit page
} } else { // NOT IN A TEST - NOT IN THE COURSE
else { // NOT IN A TEST - NOT IN THE COURSE
$actionLabel = get_lang('Reuse'); $actionLabel = get_lang('Reuse');
$actionIcon1 = get_lang('MustBeInATest'); $actionIcon1 = get_lang('MustBeInATest');
$actionIcon2 = ""; $actionIcon2 = "";
$questionTagA = 0; // we are not in this course, to messy if we link to the question in another course $questionTagA = 0; // we are not in this course, to messy if we link to the question in another course
} }
} } else { // IN A TEST - IN THE COURSE
else { // IN A TEST - IN THE COURSE
if ($selected_course == api_get_course_int_id()) { if ($selected_course == api_get_course_int_id()) {
$actionLabel = get_lang('Reuse'); $actionLabel = get_lang('Reuse');
$actionIcon1 = "add"; $actionIcon1 = "add";
$actionIcon2 = ""; $actionIcon2 = "";
$questionTagA = 1; $questionTagA = 1;
} } else { // IN A TEST - NOT IN THE COURSE
else { // IN A TEST - NOT IN THE COURSE
$actionLabel = get_lang('Reuse'); $actionLabel = get_lang('Reuse');
$actionIcon1 = "clone"; $actionIcon1 = "clone";
$actionIcon2 = ""; $actionIcon2 = "";
$questionTagA = 0; $questionTagA = 0;
} }
} }
// // Display table
// display table
//
$header = array(); $header = array();
$header[] = array(get_lang('QuestionUpperCaseFirstLetter'), false, array("style"=>"text-align:center"), ''); $header[] = array(get_lang('QuestionUpperCaseFirstLetter'), false, array("style"=>"text-align:center"), '');
$header[] = array(get_lang('Type'), false, array("style"=>"text-align:center"), array("style"=>"text-align:center"), ''); $header[] = array(get_lang('Type'), false, array("style"=>"text-align:center"), array("style"=>"text-align:center"), '');
@ -677,7 +673,6 @@ function reset_menu_exo_lvl_type() {
$courseCategoryId = 0; $courseCategoryId = 0;
} }
//
// return the <a> link to admin question, if needed // return the <a> link to admin question, if needed
// hubert.borderiou 13-10-2011 // hubert.borderiou 13-10-2011
function get_a_tag_for_question($in_addA, $in_fromex, $in_questionid, $in_questiontype, $in_questionname) { function get_a_tag_for_question($in_addA, $in_fromex, $in_questionid, $in_questiontype, $in_questionname) {
@ -711,23 +706,21 @@ $session_id, $exerciseId);
*/ */
// /*
// return the <a> html code for delete, add, clone, edit a question Return the <a> html code for delete, add, clone, edit a question hubert.borderiou 13-10-2011
// hubert.borderiou 13-10-2011 in_action = the code of the action triggered by the button
// in_action = the code of the action triggered by the button from_exercice = the id of the current exercice from which we click on question pool
// from_exercice = the id of the current exercice from which we click on question pool in_questionid = the id of the current question
// in_questionid = the id of the current question in_questiontype = the code of the type of the current question
// in_questiontype = the code of the type of the current question in_questionname = the name of the question
// in_questionname = the name of the question in_selected_course = the if of the course chosen in the FILTERING MENU
// in_selected_course = the if of the course chosen in the FILTERING MENU in_courseCategoryId = the id of the category chosen in the FILTERING MENU
// in_courseCategoryId = the id of the category chosen in the FILTERING MENU in_exerciseLevel = the level of the exercice chosen in the FILTERING MENU
// in_exerciseLevel = the level of the exercice chosen in the FILTERING MENU in_answerType = the code of the type of the question chosen in the FILTERING MENU
// in_answerType = the code of the type of the question chosen in the FILTERING MENU in_session_id = the id of the session_id chosen in the FILTERING MENU
// in_session_id = the id of the session_id chosen in the FILTERING MENU in_exercice_id = the id of the exercice chosen in the FILTERING MENU
// in_exercice_id = the id of the exercice chosen in the FILTERING MENU */
function get_action_icon_for_question($in_action, $from_exercice, $in_questionid, $in_questiontype, $in_questionname, function get_action_icon_for_question($in_action, $from_exercice, $in_questionid, $in_questiontype, $in_questionname, $in_selected_course, $in_courseCategoryId, $in_exerciseLevel, $in_answerType, $in_session_id, $in_exercice_id) {
$in_selected_course, $in_courseCategoryId, $in_exerciseLevel, $in_answerType, $in_session_id, $in_exercice_id
) {
$res = ""; $res = "";
$getParams = "&selected_course=$in_selected_course&courseCategoryId=$in_courseCategoryId&exerciseId=$in_exercice_id&exerciseLevel=$in_exerciseLevel&answerType=$in_answerType&session_id=$in_session_id"; $getParams = "&selected_course=$in_selected_course&courseCategoryId=$in_courseCategoryId&exerciseId=$in_exercice_id&exerciseLevel=$in_exerciseLevel&answerType=$in_answerType&session_id=$in_session_id";
@ -749,8 +742,7 @@ function get_action_icon_for_question($in_action, $from_exercice, $in_questionid
$res = "<a href='".api_get_self()."?".api_get_cidreq()."&recup=$in_questionid&fromExercise=$from_exercice$getParams'>"; $res = "<a href='".api_get_self()."?".api_get_cidreq()."&recup=$in_questionid&fromExercise=$from_exercice$getParams'>";
$res .= Display::return_icon("view_more_stats.gif", get_lang('InsertALinkToThisQuestionInTheExercise')); $res .= Display::return_icon("view_more_stats.gif", get_lang('InsertALinkToThisQuestionInTheExercise'));
$res .= "</a>"; $res .= "</a>";
} } else {
else {
$res = "-"; $res = "-";
} }
unset($myObjEx); unset($myObjEx);
@ -767,8 +759,8 @@ function get_action_icon_for_question($in_action, $from_exercice, $in_questionid
return $res; return $res;
} }
// return the icon for the question type /* return the icon for the question type
// hubert.borderiou 13-10-2011 hubert.borderiou 13-10-2011*/
function get_question_type_for_question($in_selectedcourse, $in_questionid) { function get_question_type_for_question($in_selectedcourse, $in_questionid) {
$myObjQuestion = Question::read($in_questionid, $in_selectedcourse); $myObjQuestion = Question::read($in_questionid, $in_selectedcourse);
$questionType = null; $questionType = null;

Loading…
Cancel
Save