@ -131,15 +131,15 @@ class CourseBuilder
*
* @param int $session_id
* @param string $courseCode
* @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 $withBaseContent true if you want to get the elements that exists in the course and
* in the session, (session_id = 0 or session_id = X)
*
* @return Course The course object structure
*/
public function build(
$session_id = 0,
$courseCode = '',
$with_base_c ontent = false
$withBaseC ontent = false
) {
$table_properties = Database::get_course_table(TABLE_ITEM_PROPERTY);
$course = api_get_course_info($courseCode);
@ -152,7 +152,7 @@ class CourseBuilder
$this->$function_build(
$session_id,
$courseId,
$with_base_c ontent,
$withBaseC ontent,
$specificIdList
);
}
@ -204,14 +204,14 @@ class CourseBuilder
*
* @param int $session_id
* @param int $courseId
* @param bool $with_base_c ontent
* @param array $id_l ist
* @param bool $withBaseC ontent
* @param array $idL ist
*/
public function build_documents(
$session_id = 0,
$courseId = 0,
$with_base_c ontent = false,
$id_l ist = []
$withBaseC ontent = false,
$idL ist = []
) {
$table_doc = Database::get_course_table(TABLE_DOCUMENT);
$table_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
@ -220,9 +220,16 @@ class CourseBuilder
$avoid_paths = " path NOT LIKE '/shared_folder%' AND
path NOT LIKE '/chat_files%' ";
$documentCondition = '';
if (!empty($idList)) {
$idList = array_unique($idList);
$idList = array_map('intval', $idList);
$documentCondition = ' d.iid IN ("'.implode('","', $idList).'") AND ';
}
if (!empty($courseId) & & !empty($session_id)) {
$session_id = intval($session_id);
if ($with_base_content) {
if ($withBaseC ontent) {
$session_condition = api_get_session_condition(
$session_id,
true,
@ -247,6 +254,7 @@ class CourseBuilder
d.c_id = $courseId AND
p.c_id = $courseId AND
tool = '".TOOL_DOCUMENT."' AND
$documentCondition
p.visibility != 2 AND
path NOT LIKE '/images/gallery%' AND
$avoid_paths
@ -261,6 +269,7 @@ class CourseBuilder
d.c_id = $courseId AND
p.c_id = $courseId AND
tool = '".TOOL_DOCUMENT."' AND
$documentCondition
$avoid_paths AND
p.visibility != 2 $session_condition
ORDER BY path";
@ -288,6 +297,7 @@ class CourseBuilder
d.c_id = $courseId AND
p.c_id = $courseId AND
tool = '".TOOL_DOCUMENT."' AND
$documentCondition
p.visibility != 2 AND
path NOT LIKE '/images/gallery%' AND
$avoid_paths AND
@ -302,14 +312,15 @@ class CourseBuilder
d.c_id = $courseId AND
p.c_id = $courseId AND
tool = '".TOOL_DOCUMENT."' AND
$documentCondition
p.visibility != 2 AND
$avoid_paths AND
(d.session_id = 0 OR d.session_id IS NULL)
ORDER BY path";
}
$db_ result = Database::query($sql);
while ($obj = Database::fetch_object($db_ result)) {
$result = Database::query($sql);
while ($obj = Database::fetch_object($result)) {
$doc = new Document(
$obj->id,
$obj->path,
@ -326,26 +337,32 @@ class CourseBuilder
/**
* Build the forums.
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_c ontent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseC ontent Whether to include content from the course without session or not
* @param array $idList If you want to restrict the structure to only the given IDs
*/
public function build_forums(
$session_id = 0,
$courseId = 0,
$with_base_c ontent = false,
$id_l ist = []
$withBaseC ontent = false,
$idL ist = []
) {
$table = Database::get_course_table(TABLE_FORUM);
$sessionCondition = api_get_session_condition(
$session_id,
true,
$with_base_c ontent
$withBaseC ontent
);
$sql = "SELECT * FROM $table WHERE c_id = $courseId $sessionCondition";
$idCondition = '';
if (!empty($idList)) {
$idList = array_unique($idList);
$idList = array_map('intval', $idList);
$idCondition = ' AND iid IN ("'.implode('","', $idList).'") ';
}
$sql = "SELECT * FROM $table WHERE c_id = $courseId $sessionCondition $idCondition";
$sql .= " ORDER BY forum_title, forum_category";
$db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) {
@ -357,27 +374,34 @@ class CourseBuilder
/**
* Build a forum-category.
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_c ontent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseC ontent Whether to include content from the course without session or not
* @param array $idList If you want to restrict the structure to only the given IDs
*/
public function build_forum_category(
$session_id = 0,
$courseId = 0,
$with_base_c ontent = false,
$id_l ist = []
$withBaseC ontent = false,
$idL ist = []
) {
$table = Database::get_course_table(TABLE_FORUM_CATEGORY);
$sessionCondition = api_get_session_condition(
$session_id,
true,
$with_base_c ontent
$withBaseC ontent
);
$idCondition = '';
if (!empty($idList)) {
$idList = array_unique($idList);
$idList = array_map('intval', $idList);
$idCondition = ' AND iid IN ("'.implode('","', $idList).'") ';
}
$sql = "SELECT * FROM $table
WHERE c_id = $courseId $sessionCondition
WHERE c_id = $courseId $sessionCondition $idCondition
ORDER BY cat_title";
$result = Database::query($sql);
@ -390,34 +414,41 @@ class CourseBuilder
/**
* Build the forum-topics.
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_c ontent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseC ontent Whether to include content from the course without session or not
* @param array $idList If you want to restrict the structure to only the given IDs
*/
public function build_forum_topics(
$session_id = 0,
$courseId = 0,
$with_base_c ontent = false,
$id_l ist = []
$withBaseC ontent = false,
$idL ist = []
) {
$table = Database::get_course_table(TABLE_FORUM_THREAD);
$sessionCondition = api_get_session_condition(
$session_id,
true,
$with_base_c ontent
$withBaseC ontent
);
$idCondition = '';
if (!empty($idList)) {
$idList = array_map('intval', $idList);
$idCondition = ' AND iid IN ("'.implode('","', $idList).'") ';
}
$sql = "SELECT * FROM $table WHERE c_id = $courseId
$sessionCondition
$idCondition
ORDER BY thread_title ";
$result = Database::query($sql);
while ($obj = Database::fetch_object($result)) {
$forum_t opic = new ForumTopic($obj);
$this->course->add_resource($forum_t opic);
$this->build_forum_posts($courseId, $obj->thread_id, $obj->forum_id, true );
$forumT opic = new ForumTopic($obj);
$this->course->add_resource($forumT opic);
$this->build_forum_posts($courseId, $obj->thread_id, $obj->forum_id);
}
}
@ -425,24 +456,31 @@ class CourseBuilder
* Build the forum-posts
* TODO: All tree structure of posts should be built, attachments for example.
*
* @param int $courseId Internal course ID
* @param int $thread_id Internal thread ID
* @param int $forum_id Internal forum ID
* @param bool $only_first_post Whether to only copy the first post or no t
* @param int $courseId Internal course ID
* @param int $thread_id Internal thread ID
* @param int $forum_id Internal forum ID
* @param array $idLis t
*/
public function build_forum_posts(
$courseId = 0,
$thread_id = null,
$forum_id = null,
$only_first_post = false
$idList = []
) {
$table = Database::get_course_table(TABLE_FORUM_POST);
$courseId = (int) $courseId;
$sql = "SELECT * FROM $table WHERE c_id = $courseId ";
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 ";
}
if (!empty($idList)) {
$idList = array_map('intval', $idList);
$sql .= ' AND iid IN ("'.implode('","', $idList).'") ';
}
$sql .= " ORDER BY post_id ASC LIMIT 1";
$db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) {
@ -454,21 +492,21 @@ class CourseBuilder
/**
* Build the links.
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_c ontent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseC ontent Whether to include content from the course without session or not
* @param array $idList If you want to restrict the structure to only the given IDs
*/
public function build_links(
$session_id = 0,
$courseId = 0,
$with_base_c ontent = false,
$id_l ist = []
$withBaseC ontent = false,
$idL ist = []
) {
$categories = LinkManager::getLinkCategories(
$courseId,
$session_id,
$with_base_c ontent
$withBaseC ontent
);
// Adding empty category
@ -481,10 +519,16 @@ class CourseBuilder
$category['id'],
$courseId,
$session_id,
$with_base_c ontent
$withBaseC ontent
);
foreach ($links as $item) {
if (!empty($idList)) {
if (!in_array($item['id'], $idList)) {
continue;
}
}
$link = new Link(
$item['id'],
$item['title'],
@ -506,25 +550,27 @@ class CourseBuilder
/**
* Build tool intro.
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_c ontent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseC ontent Whether to include content from the course without session or not
* @param array $idList If you want to restrict the structure to only the given IDs
*/
public function build_tool_intro(
$session_id = 0,
$courseId = 0,
$with_base_c ontent = false,
$id_l ist = []
$withBaseC ontent = false,
$idL ist = []
) {
$table = Database::get_course_table(TABLE_TOOL_INTRO);
$sessionCondition = api_get_session_condition(
$session_id,
true,
$with_base_c ontent
$withBaseC ontent
);
$courseId = (int) $courseId;
$sql = "SELECT * FROM $table
WHERE c_id = $courseId $sessionCondition";
@ -563,24 +609,31 @@ class CourseBuilder
/**
* Build the Quizzes.
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_c ontent Whether to include content from the course without session or not
* @param array $idList If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseC ontent Whether to include content from the course without session or not
* @param array $idList If you want to restrict the structure to only the given IDs
*/
public function build_quizzes(
$session_id = 0,
$courseId = 0,
$with_base_c ontent = false,
$withBaseC ontent = false,
$idList = []
) {
$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);
$courseId = (int) $courseId;
$idCondition = '';
if (!empty($idList)) {
$idList = array_map('intval', $idList);
$idCondition = ' iid IN ("'.implode('","', $idList).'") AND ';
}
if (!empty($courseId) & & !empty($session_id)) {
$session_id = intval($session_id);
if ($with_base_content) {
if ($withBaseC ontent) {
$session_condition = api_get_session_condition(
$session_id,
true,
@ -592,13 +645,22 @@ class CourseBuilder
true
);
}
//select only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes)
// Select only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes)
$sql = "SELECT * FROM $table_qui
WHERE c_id = $courseId AND active >=0 $session_condition";
WHERE
c_id = $courseId AND
$idCondition
active >=0
$session_condition ";
} else {
//select only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes)
// S elect only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes)
$sql = "SELECT * FROM $table_qui
WHERE c_id = $courseId AND active >=0 AND (session_id = 0 OR session_id IS NULL)";
WHERE
c_id = $courseId AND
$idCondition
active >=0 AND
(session_id = 0 OR session_id IS NULL)";
}
$sql .= 'ORDER BY title';
@ -613,7 +675,6 @@ class CourseBuilder
$obj->sound = $doc->id;
}
$quiz = new Quiz($obj);
$sql = 'SELECT * FROM '.$table_rel.'
WHERE c_id = '.$courseId.' AND exercice_id = '.$obj->id;
$db_result2 = Database::query($sql);
@ -642,6 +703,8 @@ class CourseBuilder
$table_que = Database::get_course_table(TABLE_QUIZ_QUESTION);
$table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER);
$courseId = (int) $courseId;
// Building normal tests.
$sql = "SELECT * FROM $table_que
WHERE c_id = $courseId ";
@ -668,6 +731,7 @@ class CourseBuilder
$obj->extra,
$question_category_id
);
$question->addPicture($this);
$sql = 'SELECT * FROM '.$table_ans.'
WHERE c_id = '.$courseId.' AND question_id = '.$obj->id;
@ -685,9 +749,7 @@ class CourseBuilder
$obj2->hotspot_type
);
if ($obj->type == MULTIPLE_ANSWER_TRUE_FALSE) {
$table_options = Database::get_course_table(
TABLE_QUIZ_QUESTION_OPTION
);
$table_options = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
$sql = 'SELECT * FROM '.$table_options.'
WHERE c_id = '.$courseId.' AND question_id = '.$obj->id;
$db_result3 = Database::query($sql);
@ -706,7 +768,6 @@ class CourseBuilder
// 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 question_id, q.* FROM $table_que q
INNER JOIN $table_rel r
@ -745,10 +806,7 @@ class CourseBuilder
if (!isset($this->course->resources[$obj->id])) {
// find the question category
// @todo : need to be adapted for multi category questions in 1.10
$question_category_id = TestCategory::getCategoryForQuestion(
$obj->id,
$courseId
);
$question_category_id = TestCategory::getCategoryForQuestion($obj->id, $courseId);
$question = new QuizQuestion(
$obj->id,
$obj->question,
@ -761,6 +819,7 @@ class CourseBuilder
$obj->extra,
$question_category_id
);
$question->addPicture($this);
$sql = "SELECT * FROM $table_ans
WHERE c_id = $courseId AND question_id = ".$obj->id;
$db_result2 = Database::query($sql);
@ -853,6 +912,8 @@ class CourseBuilder
$obj->level,
$obj->extra
);
$question->addPicture($this);
$sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.$obj->id;
$db_result2 = Database::query($sql);
while ($obj2 = Database::fetch_object($db_result2)) {
@ -904,24 +965,26 @@ class CourseBuilder
/**
* Build the Surveys.
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_c ontent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseC ontent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
*/
public function build_surveys(
$session_id = 0,
$courseId = 0,
$with_base_c ontent = false,
$withBaseC ontent = false,
$id_list = []
) {
$table_survey = Database::get_course_table(TABLE_SURVEY);
$table_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
$courseId = (int) $courseId;
$sessionCondition = api_get_session_condition(
$session_id,
true,
$with_base_c ontent
$withBaseC ontent
);
$sql = 'SELECT * FROM '.$table_survey.'
@ -971,6 +1034,8 @@ class CourseBuilder
$table_que = Database::get_course_table(TABLE_SURVEY_QUESTION);
$table_opt = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
$courseId = (int) $courseId;
$sql = 'SELECT * FROM '.$table_que.' WHERE c_id = '.$courseId.' ';
$db_result = Database::query($sql);
$is_required = 0;
@ -1005,15 +1070,15 @@ class CourseBuilder
/**
* Build the announcements.
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_c ontent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseC ontent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
*/
public function build_announcements(
$session_id = 0,
$courseId = 0,
$with_base_c ontent = false,
$withBaseC ontent = false,
$id_list = []
) {
$table = Database::get_course_table(TABLE_ANNOUNCEMENT);
@ -1021,9 +1086,11 @@ class CourseBuilder
$sessionCondition = api_get_session_condition(
$session_id,
true,
$with_base_c ontent
$withBaseC ontent
);
$courseId = (int) $courseId;
$sql = 'SELECT * FROM '.$table.'
WHERE c_id = '.$courseId.' '.$sessionCondition;
$db_result = Database::query($sql);
@ -1067,15 +1134,15 @@ class CourseBuilder
/**
* Build the events.
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_c ontent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseC ontent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
*/
public function build_events(
$session_id = 0,
$courseId = 0,
$with_base_c ontent = false,
$withBaseC ontent = false,
$id_list = []
) {
$table = Database::get_course_table(TABLE_AGENDA);
@ -1083,9 +1150,11 @@ class CourseBuilder
$sessionCondition = api_get_session_condition(
$session_id,
true,
$with_base_c ontent
$withBaseC ontent
);
$courseId = (int) $courseId;
$sql = 'SELECT * FROM '.$table.'
WHERE c_id = '.$courseId.' '.$sessionCondition;
$db_result = Database::query($sql);
@ -1125,22 +1194,23 @@ class CourseBuilder
/**
* Build the course-descriptions.
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_c ontent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseC ontent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
*/
public function build_course_descriptions(
$session_id = 0,
$courseId = 0,
$with_base_c ontent = false,
$withBaseC ontent = false,
$id_list = []
) {
$table = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$courseId = (int) $courseId;
if (!empty($session_id) & & !empty($courseId)) {
$session_id = intval($session_id);
if ($with_base_c ontent) {
if ($withBaseC ontent) {
$session_condition = api_get_session_condition(
$session_id,
true,
@ -1175,24 +1245,28 @@ class CourseBuilder
/**
* Build the learnpaths.
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_content Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseContent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param bool $addScormFolder
*/
public function build_learnpaths(
$session_id = 0,
$courseId = 0,
$with_base_content = false,
$id_list = []
$withBaseContent = false,
$id_list = [],
$addScormFolder = true
) {
$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);
$courseId = (int) $courseId;
if (!empty($session_id) & & !empty($courseId)) {
$session_id = intval($session_id);
if ($with_base_c ontent) {
if ($withBaseC ontent) {
$session_condition = api_get_session_condition(
$session_id,
true,
@ -1216,9 +1290,9 @@ class CourseBuilder
$sql .= " AND id IN (".implode(', ', $id_list).") ";
}
$db_ result = Database::query($sql);
if ($db_ result) {
while ($obj = Database::fetch_object($db_ result)) {
$result = Database::query($sql);
if ($result) {
while ($obj = Database::fetch_object($result)) {
$items = [];
$sql = "SELECT * FROM ".$table_item."
WHERE c_id = '$courseId' AND lp_id = ".$obj->id;
@ -1250,11 +1324,9 @@ class CourseBuilder
(link LIKE '%lp_controller.php%lp_id=".$obj->id."%' AND image='scormbuilder.gif') AND
visibility = '1' ";
$db_tool = Database::query($sql);
$visibility = '0';
if (Database::num_rows($db_tool)) {
$visibility = '1';
} else {
$visibility = '0';
}
$lp = new CourseCopyLearnpath(
@ -1286,44 +1358,59 @@ class CourseBuilder
$obj->session_id,
$items
);
$this->course->add_resource($lp);
if (!empty($obj->preview_image)) {
// Add LP teacher image
$asset = new Asset(
$obj->preview_image,
'/upload/learning_path/images/'.$obj->preview_image,
'/upload/learning_path/images/'.$obj->preview_image
);
$this->course->add_resource($asset);
}
}
}
// Save scorm directory (previously build_scorm_documents())
$i = 1;
if ($dir = @opendir($this->course->backup_path.'/scorm')) {
while ($file = readdir($dir)) {
if (is_dir($this->course->backup_path.'/scorm/'.$file) & &
!in_array($file, ['.', '..'])
) {
$doc = new ScormDocument($i++, '/'.$file, $file);
$this->course->add_resource($doc);
if ($addScormFolder) {
$i = 1;
if ($dir = @opendir($this->course->backup_path.'/scorm')) {
while ($file = readdir($dir)) {
if (is_dir($this->course->backup_path.'/scorm/'.$file) & &
!in_array($file, ['.', '..'])
) {
$doc = new ScormDocument($i++, '/'.$file, $file);
$this->course->add_resource($doc);
}
}
closedir($dir);
}
closedir($dir);
}
}
/**
* Build the glossaries.
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_c ontent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseC ontent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
*/
public function build_glossary(
$session_id = 0,
$courseId = 0,
$with_base_c ontent = false,
$withBaseC ontent = false,
$id_list = []
) {
$table_glossary = Database::get_course_table(TABLE_GLOSSARY);
$courseId = (int) $courseId;
if (!empty($session_id) & & !empty($courseId)) {
$session_id = intval($session_id);
if ($with_base_c ontent) {
if ($withBaseC ontent) {
$session_condition = api_get_session_condition(
$session_id,
true,
@ -1335,6 +1422,7 @@ class CourseBuilder
true
);
}
//@todo check this queries are the same ...
if (!empty($this->course->type) & & $this->course->type == 'partial') {
$sql = 'SELECT * FROM '.$table_glossary.' g
@ -1403,22 +1491,23 @@ class CourseBuilder
}
/**
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_c ontent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseC ontent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
*/
public function build_wiki(
$session_id = 0,
$courseId = 0,
$with_base_c ontent = false,
$withBaseC ontent = false,
$id_list = []
) {
$tbl_wiki = Database::get_course_table(TABLE_WIKI);
$courseId = (int) $courseId;
if (!empty($session_id) & & !empty($courseId)) {
$session_id = intval($session_id);
if ($with_base_c ontent) {
if ($withBaseC ontent) {
$session_condition = api_get_session_condition(
$session_id,
true,
@ -1458,24 +1547,25 @@ class CourseBuilder
/**
* Build the Surveys.
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_c ontent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseC ontent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
*/
public function build_thematic(
$session_id = 0,
$courseId = 0,
$with_base_c ontent = false,
$withBaseC ontent = false,
$id_list = []
) {
$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);
$courseId = (int) $courseId;
$courseInfo = api_get_course_info_by_id($courseId);
$session_id = intval($session_id);
if ($with_base_c ontent) {
if ($withBaseC ontent) {
$session_condition = api_get_session_condition(
$session_id,
true,
@ -1532,21 +1622,21 @@ class CourseBuilder
/**
* Build the attendances.
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_c ontent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseC ontent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
*/
public function build_attendance(
$session_id = 0,
$courseId = 0,
$with_base_c ontent = false,
$withBaseC ontent = false,
$id_list = []
) {
$table_attendance = Database::get_course_table(TABLE_ATTENDANCE);
$table_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
$sessionCondition = api_get_session_condition($session_id, true, $with_base_content) ;
$sessionCondition = api_get_session_condition($session_id, true, $withBaseContent);
$courseId = (int) $courseId ;
$sql = 'SELECT * FROM '.$table_attendance.'
WHERE c_id = '.$courseId.' '.$sessionCondition;
@ -1567,33 +1657,42 @@ class CourseBuilder
/**
* Build the works (or "student publications", or "assignments").
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_c ontent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseC ontent Whether to include content from the course without session or not
* @param array $idList If you want to restrict the structure to only the given IDs
*/
public function build_works(
$session_id = 0,
$courseId = 0,
$with_base_c ontent = false,
$id_l ist = []
$withBaseC ontent = false,
$idL ist = []
) {
$table_work = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$sessionCondition = api_get_session_condition(
$session_id,
true,
$with_base_c ontent
$withBaseC ontent
);
$courseId = (int) $courseId;
$idCondition = '';
if (!empty($idList)) {
$idList = array_map('intval', $idList);
$idCondition = ' AND iid IN ("'.implode('","', $idList).'") ';
}
$sql = "SELECT * FROM $table_work
WHERE
c_id = $courseId
$sessionCondition AND
c_id = $courseId
$sessionCondition AND
filetype = 'folder' AND
parent_id = 0 AND
active = 1";
$db_result = Database::query($sql);
while ($row = Database::fetch_array($db_result, 'ASSOC')) {
active = 1
$idCondition
";
$result = Database::query($sql);
while ($row = Database::fetch_array($result, 'ASSOC')) {
$obj = new Work($row);
$this->course->add_resource($obj);
}
@ -1602,12 +1701,12 @@ class CourseBuilder
/**
* @param int $session_id
* @param int $courseId
* @param bool $with_base_c ontent
* @param bool $withBaseC ontent
*/
public function build_gradebook(
$session_id = 0,
$courseId = 0,
$with_base_c ontent = false
$withBaseC ontent = false
) {
$courseInfo = api_get_course_info_by_id($courseId);
$courseCode = $courseInfo['code'];