CourseBuilder.class.php 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137
  1. <?php
  2. /* For licensing terms, see /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 'CourseCopyTestCategory.php';
  18. require_once 'CourseCopyLearnpath.class.php';
  19. require_once 'Survey.class.php';
  20. require_once 'SurveyQuestion.class.php';
  21. require_once 'Glossary.class.php';
  22. require_once 'CourseSession.class.php';
  23. require_once 'wiki.class.php';
  24. require_once 'Thematic.class.php';
  25. require_once 'Attendance.class.php';
  26. require_once 'Work.class.php';
  27. /**
  28. * Class which can build a course-object from a Chamilo-course.
  29. * @author Bart Mollet <bart.mollet@hogent.be>
  30. * @package chamilo.backup
  31. */
  32. class CourseBuilder
  33. {
  34. /** Course */
  35. public $course;
  36. /* With this array you can filter the tools you want to be parsed by
  37. default all tools are included */
  38. public $tools_to_build = array(
  39. 'announcements',
  40. 'attendance',
  41. 'course_descriptions',
  42. 'documents',
  43. 'events',
  44. 'forum_category',
  45. 'forums',
  46. 'forum_topics',
  47. 'glossary',
  48. 'quizzes',
  49. 'test_category',
  50. 'learnpaths',
  51. 'links',
  52. 'surveys',
  53. 'tool_intro',
  54. 'thematic',
  55. 'wiki',
  56. 'works'
  57. );
  58. /* With this array you can filter wich elements of the tools are going
  59. to be added in the course obj (only works with LPs) */
  60. public $specific_id_list = array();
  61. /**
  62. * Create a new CourseBuilder
  63. */
  64. public function __construct($type='', $course = null)
  65. {
  66. $_course = api_get_course_info();
  67. if (!empty($course['official_code'])){
  68. $_course = $course;
  69. }
  70. $this->course = new Course();
  71. $this->course->code = $_course['official_code'];
  72. $this->course->type = $type;
  73. $this->course->path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/';
  74. $this->course->backup_path = api_get_path(SYS_COURSE_PATH).$_course['path'];
  75. $this->course->encoding = api_get_system_encoding(); //current platform encoding
  76. $this->course->db_name = $_course['dbName'];
  77. $this->course->info = $_course;
  78. }
  79. /**
  80. *
  81. * @param array $array
  82. */
  83. public function set_tools_to_build($array)
  84. {
  85. $this->tools_to_build = $array;
  86. }
  87. /**
  88. *
  89. * @param array $array
  90. */
  91. public function set_tools_specific_id_list($array)
  92. {
  93. $this->specific_id_list = $array;
  94. }
  95. /**
  96. * Get the created course
  97. * @return course The course
  98. */
  99. public function get_course()
  100. {
  101. return $this->course;
  102. }
  103. /**
  104. * Build the course-object
  105. *
  106. * @param int session_id
  107. * @param string course_code
  108. * @param bool true if you want to get the elements that exists in the course and
  109. * in the session, (session_id = 0 or session_id = X)
  110. */
  111. public function build($session_id = 0, $course_code = '', $with_base_content = false)
  112. {
  113. $table_link = Database :: get_course_table(TABLE_LINKED_RESOURCES);
  114. $table_properties = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  115. $course_info = api_get_course_info($course_code);
  116. $course_id = $course_info['real_id'];
  117. foreach ($this->tools_to_build as $tool) {
  118. $function_build = 'build_'.$tool;
  119. $specificIdList = isset($this->specific_id_list[$tool]) ? $this->specific_id_list[$tool] : null;
  120. $this->$function_build(
  121. $session_id,
  122. $course_code,
  123. $with_base_content,
  124. $specificIdList
  125. );
  126. }
  127. //TABLE_LINKED_RESOURCES is the "resource" course table, which is deprecated, apparently
  128. foreach ($this->course->resources as $type => $resources) {
  129. foreach ($resources as $id => $resource) {
  130. $sql = "SELECT * FROM $table_link
  131. WHERE
  132. c_id = $course_id AND
  133. source_type = '".$resource->get_type()."' AND
  134. source_id = '".$resource->get_id()."'";
  135. $res = Database::query($sql);
  136. while ($link = Database::fetch_object($res)) {
  137. $this->course->resources[$type][$id]->add_linked_resource($link->resource_type, $link->resource_id);
  138. }
  139. }
  140. }
  141. // Once we've built the resouces array a bit more, try to get items
  142. // from the item_propry table and order them in the "resources" array
  143. foreach ($this->course->resources as $type => $resources) {
  144. foreach ($resources as $id => $resource) {
  145. $tool = $resource->get_tool();
  146. if ($tool != null) {
  147. $sql = "SELECT * FROM $table_properties
  148. WHERE
  149. c_id = $course_id AND
  150. tool = '".$tool."' AND
  151. ref='".$resource->get_id()."'";
  152. $res = Database::query($sql);
  153. $all_properties = array ();
  154. while ($item_property = Database::fetch_array($res)) {
  155. $all_properties[]= $item_property;
  156. }
  157. $this->course->resources[$type][$id]->item_properties = $all_properties;
  158. }
  159. }
  160. }
  161. return $this->course;
  162. }
  163. /**
  164. * Build the documents
  165. * @param int $session_id
  166. * @param string $course_code
  167. * @param bool $with_base_content
  168. * @param array $id_list
  169. */
  170. public function build_documents($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  171. {
  172. $course_info = api_get_course_info($course_code);
  173. $course_id = $course_info['real_id'];
  174. $table_doc = Database::get_course_table(TABLE_DOCUMENT);
  175. $table_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
  176. //Remove chat_files and shared_folder files
  177. $avoid_paths = " path NOT LIKE '/shared_folder%' AND
  178. path NOT LIKE '/chat_files%' ";
  179. //$avoid_paths = " 1 = 1 ";
  180. if (!empty($course_code) && !empty($session_id)) {
  181. $session_id = intval($session_id);
  182. if ($with_base_content) {
  183. $session_condition = api_get_session_condition($session_id, true, true);
  184. } else {
  185. $session_condition = api_get_session_condition($session_id, true);
  186. }
  187. if (!empty($this->course->type) && $this->course->type == 'partial') {
  188. $sql = "SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size
  189. FROM $table_doc d INNER JOIN $table_prop p
  190. ON (p.ref = d.id AND d.c_id = p.c_id)
  191. WHERE
  192. d.c_id = $course_id AND
  193. p.c_id = $course_id AND
  194. tool = '".TOOL_DOCUMENT."' AND
  195. p.visibility != 2 AND
  196. path NOT LIKE '/images/gallery%' AND
  197. $avoid_paths
  198. $session_condition
  199. ORDER BY path";
  200. } else {
  201. $sql = "SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size
  202. FROM $table_doc d INNER JOIN $table_prop p
  203. ON (p.ref = d.id AND d.c_id = p.c_id)
  204. WHERE
  205. d.c_id = $course_id AND
  206. p.c_id = $course_id AND
  207. tool = '".TOOL_DOCUMENT."' AND
  208. $avoid_paths AND
  209. p.visibility != 2 $session_condition
  210. ORDER BY path";
  211. }
  212. $db_result = Database::query($sql);
  213. while ($obj = Database::fetch_object($db_result)) {
  214. $doc = new Document($obj->id, $obj->path, $obj->comment, $obj->title, $obj->filetype, $obj->size);
  215. $this->course->add_resource($doc);
  216. }
  217. } else {
  218. if (!empty($this->course->type) && $this->course->type=='partial') {
  219. $sql = "SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size
  220. FROM $table_doc d INNER JOIN $table_prop p
  221. ON (p.ref = d.id AND d.c_id = p.c_id)
  222. WHERE
  223. d.c_id = $course_id AND
  224. p.c_id = $course_id AND
  225. tool = '".TOOL_DOCUMENT."' AND
  226. p.visibility != 2 AND
  227. path NOT LIKE '/images/gallery%' AND
  228. $avoid_paths AND
  229. d.session_id = 0
  230. ORDER BY path";
  231. } else {
  232. $sql = "SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size
  233. FROM $table_doc d INNER JOIN $table_prop p
  234. ON (p.ref = d.id AND d.c_id = p.c_id)
  235. WHERE
  236. d.c_id = $course_id AND
  237. p.c_id = $course_id AND
  238. tool = '".TOOL_DOCUMENT."' AND
  239. p.visibility != 2 AND
  240. $avoid_paths AND
  241. d.session_id = 0
  242. ORDER BY path";
  243. }
  244. $db_result = Database::query($sql);
  245. while ($obj = Database::fetch_object($db_result)) {
  246. $doc = new Document(
  247. $obj->id, $obj->path, $obj->comment, $obj->title, $obj->filetype, $obj->size
  248. );
  249. $this->course->add_resource($doc);
  250. }
  251. }
  252. }
  253. /**
  254. * Build the forums
  255. */
  256. public function build_forums($session_id = 0, $course_code = null, $with_base_content = false, $id_list = array())
  257. {
  258. $course_info = api_get_course_info($course_code);
  259. $course_id = $course_info['real_id'];
  260. $table = Database :: get_course_table(TABLE_FORUM);
  261. $sql = "SELECT * FROM $table WHERE c_id = $course_id ";
  262. $sql .= " ORDER BY forum_title, forum_category";
  263. $db_result = Database::query($sql);
  264. while ($obj = Database::fetch_object($db_result)) {
  265. $forum = new Forum($obj);
  266. $this->course->add_resource($forum);
  267. }
  268. }
  269. /**
  270. * Build a forum-category
  271. */
  272. public function build_forum_category($session_id = 0, $course_code = null, $with_base_content = false, $id_list = array())
  273. {
  274. $table = Database :: get_course_table(TABLE_FORUM_CATEGORY);
  275. $course_info = api_get_course_info($course_code);
  276. $course_id = $course_info['real_id'];
  277. $sql = "SELECT * FROM $table WHERE c_id = $course_id ORDER BY cat_title";
  278. $db_result = Database::query($sql);
  279. while ($obj = Database::fetch_object($db_result)) {
  280. $forum_category = new ForumCategory($obj);
  281. $this->course->add_resource($forum_category);
  282. }
  283. }
  284. /**
  285. * Build the forum-topics
  286. */
  287. public function build_forum_topics($session_id = 0, $course_code = null, $with_base_content = false, $id_list = array())
  288. {
  289. $table = Database :: get_course_table(TABLE_FORUM_THREAD);
  290. $course_info = api_get_course_info($course_code);
  291. $course_id = $course_info['real_id'];
  292. $sql = "SELECT * FROM $table WHERE c_id = $course_id
  293. ORDER BY thread_title ";
  294. $db_result = Database::query($sql);
  295. while ($obj = Database::fetch_object($db_result)) {
  296. $forum_topic = new ForumTopic($obj);
  297. $this->course->add_resource($forum_topic);
  298. $this->build_forum_posts($obj->thread_id, $obj->forum_id, true);
  299. }
  300. }
  301. /**
  302. * Build the forum-posts
  303. * TODO: All tree structure of posts should be built, attachments for example.
  304. */
  305. public function build_forum_posts($thread_id = null, $forum_id = null, $only_first_post = false)
  306. {
  307. $table = Database :: get_course_table(TABLE_FORUM_POST);
  308. $course_id = api_get_course_int_id();
  309. $sql = "SELECT * FROM $table WHERE c_id = $course_id ";
  310. if (!empty($thread_id) && !empty($forum_id)) {
  311. $forum_id = intval($forum_id);
  312. $thread_id = intval($thread_id);
  313. $sql .= " AND thread_id = $thread_id AND forum_id = $forum_id ";
  314. }
  315. $sql .= " ORDER BY post_id ASC LIMIT 1";
  316. $db_result = Database::query($sql);
  317. while ($obj = Database::fetch_object($db_result)) {
  318. $forum_post = new ForumPost($obj);
  319. $this->course->add_resource($forum_post);
  320. }
  321. }
  322. /**
  323. * Build the links
  324. */
  325. public function build_links($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  326. {
  327. $course_info = api_get_course_info($course_code);
  328. $course_id = $course_info['real_id'];
  329. $table = Database :: get_course_table(TABLE_LINK);
  330. $table_prop = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  331. if (!empty($session_id) && !empty($course_code)) {
  332. $session_id = intval($session_id);
  333. if ($with_base_content) {
  334. $session_condition = api_get_session_condition($session_id, true, true);
  335. } else {
  336. $session_condition = api_get_session_condition($session_id, true);
  337. }
  338. $sql = "SELECT l.id, l.title, l.url, l.description, l.category_id, l.on_homepage
  339. FROM $table l, $table_prop p
  340. 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
  341. ORDER BY l.display_order";
  342. } else {
  343. $sql = "SELECT l.id, l.title, l.url, l.description, l.category_id, l.on_homepage
  344. FROM $table l, $table_prop p
  345. 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
  346. ORDER BY l.display_order";
  347. }
  348. $db_result = Database::query($sql);
  349. while ($obj = Database::fetch_object($db_result)) {
  350. $link = new Link($obj->id, $obj->title, $obj->url, $obj->description, $obj->category_id, $obj->on_homepage);
  351. $this->course->add_resource($link);
  352. if (!empty($course_code)) {
  353. $res = $this->build_link_category($obj->category_id,$course_code);
  354. } else {
  355. $res = $this->build_link_category($obj->category_id);
  356. }
  357. if($res > 0) {
  358. $this->course->resources[RESOURCE_LINK][$obj->id]->add_linked_resource(RESOURCE_LINKCATEGORY, $obj->category_id);
  359. }
  360. }
  361. }
  362. /**
  363. * Build tool intro
  364. */
  365. public function build_tool_intro($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  366. {
  367. $table = Database :: get_course_table(TABLE_TOOL_INTRO);
  368. $course_id = api_get_course_int_id();
  369. $sql = "SELECT * FROM $table WHERE c_id = $course_id ";
  370. $db_result = Database::query($sql);
  371. while ($obj = Database::fetch_object($db_result)) {
  372. $tool_intro = new ToolIntro($obj->id, $obj->intro_text);
  373. $this->course->add_resource($tool_intro);
  374. }
  375. }
  376. /**
  377. * Build a link category
  378. */
  379. public function build_link_category($id, $course_code = '')
  380. {
  381. $course_info = api_get_course_info($course_code);
  382. $course_id = $course_info['real_id'];
  383. $link_cat_table = Database :: get_course_table(TABLE_LINK_CATEGORY);
  384. $sql = "SELECT * FROM $link_cat_table WHERE c_id = $course_id AND id = $id";
  385. $db_result = Database::query($sql);
  386. while ($obj = Database::fetch_object($db_result)) {
  387. $link_category = new LinkCategory($obj->id, $obj->category_title, $obj->description, $obj->display_order);
  388. $this->course->add_resource($link_category);
  389. return $id;
  390. }
  391. return 0;
  392. }
  393. /**
  394. * Build the Quizzes
  395. */
  396. public function build_quizzes($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  397. {
  398. $course_info = api_get_course_info($course_code);
  399. $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
  400. $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
  401. $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
  402. $course_id = $course_info['real_id'];
  403. if (!empty($course_code) && !empty($session_id)) {
  404. $session_id = intval($session_id);
  405. if ($with_base_content) {
  406. $session_condition = api_get_session_condition($session_id, true, true);
  407. } else {
  408. $session_condition = api_get_session_condition($session_id, true);
  409. }
  410. $sql = "SELECT * FROM $table_qui WHERE c_id = $course_id AND active >=0 $session_condition";
  411. //select only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes)
  412. } else {
  413. $sql = "SELECT * FROM $table_qui WHERE c_id = $course_id AND active >=0 AND session_id = 0";
  414. //select only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes)
  415. }
  416. $db_result = Database::query($sql);
  417. while ($obj = Database::fetch_object($db_result)) {
  418. if (strlen($obj->sound) > 0) {
  419. $sql = "SELECT id FROM $table_doc WHERE c_id = $course_id AND path = '/audio/".$obj->sound."'";
  420. $res = Database::query($sql);
  421. $doc = Database::fetch_object($res);
  422. $obj->sound = $doc->id;
  423. }
  424. $exercise_obj = new Exercise($course_id);
  425. $exercise_obj->read($obj->iid);
  426. $categories = $exercise_obj->get_categories_with_name_in_exercise();
  427. $obj->categories = $categories;
  428. $quiz = new Quiz($obj);
  429. $sql = 'SELECT * FROM '.$table_rel.' WHERE c_id = '.$course_id.' AND exercice_id = '.$obj->iid;
  430. $db_result2 = Database::query($sql);
  431. while ($obj2 = Database::fetch_object($db_result2)) {
  432. $quiz->add_question($obj2->question_id, $obj2->question_order);
  433. }
  434. $this->course->add_resource($quiz);
  435. }
  436. if (!empty($course_code)) {
  437. $this->build_quiz_questions($course_code);
  438. } else {
  439. $this->build_quiz_questions();
  440. }
  441. }
  442. /**
  443. * Build the Quiz-Questions
  444. */
  445. public function build_quiz_questions($course_code = null)
  446. {
  447. $course_info = api_get_course_info($course_code);
  448. $course_id = $course_info['real_id'];
  449. $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
  450. $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
  451. $table_que = Database :: get_course_table(TABLE_QUIZ_QUESTION);
  452. $table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
  453. // Building normal tests.
  454. $sql = "SELECT * FROM $table_que WHERE c_id = $course_id ";
  455. $db_result = Database::query($sql);
  456. while ($obj = Database::fetch_object($db_result)) {
  457. $categories = Testcategory::getCategoryForQuestionWithCategoryData($obj->iid, $course_id, true);
  458. $parent_info = array();
  459. if (isset($obj->parent_id) && !empty($obj->parent_id)) {
  460. $parent_info = (array)Question::read($obj->parent_id, $course_id);
  461. }
  462. $question = new QuizQuestion($obj->iid, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture, $obj->level, $obj->extra, $parent_info, $categories);
  463. $sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.$obj->iid;
  464. $db_result2 = Database::query($sql);
  465. while ($obj2 = Database::fetch_object($db_result2)) {
  466. $question->add_answer($obj2->iid, $obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type);
  467. if ($obj->type == MULTIPLE_ANSWER_TRUE_FALSE) {
  468. $table_options = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
  469. $sql = 'SELECT * FROM '.$table_options.' WHERE c_id = '.$course_id.' AND question_id = '.$obj->iid;
  470. $db_result3 = Database::query($sql);
  471. while ($obj3 = Database::fetch_object($db_result3)) {
  472. $question_option = new QuizQuestionOption($obj3);
  473. $question->add_option($question_option);
  474. }
  475. }
  476. }
  477. $this->course->add_resource($question);
  478. }
  479. // Building a fictional test for collecting orphan questions.
  480. $build_orphan_questions = !empty($_POST['recycle_option']); // When a course is emptied this option should be activated (true).
  481. //1st union gets the orphan questions from deleted exercises
  482. //2nd union gets the orphan questions from question that were deleted in a exercise.
  483. $sql = " (
  484. SELECT q.* FROM $table_que q INNER JOIN $table_rel r
  485. ON (q.c_id = r.c_id AND q.iid = r.question_id)
  486. INNER JOIN $table_qui ex
  487. ON (ex.iid = r.exercice_id AND ex.c_id = r.c_id )
  488. WHERE ex.c_id = $course_id AND ex.active = '-1'
  489. )
  490. UNION
  491. (
  492. SELECT q.* FROM $table_que q left
  493. OUTER JOIN $table_rel r
  494. ON (q.c_id = r.c_id AND q.iid = r.question_id)
  495. WHERE q.c_id = $course_id AND r.question_id is null
  496. )
  497. UNION
  498. (
  499. SELECT q.* FROM $table_que q
  500. INNER JOIN $table_rel r
  501. ON (q.c_id = r.c_id AND q.iid = r.question_id)
  502. WHERE r.c_id = $course_id AND (r.exercice_id = '-1' OR r.exercice_id = '0')
  503. )
  504. ";
  505. $db_result = Database::query($sql);
  506. if (Database::num_rows($db_result) > 0) {
  507. $build_orphan_questions = true;
  508. $orphanQuestionIds = array();
  509. while ($obj = Database::fetch_object($db_result)) {
  510. $categories = Testcategory::getCategoryForQuestionWithCategoryData($obj->iid, $course_id, true);
  511. $parent_info = array();
  512. if (isset($obj->parent_id) && !empty($obj->parent_id)) {
  513. $parent_info = (array)Question::read($obj->parent_id, $course_id);
  514. }
  515. //Avoid adding the same question twice
  516. if (!isset($this->course->resources[$obj->iid])) {
  517. $question = new QuizQuestion($obj->iid, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level, $obj->extra, $parent_info, $categories);
  518. $sql = "SELECT * FROM $table_ans WHERE c_id = $course_id AND question_id = ".$obj->iid;
  519. $db_result2 = Database::query($sql);
  520. if (Database::num_rows($db_result2)) {
  521. while ($obj2 = Database::fetch_object($db_result2)) {
  522. $question->add_answer($obj2->iid, $obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type);
  523. }
  524. $orphanQuestionIds[] = $obj->iid;
  525. }
  526. $this->course->add_resource($question);
  527. }
  528. }
  529. }
  530. if ($build_orphan_questions) {
  531. $obj = array(
  532. 'iid' => -1,
  533. 'title' => get_lang('OrphanQuestions', ''),
  534. 'type' => 2
  535. );
  536. $newQuiz = new Quiz((object)$obj);
  537. if (!empty($orphanQuestionIds)) {
  538. foreach ($orphanQuestionIds as $index => $orphanId) {
  539. $order = $index + 1;
  540. $newQuiz->add_question($orphanId, $order);
  541. }
  542. }
  543. $this->course->add_resource($newQuiz);
  544. }
  545. }
  546. /**
  547. * Build the orphan questions
  548. */
  549. public function build_quiz_orphan_questions()
  550. {
  551. $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
  552. $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
  553. $table_que = Database :: get_course_table(TABLE_QUIZ_QUESTION);
  554. $table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
  555. $course_id = api_get_course_int_id();
  556. $sql = 'SELECT *
  557. FROM '.$table_que.' as questions
  558. LEFT JOIN '.$table_rel.' as quizz_questions
  559. ON questions.id=quizz_questions.question_id
  560. LEFT JOIN '.$table_qui.' as exercices
  561. ON exercice_id=exercices.id
  562. WHERE questions.c_id = '.$course_id.' AND
  563. quizz_questions.c_id = '.$course_id.' AND
  564. exercices.c_id = '.$course_id.' AND
  565. (quizz_questions.exercice_id IS NULL OR
  566. exercices.active = -1)';
  567. $db_result = Database::query($sql);
  568. if (Database::num_rows($db_result) > 0) {
  569. // This is the fictional test for collecting orphan questions.
  570. $orphan_questions = new Quiz(-1, get_lang('OrphanQuestions', ''), '', 0, 0, 1, '', 0);
  571. $this->course->add_resource($orphan_questions);
  572. while ($obj = Database::fetch_object($db_result)) {
  573. $question = new QuizQuestion($obj->iid, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level,$obj->extra);
  574. $sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.$obj->iid;
  575. $db_result2 = Database::query($sql);
  576. while ($obj2 = Database::fetch_object($db_result2)) {
  577. $question->add_answer($obj2->iid, $obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type);
  578. }
  579. $this->course->add_resource($question);
  580. }
  581. }
  582. }
  583. /**
  584. * Build the test category
  585. * $session_id, $course_code, $with_base_content, $this->specific_id_list[$tool]
  586. * @todo add course session
  587. */
  588. public function build_test_category($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  589. {
  590. $course_id = api_get_course_int_id();
  591. // get all test category in course
  592. $tab_test_categories_id = Testcategory::getCategoryListInfo("id", $course_id);
  593. foreach ($tab_test_categories_id as $test_category_id)
  594. {
  595. $test_category = new Testcategory($test_category_id);
  596. $copy_course_test_category = new CourseCopyTestcategory($test_category_id, $test_category->name, $test_category->description);
  597. $this->course->add_resource($copy_course_test_category);
  598. }
  599. }
  600. /**
  601. * Build the Surveys
  602. */
  603. public function build_surveys($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  604. {
  605. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  606. $table_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  607. $course_id = api_get_course_int_id();
  608. $sql = 'SELECT * FROM '.$table_survey.' WHERE c_id = '.$course_id.' AND session_id = 0 ';
  609. $db_result = Database::query($sql);
  610. while ($obj = Database::fetch_object($db_result)) {
  611. $survey = new Survey($obj->survey_id, $obj->code,$obj->title,
  612. $obj->subtitle, $obj->author, $obj->lang,
  613. $obj->avail_from, $obj->avail_till, $obj->is_shared,
  614. $obj->template, $obj->intro, $obj->surveythanks,
  615. $obj->creation_date, $obj->invited, $obj->answered,
  616. $obj->invite_mail, $obj->reminder_mail);
  617. $sql = 'SELECT * FROM '.$table_question.' WHERE c_id = '.$course_id.' AND survey_id = '.$obj->survey_id;
  618. $db_result2 = Database::query($sql);
  619. while ($obj2 = Database::fetch_object($db_result2)){
  620. $survey->add_question($obj2->question_id);
  621. }
  622. $this->course->add_resource($survey);
  623. }
  624. $this->build_survey_questions();
  625. }
  626. /**
  627. * Build the Survey Questions
  628. */
  629. public function build_survey_questions() {
  630. $table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  631. $table_opt = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
  632. $course_id = api_get_course_int_id();
  633. $sql = 'SELECT * FROM '.$table_que.' WHERE c_id = '.$course_id.' ';
  634. $db_result = Database::query($sql);
  635. while ($obj = Database::fetch_object($db_result)){
  636. $question = new SurveyQuestion(
  637. $obj->question_id,
  638. $obj->survey_id,
  639. $obj->survey_question,
  640. $obj->survey_question_comment,
  641. $obj->type,
  642. $obj->display,
  643. $obj->sort,
  644. $obj->shared_question_id,
  645. $obj->max_value
  646. );
  647. $sql = 'SELECT * FROM '.$table_opt.' WHERE c_id = '.$course_id.' AND question_id = '.$obj->question_id;
  648. $db_result2 = Database::query($sql);
  649. while ($obj2 = Database::fetch_object($db_result2)) {
  650. $question->add_answer($obj2->option_text, $obj2->sort);
  651. }
  652. $this->course->add_resource($question);
  653. }
  654. }
  655. /**
  656. * Build the announcements
  657. */
  658. public function build_announcements($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  659. {
  660. $table = Database :: get_course_table(TABLE_ANNOUNCEMENT);
  661. $course_id = api_get_course_int_id();
  662. $sql = 'SELECT * FROM '.$table.' WHERE c_id = '.$course_id.' AND session_id = 0';
  663. $db_result = Database::query($sql);
  664. $table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
  665. while ($obj = Database::fetch_object($db_result)) {
  666. $sql = 'SELECT path, comment, filename, size FROM '.$table_attachment.' WHERE c_id = '.$course_id.' AND announcement_id = '.$obj->id.'';
  667. $result = Database::query($sql);
  668. $attachment_obj = Database::fetch_object($result);
  669. $att_path = $att_filename = $att_size = $atth_comment = '';
  670. if (!empty($attachment_obj)) {
  671. $att_path = $attachment_obj->path;
  672. $att_filename = $attachment_obj->filename;
  673. $att_size = $attachment_obj->size;
  674. $atth_comment = $attachment_obj->comment;
  675. }
  676. $announcement = new Announcement(
  677. $obj->id,
  678. $obj->title,
  679. $obj->content,
  680. $obj->end_date,
  681. $obj->display_order,
  682. $obj->email_sent,
  683. $att_path,
  684. $att_filename,
  685. $att_size,
  686. $atth_comment
  687. );
  688. $this->course->add_resource($announcement);
  689. }
  690. }
  691. /**
  692. * Build the events
  693. */
  694. public function build_events($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  695. {
  696. $table = Database :: get_course_table(TABLE_AGENDA);
  697. $course_id = api_get_course_int_id();
  698. $sql = 'SELECT * FROM '.$table.' WHERE c_id = '.$course_id.' AND session_id = 0';
  699. $db_result = Database::query($sql);
  700. while ($obj = Database::fetch_object($db_result)) {
  701. $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
  702. $sql = 'SELECT path, comment, filename, size FROM '.$table_attachment.' WHERE c_id = '.$course_id.' AND agenda_id = '.$obj->id.'';
  703. $result = Database::query($sql);
  704. $attachment_obj = Database::fetch_object($result);
  705. $att_path = $att_filename = $att_size = $atth_comment = '';
  706. if (!empty($attachment_obj)) {
  707. $att_path = $attachment_obj->path;
  708. $att_filename = $attachment_obj->filename;
  709. $att_size = $attachment_obj->size;
  710. $atth_comment = $attachment_obj->comment;
  711. }
  712. $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);
  713. $this->course->add_resource($event);
  714. }
  715. }
  716. /**
  717. * Build the course-descriptions
  718. */
  719. public function build_course_descriptions($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  720. {
  721. $course_info = api_get_course_info($course_code);
  722. $course_id = $course_info['real_id'];
  723. $table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION);
  724. if (!empty($session_id) && !empty($course_code)) {
  725. $session_id = intval($session_id);
  726. if ($with_base_content) {
  727. $session_condition = api_get_session_condition($session_id, true, true);
  728. } else {
  729. $session_condition = api_get_session_condition($session_id, true);
  730. }
  731. $sql = 'SELECT * FROM '.$table. ' WHERE c_id = '.$course_id.' '.$session_condition;
  732. } else {
  733. $table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION);
  734. $sql = 'SELECT * FROM '.$table. ' WHERE c_id = '.$course_id.' AND session_id = 0';
  735. }
  736. $db_result = Database::query($sql);
  737. while ($obj = Database::fetch_object($db_result)) {
  738. $cd = new CourseDescription($obj->id, $obj->title, $obj->content, $obj->description_type);
  739. $this->course->add_resource($cd);
  740. }
  741. }
  742. /**
  743. * Build the learnpaths
  744. */
  745. public function build_learnpaths($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  746. {
  747. $course_info = api_get_course_info($course_code);
  748. $course_id = $course_info['real_id'];
  749. $table_main = Database::get_course_table(TABLE_LP_MAIN);
  750. $table_item = Database::get_course_table(TABLE_LP_ITEM);
  751. $table_tool = Database::get_course_table(TABLE_TOOL_LIST);
  752. if (!empty($session_id) && !empty($course_code)) {
  753. $session_id = intval($session_id);
  754. if ($with_base_content) {
  755. $session_condition = api_get_session_condition($session_id, true, true);
  756. } else {
  757. $session_condition = api_get_session_condition($session_id, true);
  758. }
  759. $sql = 'SELECT * FROM '.$table_main.' WHERE c_id = '.$course_id.' '.$session_condition;
  760. } else {
  761. $sql = 'SELECT * FROM '.$table_main.' WHERE c_id = '.$course_id.' AND session_id = 0';
  762. }
  763. if (!empty($id_list)) {
  764. $id_list = array_map('intval', $id_list);
  765. $sql .=" AND id IN (".implode(', ', $id_list).") ";
  766. }
  767. $db_result = Database::query($sql);
  768. if ($db_result)
  769. while ($obj = Database::fetch_object($db_result)) {
  770. $items = array();
  771. $sql_items = "SELECT * FROM ".$table_item." WHERE c_id = '$course_id' AND lp_id = ".$obj->id;
  772. $db_items = Database::query($sql_items);
  773. while ($obj_item = Database::fetch_object($db_items)) {
  774. $item['id'] = $obj_item->id;
  775. $item['item_type'] = $obj_item->item_type;
  776. $item['ref'] = $obj_item->ref;
  777. $item['title'] = $obj_item->title;
  778. $item['description'] = $obj_item->description;
  779. $item['path'] = $obj_item->path;
  780. $item['min_score'] = $obj_item->min_score;
  781. $item['max_score'] = $obj_item->max_score;
  782. $item['mastery_score'] = $obj_item->mastery_score;
  783. $item['parent_item_id'] = $obj_item->parent_item_id;
  784. $item['previous_item_id'] = $obj_item->previous_item_id;
  785. $item['next_item_id'] = $obj_item->next_item_id;
  786. $item['display_order'] = $obj_item->display_order;
  787. $item['prerequisite'] = $obj_item->prerequisite;
  788. $item['parameters'] = $obj_item->parameters;
  789. $item['launch_data'] = $obj_item->launch_data;
  790. $item['audio'] = $obj_item->audio;
  791. $items[] = $item;
  792. }
  793. $sql_tool = "SELECT id FROM $table_tool
  794. WHERE c_id = $course_id AND
  795. (link LIKE '%lp_controller.php%lp_id=".$obj->id."%' AND image='scormbuilder.gif') AND
  796. visibility = '1' ";
  797. $db_tool = Database::query($sql_tool);
  798. if (Database::num_rows($db_tool)) {
  799. $visibility = '1';
  800. } else {
  801. $visibility = '0';
  802. }
  803. $lp = new CourseCopyLearnpath(
  804. $obj->id,
  805. $obj->lp_type,
  806. $obj->name,
  807. $obj->path,
  808. $obj->ref,
  809. $obj->description,
  810. $obj->content_local,
  811. $obj->default_encoding,
  812. $obj->default_view_mod,
  813. $obj->prevent_reinit,
  814. $obj->force_commit,
  815. $obj->content_maker,
  816. $obj->display_order,
  817. $obj->js_lib,
  818. $obj->content_license,
  819. $obj->debug,
  820. $visibility,
  821. $obj->author,
  822. $obj->preview_image,
  823. $obj->use_max_score,
  824. $obj->autolunch,
  825. $obj->created_on,
  826. $obj->modified_on,
  827. $obj->publicated_on,
  828. $obj->expired_on,
  829. $obj->session_id,
  830. $obj->subscribe_users,
  831. $items);
  832. $this->course->add_resource($lp);
  833. }
  834. //save scorm directory (previously build_scorm_documents())
  835. $i = 1;
  836. if ($dir=@opendir($this->course->backup_path.'/scorm')) {
  837. while($file=readdir($dir)) {
  838. if(is_dir($this->course->backup_path.'/scorm/'.$file) && !in_array($file,array('.','..'))) {
  839. $doc = new ScormDocument($i++, '/'.$file, $file);
  840. $this->course->add_resource($doc);
  841. }
  842. }
  843. closedir($dir);
  844. }
  845. }
  846. /**
  847. * Build the glossarys
  848. */
  849. public function build_glossary($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  850. {
  851. $course_info = api_get_course_info($course_code);
  852. $table_glossary = Database :: get_course_table(TABLE_GLOSSARY);
  853. $course_id = $course_info['real_id'];
  854. if (!empty($session_id) && !empty($course_code)) {
  855. $session_id = intval($session_id);
  856. if ($with_base_content) {
  857. $session_condition = api_get_session_condition($session_id, true, true);
  858. } else {
  859. $session_condition = api_get_session_condition($session_id, true);
  860. }
  861. //@todo check this queries are the same ...
  862. if (!empty($this->course->type) && $this->course->type=='partial') {
  863. $sql = 'SELECT * FROM '.$table_glossary.' g WHERE g.c_id = '.$course_id.' '.$session_condition;
  864. } else {
  865. $sql = 'SELECT * FROM '.$table_glossary.' g WHERE g.c_id = '.$course_id.' '.$session_condition;
  866. }
  867. } else {
  868. $table_glossary = Database :: get_course_table(TABLE_GLOSSARY);
  869. //@todo check this queries are the same ... ayayay
  870. if (!empty($this->course->type) && $this->course->type=='partial') {
  871. $sql = 'SELECT * FROM '.$table_glossary.' g WHERE g.c_id = '.$course_id.' AND session_id = 0';
  872. } else {
  873. $sql = 'SELECT * FROM '.$table_glossary.' g WHERE g.c_id = '.$course_id.' AND session_id = 0';
  874. }
  875. }
  876. $db_result = Database::query($sql);
  877. while ($obj = Database::fetch_object($db_result)) {
  878. $doc = new Glossary($obj->glossary_id, $obj->name, $obj->description, $obj->display_order);
  879. $this->course->add_resource($doc);
  880. }
  881. }
  882. /*
  883. * build session course by jhon
  884. * */
  885. public function build_session_course()
  886. {
  887. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  888. $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  889. $list_course = CourseManager::get_course_list();
  890. $list = array();
  891. foreach($list_course as $_course) {
  892. $this->course = new Course();
  893. $this->course->code = $_course['code'];
  894. $this->course->type = 'partial';
  895. $this->course->path = api_get_path(SYS_COURSE_PATH).$_course['directory'].'/';
  896. $this->course->backup_path = api_get_path(SYS_COURSE_PATH).$_course['directory'];
  897. $this->course->encoding = api_get_system_encoding(); //current platform encoding
  898. //$code_course = $_course['code'];
  899. $courseId = $_course['real_id'];
  900. $sql_session = "SELECT id, name, c_id
  901. FROM $tbl_session_course INNER JOIN $tbl_session ON id_session = id
  902. WHERE c_id = '$courseId' ";
  903. $query_session = Database::query($sql_session);
  904. while ($rows_session = Database::fetch_assoc($query_session)) {
  905. $session = new CourseSession($rows_session['id'], $rows_session['name']);
  906. $this->course->add_resource($session);
  907. }
  908. $list[] = $this->course;
  909. }
  910. return $list;
  911. }
  912. /**
  913. * @param int $session_id
  914. * @param string $course_code
  915. * @param bool $with_base_content
  916. * @param array $id_list
  917. */
  918. public function build_wiki($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  919. {
  920. $course_info = api_get_course_info($course_code);
  921. $tbl_wiki = Database::get_course_table(TABLE_WIKI);
  922. $course_id = $course_info['real_id'];
  923. if (!empty($session_id) && !empty($course_code)) {
  924. $session_id = intval($session_id);
  925. if ($with_base_content) {
  926. $session_condition = api_get_session_condition($session_id, true, true);
  927. } else {
  928. $session_condition = api_get_session_condition($session_id, true);
  929. }
  930. $sql = 'SELECT * FROM ' . $tbl_wiki . ' WHERE c_id = '.$course_id.' '.$session_condition;
  931. } else {
  932. $tbl_wiki = Database::get_course_table(TABLE_WIKI);
  933. $sql = 'SELECT * FROM ' . $tbl_wiki . ' WHERE c_id = '.$course_id.' AND session_id = 0';
  934. }
  935. $db_result = Database::query($sql);
  936. while ($obj = Database::fetch_object($db_result)) {
  937. $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);
  938. $this->course->add_resource($wiki);
  939. }
  940. }
  941. /**
  942. * Build the Surveys
  943. */
  944. public function build_thematic($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  945. {
  946. $table_thematic = Database :: get_course_table(TABLE_THEMATIC);
  947. $table_thematic_advance = Database :: get_course_table(TABLE_THEMATIC_ADVANCE);
  948. $table_thematic_plan = Database :: get_course_table(TABLE_THEMATIC_PLAN);
  949. $session_id = intval($session_id);
  950. if ($with_base_content) {
  951. $session_condition = api_get_session_condition($session_id, true, true);
  952. } else {
  953. $session_condition = api_get_session_condition($session_id, true);
  954. }
  955. $course_id = api_get_course_int_id();
  956. $courseInfo = api_get_course_info();
  957. $sql = "SELECT * FROM $table_thematic WHERE c_id = $course_id $session_condition ";
  958. $db_result = Database::query($sql);
  959. while ($row = Database::fetch_array($db_result,'ASSOC')) {
  960. $thematic = new Thematic($courseInfo);
  961. $sql = 'SELECT * FROM '.$table_thematic_advance.' WHERE c_id = '.$course_id.' AND thematic_id = '.$row['id'];
  962. $result = Database::query($sql);
  963. while ($sub_row = Database::fetch_array($result,'ASSOC')) {
  964. $thematic->add_thematic_advance($sub_row);
  965. }
  966. $items = api_get_item_property_by_tool('thematic_plan', api_get_course_id(), $session_id);
  967. //$items_from_session = api_get_item_property_by_tool('thematic_plan', api_get_course_id(), api_get_session_id());
  968. $thematic_plan_id_list = array();
  969. if (!empty($items)) {
  970. foreach($items as $item) {
  971. $thematic_plan_id_list[] = $item['ref'];
  972. //$thematic_plan_complete_list[$item['ref']] = $item;
  973. }
  974. }
  975. if (count($thematic_plan_id_list) > 0) {
  976. $sql = "SELECT tp.*
  977. FROM $table_thematic_plan tp
  978. INNER JOIN $table_thematic t ON (t.id=tp.thematic_id)
  979. WHERE
  980. t.c_id = $course_id AND
  981. tp.c_id = $course_id AND
  982. thematic_id = {$row['id']} AND
  983. tp.id IN (".implode(', ', $thematic_plan_id_list).") ";
  984. $result = Database::query($sql);
  985. while ($sub_row = Database::fetch_array($result,'ASSOC')) {
  986. $thematic->add_thematic_plan($sub_row);
  987. }
  988. }
  989. $this->course->add_resource($thematic);
  990. }
  991. }
  992. /**
  993. * Build the attendances
  994. */
  995. public function build_attendance($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  996. {
  997. $table_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
  998. $table_attendance_calendar = Database :: get_course_table(TABLE_ATTENDANCE_CALENDAR);
  999. $course_id = api_get_course_int_id();
  1000. $sql = 'SELECT * FROM '.$table_attendance.' WHERE c_id = '.$course_id.' AND session_id = 0 ';
  1001. $db_result = Database::query($sql);
  1002. while ($row = Database::fetch_array($db_result,'ASSOC')) {
  1003. $obj = new CourseCopyAttendance($row);
  1004. $sql = 'SELECT * FROM '.$table_attendance_calendar.' WHERE c_id = '.$course_id.' AND attendance_id = '.$row['id'];
  1005. $result = Database::query($sql);
  1006. while ($sub_row = Database::fetch_array($result,'ASSOC')) {
  1007. $obj->add_attendance_calendar($sub_row);
  1008. }
  1009. $this->course->add_resource($obj);
  1010. }
  1011. }
  1012. /**
  1013. * Build the works (or "student publications", or "assignments")
  1014. */
  1015. public function build_works($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  1016. {
  1017. $table_work = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  1018. //$table_work_assignment = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
  1019. $course_id = api_get_course_int_id();
  1020. $sql = 'SELECT * FROM '.$table_work.'
  1021. WHERE
  1022. c_id = '.$course_id.' AND
  1023. session_id = 0 AND
  1024. filetype = \'folder\' AND
  1025. parent_id = 0 AND
  1026. active = 1';
  1027. $db_result = Database::query($sql);
  1028. while ($row = Database::fetch_array($db_result,'ASSOC')) {
  1029. $obj = new Work($row);
  1030. $this->course->add_resource($obj);
  1031. }
  1032. }
  1033. }