learnpathList.class.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php //$id:$
  2. /**
  3. * File containing the declaration of the learnpathList class.
  4. * @package dokeos.learningpath
  5. * @author Yannick Warnier <ywarnier@beeznest.org>
  6. */
  7. /**
  8. * This class is only a learning path list container with several practical methods for sorting the list and
  9. * provide links to specific paths
  10. * @uses Database.lib.php to use the database
  11. * @uses learnpath.class.php to generate learnpath objects to get in the list
  12. */
  13. class learnpathList {
  14. var $list = array(); //holds a flat list of learnpaths data from the database
  15. var $ref_list = array(); //holds a list of references to the learnpaths objects (only filled by get_refs())
  16. var $alpha_list = array(); //holds a flat list of learnpaths sorted by alphabetical name order
  17. var $course_code;
  18. var $user_id;
  19. var $refs_active = false;
  20. /**
  21. * This method is the constructor for the learnpathList. It gets a list of available learning paths from
  22. * the database and creates the learnpath objects. This list depends on the user that is connected
  23. * (only displays) items if he has enough permissions to view them.
  24. * @param integer User ID
  25. * @param string Optional course code (otherwise we use api_get_course_id())
  26. * @return void
  27. */
  28. function learnpathList($user_id,$course_code='') {
  29. if(!empty($course_code)){
  30. //proceed with course code given
  31. }else{
  32. $course_code = api_get_course_id();
  33. $lp_table = Database::get_course_table('lp');
  34. }
  35. $this->course_code = $course_code;
  36. $this->user_id = $user_id;
  37. $sql = "SELECT * FROM $lp_table ORDER BY name ASC";
  38. $res = api_sql_query($sql);
  39. $names = array();
  40. while ($row = Database::fetch_array($res))
  41. {
  42. $tbl_tool = Database::get_course_table(TOOL_LIST_TABLE);
  43. //use domesticate here instead of mysql_real_escape_string because
  44. //it prevents ' to be slashed and the input (done by learnpath.class.php::toggle_visibility())
  45. //is done using domesticate()
  46. $myname = domesticate($row['name']);
  47. $sql2="SELECT * FROM $tbl_tool where (name='$myname' and image='scormbuilder.gif')";
  48. //error_log('New LP - learnpathList::learnpathList - getting visibility - '.$sql2,0);
  49. $res2 = api_sql_query($sql2,__FILE__,__LINE__);
  50. if(Database::num_rows($res2)>0){
  51. $row2 = Database::fetch_array($res2);
  52. $vis = $row2['visibility'];
  53. }else{
  54. $vis = 'i';
  55. }
  56. $this->list[$row['id']] = array(
  57. 'lp_type' => $row['lp_type'],
  58. 'lp_name' => stripslashes($row['name']),
  59. 'lp_desc' => stripslashes($row['description']),
  60. 'lp_path' => $row['path'],
  61. 'lp_view_mode' => $row['default_view_mod'],
  62. 'lp_force_commit' => $row['force_commit'],
  63. 'lp_maker' => stripslashes($row['content_maker']),
  64. 'lp_proximity' => $row['content_local'],
  65. 'lp_encoding' => $row['default_encoding'],
  66. 'lp_progress' => $row['progress'],
  67. 'lp_visibility' => $vis,
  68. 'lp_prevent_reinit' => $row['prevent_reinit'],
  69. 'lp_scorm_debug' => $row['debug'],
  70. );
  71. $names[$row['name']]=$row['id'];
  72. }
  73. $this->alpha_list = asort($names);
  74. }
  75. /**
  76. * Gets references to learnpaths for all learnpaths IDs kept in the local list.
  77. * This applies a transformation internally on list and ref_list and returns a copy of the refs list
  78. * @return array List of references to learnpath objects
  79. */
  80. function get_refs(){
  81. foreach($this->list as $id => $dummy)
  82. {
  83. $this->ref_list[$id] = new learnpath($this->course_code,$id,$this->user_id);
  84. }
  85. $this->refs_active = true;
  86. return $this->ref_list;
  87. }
  88. /**
  89. * Gets a table of the different learnpaths we have at the moment
  90. * @return array Learnpath info as [lp_id] => ([lp_type]=> ..., [lp_name]=>...,[lp_desc]=>...,[lp_path]=>...)
  91. */
  92. function get_flat_list()
  93. {
  94. return $this->list;
  95. }
  96. }
  97. ?>