123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- <?php
- /* For licensing terms, see /license.txt */
- /**
- * @package chamilo.webservices
- */
- require_once __DIR__.'/../inc/global.inc.php';
- require_once __DIR__.'/webservice.php';
- /**
- * Web services available for the User module. This class extends the WS class
- */
- class WSReport extends WS
- {
- /**
- * Gets the time spent on the platform by a given user
- *
- * @param string User id field name
- * @param string User id value
- * @return array Array of results
- */
- public function GetTimeSpentOnPlatform($user_id_field_name, $user_id_value)
- {
- $user_id = $this->getUserId($user_id_field_name, $user_id_value);
- if ($user_id instanceof WSError) {
- return $user_id;
- } else {
- return Tracking::get_time_spent_on_the_platform($user_id);
- }
- }
- /**
- * Gets the time spent in a course by a given user
- *
- * @param string User id field name
- * @param string User id value
- * @param string Course id field name
- * @param string Course id value
- * @return array Array of results
- */
- public function GetTimeSpentOnCourse(
- $user_id_field_name,
- $user_id_value,
- $course_id_field_name,
- $course_id_value
- ) {
- $user_id = $this->getUserId($user_id_field_name, $user_id_value);
- if ($user_id instanceof WSError) {
- return $user_id;
- }
- $course_id = $this->getCourseId(
- $course_id_field_name,
- $course_id_value
- );
- if ($course_id instanceof WSError) {
- return $course_id;
- } else {
- $course_code = CourseManager::get_course_code_from_course_id(
- $course_id
- );
- }
- return Tracking::get_time_spent_on_the_course($user_id, $course_id);
- }
- /**
- * Gets the time spent in a course by a given user
- *
- * @param string User id field name
- * @param string User id value
- * @param string Course id field name
- * @param string Course id value
- * @return array Array of results
- */
- public function GetTimeSpentOnCourseInSession(
- $user_id_field_name,
- $user_id_value,
- $course_id_field_name,
- $course_id_value,
- $session_id_field_name,
- $session_id_value
- ) {
- $user_id = $this->getUserId($user_id_field_name, $user_id_value);
- if ($user_id instanceof WSError) {
- return $user_id;
- }
- $course_id = $this->getCourseId(
- $course_id_field_name,
- $course_id_value
- );
- if ($course_id instanceof WSError) {
- return $course_id;
- } else {
- $course_code = CourseManager::get_course_code_from_course_id(
- $course_id
- );
- }
- $session_id = $this->getSessionId(
- $session_id_field_name,
- $session_id_value
- );
- if ($session_id instanceof WSError) {
- return $session_id;
- }
- return Tracking::get_time_spent_on_the_course(
- $user_id,
- $course_id,
- $session_id
- );
- }
- /**
- * Gets a list of learning paths by course
- *
- * @param string User id field name
- * @param string User id value
- * @param string Course id field name
- * @param string Course id value
- * @return array Array of id=>title of learning paths
- */
- public function GetLearnpathsByCourse(
- $secret_key,
- $user_id_field_name,
- $user_id_value,
- $course_id_field_name,
- $course_id_value
- ) {
- $user_id = $this->getUserId($user_id_field_name, $user_id_value);
- if ($user_id instanceof WSError) {
- return $user_id;
- }
- $course_id = $this->getCourseId(
- $course_id_field_name,
- $course_id_value
- );
- if ($course_id instanceof WSError) {
- return $course_id;
- } else {
- $course_code = CourseManager::get_course_code_from_course_id(
- $course_id
- );
- }
- $lp = new LearnpathList($user_id, $course_code);
- $list = $lp->list;
- $return = array();
- foreach ($list as $id => $item) {
- $return[] = array('id' => $id, 'title' => $item['lp_name']);
- }
- return $return;
- }
- /**
- * Gets progress attained in the given learning path by the given user
- *
- * @param string User id field name
- * @param string User id value
- * @param string Course id field name
- * @param string Course id value
- * @param string Learnpath ID
- * @return double Between 0 and 100 (% of progress)
- */
- public function GetLearnpathProgress(
- $secret_key,
- $user_id_field_name,
- $user_id_value,
- $course_id_field_name,
- $course_id_value,
- $learnpath_id
- ) {
- $user_id = $this->getUserId($user_id_field_name, $user_id_value);
- if ($user_id instanceof WSError) {
- return $user_id;
- }
- $course_id = $this->getCourseId(
- $course_id_field_name,
- $course_id_value
- );
- if ($course_id instanceof WSError) {
- return $course_id;
- } else {
- $course_code = CourseManager::get_course_code_from_course_id(
- $course_id
- );
- }
- $lp = new learnpath($course_code, $learnpath_id, $user_id);
- $return = array(
- 'progress_bar_mode' => $lp->progress_bar_mode,
- 'progress_db' => $lp->progress_db,
- );
- return $return;
- }
- /**
- * Gets the highest element seen (lesson_location) in the given learning
- * path by the given user. If the user saw the learning path several times,
- * the last time (lp_view) is assumed. If there are several items in the lp,
- * the last item seen (lp_view.last_item) is considered as the relevant one
- * to get the lesson_location from.
- *
- * @param string User id field name
- * @param string User id value
- * @param string Course id field name
- * @param string Course id value
- * @param string Learnpath ID
- * @return string The last item's lesson_location value
- */
- public function GetLearnpathHighestLessonLocation(
- $secret_key,
- $user_id_field_name,
- $user_id_value,
- $course_id_field_name,
- $course_id_value,
- $learnpath_id
- ) {
- $user_id = $this->getUserId($user_id_field_name, $user_id_value);
- if ($user_id instanceof WSError) {
- return $user_id;
- }
- $course_id = $this->getCourseId(
- $course_id_field_name,
- $course_id_value
- );
- if ($course_id instanceof WSError) {
- return $course_id;
- } else {
- $course_code = CourseManager::get_course_code_from_course_id(
- $course_id
- );
- }
- $lp = new learnpath($course_code, $learnpath_id, $user_id);
- $item = $lp->last_item_seen;
- $return = $lp->items[$item]->get_lesson_location();
- return $return;
- }
- /**
- * Gets score obtained in the given learning path by the given user,
- * assuming there is only one item (SCO) in the learning path
- *
- * @param string User id field name
- * @param string User id value
- * @param string Course id field name
- * @param string Course id value
- * @param int Learnpath ID
- * @param int Learnpath *ITEM* ID
- * @return double Generally between 0 and 100
- */
- public function GetLearnpathScoreSingleItem(
- $secret_key,
- $user_id_field_name,
- $user_id_value,
- $course_id_field_name,
- $course_id_value,
- $learnpath_id,
- $learnpath_item_id
- ) {
- $user_id = $this->getUserId($user_id_field_name, $user_id_value);
- if ($user_id instanceof WSError) {
- return $user_id;
- }
- $course_id = $this->getCourseId(
- $course_id_field_name,
- $course_id_value
- );
- if ($course_id instanceof WSError) {
- return $course_id;
- } else {
- $course_code = CourseManager::get_course_code_from_course_id(
- $course_id
- );
- }
- $lp = new learnpath($course_code, $learnpath_id, $user_id);
- $return = array(
- 'min_score' => $lp->items[$learnpath_item_id]->min_score,
- 'max_score' => $lp->items[$learnpath_item_id]->max_score,
- 'mastery_score' => $lp->items[$learnpath_item_id]->mastery_score,
- 'current_score' => $lp->items[$learnpath_item_id]->current_score,
- );
- return $return;
- }
- /**
- * Gets status obtained in the given learning path by the given user,
- * assuming there is only one item (SCO) in the learning path
- *
- * @param string Secret key
- * @param string User id field name (use chamilo_user_id if none)
- * @param string User id value
- * @param string Course id field name (use chamilo_course_id if none)
- * @param string Course id value
- * @param int Learnpath ID
- * @param int Learnpath *ITEM* ID
- * @return string "not attempted", "passed", "completed", "failed", "incomplete"
- */
- public function GetLearnpathStatusSingleItem(
- $secret_key,
- $user_id_field_name,
- $user_id_value,
- $course_id_field_name,
- $course_id_value,
- $learnpath_id,
- $learnpath_item_id
- ) {
- $verifKey = $this->verifyKey($secret_key);
- if ($verifKey instanceof WSError) {
- $this->handleError($verifKey);
- } else {
- $user_id = $this->getUserId($user_id_field_name, $user_id_value);
- if ($user_id instanceof WSError) {
- return $user_id;
- }
- $course_id = $this->getCourseId(
- $course_id_field_name,
- $course_id_value
- );
- if ($course_id instanceof WSError) {
- return $course_id;
- } else {
- $course_code = CourseManager::get_course_code_from_course_id(
- $course_id
- );
- }
- $lp = new learnpath($course_code, $learnpath_id, $user_id);
- return $lp->items[$learnpath_item_id]->status;
- }
- }
- public function test()
- {
- return 'Hello world!';
- }
- }
|