webservice_report.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. require_once(dirname(__FILE__).'/webservice.php');
  8. /**
  9. * Web services available for the User module. This class extends the WS class
  10. */
  11. class WSReport extends WS {
  12. /**
  13. * Gets the time spent on the platform by a given user
  14. *
  15. * @param string User id field name
  16. * @param string User id value
  17. * @return array Array of results
  18. */
  19. public function GetTimeSpentOnPlatform($user_id_field_name, $user_id_value) {
  20. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  21. if($user_id instanceof WSError) {
  22. return $user_id;
  23. } else {
  24. return Tracking::get_time_spent_on_the_platform($user_id);
  25. }
  26. }
  27. /**
  28. * Gets the time spent in a course by a given user
  29. *
  30. * @param string User id field name
  31. * @param string User id value
  32. * @param string Course id field name
  33. * @param string Course id value
  34. * @return array Array of results
  35. */
  36. public function GetTimeSpentOnCourse($user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value) {
  37. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  38. if($user_id instanceof WSError) {
  39. return $user_id;
  40. }
  41. $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
  42. if($course_id instanceof WSError) {
  43. return $course_id;
  44. } else {
  45. $course_code = CourseManager::get_course_code_from_course_id($course_id);
  46. }
  47. return Tracking::get_time_spent_on_the_course($user_id, $course_code);
  48. }
  49. /**
  50. * Gets the time spent in a course by a given user
  51. *
  52. * @param string User id field name
  53. * @param string User id value
  54. * @param string Course id field name
  55. * @param string Course id value
  56. * @return array Array of results
  57. */
  58. public function GetTimeSpentOnCourseInSession($user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $session_id_field_name, $session_id_value) {
  59. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  60. if($user_id instanceof WSError) {
  61. return $user_id;
  62. }
  63. $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
  64. if($course_id instanceof WSError) {
  65. return $course_id;
  66. } else {
  67. $course_code = CourseManager::get_course_code_from_course_id($course_id);
  68. }
  69. $session_id = $this->getSessionId($session_id_field_name, $session_id_value);
  70. if($session_id instanceof WSError) {
  71. return $session_id;
  72. }
  73. return Tracking::get_time_spent_on_the_course($user_id, $course_code, $session_id);
  74. }
  75. /**
  76. * Gets a list of learning paths by course
  77. *
  78. * @param string User id field name
  79. * @param string User id value
  80. * @param string Course id field name
  81. * @param string Course id value
  82. * @return array Array of id=>title of learning paths
  83. */
  84. public function GetLearnpathsByCourse($secret_key, $user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value) {
  85. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  86. if($user_id instanceof WSError) {
  87. return $user_id;
  88. }
  89. $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
  90. if($course_id instanceof WSError) {
  91. return $course_id;
  92. } else {
  93. $course_code = CourseManager::get_course_code_from_course_id($course_id);
  94. }
  95. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php';
  96. $lp = new LearnpathList($user_id,$course_code);
  97. $list = $lp->list;
  98. $return = array();
  99. foreach ($list as $id => $item) {
  100. $return[] = array('id'=>$id, 'title' => $item['lp_name']);
  101. }
  102. return $return;
  103. }
  104. /**
  105. * Gets progress attained in the given learning path by the given user
  106. *
  107. * @param string User id field name
  108. * @param string User id value
  109. * @param string Course id field name
  110. * @param string Course id value
  111. * @param string Learnpath ID
  112. * @return double Between 0 and 100 (% of progress)
  113. */
  114. public function GetLearnpathProgress($secret_key, $user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $learnpath_id) {
  115. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  116. if($user_id instanceof WSError) {
  117. return $user_id;
  118. }
  119. $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
  120. if($course_id instanceof WSError) {
  121. return $course_id;
  122. } else {
  123. $course_code = CourseManager::get_course_code_from_course_id($course_id);
  124. }
  125. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
  126. $lp = new learnpath($course_code, $learnpath_id, $user_id);
  127. $return = array(
  128. 'progress_bar_mode' => $lp->progress_bar_mode,
  129. 'progress_db' => $lp->progress_db,
  130. );
  131. return $return;
  132. }
  133. /**
  134. * Gets the highest element seen (lesson_location) in the given learning
  135. * path by the given user. If the user saw the learning path several times,
  136. * the last time (lp_view) is assumed. If there are several items in the lp,
  137. * the last item seen (lp_view.last_item) is considered as the relevant one
  138. * to get the lesson_location from.
  139. *
  140. * @param string User id field name
  141. * @param string User id value
  142. * @param string Course id field name
  143. * @param string Course id value
  144. * @param string Learnpath ID
  145. * @return string The last item's lesson_location value
  146. */
  147. public function GetLearnpathHighestLessonLocation($secret_key, $user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $learnpath_id) {
  148. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  149. if($user_id instanceof WSError) {
  150. return $user_id;
  151. }
  152. $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
  153. if($course_id instanceof WSError) {
  154. return $course_id;
  155. } else {
  156. $course_code = CourseManager::get_course_code_from_course_id($course_id);
  157. }
  158. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
  159. $lp = new learnpath($course_code, $learnpath_id, $user_id);
  160. $item = $lp->last_item_seen;
  161. $return = $lp->items[$item]->get_lesson_location();
  162. return $return;
  163. }
  164. /**
  165. * Gets score obtained in the given learning path by the given user,
  166. * assuming there is only one item (SCO) in the learning path
  167. *
  168. * @param string User id field name
  169. * @param string User id value
  170. * @param string Course id field name
  171. * @param string Course id value
  172. * @param int Learnpath ID
  173. * @param int Learnpath *ITEM* ID
  174. * @return double Generally between 0 and 100
  175. */
  176. public function GetLearnpathScoreSingleItem($secret_key, $user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $learnpath_id, $learnpath_item_id) {
  177. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  178. if($user_id instanceof WSError) {
  179. return $user_id;
  180. }
  181. $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
  182. if($course_id instanceof WSError) {
  183. return $course_id;
  184. } else {
  185. $course_code = CourseManager::get_course_code_from_course_id($course_id);
  186. }
  187. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
  188. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathItem.class.php';
  189. $lp = new learnpath($course_code, $learnpath_id, $user_id);
  190. $return = array(
  191. 'min_score' => $lp->items[$learnpath_item_id]->min_score,
  192. 'max_score' => $lp->items[$learnpath_item_id]->max_score,
  193. 'mastery_score' => $lp->items[$learnpath_item_id]->mastery_score,
  194. 'current_score' => $lp->items[$learnpath_item_id]->current_score,
  195. );
  196. return $return;
  197. }
  198. /**
  199. * Gets status obtained in the given learning path by the given user,
  200. * assuming there is only one item (SCO) in the learning path
  201. *
  202. * @param string Secret key
  203. * @param string User id field name (use chamilo_user_id if none)
  204. * @param string User id value
  205. * @param string Course id field name (use chamilo_course_id if none)
  206. * @param string Course id value
  207. * @param int Learnpath ID
  208. * @param int Learnpath *ITEM* ID
  209. * @return string "not attempted", "passed", "completed", "failed", "incomplete"
  210. */
  211. public function GetLearnpathStatusSingleItem($secret_key, $user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $learnpath_id, $learnpath_item_id) {
  212. $verifKey = $this->verifyKey($secret_key);
  213. if($verifKey instanceof WSError) {
  214. $this->handleError($verifKey);
  215. } else {
  216. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  217. if($user_id instanceof WSError) {
  218. return $user_id;
  219. }
  220. $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
  221. if($course_id instanceof WSError) {
  222. return $course_id;
  223. } else {
  224. $course_code = CourseManager::get_course_code_from_course_id($course_id);
  225. }
  226. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
  227. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathItem.class.php';
  228. $lp = new learnpath($course_code, $learnpath_id, $user_id);
  229. return $lp->items[$learnpath_item_id]->status;
  230. }
  231. }
  232. public function test() {
  233. return 'Hello world!';
  234. }
  235. }