webservice_report.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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_id);
  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_id, $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. $lp = new LearnpathList($user_id,$course_code);
  96. $list = $lp->list;
  97. $return = array();
  98. foreach ($list as $id => $item) {
  99. $return[] = array('id'=>$id, 'title' => $item['lp_name']);
  100. }
  101. return $return;
  102. }
  103. /**
  104. * Gets progress attained in the given learning path by the given user
  105. *
  106. * @param string User id field name
  107. * @param string User id value
  108. * @param string Course id field name
  109. * @param string Course id value
  110. * @param string Learnpath ID
  111. * @return double Between 0 and 100 (% of progress)
  112. */
  113. public function GetLearnpathProgress($secret_key, $user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $learnpath_id) {
  114. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  115. if($user_id instanceof WSError) {
  116. return $user_id;
  117. }
  118. $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
  119. if($course_id instanceof WSError) {
  120. return $course_id;
  121. } else {
  122. $course_code = CourseManager::get_course_code_from_course_id($course_id);
  123. }
  124. $lp = new learnpath($course_code, $learnpath_id, $user_id);
  125. $return = array(
  126. 'progress_bar_mode' => $lp->progress_bar_mode,
  127. 'progress_db' => $lp->progress_db,
  128. );
  129. return $return;
  130. }
  131. /**
  132. * Gets the highest element seen (lesson_location) in the given learning
  133. * path by the given user. If the user saw the learning path several times,
  134. * the last time (lp_view) is assumed. If there are several items in the lp,
  135. * the last item seen (lp_view.last_item) is considered as the relevant one
  136. * to get the lesson_location from.
  137. *
  138. * @param string User id field name
  139. * @param string User id value
  140. * @param string Course id field name
  141. * @param string Course id value
  142. * @param string Learnpath ID
  143. * @return string The last item's lesson_location value
  144. */
  145. public function GetLearnpathHighestLessonLocation($secret_key, $user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $learnpath_id) {
  146. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  147. if($user_id instanceof WSError) {
  148. return $user_id;
  149. }
  150. $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
  151. if($course_id instanceof WSError) {
  152. return $course_id;
  153. } else {
  154. $course_code = CourseManager::get_course_code_from_course_id($course_id);
  155. }
  156. $lp = new learnpath($course_code, $learnpath_id, $user_id);
  157. $item = $lp->last_item_seen;
  158. $return = $lp->items[$item]->get_lesson_location();
  159. return $return;
  160. }
  161. /**
  162. * Gets score obtained in the given learning path by the given user,
  163. * assuming there is only one item (SCO) in the learning path
  164. *
  165. * @param string User id field name
  166. * @param string User id value
  167. * @param string Course id field name
  168. * @param string Course id value
  169. * @param int Learnpath ID
  170. * @param int Learnpath *ITEM* ID
  171. * @return double Generally between 0 and 100
  172. */
  173. public function GetLearnpathScoreSingleItem($secret_key, $user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $learnpath_id, $learnpath_item_id) {
  174. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  175. if($user_id instanceof WSError) {
  176. return $user_id;
  177. }
  178. $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
  179. if($course_id instanceof WSError) {
  180. return $course_id;
  181. } else {
  182. $course_code = CourseManager::get_course_code_from_course_id($course_id);
  183. }
  184. $lp = new learnpath($course_code, $learnpath_id, $user_id);
  185. $return = array(
  186. 'min_score' => $lp->items[$learnpath_item_id]->min_score,
  187. 'max_score' => $lp->items[$learnpath_item_id]->max_score,
  188. 'mastery_score' => $lp->items[$learnpath_item_id]->mastery_score,
  189. 'current_score' => $lp->items[$learnpath_item_id]->current_score,
  190. );
  191. return $return;
  192. }
  193. /**
  194. * Gets status obtained in the given learning path by the given user,
  195. * assuming there is only one item (SCO) in the learning path
  196. *
  197. * @param string Secret key
  198. * @param string User id field name (use chamilo_user_id if none)
  199. * @param string User id value
  200. * @param string Course id field name (use chamilo_course_id if none)
  201. * @param string Course id value
  202. * @param int Learnpath ID
  203. * @param int Learnpath *ITEM* ID
  204. * @return string "not attempted", "passed", "completed", "failed", "incomplete"
  205. */
  206. public function GetLearnpathStatusSingleItem($secret_key, $user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $learnpath_id, $learnpath_item_id) {
  207. $verifKey = $this->verifyKey($secret_key);
  208. if($verifKey instanceof WSError) {
  209. $this->handleError($verifKey);
  210. } else {
  211. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  212. if($user_id instanceof WSError) {
  213. return $user_id;
  214. }
  215. $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
  216. if($course_id instanceof WSError) {
  217. return $course_id;
  218. } else {
  219. $course_code = CourseManager::get_course_code_from_course_id($course_id);
  220. }
  221. $lp = new learnpath($course_code, $learnpath_id, $user_id);
  222. return $lp->items[$learnpath_item_id]->status;
  223. }
  224. }
  225. public function test() {
  226. return 'Hello world!';
  227. }
  228. }