learnpathList.class.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * File containing the declaration of the learnpathList class.
  5. * @package chamilo.learnpath
  6. * @author Yannick Warnier <ywarnier@beeznest.org>
  7. */
  8. /**
  9. * This class is only a learning path list container with several practical methods for sorting the list and
  10. * provide links to specific paths
  11. * @uses Database.lib.php to use the database
  12. * @uses learnpath.class.php to generate learnpath objects to get in the list
  13. */
  14. class learnpathList {
  15. public $list = array(); // Holds a flat list of learnpaths data from the database.
  16. public $ref_list = array(); // Holds a list of references to the learnpaths objects (only filled by get_refs()).
  17. public $alpha_list = array(); // Holds a flat list of learnpaths sorted by alphabetical name order.
  18. public $course_code;
  19. public $user_id;
  20. public $refs_active = false;
  21. /**
  22. * This method is the constructor for the learnpathList. It gets a list of available learning paths from
  23. * the database and creates the learnpath objects. This list depends on the user that is connected
  24. * (only displays) items if he has enough permissions to view them.
  25. * @param integer User ID
  26. * @param string Optional course code (otherwise we use api_get_course_id())
  27. * @param int Optional session id (otherwise we use api_get_session_id())
  28. * @return void
  29. */
  30. function __construct($user_id, $course_code = '', $session_id = null, $order_by = null, $check_publication_dates = false) {
  31. $course_info = api_get_course_info($course_code);
  32. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  33. $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
  34. $this->course_code = $course_code;
  35. $this->user_id = $user_id;
  36. $course_id = $course_info['real_id'];
  37. // Condition for the session.
  38. if (isset($session_id)) {
  39. $session_id = intval($session_id);
  40. } else {
  41. $session_id = api_get_session_id();
  42. }
  43. $condition_session = api_get_session_condition($session_id, true, true);
  44. $order = "ORDER BY display_order ASC, name ASC";
  45. if (isset($order_by)) {
  46. $order = Database::parse_conditions(array('order'=>$order_by));
  47. }
  48. $now = api_get_utc_datetime();
  49. $time_conditions = '';
  50. if ($check_publication_dates) {
  51. $time_conditions = " AND ( (publicated_on <> '0000-00-00 00:00:00' AND publicated_on < '$now' AND expired_on <> '0000-00-00 00:00:00' AND expired_on > '$now' ) OR
  52. (publicated_on <> '0000-00-00 00:00:00' AND publicated_on < '$now' AND expired_on = '0000-00-00 00:00:00') OR
  53. (publicated_on = '0000-00-00 00:00:00' AND expired_on <> '0000-00-00 00:00:00' AND expired_on > '$now') OR
  54. (publicated_on = '0000-00-00 00:00:00' AND expired_on = '0000-00-00 00:00:00' ))
  55. ";
  56. }
  57. $sql = "SELECT * FROM $lp_table WHERE c_id = $course_id $time_conditions $condition_session $order";
  58. $res = Database::query($sql);
  59. $names = array();
  60. while ($row = Database::fetch_array($res,'ASSOC')) {
  61. // Check if published.
  62. $pub = '';
  63. // Use domesticate here instead of Database::escape_string because
  64. // it prevents ' to be slashed and the input (done by learnpath.class.php::toggle_visibility())
  65. // is done using domesticate()
  66. $myname = domesticate($row['name']);
  67. $mylink = 'newscorm/lp_controller.php?action=view&lp_id='.$row['id'].'&id_session='.$session_id;
  68. $sql2="SELECT * FROM $tbl_tool WHERE c_id = $course_id AND (name='$myname' and image='scormbuilder.gif' and link LIKE '$mylink%')";
  69. //error_log('New LP - learnpathList::__construct - getting visibility - '.$sql2, 0);
  70. $res2 = Database::query($sql2);
  71. if (Database::num_rows($res2) > 0) {
  72. $row2 = Database::fetch_array($res2);
  73. $pub = $row2['visibility'];
  74. } else {
  75. $pub = 'i';
  76. }
  77. // Check if visible.
  78. $vis = api_get_item_visibility(api_get_course_info($course_code), 'learnpath', $row['id'], $session_id);
  79. if (!empty($row['created_on']) && $row['created_on'] != '0000-00-00 00:00:00') {
  80. $row['created_on'] = $row['created_on'];
  81. } else {
  82. $row['created_on'] = '';
  83. }
  84. if (!empty($row['modified_on']) && $row['modified_on'] != '0000-00-00 00:00:00') {
  85. $row['modified_on'] = $row['modified_on'];
  86. } else {
  87. $row['modified_on'] = '';
  88. }
  89. if (!empty($row['publicated_on']) && $row['publicated_on'] != '0000-00-00 00:00:00') {
  90. $row['publicated_on'] = $row['publicated_on'];
  91. } else {
  92. $row['publicated_on'] = '';
  93. }
  94. if (!empty($row['expired_on']) && $row['expired_on'] != '0000-00-00 00:00:00') {
  95. $row['expired_on'] = $row['expired_on'];
  96. } else {
  97. $row['expired_on'] = '';
  98. }
  99. $this->list[$row['id']] = array(
  100. 'lp_type' => $row['lp_type'],
  101. 'lp_session' => $row['session_id'],
  102. 'lp_name' => stripslashes($row['name']),
  103. 'lp_desc' => stripslashes($row['description']),
  104. 'lp_path' => $row['path'],
  105. 'lp_view_mode' => $row['default_view_mod'],
  106. 'lp_force_commit' => $row['force_commit'],
  107. 'lp_maker' => stripslashes($row['content_maker']),
  108. 'lp_proximity' => $row['content_local'],
  109. //'lp_encoding' => $row['default_encoding'],
  110. 'lp_encoding' => api_get_system_encoding(), // Chamilo 1.8.8: We intend always to use the system encoding.
  111. 'lp_visibility' => $vis,
  112. 'lp_published' => $pub,
  113. 'lp_prevent_reinit' => $row['prevent_reinit'],
  114. 'seriousgame_mode' => $row['seriousgame_mode'],
  115. 'lp_scorm_debug' => $row['debug'],
  116. 'lp_display_order' => $row['display_order'],
  117. 'lp_preview_image' => stripslashes($row['preview_image']),
  118. 'autolaunch' => $row['autolunch'],
  119. 'session_id' => $row['session_id'],
  120. 'created_on' => $row['created_on'],
  121. 'modified_on' => $row['modified_on'],
  122. 'publicated_on' => $row['publicated_on'],
  123. 'expired_on' => $row['expired_on']
  124. );
  125. $names[$row['name']] = $row['id'];
  126. }
  127. $this->alpha_list = asort($names);
  128. }
  129. /**
  130. * Gets references to learnpaths for all learnpaths IDs kept in the local list.
  131. * This applies a transformation internally on list and ref_list and returns a copy of the refs list
  132. * @return array List of references to learnpath objects
  133. */
  134. function get_refs() {
  135. foreach ($this->list as $id => $dummy) {
  136. $this->ref_list[$id] = new learnpath($this->course_code, $id, $this->user_id);
  137. }
  138. $this->refs_active = true;
  139. return $this->ref_list;
  140. }
  141. /**
  142. * Gets a table of the different learnpaths we have at the moment
  143. * @return array Learnpath info as [lp_id] => ([lp_type]=> ..., [lp_name]=>...,[lp_desc]=>...,[lp_path]=>...)
  144. */
  145. function get_flat_list() {
  146. return $this->list;
  147. }
  148. }