webservice_report.php 10 KB

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