webservice_report.php 8.4 KB

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