CourseBuilder.class.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. <?php
  2. /* For licensing terms, see /dokeos_license.txt */
  3. require_once 'Course.class.php';
  4. require_once 'Event.class.php';
  5. require_once 'Link.class.php';
  6. require_once 'ToolIntro.class.php';
  7. require_once 'Document.class.php';
  8. require_once 'ScormDocument.class.php';
  9. require_once 'LinkCategory.class.php';
  10. require_once 'CourseDescription.class.php';
  11. require_once 'ForumPost.class.php';
  12. require_once 'ForumTopic.class.php';
  13. require_once 'Forum.class.php';
  14. require_once 'ForumCategory.class.php';
  15. require_once 'Quiz.class.php';
  16. require_once 'QuizQuestion.class.php';
  17. require_once 'Learnpath.class.php';
  18. require_once 'Survey.class.php';
  19. require_once 'SurveyQuestion.class.php';
  20. require_once 'Glossary.class.php';
  21. require_once 'CourseSession.class.php';
  22. require_once 'wiki.class.php';
  23. /**
  24. * Class which can build a course-object from a Dokeos-course.
  25. * @author Bart Mollet <bart.mollet@hogent.be>
  26. * @package dokeos.backup
  27. */
  28. class CourseBuilder
  29. {
  30. /**
  31. * The course
  32. */
  33. var $course;
  34. /**
  35. * Create a new CourseBuilder
  36. */
  37. function CourseBuilder($type='')
  38. {
  39. global $_course;
  40. $this->course = new Course();
  41. $this->course->code = $_course['official_code'];
  42. $this->course->type = $type;
  43. $this->course->path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/';
  44. $this->course->backup_path = api_get_path(SYS_COURSE_PATH).$_course['path'];
  45. $this->course->encoding = api_get_system_encoding(); //current platform encoding
  46. }
  47. /**
  48. * Get the created course
  49. * @return course The course
  50. */
  51. function get_course()
  52. {
  53. return $this->course;
  54. }
  55. /**
  56. * Build the course-object
  57. */
  58. function build($session_id = 0,$course_code = '')
  59. {
  60. if (!empty($session_id) && !empty($course_code)) {
  61. $course_info = api_get_course_info($course_code);
  62. $table_link = Database :: get_course_table(TABLE_LINKED_RESOURCES,$course_info['dbName']);
  63. $table_properties = Database :: get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']);
  64. $this->build_documents($session_id,$course_code);
  65. $this->build_quizzes($session_id,$course_code);
  66. $this->build_glossary($session_id,$course_code);
  67. $this->build_learnpaths($session_id,$course_code);
  68. $this->build_links($session_id,$course_code);
  69. $this->build_course_descriptions($session_id,$course_code);
  70. $this->build_wiki($session_id,$course_code);
  71. } else {
  72. $table_link = Database :: get_course_table(TABLE_LINKED_RESOURCES);
  73. $table_properties = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  74. $this->build_events();
  75. $this->build_announcements();
  76. $this->build_links();
  77. $this->build_tool_intro();
  78. $this->build_documents();
  79. $this->build_course_descriptions();
  80. $this->build_wiki();
  81. $this->build_quizzes();
  82. $this->build_learnpaths();
  83. $this->build_surveys();
  84. $this->build_glossary();
  85. }
  86. //TABLE_LINKED_RESOURCES is the "resource" course table, which is deprecated, apparently
  87. foreach ($this->course->resources as $type => $resources) {
  88. foreach ($resources as $id => $resource) {
  89. $sql = "SELECT * FROM ".$table_link." WHERE source_type = '".$resource->get_type()."' AND source_id = '".$resource->get_id()."'";
  90. $res = Database::query($sql, __FILE__, __LINE__);
  91. while ($link = Database::fetch_object($res)) {
  92. $this->course->resources[$type][$id]->add_linked_resource($link->resource_type, $link->resource_id);
  93. }
  94. }
  95. }
  96. foreach ($this->course->resources as $type => $resources)
  97. {
  98. foreach ($resources as $id => $resource)
  99. {
  100. $tool = $resource->get_tool();
  101. if ($tool != null)
  102. {
  103. $sql = "SELECT * FROM $table_properties WHERE TOOL = '".$tool."' AND ref='".$resource->get_id()."'";
  104. $res = Database::query($sql,__FILE__,__LINE__);
  105. $all_properties = array ();
  106. while ($item_property = Database::fetch_array($res))
  107. {
  108. $all_properties[] = $item_property;
  109. }
  110. $this->course->resources[$type][$id]->item_properties = $all_properties;
  111. }
  112. }
  113. }
  114. return $this->course;
  115. }
  116. /**
  117. * Build the documents
  118. */
  119. function build_documents($session_id = 0,$course_code = '')
  120. {
  121. if (!empty($course_code) && !empty($session_id)) {
  122. $course_info = api_get_course_info($course_code);
  123. $table_doc = Database :: get_course_table(TABLE_DOCUMENT,$course_info['dbName']);
  124. $table_prop = Database :: get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']);
  125. $session_id = intval($session_id);
  126. if (!empty($this->course->type) && $this->course->type=='partial') {
  127. $sql = 'SELECT * FROM '.$table_doc.' d, '.$table_prop.' p WHERE tool = \''.TOOL_DOCUMENT.'\' AND p.ref = d.id AND p.visibility != 2 AND path NOT LIKE \'/images/gallery%\' AND session_id = '.$session_id.' ORDER BY path';
  128. } else {
  129. $sql = 'SELECT * FROM '.$table_doc.' d, '.$table_prop.' p WHERE tool = \''.TOOL_DOCUMENT.'\' AND p.ref = d.id AND p.visibility != 2 AND session_id = '.$session_id.' ORDER BY path';
  130. }
  131. $db_result = Database::query($sql, __FILE__, __LINE__);
  132. while ($obj = Database::fetch_object($db_result))
  133. {
  134. $doc = new Document($obj->id, $obj->path, $obj->comment, $obj->title, $obj->filetype, $obj->size);
  135. $this->course->add_resource($doc);
  136. }
  137. } else {
  138. $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
  139. $table_prop = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  140. if (!empty($this->course->type) && $this->course->type=='partial')
  141. $sql = 'SELECT * FROM '.$table_doc.' d, '.$table_prop.' p WHERE tool = \''.TOOL_DOCUMENT.'\' AND p.ref = d.id AND p.visibility != 2 AND path NOT LIKE \'/images/gallery%\' AND d.session_id = 0 ORDER BY path';
  142. else
  143. $sql = 'SELECT * FROM '.$table_doc.' d, '.$table_prop.' p WHERE tool = \''.TOOL_DOCUMENT.'\' AND p.ref = d.id AND p.visibility != 2 AND d.session_id = 0 ORDER BY path';
  144. $db_result = Database::query($sql, __FILE__, __LINE__);
  145. while ($obj = Database::fetch_object($db_result))
  146. {
  147. $doc = new Document($obj->id, $obj->path, $obj->comment, $obj->title, $obj->filetype, $obj->size);
  148. $this->course->add_resource($doc);
  149. }
  150. }
  151. }
  152. /**
  153. * Build the forums
  154. */
  155. function build_forums()
  156. {
  157. $table = Database :: get_course_table(TABLE_FORUM);
  158. $sql = 'SELECT * FROM '.$table;
  159. $db_result = Database::query($sql, __FILE__, __LINE__);
  160. while ($obj = Database::fetch_object($db_result))
  161. {
  162. $forum = new Forum($obj->forum_id, $obj->forum_title, $obj->forum_comment, $obj->forum_category, $obj->forum_last_post, $obj->forum_threads, $obj->forum_posts, $obj->allow_anonymous, $obj->allow_edit, $obj->approval_direct_post, $obj->allow_attachements, $obj->allow_new_threads, $obj->default_view, $obj->forum_of_group, $obj->forum_group_public_private, $obj->forum_order, $obj->locked, $obj->session_id, $obj->forum_image);
  163. $this->course->add_resource($forum);
  164. $this->build_forum_category($obj->forum_category);
  165. }
  166. $this->build_forum_topics();
  167. $this->build_forum_posts();
  168. }
  169. /**
  170. * Build a forum-category
  171. */
  172. function build_forum_category($id)
  173. {
  174. $table = Database :: get_course_table(TABLE_FORUM_CATEGORY);
  175. $sql = 'SELECT * FROM '.$table.' WHERE cat_id = '.$id;
  176. $db_result = Database::query($sql, __FILE__, __LINE__);
  177. while ($obj = Database::fetch_object($db_result))
  178. {
  179. $forum_category = new ForumCategory($obj->cat_id, $obj->cat_title, $obj->cat_comment, $obj->cat_order, $obj->locked, $obj->session_id);
  180. $this->course->add_resource($forum_category);
  181. }
  182. }
  183. /**
  184. * Build the forum-topics
  185. */
  186. function build_forum_topics()
  187. {
  188. $table = Database :: get_course_table(TABLE_FORUM_THREAD);
  189. $sql = 'SELECT * FROM '.$table;
  190. $db_result = Database::query($sql, __FILE__, __LINE__);
  191. while ($obj = Database::fetch_object($db_result))
  192. {
  193. $forum_topic = new ForumTopic($obj->thread_id, $obj->thread_title, $obj->thread_date, $obj->thread_poster_id, $obj->thread_poster_name, $obj->forum_id, $obj->thread_last_post, $obj->thread_replies, $obj->thread_views, $obj->thread_sticky, $obj->locked, $obj->thread_close_date, $obj->thread_weight, $obj->thread_title_qualify, $obj->thread_qualify_max);
  194. $this->course->add_resource($forum_topic);
  195. }
  196. }
  197. /**
  198. * Build the forum-posts
  199. * TODO: All tree structure of posts should be built, attachments for example.
  200. */
  201. function build_forum_posts()
  202. {
  203. $table_post = Database :: get_course_table(TABLE_FORUM_POST);
  204. $sql = 'SELECT * FROM '.$table_post;
  205. $db_result = Database::query($sql, __FILE__, __LINE__);
  206. while ($obj = Database::fetch_object($db_result))
  207. {
  208. $forum_post = new ForumPost($obj->post_id, $obj->post_title, $obj->post_text, $obj->post_date, $obj->poster_id, $obj->poster_name, $obj->post_notification, $obj->post_parent_id, $obj->thread_id, $obj->forum_id, $obj->visible);
  209. $this->course->add_resource($forum_post);
  210. }
  211. }
  212. /**
  213. * Build the links
  214. */
  215. function build_links($session_id = 0,$course_code = '')
  216. {
  217. if (!empty($session_id) && !empty($course_code)) {
  218. $course_info = api_get_course_info($course_code);
  219. $table = Database :: get_course_table(TABLE_LINK,$course_info['dbName']);
  220. $table_prop = Database :: get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']);
  221. $session_id = intval($session_id);
  222. $sql = "SELECT * FROM $table l, $table_prop p WHERE p.ref=l.id AND p.tool = '".TOOL_LINK."' AND p.visibility != 2 AND session_id = '$session_id' ORDER BY l.display_order";
  223. } else {
  224. $table = Database :: get_course_table(TABLE_LINK);
  225. $table_prop = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  226. $sql = "SELECT * FROM $table l, $table_prop p WHERE p.ref=l.id AND p.tool = '".TOOL_LINK."' AND p.visibility != 2 AND l.session_id = 0 ORDER BY l.display_order";
  227. }
  228. $db_result = Database::query($sql, __FILE__, __LINE__);
  229. while ($obj = Database::fetch_object($db_result))
  230. {
  231. $link = new Link($obj->id, $obj->title, $obj->url, $obj->description, $obj->category_id, $obj->on_homepage);
  232. $this->course->add_resource($link);
  233. if (!empty($course_code)) {
  234. $res = $this->build_link_category($obj->category_id,$course_code);
  235. } else {
  236. $res = $this->build_link_category($obj->category_id);
  237. }
  238. if($res > 0)
  239. {
  240. $this->course->resources[RESOURCE_LINK][$obj->id]->add_linked_resource(RESOURCE_LINKCATEGORY, $obj->category_id);
  241. }
  242. }
  243. }
  244. /**
  245. * Build tool intro
  246. */
  247. function build_tool_intro()
  248. {
  249. $table = Database :: get_course_table(TABLE_TOOL_INTRO);
  250. $sql = 'SELECT * FROM '.$table;
  251. $db_result = Database::query($sql, __FILE__, __LINE__);
  252. while ($obj = Database::fetch_object($db_result))
  253. {
  254. $tool_intro = new ToolIntro($obj->id, $obj->intro_text);
  255. $this->course->add_resource($tool_intro);
  256. }
  257. }
  258. /**
  259. * Build a link category
  260. */
  261. function build_link_category($id, $course_code = '')
  262. {
  263. if (!empty($course_code)) {
  264. $course_info = api_get_course_info($course_code);
  265. $link_cat_table = Database :: get_course_table(TABLE_LINK_CATEGORY, $course_info['dbName']);
  266. } else {
  267. $link_cat_table = Database :: get_course_table(TABLE_LINK_CATEGORY);
  268. }
  269. $sql = 'SELECT * FROM '.$link_cat_table.' WHERE id = '.$id;
  270. $db_result = Database::query($sql, __FILE__, __LINE__);
  271. while ($obj = Database::fetch_object($db_result))
  272. {
  273. $link_category = new LinkCategory($obj->id, $obj->category_title, $obj->description, $obj->display_order);
  274. $this->course->add_resource($link_category);
  275. return $id;
  276. }
  277. return 0;
  278. }
  279. /**
  280. * Build the Quizzes
  281. */
  282. function build_quizzes($session_id = 0,$course_code = '')
  283. {
  284. if (!empty($course_code) && !empty($session_id)) {
  285. $course_info = api_get_course_info($course_code);
  286. $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST, $course_info['dbName']);
  287. $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION, $course_info['dbName']);
  288. $table_doc = Database :: get_course_table(TABLE_DOCUMENT, $course_info['dbName']);
  289. $session_id = intval($session_id);
  290. $sql = 'SELECT * FROM '.$table_qui.' WHERE active >=0 AND session_id = '.$session_id; //select only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes)
  291. } else {
  292. $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
  293. $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
  294. $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
  295. $sql = 'SELECT * FROM '.$table_qui.' WHERE active >=0 AND session_id = 0'; //select only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes)
  296. }
  297. $db_result = Database::query($sql, __FILE__, __LINE__);
  298. while ($obj = Database::fetch_object($db_result))
  299. {
  300. if (strlen($obj->sound) > 0)
  301. {
  302. $doc = Database::fetch_object(Database::query("SELECT id FROM ".$table_doc." WHERE path = '/audio/".$obj->sound."'"));
  303. $obj->sound = $doc->id;
  304. }
  305. $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);
  306. $sql = 'SELECT * FROM '.$table_rel.' WHERE exercice_id = '.$obj->id;
  307. $db_result2 = Database::query($sql, __FILE__, __LINE__);
  308. while ($obj2 = Database::fetch_object($db_result2))
  309. {
  310. $quiz->add_question($obj2->question_id, $obj2->question_order);
  311. }
  312. $this->course->add_resource($quiz);
  313. }
  314. if (!empty($course_code)) {
  315. $this->build_quiz_questions($course_code);
  316. } else {
  317. $this->build_quiz_questions();
  318. }
  319. }
  320. /**
  321. * Build the Quiz-Questions
  322. */
  323. function build_quiz_questions($course_code = '')
  324. {
  325. if (!empty($course_code)) {
  326. $course_info = api_get_course_info($course_code);
  327. $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST,$course_info['dbName']);
  328. $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION,$course_info['dbName']);
  329. $table_que = Database :: get_course_table(TABLE_QUIZ_QUESTION,$course_info['dbName']);
  330. $table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER,$course_info['dbName']);
  331. } else {
  332. $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
  333. $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
  334. $table_que = Database :: get_course_table(TABLE_QUIZ_QUESTION);
  335. $table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
  336. }
  337. // Building normal tests.
  338. $sql = 'SELECT * FROM '.$table_que;
  339. $db_result = Database::query($sql, __FILE__, __LINE__);
  340. while ($obj = Database::fetch_object($db_result))
  341. {
  342. $question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level);
  343. $sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.$obj->id;
  344. $db_result2 = Database::query($sql, __FILE__, __LINE__);
  345. while ($obj2 = Database::fetch_object($db_result2))
  346. {
  347. $question->add_answer($obj2->id, $obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type);
  348. }
  349. $this->course->add_resource($question);
  350. }
  351. // Building a fictional test for collecting orphan questions.
  352. $build_orphan_questions = !empty($_POST['recycle_option']); // When a course is emptied this option should be activated (true).
  353. $sql = 'SELECT * FROM '.$table_que.
  354. ' as questions LEFT JOIN '.$table_rel.' as quizz_questions ON questions.id=quizz_questions.question_id LEFT JOIN '.$table_qui.
  355. ' as exercices ON exercice_id=exercices.id WHERE quizz_questions.exercice_id IS NULL OR exercices.active = -1'; // active = -1 means "deleted" test.
  356. $db_result = Database::query($sql, __FILE__, __LINE__);
  357. if (Database::num_rows($db_result) > 0)
  358. {
  359. $build_orphan_questions = true;
  360. while ($obj = Database::fetch_object($db_result))
  361. {
  362. $question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level);
  363. $sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.(int)$obj->id;
  364. $db_result2 = Database::query($sql, __FILE__, __LINE__);
  365. while ($obj2 = Database::fetch_object($db_result2))
  366. {
  367. $question->add_answer($obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type);
  368. }
  369. $this->course->add_resource($question);
  370. }
  371. }
  372. if ($build_orphan_questions)
  373. {
  374. //$this->course->add_resource(new Quiz(-1, get_lang('OrphanQuestions', ''), '', 0, 0, 1, '', 0));
  375. }
  376. }
  377. /**
  378. * Build the orphan questions
  379. */
  380. function build_quiz_orphan_questions()
  381. {
  382. $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
  383. $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
  384. $table_que = Database :: get_course_table(TABLE_QUIZ_QUESTION);
  385. $table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
  386. $sql = 'SELECT * FROM '.$table_que.
  387. ' as questions LEFT JOIN '.$table_rel.' as quizz_questions ON questions.id=quizz_questions.question_id LEFT JOIN '.$table_qui.
  388. ' as exercices ON exercice_id=exercices.id WHERE quizz_questions.exercice_id IS NULL OR exercices.active = -1';
  389. $db_result = Database::query($sql, __FILE__, __LINE__);
  390. if (Database::num_rows($db_result) > 0)
  391. {
  392. $orphan_questions = new Quiz(-1, get_lang('OrphanQuestions', ''), '', 0, 0, 1, '', 0); // Tjis is the fictional test for collecting orphan questions.
  393. $this->course->add_resource($orphan_questions);
  394. while ($obj = Database::fetch_object($db_result))
  395. {
  396. $question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level);
  397. $sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.$obj->id;
  398. $db_result2 = Database::query($sql, __FILE__, __LINE__);
  399. while ($obj2 = Database::fetch_object($db_result2))
  400. {
  401. $question->add_answer($obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type);
  402. }
  403. $this->course->add_resource($question);
  404. }
  405. }
  406. }
  407. /**
  408. * Build the Surveys
  409. */
  410. function build_surveys()
  411. {
  412. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  413. $table_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  414. $sql = 'SELECT * FROM '.$table_survey.' WHERE session_id = 0 ';
  415. $db_result = Database::query($sql, __FILE__, __LINE__);
  416. while ($obj = Database::fetch_object($db_result))
  417. {
  418. $survey = new Survey($obj->survey_id, $obj->code,$obj->title,
  419. $obj->subtitle, $obj->author, $obj->lang,
  420. $obj->avail_from, $obj->avail_till, $obj->is_shared,
  421. $obj->template, $obj->intro, $obj->surveythanks,
  422. $obj->creation_date, $obj->invited, $obj->answered,
  423. $obj->invite_mail, $obj->reminder_mail);
  424. $sql = 'SELECT * FROM '.$table_question.' WHERE survey_id = '.$obj->survey_id;
  425. $db_result2 = Database::query($sql, __FILE__, __LINE__);
  426. while ($obj2 = Database::fetch_object($db_result2))
  427. {
  428. $survey->add_question($obj2->question_id);
  429. }
  430. $this->course->add_resource($survey);
  431. }
  432. $this->build_survey_questions();
  433. }
  434. /**
  435. * Build the Survey Questions
  436. */
  437. function build_survey_questions()
  438. {
  439. $table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  440. $table_opt = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
  441. $sql = 'SELECT * FROM '.$table_que;
  442. $db_result = Database::query($sql, __FILE__, __LINE__);
  443. while ($obj = Database::fetch_object($db_result))
  444. {
  445. $question = new SurveyQuestion($obj->question_id, $obj->survey_id,
  446. $obj->survey_question, $obj->survey_question_comment,
  447. $obj->type, $obj->display, $obj->sort,
  448. $obj->shared_question_id, $obj->max_value);
  449. $sql = 'SELECT * FROM '.$table_opt.' WHERE question_id = '."'".$obj->question_id."'";
  450. $db_result2 = Database::query($sql, __FILE__, __LINE__);
  451. while ($obj2 = Database::fetch_object($db_result2))
  452. {
  453. $question->add_answer($obj2->option_text, $obj2->sort);
  454. }
  455. $this->course->add_resource($question);
  456. }
  457. }
  458. /**
  459. * Build the announcements
  460. */
  461. function build_announcements()
  462. {
  463. $table = Database :: get_course_table(TABLE_ANNOUNCEMENT);
  464. $sql = 'SELECT * FROM '.$table.' WHERE session_id = 0';
  465. $db_result = Database::query($sql, __FILE__, __LINE__);
  466. while ($obj = Database::fetch_object($db_result))
  467. {
  468. $announcement = new Announcement($obj->id, $obj->title, $obj->content, $obj->end_date,$obj->display_order,$obj->email_sent);
  469. $this->course->add_resource($announcement);
  470. }
  471. }
  472. /**
  473. * Build the events
  474. */
  475. function build_events()
  476. {
  477. $table = Database :: get_course_table(TABLE_AGENDA);
  478. $sql = 'SELECT * FROM '.$table.' WHERE session_id = 0';
  479. $db_result = Database::query($sql, __FILE__, __LINE__);
  480. while ($obj = Database::fetch_object($db_result))
  481. {
  482. $event = new Event($obj->id, $obj->title, $obj->content, $obj->start_date, $obj->end_date);
  483. $this->course->add_resource($event);
  484. }
  485. }
  486. /**
  487. * Build the course-descriptions
  488. */
  489. function build_course_descriptions($session_id = 0,$course_code = '')
  490. {
  491. if (!empty($session_id) && !empty($course_code)) {
  492. $course_info = api_get_course_info($course_code);
  493. $table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION,$course_info['dbName']);
  494. $session_id = intval($session_id);
  495. $sql = 'SELECT * FROM '.$table. ' WHERE session_id ='.$session_id;
  496. } else {
  497. $table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION);
  498. $sql = 'SELECT * FROM '.$table. ' WHERE session_id = 0';
  499. }
  500. $db_result = Database::query($sql, __FILE__, __LINE__);
  501. while ($obj = Database::fetch_object($db_result))
  502. {
  503. $cd = new CourseDescription($obj->id, $obj->title, $obj->content, $obj->description_type);
  504. $this->course->add_resource($cd);
  505. }
  506. }
  507. /**
  508. * Build the learnpaths
  509. */
  510. function build_learnpaths($session_id = 0,$course_code = '')
  511. {
  512. if (!empty($session_id) && !empty($course_code)) {
  513. $course_info = api_get_course_info($course_code);
  514. $table_main = Database :: get_course_table(TABLE_LP_MAIN,$course_info['dbName']);
  515. $table_item = Database :: get_course_table(TABLE_LP_ITEM,$course_info['dbName']);
  516. $table_tool = Database::get_course_table(TABLE_TOOL_LIST,$course_info['dbName']);
  517. $sql = 'SELECT * FROM '.$table_main.' WHERE session_id = '.$session_id;
  518. } else {
  519. $table_main = Database :: get_course_table(TABLE_LP_MAIN);
  520. $table_item = Database :: get_course_table(TABLE_LP_ITEM);
  521. $table_tool = Database::get_course_table(TABLE_TOOL_LIST);
  522. $sql = 'SELECT * FROM '.$table_main.' WHERE session_id = 0';
  523. }
  524. $db_result = Database::query($sql, __FILE__, __LINE__);
  525. while ($obj = Database::fetch_object($db_result))
  526. {
  527. $items = array();
  528. $sql_items = "SELECT * FROM ".$table_item." WHERE lp_id = ".$obj->id."";
  529. $db_items = Database::query($sql_items);
  530. while ($obj_item = Database::fetch_object($db_items))
  531. {
  532. $item['id'] = $obj_item->id;
  533. $item['item_type'] = $obj_item->item_type;
  534. $item['ref'] = $obj_item->ref;
  535. $item['title'] = $obj_item->title;
  536. $item['description'] = $obj_item->description;
  537. $item['path'] = $obj_item->path;
  538. $item['min_score'] = $obj_item->min_score;
  539. $item['max_score'] = $obj_item->max_score;
  540. $item['mastery_score'] = $obj_item->mastery_score;
  541. $item['parent_item_id'] = $obj_item->parent_item_id;
  542. $item['previous_item_id'] = $obj_item->previous_item_id;
  543. $item['next_item_id'] = $obj_item->next_item_id;
  544. $item['display_order'] = $obj_item->display_order;
  545. $item['prerequisite'] = $obj_item->prerequisite;
  546. $item['parameters'] = $obj_item->parameters;
  547. $item['launch_data'] = $obj_item->launch_data;
  548. $items[] = $item;
  549. }
  550. $sql_tool = "SELECT id FROM ".$table_tool." WHERE (link LIKE '%lp_controller.php%lp_id=".$obj->id."%' and image='scormbuilder.gif') AND visibility='1'";
  551. $db_tool = Database::query($sql_tool);
  552. if(Database::num_rows($db_tool))
  553. {
  554. $visibility='1';
  555. }
  556. else
  557. {
  558. $visibility='0';
  559. }
  560. $lp = new Learnpath($obj->id,
  561. $obj->lp_type,
  562. $obj->name,
  563. $obj->path,
  564. $obj->ref,
  565. $obj->description,
  566. $obj->content_local,
  567. $obj->default_encoding,
  568. $obj->default_view_mod,
  569. $obj->prevent_reinit,
  570. $obj->force_commit,
  571. $obj->content_maker,
  572. $obj->display_order,
  573. $obj->js_lib,
  574. $obj->content_license,
  575. $obj->debug,
  576. $visibility,
  577. $items);
  578. $this->course->add_resource($lp);
  579. }
  580. //save scorm directory (previously build_scorm_documents())
  581. $i = 1;
  582. if($dir=@opendir($this->course->backup_path.'/scorm'))
  583. {
  584. while($file=readdir($dir))
  585. {
  586. if(is_dir($this->course->backup_path.'/scorm/'.$file) && !in_array($file,array('.','..')))
  587. {
  588. $doc = new ScormDocument($i++, '/'.$file, $file);
  589. $this->course->add_resource($doc);
  590. }
  591. }
  592. closedir($dir);
  593. }
  594. }
  595. /**
  596. * Build the glossarys
  597. */
  598. function build_glossary($session_id = 0, $course_code = '') {
  599. if (!empty($session_id) && !empty($course_code)) {
  600. $course_info = api_get_course_info($course_code);
  601. $table_glossary = Database :: get_course_table(TABLE_GLOSSARY,$course_info['dbName']);
  602. $session_id = intval($session_id);
  603. if (!empty($this->course->type) && $this->course->type=='partial') {
  604. $sql = 'SELECT * FROM '.$table_glossary.' g WHERE session_id = '.$session_id;
  605. } else {
  606. $sql = 'SELECT * FROM '.$table_glossary.' g WHERE session_id = '.$session_id;
  607. }
  608. } else {
  609. $table_glossary = Database :: get_course_table(TABLE_GLOSSARY);
  610. if (!empty($this->course->type) && $this->course->type=='partial') {
  611. $sql = 'SELECT * FROM '.$table_glossary.' g WHERE session_id = 0';
  612. } else {
  613. $sql = 'SELECT * FROM '.$table_glossary.' g WHERE session_id = 0';
  614. }
  615. }
  616. $db_result = Database::query($sql, __FILE__, __LINE__);
  617. while ($obj = Database::fetch_object($db_result))
  618. {
  619. $doc = new Glossary($obj->glossary_id, $obj->name, $obj->description, $obj->display_order);
  620. $this->course->add_resource($doc);
  621. }
  622. }
  623. /*
  624. * build session course by jhon
  625. * */
  626. function build_session_course(){
  627. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  628. $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  629. $list_course = Database::get_course_list();
  630. $list = array();
  631. foreach($list_course as $_course) {
  632. $this->course = new Course();
  633. $this->course->code = $_course['code'];
  634. $this->course->type = 'partial';
  635. $this->course->path = api_get_path(SYS_COURSE_PATH).$_course['directory'].'/';
  636. $this->course->backup_path = api_get_path(SYS_COURSE_PATH).$_course['directory'];
  637. $this->course->encoding = api_get_system_encoding(); //current platform encoding
  638. $code_course = $_course['code'];
  639. $sql_session = "SELECT id, name, course_code FROM $tbl_session_course
  640. INNER JOIN $tbl_session ON id_session = id
  641. WHERE course_code = '$code_course' ";
  642. $query_session = Database::query($sql_session, __FILE__, __LINE__);
  643. while($rows_session = mysql_fetch_assoc($query_session)) {
  644. $session = new CourseSession($rows_session['id'], $rows_session['name']);
  645. $this->course->add_resource($session);
  646. }
  647. $list[] = $this->course;
  648. }
  649. return $list;
  650. }
  651. function build_wiki($session_id = 0, $course_code = 0)
  652. {
  653. if (!empty($session_id) && !empty($course_code)) {
  654. $course_info = api_get_course_info($course_code);
  655. $tbl_wiki = Database::get_course_table(TABLE_WIKI,$course_info['dbName']);
  656. $session_id = intval($session_id);
  657. $sql = 'SELECT * FROM ' . $tbl_wiki . ' WHERE session_id='.$session_id.'';
  658. } else {
  659. $tbl_wiki = Database::get_course_table(TABLE_WIKI);
  660. $sql = 'SELECT * FROM ' . $tbl_wiki . ' WHERE session_id = 0';
  661. }
  662. $db_result = api_sql_query($sql, __FILE__, __LINE__);
  663. while ($obj = mysql_fetch_object($db_result))
  664. {
  665. $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);
  666. $this->course->add_resource($wiki);
  667. }
  668. }
  669. }