@ -32,41 +32,41 @@ require_once 'Attendance.class.php';
class CourseBuilder {
/** Course */
var $course;
/* With this array you can filter the tools you want to be parsed by default all tools are included*/
var $tools_to_build = array(
'announcements',
'attendance',
'course_descriptions',
'documents',
'documents',
'events',
'forum_category',
'forum_category',
'forums',
'forum_topics',
'glossary',
'quizzes',
'quizzes',
'learnpaths',
'links',
'links',
'surveys',
'tool_intro',
'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) */
var $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
@ -173,10 +173,10 @@ class CourseBuilder {
$this->course->resources[$type][$id]->item_properties = $all_properties;
}
}
}
}
return $this->course;
}
/**
* Build the documents
*/
@ -184,76 +184,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);
@ -261,25 +261,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
*/
@ -287,39 +287,39 @@ 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);
@ -329,36 +329,36 @@ class CourseBuilder {
$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";
}
@ -378,13 +378,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)) {
@ -392,14 +392,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";
@ -411,7 +411,7 @@ class CourseBuilder {
}
return 0;
}
/**
* Build the Quizzes
*/
@ -420,21 +420,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) {
@ -443,27 +443,27 @@ class CourseBuilder {
$doc = Database::fetch_object($res);
$obj->sound = $doc->id;
}
$quiz = new Quiz( $obj->id,
$obj->title,
$obj->description,
$obj->random,
$obj->type,
$obj->active,
$obj->sound,
$obj->max_attempt,
$obj->results_disabled,
$obj->access_condition,
$obj->start_time,
$obj->end_time,
$obj->feedback_type,
$obj->random_answers,
$obj->expired_time,
$quiz = new Quiz( $obj->id,
$obj->title,
$obj->description,
$obj->random,
$obj->type,
$obj->active,
$obj->sound,
$obj->max_attempt,
$obj->results_disabled,
$obj->access_condition,
$obj->start_time,
$obj->end_time,
$obj->feedback_type,
$obj->random_answers,
$obj->expired_time,
$obj->session_id);
$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);
}
@ -473,24 +473,24 @@ 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);
$table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
// 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);
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);
$sql = 'SELECT * FROM '.$table_ans.' WHERE c_id = '.$course_id.' AND question_id = '.$obj->id;
$db_result2 = Database::query($sql);
@ -502,37 +502,40 @@ 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
(quizz_questions.exercice_id IS NULL OR exercices.active = -1) "; // active = -1 means "deleted" test.
$db_result = Database::query($sql);
if (Database::num_rows($db_result) > 0) {
$build_orphan_questions = true;
while ($obj = Database::fetch_object($db_result)) {
$question = new QuizQuestion($obj->id.$course_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);
//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);
}
}
$this->course->add_resource($question);
}
$this->course->add_resource($question);
}
}
if ($build_orphan_questions) {
$this->course->add_resource(new Quiz(-1, get_lang('OrphanQuestions', ''), '', 0, 0, 1, '', 0));
}
}
/**
* Build the orphan questions
*/
@ -541,19 +544,19 @@ 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();
$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
$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
quizz_questions.c_id = '.$course_id.' AND
exercices.c_id = '.$course_id.' AND
(quizz_questions.exercice_id IS NULL OR
(quizz_questions.exercice_id IS NULL OR
exercices.active = -1)';
$db_result = Database::query($sql);
if (Database::num_rows($db_result) > 0) {
@ -572,7 +575,7 @@ class CourseBuilder {
}
}
}
/**
* Build the Surveys
*/
@ -580,7 +583,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)) {
@ -605,9 +608,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)){
@ -623,18 +626,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);
@ -644,10 +647,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);
}
}
/**
@ -656,26 +659,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
@ -683,16 +686,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);
@ -709,30 +712,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)) {
@ -756,7 +759,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;
}
@ -784,7 +787,7 @@ class CourseBuilder {
$obj->display_order,
$obj->js_lib,
$obj->content_license,
$obj->debug,
$obj->debug,
$visibility,
$obj->author,
$obj->preview_image,
@ -793,7 +796,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);
@ -818,16 +821,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 {
@ -835,7 +838,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 {
@ -881,16 +884,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);
@ -902,7 +905,7 @@ class CourseBuilder {
$this->course->add_resource($wiki);
}
}
/**
* Build the Surveys
*/
@ -910,76 +913,76 @@ 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)
WHERE t.c_id = $course_id AND
tp.c_id = $course_id AND
thematic_id = {$row['id']} AND
FROM $table_thematic_plan tp
INNER JOIN $table_thematic t ON (t.id=tp.thematic_id)
WHERE t.c_id = $course_id AND
tp.c_id = $course_id AND
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 Attendance($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);
}
}
}
}