Fixes bug that queries all "quiz_rel_question" rows (for orphan questions) when cleaning/copying a course see BT#5854

skala
Julio Montoya 12 years ago
parent 356c9e1f05
commit 482a9832c9
  1. 428
      main/coursecopy/classes/CourseBuilder.class.php
  2. 31
      main/coursecopy/classes/CourseRecycler.class.php
  3. 11
      main/coursecopy/classes/CourseRestorer.class.php
  4. 303
      main/exercice/question_pool.php

@ -32,7 +32,7 @@ require_once 'Attendance.class.php';
class CourseBuilder {
/** Course */
public $course;
/* With this array you can filter the tools you want to be parsed by default all tools are included*/
public $tools_to_build = array(
'announcements',
@ -52,21 +52,21 @@ class CourseBuilder {
'thematic',
'wiki'
);
/* With this array you can filter wich elements of the tools are going to be added in the course obj (only works with LPs) */
public $specific_id_list = array();
/**
* Create a new CourseBuilder
*/
function __construct($type='', $course = null) {
global $_course;
if (!empty($course['official_code'])){
$_course = $course;
}
$this->course = new Course();
}
$this->course = new Course();
$this->course->code = $_course['official_code'];
$this->course->type = $type;
$this->course->path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/';
@ -75,23 +75,23 @@ class CourseBuilder {
$this->course->db_name = $_course['dbName'];
$this->course->info = $_course;
}
/**
*
* @param type $array
*
* @param type $array
*/
function set_tools_to_build($array) {
$this->tools_to_build = $array;
}
/**
*
* @param type $array
*
* @param type $array
*/
function set_tools_specific_id_list($array) {
$this->specific_id_list = $array;
}
/**
* Get the created course
* @return course The course
@ -99,28 +99,28 @@ class CourseBuilder {
function get_course() {
return $this->course;
}
/**
* Build the course-object
*
*
* @param int session_id
* @param string course_code
* @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)
* @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)
*/
function build($session_id = 0, $course_code = '', $with_base_content = false) {
$table_link = Database :: get_course_table(TABLE_LINKED_RESOURCES);
$table_properties = Database :: get_course_table(TABLE_ITEM_PROPERTY);
$course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id'];
$course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id'];
foreach ($this->tools_to_build as $tool) {
$function_build = 'build_'.$tool;
$this->$function_build($session_id, $course_code, $with_base_content, $this->specific_id_list[$tool]);
}
if (!empty($session_id) && !empty($course_code)) {
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);
@ -129,7 +129,7 @@ class CourseBuilder {
$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_thematic();
$this->build_attendance();*/
} else {
/*$this->build_events();
@ -145,7 +145,7 @@ class CourseBuilder {
$this->build_glossary();
$this->build_thematic();
$this->build_attendance();*/
}
//TABLE_LINKED_RESOURCES is the "resource" course table, which is deprecated, apparently
@ -175,10 +175,10 @@ class CourseBuilder {
$this->course->resources[$type][$id]->item_properties = $all_properties;
}
}
}
}
return $this->course;
}
/**
* Build the documents
*/
@ -186,76 +186,76 @@ class CourseBuilder {
$course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id'];
$table_doc = Database::get_course_table(TABLE_DOCUMENT);
$table_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
//Remove chat_files and shared_folder files
$avoid_paths = " path NOT LIKE '/shared_folder%' AND
path NOT LIKE '/chat_files%' ";
$avoid_paths = " path NOT LIKE '/shared_folder%' AND
path NOT LIKE '/chat_files%' ";
//$avoid_paths = " 1 = 1 ";
if (!empty($course_code) && !empty($session_id)) {
$session_id = intval($session_id);
if ($with_base_content) {
$session_condition = api_get_session_condition($session_id, true, true);
$session_condition = api_get_session_condition($session_id, true, true);
} else {
$session_condition = api_get_session_condition($session_id, true);
}
if (!empty($this->course->type) && $this->course->type=='partial') {
$sql = "SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size FROM $table_doc d, $table_prop p
WHERE d.c_id = $course_id AND
$sql = "SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size FROM $table_doc d, $table_prop p
WHERE d.c_id = $course_id AND
p.c_id = $course_id AND
tool = '".TOOL_DOCUMENT."' AND
p.ref = d.id AND
p.visibility != 2 AND
tool = '".TOOL_DOCUMENT."' AND
p.ref = d.id AND
p.visibility != 2 AND
path NOT LIKE '/images/gallery%' AND
$avoid_paths
$session_condition
$session_condition
ORDER BY path";
} else {
$sql = "SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size FROM $table_doc d, $table_prop p
WHERE d.c_id = $course_id AND
$sql = "SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size FROM $table_doc d, $table_prop p
WHERE d.c_id = $course_id AND
p.c_id = $course_id AND
tool = '".TOOL_DOCUMENT."' AND
$avoid_paths AND
p.ref = d.id AND
p.visibility != 2 $session_condition
p.ref = d.id AND
p.visibility != 2 $session_condition
ORDER BY path";
}
$db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) {
$doc = new Document($obj->id, $obj->path, $obj->comment, $obj->title, $obj->filetype, $obj->size);
$this->course->add_resource($doc);
}
} else {
if (!empty($this->course->type) && $this->course->type=='partial')
$sql = 'SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size FROM '.$table_doc.' d, '.$table_prop.' p
WHERE d.c_id = '.$course_id.' AND
$sql = 'SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size FROM '.$table_doc.' d, '.$table_prop.' p
WHERE d.c_id = '.$course_id.' AND
p.c_id = '.$course_id.' AND
tool = \''.TOOL_DOCUMENT.'\' AND
p.ref = d.id AND
p.visibility != 2 AND
tool = \''.TOOL_DOCUMENT.'\' AND
p.ref = d.id AND
p.visibility != 2 AND
path NOT LIKE \'/images/gallery%\' AND
'.$avoid_paths.'AND
d.session_id = 0
d.session_id = 0
ORDER BY path';
else
$sql = 'SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size
$sql = 'SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size
FROM '.$table_doc.' d, '.$table_prop.' p
WHERE d.c_id = '.$course_id.' AND
p.c_id = '.$course_id.' AND
tool = \''.TOOL_DOCUMENT.'\' AND
p.ref = d.id AND
WHERE d.c_id = '.$course_id.' AND
p.c_id = '.$course_id.' AND
tool = \''.TOOL_DOCUMENT.'\' AND
p.ref = d.id AND
p.visibility != 2 AND
'.$avoid_paths.' AND
d.session_id = 0
d.session_id = 0
ORDER BY path';
$db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) {
$doc = new Document($obj->id, $obj->path, $obj->comment, $obj->title, $obj->filetype, $obj->size);
@ -263,25 +263,25 @@ class CourseBuilder {
}
}
}
/**
* Build the forums
*/
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_id = $course_info['real_id'];
$table = Database :: get_course_table(TABLE_FORUM);
$sql = "SELECT * FROM $table WHERE c_id = $course_id ";
$sql = "SELECT * FROM $table WHERE c_id = $course_id ";
$sql .= " ORDER BY forum_title, forum_category";
$db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) {
$forum = new Forum($obj);
$this->course->add_resource($forum);
$this->course->add_resource($forum);
}
}
/**
* Build a forum-category
*/
@ -289,78 +289,78 @@ class CourseBuilder {
$table = Database :: get_course_table(TABLE_FORUM_CATEGORY);
$course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id'];
$sql = "SELECT * FROM $table WHERE c_id = $course_id ORDER BY cat_title";
$db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) {
$forum_category = new ForumCategory($obj);
$this->course->add_resource($forum_category);
$forum_category = new ForumCategory($obj);
$this->course->add_resource($forum_category);
}
}
/**
* Build the forum-topics
*/
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);
$course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id'];
$sql = "SELECT * FROM $table WHERE c_id = $course_id
$course_id = $course_info['real_id'];
$sql = "SELECT * FROM $table WHERE c_id = $course_id
ORDER BY thread_title ";
$db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) {
while ($obj = Database::fetch_object($db_result)) {
$forum_topic = new ForumTopic($obj);
$this->course->add_resource($forum_topic);
$this->build_forum_posts($obj->thread_id, $obj->forum_id, true);
}
}
/**
* Build the forum-posts
* 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) {
$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 ";
if (!empty($thread_id) && !empty($forum_id)) {
$forum_id = intval($forum_id);
$thread_id = intval($thread_id);
$sql .= " AND thread_id = $thread_id AND forum_id = $forum_id ";
}
}
$sql .= " ORDER BY post_id ASC LIMIT 1";
$db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) {
$forum_post = new ForumPost($obj);
$forum_post = new ForumPost($obj);
$this->course->add_resource($forum_post);
}
}
/**
* Build the links
*/
function build_links($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array()) {
$course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id'];
$course_id = $course_info['real_id'];
$table = Database :: get_course_table(TABLE_LINK);
$table_prop = Database :: get_course_table(TABLE_ITEM_PROPERTY);
if (!empty($session_id) && !empty($course_code)) {
if (!empty($session_id) && !empty($course_code)) {
$session_id = intval($session_id);
if ($with_base_content) {
$session_condition = api_get_session_condition($session_id, true, true);
$session_condition = api_get_session_condition($session_id, true, true);
} else {
$session_condition = api_get_session_condition($session_id, true);
}
$sql = "SELECT l.id, l.title, l.url, l.description, l.category_id, l.on_homepage
}
$sql = "SELECT l.id, l.title, l.url, l.description, l.category_id, l.on_homepage
FROM $table l, $table_prop p
WHERE l.c_id = $course_id AND p.c_id = $course_id AND p.ref=l.id AND p.tool = '".TOOL_LINK."' AND p.visibility != 2 $session_condition
WHERE l.c_id = $course_id AND p.c_id = $course_id AND p.ref=l.id AND p.tool = '".TOOL_LINK."' AND p.visibility != 2 $session_condition
ORDER BY l.display_order";
} else {
$sql = "SELECT l.id, l.title, l.url, l.description, l.category_id, l.on_homepage
FROM $table l, $table_prop p
WHERE l.c_id = $course_id AND p.c_id = $course_id AND p.ref=l.id AND p.tool = '".TOOL_LINK."' AND p.visibility != 2 AND l.session_id = 0
} else {
$sql = "SELECT l.id, l.title, l.url, l.description, l.category_id, l.on_homepage
FROM $table l, $table_prop p
WHERE l.c_id = $course_id AND p.c_id = $course_id AND p.ref=l.id AND p.tool = '".TOOL_LINK."' AND p.visibility != 2 AND l.session_id = 0
ORDER BY l.display_order";
}
@ -380,13 +380,13 @@ class CourseBuilder {
}
}
}
/**
* Build tool intro
*/
function build_tool_intro($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array()) {
$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 ";
$db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) {
@ -394,14 +394,14 @@ class CourseBuilder {
$this->course->add_resource($tool_intro);
}
}
/**
* Build a link category
*/
function build_link_category($id, $course_code = '') {
$course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id'];
$link_cat_table = Database :: get_course_table(TABLE_LINK_CATEGORY);
$sql = "SELECT * FROM $link_cat_table WHERE c_id = $course_id AND id = $id";
@ -413,7 +413,7 @@ class CourseBuilder {
}
return 0;
}
/**
* Build the Quizzes
*/
@ -422,21 +422,21 @@ class CourseBuilder {
$table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
$table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
$table_doc = Database :: get_course_table(TABLE_DOCUMENT);
$course_id = $course_info['real_id'];
if (!empty($course_code) && !empty($session_id)) {
$course_id = $course_info['real_id'];
if (!empty($course_code) && !empty($session_id)) {
$session_id = intval($session_id);
if ($with_base_content) {
$session_condition = api_get_session_condition($session_id, true, true);
$session_condition = api_get_session_condition($session_id, true, true);
} else {
$session_condition = api_get_session_condition($session_id, true);
}
}
$sql = "SELECT * FROM $table_qui WHERE c_id = $course_id AND active >=0 $session_condition"; //select only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes)
} else {
} else {
$sql = "SELECT * FROM $table_qui WHERE c_id = $course_id AND active >=0 AND session_id = 0"; //select only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes)
}
$db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) {
if (strlen($obj->sound) > 0) {
@ -446,11 +446,11 @@ class CourseBuilder {
$obj->sound = $doc->id;
}
$quiz = new Quiz($obj);
$sql = 'SELECT * FROM '.$table_rel.' WHERE c_id = '.$course_id.' AND exercice_id = '.$obj->id;
$sql = 'SELECT * FROM '.$table_rel.' WHERE c_id = '.$course_id.' AND exercice_id = '.$obj->id;
$db_result2 = Database::query($sql);
while ($obj2 = Database::fetch_object($db_result2)) {
$quiz->add_question($obj2->question_id, $obj2->question_order);
}
}
$this->course->add_resource($quiz);
}
@ -460,14 +460,14 @@ class CourseBuilder {
$this->build_quiz_questions();
}
}
/**
* Build the Quiz-Questions
*/
function build_quiz_questions($course_code = null) {
$course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id'];
$table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
$table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
$table_que = Database :: get_course_table(TABLE_QUIZ_QUESTION);
@ -475,8 +475,8 @@ class CourseBuilder {
// Building normal tests.
$sql = "SELECT * FROM $table_que WHERE c_id = $course_id ";
$db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) {
$db_result = Database::query($sql);
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);
$sql = 'SELECT * FROM '.$table_ans.' WHERE c_id = '.$course_id.' AND question_id = '.$obj->id;
$db_result2 = Database::query($sql);
@ -497,45 +497,79 @@ class CourseBuilder {
// 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).
$sql = "SELECT questions.*
/*$sql = "SELECT questions.*
FROM $table_que as questions
LEFT JOIN $table_rel as quizz_questions
LEFT JOIN $table_rel as quizz_questions
ON (questions.id = quizz_questions.question_id AND questions.c_id = $course_id AND quizz_questions.c_id = $course_id)
LEFT JOIN $table_qui as exercices
LEFT JOIN $table_qui as exercices
ON (exercice_id = exercices.id AND exercices.c_id = $course_id AND questions.c_id = $course_id)
WHERE questions.c_id = $course_id AND
exercices.c_id = $course_id AND
(quizz_questions.exercice_id IS NULL OR exercices.active = -1) "; // active = -1 means "deleted" test.
*/
//1st union gets the orphan questions from deleted exercises
//2nd union gets the orphan questions from question that were deleted in a exercise.
$sql = " (
SELECT q.* FROM $table_que q INNER JOIN $table_rel r
ON (q.c_id = r.c_id AND q.id = r.question_id)
INNER JOIN $table_qui ex
ON (ex.id = r.exercice_id AND ex.c_id =r.c_id )
WHERE ex.c_id = $course_id AND ex.active = '-1'
)
UNION
(
SELECT 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 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);
if (Database::num_rows($db_result) > 0) {
$build_orphan_questions = true;
$orphanQuestionIds = array();
while ($obj = Database::fetch_object($db_result)) {
//Avoid adding the same question twice
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);
$sql = "SELECT * FROM $table_ans WHERE c_id = $course_id AND question_id = ".$obj->id;
$db_result2 = Database::query($sql);
if (Database::num_rows($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);
$sql = "SELECT * FROM $table_ans WHERE c_id = $course_id AND question_id = ".$obj->id;
$db_result2 = Database::query($sql);
if (Database::num_rows($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);
$orphanQuestionIds[] = $obj2->id;
}
}
}
$this->course->add_resource($question);
}
}
$this->course->add_resource($question);
}
}
}
if ($build_orphan_questions) {
$obj = array(
'id' => -1,
'title' => get_lang('OrphanQuestions', '')
);
$this->course->add_resource(new Quiz((object)$obj));
$newQuiz = new Quiz((object)$obj);
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
*/
@ -544,16 +578,16 @@ class CourseBuilder {
$table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
$table_que = Database :: get_course_table(TABLE_QUIZ_QUESTION);
$table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
$course_id = api_get_course_int_id();
$course_id = api_get_course_int_id();
$sql = 'SELECT *
FROM '.$table_que.' as questions
LEFT JOIN '.$table_rel.' as quizz_questions
ON questions.id=quizz_questions.question_id
LEFT JOIN '.$table_qui.' as exercices
ON exercice_id=exercices.id
WHERE questions.c_id = '.$course_id.' AND
ON exercice_id=exercices.id
WHERE questions.c_id = '.$course_id.' AND
quizz_questions.c_id = '.$course_id.' AND
exercices.c_id = '.$course_id.' AND
(quizz_questions.exercice_id IS NULL OR
@ -575,7 +609,7 @@ class CourseBuilder {
}
}
}
/**
* Build the Surveys
*/
@ -583,7 +617,7 @@ class CourseBuilder {
$table_survey = Database :: get_course_table(TABLE_SURVEY);
$table_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
$course_id = api_get_course_int_id();
$sql = 'SELECT * FROM '.$table_survey.' WHERE c_id = '.$course_id.' AND session_id = 0 ';
$db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) {
@ -608,9 +642,9 @@ class CourseBuilder {
function build_survey_questions() {
$table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
$table_opt = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
$course_id = api_get_course_int_id();
$sql = 'SELECT * FROM '.$table_que.' WHERE c_id = '.$course_id.' ';
$db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)){
@ -626,18 +660,18 @@ class CourseBuilder {
$this->course->add_resource($question);
}
}
/**
* Build the announcements
*/
function build_announcements($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array()) {
$table = Database :: get_course_table(TABLE_ANNOUNCEMENT);
$course_id = api_get_course_int_id();
$sql = 'SELECT * FROM '.$table.' WHERE c_id = '.$course_id.' AND session_id = 0';
$db_result = Database::query($sql);
$table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
while ($obj = Database::fetch_object($db_result)) {
while ($obj = Database::fetch_object($db_result)) {
$sql = 'SELECT path, comment, filename, size FROM '.$table_attachment.' WHERE c_id = '.$course_id.' AND announcement_id = '.$obj->id.'';
$result = Database::query($sql);
$attachment_obj = Database::fetch_object($result);
@ -647,10 +681,10 @@ class CourseBuilder {
$att_filename = $attachment_obj->filename;
$att_size = $attachment_obj->size;
$atth_comment = $attachment_obj->comment;
}
$announcement = new Announcement($obj->id, $obj->title, $obj->content, $obj->end_date,$obj->display_order,$obj->email_sent, $att_path, $att_filename, $att_size, $atth_comment);
}
$announcement = new Announcement($obj->id, $obj->title, $obj->content, $obj->end_date,$obj->display_order,$obj->email_sent, $att_path, $att_filename, $att_size, $atth_comment);
$this->course->add_resource($announcement);
}
}
/**
@ -659,26 +693,26 @@ class CourseBuilder {
function build_events($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array()) {
$table = Database :: get_course_table(TABLE_AGENDA);
$course_id = api_get_course_int_id();
$sql = 'SELECT * FROM '.$table.' WHERE c_id = '.$course_id.' AND session_id = 0';
$db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) {
$table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
$sql = 'SELECT path, comment, filename, size FROM '.$table_attachment.' WHERE c_id = '.$course_id.' AND agenda_id = '.$obj->id.'';
$result = Database::query($sql);
$attachment_obj = Database::fetch_object($result);
$attachment_obj = Database::fetch_object($result);
$att_path = $att_filename = $att_size = $atth_comment = '';
if (!empty($attachment_obj)) {
$att_path = $attachment_obj->path;
$att_filename = $attachment_obj->filename;
$att_size = $attachment_obj->size;
$atth_comment = $attachment_obj->comment;
}
$event = new Event($obj->id, $obj->title, $obj->content, $obj->start_date, $obj->end_date, $att_path, $att_filename, $att_size, $atth_comment, $obj->all_day);
}
$event = new Event($obj->id, $obj->title, $obj->content, $obj->start_date, $obj->end_date, $att_path, $att_filename, $att_size, $atth_comment, $obj->all_day);
$this->course->add_resource($event);
}
}
/**
* Build the course-descriptions
@ -686,16 +720,16 @@ class CourseBuilder {
function build_course_descriptions($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array()) {
$course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id'];
$table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION);
if (!empty($session_id) && !empty($course_code)) {
if (!empty($session_id) && !empty($course_code)) {
$session_id = intval($session_id);
if ($with_base_content) {
$session_condition = api_get_session_condition($session_id, true, true);
$session_condition = api_get_session_condition($session_id, true, true);
} else {
$session_condition = api_get_session_condition($session_id, true);
}
}
$sql = 'SELECT * FROM '.$table. ' WHERE c_id = '.$course_id.' '.$session_condition;
} else {
$table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION);
@ -712,30 +746,30 @@ class CourseBuilder {
* Build the learnpaths
*/
function build_learnpaths($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array()) {
$course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id'];
$table_main = Database::get_course_table(TABLE_LP_MAIN);
$table_item = Database::get_course_table(TABLE_LP_ITEM);
$table_tool = Database::get_course_table(TABLE_TOOL_LIST);
if (!empty($session_id) && !empty($course_code)) {
$session_id = intval($session_id);
if ($with_base_content) {
$session_condition = api_get_session_condition($session_id, true, true);
$session_condition = api_get_session_condition($session_id, true, true);
} else {
$session_condition = api_get_session_condition($session_id, true);
}
}
$sql = 'SELECT * FROM '.$table_main.' WHERE c_id = '.$course_id.' '.$session_condition;
} else {
} else {
$sql = 'SELECT * FROM '.$table_main.' WHERE c_id = '.$course_id.' AND session_id = 0';
}
}
if (!empty($id_list)) {
$id_list = array_map('intval', $id_list);
$sql .=" AND id IN (".implode(', ', $id_list).") ";
}
$db_result = Database::query($sql);
if ($db_result)
while ($obj = Database::fetch_object($db_result)) {
@ -759,7 +793,7 @@ class CourseBuilder {
$item['prerequisite'] = $obj_item->prerequisite;
$item['parameters'] = $obj_item->parameters;
$item['launch_data'] = $obj_item->launch_data;
$item['audio'] = $obj_item->audio;
$item['audio'] = $obj_item->audio;
$items[] = $item;
}
@ -791,7 +825,7 @@ class CourseBuilder {
$obj->display_order,
$obj->js_lib,
$obj->content_license,
$obj->debug,
$obj->debug,
$visibility,
$obj->author,
$obj->preview_image,
@ -800,7 +834,7 @@ class CourseBuilder {
$obj->created_on,
$obj->modified_on,
$obj->publicated_on,
$obj->expired_on,
$obj->expired_on,
$obj->session_id,
$items);
$this->course->add_resource($lp);
@ -825,16 +859,16 @@ class CourseBuilder {
function build_glossary($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array()) {
$course_info = api_get_course_info($course_code);
$table_glossary = Database :: get_course_table(TABLE_GLOSSARY);
$course_id = $course_info['real_id'];
if (!empty($session_id) && !empty($course_code)) {
$course_id = $course_info['real_id'];
if (!empty($session_id) && !empty($course_code)) {
$session_id = intval($session_id);
if ($with_base_content) {
$session_condition = api_get_session_condition($session_id, true, true);
$session_condition = api_get_session_condition($session_id, true, true);
} else {
$session_condition = api_get_session_condition($session_id, true);
}
//@todo check this queries are the same ...
//@todo check this queries are the same ...
if (!empty($this->course->type) && $this->course->type=='partial') {
$sql = 'SELECT * FROM '.$table_glossary.' g WHERE g.c_id = '.$course_id.' '.$session_condition;
} else {
@ -842,7 +876,7 @@ class CourseBuilder {
}
} else {
$table_glossary = Database :: get_course_table(TABLE_GLOSSARY);
//@todo check this queries are the same ... ayayay
//@todo check this queries are the same ... ayayay
if (!empty($this->course->type) && $this->course->type=='partial') {
$sql = 'SELECT * FROM '.$table_glossary.' g WHERE g.c_id = '.$course_id.' AND session_id = 0';
} else {
@ -888,16 +922,16 @@ class CourseBuilder {
function build_wiki($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array()) {
$course_info = api_get_course_info($course_code);
$tbl_wiki = Database::get_course_table(TABLE_WIKI);
$course_id = $course_info['real_id'];
if (!empty($session_id) && !empty($course_code)) {
if (!empty($session_id) && !empty($course_code)) {
$session_id = intval($session_id);
if ($with_base_content) {
$session_condition = api_get_session_condition($session_id, true, true);
$session_condition = api_get_session_condition($session_id, true, true);
} else {
$session_condition = api_get_session_condition($session_id, true);
}
}
$sql = 'SELECT * FROM ' . $tbl_wiki . ' WHERE c_id = '.$course_id.' '.$session_condition;
} else {
$tbl_wiki = Database::get_course_table(TABLE_WIKI);
@ -909,7 +943,7 @@ class CourseBuilder {
$this->course->add_resource($wiki);
}
}
/**
* Build the Surveys
*/
@ -917,39 +951,39 @@ class CourseBuilder {
$table_thematic = Database :: get_course_table(TABLE_THEMATIC);
$table_thematic_advance = Database :: get_course_table(TABLE_THEMATIC_ADVANCE);
$table_thematic_plan = Database :: get_course_table(TABLE_THEMATIC_PLAN);
$session_id = intval($session_id);
if ($with_base_content) {
$session_condition = api_get_session_condition($session_id, true, true);
$session_condition = api_get_session_condition($session_id, true, true);
} else {
$session_condition = api_get_session_condition($session_id, true);
}
$course_id = api_get_course_int_id();
$sql = "SELECT * FROM $table_thematic WHERE c_id = $course_id $session_condition ";
$db_result = Database::query($sql);
while ($row = Database::fetch_array($db_result,'ASSOC')) {
$thematic = new Thematic($row);
$sql = 'SELECT * FROM '.$table_thematic_advance.' WHERE c_id = '.$course_id.' AND thematic_id = '.$row['id'];
$result = Database::query($sql);
while ($sub_row = Database::fetch_array($result,'ASSOC')) {
while ($sub_row = Database::fetch_array($result,'ASSOC')) {
$thematic->add_thematic_advance($sub_row);
}
$items = api_get_item_property_by_tool('thematic_plan', api_get_course_id(), $session_id);
$items = api_get_item_property_by_tool('thematic_plan', api_get_course_id(), $session_id);
//$items_from_session = api_get_item_property_by_tool('thematic_plan', api_get_course_id(), api_get_session_id());
$thematic_plan_id_list = array();
if (!empty($items)) {
foreach($items as $item) {
foreach($items as $item) {
$thematic_plan_id_list[] = $item['ref'];
//$thematic_plan_complete_list[$item['ref']] = $item;
}
}
//$sql = 'SELECT * FROM '.$table_thematic_plan.' WHERE c_id = '.$course_id.' AND thematic_id = '.$row['id'];
$sql = "SELECT tp.*
FROM $table_thematic_plan tp
INNER JOIN $table_thematic t ON (t.id=tp.thematic_id)
@ -958,35 +992,35 @@ class CourseBuilder {
thematic_id = {$row['id']} AND
tp.id IN (".implode(', ', $thematic_plan_id_list).") ";
$result = Database::query($sql);
while ($sub_row = Database::fetch_array($result,'ASSOC')) {
$thematic->add_thematic_plan($sub_row);
}
$this->course->add_resource($thematic);
}
}
}
$this->course->add_resource($thematic);
}
}
/**
* Build the Surveys
*/
function build_attendance($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array()) {
$table_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
$table_attendance_calendar = Database :: get_course_table(TABLE_ATTENDANCE_CALENDAR);
$course_id = api_get_course_int_id();
$course_id = api_get_course_int_id();
$sql = 'SELECT * FROM '.$table_attendance.' WHERE c_id = '.$course_id.' AND session_id = 0 ';
$db_result = Database::query($sql);
while ($row = Database::fetch_array($db_result,'ASSOC')) {
$obj = new CourseCopyAttendance($row);
$sql = 'SELECT * FROM '.$table_attendance_calendar.' WHERE c_id = '.$course_id.' AND attendance_id = '.$row['id'];
$result = Database::query($sql);
while ($sub_row = Database::fetch_array($result,'ASSOC')) {
$obj->add_attendance_calendar($sub_row);
}
$this->course->add_resource($obj);
}
}
}
}

@ -319,7 +319,7 @@ class CourseRecycler
// This value is set in CourseBuilder::quiz_build_questions()
$delete_orphan_questions = in_array(-1, $ids);
$ids = implode(',', $ids);
if (!empty($ids)) {
// Deletion of the tests first. Questions in these tests are
// not deleted and become orphan at this point
@ -331,7 +331,8 @@ class CourseRecycler
// Identifying again and deletion of the orphan questions, if it was desired.
if ($delete_orphan_questions) {
$sql = 'SELECT questions.id '.
/*$sql = 'SELECT questions.id '.
' FROM '.$table_qui_que.' as questions '.
' LEFT JOIN '.$table_rel.' as quizz_questions '.
' ON questions.id=quizz_questions.question_id '.
@ -344,6 +345,32 @@ class CourseRecycler
' quizz_questions.exercice_id IS NULL OR '.
' exercices.active = -1';
// active = -1 means "deleted" test.
*/
$sql = " (
SELECT q.id FROM $table_qui_que q INNER JOIN $table_rel r
ON (q.c_id = r.c_id AND q.id = r.question_id)
INNER JOIN $table_qui ex
ON (ex.id = r.exercice_id AND ex.c_id =r.c_id )
WHERE ex.c_id = '.$this->course_id.' AND (ex.active = '-1' OR ex.exercice_id = '-1')
)
UNION
(
SELECT q.id FROM $table_qui_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 = '.$this->course_id.' AND r.question_id is null
)
UNION
(
SELECT q.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);
if (Database::num_rows($db_result) > 0) {
$orphan_ids = array();

@ -1445,7 +1445,7 @@ class CourseRestorer
}
}
if ($id != -1) {
// check resources inside html from fckeditor tool and copy correct urls into recipient course
// check resources inside html from fckeditor tool and copy correct urls into recipient course
$quiz->description = DocumentManager::replace_urls_inside_content_html_from_copy_course(
$quiz->description,
$this->course->code,
@ -1502,13 +1502,15 @@ class CourseRestorer
}
if ($new_id) {
// updates the question position
// Updates the question position
$exercise = new Exercise($this->destination_course_id);
$exercise->read($new_id);
$exercise->add_exercise_to_order_table();
$this->course->resources[RESOURCE_QUIZ][$id]->destination_id = $new_id;
if ($new_id != -1) {
$exercise->add_exercise_to_order_table();
}
$this->course->resources[RESOURCE_QUIZ][$id]->destination_id = $new_id;
$order = 0;
if (!empty($quiz->question_ids)) {
foreach ($quiz->question_ids as $index => $question_id) {
@ -1516,6 +1518,7 @@ class CourseRestorer
$question_order = $quiz->question_orders[$index] ? $quiz->question_orders[$index] : ++$order;
$sql = "INSERT IGNORE INTO ".$table_rel." SET c_id = ".$this->destination_course_id.", question_id = ".$qid.", exercice_id = ".$new_id.", question_order = ".$question_order;
Database::query($sql);
}
}
}

@ -7,7 +7,7 @@
* One question can be in several exercises
* @package chamilo.exercise
* @author Olivier Brouckaert
* @author Julio Montoya adding support to query all questions from all session, courses, exercises
* @author Julio Montoya adding support to query all questions from all session, courses, exercises
* @author Modify by hubert borderiou 2011-10-21 Question's category
*/
/**
@ -78,14 +78,14 @@ $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
$picturePath = $documentPath.'/images';
if(!($objExcercise instanceOf Exercise) && !empty($fromExercise)) {
$objExercise = new Exercise();
$objExercise = new Exercise();
$objExercise->read($fromExercise);
}
$nameTools = get_lang('QuestionPool');
$interbreadcrumb[] = array("url" => "exercice.php","name" => get_lang('Exercices'));
$interbreadcrumb[] = array("url" => "admin.php?exerciseId=".$objExercise->id, "name" => $objExercise->name);
$displayMessage = ""; // messag to be displayed if actions succesfull
if ($is_allowedToEdit) {
//Duplicating a Question
@ -93,22 +93,22 @@ if ($is_allowedToEdit) {
$origin_course_id = intval($_GET['course_id']);
$origin_course_info = api_get_course_info_by_id($origin_course_id);
$current_course = api_get_course_info();
$old_question_id = $copy_question;
//Reading the source question
$old_question_id = $copy_question;
//Reading the source question
$old_question_obj = Question::read($old_question_id, $origin_course_id);
if ($old_question_obj) {
$old_question_obj->updateTitle($old_question_obj->selectTitle().' - '.get_lang('Copy'));
$old_question_obj->updateTitle($old_question_obj->selectTitle().' - '.get_lang('Copy'));
//Duplicating the source question, in the current course
$new_id = $old_question_obj->duplicate($current_course);
//Reading new question
$new_question_obj = Question::read($new_id);
$new_question_obj->addToList($fromExercise);
//Reading Answers obj of the current course
//Reading Answers obj of the current course
$new_answer_obj = new Answer($old_question_id, $origin_course_id);
$new_answer_obj->read();
//Duplicating the Answers in the current course
$new_answer_obj->duplicate($new_id, $current_course);
$new_answer_obj->duplicate($new_id, $current_course);
// destruction of the Question object
unset($new_question_obj);
unset($old_question_obj);
@ -116,7 +116,7 @@ if ($is_allowedToEdit) {
$objExercise = new Exercise();
$objExercise->read($fromExercise);
}
Session::write('objExercise', $objExercise);
Session::write('objExercise', $objExercise);
}
$displayMessage = get_lang('ItemAdded');
}
@ -152,17 +152,17 @@ if ($is_allowedToEdit) {
// header("Location: admin.php?".api_get_cidreq()."&exerciseId=$fromExercise");
// exit();
}
}
else if( isset($_POST['recup']) && is_array($_POST['recup']) && $fromExercise) {
$list_recup = $_POST['recup'];
foreach ($list_recup as $course_id => $question_data) {
$origin_course_id = intval($course_id);
$origin_course_info = api_get_course_info_by_id($origin_course_id);
$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
@ -178,31 +178,31 @@ if ($is_allowedToEdit) {
}
// adds the question ID represented by $recup into the list of questions for the current exercise
$objExercise->addToList($recup);
*/
*/
//Reading the source question
$old_question_obj = Question::read($old_question_id, $origin_course_id);
if ($old_question_obj) {
$old_question_obj->updateTitle($old_question_obj->selectTitle().' - '.get_lang('Copy'));
//Duplicating the source question, in the current course
$new_id = $old_question_obj->duplicate($current_course);
//Reading new question
$new_question_obj = Question::read($new_id);
$new_question_obj->addToList($fromExercise);
//Reading Answers obj of the current course
$new_answer_obj = new Answer($old_question_id, $origin_course_id);
$new_answer_obj->read();
//Duplicating the Answers in the current course
$new_answer_obj->duplicate($new_id, $current_course);
// destruction of the Question object
unset($new_question_obj);
unset($old_question_obj);
if (!$objExcercise instanceOf Exercise) {
$objExercise = new Exercise();
$objExercise->read($fromExercise);
@ -231,20 +231,20 @@ if (!$is_allowedToEdit) {
$confirmYourChoice = addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset));
$htmlHeadXtra[] = "
<script type='text/javascript'>
function submit_form(obj) {
$htmlHeadXtra[] = "
<script>
function submit_form(obj) {
document.question_pool.submit();
}
function mark_course_id_changed() {
}
function mark_course_id_changed() {
$('#course_id_changed').val('1');
}
function mark_exercice_id_changed() {
function mark_exercice_id_changed() {
$('#exercice_id_changed').val('1');
}
function confirm_your_choice() {
return confirm('$confirmYourChoice');
}
@ -252,7 +252,7 @@ $htmlHeadXtra[] = "
Display::display_header($nameTools,'Exercise');
// Menu
// Menu
echo '<div class="actions">';
if (isset($type)) {
$url = api_get_self().'?type=1';
@ -276,7 +276,7 @@ if ($displayMessage != "") {
}
//Form
echo '<form class="form-horizontal" name="question_pool" method="GET" action="'.$url.'">';
echo '<form class="form-horizontal" name="question_pool" method="GET" action="'.$url.'">';
//Title
echo '<legend>'.$nameTools.' - '.$titleAdd.'</legend>';
if (isset($type)) {
@ -298,9 +298,9 @@ echo Display::form_row($labelFormRow, $select_session_html); // hub 13-10-2011
// Course list, get course list of session, or for course where user is admin
if (!empty($session_id) && $session_id != '-1') {
$course_list = SessionManager::get_course_list_by_session_id($session_id);
} else {
$course_list = CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id());
}
} else {
$course_list = CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id());
}
$course_select_list = array();
foreach ($course_list as $item) {
$course_select_list[$item['id']] = "";
@ -311,14 +311,14 @@ foreach ($course_list as $item) {
}
$select_course_html = Display::select('selected_course', $course_select_list, $selected_course, array('class'=>'chzn-select','onchange'=>'mark_course_id_changed(); submit_form(this);'));
echo Display::form_row(get_lang('Course'), $select_course_html);
echo Display::form_row(get_lang('Course'), $select_course_html);
if (empty($selected_course) || $selected_course == '-1') {
$course_info = api_get_course_info();
reset_menu_exo_lvl_type(); // no course selected, reset menu test / difficult<EFBFBD> / type de reponse // hub 13-10-2011
}
else {
$course_info = CourseManager::get_course_information_by_id($selected_course);
}
else {
$course_info = CourseManager::get_course_information_by_id($selected_course);
}
// If course has changed, reset the menu default
if ($course_id_changed) {
@ -346,16 +346,16 @@ $exercise_list = get_all_exercises_for_course_id($course_info, $session_
//Exercise List
$my_exercise_list = array();
$my_exercise_list['0'] = get_lang('AllExercises');
$my_exercise_list['-1'] = get_lang('OrphanQuestions');
$my_exercise_list['-1'] = get_lang('OrphanQuestions');
if (is_array($exercise_list)) {
foreach($exercise_list as $row) {
foreach($exercise_list as $row) {
$my_exercise_list[$row['id']] = "";
if ($row['id'] == $fromExercise && $selected_course == api_get_course_int_id()) {
if ($row['id'] == $fromExercise && $selected_course == api_get_course_int_id()) {
$my_exercise_list[$row['id']] = ">&nbsp;&nbsp;&nbsp;&nbsp;"; // hub 13-10-2011
}
}
$my_exercise_list[$row['id']] .= $row['title'];
}
}
}
if ($exercice_id_changed == 1) {
reset_menu_lvl_type();
@ -363,14 +363,14 @@ if ($exercice_id_changed == 1) {
$select_exercise_html = Display::select('exerciseId', $my_exercise_list, $exerciseId, array('class'=>'chzn-select','onchange'=>'mark_exercice_id_changed(); submit_form(this);'), false);
echo Display::form_row(get_lang('Exercise'), $select_exercise_html);
// Difficulty list (only from 0 to 5)
// Difficulty list (only from 0 to 5)
$select_difficulty_html = Display::select('exerciseLevel', array(-1 => get_lang('All'), 0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5), $exerciseLevel, array('class'=>'chzn-select', 'onchange'=>'submit_form(this);'), false);
echo Display::form_row(get_lang('Difficulty'), $select_difficulty_html);
// Answer type
$question_list = Question::get_question_type_list();
$new_question_list = array();
@ -394,9 +394,9 @@ foreach ($question_list as $key=>$item) {
//Answer type list
$select_answer_html = Display::select('answerType', $new_question_list, $answerType, array('class'=>'chzn-select','onchange'=>'submit_form(this);'), false);
echo Display::form_row(get_lang('AnswerType'), $select_answer_html);
$button = '<button class="save" type="submit" name="name" value="'.get_lang('Filter').'">'.get_lang('Filter').'</button>';
$button = '<button class="save" type="submit" name="name" value="'.get_lang('Filter').'">'.get_lang('Filter').'</button>';
echo Display::form_row('', $button);
echo "<input type='hidden' id='course_id_changed' name='course_id_changed' value='0' />";
echo "<input type='hidden' id='course_id_changed' name='course_id_changed' value='0' />";
echo "<input type='hidden' id='exercice_id_changed' name='exercice_id_changed' value='0' />";
?>
</form>
@ -407,7 +407,7 @@ echo '<input type="hidden" name="course_id" value="'.$selected_course.'">';
// if we have selected an exercise in the list-box 'Filter'
if ($exerciseId > 0) {
$where = '';
$from = '';
@ -421,64 +421,87 @@ if ($exerciseId > 0) {
if (isset($answerType) && $answerType > 0) {
$where .= ' AND type='.$answerType;
}
$sql = "SELECT DISTINCT
$sql = "SELECT DISTINCT
id,question,
type,
level
FROM
level
FROM
$TBL_EXERCICE_QUESTION qt,
$TBL_QUESTIONS qu
$from
WHERE
qt.question_id=qu.id
AND qt.exercice_id = $exerciseId
AND qt.c_id = $selected_course
AND qu.c_id = $selected_course
$where
ORDER BY
$TBL_QUESTIONS qu
$from
WHERE
qt.question_id=qu.id
AND qt.exercice_id = $exerciseId
AND qt.c_id = $selected_course
AND qu.c_id = $selected_course
$where
ORDER BY
question_order";
$result=Database::query($sql);
while($row = Database::fetch_array($result, 'ASSOC')) {
$main_question_list[] = $row;
}
}
} 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 = '';
$from = '';
if (isset($courseCategoryId) && $courseCategoryId > 0) {
$from = ", $TBL_COURSE_REL_CATEGORY crc ";
$level_where .= " AND crc.c_id=$selected_course AND crc.question_id=qu.id AND crc.category_id = $courseCategoryId";
}
}
if (isset($exerciseLevel) && $exerciseLevel!= -1 ) {
$level_where = ' AND level='.$exerciseLevel;
$level_where = ' AND level = '.$exerciseLevel;
}
$answer_where = '';
if (isset($answerType) && $answerType >0 -1 ) {
$answer_where = ' AND type='.$answerType;
$answer_where = ' AND q.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";*/
$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);
while($row = Database::fetch_array($result, 'ASSOC')) {
$main_question_list[] = $row;
}
} else {
//
// All tests for selected course
//
//
// All tests for selected course
//
// if we have not selected any option in the list-box 'Filter'
$filter = '';
$from = '';
if (isset($courseCategoryId) && $courseCategoryId > 0) {
$from = ", $TBL_COURSE_REL_CATEGORY crc ";
$filter .= " AND crc.c_id=$selected_course AND crc.question_id=qu.id AND crc.category_id=$courseCategoryId";
}
}
if (isset($exerciseLevel) && $exerciseLevel != -1) {
$filter .= ' AND level='.$exerciseLevel.' ';
}
@ -488,20 +511,20 @@ if ($exerciseId > 0) {
if (!empty($session_id) && $session_id != '-1') {
$main_question_list = array();
if (!empty($course_list))
foreach ($course_list as $course_item) {
foreach ($course_list as $course_item) {
if (!empty($selected_course) && $selected_course != '-1') {
if ($selected_course != $course_item['id']) {
if ($selected_course != $course_item['id']) {
continue;
}
}
}
$exercise_list = get_all_exercises($course_item, $session_id);
if (!empty($exercise_list)) {
foreach ($exercise_list as $exercise) {
if (!empty($exercise_list)) {
foreach ($exercise_list as $exercise) {
$my_exercise = new Exercise($course_item['id']);
$my_exercise->read($exercise['id']);
if (!empty($my_exercise)) {
if (!empty($my_exercise->questionList)) {
foreach ($my_exercise->questionList as $question_id) {
if (!empty($my_exercise->questionList)) {
foreach ($my_exercise->questionList as $question_id) {
$question_obj = Question::read($question_id, $course_item['id']);
if ($exerciseLevel != '-1')
if ($exerciseLevel != $question_obj->level) {
@ -512,7 +535,7 @@ if ($exerciseId > 0) {
continue;
}
$category_list = Testcategory::getCategoryForQuestion($question_obj->id, $selected_course);
if ($courseCategoryId > 0 && !empty($category_list)) {
continue;
}
@ -520,26 +543,26 @@ if ($exerciseId > 0) {
if ($question_obj->type == HOT_SPOT_DELINEATION) {
continue;
}
}
$question_row = array( 'id' => $question_obj->id,
'question' => $question_obj->question,
'type' => $question_obj->type,
'level' => $question_obj->level,
}
$question_row = array( 'id' => $question_obj->id,
'question' => $question_obj->question,
'type' => $question_obj->type,
'level' => $question_obj->level,
'exercise_id' => $exercise['id'],
'course_id' => $course_item['id'],
);
$main_question_list[] = $question_row;
$main_question_list[] = $question_row;
}
}
}
}
}
}
}
}
}
}
}
else {
//
//
// All tests for the course selected, not in session
//
//
$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";
$result = Database::query($sql);
while($row = Database::fetch_array($result, 'ASSOC')) {
@ -569,7 +592,7 @@ $nbrQuestions = count($main_question_list);
+----------------------+---------------------+---------------------+----------------------+
(*) this is the only way to delete or modify orphan questions
*/
//
//
if ($fromExercise <= 0) { // NOT IN A TEST - IN THE COURSE
if ($selected_course == api_get_course_int_id()) {
$actionLabel = get_lang('Modify');
@ -598,9 +621,9 @@ else { // IN A TEST - IN THE COURSE
$questionTagA = 0;
}
}
//
//
// display table
//
//
$header = array();
$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"), '');
@ -626,22 +649,22 @@ if (is_array($main_question_list)) {
$row[] = $question_type;
$row[] = get_question_categorie_for_question($selected_course, $tabQuestion['id']);
$row[] = $tabQuestion['level'];
$row[] = get_action_icon_for_question($actionIcon1,
$fromExercise,
$tabQuestion['id'],
$tabQuestion['type'],
$tabQuestion['question'],
$selected_course,
$courseCategoryId,
$exerciseLevel,
$answerType,
$row[] = get_action_icon_for_question($actionIcon1,
$fromExercise,
$tabQuestion['id'],
$tabQuestion['type'],
$tabQuestion['question'],
$selected_course,
$courseCategoryId,
$exerciseLevel,
$answerType,
$session_id, $exerciseId).
"&nbsp;".
get_action_icon_for_question($actionIcon2, $fromExercise, $tabQuestion['id'], $tabQuestion['type'],
$tabQuestion['question'], $selected_course, $courseCategoryId, $exerciseLevel, $answerType,
get_action_icon_for_question($actionIcon2, $fromExercise, $tabQuestion['id'], $tabQuestion['type'],
$tabQuestion['question'], $selected_course, $courseCategoryId, $exerciseLevel, $answerType,
$session_id, $exerciseId);
$data[] = $row;
}
}
}
Display :: display_sortable_table($header, $data, '', array('per_page_default'=>999,'per_page'=>999,'page_nr'=>1));
@ -683,7 +706,7 @@ function reset_menu_exo_lvl_type() {
$courseCategoryId = 0;
}
//
//
// return the <a> link to admin question, if needed
// hubert.borderiou 13-10-2011
function get_a_tag_for_question($in_addA, $in_fromex, $in_questionid, $in_questiontype, $in_questionname) {
@ -700,24 +723,24 @@ $row[] = get_action_icon_for_question(
$actionIcon1, --
$fromExercise, --
$tabQuestion['id'], --
$tabQuestion['type'],
$tabQuestion['question'],
$selected_course,
$courseCategoryId,
$exerciseLevel,
$answerType,
$session_id,
$tabQuestion['type'],
$tabQuestion['question'],
$selected_course,
$courseCategoryId,
$exerciseLevel,
$answerType,
$session_id,
$exerciseId).
"&nbsp;".
get_action_icon_for_question($actionIcon2, $fromExercise, $tabQuestion['id'], $tabQuestion['type'],
$tabQuestion['question'], $selected_course, $courseCategoryId, $exerciseLevel, $answerType,
get_action_icon_for_question($actionIcon2, $fromExercise, $tabQuestion['id'], $tabQuestion['type'],
$tabQuestion['question'], $selected_course, $courseCategoryId, $exerciseLevel, $answerType,
$session_id, $exerciseId);
*/
//
//
// return the <a> html code for delete, add, clone, edit a question
// hubert.borderiou 13-10-2011
// in_action = the code of the action triggered by the button
@ -725,21 +748,21 @@ $session_id, $exerciseId);
// in_questionid = the id of the current question
// in_questiontype = the code of the type of the current question
// in_questionname = the name of the question
// 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_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_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_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
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
) {
$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";
switch ($in_action) {
case "delete" :
case "delete" :
$res = "<a href='".api_get_self()."?".api_get_cidreq()."&delete=$in_questionid$getParams' onclick='return confirm_your_choice()'>";
$res .= Display::return_icon("delete.gif", get_lang('Delete'));
$res .= "</a>";
@ -766,7 +789,7 @@ function get_action_icon_for_question($in_action, $from_exercice, $in_questionid
$res .= Display::return_icon('cd.gif', get_lang('ReUseACopyInCurrentTest'));
$res .= "</a>";
break;
default :
default :
$res = $in_action;
break;
}
@ -776,9 +799,9 @@ function get_action_icon_for_question($in_action, $from_exercice, $in_questionid
// return the icon for the question type
// hubert.borderiou 13-10-2011
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;
if (!empty($myObjQuestion)) {
if (!empty($myObjQuestion)) {
list($typeImg, $typeExpl) = $myObjQuestion->get_type_icon_html();
$questionType = Display::tag('div', Display::return_icon($typeImg, $typeExpl, array(), 32), array());
unset($myObjQuestion);
@ -790,7 +813,7 @@ function get_question_type_for_question($in_selectedcourse, $in_questionid) {
// hubert.borderiou 13-10-2011
function get_question_categorie_for_question($course_id, $question_id) {
global $all_category_list;
$objQuestionTmp = Question :: read($question_id, $course_id);
return Testcategory::return_category_labels($objQuestionTmp->category_list, $all_category_list);
$objQuestionTmp = Question :: read($question_id, $course_id);
return Testcategory::return_category_labels($objQuestionTmp->category_list, $all_category_list);
}

Loading…
Cancel
Save