webservice_report.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. $items = $lp->items[$learnpath_id];
  128. $return = array(
  129. 'progress_bar_mode' => $lp->progress_bar_mode,
  130. 'progress_db' => $lp->progress_db,
  131. );
  132. return $return;
  133. }
  134. /**
  135. * Gets score obtained in the given learning path by the given user,
  136. * assuming there is only one item (SCO) in the learning path
  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 double Generally between 0 and 100
  144. */
  145. public function GetLearnpathScoreSingleItem($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. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
  157. $lp = new learnpath($course_code, $learnpath_id, $user_id);
  158. $return = array(
  159. 'min_score' => $lp->items[$learnpath_id]->min_score,
  160. 'max_score' => $lp->items[$learnpath_id]->max_score,
  161. 'mastery_score' => $lp->items[$learnpath_id]->mastery_score,
  162. 'current_score' => $lp->items[$learnpath_id]->current_score,
  163. );
  164. return $return;
  165. }
  166. /**
  167. * Gets status obtained in the given learning path by the given user,
  168. * assuming there is only one item (SCO) in the learning path
  169. *
  170. * @param string Secret key
  171. * @param string User id field name (use chamilo_user_id if none)
  172. * @param string User id value
  173. * @param string Course id field name (use chamilo_course_id if none)
  174. * @param string Course id value
  175. * @param string Learnpath ID
  176. * @return string "not attempted", "passed", "completed", "failed", "incomplete"
  177. */
  178. public function GetLearnpathStatusSingleItem($secret_key, $user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $learnpath_id) {
  179. $verifKey = $this->verifyKey($secret_key);
  180. if($verifKey instanceof WSError) {
  181. $this->handleError($verifKey);
  182. } else {
  183. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  184. if($user_id instanceof WSError) {
  185. return $user_id;
  186. }
  187. $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
  188. if($course_id instanceof WSError) {
  189. return $course_id;
  190. } else {
  191. $course_code = CourseManager::get_course_code_from_course_id($course_id);
  192. }
  193. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
  194. $lp = new learnpath($course_code, $learnpath_id, $user_id);
  195. return $lp->items[$learnpath_id]->status;
  196. }
  197. }
  198. public function test() {
  199. return 'Hello world!';
  200. }
  201. }