webservice_report.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. }
  45. return Tracking::get_time_spent_on_the_course($user_id, $course_id);
  46. }
  47. /**
  48. * Gets the time spent in a course by a given user
  49. *
  50. * @param string User id field name
  51. * @param string User id value
  52. * @param string Course id field name
  53. * @param string Course id value
  54. * @return array Array of results
  55. */
  56. public function GetTimeSpentOnCourseInSession($user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $session_id_field_name, $session_id_value) {
  57. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  58. if($user_id instanceof WSError) {
  59. return $user_id;
  60. }
  61. $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
  62. if ($course_id instanceof WSError) {
  63. return $course_id;
  64. }
  65. $session_id = $this->getSessionId($session_id_field_name, $session_id_value);
  66. if ($session_id instanceof WSError) {
  67. return $session_id;
  68. }
  69. return Tracking::get_time_spent_on_the_course($user_id, $course_id, $session_id);
  70. }
  71. /**
  72. * Gets a list of learning paths by course
  73. *
  74. * @param string User id field name
  75. * @param string User id value
  76. * @param string Course id field name
  77. * @param string Course id value
  78. * @return array Array of id=>title of learning paths
  79. */
  80. public function GetLearnpathsByCourse($secret_key, $user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value) {
  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($course_id_field_name, $course_id_value);
  86. if($course_id instanceof WSError) {
  87. return $course_id;
  88. } else {
  89. $course_code = CourseManager::get_course_code_from_course_id($course_id);
  90. }
  91. $lp = new LearnpathList($user_id,$course_code);
  92. $list = $lp->list;
  93. $return = array();
  94. foreach ($list as $id => $item) {
  95. $return[] = array('id'=>$id, 'title' => $item['lp_name']);
  96. }
  97. return $return;
  98. }
  99. /**
  100. * Gets progress attained in the given learning path by the given user
  101. *
  102. * @param string User id field name
  103. * @param string User id value
  104. * @param string Course id field name
  105. * @param string Course id value
  106. * @param string Learnpath ID
  107. * @return double Between 0 and 100 (% of progress)
  108. */
  109. public function GetLearnpathProgress($secret_key, $user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $learnpath_id) {
  110. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  111. if($user_id instanceof WSError) {
  112. return $user_id;
  113. }
  114. $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
  115. if($course_id instanceof WSError) {
  116. return $course_id;
  117. } else {
  118. $course_code = CourseManager::get_course_code_from_course_id($course_id);
  119. }
  120. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
  121. $lp = new learnpath($course_code, $learnpath_id, $user_id);
  122. $items = $lp->items[$learnpath_id];
  123. $return = array(
  124. 'progress_bar_mode' => $lp->progress_bar_mode,
  125. 'progress_db' => $lp->progress_db,
  126. );
  127. return $return;
  128. }
  129. /**
  130. * Gets score obtained in the given learning path by the given user,
  131. * assuming there is only one item (SCO) in the learning path
  132. *
  133. * @param string User id field name
  134. * @param string User id value
  135. * @param string Course id field name
  136. * @param string Course id value
  137. * @param int Learnpath ID
  138. * @param int Learnpath *ITEM* ID
  139. * @return double Generally between 0 and 100
  140. */
  141. public function GetLearnpathScoreSingleItem($secret_key, $user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $learnpath_id, $learnpath_item_id) {
  142. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  143. if($user_id instanceof WSError) {
  144. return $user_id;
  145. }
  146. $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
  147. if($course_id instanceof WSError) {
  148. return $course_id;
  149. } else {
  150. $course_code = CourseManager::get_course_code_from_course_id($course_id);
  151. }
  152. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
  153. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathItem.class.php';
  154. $lp = new learnpath($course_code, $learnpath_id, $user_id);
  155. $return = array(
  156. 'min_score' => $lp->items[$learnpath_item_id]->min_score,
  157. 'max_score' => $lp->items[$learnpath_item_id]->max_score,
  158. 'mastery_score' => $lp->items[$learnpath_item_id]->mastery_score,
  159. 'current_score' => $lp->items[$learnpath_item_id]->current_score,
  160. );
  161. return $return;
  162. }
  163. /**
  164. * Gets status obtained in the given learning path by the given user,
  165. * assuming there is only one item (SCO) in the learning path
  166. *
  167. * @param string Secret key
  168. * @param string User id field name (use chamilo_user_id if none)
  169. * @param string User id value
  170. * @param string Course id field name (use chamilo_course_id if none)
  171. * @param string Course id value
  172. * @param int Learnpath ID
  173. * @param int Learnpath *ITEM* ID
  174. * @return string "not attempted", "passed", "completed", "failed", "incomplete"
  175. */
  176. public function GetLearnpathStatusSingleItem($secret_key, $user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $learnpath_id, $learnpath_item_id) {
  177. $verifKey = $this->verifyKey($secret_key);
  178. if($verifKey instanceof WSError) {
  179. $this->handleError($verifKey);
  180. } else {
  181. $user_id = $this->getUserId($user_id_field_name, $user_id_value);
  182. if($user_id instanceof WSError) {
  183. return $user_id;
  184. }
  185. $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
  186. if($course_id instanceof WSError) {
  187. return $course_id;
  188. } else {
  189. $course_code = CourseManager::get_course_code_from_course_id($course_id);
  190. }
  191. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
  192. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathItem.class.php';
  193. $lp = new learnpath($course_code, $learnpath_id, $user_id);
  194. return $lp->items[$learnpath_item_id]->status;
  195. }
  196. }
  197. public function test() {
  198. return 'Hello world!';
  199. }
  200. }