Minor - Format code

pull/2487/head
jmontoyaa 8 years ago
parent 62720eecd1
commit a077c29109
  1. 71
      main/webservices/cm_webservice_announcements.php
  2. 216
      main/webservices/soap_report.php
  3. 120
      main/webservices/soap_session.php
  4. 399
      main/webservices/soap_user.php
  5. 125
      main/webservices/user_info.soap.php
  6. 462
      main/webservices/webservice.php
  7. 1138
      main/webservices/webservice_course.php
  8. 203
      main/webservices/webservice_report.php
  9. 992
      main/webservices/webservice_session.php
  10. 1029
      main/webservices/webservice_user.php

@ -18,67 +18,82 @@ class WSCMAnnouncements extends WSCM
public function get_announcements_id($username, $password, $course_code)
{
if ($this->verifyUserPass($username, $password) == "valid")
{
if ($this->verifyUserPass($username, $password) == "valid") {
$result = self::get_announcements($username, $course_code);
$announcements = "#";
while ($announcement = Database::fetch_array($result)) {
$announcements .= $announcement['id']."#";
}
return $announcements;
} else
} else {
return get_lang('InvalidId');
}
}
public function get_announcement_data($username, $password, $course_code, $announcement_id, $field)
{
if ($this->verifyUserPass($username, $password) == "valid")
{
public function get_announcement_data(
$username,
$password,
$course_code,
$announcement_id,
$field
) {
if ($this->verifyUserPass($username, $password) == "valid") {
$htmlcode = false;
$user_id = UserManager::get_user_id_from_username($username);
$result = self::get_announcements($username, $course_code, $announcement_id);
while ($announcement = Database::fetch_array($result))
{
$result = self::get_announcements(
$username,
$course_code,
$announcement_id
);
while ($announcement = Database::fetch_array($result)) {
$announcements[] = $announcement;
}
switch ($field)
{
switch ($field) {
case 'sender':
$field_table = "insert_user_id";
$sender = api_get_user_info($announcements[0][$field_table]);
$sender = api_get_user_info(
$announcements[0][$field_table]
);
$announcements[0][$field_table] = $sender['firstname']." ".$sender['lastname'];
break;
case 'title' :
case 'title':
$htmlcode = true;
$field_table = "title";
break;
case 'date' :
case 'date':
$field_table = "end_date";
break;
case 'content' :
case 'content':
$htmlcode = true;
$field_table = "content";
$announcements[0][$field_table] = nl2br_revert($announcements[0][$field_table]);
$announcements[0][$field_table] = nl2br_revert(
$announcements[0][$field_table]
);
break;
default:
$field_table = "title";
}
return (htmlcode) ? html_entity_decode($announcements[0][$field_table]) : $announcements[0][$field_table];
return (htmlcode) ? html_entity_decode(
$announcements[0][$field_table]
) : $announcements[0][$field_table];
} else
} else {
return get_lang('InvalidId');
}
}
private function get_announcements($username, $course_code, $announcement_id = 0)
{
private function get_announcements(
$username,
$course_code,
$announcement_id = 0
) {
$session_id = api_get_session_id();
$condition_session = api_get_session_condition($session_id);
@ -89,7 +104,10 @@ class WSCMAnnouncements extends WSCM
$tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
$maximum = '12';
$group_memberships = GroupManager::get_group_ids($course_info['real_id'], $user_id);
$group_memberships = GroupManager::get_group_ids(
$course_info['real_id'],
$user_id
);
if (api_get_group_id() == 0) {
$cond_user_id = " AND (
@ -125,7 +143,6 @@ class WSCMAnnouncements extends WSCM
// the user is not member of any group
// this is an identified user => show the general announcements AND his personal announcements
if ($user_id) {
if ((api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
$cond_user_id = " AND (
ip.lastedit_user_id = '".api_get_user_id()."' OR
@ -149,7 +166,6 @@ class WSCMAnnouncements extends WSCM
ORDER BY display_order DESC
LIMIT 0,$maximum";
} else {
if (api_get_course_setting('allow_user_edit_announcement')) {
$cond_user_id = " AND (
ip.lastedit_user_id = '".api_get_user_id()."' OR ip.to_group_id='0' OR ip.to_group_id IS NULL
@ -178,9 +194,6 @@ class WSCMAnnouncements extends WSCM
return $result;
}
}
/*

@ -9,15 +9,21 @@ require_once __DIR__.'/soap.php';
$s = WSSoapServer::singleton();
$s->wsdl->addComplexType(
'user_id',
'complexType',
'struct',
'all',
'',
array(
'user_id_field_name' => array('name' => 'user_id_field_name', 'type' => 'xsd:string'),
'user_id_value' => array('name' => 'user_id_value', 'type' => 'xsd:string')
)
'user_id',
'complexType',
'struct',
'all',
'',
array(
'user_id_field_name' => array(
'name' => 'user_id_field_name',
'type' => 'xsd:string',
),
'user_id_value' => array(
'name' => 'user_id_value',
'type' => 'xsd:string',
),
)
);
$s->wsdl->addComplexType(
@ -27,8 +33,14 @@ $s->wsdl->addComplexType(
'all',
'',
array(
'course_id_field_name' => array('name' => 'course_id_field_name', 'type' => 'xsd:string'),
'course_id_value' => array('name' => 'course_id_value', 'type' => 'xsd:string')
'course_id_field_name' => array(
'name' => 'course_id_field_name',
'type' => 'xsd:string',
),
'course_id_value' => array(
'name' => 'course_id_value',
'type' => 'xsd:string',
),
)
);
@ -39,8 +51,14 @@ $s->wsdl->addComplexType(
'all',
'',
array(
'session_id_field_name' => array('name' => 'session_id_field_name', 'type' => 'xsd:string'),
'session_id_value' => array('name' => 'session_id_value', 'type' => 'xsd:string')
'session_id_field_name' => array(
'name' => 'session_id_field_name',
'type' => 'xsd:string',
),
'session_id_value' => array(
'name' => 'session_id_value',
'type' => 'xsd:string',
),
)
);
@ -59,112 +77,186 @@ $s->wsdl->addComplexType(
$s->wsdl->addComplexType(
'user_result',
'complexType',
'struct',
'all',
'',
array(
'id' => array('name' => 'id', 'type' => 'xsd:string'),
'title' => array('name' => 'title', 'type' => 'xsd:string')
)
'user_result',
'complexType',
'struct',
'all',
'',
array(
'id' => array('name' => 'id', 'type' => 'xsd:string'),
'title' => array('name' => 'title', 'type' => 'xsd:string'),
)
);
$s->wsdl->addComplexType(
'progress_result',
'complexType',
'struct',
'all',
'',
array(
'progress_bar_mode' => array('name' => 'progress_bar_mode', 'type' => 'xsd:string'),
'progress_db' => array('name' => 'progress_db', 'type' => 'xsd:string')
)
'progress_result',
'complexType',
'struct',
'all',
'',
array(
'progress_bar_mode' => array(
'name' => 'progress_bar_mode',
'type' => 'xsd:string',
),
'progress_db' => array('name' => 'progress_db', 'type' => 'xsd:string'),
)
);
$s->wsdl->addComplexType(
'score_result',
'complexType',
'struct',
'all',
'',
array(
'min_score' => array('name' => 'min_score', 'type' => 'xsd:string'),
'max_score' => array('name' => 'max_score', 'type' => 'xsd:string'),
'mastery_score' => array('name' => 'mastery_score', 'type' => 'xsd:string'),
'current_score' => array('name' => 'current_score', 'type' => 'xsd:string'),
)
'score_result',
'complexType',
'struct',
'all',
'',
array(
'min_score' => array('name' => 'min_score', 'type' => 'xsd:string'),
'max_score' => array('name' => 'max_score', 'type' => 'xsd:string'),
'mastery_score' => array(
'name' => 'mastery_score',
'type' => 'xsd:string',
),
'current_score' => array(
'name' => 'current_score',
'type' => 'xsd:string',
),
)
);
$s->wsdl->addComplexType(
'user_result_array',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(array('ref'=>'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:user_result[]')),
'tns:user_result'
'user_result_array',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array(
'ref' => 'SOAP-ENC:arrayType',
'wsdl:arrayType' => 'tns:user_result[]',
),
),
'tns:user_result'
);
$s->register(
'WSReport.GetTimeSpentOnPlatform',
array('secret_key' => 'xsd:string', 'user_id_field_name' => 'xsd:string', 'user_id_value' => 'xsd:string'),
array(
'secret_key' => 'xsd:string',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string',
),
array('return' => 'xsd:string')
);
$s->register(
'WSReport.GetTimeSpentOnCourse',
array('secret_key' => 'xsd:string', 'user_id_field_name' => 'xsd:string', 'user_id_value' => 'xsd:string', 'course_id_field_name' => 'xsd:string', 'course_id_value' => 'xsd:string'),
array('return' => 'xsd:string')
array(
'secret_key' => 'xsd:string',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string',
'course_id_field_name' => 'xsd:string',
'course_id_value' => 'xsd:string',
),
array('return' => 'xsd:string')
);
$s->register(
'WSReport.GetTimeSpentOnCourseInSession',
array('secret_key' => 'xsd:string', 'user_id_field_name' => 'xsd:string', 'user_id_value' => 'xsd:string', 'course_id_field_name' => 'xsd:string', 'course_id_value' => 'xsd:string', 'session_id_field_name' => 'xsd:string', 'session_id_value' => 'xsd:string'),
array(
'secret_key' => 'xsd:string',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string',
'course_id_field_name' => 'xsd:string',
'course_id_value' => 'xsd:string',
'session_id_field_name' => 'xsd:string',
'session_id_value' => 'xsd:string',
),
array('return' => 'xsd:string')
);
$s->register(
'WSReport.GetTimeSpentOnLearnpathInCourse',
array('secret_key' => 'xsd:string', 'user_id_field_name' => 'xsd:string', 'user_id_value' => 'xsd:string', 'course_id_field_name' => 'xsd:string', 'course_id_value' => 'xsd:string', 'learnpath_id' => 'xsd:string'),
array(
'secret_key' => 'xsd:string',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string',
'course_id_field_name' => 'xsd:string',
'course_id_value' => 'xsd:string',
'learnpath_id' => 'xsd:string',
),
array('return' => 'xsd:string')
);
$s->register(
'WSReport.GetLearnpathsByCourse',
array('secret_key' => 'xsd:string', 'user_id_field_name' => 'xsd:string', 'user_id_value' => 'xsd:string', 'course_id_field_name' => 'xsd:string', 'course_id_value' => 'xsd:string'),
array(
'secret_key' => 'xsd:string',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string',
'course_id_field_name' => 'xsd:string',
'course_id_value' => 'xsd:string',
),
array('return' => 'tns:user_result_array')
);
$s->register(
'WSReport.GetLearnpathProgress',
array('secret_key' => 'xsd:string', 'user_id_field_name' => 'xsd:string', 'user_id_value' => 'xsd:string', 'course_id_field_name' => 'xsd:string', 'course_id_value' => 'xsd:string', 'learnpath_id' => 'xsd:string'),
array(
'secret_key' => 'xsd:string',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string',
'course_id_field_name' => 'xsd:string',
'course_id_value' => 'xsd:string',
'learnpath_id' => 'xsd:string',
),
array('return' => 'tns:progress_result')
);
$s->register(
'WSReport.GetLearnpathHighestLessonLocation',
array('secret_key' => 'xsd:string', 'user_id_field_name' => 'xsd:string', 'user_id_value' => 'xsd:string', 'course_id_field_name' => 'xsd:string', 'course_id_value' => 'xsd:string', 'learnpath_id' => 'xsd:string'),
array(
'secret_key' => 'xsd:string',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string',
'course_id_field_name' => 'xsd:string',
'course_id_value' => 'xsd:string',
'learnpath_id' => 'xsd:string',
),
array('return' => 'xsd:string')
);
$s->register(
'WSReport.GetLearnpathScoreSingleItem',
array('secret_key' => 'xsd:string', 'user_id_field_name' => 'xsd:string', 'user_id_value' => 'xsd:string', 'course_id_field_name' => 'xsd:string', 'course_id_value' => 'xsd:string', 'learnpath_id' => 'xsd:string', 'learnpath_item_id' => 'xsd:string'),
array(
'secret_key' => 'xsd:string',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string',
'course_id_field_name' => 'xsd:string',
'course_id_value' => 'xsd:string',
'learnpath_id' => 'xsd:string',
'learnpath_item_id' => 'xsd:string',
),
array('return' => 'tns:score_result')
);
$s->register(
'WSReport.GetLearnpathStatusSingleItem',
array('secret_key' => 'xsd:string', 'user_id_field_name' => 'xsd:string', 'user_id_value' => 'xsd:string', 'course_id_field_name' => 'xsd:string', 'course_id_value' => 'xsd:string', 'learnpath_id' => 'xsd:string', 'learnpath_item_id' => 'xsd:string'),
array(
'secret_key' => 'xsd:string',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string',
'course_id_field_name' => 'xsd:string',
'course_id_value' => 'xsd:string',
'learnpath_id' => 'xsd:string',
'learnpath_item_id' => 'xsd:string',
),
array('return' => 'xsd:string')
);
$s->register(
'WSReport.test',
array(),
array('return' => 'xsd:string')
array('return' => 'xsd:string')
);

@ -12,19 +12,19 @@ $s = WSSoapServer::singleton();
$s->register(
'WSSession.CreateSession',
array(
'secret_key' => 'xsd:string',
'name' => 'xsd:string',
'start_date' => 'xsd:string',
'end_date' => 'xsd:string',
'nb_days_access_before' => 'xsd:int',
'nb_days_access_after' => 'xsd:int',
'nolimit' => 'xsd:int',
'visibility' => 'xsd:int',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string',
'session_id_field_name' => 'xsd:string',
'session_id_value' => 'xsd:string',
'extras' => 'tns:extra_field'
'secret_key' => 'xsd:string',
'name' => 'xsd:string',
'start_date' => 'xsd:string',
'end_date' => 'xsd:string',
'nb_days_access_before' => 'xsd:int',
'nb_days_access_after' => 'xsd:int',
'nolimit' => 'xsd:int',
'visibility' => 'xsd:int',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string',
'session_id_field_name' => 'xsd:string',
'session_id_value' => 'xsd:string',
'extras' => 'tns:extra_field',
),
array('return' => 'xsd:int')
);
@ -32,50 +32,50 @@ $s->register(
$s->register(
'WSSession.DeleteSession',
array(
'secret_key' => 'xsd:string',
'session_id_field_name' => 'xsd:string',
'session_id_value' => 'xsd:string'
'secret_key' => 'xsd:string',
'session_id_field_name' => 'xsd:string',
'session_id_value' => 'xsd:string',
)
);
$s->register(
'WSSession.EditSession',
array(
'secret_key' => 'xsd:string',
'name' => 'xsd:string',
'start_date' => 'xsd:string',
'end_date' => 'xsd:string',
'nb_days_access_before' => 'xsd:int',
'nb_days_access_after' => 'xsd:int',
'nolimit' => 'xsd:int',
'visibility' => 'xsd:int',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string',
'session_id_field_name' => 'xsd:string',
'session_id_value' => 'xsd:string',
'extras' => 'tns:extra_field'
'secret_key' => 'xsd:string',
'name' => 'xsd:string',
'start_date' => 'xsd:string',
'end_date' => 'xsd:string',
'nb_days_access_before' => 'xsd:int',
'nb_days_access_after' => 'xsd:int',
'nolimit' => 'xsd:int',
'visibility' => 'xsd:int',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string',
'session_id_field_name' => 'xsd:string',
'session_id_value' => 'xsd:string',
'extras' => 'tns:extra_field',
)
);
$s->register(
'WSSession.SubscribeUserToSession',
array(
'secret_key' => 'xsd:string',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string',
'session_id_field_name' => 'xsd:string',
'session_id_value' => 'xsd:string'
'secret_key' => 'xsd:string',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string',
'session_id_field_name' => 'xsd:string',
'session_id_value' => 'xsd:string',
)
);
$s->register(
'WSSession.UnsubscribeUserFromSession',
array(
'secret_key' => 'xsd:string',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string',
'session_id_field_name' => 'xsd:string',
'session_id_value' => 'xsd:string'
'secret_key' => 'xsd:string',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string',
'session_id_field_name' => 'xsd:string',
'session_id_value' => 'xsd:string',
)
);
@ -83,46 +83,46 @@ $s->register(
'WSSession.SubscribeTeacherToSessionCourse',
array(
'secret_key' => 'xsd:string',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string',
'session_id_field_name' => 'xsd:string',
'session_id_value' => 'xsd:string',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string',
'session_id_field_name' => 'xsd:string',
'session_id_value' => 'xsd:string',
'course_id_field_name' => 'xsd:string',
'course_id_value' => 'xsd:string'
'course_id_value' => 'xsd:string',
)
);
$s->register(
'WSSession.UnsubscribeTeacherFromSessionCourse',
array(
'secret_key' => 'xsd:string',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string',
'session_id_field_name' => 'xsd:string',
'session_id_value' => 'xsd:string',
'secret_key' => 'xsd:string',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string',
'session_id_field_name' => 'xsd:string',
'session_id_value' => 'xsd:string',
'course_id_field_name' => 'xsd:string',
'course_id_value' => 'xsd:string'
'course_id_value' => 'xsd:string',
)
);
$s->register(
'WSSession.SubscribeCourseToSession',
array(
'secret_key' => 'xsd:string',
'course_id_field_name' => 'xsd:string',
'course_id_value' => 'xsd:string',
'session_id_field_name' => 'xsd:string',
'session_id_value' => 'xsd:string'
'secret_key' => 'xsd:string',
'course_id_field_name' => 'xsd:string',
'course_id_value' => 'xsd:string',
'session_id_field_name' => 'xsd:string',
'session_id_value' => 'xsd:string',
)
);
$s->register(
'WSSession.UnsubscribeCourseFromSession',
array(
'secret_key' => 'xsd:string',
'course_id_field_name' => 'xsd:string',
'course_id_value' => 'xsd:string',
'session_id_field_name' => 'xsd:string',
'session_id_value' => 'xsd:string'
'secret_key' => 'xsd:string',
'course_id_field_name' => 'xsd:string',
'course_id_value' => 'xsd:string',
'session_id_field_name' => 'xsd:string',
'session_id_value' => 'xsd:string',
)
);

@ -14,223 +14,292 @@ require_once __DIR__.'/soap.php';
$s = WSSoapServer::singleton();
$s->wsdl->addComplexType(
'user_id',
'complexType',
'struct',
'all',
'',
array(
'user_id_field_name' => array('name' => 'user_id_field_name', 'type' => 'xsd:string'),
'user_id_value' => array('name' => 'user_id_value', 'type' => 'xsd:string')
)
'user_id',
'complexType',
'struct',
'all',
'',
array(
'user_id_field_name' => array(
'name' => 'user_id_field_name',
'type' => 'xsd:string',
),
'user_id_value' => array(
'name' => 'user_id_value',
'type' => 'xsd:string',
),
)
);
$s->wsdl->addComplexType(
'user_result',
'complexType',
'struct',
'all',
'',
array(
'user_id_value' => array('name' => 'user_id_value', 'type' => 'xsd:string'),
'result' => array('name' => 'result', 'type' => 'tns:result')
)
'user_result',
'complexType',
'struct',
'all',
'',
array(
'user_id_value' => array(
'name' => 'user_id_value',
'type' => 'xsd:string',
),
'result' => array('name' => 'result', 'type' => 'tns:result'),
)
);
$s->wsdl->addComplexType(
'user_result_array',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(array('ref'=>'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:user_result[]')),
'tns:user_result'
'user_result_array',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array(
'ref' => 'SOAP-ENC:arrayType',
'wsdl:arrayType' => 'tns:user_result[]',
),
),
'tns:user_result'
);
$s->register(
'WSUser.DisableUser',
array('secret_key' => 'xsd:string', 'user_id_field_name' => 'xsd:string', 'user_id_value' => 'xsd:string')
'WSUser.DisableUser',
array(
'secret_key' => 'xsd:string',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string',
)
);
$s->register(
'WSUser.DisableUsers',
array('secret_key' => 'xsd:string', 'users' => 'tns:user_id[]'),
array('return' => 'tns:user_result_array')
'WSUser.DisableUsers',
array('secret_key' => 'xsd:string', 'users' => 'tns:user_id[]'),
array('return' => 'tns:user_result_array')
);
$s->register(
'WSUser.EnableUser',
array('secret_key' => 'xsd:string', 'user_id_field_name' => 'xsd:string', 'user_id_value' => 'xsd:string')
'WSUser.EnableUser',
array(
'secret_key' => 'xsd:string',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string',
)
);
$s->register(
'WSUser.EnableUsers',
array('secret_key' => 'xsd:string', 'users' => 'tns:user_id[]'),
array('return' => 'tns:user_result_array')
'WSUser.EnableUsers',
array('secret_key' => 'xsd:string', 'users' => 'tns:user_id[]'),
array('return' => 'tns:user_result_array')
);
$s->register(
'WSUser.DeleteUser',
array('secret_key' => 'xsd:string', 'user_id_field_name' => 'xsd:string', 'user_id_value' => 'xsd:string')
'WSUser.DeleteUser',
array(
'secret_key' => 'xsd:string',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string',
)
);
$s->register(
'WSUser.DeleteUsers',
array('secret_key' => 'xsd:string', 'users' => 'tns:user_id[]'),
array('return' => 'tns:user_result_array')
'WSUser.DeleteUsers',
array('secret_key' => 'xsd:string', 'users' => 'tns:user_id[]'),
array('return' => 'tns:user_result_array')
);
$s->register(
'WSUser.CreateUser',
array(
'secret_key' => 'xsd:string',
'firstname' => 'xsd:string',
'lastname' => 'xsd:string',
'status' => 'xsd:int',
'loginname' => 'xsd:string',
'password' => 'xsd:string',
'encrypt_method' => 'xsd:string',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string',
'visibility' => 'xsd:int',
'email' => 'xsd:string',
'language' => 'xsd:string',
'phone' => 'xsd:string',
'expiration_date' => 'xsd:string',
'extras' => 'tns:extra_field'
),
array('return' => 'xsd:int')
'WSUser.CreateUser',
array(
'secret_key' => 'xsd:string',
'firstname' => 'xsd:string',
'lastname' => 'xsd:string',
'status' => 'xsd:int',
'loginname' => 'xsd:string',
'password' => 'xsd:string',
'encrypt_method' => 'xsd:string',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string',
'visibility' => 'xsd:int',
'email' => 'xsd:string',
'language' => 'xsd:string',
'phone' => 'xsd:string',
'expiration_date' => 'xsd:string',
'extras' => 'tns:extra_field',
),
array('return' => 'xsd:int')
);
$s->wsdl->addComplexType(
'user_create',
'complexType',
'struct',
'all',
'',
array(
'firstname' => array('name' => 'firstname', 'type' => 'xsd:string'),
'lastname' => array('name' => 'lastname', 'type' => 'xsd:string'),
'status' => array('name' => 'status', 'type' => 'xsd:int'),
'loginname' => array('name' => 'loginname', 'type' => 'xsd:string'),
'password' => array('name' => 'password', 'type' => 'xsd:string'),
'encrypt_method' => array('name' => 'encrypt_method', 'type' => 'xsd:string'),
'user_id_field_name' => array('name' => 'user_id_field_name', 'type' => 'xsd:string'),
'user_id_value' => array('name' => 'user_id_value', 'type' => 'xsd:string'),
'visibility' => array('name' => 'visibility', 'type' => 'xsd:int'),
'email' => array('name' => 'email', 'type' => 'xsd:string'),
'language' => array('name' => 'language', 'type' => 'xsd:string'),
'phone' => array('name' => 'phone', 'type' => 'xsd:string'),
'expiration_date' => array('name' => 'expiration_date', 'type' => 'xsd:string'),
'extras' => array('name' => 'extras', 'type' => 'tns:extra_field')
)
'user_create',
'complexType',
'struct',
'all',
'',
array(
'firstname' => array('name' => 'firstname', 'type' => 'xsd:string'),
'lastname' => array('name' => 'lastname', 'type' => 'xsd:string'),
'status' => array('name' => 'status', 'type' => 'xsd:int'),
'loginname' => array('name' => 'loginname', 'type' => 'xsd:string'),
'password' => array('name' => 'password', 'type' => 'xsd:string'),
'encrypt_method' => array(
'name' => 'encrypt_method',
'type' => 'xsd:string',
),
'user_id_field_name' => array(
'name' => 'user_id_field_name',
'type' => 'xsd:string',
),
'user_id_value' => array(
'name' => 'user_id_value',
'type' => 'xsd:string',
),
'visibility' => array('name' => 'visibility', 'type' => 'xsd:int'),
'email' => array('name' => 'email', 'type' => 'xsd:string'),
'language' => array('name' => 'language', 'type' => 'xsd:string'),
'phone' => array('name' => 'phone', 'type' => 'xsd:string'),
'expiration_date' => array(
'name' => 'expiration_date',
'type' => 'xsd:string',
),
'extras' => array('name' => 'extras', 'type' => 'tns:extra_field'),
)
);
$s->wsdl->addComplexType(
'user_create_result',
'complexType',
'struct',
'all',
'',
array(
'user_id_value' => array('name' => 'user_id_value', 'type' => 'xsd:string'),
'user_id_generated' => array('name' => 'user_id_generated', 'type' => 'xsd:int'),
'result' => array('name' => 'result', 'type' => 'tns:result')
)
'user_create_result',
'complexType',
'struct',
'all',
'',
array(
'user_id_value' => array(
'name' => 'user_id_value',
'type' => 'xsd:string',
),
'user_id_generated' => array(
'name' => 'user_id_generated',
'type' => 'xsd:int',
),
'result' => array('name' => 'result', 'type' => 'tns:result'),
)
);
$s->wsdl->addComplexType(
'user_create_result_array',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(array('ref'=>'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:user_create_result[]')),
'tns:user_create_result'
'user_create_result_array',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array(
'ref' => 'SOAP-ENC:arrayType',
'wsdl:arrayType' => 'tns:user_create_result[]',
),
),
'tns:user_create_result'
);
$s->register(
'WSUser.CreateUsers',
array(
'secret_key' => 'xsd:string',
'users' => 'tns:user_create[]'
),
array('return' => 'tns:user_create_result_array')
'WSUser.CreateUsers',
array(
'secret_key' => 'xsd:string',
'users' => 'tns:user_create[]',
),
array('return' => 'tns:user_create_result_array')
);
$s->register(
'WSUser.EditUser',
array(
'secret_key' => 'xsd:string',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string',
'firstname' => 'xsd:string',
'lastname' => 'xsd:string',
'status' => 'xsd:int',
'loginname' => 'xsd:string',
'password' => 'xsd:string',
'encrypt_method' => 'xsd:string',
'email' => 'xsd:string',
'language' => 'xsd:string',
'phone' => 'xsd:string',
'expiration_date' => 'xsd:string',
'extras' => 'tns:extra_field'
)
'WSUser.EditUser',
array(
'secret_key' => 'xsd:string',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string',
'firstname' => 'xsd:string',
'lastname' => 'xsd:string',
'status' => 'xsd:int',
'loginname' => 'xsd:string',
'password' => 'xsd:string',
'encrypt_method' => 'xsd:string',
'email' => 'xsd:string',
'language' => 'xsd:string',
'phone' => 'xsd:string',
'expiration_date' => 'xsd:string',
'extras' => 'tns:extra_field',
)
);
$s->wsdl->addComplexType(
'user_edit',
'complexType',
'struct',
'all',
'',
array(
'user_id_field_name' => array('name' => 'user_id_field_name', 'type' => 'xsd:string'),
'user_id_value' => array('name' => 'user_id_value', 'type' => 'xsd:string'),
'firstname' => array('name' => 'firstname', 'type' => 'xsd:string'),
'lastname' => array('name' => 'lastname', 'type' => 'xsd:string'),
'status' => array('name' => 'status', 'type' => 'xsd:int'),
'loginname' => array('name' => 'loginname', 'type' => 'xsd:string'),
'password' => array('name' => 'password', 'type' => 'xsd:string'),
'encrypt_method' => array('name' => 'encrypt_method', 'type' => 'xsd:string'),
'email' => array('name' => 'email', 'type' => 'xsd:string'),
'language' => array('name' => 'language', 'type' => 'xsd:string'),
'phone' => array('name' => 'phone', 'type' => 'xsd:string'),
'expiration_date' => array('name' => 'expiration_date', 'type' => 'xsd:string'),
'extras' => array('name' => 'extras', 'type' => 'tns:extra_field')
)
'user_edit',
'complexType',
'struct',
'all',
'',
array(
'user_id_field_name' => array(
'name' => 'user_id_field_name',
'type' => 'xsd:string',
),
'user_id_value' => array(
'name' => 'user_id_value',
'type' => 'xsd:string',
),
'firstname' => array('name' => 'firstname', 'type' => 'xsd:string'),
'lastname' => array('name' => 'lastname', 'type' => 'xsd:string'),
'status' => array('name' => 'status', 'type' => 'xsd:int'),
'loginname' => array('name' => 'loginname', 'type' => 'xsd:string'),
'password' => array('name' => 'password', 'type' => 'xsd:string'),
'encrypt_method' => array(
'name' => 'encrypt_method',
'type' => 'xsd:string',
),
'email' => array('name' => 'email', 'type' => 'xsd:string'),
'language' => array('name' => 'language', 'type' => 'xsd:string'),
'phone' => array('name' => 'phone', 'type' => 'xsd:string'),
'expiration_date' => array(
'name' => 'expiration_date',
'type' => 'xsd:string',
),
'extras' => array('name' => 'extras', 'type' => 'tns:extra_field'),
)
);
$s->wsdl->addComplexType(
'user_edit_result',
'complexType',
'struct',
'all',
'',
array(
'user_id_value' => array('name' => 'user_id_value', 'type' => 'xsd:string'),
'result' => array('name' => 'result', 'type' => 'tns:result')
)
'user_edit_result',
'complexType',
'struct',
'all',
'',
array(
'user_id_value' => array(
'name' => 'user_id_value',
'type' => 'xsd:string',
),
'result' => array('name' => 'result', 'type' => 'tns:result'),
)
);
$s->wsdl->addComplexType(
'user_edit_result_array',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(array('ref'=>'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:user_edit_result[]')),
'tns:user_edit_result'
'user_edit_result_array',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array(
'ref' => 'SOAP-ENC:arrayType',
'wsdl:arrayType' => 'tns:user_edit_result[]',
),
),
'tns:user_edit_result'
);
$s->register(
'WSUser.EditUsers',
array(
'secret_key' => 'xsd:string',
'users' => 'tns:user_edit[]'
),
array('return' => 'tns:user_edit_result_array')
'WSUser.EditUsers',
array(
'secret_key' => 'xsd:string',
'users' => 'tns:user_edit[]',
),
array('return' => 'tns:user_edit_result_array')
);

@ -20,18 +20,23 @@ $server->configureWSDL('WSUserInfo', 'urn:WSUserInfo');
// Register the data structures used by the service
$server->wsdl->addComplexType(
'courseDetails',
'complexType',
'struct',
'all',
'',
array(
'name'=>'code', 'type'=>'xsd:string',
'name'=>'title', 'type'=>'xsd:string',
'name'=>'url', 'type'=>'xsd:string',
'name'=>'teacher', 'type'=>'xsd:string',
'name'=>'language', 'type'=>'xsd:string',
)
'courseDetails',
'complexType',
'struct',
'all',
'',
array(
'name' => 'code',
'type' => 'xsd:string',
'name' => 'title',
'type' => 'xsd:string',
'name' => 'url',
'type' => 'xsd:string',
'name' => 'teacher',
'type' => 'xsd:string',
'name' => 'language',
'type' => 'xsd:string',
)
);
$server->wsdl->addComplexType(
@ -42,16 +47,21 @@ $server->wsdl->addComplexType(
'SOAP-ENC:Array',
array(),
array(
array('ref'=>'SOAP-ENC:arrayType',
'wsdl:arrayType'=>'tns:courseDetails[]')
array(
'ref' => 'SOAP-ENC:arrayType',
'wsdl:arrayType' => 'tns:courseDetails[]',
),
),
'tns:courseDetails'
);
// Register the method to expose
$server->register('WSCourseListOfUser', // method name
array('username' => 'xsd:string',
'signature' => 'xsd:string'), // input parameters
$server->register(
'WSCourseListOfUser', // method name
array(
'username' => 'xsd:string',
'signature' => 'xsd:string',
), // input parameters
array('return' => 'xsd:Array'), // output parameters
'urn:WSUserInfo', // namespace
'urn:WSUserInfo#WSUserInfo', // soapaction
@ -68,8 +78,11 @@ $server->register('WSCourseListOfUser', // method name
* @param string Signature (composed of the sha1(username+apikey)
* @return array Courses list (code=>[title=>'title',url='http://...',teacher=>'...',language=>''],code=>[...],...)
*/
function WSCourseListOfUser($username, $signature) {
if (empty($username) or empty($signature)) { return -1; }
function WSCourseListOfUser($username, $signature)
{
if (empty($username) or empty($signature)) {
return -1;
}
global $_configuration;
$info = api_get_user_info_from_username($username);
@ -77,7 +90,7 @@ function WSCourseListOfUser($username, $signature) {
$list = UserManager::get_api_keys($user_id, 'dokeos');
$key = '';
foreach ($list as $key) {
break;
break;
}
$local_key = $username.$key;
@ -90,8 +103,17 @@ function WSCourseListOfUser($username, $signature) {
$courses_list_tmp = CourseManager::get_courses_list_by_user_id($user_id);
foreach ($courses_list_tmp as $index => $course) {
$course_info = CourseManager::get_course_information($course['code']);
$courses_list[] = array('code' => $course['code'], 'title' => api_utf8_encode($course_info['title']), 'url' => api_get_path(WEB_COURSE_PATH).$course_info['directory'].'/', 'teacher' => api_utf8_encode($course_info['tutor_name']), 'language' => $course_info['course_language']);
$courses_list[] = array(
'code' => $course['code'],
'title' => api_utf8_encode($course_info['title']),
'url' => api_get_path(
WEB_COURSE_PATH
).$course_info['directory'].'/',
'teacher' => api_utf8_encode($course_info['tutor_name']),
'language' => $course_info['course_language'],
);
}
return $courses_list;
}
@ -104,11 +126,16 @@ $server->wsdl->addComplexType(
'all',
'',
array(
'name'=>'datestart', 'type'=>'xsd:string',
'name'=>'dateend', 'type'=>'xsd:string',
'name'=>'title', 'type'=>'xsd:string',
'name'=>'link', 'type'=>'xsd:string',
'name'=>'coursetitle', 'type'=>'xsd:string',
'name' => 'datestart',
'type' => 'xsd:string',
'name' => 'dateend',
'type' => 'xsd:string',
'name' => 'title',
'type' => 'xsd:string',
'name' => 'link',
'type' => 'xsd:string',
'name' => 'coursetitle',
'type' => 'xsd:string',
)
);
@ -120,23 +147,35 @@ $server->wsdl->addComplexType(
'SOAP-ENC:Array',
array(),
array(
array('ref'=>'SOAP-ENC:arrayType',
'wsdl:arrayType'=>'tns:eventDetails[]')
array(
'ref' => 'SOAP-ENC:arrayType',
'wsdl:arrayType' => 'tns:eventDetails[]',
),
),
'tns:eventDetails'
);
// Register the method to expose
$server->register('WSEventsList', // method name
array('username' => 'xsd:string',
'signature' => 'xsd:string',
'datestart' => 'xsd:int',
'dateend' => 'xsd:int'), // input parameters
array('return' => 'xsd:Array'), // output parameters
'urn:WSUserInfo', // namespace
'urn:WSUserInfo#WSEventsList', // soapaction
'rpc', // style
'encoded', // use
$server->register(
'WSEventsList',
// method name
array(
'username' => 'xsd:string',
'signature' => 'xsd:string',
'datestart' => 'xsd:int',
'dateend' => 'xsd:int',
),
// input parameters
array('return' => 'xsd:Array'),
// output parameters
'urn:WSUserInfo',
// namespace
'urn:WSUserInfo#WSEventsList',
// soapaction
'rpc',
// style
'encoded',
// use
'This service returns a list of events of the courses the given user is subscribed to' // documentation
);
@ -170,10 +209,16 @@ function WSEventsList($username, $signature, $datestart = 0, $dateend = 0) {
$events_list = array();
$user_id = UserManager::get_user_id_from_username($username);
if ($user_id === false) { return $events_list; } // Error in user id recovery.
if ($user_id === false) {
return $events_list;
} // Error in user id recovery.
$ds = substr($datestart, 0, 4).'-'.substr($datestart, 4, 2).'-'.substr($datestart, 6, 2).' 00:00:00';
$de = substr($dateend, 0, 4).'-'.substr($dateend, 4, 2).'-'.substr($dateend, 6, 2).' 00:00:00';
$events_list = Agenda::get_personal_agenda_items_between_dates($user_id, $ds, $de);
$events_list = Agenda::get_personal_agenda_items_between_dates(
$user_id,
$ds,
$de
);
return $events_list;
}

@ -11,237 +11,255 @@ require_once __DIR__.'/../inc/global.inc.php';
*/
class WSError
{
/**
* Error handler. This needs to be a class that implements the interface WSErrorHandler
*
* @var WSErrorHandler
*/
protected static $_handler;
/**
* Error code
*
* @var int
*/
public $code;
/**
* Error message
*
* @var string
*/
public $message;
/**
* Constructor
*
* @param int Error code
* @param string Error message
*/
public function __construct($code, $message) {
$this->code = $code;
$this->message = $message;
}
/**
* Sets the error handler
*
* @param WSErrorHandler Error handler
*/
public static function setErrorHandler($handler) {
if ($handler instanceof WSErrorHandler) {
self::$_handler = $handler;
}
}
/**
* Returns the error handler
*
* @return WSErrorHandler Error handler
*/
public static function getErrorHandler() {
return self::$_handler;
}
/**
* Transforms the error into an array
*
* @return array Associative array with code and message
*/
public function toArray() {
return array('code' => $this->code, 'message' => $this->message);
}
/**
* Error handler. This needs to be a class that implements the interface WSErrorHandler
*
* @var WSErrorHandler
*/
protected static $_handler;
/**
* Error code
*
* @var int
*/
public $code;
/**
* Error message
*
* @var string
*/
public $message;
/**
* Constructor
*
* @param int Error code
* @param string Error message
*/
public function __construct($code, $message)
{
$this->code = $code;
$this->message = $message;
}
/**
* Sets the error handler
*
* @param WSErrorHandler Error handler
*/
public static function setErrorHandler($handler)
{
if ($handler instanceof WSErrorHandler) {
self::$_handler = $handler;
}
}
/**
* Returns the error handler
*
* @return WSErrorHandler Error handler
*/
public static function getErrorHandler()
{
return self::$_handler;
}
/**
* Transforms the error into an array
*
* @return array Associative array with code and message
*/
public function toArray()
{
return array('code' => $this->code, 'message' => $this->message);
}
}
/**
* Interface that must be implemented by any error handler
*/
interface WSErrorHandler {
/**
* Handle method
*
* @param WSError Error
*/
public function handle($error);
interface WSErrorHandler
{
/**
* Handle method
*
* @param WSError Error
*/
public function handle($error);
}
/**
* Main class of the webservice. Webservice classes extend this class
*/
class WS {
/**
* Chamilo configuration
*
* @var array
*/
protected $_configuration;
/**
* Constructor
*/
public function __construct() {
$this->_configuration = $GLOBALS['_configuration'];
}
/**
* Verifies the API key
*
* @param string Secret key
* @return mixed WSError in case of failure, null in case of success
*/
protected function verifyKey($secret_key) {
$ip = trim($_SERVER['REMOTE_ADDR']);
// if we are behind a reverse proxy, assume it will send the
// HTTP_X_FORWARDED_FOR header and use this IP instead
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
list($ip1, $ip2) = preg_split('/,/', $_SERVER['HTTP_X_FORWARDED_FOR']);
$ip = trim($ip1);
}
$security_key = $ip.$this->_configuration['security_key'];
if (!api_is_valid_secret_key($secret_key, $security_key)) {
return new WSError(1, "API key is invalid");
} else {
return null;
}
}
/**
* Gets the real user id based on the user id field name and value.
* Note that if the user id field name is "chamilo_user_id", it will use the user id
* in the system database
*
* @param string User id field name
* @param string User id value
* @return mixed System user id if the user was found, WSError otherwise
*/
protected function getUserId($user_id_field_name, $user_id_value) {
if ($user_id_field_name == "chamilo_user_id") {
if (UserManager::is_user_id_valid(intval($user_id_value))) {
return intval($user_id_value);
} else {
return new WSError(100, "User not found");
}
} else {
$user_id = UserManager::get_user_id_from_original_id($user_id_value, $user_id_field_name);
if ($user_id == 0) {
return new WSError(100, "User not found");
} else {
return $user_id;
}
}
}
/**
* Gets the real course id based on the course id field name and value.
* Note that if the course id field name is "chamilo_course_id", it will use the course id
* in the system database
*
* @param string Course id field name
* @param string Course id value
* @return mixed System course id if the course was found, WSError otherwise
*/
protected function getCourseId($course_id_field_name, $course_id_value)
{
if ($course_id_field_name == "chamilo_course_id") {
if (CourseManager::get_course_code_from_course_id(
intval($course_id_value)
) != null
) {
return intval($course_id_value);
} else {
return new WSError(200, "Course not found");
}
} else {
$courseId = CourseManager::get_course_code_from_original_id(
$course_id_value,
$course_id_field_name
);
if (!empty($courseId)) {
return $courseId;
} else {
return new WSError(200, "Course not found");
}
}
}
/**
* Gets the real session id based on the session id field name and value.
* Note that if the session id field name is "chamilo_session_id", it will use the session id
* in the system database
*
* @param string Session id field name
* @param string Session id value
* @return mixed System session id if the session was found, WSError otherwise
*/
protected function getSessionId($session_id_field_name, $session_id_value)
{
if ($session_id_field_name == "chamilo_session_id") {
$session = SessionManager::fetch((int) $session_id_value);
if (!empty($session)) {
return intval($session_id_value);
} else {
return new WSError(300, "Session not found");
}
} else {
$session_id = SessionManager::getSessionIdFromOriginalId(
$session_id_value,
$session_id_field_name
);
if ($session_id == 0) {
return new WSError(300, "Session not found");
} else {
return $session_id;
}
}
}
/**
* Handles an error by calling the WSError error handler
*
* @param WSError Error
*/
protected function handleError($error) {
$handler = WSError::getErrorHandler();
$handler->handle($error);
}
/**
* Gets a successful result
*
* @return array Array with a code of 0 and a message 'Operation was successful'
*/
protected function getSuccessfulResult() {
return array('code' => 0, 'message' => 'Operation was successful');
}
/**
* Test function. Returns the string success
*
* @return string Success
*/
public function test() {
return "success";
}
class WS
{
/**
* Chamilo configuration
*
* @var array
*/
protected $_configuration;
/**
* Constructor
*/
public function __construct()
{
$this->_configuration = $GLOBALS['_configuration'];
}
/**
* Verifies the API key
*
* @param string Secret key
* @return mixed WSError in case of failure, null in case of success
*/
protected function verifyKey($secret_key)
{
$ip = trim($_SERVER['REMOTE_ADDR']);
// if we are behind a reverse proxy, assume it will send the
// HTTP_X_FORWARDED_FOR header and use this IP instead
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
list($ip1, $ip2) = preg_split(
'/,/',
$_SERVER['HTTP_X_FORWARDED_FOR']
);
$ip = trim($ip1);
}
$security_key = $ip.$this->_configuration['security_key'];
if (!api_is_valid_secret_key($secret_key, $security_key)) {
return new WSError(1, "API key is invalid");
} else {
return null;
}
}
/**
* Gets the real user id based on the user id field name and value.
* Note that if the user id field name is "chamilo_user_id", it will use the user id
* in the system database
*
* @param string User id field name
* @param string User id value
* @return mixed System user id if the user was found, WSError otherwise
*/
protected function getUserId($user_id_field_name, $user_id_value)
{
if ($user_id_field_name == "chamilo_user_id") {
if (UserManager::is_user_id_valid(intval($user_id_value))) {
return intval($user_id_value);
} else {
return new WSError(100, "User not found");
}
} else {
$user_id = UserManager::get_user_id_from_original_id(
$user_id_value,
$user_id_field_name
);
if ($user_id == 0) {
return new WSError(100, "User not found");
} else {
return $user_id;
}
}
}
/**
* Gets the real course id based on the course id field name and value.
* Note that if the course id field name is "chamilo_course_id", it will use the course id
* in the system database
*
* @param string Course id field name
* @param string Course id value
* @return mixed System course id if the course was found, WSError otherwise
*/
protected function getCourseId($course_id_field_name, $course_id_value)
{
if ($course_id_field_name == "chamilo_course_id") {
if (CourseManager::get_course_code_from_course_id(
intval($course_id_value)
) != null
) {
return intval($course_id_value);
} else {
return new WSError(200, "Course not found");
}
} else {
$courseId = CourseManager::get_course_code_from_original_id(
$course_id_value,
$course_id_field_name
);
if (!empty($courseId)) {
return $courseId;
} else {
return new WSError(200, "Course not found");
}
}
}
/**
* Gets the real session id based on the session id field name and value.
* Note that if the session id field name is "chamilo_session_id", it will use the session id
* in the system database
*
* @param string Session id field name
* @param string Session id value
* @return mixed System session id if the session was found, WSError otherwise
*/
protected function getSessionId($session_id_field_name, $session_id_value)
{
if ($session_id_field_name == "chamilo_session_id") {
$session = SessionManager::fetch((int)$session_id_value);
if (!empty($session)) {
return intval($session_id_value);
} else {
return new WSError(300, "Session not found");
}
} else {
$session_id = SessionManager::getSessionIdFromOriginalId(
$session_id_value,
$session_id_field_name
);
if ($session_id == 0) {
return new WSError(300, "Session not found");
} else {
return $session_id;
}
}
}
/**
* Handles an error by calling the WSError error handler
*
* @param WSError Error
*/
protected function handleError($error)
{
$handler = WSError::getErrorHandler();
$handler->handle($error);
}
/**
* Gets a successful result
*
* @return array Array with a code of 0 and a message 'Operation was successful'
*/
protected function getSuccessfulResult()
{
return array('code' => 0, 'message' => 'Operation was successful');
}
/**
* Test function. Returns the string success
*
* @return string Success
*/
public function test()
{
return "success";
}
}

File diff suppressed because it is too large Load Diff

@ -9,46 +9,59 @@ require_once __DIR__.'/webservice.php';
/**
* Web services available for the User module. This class extends the WS class
*/
class WSReport extends WS {
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
/**
* 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 {
*/
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) {
* @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);
$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);
$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
@ -59,23 +72,44 @@ class WSReport extends WS {
* @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) {
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);
$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);
$course_code = CourseManager::get_course_code_from_course_id(
$course_id
);
}
$session_id = $this->getSessionId($session_id_field_name, $session_id_value);
$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);
return Tracking::get_time_spent_on_the_course(
$user_id,
$course_id,
$session_id
);
}
/**
* Gets a list of learning paths by course
*
@ -85,26 +119,39 @@ class WSReport extends WS {
* @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) {
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);
$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);
$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[] = array('id' => $id, 'title' => $item['lp_name']);
}
return $return;
}
/**
* Gets progress attained in the given learning path by the given user
*
@ -115,22 +162,35 @@ class WSReport extends WS {
* @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) {
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);
$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);
$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,
'progress_bar_mode' => $lp->progress_bar_mode,
'progress_db' => $lp->progress_db,
);
return $return;
}
@ -148,20 +208,33 @@ class WSReport extends WS {
* @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) {
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);
$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);
$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;
}
@ -177,27 +250,42 @@ class WSReport extends WS {
* @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) {
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);
$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);
$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,
'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
@ -211,7 +299,15 @@ class WSReport extends WS {
* @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) {
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);
@ -220,19 +316,26 @@ class WSReport extends WS {
if ($user_id instanceof WSError) {
return $user_id;
}
$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
$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);
$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() {
public function test()
{
return 'Hello world!';
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save