learnpathList.class.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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) {
  31. if (!empty($course_code)){
  32. $course_info = api_get_course_info($course_code);
  33. $lp_table = Database::get_course_table(TABLE_LP_MAIN, $course_info['dbName']);
  34. } else {
  35. $course_code = api_get_course_id();
  36. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  37. }
  38. $this->course_code = $course_code;
  39. $this->user_id = $user_id;
  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, false, true);
  47. $sql = "SELECT * FROM $lp_table $condition_session ORDER BY display_order ASC, name ASC";
  48. $res = Database::query($sql);
  49. $names = array();
  50. while ($row = Database::fetch_array($res)) {
  51. // Check if published.
  52. $pub = '';
  53. $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
  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 (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. $this->list[$row['id']] = array(
  71. 'lp_type' => $row['lp_type'],
  72. 'lp_session' => $row['session_id'],
  73. 'lp_name' => stripslashes($row['name']),
  74. 'lp_desc' => stripslashes($row['description']),
  75. 'lp_path' => $row['path'],
  76. 'lp_view_mode' => $row['default_view_mod'],
  77. 'lp_force_commit' => $row['force_commit'],
  78. 'lp_maker' => stripslashes($row['content_maker']),
  79. 'lp_proximity' => $row['content_local'],
  80. //'lp_encoding' => $row['default_encoding'],
  81. 'lp_encoding' => api_get_system_encoding(), // Chamilo 1.8.8: We intend always to use the system encoding.
  82. 'lp_visibility' => $vis,
  83. 'lp_published' => $pub,
  84. 'lp_prevent_reinit' => $row['prevent_reinit'],
  85. 'lp_scorm_debug' => $row['debug'],
  86. 'lp_display_order' => $row['display_order'],
  87. 'lp_preview_image' => stripslashes($row['preview_image'])
  88. );
  89. $names[$row['name']] = $row['id'];
  90. }
  91. $this->alpha_list = asort($names);
  92. }
  93. /**
  94. * Gets references to learnpaths for all learnpaths IDs kept in the local list.
  95. * This applies a transformation internally on list and ref_list and returns a copy of the refs list
  96. * @return array List of references to learnpath objects
  97. */
  98. function get_refs() {
  99. foreach ($this->list as $id => $dummy) {
  100. $this->ref_list[$id] = new learnpath($this->course_code, $id, $this->user_id);
  101. }
  102. $this->refs_active = true;
  103. return $this->ref_list;
  104. }
  105. /**
  106. * Gets a table of the different learnpaths we have at the moment
  107. * @return array Learnpath info as [lp_id] => ([lp_type]=> ..., [lp_name]=>...,[lp_desc]=>...,[lp_path]=>...)
  108. */
  109. function get_flat_list() {
  110. return $this->list;
  111. }
  112. }