CourseBuilder.class.php 49 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. $this->course->db_name = $_course['dbName'];
  78. $this->course->info = $_course;
  79. }
  80. /**
  81. *
  82. * @param array $array
  83. */
  84. public function set_tools_to_build($array)
  85. {
  86. $this->tools_to_build = $array;
  87. }
  88. /**
  89. *
  90. * @param array $array
  91. */
  92. public function set_tools_specific_id_list($array)
  93. {
  94. $this->specific_id_list = $array;
  95. }
  96. /**
  97. * Get the created course
  98. * @return course The course
  99. */
  100. public function get_course()
  101. {
  102. return $this->course;
  103. }
  104. /**
  105. * Build the course-object
  106. *
  107. * @param int session_id
  108. * @param string course_code
  109. * @param bool true if you want to get the elements that exists in the course and
  110. * in the session, (session_id = 0 or session_id = X)
  111. */
  112. public function build($session_id = 0, $course_code = '', $with_base_content = false)
  113. {
  114. $table_link = Database :: get_course_table(TABLE_LINKED_RESOURCES);
  115. $table_properties = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  116. $course_info = api_get_course_info($course_code);
  117. $course_id = $course_info['real_id'];
  118. foreach ($this->tools_to_build as $tool) {
  119. $function_build = 'build_'.$tool;
  120. $specificIdList = isset($this->specific_id_list[$tool]) ? $this->specific_id_list[$tool] : null;
  121. $this->$function_build(
  122. $session_id,
  123. $course_code,
  124. $with_base_content,
  125. $specificIdList
  126. );
  127. }
  128. //TABLE_LINKED_RESOURCES is the "resource" course table, which is deprecated, apparently
  129. foreach ($this->course->resources as $type => $resources) {
  130. foreach ($resources as $id => $resource) {
  131. $sql = "SELECT * FROM $table_link
  132. WHERE
  133. c_id = $course_id AND
  134. source_type = '".$resource->get_type()."' AND
  135. source_id = '".$resource->get_id()."'";
  136. $res = Database::query($sql);
  137. while ($link = Database::fetch_object($res)) {
  138. $this->course->resources[$type][$id]->add_linked_resource($link->resource_type, $link->resource_id);
  139. }
  140. }
  141. }
  142. // Once we've built the resources array a bit more, try to get items
  143. // from the item_property table and order them in the "resources" array
  144. foreach ($this->course->resources as $type => $resources) {
  145. foreach ($resources as $id => $resource) {
  146. $tool = $resource->get_tool();
  147. if ($tool != null) {
  148. $sql = "SELECT * FROM $table_properties
  149. WHERE
  150. c_id = $course_id AND
  151. tool = '".$tool."' AND
  152. ref='".$resource->get_id()."'";
  153. $res = Database::query($sql);
  154. $all_properties = array ();
  155. while ($item_property = Database::fetch_array($res)) {
  156. $all_properties[]= $item_property;
  157. }
  158. $this->course->resources[$type][$id]->item_properties = $all_properties;
  159. }
  160. }
  161. }
  162. return $this->course;
  163. }
  164. /**
  165. * Build the documents
  166. * @param int $session_id
  167. * @param string $course_code
  168. * @param bool $with_base_content
  169. * @param array $id_list
  170. */
  171. public function build_documents($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  172. {
  173. $course_info = api_get_course_info($course_code);
  174. $course_id = $course_info['real_id'];
  175. $table_doc = Database::get_course_table(TABLE_DOCUMENT);
  176. $table_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
  177. //Remove chat_files and shared_folder files
  178. $avoid_paths = " path NOT LIKE '/shared_folder%' AND
  179. path NOT LIKE '/chat_files%' ";
  180. //$avoid_paths = " 1 = 1 ";
  181. if (!empty($course_code) && !empty($session_id)) {
  182. $session_id = intval($session_id);
  183. if ($with_base_content) {
  184. $session_condition = api_get_session_condition($session_id, true, true);
  185. } else {
  186. $session_condition = api_get_session_condition($session_id, true);
  187. }
  188. if (!empty($this->course->type) && $this->course->type == 'partial') {
  189. $sql = "SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size
  190. FROM $table_doc d INNER JOIN $table_prop p
  191. ON (p.ref = d.id AND d.c_id = p.c_id)
  192. WHERE
  193. d.c_id = $course_id AND
  194. p.c_id = $course_id AND
  195. tool = '".TOOL_DOCUMENT."' AND
  196. p.visibility != 2 AND
  197. path NOT LIKE '/images/gallery%' AND
  198. $avoid_paths
  199. $session_condition
  200. ORDER BY path";
  201. } else {
  202. $sql = "SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size
  203. FROM $table_doc d INNER JOIN $table_prop p
  204. ON (p.ref = d.id AND d.c_id = p.c_id)
  205. WHERE
  206. d.c_id = $course_id AND
  207. p.c_id = $course_id AND
  208. tool = '".TOOL_DOCUMENT."' AND
  209. $avoid_paths AND
  210. p.visibility != 2 $session_condition
  211. ORDER BY path";
  212. }
  213. $db_result = Database::query($sql);
  214. while ($obj = Database::fetch_object($db_result)) {
  215. $doc = new Document($obj->id, $obj->path, $obj->comment, $obj->title, $obj->filetype, $obj->size);
  216. $this->course->add_resource($doc);
  217. }
  218. } else {
  219. if (!empty($this->course->type) && $this->course->type=='partial') {
  220. $sql = "SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size
  221. FROM $table_doc d INNER JOIN $table_prop p
  222. ON (p.ref = d.id AND d.c_id = p.c_id)
  223. WHERE
  224. d.c_id = $course_id AND
  225. p.c_id = $course_id AND
  226. tool = '".TOOL_DOCUMENT."' AND
  227. p.visibility != 2 AND
  228. path NOT LIKE '/images/gallery%' AND
  229. $avoid_paths AND
  230. d.session_id = 0
  231. ORDER BY path";
  232. } else {
  233. $sql = "SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size
  234. FROM $table_doc d INNER JOIN $table_prop p
  235. ON (p.ref = d.id AND d.c_id = p.c_id)
  236. WHERE
  237. d.c_id = $course_id AND
  238. p.c_id = $course_id AND
  239. tool = '".TOOL_DOCUMENT."' AND
  240. p.visibility != 2 AND
  241. $avoid_paths AND
  242. d.session_id = 0
  243. ORDER BY path";
  244. }
  245. $db_result = Database::query($sql);
  246. while ($obj = Database::fetch_object($db_result)) {
  247. $doc = new Document(
  248. $obj->id, $obj->path, $obj->comment, $obj->title, $obj->filetype, $obj->size
  249. );
  250. $this->course->add_resource($doc);
  251. }
  252. }
  253. }
  254. /**
  255. * Build the forums
  256. */
  257. public function build_forums($session_id = 0, $course_code = null, $with_base_content = false, $id_list = array())
  258. {
  259. $course_info = api_get_course_info($course_code);
  260. $course_id = $course_info['real_id'];
  261. $table = Database :: get_course_table(TABLE_FORUM);
  262. $sql = "SELECT * FROM $table WHERE c_id = $course_id ";
  263. $sql .= " ORDER BY forum_title, forum_category";
  264. $db_result = Database::query($sql);
  265. while ($obj = Database::fetch_object($db_result)) {
  266. $forum = new Forum($obj);
  267. $this->course->add_resource($forum);
  268. }
  269. }
  270. /**
  271. * Build a forum-category
  272. */
  273. public function build_forum_category($session_id = 0, $course_code = null, $with_base_content = false, $id_list = array())
  274. {
  275. $table = Database :: get_course_table(TABLE_FORUM_CATEGORY);
  276. $course_info = api_get_course_info($course_code);
  277. $course_id = $course_info['real_id'];
  278. $sql = "SELECT * FROM $table WHERE c_id = $course_id ORDER BY cat_title";
  279. $db_result = Database::query($sql);
  280. while ($obj = Database::fetch_object($db_result)) {
  281. $forum_category = new ForumCategory($obj);
  282. $this->course->add_resource($forum_category);
  283. }
  284. }
  285. /**
  286. * Build the forum-topics
  287. */
  288. public function build_forum_topics($session_id = 0, $course_code = null, $with_base_content = false, $id_list = array())
  289. {
  290. $table = Database :: get_course_table(TABLE_FORUM_THREAD);
  291. $course_info = api_get_course_info($course_code);
  292. $course_id = $course_info['real_id'];
  293. $sql = "SELECT * FROM $table WHERE c_id = $course_id
  294. ORDER BY thread_title ";
  295. $db_result = Database::query($sql);
  296. while ($obj = Database::fetch_object($db_result)) {
  297. $forum_topic = new ForumTopic($obj);
  298. $this->course->add_resource($forum_topic);
  299. $this->build_forum_posts($obj->thread_id, $obj->forum_id, true);
  300. }
  301. }
  302. /**
  303. * Build the forum-posts
  304. * TODO: All tree structure of posts should be built, attachments for example.
  305. */
  306. public function build_forum_posts($thread_id = null, $forum_id = null, $only_first_post = false)
  307. {
  308. $table = Database :: get_course_table(TABLE_FORUM_POST);
  309. $course_id = api_get_course_int_id();
  310. $sql = "SELECT * FROM $table WHERE c_id = $course_id ";
  311. if (!empty($thread_id) && !empty($forum_id)) {
  312. $forum_id = intval($forum_id);
  313. $thread_id = intval($thread_id);
  314. $sql .= " AND thread_id = $thread_id AND forum_id = $forum_id ";
  315. }
  316. $sql .= " ORDER BY post_id ASC LIMIT 1";
  317. $db_result = Database::query($sql);
  318. while ($obj = Database::fetch_object($db_result)) {
  319. $forum_post = new ForumPost($obj);
  320. $this->course->add_resource($forum_post);
  321. }
  322. }
  323. /**
  324. * Build the links
  325. */
  326. public function build_links($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  327. {
  328. $course_info = api_get_course_info($course_code);
  329. $course_id = $course_info['real_id'];
  330. $table = Database :: get_course_table(TABLE_LINK);
  331. $table_prop = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  332. if (!empty($session_id) && !empty($course_code)) {
  333. $session_id = intval($session_id);
  334. if ($with_base_content) {
  335. $session_condition = api_get_session_condition($session_id, true, true);
  336. } else {
  337. $session_condition = api_get_session_condition($session_id, true);
  338. }
  339. $sql = "SELECT l.id, l.title, l.url, l.description, l.category_id, l.on_homepage
  340. FROM $table l, $table_prop p
  341. 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
  342. ORDER BY l.display_order";
  343. } else {
  344. $sql = "SELECT l.id, l.title, l.url, l.description, l.category_id, l.on_homepage
  345. FROM $table l, $table_prop p
  346. 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
  347. ORDER BY l.display_order";
  348. }
  349. $db_result = Database::query($sql);
  350. while ($obj = Database::fetch_object($db_result)) {
  351. $link = new Link($obj->id, $obj->title, $obj->url, $obj->description, $obj->category_id, $obj->on_homepage);
  352. $this->course->add_resource($link);
  353. if (!empty($course_code)) {
  354. $res = $this->build_link_category($obj->category_id,$course_code);
  355. } else {
  356. $res = $this->build_link_category($obj->category_id);
  357. }
  358. if($res > 0) {
  359. $this->course->resources[RESOURCE_LINK][$obj->id]->add_linked_resource(RESOURCE_LINKCATEGORY, $obj->category_id);
  360. }
  361. }
  362. }
  363. /**
  364. * Build tool intro
  365. */
  366. public function build_tool_intro($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  367. {
  368. $table = Database :: get_course_table(TABLE_TOOL_INTRO);
  369. $course_id = api_get_course_int_id();
  370. $sql = "SELECT * FROM $table WHERE c_id = $course_id ";
  371. $db_result = Database::query($sql);
  372. while ($obj = Database::fetch_object($db_result)) {
  373. $tool_intro = new ToolIntro($obj->id, $obj->intro_text);
  374. $this->course->add_resource($tool_intro);
  375. }
  376. }
  377. /**
  378. * Build a link category
  379. */
  380. public function build_link_category($id, $course_code = '')
  381. {
  382. $course_info = api_get_course_info($course_code);
  383. $course_id = $course_info['real_id'];
  384. $link_cat_table = Database :: get_course_table(TABLE_LINK_CATEGORY);
  385. $sql = "SELECT * FROM $link_cat_table WHERE c_id = $course_id AND id = $id";
  386. $db_result = Database::query($sql);
  387. while ($obj = Database::fetch_object($db_result)) {
  388. $link_category = new LinkCategory($obj->id, $obj->category_title, $obj->description, $obj->display_order);
  389. $this->course->add_resource($link_category);
  390. return $id;
  391. }
  392. return 0;
  393. }
  394. /**
  395. * Build the Quizzes
  396. */
  397. public function build_quizzes($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  398. {
  399. $course_info = api_get_course_info($course_code);
  400. $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
  401. $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
  402. $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
  403. $course_id = $course_info['real_id'];
  404. if (!empty($course_code) && !empty($session_id)) {
  405. $session_id = intval($session_id);
  406. if ($with_base_content) {
  407. $session_condition = api_get_session_condition($session_id, true, true);
  408. } else {
  409. $session_condition = api_get_session_condition($session_id, true);
  410. }
  411. $sql = "SELECT * FROM $table_qui WHERE c_id = $course_id AND active >=0 $session_condition";
  412. //select only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes)
  413. } else {
  414. $sql = "SELECT * FROM $table_qui WHERE c_id = $course_id AND active >=0 AND session_id = 0";
  415. //select only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes)
  416. }
  417. $db_result = Database::query($sql);
  418. while ($obj = Database::fetch_object($db_result)) {
  419. if (strlen($obj->sound) > 0) {
  420. $sql = "SELECT id FROM $table_doc WHERE c_id = $course_id AND path = '/audio/".$obj->sound."'";
  421. $res = Database::query($sql);
  422. $doc = Database::fetch_object($res);
  423. $obj->sound = $doc->id;
  424. }
  425. $quiz = new Quiz($obj);
  426. $sql = 'SELECT * FROM '.$table_rel.' WHERE c_id = '.$course_id.' AND exercice_id = '.$obj->id;
  427. $db_result2 = Database::query($sql);
  428. while ($obj2 = Database::fetch_object($db_result2)) {
  429. $quiz->add_question($obj2->question_id, $obj2->question_order);
  430. }
  431. $this->course->add_resource($quiz);
  432. }
  433. if (!empty($course_code)) {
  434. $this->build_quiz_questions($course_code);
  435. } else {
  436. $this->build_quiz_questions();
  437. }
  438. }
  439. /**
  440. * Build the Quiz-Questions
  441. */
  442. public function build_quiz_questions($course_code = null)
  443. {
  444. $course_info = api_get_course_info($course_code);
  445. $course_id = $course_info['real_id'];
  446. $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
  447. $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
  448. $table_que = Database :: get_course_table(TABLE_QUIZ_QUESTION);
  449. $table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
  450. // Building normal tests.
  451. $sql = "SELECT * FROM $table_que WHERE c_id = $course_id ";
  452. $db_result = Database::query($sql);
  453. while ($obj = Database::fetch_object($db_result)) {
  454. // find the question category
  455. // @todo : need to be adapted for multi category questions in 1.10
  456. $question_category_id = Testcategory::getCategoryForQuestion($obj->id, $course_id);
  457. // build the backup resource question object
  458. $question = new QuizQuestion(
  459. $obj->id,
  460. $obj->question,
  461. $obj->description,
  462. $obj->ponderation,
  463. $obj->type,
  464. $obj->position,
  465. $obj->picture,
  466. $obj->level,
  467. $obj->extra,
  468. $question_category_id
  469. );
  470. $sql = 'SELECT * FROM '.$table_ans.' WHERE c_id = '.$course_id.' AND question_id = '.$obj->id;
  471. $db_result2 = Database::query($sql);
  472. while ($obj2 = Database::fetch_object($db_result2)) {
  473. $question->add_answer(
  474. $obj2->id,
  475. $obj2->answer,
  476. $obj2->correct,
  477. $obj2->comment,
  478. $obj2->ponderation,
  479. $obj2->position,
  480. $obj2->hotspot_coordinates,
  481. $obj2->hotspot_type
  482. );
  483. if ($obj->type == MULTIPLE_ANSWER_TRUE_FALSE) {
  484. $table_options = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
  485. $sql = 'SELECT * FROM '.$table_options.' WHERE c_id = '.$course_id.' AND question_id = '.$obj->id;
  486. $db_result3 = Database::query($sql);
  487. while ($obj3 = Database::fetch_object($db_result3)) {
  488. $question_option = new QuizQuestionOption($obj3);
  489. $question->add_option($question_option);
  490. }
  491. }
  492. }
  493. $this->course->add_resource($question);
  494. }
  495. // Building a fictional test for collecting orphan questions.
  496. // When a course is emptied this option should be activated (true).
  497. $build_orphan_questions = !empty($_POST['recycle_option']);
  498. // 1st union gets the orphan questions from deleted exercises
  499. // 2nd union gets the orphan questions from question that were deleted in a exercise.
  500. $sql = " (
  501. SELECT question_id, q.* FROM $table_que q INNER JOIN $table_rel r
  502. ON (q.c_id = r.c_id AND q.id = r.question_id)
  503. INNER JOIN $table_qui ex
  504. ON (ex.id = r.exercice_id AND ex.c_id = r.c_id )
  505. WHERE ex.c_id = $course_id AND ex.active = '-1'
  506. )
  507. UNION
  508. (
  509. SELECT question_id, q.* FROM $table_que q left
  510. OUTER JOIN $table_rel r
  511. ON (q.c_id = r.c_id AND q.id = r.question_id)
  512. WHERE q.c_id = $course_id AND r.question_id is null
  513. )
  514. UNION
  515. (
  516. SELECT question_id, q.* FROM $table_que q
  517. INNER JOIN $table_rel r
  518. ON (q.c_id = r.c_id AND q.id = r.question_id)
  519. WHERE r.c_id = $course_id AND (r.exercice_id = '-1' OR r.exercice_id = '0')
  520. )
  521. ";
  522. $db_result = Database::query($sql);
  523. if (Database::num_rows($db_result) > 0) {
  524. $build_orphan_questions = true;
  525. $orphanQuestionIds = array();
  526. while ($obj = Database::fetch_object($db_result)) {
  527. // Orphan questions
  528. if (!empty($obj->question_id)) {
  529. $obj->id = $obj->question_id;
  530. }
  531. // Avoid adding the same question twice
  532. if (!isset($this->course->resources[$obj->id])) {
  533. // find the question category
  534. // @todo : need to be adapted for multi category questions in 1.10
  535. $question_category_id = Testcategory::getCategoryForQuestion($obj->id, $course_id);
  536. $question = new QuizQuestion(
  537. $obj->id,
  538. $obj->question,
  539. $obj->description,
  540. $obj->ponderation,
  541. $obj->type,
  542. $obj->position,
  543. $obj->picture,
  544. $obj->level,
  545. $obj->extra,
  546. $question_category_id
  547. );
  548. $sql = "SELECT * FROM $table_ans WHERE c_id = $course_id AND question_id = ".$obj->id;
  549. $db_result2 = Database::query($sql);
  550. if (Database::num_rows($db_result2)) {
  551. while ($obj2 = Database::fetch_object($db_result2)) {
  552. $question->add_answer(
  553. $obj2->id,
  554. $obj2->answer,
  555. $obj2->correct,
  556. $obj2->comment,
  557. $obj2->ponderation,
  558. $obj2->position,
  559. $obj2->hotspot_coordinates,
  560. $obj2->hotspot_type
  561. );
  562. }
  563. $orphanQuestionIds[] = $obj->id;
  564. }
  565. $this->course->add_resource($question);
  566. }
  567. }
  568. }
  569. if ($build_orphan_questions) {
  570. $obj = array(
  571. 'id' => -1,
  572. 'title' => get_lang('OrphanQuestions', ''),
  573. 'type' => 2
  574. );
  575. $newQuiz = new Quiz((object)$obj);
  576. if (!empty($orphanQuestionIds)) {
  577. foreach ($orphanQuestionIds as $index => $orphanId) {
  578. $order = $index + 1;
  579. $newQuiz->add_question($orphanId, $order);
  580. }
  581. }
  582. $this->course->add_resource($newQuiz);
  583. }
  584. }
  585. /**
  586. * Build the orphan questions
  587. */
  588. public function build_quiz_orphan_questions()
  589. {
  590. $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
  591. $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
  592. $table_que = Database :: get_course_table(TABLE_QUIZ_QUESTION);
  593. $table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
  594. $course_id = api_get_course_int_id();
  595. $sql = 'SELECT *
  596. FROM '.$table_que.' as questions
  597. LEFT JOIN '.$table_rel.' as quizz_questions
  598. ON questions.id=quizz_questions.question_id
  599. LEFT JOIN '.$table_qui.' as exercises
  600. ON quizz_questions.exercice_id = exercises.id
  601. WHERE questions.c_id = quizz_questions.c_id AND
  602. questions.c_id = exercises.c_id AND
  603. exercises.c_id = '.$course_id.' AND
  604. (quizz_questions.exercice_id IS NULL OR
  605. exercises.active = -1)';
  606. $db_result = Database::query($sql);
  607. if (Database::num_rows($db_result) > 0) {
  608. // This is the fictional test for collecting orphan questions.
  609. $orphan_questions = new Quiz(-1, get_lang('OrphanQuestions', ''), '', 0, 0, 1, '', 0);
  610. $this->course->add_resource($orphan_questions);
  611. while ($obj = Database::fetch_object($db_result)) {
  612. $question = new QuizQuestion(
  613. $obj->id,
  614. $obj->question,
  615. $obj->description,
  616. $obj->ponderation,
  617. $obj->type,
  618. $obj->position,
  619. $obj->picture,
  620. $obj->level,
  621. $obj->extra
  622. );
  623. $sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.$obj->id;
  624. $db_result2 = Database::query($sql);
  625. while ($obj2 = Database::fetch_object($db_result2)) {
  626. $question->add_answer(
  627. $obj2->id,
  628. $obj2->answer,
  629. $obj2->correct,
  630. $obj2->comment,
  631. $obj2->ponderation,
  632. $obj2->position,
  633. $obj2->hotspot_coordinates,
  634. $obj2->hotspot_type
  635. );
  636. }
  637. $this->course->add_resource($question);
  638. }
  639. }
  640. }
  641. /**
  642. * Build the test category
  643. * $session_id, $course_code, $with_base_content, $this->specific_id_list[$tool]
  644. * @todo add course session
  645. */
  646. public function build_test_category($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  647. {
  648. $course_id = api_get_course_int_id();
  649. // get all test category in course
  650. $tab_test_categories_id = Testcategory::getCategoryListInfo("id", $course_id);
  651. foreach ($tab_test_categories_id as $test_category_id)
  652. {
  653. $test_category = new Testcategory($test_category_id);
  654. $copy_course_test_category = new CourseCopyTestcategory($test_category_id, $test_category->name, $test_category->description);
  655. $this->course->add_resource($copy_course_test_category);
  656. }
  657. }
  658. /**
  659. * Build the Surveys
  660. */
  661. public function build_surveys($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  662. {
  663. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  664. $table_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  665. $course_id = api_get_course_int_id();
  666. $sql = 'SELECT * FROM '.$table_survey.' WHERE c_id = '.$course_id.' AND session_id = 0 ';
  667. $db_result = Database::query($sql);
  668. while ($obj = Database::fetch_object($db_result)) {
  669. $survey = new Survey($obj->survey_id, $obj->code,$obj->title,
  670. $obj->subtitle, $obj->author, $obj->lang,
  671. $obj->avail_from, $obj->avail_till, $obj->is_shared,
  672. $obj->template, $obj->intro, $obj->surveythanks,
  673. $obj->creation_date, $obj->invited, $obj->answered,
  674. $obj->invite_mail, $obj->reminder_mail);
  675. $sql = 'SELECT * FROM '.$table_question.' WHERE c_id = '.$course_id.' AND survey_id = '.$obj->survey_id;
  676. $db_result2 = Database::query($sql);
  677. while ($obj2 = Database::fetch_object($db_result2)){
  678. $survey->add_question($obj2->question_id);
  679. }
  680. $this->course->add_resource($survey);
  681. }
  682. $this->build_survey_questions();
  683. }
  684. /**
  685. * Build the Survey Questions
  686. */
  687. public function build_survey_questions() {
  688. $table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  689. $table_opt = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
  690. $course_id = api_get_course_int_id();
  691. $sql = 'SELECT * FROM '.$table_que.' WHERE c_id = '.$course_id.' ';
  692. $db_result = Database::query($sql);
  693. while ($obj = Database::fetch_object($db_result)){
  694. $question = new SurveyQuestion(
  695. $obj->question_id,
  696. $obj->survey_id,
  697. $obj->survey_question,
  698. $obj->survey_question_comment,
  699. $obj->type,
  700. $obj->display,
  701. $obj->sort,
  702. $obj->shared_question_id,
  703. $obj->max_value
  704. );
  705. $sql = 'SELECT * FROM '.$table_opt.' WHERE c_id = '.$course_id.' AND question_id = '.$obj->question_id;
  706. $db_result2 = Database::query($sql);
  707. while ($obj2 = Database::fetch_object($db_result2)) {
  708. $question->add_answer($obj2->option_text, $obj2->sort);
  709. }
  710. $this->course->add_resource($question);
  711. }
  712. }
  713. /**
  714. * Build the announcements
  715. */
  716. public function build_announcements($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  717. {
  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. if (count($thematic_plan_id_list) > 0) {
  1033. $sql = "SELECT tp.*
  1034. FROM $table_thematic_plan tp
  1035. INNER JOIN $table_thematic t ON (t.id=tp.thematic_id)
  1036. WHERE
  1037. t.c_id = $course_id AND
  1038. tp.c_id = $course_id AND
  1039. thematic_id = {$row['id']} AND
  1040. tp.id IN (".implode(', ', $thematic_plan_id_list).") ";
  1041. $result = Database::query($sql);
  1042. while ($sub_row = Database::fetch_array($result,'ASSOC')) {
  1043. $thematic->add_thematic_plan($sub_row);
  1044. }
  1045. }
  1046. $this->course->add_resource($thematic);
  1047. }
  1048. }
  1049. /**
  1050. * Build the attendances
  1051. */
  1052. public function build_attendance($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  1053. {
  1054. $table_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
  1055. $table_attendance_calendar = Database :: get_course_table(TABLE_ATTENDANCE_CALENDAR);
  1056. $course_id = api_get_course_int_id();
  1057. $sql = 'SELECT * FROM '.$table_attendance.' WHERE c_id = '.$course_id.' AND session_id = 0 ';
  1058. $db_result = Database::query($sql);
  1059. while ($row = Database::fetch_array($db_result,'ASSOC')) {
  1060. $obj = new Attendance($row);
  1061. $sql = 'SELECT * FROM '.$table_attendance_calendar.' WHERE c_id = '.$course_id.' AND attendance_id = '.$row['id'];
  1062. $result = Database::query($sql);
  1063. while ($sub_row = Database::fetch_array($result,'ASSOC')) {
  1064. $obj->add_attendance_calendar($sub_row);
  1065. }
  1066. $this->course->add_resource($obj);
  1067. }
  1068. }
  1069. /**
  1070. * Build the works (or "student publications", or "assignments")
  1071. */
  1072. public function build_works($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  1073. {
  1074. $table_work = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  1075. //$table_work_assignment = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
  1076. $course_id = api_get_course_int_id();
  1077. $sql = 'SELECT * FROM '.$table_work.'
  1078. WHERE
  1079. c_id = '.$course_id.' AND
  1080. session_id = 0 AND
  1081. filetype = \'folder\' AND
  1082. parent_id = 0 AND
  1083. active = 1';
  1084. $db_result = Database::query($sql);
  1085. while ($row = Database::fetch_array($db_result,'ASSOC')) {
  1086. $obj = new Work($row);
  1087. $this->course->add_resource($obj);
  1088. }
  1089. }
  1090. }