webservice_report.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.webservices
  5. */
  6. require_once __DIR__.'/../inc/global.inc.php';
  7. require_once __DIR__.'/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. /**
  14. * Gets the time spent on the platform by a given user
  15. *
  16. * @param string User id field name
  17. * @param string User id value
  18. * @return array Array of results
  19. */
  20. public function GetTimeSpentOnPlatform($user_id_field_name, $user_id_value)
  21. {
  22. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  23. if ($user_id instanceof WSError) {
  24. return $user_id;
  25. } else {
  26. return Tracking::get_time_spent_on_the_platform($user_id);
  27. }
  28. }
  29. /**
  30. * Gets the time spent in a course by a given user
  31. *
  32. * @param string User id field name
  33. * @param string User id value
  34. * @param string Course id field name
  35. * @param string Course id value
  36. * @return array Array of results
  37. */
  38. public function GetTimeSpentOnCourse(
  39. $user_id_field_name,
  40. $user_id_value,
  41. $course_id_field_name,
  42. $course_id_value
  43. ) {
  44. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  45. if ($user_id instanceof WSError) {
  46. return $user_id;
  47. }
  48. $course_id = $this->getCourseId(
  49. $course_id_field_name,
  50. $course_id_value
  51. );
  52. if ($course_id instanceof WSError) {
  53. return $course_id;
  54. } else {
  55. $course_code = CourseManager::get_course_code_from_course_id(
  56. $course_id
  57. );
  58. }
  59. return Tracking::get_time_spent_on_the_course($user_id, $course_id);
  60. }
  61. /**
  62. * Gets the time spent in a course by a given user
  63. *
  64. * @param string User id field name
  65. * @param string User id value
  66. * @param string Course id field name
  67. * @param string Course id value
  68. * @return array Array of results
  69. */
  70. public function GetTimeSpentOnCourseInSession(
  71. $user_id_field_name,
  72. $user_id_value,
  73. $course_id_field_name,
  74. $course_id_value,
  75. $session_id_field_name,
  76. $session_id_value
  77. ) {
  78. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  79. if ($user_id instanceof WSError) {
  80. return $user_id;
  81. }
  82. $course_id = $this->getCourseId(
  83. $course_id_field_name,
  84. $course_id_value
  85. );
  86. if ($course_id instanceof WSError) {
  87. return $course_id;
  88. } else {
  89. $course_code = CourseManager::get_course_code_from_course_id(
  90. $course_id
  91. );
  92. }
  93. $session_id = $this->getSessionId(
  94. $session_id_field_name,
  95. $session_id_value
  96. );
  97. if ($session_id instanceof WSError) {
  98. return $session_id;
  99. }
  100. return Tracking::get_time_spent_on_the_course(
  101. $user_id,
  102. $course_id,
  103. $session_id
  104. );
  105. }
  106. /**
  107. * Gets a list of learning paths by course
  108. *
  109. * @param string User id field name
  110. * @param string User id value
  111. * @param string Course id field name
  112. * @param string Course id value
  113. * @return array Array of id=>title of learning paths
  114. */
  115. public function GetLearnpathsByCourse(
  116. $secret_key,
  117. $user_id_field_name,
  118. $user_id_value,
  119. $course_id_field_name,
  120. $course_id_value
  121. ) {
  122. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  123. if ($user_id instanceof WSError) {
  124. return $user_id;
  125. }
  126. $course_id = $this->getCourseId(
  127. $course_id_field_name,
  128. $course_id_value
  129. );
  130. if ($course_id instanceof WSError) {
  131. return $course_id;
  132. } else {
  133. $course_code = CourseManager::get_course_code_from_course_id(
  134. $course_id
  135. );
  136. }
  137. $lp = new LearnpathList($user_id, $course_code);
  138. $list = $lp->list;
  139. $return = array();
  140. foreach ($list as $id => $item) {
  141. $return[] = array('id' => $id, 'title' => $item['lp_name']);
  142. }
  143. return $return;
  144. }
  145. /**
  146. * Gets progress attained in the given learning path by the given user
  147. *
  148. * @param string User id field name
  149. * @param string User id value
  150. * @param string Course id field name
  151. * @param string Course id value
  152. * @param string Learnpath ID
  153. * @return double Between 0 and 100 (% of progress)
  154. */
  155. public function GetLearnpathProgress(
  156. $secret_key,
  157. $user_id_field_name,
  158. $user_id_value,
  159. $course_id_field_name,
  160. $course_id_value,
  161. $learnpath_id
  162. ) {
  163. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  164. if ($user_id instanceof WSError) {
  165. return $user_id;
  166. }
  167. $course_id = $this->getCourseId(
  168. $course_id_field_name,
  169. $course_id_value
  170. );
  171. if ($course_id instanceof WSError) {
  172. return $course_id;
  173. } else {
  174. $course_code = CourseManager::get_course_code_from_course_id(
  175. $course_id
  176. );
  177. }
  178. $lp = new learnpath($course_code, $learnpath_id, $user_id);
  179. $return = array(
  180. 'progress_bar_mode' => $lp->progress_bar_mode,
  181. 'progress_db' => $lp->progress_db,
  182. );
  183. return $return;
  184. }
  185. /**
  186. * Gets the highest element seen (lesson_location) in the given learning
  187. * path by the given user. If the user saw the learning path several times,
  188. * the last time (lp_view) is assumed. If there are several items in the lp,
  189. * the last item seen (lp_view.last_item) is considered as the relevant one
  190. * to get the lesson_location from.
  191. *
  192. * @param string User id field name
  193. * @param string User id value
  194. * @param string Course id field name
  195. * @param string Course id value
  196. * @param string Learnpath ID
  197. * @return string The last item's lesson_location value
  198. */
  199. public function GetLearnpathHighestLessonLocation(
  200. $secret_key,
  201. $user_id_field_name,
  202. $user_id_value,
  203. $course_id_field_name,
  204. $course_id_value,
  205. $learnpath_id
  206. ) {
  207. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  208. if ($user_id instanceof WSError) {
  209. return $user_id;
  210. }
  211. $course_id = $this->getCourseId(
  212. $course_id_field_name,
  213. $course_id_value
  214. );
  215. if ($course_id instanceof WSError) {
  216. return $course_id;
  217. } else {
  218. $course_code = CourseManager::get_course_code_from_course_id(
  219. $course_id
  220. );
  221. }
  222. $lp = new learnpath($course_code, $learnpath_id, $user_id);
  223. $item = $lp->last_item_seen;
  224. $return = $lp->items[$item]->get_lesson_location();
  225. return $return;
  226. }
  227. /**
  228. * Gets score obtained in the given learning path by the given user,
  229. * assuming there is only one item (SCO) in the learning path
  230. *
  231. * @param string User id field name
  232. * @param string User id value
  233. * @param string Course id field name
  234. * @param string Course id value
  235. * @param int Learnpath ID
  236. * @param int Learnpath *ITEM* ID
  237. * @return double Generally between 0 and 100
  238. */
  239. public function GetLearnpathScoreSingleItem(
  240. $secret_key,
  241. $user_id_field_name,
  242. $user_id_value,
  243. $course_id_field_name,
  244. $course_id_value,
  245. $learnpath_id,
  246. $learnpath_item_id
  247. ) {
  248. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  249. if ($user_id instanceof WSError) {
  250. return $user_id;
  251. }
  252. $course_id = $this->getCourseId(
  253. $course_id_field_name,
  254. $course_id_value
  255. );
  256. if ($course_id instanceof WSError) {
  257. return $course_id;
  258. } else {
  259. $course_code = CourseManager::get_course_code_from_course_id(
  260. $course_id
  261. );
  262. }
  263. $lp = new learnpath($course_code, $learnpath_id, $user_id);
  264. $return = array(
  265. 'min_score' => $lp->items[$learnpath_item_id]->min_score,
  266. 'max_score' => $lp->items[$learnpath_item_id]->max_score,
  267. 'mastery_score' => $lp->items[$learnpath_item_id]->mastery_score,
  268. 'current_score' => $lp->items[$learnpath_item_id]->current_score,
  269. );
  270. return $return;
  271. }
  272. /**
  273. * Gets status obtained in the given learning path by the given user,
  274. * assuming there is only one item (SCO) in the learning path
  275. *
  276. * @param string Secret key
  277. * @param string User id field name (use chamilo_user_id if none)
  278. * @param string User id value
  279. * @param string Course id field name (use chamilo_course_id if none)
  280. * @param string Course id value
  281. * @param int Learnpath ID
  282. * @param int Learnpath *ITEM* ID
  283. * @return string "not attempted", "passed", "completed", "failed", "incomplete"
  284. */
  285. public function GetLearnpathStatusSingleItem(
  286. $secret_key,
  287. $user_id_field_name,
  288. $user_id_value,
  289. $course_id_field_name,
  290. $course_id_value,
  291. $learnpath_id,
  292. $learnpath_item_id
  293. ) {
  294. $verifKey = $this->verifyKey($secret_key);
  295. if ($verifKey instanceof WSError) {
  296. $this->handleError($verifKey);
  297. } else {
  298. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  299. if ($user_id instanceof WSError) {
  300. return $user_id;
  301. }
  302. $course_id = $this->getCourseId(
  303. $course_id_field_name,
  304. $course_id_value
  305. );
  306. if ($course_id instanceof WSError) {
  307. return $course_id;
  308. } else {
  309. $course_code = CourseManager::get_course_code_from_course_id(
  310. $course_id
  311. );
  312. }
  313. $lp = new learnpath($course_code, $learnpath_id, $user_id);
  314. return $lp->items[$learnpath_item_id]->status;
  315. }
  316. }
  317. public function test()
  318. {
  319. return 'Hello world!';
  320. }
  321. }