webservice_report.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.webservices
  5. */
  6. require_once(dirname(__FILE__).'/../inc/global.inc.php');
  7. $libpath = api_get_path(LIBRARY_PATH);
  8. require_once($libpath.'sessionmanager.lib.php');
  9. require_once $libpath.'usermanager.lib.php';
  10. require_once $libpath.'tracking.lib.php';
  11. require_once $libpath.'course.lib.php';
  12. require_once(dirname(__FILE__).'/webservice.php');
  13. /**
  14. * Web services available for the User module. This class extends the WS class
  15. */
  16. class WSReport extends WS {
  17. /**
  18. * Gets the time spent on the platform by a given user
  19. *
  20. * @param string User id field name
  21. * @param string User id value
  22. * @return array Array of results
  23. */
  24. protected function get_time_spent_on_platform($user_id_field_name, $user_id_value) {
  25. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  26. if($user_id instanceof WSError) {
  27. return $user_id;
  28. } else {
  29. return Tracking::get_time_spent_on_the_platform($user_id);
  30. }
  31. }
  32. /**
  33. * Gets the time spent in a course by a given user
  34. *
  35. * @param string User id field name
  36. * @param string User id value
  37. * @param string Course id field name
  38. * @param string Course id value
  39. * @return array Array of results
  40. */
  41. protected function get_time_spent_on_course($user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value) {
  42. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  43. if($user_id instanceof WSError) {
  44. return $user_id;
  45. }
  46. $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
  47. if($course_id instanceof WSError) {
  48. return $course_id;
  49. } else {
  50. $course_code = CourseManager::get_course_code_from_course_id($course_id);
  51. }
  52. return Tracking::get_time_spent_on_the_course($user_id, $course_code);
  53. }
  54. /**
  55. * Gets the time spent in a course by a given user
  56. *
  57. * @param string User id field name
  58. * @param string User id value
  59. * @param string Course id field name
  60. * @param string Course id value
  61. * @return array Array of results
  62. */
  63. protected function get_time_spent_on_course_in_session($user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $session_id_field_name, $session_id_value) {
  64. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  65. if($user_id instanceof WSError) {
  66. return $user_id;
  67. }
  68. $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
  69. if($course_id instanceof WSError) {
  70. return $course_id;
  71. } else {
  72. $course_code = CourseManager::get_course_code_from_course_id($course_id);
  73. }
  74. $session_id = $this->getSessionId($session_id_field_name, $session_id_value);
  75. if($session_id instanceof WSError) {
  76. return $session_id;
  77. }
  78. return Tracking::get_time_spent_on_the_course($user_id, $course_code, $session_id);
  79. }
  80. /**
  81. * Gets a list of learning paths by course
  82. *
  83. * @param string User id field name
  84. * @param string User id value
  85. * @param string Course id field name
  86. * @param string Course id value
  87. * @return array Array of id=>title of learning paths
  88. */
  89. protected function get_learnpaths_by_course($user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $lp_id) {
  90. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  91. if($user_id instanceof WSError) {
  92. return $user_id;
  93. }
  94. $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
  95. if($course_id instanceof WSError) {
  96. return $course_id;
  97. } else {
  98. $course_code = CourseManager::get_course_code_from_course_id($course_id);
  99. }
  100. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php';
  101. $list = new LearnpathList($user_id,$course_code);
  102. $return = array();
  103. foreach ($list as $id => $item) {
  104. $return[] = array('id'=>$id, 'title' => $item);
  105. }
  106. return $return;
  107. }
  108. /**
  109. * Gets progress attained in the given learning path by the given user
  110. *
  111. * @param string User id field name
  112. * @param string User id value
  113. * @param string Course id field name
  114. * @param string Course id value
  115. * @param string Learnpath ID
  116. * @return double Between 0 and 100 (% of progress)
  117. */
  118. protected function get_user_learnpath_progress($user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $learnpath_id) {
  119. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  120. if($user_id instanceof WSError) {
  121. return $user_id;
  122. }
  123. $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
  124. if($course_id instanceof WSError) {
  125. return $course_id;
  126. } else {
  127. $course_code = CourseManager::get_course_code_from_course_id($course_id);
  128. }
  129. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
  130. $lp = new learnpath($course_code, $learnpath_id, $user_id);
  131. return $lp['progress'];
  132. }
  133. /**
  134. * Gets score obtained in the given learning path by the given user,
  135. * assuming there is only one item (SCO) in the learning path
  136. *
  137. * @param string User id field name
  138. * @param string User id value
  139. * @param string Course id field name
  140. * @param string Course id value
  141. * @param string Learnpath ID
  142. * @return double Generally between 0 and 100
  143. */
  144. protected function get_user_learnpath_score_single_item($user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $learnpath_id) {
  145. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  146. if($user_id instanceof WSError) {
  147. return $user_id;
  148. }
  149. $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
  150. if($course_id instanceof WSError) {
  151. return $course_id;
  152. } else {
  153. $course_code = CourseManager::get_course_code_from_course_id($course_id);
  154. }
  155. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
  156. $lp = new learnpath($course_code, $learnpath_id, $user_id);
  157. //return $lp['progress'];
  158. return 100;
  159. }
  160. /**
  161. * Gets status obtained in the given learning path by the given user,
  162. * assuming there is only one item (SCO) in the learning path
  163. *
  164. * @param string User id field name
  165. * @param string User id value
  166. * @param string Course id field name
  167. * @param string Course id value
  168. * @param string Learnpath ID
  169. * @return string "not attempted", "passed", "completed", "failed", "incomplete"
  170. */
  171. protected function get_user_learnpath_status_single_item($user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $learnpath_id) {
  172. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  173. if($user_id instanceof WSError) {
  174. return $user_id;
  175. }
  176. $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
  177. if($course_id instanceof WSError) {
  178. return $course_id;
  179. } else {
  180. $course_code = CourseManager::get_course_code_from_course_id($course_id);
  181. }
  182. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
  183. $lp = new learnpath($course_code, $learnpath_id, $user_id);
  184. //return $lp['progress'];
  185. return 'failed';
  186. //return 'passed';
  187. //return 'incomplete';
  188. }
  189. }