learnpathList.class.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 = null, $session_id = null, $order_by = null, $check_publication_dates = false, $filter_by_category = null) {
  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. if (empty($course_id)) {
  38. return false;
  39. }
  40. // Condition for the session.
  41. if (isset($session_id)) {
  42. $session_id = intval($session_id);
  43. } else {
  44. $session_id = api_get_session_id();
  45. }
  46. $condition_session = api_get_session_condition($session_id, true, true);
  47. $order = "ORDER BY display_order ASC, name ASC";
  48. if (isset($order_by)) {
  49. $order = Database::parse_conditions(array('order'=>$order_by));
  50. }
  51. $now = api_get_utc_datetime();
  52. $time_conditions = '';
  53. if ($check_publication_dates) {
  54. $time_conditions = " AND (
  55. (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
  56. (publicated_on <> '0000-00-00 00:00:00' AND publicated_on < '$now' AND expired_on = '0000-00-00 00:00:00') OR
  57. (publicated_on = '0000-00-00 00:00:00' AND expired_on <> '0000-00-00 00:00:00' AND expired_on > '$now') OR
  58. (publicated_on = '0000-00-00 00:00:00' AND expired_on = '0000-00-00 00:00:00' )
  59. )";
  60. }
  61. $category_filter = null;
  62. if (isset($filter_by_category)) {
  63. $filter_by_category = intval($filter_by_category);
  64. $category_filter = " AND category_id = $filter_by_category";
  65. }
  66. $sql = "SELECT * FROM $lp_table WHERE c_id = $course_id $time_conditions $condition_session $category_filter $order";
  67. $res = Database::query($sql);
  68. $names = array();
  69. while ($row = Database::fetch_array($res,'ASSOC')) {
  70. // Check if published.
  71. $pub = '';
  72. // Use domesticate here instead of Database::escape_string because
  73. // it prevents ' to be slashed and the input (done by learnpath.class.php::toggle_visibility())
  74. // is done using domesticate()
  75. $myname = Text::domesticate($row['name']);
  76. $mylink = 'newscorm/lp_controller.php?action=view&lp_id='.$row['id'].'&id_session='.$session_id;
  77. $sql2 = "SELECT * FROM $tbl_tool WHERE c_id = $course_id AND (name='$myname' and image='scormbuilder.gif' and link LIKE '$mylink%')";
  78. //error_log('New LP - learnpathList::__construct - getting visibility - '.$sql2, 0);
  79. $res2 = Database::query($sql2);
  80. if (Database::num_rows($res2) > 0) {
  81. $row2 = Database::fetch_array($res2);
  82. $pub = $row2['visibility'];
  83. } else {
  84. $pub = 'i';
  85. }
  86. // Check if visible
  87. $vis = api_get_item_visibility(api_get_course_info($course_code), 'learnpath', $row['id'], $session_id);
  88. if (!empty($row['created_on']) && $row['created_on'] != '0000-00-00 00:00:00') {
  89. $row['created_on'] = $row['created_on'];
  90. } else {
  91. $row['created_on'] = '';
  92. }
  93. if (!empty($row['modified_on']) && $row['modified_on'] != '0000-00-00 00:00:00') {
  94. $row['modified_on'] = $row['modified_on'];
  95. } else {
  96. $row['modified_on'] = '';
  97. }
  98. if (!empty($row['publicated_on']) && $row['publicated_on'] != '0000-00-00 00:00:00') {
  99. $row['publicated_on'] = $row['publicated_on'];
  100. } else {
  101. $row['publicated_on'] = '';
  102. }
  103. if (!empty($row['expired_on']) && $row['expired_on'] != '0000-00-00 00:00:00') {
  104. $row['expired_on'] = $row['expired_on'];
  105. } else {
  106. $row['expired_on'] = '';
  107. }
  108. //@todo user LP object
  109. $this->list[$row['id']] = array(
  110. 'lp_type' => $row['lp_type'],
  111. 'lp_session' => $row['session_id'],
  112. 'lp_name' => stripslashes($row['name']),
  113. 'lp_desc' => stripslashes($row['description']),
  114. 'lp_path' => $row['path'],
  115. 'lp_view_mode' => $row['default_view_mod'],
  116. 'lp_force_commit' => $row['force_commit'],
  117. 'lp_maker' => stripslashes($row['content_maker']),
  118. 'lp_proximity' => $row['content_local'],
  119. //'lp_encoding' => $row['default_encoding'],
  120. 'lp_encoding' => api_get_system_encoding(), // Chamilo 1.8.8: We intend always to use the system encoding.
  121. 'lp_visibility' => $vis,
  122. 'lp_published' => $pub,
  123. 'lp_prevent_reinit' => $row['prevent_reinit'],
  124. 'seriousgame_mode' => $row['seriousgame_mode'],
  125. 'lp_scorm_debug' => $row['debug'],
  126. 'lp_display_order' => $row['display_order'],
  127. 'lp_preview_image' => stripslashes($row['preview_image']),
  128. 'autolaunch' => $row['autolunch'],
  129. 'session_id' => $row['session_id'],
  130. 'created_on' => $row['created_on'],
  131. 'modified_on' => $row['modified_on'],
  132. 'publicated_on' => $row['publicated_on'],
  133. 'expired_on' => $row['expired_on'],
  134. 'category_id' => $row['category_id'],
  135. 'subscribe_users' => $row['subscribe_users']
  136. );
  137. $names[$row['name']] = $row['id'];
  138. }
  139. $this->alpha_list = asort($names);
  140. }
  141. /**
  142. * Gets references to learnpaths for all learnpaths IDs kept in the local list.
  143. * This applies a transformation internally on list and ref_list and returns a copy of the refs list
  144. * @return array List of references to learnpath objects
  145. */
  146. function get_refs() {
  147. foreach ($this->list as $id => $dummy) {
  148. $this->ref_list[$id] = new learnpath($this->course_code, $id, $this->user_id);
  149. }
  150. $this->refs_active = true;
  151. return $this->ref_list;
  152. }
  153. /**
  154. * Gets a table of the different learnpaths we have at the moment
  155. * @return array Learnpath info as [lp_id] => ([lp_type]=> ..., [lp_name]=>...,[lp_desc]=>...,[lp_path]=>...)
  156. */
  157. function get_flat_list() {
  158. return $this->list;
  159. }
  160. }