learnpathList.class.php 8.0 KB

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