CourseBuilder.class.php 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once 'Course.class.php';
  4. require_once 'Event.class.php';
  5. require_once 'Link.class.php';
  6. require_once 'ToolIntro.class.php';
  7. require_once 'Document.class.php';
  8. require_once 'ScormDocument.class.php';
  9. require_once 'LinkCategory.class.php';
  10. require_once 'CourseDescription.class.php';
  11. require_once 'ForumPost.class.php';
  12. require_once 'ForumTopic.class.php';
  13. require_once 'Forum.class.php';
  14. require_once 'ForumCategory.class.php';
  15. require_once 'Quiz.class.php';
  16. require_once 'QuizQuestion.class.php';
  17. require_once 'CourseCopyTestCategory.php';
  18. require_once 'CourseCopyLearnpath.class.php';
  19. require_once 'Survey.class.php';
  20. require_once 'SurveyQuestion.class.php';
  21. require_once 'Glossary.class.php';
  22. require_once 'CourseSession.class.php';
  23. require_once 'wiki.class.php';
  24. require_once 'Thematic.class.php';
  25. require_once 'Attendance.class.php';
  26. require_once 'Work.class.php';
  27. /**
  28. * Class CourseBuilder
  29. * Builds 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. /** @var 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. * @param string $type
  65. * @param null $course
  66. */
  67. public function __construct($type='', $course = null)
  68. {
  69. $_course = api_get_course_info();
  70. if (!empty($course['official_code'])){
  71. $_course = $course;
  72. }
  73. $this->course = new Course();
  74. $this->course->code = $_course['official_code'];
  75. $this->course->type = $type;
  76. $this->course->path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/';
  77. $this->course->backup_path = api_get_path(SYS_COURSE_PATH).$_course['path'];
  78. $this->course->encoding = api_get_system_encoding(); //current platform encoding
  79. $this->course->db_name = $_course['dbName'];
  80. $this->course->info = $_course;
  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. $sessionCodition = api_get_session_condition($session_id, true, $with_base_content);
  264. $sql = "SELECT * FROM $table WHERE c_id = $course_id $sessionCodition";
  265. $sql .= " ORDER BY forum_title, forum_category";
  266. $db_result = Database::query($sql);
  267. while ($obj = Database::fetch_object($db_result)) {
  268. $forum = new Forum($obj);
  269. $this->course->add_resource($forum);
  270. }
  271. }
  272. /**
  273. * Build a forum-category
  274. */
  275. public function build_forum_category($session_id = 0, $course_code = null, $with_base_content = false, $id_list = array())
  276. {
  277. $table = Database :: get_course_table(TABLE_FORUM_CATEGORY);
  278. $course_info = api_get_course_info($course_code);
  279. $course_id = $course_info['real_id'];
  280. $sessionCodition = api_get_session_condition($session_id, true, $with_base_content);
  281. $sql = "SELECT * FROM $table WHERE c_id = $course_id $sessionCodition ORDER BY cat_title";
  282. $db_result = Database::query($sql);
  283. while ($obj = Database::fetch_object($db_result)) {
  284. $forum_category = new ForumCategory($obj);
  285. $this->course->add_resource($forum_category);
  286. }
  287. }
  288. /**
  289. * Build the forum-topics
  290. */
  291. public function build_forum_topics($session_id = 0, $course_code = null, $with_base_content = false, $id_list = array())
  292. {
  293. $table = Database :: get_course_table(TABLE_FORUM_THREAD);
  294. $course_info = api_get_course_info($course_code);
  295. $course_id = $course_info['real_id'];
  296. $sessionCodition = api_get_session_condition($session_id, true, $with_base_content);
  297. $sql = "SELECT * FROM $table WHERE c_id = $course_id
  298. $sessionCodition
  299. ORDER BY thread_title ";
  300. $db_result = Database::query($sql);
  301. while ($obj = Database::fetch_object($db_result)) {
  302. $forum_topic = new ForumTopic($obj);
  303. $this->course->add_resource($forum_topic);
  304. $this->build_forum_posts($obj->thread_id, $obj->forum_id, true);
  305. }
  306. }
  307. /**
  308. * Build the forum-posts
  309. * TODO: All tree structure of posts should be built, attachments for example.
  310. */
  311. public function build_forum_posts($thread_id = null, $forum_id = null, $only_first_post = false)
  312. {
  313. $table = Database :: get_course_table(TABLE_FORUM_POST);
  314. $course_id = api_get_course_int_id();
  315. $sql = "SELECT * FROM $table WHERE c_id = $course_id ";
  316. if (!empty($thread_id) && !empty($forum_id)) {
  317. $forum_id = intval($forum_id);
  318. $thread_id = intval($thread_id);
  319. $sql .= " AND thread_id = $thread_id AND forum_id = $forum_id ";
  320. }
  321. $sql .= " ORDER BY post_id ASC LIMIT 1";
  322. $db_result = Database::query($sql);
  323. while ($obj = Database::fetch_object($db_result)) {
  324. $forum_post = new ForumPost($obj);
  325. $this->course->add_resource($forum_post);
  326. }
  327. }
  328. /**
  329. * Build the links
  330. */
  331. public function build_links($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  332. {
  333. $course_info = api_get_course_info($course_code);
  334. $course_id = $course_info['real_id'];
  335. $table = Database :: get_course_table(TABLE_LINK);
  336. $table_prop = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  337. if (!empty($session_id) && !empty($course_code)) {
  338. $session_id = intval($session_id);
  339. if ($with_base_content) {
  340. $session_condition = api_get_session_condition($session_id, true, true);
  341. } else {
  342. $session_condition = api_get_session_condition($session_id, true);
  343. }
  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 $session_condition
  347. ORDER BY l.display_order";
  348. } else {
  349. $sql = "SELECT l.id, l.title, l.url, l.description, l.category_id, l.on_homepage
  350. FROM $table l, $table_prop p
  351. 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
  352. ORDER BY l.display_order";
  353. }
  354. $db_result = Database::query($sql);
  355. while ($obj = Database::fetch_object($db_result)) {
  356. $link = new Link($obj->id, $obj->title, $obj->url, $obj->description, $obj->category_id, $obj->on_homepage);
  357. $this->course->add_resource($link);
  358. if (!empty($course_code)) {
  359. $res = $this->build_link_category($obj->category_id,$course_code);
  360. } else {
  361. $res = $this->build_link_category($obj->category_id);
  362. }
  363. if($res > 0) {
  364. $this->course->resources[RESOURCE_LINK][$obj->id]->add_linked_resource(RESOURCE_LINKCATEGORY, $obj->category_id);
  365. }
  366. }
  367. }
  368. /**
  369. * Build tool intro
  370. */
  371. public function build_tool_intro($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  372. {
  373. $table = Database :: get_course_table(TABLE_TOOL_INTRO);
  374. $course_id = api_get_course_int_id();
  375. $sessionCodition = api_get_session_condition($session_id, true, $with_base_content);
  376. $sql = "SELECT * FROM $table WHERE c_id = $course_id $sessionCodition";
  377. $db_result = Database::query($sql);
  378. while ($obj = Database::fetch_object($db_result)) {
  379. $tool_intro = new ToolIntro($obj->id, $obj->intro_text);
  380. $this->course->add_resource($tool_intro);
  381. }
  382. }
  383. /**
  384. * Build a link category
  385. */
  386. public function build_link_category($id, $course_code = '')
  387. {
  388. $course_info = api_get_course_info($course_code);
  389. $course_id = $course_info['real_id'];
  390. $link_cat_table = Database :: get_course_table(TABLE_LINK_CATEGORY);
  391. $sql = "SELECT * FROM $link_cat_table WHERE c_id = $course_id AND id = $id";
  392. $db_result = Database::query($sql);
  393. while ($obj = Database::fetch_object($db_result)) {
  394. $link_category = new LinkCategory($obj->id, $obj->category_title, $obj->description, $obj->display_order);
  395. $this->course->add_resource($link_category);
  396. return $id;
  397. }
  398. return 0;
  399. }
  400. /**
  401. * Build the Quizzes
  402. */
  403. public function build_quizzes($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  404. {
  405. $course_info = api_get_course_info($course_code);
  406. $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
  407. $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
  408. $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
  409. $course_id = $course_info['real_id'];
  410. if (!empty($course_code) && !empty($session_id)) {
  411. $session_id = intval($session_id);
  412. if ($with_base_content) {
  413. $session_condition = api_get_session_condition($session_id, true, true);
  414. } else {
  415. $session_condition = api_get_session_condition($session_id, true);
  416. }
  417. $sql = "SELECT * FROM $table_qui WHERE c_id = $course_id AND active >=0 $session_condition";
  418. //select only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes)
  419. } else {
  420. $sql = "SELECT * FROM $table_qui WHERE c_id = $course_id AND active >=0 AND session_id = 0";
  421. //select only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes)
  422. }
  423. $db_result = Database::query($sql);
  424. while ($obj = Database::fetch_object($db_result)) {
  425. if (strlen($obj->sound) > 0) {
  426. $sql = "SELECT id FROM $table_doc WHERE c_id = $course_id AND path = '/audio/".$obj->sound."'";
  427. $res = Database::query($sql);
  428. $doc = Database::fetch_object($res);
  429. $obj->sound = $doc->id;
  430. }
  431. $quiz = new Quiz($obj);
  432. $sql = 'SELECT * FROM '.$table_rel.' WHERE c_id = '.$course_id.' AND exercice_id = '.$obj->id;
  433. $db_result2 = Database::query($sql);
  434. while ($obj2 = Database::fetch_object($db_result2)) {
  435. $quiz->add_question($obj2->question_id, $obj2->question_order);
  436. }
  437. $this->course->add_resource($quiz);
  438. }
  439. if (!empty($course_code)) {
  440. $this->build_quiz_questions($course_code);
  441. } else {
  442. $this->build_quiz_questions();
  443. }
  444. }
  445. /**
  446. * Build the Quiz-Questions
  447. */
  448. public function build_quiz_questions($course_code = null)
  449. {
  450. $course_info = api_get_course_info($course_code);
  451. $course_id = $course_info['real_id'];
  452. $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
  453. $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
  454. $table_que = Database :: get_course_table(TABLE_QUIZ_QUESTION);
  455. $table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
  456. // Building normal tests.
  457. $sql = "SELECT * FROM $table_que WHERE c_id = $course_id ";
  458. $db_result = Database::query($sql);
  459. while ($obj = Database::fetch_object($db_result)) {
  460. // find the question category
  461. // @todo : need to be adapted for multi category questions in 1.10
  462. $question_category_id = Testcategory::getCategoryForQuestion($obj->id, $course_id);
  463. // build the backup resource question object
  464. $question = new QuizQuestion(
  465. $obj->id,
  466. $obj->question,
  467. $obj->description,
  468. $obj->ponderation,
  469. $obj->type,
  470. $obj->position,
  471. $obj->picture,
  472. $obj->level,
  473. $obj->extra,
  474. $question_category_id
  475. );
  476. $sql = 'SELECT * FROM '.$table_ans.' WHERE c_id = '.$course_id.' AND question_id = '.$obj->id;
  477. $db_result2 = Database::query($sql);
  478. while ($obj2 = Database::fetch_object($db_result2)) {
  479. $question->add_answer(
  480. $obj2->id,
  481. $obj2->answer,
  482. $obj2->correct,
  483. $obj2->comment,
  484. $obj2->ponderation,
  485. $obj2->position,
  486. $obj2->hotspot_coordinates,
  487. $obj2->hotspot_type
  488. );
  489. if ($obj->type == MULTIPLE_ANSWER_TRUE_FALSE) {
  490. $table_options = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
  491. $sql = 'SELECT * FROM '.$table_options.' WHERE c_id = '.$course_id.' AND question_id = '.$obj->id;
  492. $db_result3 = Database::query($sql);
  493. while ($obj3 = Database::fetch_object($db_result3)) {
  494. $question_option = new QuizQuestionOption($obj3);
  495. $question->add_option($question_option);
  496. }
  497. }
  498. }
  499. $this->course->add_resource($question);
  500. }
  501. // Building a fictional test for collecting orphan questions.
  502. // When a course is emptied this option should be activated (true).
  503. $build_orphan_questions = !empty($_POST['recycle_option']);
  504. // 1st union gets the orphan questions from deleted exercises
  505. // 2nd union gets the orphan questions from question that were deleted in a exercise.
  506. $sql = " (
  507. SELECT question_id, q.* FROM $table_que q INNER JOIN $table_rel r
  508. ON (q.c_id = r.c_id AND q.id = r.question_id)
  509. INNER JOIN $table_qui ex
  510. ON (ex.id = r.exercice_id AND ex.c_id = r.c_id )
  511. WHERE ex.c_id = $course_id AND ex.active = '-1'
  512. )
  513. UNION
  514. (
  515. SELECT question_id, q.* FROM $table_que q left
  516. OUTER JOIN $table_rel r
  517. ON (q.c_id = r.c_id AND q.id = r.question_id)
  518. WHERE q.c_id = $course_id AND r.question_id is null
  519. )
  520. UNION
  521. (
  522. SELECT question_id, q.* FROM $table_que q
  523. INNER JOIN $table_rel r
  524. ON (q.c_id = r.c_id AND q.id = r.question_id)
  525. WHERE r.c_id = $course_id AND (r.exercice_id = '-1' OR r.exercice_id = '0')
  526. )
  527. ";
  528. $db_result = Database::query($sql);
  529. if (Database::num_rows($db_result) > 0) {
  530. $build_orphan_questions = true;
  531. $orphanQuestionIds = array();
  532. while ($obj = Database::fetch_object($db_result)) {
  533. // Orphan questions
  534. if (!empty($obj->question_id)) {
  535. $obj->id = $obj->question_id;
  536. }
  537. // Avoid adding the same question twice
  538. if (!isset($this->course->resources[$obj->id])) {
  539. // find the question category
  540. // @todo : need to be adapted for multi category questions in 1.10
  541. $question_category_id = Testcategory::getCategoryForQuestion($obj->id, $course_id);
  542. $question = new QuizQuestion(
  543. $obj->id,
  544. $obj->question,
  545. $obj->description,
  546. $obj->ponderation,
  547. $obj->type,
  548. $obj->position,
  549. $obj->picture,
  550. $obj->level,
  551. $obj->extra,
  552. $question_category_id
  553. );
  554. $sql = "SELECT * FROM $table_ans WHERE c_id = $course_id AND question_id = ".$obj->id;
  555. $db_result2 = Database::query($sql);
  556. if (Database::num_rows($db_result2)) {
  557. while ($obj2 = Database::fetch_object($db_result2)) {
  558. $question->add_answer(
  559. $obj2->id,
  560. $obj2->answer,
  561. $obj2->correct,
  562. $obj2->comment,
  563. $obj2->ponderation,
  564. $obj2->position,
  565. $obj2->hotspot_coordinates,
  566. $obj2->hotspot_type
  567. );
  568. }
  569. $orphanQuestionIds[] = $obj->id;
  570. }
  571. $this->course->add_resource($question);
  572. }
  573. }
  574. }
  575. if ($build_orphan_questions) {
  576. $obj = array(
  577. 'id' => -1,
  578. 'title' => get_lang('OrphanQuestions', ''),
  579. 'type' => 2
  580. );
  581. $newQuiz = new Quiz((object)$obj);
  582. if (!empty($orphanQuestionIds)) {
  583. foreach ($orphanQuestionIds as $index => $orphanId) {
  584. $order = $index + 1;
  585. $newQuiz->add_question($orphanId, $order);
  586. }
  587. }
  588. $this->course->add_resource($newQuiz);
  589. }
  590. }
  591. /**
  592. * Build the orphan questions
  593. */
  594. public function build_quiz_orphan_questions()
  595. {
  596. $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
  597. $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
  598. $table_que = Database :: get_course_table(TABLE_QUIZ_QUESTION);
  599. $table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
  600. $course_id = api_get_course_int_id();
  601. $sql = 'SELECT *
  602. FROM '.$table_que.' as questions
  603. LEFT JOIN '.$table_rel.' as quizz_questions
  604. ON questions.id=quizz_questions.question_id
  605. LEFT JOIN '.$table_qui.' as exercises
  606. ON quizz_questions.exercice_id = exercises.id
  607. WHERE questions.c_id = quizz_questions.c_id AND
  608. questions.c_id = exercises.c_id AND
  609. exercises.c_id = '.$course_id.' AND
  610. (quizz_questions.exercice_id IS NULL OR
  611. exercises.active = -1)';
  612. $db_result = Database::query($sql);
  613. if (Database::num_rows($db_result) > 0) {
  614. // This is the fictional test for collecting orphan questions.
  615. $orphan_questions = new Quiz(-1, get_lang('OrphanQuestions', ''), '', 0, 0, 1, '', 0);
  616. $this->course->add_resource($orphan_questions);
  617. while ($obj = Database::fetch_object($db_result)) {
  618. $question = new QuizQuestion(
  619. $obj->id,
  620. $obj->question,
  621. $obj->description,
  622. $obj->ponderation,
  623. $obj->type,
  624. $obj->position,
  625. $obj->picture,
  626. $obj->level,
  627. $obj->extra
  628. );
  629. $sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.$obj->id;
  630. $db_result2 = Database::query($sql);
  631. while ($obj2 = Database::fetch_object($db_result2)) {
  632. $question->add_answer(
  633. $obj2->id,
  634. $obj2->answer,
  635. $obj2->correct,
  636. $obj2->comment,
  637. $obj2->ponderation,
  638. $obj2->position,
  639. $obj2->hotspot_coordinates,
  640. $obj2->hotspot_type
  641. );
  642. }
  643. $this->course->add_resource($question);
  644. }
  645. }
  646. }
  647. /**
  648. * Build the test category
  649. * $session_id, $course_code, $with_base_content, $this->specific_id_list[$tool]
  650. * @todo add course session
  651. */
  652. public function build_test_category($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  653. {
  654. $course_id = api_get_course_int_id();
  655. // get all test category in course
  656. $tab_test_categories_id = Testcategory::getCategoryListInfo("id", $course_id);
  657. foreach ($tab_test_categories_id as $test_category_id)
  658. {
  659. $test_category = new Testcategory($test_category_id);
  660. $copy_course_test_category = new CourseCopyTestcategory($test_category_id, $test_category->name, $test_category->description);
  661. $this->course->add_resource($copy_course_test_category);
  662. }
  663. }
  664. /**
  665. * Build the Surveys
  666. */
  667. public function build_surveys($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  668. {
  669. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  670. $table_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  671. $course_id = api_get_course_int_id();
  672. $sessionCondition = api_get_session_condition($session_id, true, $with_base_content);
  673. $sql = 'SELECT * FROM '.$table_survey.' WHERE c_id = '.$course_id.' ' . $sessionCondition;
  674. $db_result = Database::query($sql);
  675. while ($obj = Database::fetch_object($db_result)) {
  676. $survey = new Survey($obj->survey_id, $obj->code,$obj->title,
  677. $obj->subtitle, $obj->author, $obj->lang,
  678. $obj->avail_from, $obj->avail_till, $obj->is_shared,
  679. $obj->template, $obj->intro, $obj->surveythanks,
  680. $obj->creation_date, $obj->invited, $obj->answered,
  681. $obj->invite_mail, $obj->reminder_mail);
  682. $sql = 'SELECT * FROM '.$table_question.' WHERE c_id = '.$course_id.' AND survey_id = '.$obj->survey_id;
  683. $db_result2 = Database::query($sql);
  684. while ($obj2 = Database::fetch_object($db_result2)){
  685. $survey->add_question($obj2->question_id);
  686. }
  687. $this->course->add_resource($survey);
  688. }
  689. $this->build_survey_questions();
  690. }
  691. /**
  692. * Build the Survey Questions
  693. */
  694. public function build_survey_questions() {
  695. $table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  696. $table_opt = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
  697. $course_id = api_get_course_int_id();
  698. $sql = 'SELECT * FROM '.$table_que.' WHERE c_id = '.$course_id.' ';
  699. $db_result = Database::query($sql);
  700. while ($obj = Database::fetch_object($db_result)){
  701. $question = new SurveyQuestion(
  702. $obj->question_id,
  703. $obj->survey_id,
  704. $obj->survey_question,
  705. $obj->survey_question_comment,
  706. $obj->type,
  707. $obj->display,
  708. $obj->sort,
  709. $obj->shared_question_id,
  710. $obj->max_value
  711. );
  712. $sql = 'SELECT * FROM '.$table_opt.' WHERE c_id = '.$course_id.' AND question_id = '.$obj->question_id;
  713. $db_result2 = Database::query($sql);
  714. while ($obj2 = Database::fetch_object($db_result2)) {
  715. $question->add_answer($obj2->option_text, $obj2->sort);
  716. }
  717. $this->course->add_resource($question);
  718. }
  719. }
  720. /**
  721. * Build the announcements
  722. */
  723. public function build_announcements($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  724. {
  725. $table = Database :: get_course_table(TABLE_ANNOUNCEMENT);
  726. $course_id = api_get_course_int_id();
  727. $sessionCondition = api_get_session_condition($session_id, true, $with_base_content);
  728. $sql = 'SELECT * FROM '.$table.' WHERE c_id = '.$course_id.' ' . $sessionCondition;
  729. $db_result = Database::query($sql);
  730. $table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
  731. while ($obj = Database::fetch_object($db_result)) {
  732. $sql = 'SELECT path, comment, filename, size FROM '.$table_attachment.' WHERE c_id = '.$course_id.' AND announcement_id = '.$obj->id.'';
  733. $result = Database::query($sql);
  734. $attachment_obj = Database::fetch_object($result);
  735. $att_path = $att_filename = $att_size = $atth_comment = '';
  736. if (!empty($attachment_obj)) {
  737. $att_path = $attachment_obj->path;
  738. $att_filename = $attachment_obj->filename;
  739. $att_size = $attachment_obj->size;
  740. $atth_comment = $attachment_obj->comment;
  741. }
  742. $announcement = new Announcement(
  743. $obj->id,
  744. $obj->title,
  745. $obj->content,
  746. $obj->end_date,
  747. $obj->display_order,
  748. $obj->email_sent,
  749. $att_path,
  750. $att_filename,
  751. $att_size,
  752. $atth_comment
  753. );
  754. $this->course->add_resource($announcement);
  755. }
  756. }
  757. /**
  758. * Build the events
  759. */
  760. public function build_events($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  761. {
  762. $table = Database :: get_course_table(TABLE_AGENDA);
  763. $course_id = api_get_course_int_id();
  764. $sessionCondition = api_get_session_condition($session_id, true, $with_base_content);
  765. $sql = 'SELECT * FROM '.$table.' WHERE c_id = '.$course_id.' ' . $sessionCondition;
  766. $db_result = Database::query($sql);
  767. while ($obj = Database::fetch_object($db_result)) {
  768. $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
  769. $sql = 'SELECT path, comment, filename, size FROM '.$table_attachment.' WHERE c_id = '.$course_id.' AND agenda_id = '.$obj->id.'';
  770. $result = Database::query($sql);
  771. $attachment_obj = Database::fetch_object($result);
  772. $att_path = $att_filename = $att_size = $atth_comment = '';
  773. if (!empty($attachment_obj)) {
  774. $att_path = $attachment_obj->path;
  775. $att_filename = $attachment_obj->filename;
  776. $att_size = $attachment_obj->size;
  777. $atth_comment = $attachment_obj->comment;
  778. }
  779. $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);
  780. $this->course->add_resource($event);
  781. }
  782. }
  783. /**
  784. * Build the course-descriptions
  785. */
  786. public function build_course_descriptions($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  787. {
  788. $course_info = api_get_course_info($course_code);
  789. $course_id = $course_info['real_id'];
  790. $table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION);
  791. if (!empty($session_id) && !empty($course_code)) {
  792. $session_id = intval($session_id);
  793. if ($with_base_content) {
  794. $session_condition = api_get_session_condition($session_id, true, true);
  795. } else {
  796. $session_condition = api_get_session_condition($session_id, true);
  797. }
  798. $sql = 'SELECT * FROM '.$table. ' WHERE c_id = '.$course_id.' '.$session_condition;
  799. } else {
  800. $table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION);
  801. $sql = 'SELECT * FROM '.$table. ' WHERE c_id = '.$course_id.' AND session_id = 0';
  802. }
  803. $db_result = Database::query($sql);
  804. while ($obj = Database::fetch_object($db_result)) {
  805. $cd = new CourseDescription($obj->id, $obj->title, $obj->content, $obj->description_type);
  806. $this->course->add_resource($cd);
  807. }
  808. }
  809. /**
  810. * Build the learnpaths
  811. */
  812. public function build_learnpaths($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  813. {
  814. $course_info = api_get_course_info($course_code);
  815. $course_id = $course_info['real_id'];
  816. $table_main = Database::get_course_table(TABLE_LP_MAIN);
  817. $table_item = Database::get_course_table(TABLE_LP_ITEM);
  818. $table_tool = Database::get_course_table(TABLE_TOOL_LIST);
  819. if (!empty($session_id) && !empty($course_code)) {
  820. $session_id = intval($session_id);
  821. if ($with_base_content) {
  822. $session_condition = api_get_session_condition($session_id, true, true);
  823. } else {
  824. $session_condition = api_get_session_condition($session_id, true);
  825. }
  826. $sql = 'SELECT * FROM '.$table_main.' WHERE c_id = '.$course_id.' '.$session_condition;
  827. } else {
  828. $sql = 'SELECT * FROM '.$table_main.' WHERE c_id = '.$course_id.' AND session_id = 0';
  829. }
  830. if (!empty($id_list)) {
  831. $id_list = array_map('intval', $id_list);
  832. $sql .=" AND id IN (".implode(', ', $id_list).") ";
  833. }
  834. $db_result = Database::query($sql);
  835. if ($db_result)
  836. while ($obj = Database::fetch_object($db_result)) {
  837. $items = array();
  838. $sql_items = "SELECT * FROM ".$table_item." WHERE c_id = '$course_id' AND lp_id = ".$obj->id;
  839. $db_items = Database::query($sql_items);
  840. while ($obj_item = Database::fetch_object($db_items)) {
  841. $item['id'] = $obj_item->id;
  842. $item['item_type'] = $obj_item->item_type;
  843. $item['ref'] = $obj_item->ref;
  844. $item['title'] = $obj_item->title;
  845. $item['description'] = $obj_item->description;
  846. $item['path'] = $obj_item->path;
  847. $item['min_score'] = $obj_item->min_score;
  848. $item['max_score'] = $obj_item->max_score;
  849. $item['mastery_score'] = $obj_item->mastery_score;
  850. $item['parent_item_id'] = $obj_item->parent_item_id;
  851. $item['previous_item_id'] = $obj_item->previous_item_id;
  852. $item['next_item_id'] = $obj_item->next_item_id;
  853. $item['display_order'] = $obj_item->display_order;
  854. $item['prerequisite'] = $obj_item->prerequisite;
  855. $item['parameters'] = $obj_item->parameters;
  856. $item['launch_data'] = $obj_item->launch_data;
  857. $item['audio'] = $obj_item->audio;
  858. $items[] = $item;
  859. }
  860. $sql_tool = "SELECT id FROM $table_tool
  861. WHERE
  862. c_id = $course_id AND
  863. (link LIKE '%lp_controller.php%lp_id=".$obj->id."%' AND image='scormbuilder.gif') AND
  864. visibility = '1' ";
  865. $db_tool = Database::query($sql_tool);
  866. if (Database::num_rows($db_tool)) {
  867. $visibility = '1';
  868. } else {
  869. $visibility = '0';
  870. }
  871. $lp = new CourseCopyLearnpath(
  872. $obj->id,
  873. $obj->lp_type,
  874. $obj->name,
  875. $obj->path,
  876. $obj->ref,
  877. $obj->description,
  878. $obj->content_local,
  879. $obj->default_encoding,
  880. $obj->default_view_mod,
  881. $obj->prevent_reinit,
  882. $obj->force_commit,
  883. $obj->content_maker,
  884. $obj->display_order,
  885. $obj->js_lib,
  886. $obj->content_license,
  887. $obj->debug,
  888. $visibility,
  889. $obj->author,
  890. $obj->preview_image,
  891. $obj->use_max_score,
  892. $obj->autolunch,
  893. $obj->created_on,
  894. $obj->modified_on,
  895. $obj->publicated_on,
  896. $obj->expired_on,
  897. $obj->session_id,
  898. $items
  899. );
  900. $this->course->add_resource($lp);
  901. }
  902. // Save scorm directory (previously build_scorm_documents())
  903. $i = 1;
  904. if ($dir = @opendir($this->course->backup_path . '/scorm')) {
  905. while ($file = readdir($dir)) {
  906. if (is_dir($this->course->backup_path.'/scorm/'.$file) &&
  907. !in_array($file, array('.','..'))
  908. ) {
  909. $doc = new ScormDocument($i++, '/'.$file, $file);
  910. $this->course->add_resource($doc);
  911. }
  912. }
  913. closedir($dir);
  914. }
  915. }
  916. /**
  917. * Build the glossarys
  918. */
  919. public function build_glossary($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  920. {
  921. $course_info = api_get_course_info($course_code);
  922. $table_glossary = Database :: get_course_table(TABLE_GLOSSARY);
  923. $course_id = $course_info['real_id'];
  924. if (!empty($session_id) && !empty($course_code)) {
  925. $session_id = intval($session_id);
  926. if ($with_base_content) {
  927. $session_condition = api_get_session_condition($session_id, true, true);
  928. } else {
  929. $session_condition = api_get_session_condition($session_id, true);
  930. }
  931. //@todo check this queries are the same ...
  932. if (!empty($this->course->type) && $this->course->type=='partial') {
  933. $sql = 'SELECT * FROM '.$table_glossary.' g WHERE g.c_id = '.$course_id.' '.$session_condition;
  934. } else {
  935. $sql = 'SELECT * FROM '.$table_glossary.' g WHERE g.c_id = '.$course_id.' '.$session_condition;
  936. }
  937. } else {
  938. $table_glossary = Database :: get_course_table(TABLE_GLOSSARY);
  939. //@todo check this queries are the same ... ayayay
  940. if (!empty($this->course->type) && $this->course->type=='partial') {
  941. $sql = 'SELECT * FROM '.$table_glossary.' g WHERE g.c_id = '.$course_id.' AND session_id = 0';
  942. } else {
  943. $sql = 'SELECT * FROM '.$table_glossary.' g WHERE g.c_id = '.$course_id.' AND session_id = 0';
  944. }
  945. }
  946. $db_result = Database::query($sql);
  947. while ($obj = Database::fetch_object($db_result)) {
  948. $doc = new Glossary($obj->glossary_id, $obj->name, $obj->description, $obj->display_order);
  949. $this->course->add_resource($doc);
  950. }
  951. }
  952. /*
  953. * build session course by jhon
  954. * */
  955. public function build_session_course()
  956. {
  957. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  958. $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  959. $list_course = CourseManager::get_course_list();
  960. $list = array();
  961. foreach($list_course as $_course) {
  962. $this->course = new Course();
  963. $this->course->code = $_course['code'];
  964. $this->course->type = 'partial';
  965. $this->course->path = api_get_path(SYS_COURSE_PATH).$_course['directory'].'/';
  966. $this->course->backup_path = api_get_path(SYS_COURSE_PATH).$_course['directory'];
  967. $this->course->encoding = api_get_system_encoding(); //current platform encoding
  968. $code_course = $_course['code'];
  969. $sql_session = "SELECT id, name, course_code FROM $tbl_session_course
  970. INNER JOIN $tbl_session ON id_session = id
  971. WHERE course_code = '$code_course' ";
  972. $query_session = Database::query($sql_session);
  973. while ($rows_session = Database::fetch_assoc($query_session)) {
  974. $session = new CourseSession($rows_session['id'], $rows_session['name']);
  975. $this->course->add_resource($session);
  976. }
  977. $list[] = $this->course;
  978. }
  979. return $list;
  980. }
  981. /**
  982. * @param int $session_id
  983. * @param string $course_code
  984. * @param bool $with_base_content
  985. * @param array $id_list
  986. */
  987. public function build_wiki($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  988. {
  989. $course_info = api_get_course_info($course_code);
  990. $tbl_wiki = Database::get_course_table(TABLE_WIKI);
  991. $course_id = $course_info['real_id'];
  992. if (!empty($session_id) && !empty($course_code)) {
  993. $session_id = intval($session_id);
  994. if ($with_base_content) {
  995. $session_condition = api_get_session_condition($session_id, true, true);
  996. } else {
  997. $session_condition = api_get_session_condition($session_id, true);
  998. }
  999. $sql = 'SELECT * FROM ' . $tbl_wiki . ' WHERE c_id = '.$course_id.' '.$session_condition;
  1000. } else {
  1001. $tbl_wiki = Database::get_course_table(TABLE_WIKI);
  1002. $sql = 'SELECT * FROM ' . $tbl_wiki . ' WHERE c_id = '.$course_id.' AND session_id = 0';
  1003. }
  1004. $db_result = Database::query($sql);
  1005. while ($obj = Database::fetch_object($db_result)) {
  1006. $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);
  1007. $this->course->add_resource($wiki);
  1008. }
  1009. }
  1010. /**
  1011. * Build the Surveys
  1012. */
  1013. public function build_thematic($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  1014. {
  1015. $table_thematic = Database :: get_course_table(TABLE_THEMATIC);
  1016. $table_thematic_advance = Database :: get_course_table(TABLE_THEMATIC_ADVANCE);
  1017. $table_thematic_plan = Database :: get_course_table(TABLE_THEMATIC_PLAN);
  1018. $session_id = intval($session_id);
  1019. if ($with_base_content) {
  1020. $session_condition = api_get_session_condition($session_id, true, true);
  1021. } else {
  1022. $session_condition = api_get_session_condition($session_id, true);
  1023. }
  1024. $course_id = api_get_course_int_id();
  1025. $sql = "SELECT * FROM $table_thematic WHERE c_id = $course_id $session_condition ";
  1026. $db_result = Database::query($sql);
  1027. while ($row = Database::fetch_array($db_result,'ASSOC')) {
  1028. $thematic = new Thematic($row);
  1029. $sql = 'SELECT * FROM '.$table_thematic_advance.' WHERE c_id = '.$course_id.' AND thematic_id = '.$row['id'];
  1030. $result = Database::query($sql);
  1031. while ($sub_row = Database::fetch_array($result,'ASSOC')) {
  1032. $thematic->add_thematic_advance($sub_row);
  1033. }
  1034. $items = api_get_item_property_by_tool('thematic_plan', api_get_course_id(), $session_id);
  1035. //$items_from_session = api_get_item_property_by_tool('thematic_plan', api_get_course_id(), api_get_session_id());
  1036. $thematic_plan_id_list = array();
  1037. if (!empty($items)) {
  1038. foreach($items as $item) {
  1039. $thematic_plan_id_list[] = $item['ref'];
  1040. //$thematic_plan_complete_list[$item['ref']] = $item;
  1041. }
  1042. }
  1043. if (count($thematic_plan_id_list) > 0) {
  1044. $sql = "SELECT tp.*
  1045. FROM $table_thematic_plan tp
  1046. INNER JOIN $table_thematic t ON (t.id=tp.thematic_id)
  1047. WHERE
  1048. t.c_id = $course_id AND
  1049. tp.c_id = $course_id AND
  1050. thematic_id = {$row['id']} AND
  1051. tp.id IN (".implode(', ', $thematic_plan_id_list).") ";
  1052. $result = Database::query($sql);
  1053. while ($sub_row = Database::fetch_array($result,'ASSOC')) {
  1054. $thematic->add_thematic_plan($sub_row);
  1055. }
  1056. }
  1057. $this->course->add_resource($thematic);
  1058. }
  1059. }
  1060. /**
  1061. * Build the attendances
  1062. */
  1063. public function build_attendance($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  1064. {
  1065. $table_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
  1066. $table_attendance_calendar = Database :: get_course_table(TABLE_ATTENDANCE_CALENDAR);
  1067. $course_id = api_get_course_int_id();
  1068. $sessionCondition = api_get_session_condition($session_id, true, $with_base_content);
  1069. $sql = 'SELECT * FROM '.$table_attendance.' WHERE c_id = '.$course_id.' ' . $sessionCondition;
  1070. $db_result = Database::query($sql);
  1071. while ($row = Database::fetch_array($db_result,'ASSOC')) {
  1072. $obj = new Attendance($row);
  1073. $sql = 'SELECT * FROM '.$table_attendance_calendar.' WHERE c_id = '.$course_id.' AND attendance_id = '.$row['id'];
  1074. $result = Database::query($sql);
  1075. while ($sub_row = Database::fetch_array($result,'ASSOC')) {
  1076. $obj->add_attendance_calendar($sub_row);
  1077. }
  1078. $this->course->add_resource($obj);
  1079. }
  1080. }
  1081. /**
  1082. * Build the works (or "student publications", or "assignments")
  1083. *
  1084. * @param int $session_id
  1085. * @param string $course_code
  1086. * @param bool $with_base_content
  1087. * @param array $id_list
  1088. */
  1089. public function build_works($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
  1090. {
  1091. $table_work = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  1092. $course_id = api_get_course_int_id();
  1093. $sessionCondition = api_get_session_condition($session_id, true, $with_base_content);
  1094. $sql = "SELECT * FROM $table_work
  1095. WHERE
  1096. c_id = $course_id
  1097. $sessionCondition AND
  1098. filetype = 'folder' AND
  1099. parent_id = 0 AND
  1100. active = 1";
  1101. $db_result = Database::query($sql);
  1102. while ($row = Database::fetch_array($db_result,'ASSOC')) {
  1103. $obj = new Work($row);
  1104. $this->course->add_resource($obj);
  1105. }
  1106. }
  1107. }