CourseBuilder.class.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. <?php // $Id: CourseBuilder.class.php 19948 2009-04-21 17:27:59Z juliomontoya $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) Bart Mollet (bart.mollet@hogent.be)
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  17. Mail: info@dokeos.com
  18. ==============================================================================
  19. */
  20. require_once ('Course.class.php');
  21. require_once ('Event.class.php');
  22. require_once ('Link.class.php');
  23. require_once ('ToolIntro.class.php');
  24. require_once ('Document.class.php');
  25. require_once ('ScormDocument.class.php');
  26. require_once ('LinkCategory.class.php');
  27. require_once ('CourseDescription.class.php');
  28. require_once ('ForumPost.class.php');
  29. require_once ('ForumTopic.class.php');
  30. require_once ('Forum.class.php');
  31. require_once ('ForumCategory.class.php');
  32. require_once ('Quiz.class.php');
  33. require_once ('QuizQuestion.class.php');
  34. require_once ('Learnpath.class.php');
  35. require_once ('Survey.class.php');
  36. require_once ('SurveyQuestion.class.php');
  37. /**
  38. * Class which can build a course-object from a Dokeos-course.
  39. * @author Bart Mollet <bart.mollet@hogent.be>
  40. * @package dokeos.backup
  41. */
  42. class CourseBuilder
  43. {
  44. /**
  45. * The course
  46. */
  47. var $course;
  48. /**
  49. * Create a new CourseBuilder
  50. */
  51. function CourseBuilder($type='')
  52. {
  53. global $_course;
  54. $this->course = new Course();
  55. $this->course->code = $_course['official_code'];
  56. $this->course->type = $type;
  57. $this->course->path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/';
  58. $this->course->backup_path = api_get_path(SYS_COURSE_PATH).$_course['path'];
  59. }
  60. /**
  61. * Get the created course
  62. * @return course The course
  63. */
  64. function get_course()
  65. {
  66. return $this->course;
  67. }
  68. /**
  69. * Build the course-object
  70. */
  71. function build()
  72. {
  73. $this->build_events();
  74. $this->build_announcements();
  75. $this->build_links();
  76. $this->build_tool_intro();
  77. //$this->build_forums();
  78. $this->build_documents();
  79. $this->build_course_descriptions();
  80. $this->build_quizzes();
  81. $this->build_learnpaths();
  82. $this->build_surveys();
  83. //TABLE_LINKED_RESOURCES is the "resource" course table, which is deprecated, apparently
  84. $table = Database :: get_course_table(TABLE_LINKED_RESOURCES);
  85. foreach ($this->course->resources as $type => $resources)
  86. {
  87. foreach ($resources as $id => $resource)
  88. {
  89. $sql = "SELECT * FROM ".$table." WHERE source_type = '".$resource->get_type()."' AND source_id = '".$resource->get_id()."'";
  90. $res = api_sql_query($sql, __FILE__, __LINE__);
  91. while ($link = Database::fetch_object($res))
  92. {
  93. $this->course->resources[$type][$id]->add_linked_resource($link->resource_type, $link->resource_id);
  94. }
  95. }
  96. }
  97. $table = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  98. foreach ($this->course->resources as $type => $resources)
  99. {
  100. foreach ($resources as $id => $resource)
  101. {
  102. $tool = $resource->get_tool();
  103. if ($tool != null)
  104. {
  105. $sql = "SELECT * FROM $table WHERE TOOL = '".$tool."' AND ref='".$resource->get_id()."'";
  106. $res = api_sql_query($sql,__FILE__,__LINE__);
  107. $all_properties = array ();
  108. while ($item_property = Database::fetch_array($res))
  109. {
  110. $all_properties[] = $item_property;
  111. }
  112. $this->course->resources[$type][$id]->item_properties = $all_properties;
  113. }
  114. }
  115. }
  116. return $this->course;
  117. }
  118. /**
  119. * Build the documents
  120. */
  121. function build_documents()
  122. {
  123. $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
  124. $table_prop = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  125. if (!empty($this->course->type) && $this->course->type=='partial')
  126. $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%\' ORDER BY path';
  127. else
  128. $sql = 'SELECT * FROM '.$table_doc.' d, '.$table_prop.' p WHERE tool = \''.TOOL_DOCUMENT.'\' AND p.ref = d.id AND p.visibility != 2 ORDER BY path';
  129. $db_result = api_sql_query($sql, __FILE__, __LINE__);
  130. while ($obj = Database::fetch_object($db_result))
  131. {
  132. $doc = new Document($obj->id, $obj->path, $obj->comment, $obj->title, $obj->filetype, $obj->size);
  133. $this->course->add_resource($doc);
  134. }
  135. }
  136. /**
  137. * Build the forums
  138. */
  139. function build_forums()
  140. {
  141. $table = Database :: get_course_table(TABLE_FORUM);
  142. $sql = 'SELECT * FROM '.$table;
  143. $db_result = api_sql_query($sql, __FILE__, __LINE__);
  144. while ($obj = Database::fetch_object($db_result))
  145. {
  146. $forum = new Forum($obj->forum_id, $obj->forum_name, $obj->forum_description, $obj->cat_id, $obj->forum_last_post_id);
  147. $this->course->add_resource($forum);
  148. $this->build_forum_category($obj->cat_id);
  149. }
  150. $this->build_forum_topics();
  151. $this->build_forum_posts();
  152. }
  153. /**
  154. * Build a forum-category
  155. */
  156. function build_forum_category($id)
  157. {
  158. $table = Database :: get_course_table(TABLE_FORUM_CATEGORY);
  159. $sql = 'SELECT * FROM '.$table.' WHERE cat_id = '.$id;
  160. $db_result = api_sql_query($sql, __FILE__, __LINE__);
  161. while ($obj = Database::fetch_object($db_result))
  162. {
  163. $forum_category = new ForumCategory($obj->cat_id, $obj->cat_title);
  164. $this->course->add_resource($forum_category);
  165. }
  166. }
  167. /**
  168. * Build the forum-topics
  169. */
  170. function build_forum_topics()
  171. {
  172. $table = Database :: get_course_table(TABLE_FORUM_POST);
  173. $sql = 'SELECT * FROM '.$table;
  174. $db_result = api_sql_query($sql, __FILE__, __LINE__);
  175. while ($obj = Database::fetch_object($db_result))
  176. {
  177. $forum_topic = new ForumTopic($obj->topic_id, $obj->topic_title, $obj->topic_time, $obj->prenom, $obj->nom, $obj->topic_notify, $obj->forum_id, $obj->topic_last_post_id);
  178. $this->course->add_resource($forum_topic);
  179. }
  180. }
  181. /**
  182. * Build the forum-posts
  183. */
  184. function build_forum_posts()
  185. {
  186. $table_post = Database :: get_course_table(TABLE_FORUM_POST);
  187. $table_posttext = Database :: get_course_table(TOOL_FORUM_POST_TEXT_TABLE);
  188. $sql = 'SELECT * FROM '.$table_post.' p,'.$table_posttext.' pt WHERE p.post_id = pt.post_id';
  189. $db_result = api_sql_query($sql, __FILE__, __LINE__);
  190. while ($obj = Database::fetch_object($db_result))
  191. {
  192. $forum_post = new ForumPost($obj->post_id, $obj->post_title, $obj->post_text, $obj->post_time, $obj->poster_ip, $obj->prenom, $obj->nom, $obj->topic_notify, $obj->parent_id, $obj->topic_id);
  193. $this->course->add_resource($forum_post);
  194. }
  195. }
  196. /**
  197. * Build the links
  198. */
  199. function build_links()
  200. {
  201. $table = Database :: get_course_table(TABLE_LINK);
  202. $table_prop = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  203. $sql = "SELECT * FROM $table l, $table_prop p WHERE p.ref=l.id AND p.tool = '".TOOL_LINK."' AND p.visibility != 2 ORDER BY l.display_order";
  204. $db_result = api_sql_query($sql, __FILE__, __LINE__);
  205. while ($obj = Database::fetch_object($db_result))
  206. {
  207. $link = new Link($obj->id, $obj->title, $obj->url, $obj->description, $obj->category_id, $obj->on_homepage);
  208. $this->course->add_resource($link);
  209. $res = $this->build_link_category($obj->category_id);
  210. if($res > 0)
  211. {
  212. $this->course->resources[RESOURCE_LINK][$obj->id]->add_linked_resource(RESOURCE_LINKCATEGORY, $obj->category_id);
  213. }
  214. }
  215. }
  216. /**
  217. * Build tool intro
  218. */
  219. function build_tool_intro()
  220. {
  221. $table = Database :: get_course_table(TABLE_TOOL_INTRO);
  222. $sql = 'SELECT * FROM '.$table;
  223. $db_result = api_sql_query($sql, __FILE__, __LINE__);
  224. while ($obj = Database::fetch_object($db_result))
  225. {
  226. $tool_intro = new ToolIntro($obj->id, $obj->intro_text);
  227. $this->course->add_resource($tool_intro);
  228. }
  229. }
  230. /**
  231. * Build a link category
  232. */
  233. function build_link_category($id)
  234. {
  235. $link_cat_table = Database :: get_course_table(TABLE_LINK_CATEGORY);
  236. $sql = 'SELECT * FROM '.$link_cat_table.' WHERE id = '.$id;
  237. $db_result = api_sql_query($sql, __FILE__, __LINE__);
  238. while ($obj = Database::fetch_object($db_result))
  239. {
  240. $link_category = new LinkCategory($obj->id, $obj->category_title, $obj->description, $obj->display_order);
  241. $this->course->add_resource($link_category);
  242. return $id;
  243. }
  244. return 0;
  245. }
  246. /**
  247. * Build the Quizzes
  248. */
  249. function build_quizzes()
  250. {
  251. $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
  252. $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
  253. $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
  254. $sql = 'SELECT * FROM '.$table_qui.' WHERE active >=0'; //select only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes)
  255. $db_result = api_sql_query($sql, __FILE__, __LINE__);
  256. while ($obj = Database::fetch_object($db_result))
  257. {
  258. if (strlen($obj->sound) > 0)
  259. {
  260. $doc = Database::fetch_object(api_sql_query("SELECT id FROM ".$table_doc." WHERE path = '/audio/".$obj->sound."'"));
  261. $obj->sound = $doc->id;
  262. }
  263. $quiz = new Quiz($obj->id, $obj->title, $obj->description, $obj->random, $obj->type, $obj->active, $obj->sound, $obj->attempts);
  264. $sql = 'SELECT * FROM '.$table_rel.' WHERE exercice_id = '.$obj->id;
  265. $db_result2 = api_sql_query($sql, __FILE__, __LINE__);
  266. while ($obj2 = Database::fetch_object($db_result2))
  267. {
  268. $quiz->add_question($obj2->question_id);
  269. }
  270. $this->course->add_resource($quiz);
  271. }
  272. $this->build_quiz_questions();
  273. }
  274. /**
  275. * Build the Quiz-Questions
  276. */
  277. function build_quiz_questions()
  278. {
  279. $table_que = Database :: get_course_table(TABLE_QUIZ_QUESTION);
  280. $table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
  281. $sql = 'SELECT * FROM '.$table_que;
  282. $db_result = api_sql_query($sql, __FILE__, __LINE__);
  283. while ($obj = Database::fetch_object($db_result))
  284. {
  285. $question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level);
  286. $sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.$obj->id;
  287. $db_result2 = api_sql_query($sql, __FILE__, __LINE__);
  288. while ($obj2 = Database::fetch_object($db_result2))
  289. {
  290. $question->add_answer($obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type);
  291. }
  292. $this->course->add_resource($question);
  293. }
  294. }
  295. /**
  296. * Build the Surveys
  297. */
  298. function build_surveys()
  299. {
  300. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  301. $table_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  302. $sql = 'SELECT * FROM '.$table_survey;
  303. $db_result = api_sql_query($sql, __FILE__, __LINE__);
  304. while ($obj = Database::fetch_object($db_result))
  305. {
  306. $survey = new Survey($obj->survey_id, $obj->code,$obj->title,
  307. $obj->subtitle, $obj->author, $obj->lang,
  308. $obj->avail_from, $obj->avail_till, $obj->is_shared,
  309. $obj->template, $obj->intro, $obj->surveythanks,
  310. $obj->creation_date, $obj->invited, $obj->answered,
  311. $obj->invite_mail, $obj->reminder_mail);
  312. $sql = 'SELECT * FROM '.$table_question.' WHERE survey_id = '.$obj->survey_id;
  313. $db_result2 = api_sql_query($sql, __FILE__, __LINE__);
  314. while ($obj2 = Database::fetch_object($db_result2))
  315. {
  316. $survey->add_question($obj2->question_id);
  317. }
  318. $this->course->add_resource($survey);
  319. }
  320. $this->build_survey_questions();
  321. }
  322. /**
  323. * Build the Survey Questions
  324. */
  325. function build_survey_questions()
  326. {
  327. $table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  328. $table_opt = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
  329. $sql = 'SELECT * FROM '.$table_que;
  330. $db_result = api_sql_query($sql, __FILE__, __LINE__);
  331. while ($obj = Database::fetch_object($db_result))
  332. {
  333. $question = new SurveyQuestion($obj->question_id, $obj->survey_id,
  334. $obj->survey_question, $obj->survey_question_comment,
  335. $obj->type, $obj->display, $obj->sort,
  336. $obj->shared_question_id, $obj->max_value);
  337. $sql = 'SELECT * FROM '.$table_opt.' WHERE question_id = '."'".$obj->question_id."'";
  338. $db_result2 = api_sql_query($sql, __FILE__, __LINE__);
  339. while ($obj2 = Database::fetch_object($db_result2))
  340. {
  341. $question->add_answer($obj2->option_text, $obj2->sort);
  342. }
  343. $this->course->add_resource($question);
  344. }
  345. }
  346. /**
  347. * Build the announcements
  348. */
  349. function build_announcements()
  350. {
  351. $table = Database :: get_course_table(TABLE_ANNOUNCEMENT);
  352. $sql = 'SELECT * FROM '.$table;
  353. $db_result = api_sql_query($sql, __FILE__, __LINE__);
  354. while ($obj = Database::fetch_object($db_result))
  355. {
  356. $announcement = new Announcement($obj->id, $obj->title, $obj->content, $obj->end_date,$obj->display_order,$obj->email_sent);
  357. $this->course->add_resource($announcement);
  358. }
  359. }
  360. /**
  361. * Build the events
  362. */
  363. function build_events()
  364. {
  365. $table = Database :: get_course_table(TABLE_AGENDA);
  366. $sql = 'SELECT * FROM '.$table;
  367. $db_result = api_sql_query($sql, __FILE__, __LINE__);
  368. while ($obj = Database::fetch_object($db_result))
  369. {
  370. $event = new Event($obj->id, $obj->title, $obj->content, $obj->start_date, $obj->end_date);
  371. $this->course->add_resource($event);
  372. }
  373. }
  374. /**
  375. * Build the course-descriptions
  376. */
  377. function build_course_descriptions()
  378. {
  379. $table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION);
  380. $sql = 'SELECT * FROM '.$table;
  381. $db_result = api_sql_query($sql, __FILE__, __LINE__);
  382. while ($obj = Database::fetch_object($db_result))
  383. {
  384. $cd = new CourseDescription($obj->id, $obj->title, $obj->content);
  385. $this->course->add_resource($cd);
  386. }
  387. }
  388. /**
  389. * Build the learnpaths
  390. */
  391. function build_learnpaths()
  392. {
  393. $table_main = Database :: get_course_table(TABLE_LP_MAIN);
  394. $table_item = Database :: get_course_table(TABLE_LP_ITEM);
  395. $table_tool = Database::get_course_table(TABLE_TOOL_LIST);
  396. $sql = 'SELECT * FROM '.$table_main;
  397. $db_result = api_sql_query($sql, __FILE__, __LINE__);
  398. while ($obj = Database::fetch_object($db_result))
  399. {
  400. $items = array();
  401. $sql_items = "SELECT * FROM ".$table_item." WHERE lp_id = ".$obj->id."";
  402. $db_items = api_sql_query($sql_items);
  403. while ($obj_item = Database::fetch_object($db_items))
  404. {
  405. $item['id'] = $obj_item->id;
  406. $item['item_type'] = $obj_item->item_type;
  407. $item['ref'] = $obj_item->ref;
  408. $item['title'] = $obj_item->title;
  409. $item['description'] = $obj_item->description;
  410. $item['path'] = $obj_item->path;
  411. $item['min_score'] = $obj_item->min_score;
  412. $item['max_score'] = $obj_item->max_score;
  413. $item['mastery_score'] = $obj_item->mastery_score;
  414. $item['parent_item_id'] = $obj_item->parent_item_id;
  415. $item['previous_item_id'] = $obj_item->previous_item_id;
  416. $item['next_item_id'] = $obj_item->next_item_id;
  417. $item['display_order'] = $obj_item->display_order;
  418. $item['prerequisite'] = $obj_item->prerequisite;
  419. $item['parameters'] = $obj_item->parameters;
  420. $item['launch_data'] = $obj_item->launch_data;
  421. $items[] = $item;
  422. }
  423. $sql_tool = "SELECT id FROM ".$table_tool." WHERE (link LIKE '%lp_controller.php%lp_id=".$obj->id."%' and image='scormbuilder.gif') AND visibility='1'";
  424. $db_tool = api_sql_query($sql_tool);
  425. if(Database::num_rows($db_tool))
  426. {
  427. $visibility='1';
  428. }
  429. else
  430. {
  431. $visibility='0';
  432. }
  433. $lp = new Learnpath($obj->id,
  434. $obj->lp_type,
  435. $obj->name,
  436. $obj->path,
  437. $obj->ref,
  438. $obj->description,
  439. $obj->content_local,
  440. $obj->default_encoding,
  441. $obj->default_view_mod,
  442. $obj->prevent_reinit,
  443. $obj->force_commit,
  444. $obj->content_maker,
  445. $obj->display_order,
  446. $obj->js_lib,
  447. $obj->content_license,
  448. $obj->debug,
  449. $visibility,
  450. $items);
  451. $this->course->add_resource($lp);
  452. }
  453. //save scorm directory (previously build_scorm_documents())
  454. $i = 1;
  455. if($dir=@opendir($this->course->backup_path.'/scorm'))
  456. {
  457. while($file=readdir($dir))
  458. {
  459. if(is_dir($this->course->backup_path.'/scorm/'.$file) && !in_array($file,array('.','..')))
  460. {
  461. $doc = new ScormDocument($i++, '/'.$file, $file);
  462. $this->course->add_resource($doc);
  463. }
  464. }
  465. closedir($dir);
  466. }
  467. }
  468. }
  469. ?>