CourseBuilder.class.php 50 KB

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