Skip to content

Commit

Permalink
Implemented 3 WebServices Functions to Subscribe/Unsubscribe teachers…
Browse files Browse the repository at this point in the history
… to session - Refs #BT10476
  • Loading branch information
jloguercio committed Nov 2, 2015
1 parent 5c4ff62 commit f30d5fd
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 1 deletion.
2 changes: 1 addition & 1 deletion main/user/subscribe_user.php
Expand Up @@ -60,7 +60,7 @@
$result_simple_sub = SessionManager::set_coach_to_course_session(
$_REQUEST['user_id'],
$current_session_id,
$courseInfo['code']
$courseInfo['real_id']
);
} else {
$result_simple_sub = CourseManager:: subscribe_user(
Expand Down
26 changes: 26 additions & 0 deletions main/webservices/soap_session.php
Expand Up @@ -80,6 +80,32 @@
)
);

$s->register(
'WSSession.SubscribeTeacherToSession',
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',
'course_id_field_name' => 'xsd:string',
'course_id_value' => 'xsd:string'
)
);

$s->register(
'WSSession.UnsubscribeTeacherFromSession',
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',
'course_id_field_name' => 'xsd:string',
'course_id_value' => 'xsd:string'
)
);

$s->register(
'WSSession.SubscribeCourseToSession',
array(
Expand Down
81 changes: 81 additions & 0 deletions main/webservices/webservice_session.php
Expand Up @@ -355,6 +355,87 @@ public function UnsubscribeUserFromSession($secret_key, $user_id_field_name, $us
}
}
}

/**
* Change Teacher subscription (helper method)
*
* @param string User id field name
* @param string User id value
* @param string Session id field name
* @param string Session id value
* @param string Course id field name
* @param string Course id value
* @param int State (1 to subscribe, 0 to unsubscribe)
* @return mixed True on success, WSError otherwise
*/
protected function changeTeacherSubscription($user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value, $course_id_field_name, $course_id_value, $state) {
$session_id = $this->getSessionId($session_id_field_name, $session_id_value);
if($session_id instanceof WSError) {
return $session_id;
} else {
$user_id = $this->getUserId($user_id_field_name, $user_id_value);
if($user_id instanceof WSError) {
return $user_id;
} else {
$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
if($course_id instanceof WSError) {
return $course_id;
} else {
if($state == 1) {
SessionManager::set_coach_to_course_session($user_id, $session_id, $course_id );
} else {
$result = SessionManager::unsubscribe_user_from_session($session_id, $user_id);
if (!$result) {
return new WSError(303, 'There was an error unsubscribing this Teacher from the session');
}
}
return true;
}
}
}
}

/**
* Subscribe user to a session
*
* @param string API secret key
* @param string User id field name
* @param string User id value
* @param string Session id field name
* @param string Session id value
*/
public function SubscribeTeacherToSession($secret_key, $user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value, $course_id_field_name, $course_id_value) {
$verifKey = $this->verifyKey($secret_key);
if($verifKey instanceof WSError) {
$this->handleError($verifKey);
} else {
$result = $this->changeUserSubscription($user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value, $course_id_field_name, $course_id_value, 1);
if($result instanceof WSError) {
$this->handleError($result);
}
}
}

/**
* Subscribe user to a session
*
* @param string API secret key
* @param string User id field name
* @param string User id value
* @param string Session id field name
* @param string Session id value
*/
public function UnsubscribeTeacherFromSession($secret_key, $user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value, $course_id_field_name, $course_id_value) {
$verifKey = $this->verifyKey($secret_key);
if($verifKey instanceof WSError) {
$this->handleError($verifKey);
} else {
$result = $this->changeUserSubscription($user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value, $course_id_field_name, $course_id_value, 0);
if($result instanceof WSError) {
$this->handleError($result);
}
}
}

/**
* Change course subscription
Expand Down

0 comments on commit f30d5fd

Please sign in to comment.