123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137 |
- <?php
- /* For licensing terms, see /license.txt */
- require_once 'Course.class.php';
- require_once 'Event.class.php';
- require_once 'Link.class.php';
- require_once 'ToolIntro.class.php';
- require_once 'Document.class.php';
- require_once 'ScormDocument.class.php';
- require_once 'LinkCategory.class.php';
- require_once 'CourseDescription.class.php';
- require_once 'ForumPost.class.php';
- require_once 'ForumTopic.class.php';
- require_once 'Forum.class.php';
- require_once 'ForumCategory.class.php';
- require_once 'Quiz.class.php';
- require_once 'QuizQuestion.class.php';
- require_once 'CourseCopyTestCategory.php';
- require_once 'CourseCopyLearnpath.class.php';
- require_once 'Survey.class.php';
- require_once 'SurveyQuestion.class.php';
- require_once 'Glossary.class.php';
- require_once 'CourseSession.class.php';
- require_once 'wiki.class.php';
- require_once 'Thematic.class.php';
- require_once 'Attendance.class.php';
- require_once 'Work.class.php';
- /**
- * Class which can build a course-object from a Chamilo-course.
- * @author Bart Mollet <bart.mollet@hogent.be>
- * @package chamilo.backup
- */
- 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',
- 'attendance',
- 'course_descriptions',
- 'documents',
- 'events',
- 'forum_category',
- 'forums',
- 'forum_topics',
- 'glossary',
- 'quizzes',
- 'test_category',
- 'learnpaths',
- 'links',
- 'surveys',
- 'tool_intro',
- 'thematic',
- 'wiki',
- 'works'
- );
- /* 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
- */
- public function __construct($type='', $course = null)
- {
- $_course = api_get_course_info();
- if (!empty($course['official_code'])){
- $_course = $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'].'/';
- $this->course->backup_path = api_get_path(SYS_COURSE_PATH).$_course['path'];
- $this->course->encoding = api_get_system_encoding(); //current platform encoding
- $this->course->db_name = $_course['dbName'];
- $this->course->info = $_course;
- }
- /**
- *
- * @param array $array
- */
- public function set_tools_to_build($array)
- {
- $this->tools_to_build = $array;
- }
- /**
- *
- * @param array $array
- */
- public function set_tools_specific_id_list($array)
- {
- $this->specific_id_list = $array;
- }
- /**
- * Get the created course
- * @return course The course
- */
- public 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)
- */
- public 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'];
- foreach ($this->tools_to_build as $tool) {
- $function_build = 'build_'.$tool;
- $specificIdList = isset($this->specific_id_list[$tool]) ? $this->specific_id_list[$tool] : null;
- $this->$function_build(
- $session_id,
- $course_code,
- $with_base_content,
- $specificIdList
- );
- }
- //TABLE_LINKED_RESOURCES is the "resource" course table, which is deprecated, apparently
- foreach ($this->course->resources as $type => $resources) {
- foreach ($resources as $id => $resource) {
- $sql = "SELECT * FROM $table_link
- WHERE
- c_id = $course_id AND
- source_type = '".$resource->get_type()."' AND
- source_id = '".$resource->get_id()."'";
- $res = Database::query($sql);
- while ($link = Database::fetch_object($res)) {
- $this->course->resources[$type][$id]->add_linked_resource($link->resource_type, $link->resource_id);
- }
- }
- }
- // Once we've built the resouces array a bit more, try to get items
- // from the item_propry table and order them in the "resources" array
- foreach ($this->course->resources as $type => $resources) {
- foreach ($resources as $id => $resource) {
- $tool = $resource->get_tool();
- if ($tool != null) {
- $sql = "SELECT * FROM $table_properties
- WHERE
- c_id = $course_id AND
- tool = '".$tool."' AND
- ref='".$resource->get_id()."'";
- $res = Database::query($sql);
- $all_properties = array ();
- while ($item_property = Database::fetch_array($res)) {
- $all_properties[]= $item_property;
- }
- $this->course->resources[$type][$id]->item_properties = $all_properties;
- }
- }
- }
- return $this->course;
- }
- /**
- * Build the documents
- * @param int $session_id
- * @param string $course_code
- * @param bool $with_base_content
- * @param array $id_list
- */
- public function build_documents($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_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 = " 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);
- } 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 INNER JOIN $table_prop p
- ON (p.ref = d.id AND d.c_id = p.c_id)
- WHERE
- d.c_id = $course_id AND
- p.c_id = $course_id AND
- tool = '".TOOL_DOCUMENT."' AND
- p.visibility != 2 AND
- path NOT LIKE '/images/gallery%' AND
- $avoid_paths
- $session_condition
- ORDER BY path";
- } else {
- $sql = "SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size
- FROM $table_doc d INNER JOIN $table_prop p
- ON (p.ref = d.id AND d.c_id = p.c_id)
- WHERE
- d.c_id = $course_id AND
- p.c_id = $course_id AND
- tool = '".TOOL_DOCUMENT."' AND
- $avoid_paths 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 INNER JOIN $table_prop p
- ON (p.ref = d.id AND d.c_id = p.c_id)
- WHERE
- d.c_id = $course_id AND
- p.c_id = $course_id AND
- tool = '".TOOL_DOCUMENT."' AND
- p.visibility != 2 AND
- path NOT LIKE '/images/gallery%' AND
- $avoid_paths AND
- d.session_id = 0
- ORDER BY path";
- } else {
- $sql = "SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size
- FROM $table_doc d INNER JOIN $table_prop p
- ON (p.ref = d.id AND d.c_id = p.c_id)
- WHERE
- d.c_id = $course_id AND
- p.c_id = $course_id AND
- tool = '".TOOL_DOCUMENT."' AND
- p.visibility != 2 AND
- $avoid_paths AND
- 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
- );
- $this->course->add_resource($doc);
- }
- }
- }
- /**
- * Build the forums
- */
- public 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 .= " 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);
- }
- }
- /**
- * Build a forum-category
- */
- public function build_forum_category($session_id = 0, $course_code = null, $with_base_content = false, $id_list = array())
- {
- $table = Database :: get_course_table(TABLE_FORUM_CATEGORY);
- $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);
- }
- }
- /**
- * Build the forum-topics
- */
- public 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
- ORDER BY thread_title ";
- $db_result = Database::query($sql);
- 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.
- */
- public 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();
- $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);
- $this->course->add_resource($forum_post);
- }
- }
- /**
- * Build the links
- */
- public 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'];
- $table = Database :: get_course_table(TABLE_LINK);
- $table_prop = Database :: get_course_table(TABLE_ITEM_PROPERTY);
- 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);
- } 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
- 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
- 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
- ORDER BY l.display_order";
- }
- $db_result = Database::query($sql);
- while ($obj = Database::fetch_object($db_result)) {
- $link = new Link($obj->id, $obj->title, $obj->url, $obj->description, $obj->category_id, $obj->on_homepage);
- $this->course->add_resource($link);
- if (!empty($course_code)) {
- $res = $this->build_link_category($obj->category_id,$course_code);
- } else {
- $res = $this->build_link_category($obj->category_id);
- }
- if($res > 0) {
- $this->course->resources[RESOURCE_LINK][$obj->id]->add_linked_resource(RESOURCE_LINKCATEGORY, $obj->category_id);
- }
- }
- }
- /**
- * Build tool intro
- */
- public 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();
- $sql = "SELECT * FROM $table WHERE c_id = $course_id ";
- $db_result = Database::query($sql);
- while ($obj = Database::fetch_object($db_result)) {
- $tool_intro = new ToolIntro($obj->id, $obj->intro_text);
- $this->course->add_resource($tool_intro);
- }
- }
- /**
- * Build a link category
- */
- public 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";
- $db_result = Database::query($sql);
- while ($obj = Database::fetch_object($db_result)) {
- $link_category = new LinkCategory($obj->id, $obj->category_title, $obj->description, $obj->display_order);
- $this->course->add_resource($link_category);
- return $id;
- }
- return 0;
- }
- /**
- * Build the Quizzes
- */
- public function build_quizzes($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
- {
- $course_info = api_get_course_info($course_code);
- $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)) {
- $session_id = intval($session_id);
- if ($with_base_content) {
- $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 {
- $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) {
- $sql = "SELECT id FROM $table_doc WHERE c_id = $course_id AND path = '/audio/".$obj->sound."'";
- $res = Database::query($sql);
- $doc = Database::fetch_object($res);
- $obj->sound = $doc->id;
- }
- $exercise_obj = new Exercise($course_id);
- $exercise_obj->read($obj->iid);
- $categories = $exercise_obj->get_categories_with_name_in_exercise();
- $obj->categories = $categories;
- $quiz = new Quiz($obj);
- $sql = 'SELECT * FROM '.$table_rel.' WHERE c_id = '.$course_id.' AND exercice_id = '.$obj->iid;
- $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);
- }
- if (!empty($course_code)) {
- $this->build_quiz_questions($course_code);
- } else {
- $this->build_quiz_questions();
- }
- }
- /**
- * Build the Quiz-Questions
- */
- public 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 ";
- $db_result = Database::query($sql);
- while ($obj = Database::fetch_object($db_result)) {
- $categories = Testcategory::getCategoryForQuestionWithCategoryData($obj->iid, $course_id, true);
- $parent_info = array();
- if (isset($obj->parent_id) && !empty($obj->parent_id)) {
- $parent_info = (array)Question::read($obj->parent_id, $course_id);
- }
- $question = new QuizQuestion($obj->iid, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture, $obj->level, $obj->extra, $parent_info, $categories);
- $sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.$obj->iid;
- $db_result2 = Database::query($sql);
- while ($obj2 = Database::fetch_object($db_result2)) {
- $question->add_answer($obj2->iid, $obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type);
- if ($obj->type == MULTIPLE_ANSWER_TRUE_FALSE) {
- $table_options = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
- $sql = 'SELECT * FROM '.$table_options.' WHERE c_id = '.$course_id.' AND question_id = '.$obj->iid;
- $db_result3 = Database::query($sql);
- while ($obj3 = Database::fetch_object($db_result3)) {
- $question_option = new QuizQuestionOption($obj3);
- $question->add_option($question_option);
- }
- }
- }
- $this->course->add_resource($question);
- }
- // 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).
- //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.iid = r.question_id)
- INNER JOIN $table_qui ex
- ON (ex.iid = 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.iid = 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.iid = 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)) {
- $categories = Testcategory::getCategoryForQuestionWithCategoryData($obj->iid, $course_id, true);
- $parent_info = array();
- if (isset($obj->parent_id) && !empty($obj->parent_id)) {
- $parent_info = (array)Question::read($obj->parent_id, $course_id);
- }
- //Avoid adding the same question twice
- if (!isset($this->course->resources[$obj->iid])) {
- $question = new QuizQuestion($obj->iid, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level, $obj->extra, $parent_info, $categories);
- $sql = "SELECT * FROM $table_ans WHERE c_id = $course_id AND question_id = ".$obj->iid;
- $db_result2 = Database::query($sql);
- if (Database::num_rows($db_result2)) {
- while ($obj2 = Database::fetch_object($db_result2)) {
- $question->add_answer($obj2->iid, $obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type);
- }
- $orphanQuestionIds[] = $obj->iid;
- }
- $this->course->add_resource($question);
- }
- }
- }
- if ($build_orphan_questions) {
- $obj = array(
- 'iid' => -1,
- 'title' => get_lang('OrphanQuestions', ''),
- 'type' => 2
- );
- $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
- */
- public function build_quiz_orphan_questions()
- {
- $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);
- $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
- exercices.active = -1)';
- $db_result = Database::query($sql);
- if (Database::num_rows($db_result) > 0) {
- // This is the fictional test for collecting orphan questions.
- $orphan_questions = new Quiz(-1, get_lang('OrphanQuestions', ''), '', 0, 0, 1, '', 0);
- $this->course->add_resource($orphan_questions);
- while ($obj = Database::fetch_object($db_result)) {
- $question = new QuizQuestion($obj->iid, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level,$obj->extra);
- $sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.$obj->iid;
- $db_result2 = Database::query($sql);
- while ($obj2 = Database::fetch_object($db_result2)) {
- $question->add_answer($obj2->iid, $obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type);
- }
- $this->course->add_resource($question);
- }
- }
- }
- /**
- * Build the test category
- * $session_id, $course_code, $with_base_content, $this->specific_id_list[$tool]
- * @todo add course session
- */
- public function build_test_category($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
- {
- $course_id = api_get_course_int_id();
- // get all test category in course
- $tab_test_categories_id = Testcategory::getCategoryListInfo("id", $course_id);
- foreach ($tab_test_categories_id as $test_category_id)
- {
- $test_category = new Testcategory($test_category_id);
- $copy_course_test_category = new CourseCopyTestcategory($test_category_id, $test_category->name, $test_category->description);
- $this->course->add_resource($copy_course_test_category);
- }
- }
- /**
- * Build the Surveys
- */
- public function build_surveys($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
- {
- $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)) {
- $survey = new Survey($obj->survey_id, $obj->code,$obj->title,
- $obj->subtitle, $obj->author, $obj->lang,
- $obj->avail_from, $obj->avail_till, $obj->is_shared,
- $obj->template, $obj->intro, $obj->surveythanks,
- $obj->creation_date, $obj->invited, $obj->answered,
- $obj->invite_mail, $obj->reminder_mail);
- $sql = 'SELECT * FROM '.$table_question.' WHERE c_id = '.$course_id.' AND survey_id = '.$obj->survey_id;
- $db_result2 = Database::query($sql);
- while ($obj2 = Database::fetch_object($db_result2)){
- $survey->add_question($obj2->question_id);
- }
- $this->course->add_resource($survey);
- }
- $this->build_survey_questions();
- }
- /**
- * Build the Survey Questions
- */
- public 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)){
- $question = new SurveyQuestion(
- $obj->question_id,
- $obj->survey_id,
- $obj->survey_question,
- $obj->survey_question_comment,
- $obj->type,
- $obj->display,
- $obj->sort,
- $obj->shared_question_id,
- $obj->max_value
- );
- $sql = 'SELECT * FROM '.$table_opt.' WHERE c_id = '.$course_id.' AND question_id = '.$obj->question_id;
- $db_result2 = Database::query($sql);
- while ($obj2 = Database::fetch_object($db_result2)) {
- $question->add_answer($obj2->option_text, $obj2->sort);
- }
- $this->course->add_resource($question);
- }
- }
- /**
- * Build the announcements
- */
- public 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)) {
- $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);
- $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;
- }
- $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);
- }
- }
- /**
- * Build the events
- */
- public 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);
- $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);
- $this->course->add_resource($event);
- }
- }
- /**
- * Build the course-descriptions
- */
- public 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)) {
- $session_id = intval($session_id);
- if ($with_base_content) {
- $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);
- $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)) {
- $cd = new CourseDescription($obj->id, $obj->title, $obj->content, $obj->description_type);
- $this->course->add_resource($cd);
- }
- }
- /**
- * Build the learnpaths
- */
- public 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);
- } else {
- $session_condition = api_get_session_condition($session_id, true);
- }
- $sql = 'SELECT * FROM '.$table_main.' WHERE c_id = '.$course_id.' '.$session_condition;
- } 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)) {
- $items = array();
- $sql_items = "SELECT * FROM ".$table_item." WHERE c_id = '$course_id' AND lp_id = ".$obj->id;
- $db_items = Database::query($sql_items);
- while ($obj_item = Database::fetch_object($db_items)) {
- $item['id'] = $obj_item->id;
- $item['item_type'] = $obj_item->item_type;
- $item['ref'] = $obj_item->ref;
- $item['title'] = $obj_item->title;
- $item['description'] = $obj_item->description;
- $item['path'] = $obj_item->path;
- $item['min_score'] = $obj_item->min_score;
- $item['max_score'] = $obj_item->max_score;
- $item['mastery_score'] = $obj_item->mastery_score;
- $item['parent_item_id'] = $obj_item->parent_item_id;
- $item['previous_item_id'] = $obj_item->previous_item_id;
- $item['next_item_id'] = $obj_item->next_item_id;
- $item['display_order'] = $obj_item->display_order;
- $item['prerequisite'] = $obj_item->prerequisite;
- $item['parameters'] = $obj_item->parameters;
- $item['launch_data'] = $obj_item->launch_data;
- $item['audio'] = $obj_item->audio;
- $items[] = $item;
- }
- $sql_tool = "SELECT id FROM $table_tool
- WHERE c_id = $course_id AND
- (link LIKE '%lp_controller.php%lp_id=".$obj->id."%' AND image='scormbuilder.gif') AND
- visibility = '1' ";
- $db_tool = Database::query($sql_tool);
- if (Database::num_rows($db_tool)) {
- $visibility = '1';
- } else {
- $visibility = '0';
- }
- $lp = new CourseCopyLearnpath(
- $obj->id,
- $obj->lp_type,
- $obj->name,
- $obj->path,
- $obj->ref,
- $obj->description,
- $obj->content_local,
- $obj->default_encoding,
- $obj->default_view_mod,
- $obj->prevent_reinit,
- $obj->force_commit,
- $obj->content_maker,
- $obj->display_order,
- $obj->js_lib,
- $obj->content_license,
- $obj->debug,
- $visibility,
- $obj->author,
- $obj->preview_image,
- $obj->use_max_score,
- $obj->autolunch,
- $obj->created_on,
- $obj->modified_on,
- $obj->publicated_on,
- $obj->expired_on,
- $obj->session_id,
- $obj->subscribe_users,
- $items);
- $this->course->add_resource($lp);
- }
- //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,array('.','..'))) {
- $doc = new ScormDocument($i++, '/'.$file, $file);
- $this->course->add_resource($doc);
- }
- }
- closedir($dir);
- }
- }
- /**
- * Build the glossarys
- */
- public 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)) {
- $session_id = intval($session_id);
- if ($with_base_content) {
- $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 ...
- if (!empty($this->course->type) && $this->course->type=='partial') {
- $sql = 'SELECT * FROM '.$table_glossary.' g WHERE g.c_id = '.$course_id.' '.$session_condition;
- } else {
- $sql = 'SELECT * FROM '.$table_glossary.' g WHERE g.c_id = '.$course_id.' '.$session_condition;
- }
- } else {
- $table_glossary = Database :: get_course_table(TABLE_GLOSSARY);
- //@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 {
- $sql = 'SELECT * FROM '.$table_glossary.' g WHERE g.c_id = '.$course_id.' AND session_id = 0';
- }
- }
- $db_result = Database::query($sql);
- while ($obj = Database::fetch_object($db_result)) {
- $doc = new Glossary($obj->glossary_id, $obj->name, $obj->description, $obj->display_order);
- $this->course->add_resource($doc);
- }
- }
- /*
- * build session course by jhon
- * */
- public function build_session_course()
- {
- $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
- $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
- $list_course = CourseManager::get_course_list();
- $list = array();
- foreach($list_course as $_course) {
- $this->course = new Course();
- $this->course->code = $_course['code'];
- $this->course->type = 'partial';
- $this->course->path = api_get_path(SYS_COURSE_PATH).$_course['directory'].'/';
- $this->course->backup_path = api_get_path(SYS_COURSE_PATH).$_course['directory'];
- $this->course->encoding = api_get_system_encoding(); //current platform encoding
- //$code_course = $_course['code'];
- $courseId = $_course['real_id'];
- $sql_session = "SELECT id, name, c_id
- FROM $tbl_session_course INNER JOIN $tbl_session ON id_session = id
- WHERE c_id = '$courseId' ";
- $query_session = Database::query($sql_session);
- while ($rows_session = Database::fetch_assoc($query_session)) {
- $session = new CourseSession($rows_session['id'], $rows_session['name']);
- $this->course->add_resource($session);
- }
- $list[] = $this->course;
- }
- return $list;
- }
- /**
- * @param int $session_id
- * @param string $course_code
- * @param bool $with_base_content
- * @param array $id_list
- */
- public 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)) {
- $session_id = intval($session_id);
- if ($with_base_content) {
- $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);
- $sql = 'SELECT * FROM ' . $tbl_wiki . ' WHERE c_id = '.$course_id.' AND session_id = 0';
- }
- $db_result = Database::query($sql);
- while ($obj = Database::fetch_object($db_result)) {
- $wiki = new Wiki($obj->id, $obj->page_id, $obj->reflink, $obj->title, $obj->content, $obj->user_id, $obj->group_id, $obj->dtime, $obj->progress, $obj->version);
- $this->course->add_resource($wiki);
- }
- }
- /**
- * Build the Surveys
- */
- public function build_thematic($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
- {
- $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);
- } else {
- $session_condition = api_get_session_condition($session_id, true);
- }
- $course_id = api_get_course_int_id();
- $courseInfo = api_get_course_info();
- $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($courseInfo);
- $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')) {
- $thematic->add_thematic_advance($sub_row);
- }
- $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) {
- $thematic_plan_id_list[] = $item['ref'];
- //$thematic_plan_complete_list[$item['ref']] = $item;
- }
- }
- if (count($thematic_plan_id_list) > 0) {
- $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
- 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);
- }
- }
- /**
- * Build the attendances
- */
- public 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();
- $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);
- }
- }
- /**
- * Build the works (or "student publications", or "assignments")
- */
- public function build_works($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
- {
- $table_work = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
- //$table_work_assignment = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
- $course_id = api_get_course_int_id();
- $sql = 'SELECT * FROM '.$table_work.'
- WHERE
- c_id = '.$course_id.' AND
- session_id = 0 AND
- filetype = \'folder\' AND
- parent_id = 0 AND
- active = 1';
- $db_result = Database::query($sql);
- while ($row = Database::fetch_array($db_result,'ASSOC')) {
- $obj = new Work($row);
- $this->course->add_resource($obj);
- }
- }
- }
|