learnpathList.class.php 6.9 KB

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