Procházet zdrojové kódy

Merge pull request #924 from jloguercio/10476

Implemented 3 WebServices Functions to Subscribe/Unsubscribe teachers to session - Refs #BT10476
Yannick Warnier před 9 roky
rodič
revize
82b0533f1f

+ 1 - 1
main/inc/lib/sessionmanager.lib.php

@@ -1831,7 +1831,7 @@ class SessionManager
             return false;
         }
 
-        $courseId = $courseInfo['real_id'];
+        is_array($courseInfo) ? $courseId = $courseInfo['real_id'] : $courseId = $courseInfo;
 
         $statusCondition = null;
         if (isset($status) && !is_null($status))  {

+ 103 - 0
main/webservices/registration.soap.php

@@ -969,6 +969,109 @@ function WSCreateUsersPasswordCrypted($params)
 
     return $output;
 }
+// Subscribe / Unsubscribe Teacher to Session Course
+// 
+// Prepare Input params for Subscribe Teacher to SC
+$server->wsdl->addComplexType(
+    'SubscribeTeacherToSessionCourse',
+    'complexType',
+    'struct',
+    'all',
+    '',
+    array(
+        'userId'       => array('name' => 'course',     'type' => 'xsd:string'), // Chamilo user Id
+        'sessionId'      => array('name' => 'user_id',    'type' => 'xsd:string'), // Current Session course ID
+        'courseId'      =>array('name' => 'courseId',      'type' => 'xsd:string'), // Course Real Id
+        'secret_key'   => array('name' => 'secret_key', 'type' => 'xsd:string')
+    )
+);
+
+$server->register(
+	'WSSubscribeTeacherToSessionCourse',
+	array('SubscribeTeacherToSessionCourse' => 'tns:SubscribeTeacherToSessionCourse'),
+    array('return' => 'xsd:string'),
+    'urn:WSRegistration',
+    'urn:WSRegistration#WSSubscribeTeacherToSessionCourse',
+    'rpc',
+    'encoded',
+    'This webservice subscribe a teacher to a session course'
+);
+
+// Prepare Input params for Unsubscribe Teacher from SC
+$server->wsdl->addComplexType(
+    'UnsubscribeTeacherFromSessionCourse',
+    'complexType',
+    'struct',
+    'all',
+    '',
+    array(
+        'userId'       => array('name' => 'course',     'type' => 'xsd:string'), // Chamilo user Id
+        'sessionId'      => array('name' => 'user_id',    'type' => 'xsd:string'), // Current Session course ID
+        'courseId'      =>array('name' => 'courseId',      'type' => 'xsd:string'), // Course Real Id
+        'secret_key'   => array('name' => 'secret_key', 'type' => 'xsd:string')
+    )
+);
+
+$server->register(
+	'WSUnsubscribeTeacherFromSessionCourse',
+	array('UnsubscribeTeacherFromSessionCourse' => 'tns:UnsubscribeTeacherFromSessionCourse'),
+    array('return' => 'xsd:string'),
+    'urn:WSRegistration',
+    'urn:WSRegistration#WSUnsubscribeTeacherFromSessionCourse',
+    'rpc',
+    'encoded',
+    'This webservice unsubscribe a teacher from a session course'
+);
+
+    /**
+     * Subscribe teacher to a session course
+     *
+     * @param array $params - WSFunction parameters (include VerifyKey)
+     * @return bool|null|soap_fault A simple boolean (true if teacher successful subscribed, false otherwise)
+     */
+    function WSSubscribeTeacherToSessionCourse($params)
+    {
+        global $debug;
+        
+        if ($debug) error_log('WSSubscribeTeacherToSessionCourse');
+        if ($debug) error_log('Params '. print_r($params, 1));
+        
+        if (!WSHelperVerifyKey($params)) {
+            return return_error(WS_ERROR_SECRET_KEY);
+        }
+        
+        $userId = $params['userId']; // Chamilo user Id
+        $sessionId = $params['sessionId']; // Current Session course ID
+        $courseId = $params['courseId']; // Course Real Id
+        
+        return (SessionManager::set_coach_to_course_session($userId, $sessionId, $courseId));
+    }
+
+    /**
+     * Subscribe teacher to a session course
+     *
+     *  @param array $params - WSFunction parameters (include VerifyKey)
+     *  @return bool|null|soap_fault A simple boolean (true if teacher successful unsubscribed, false otherwise)
+     */
+    function WSUnsubscribeTeacherFromSessionCourse($params)
+    {
+        global $debug;
+        
+        if ($debug) error_log('WSSubscribeTeacherToSessionCourse');
+        if ($debug) error_log('Params '. print_r($params, 1));
+        
+        if (!WSHelperVerifyKey($params)) {
+            return return_error(WS_ERROR_SECRET_KEY);
+        }
+        
+        $userId = $params['userId']; // Chamilo user Id
+        $sessionId = $params['sessionId']; // Current Session course ID
+        $courseId = $params['courseId']; // Course Real Id
+        
+        return (SessionManager::removeUsersFromCourseSession($userId, $sessionId, $courseId));
+        
+    }
+
 
 /* Register WSCreateUserPasswordCrypted function */
 // Register the data structures used by the service

+ 97 - 71
main/webservices/soap_session.php

@@ -11,93 +11,119 @@ require_once(dirname(__FILE__).'/soap.php');
 $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'
-	),
-	array('return' => 'xsd:int')
+    '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'
+    ),
+    array('return' => 'xsd:int')
 );
 
 $s->register(
-	'WSSession.DeleteSession',
-	array(
-		'secret_key' => 'xsd:string',
-		'session_id_field_name' => 'xsd:string',
-		'session_id_value' => 'xsd:string'
-	)
+    'WSSession.DeleteSession',
+    array(
+	'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'
-	)
+    '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'
+    )
 );
 
 $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'
-	)
+    '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'
+    )
 );
 
 $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'
-	)
+    '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'
+    )
 );
 
 $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'
-	)
+    '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',
+        'course_id_field_name' => 'xsd:string',
+	'course_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'
-	)
+    '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',
+        'course_id_field_name' => '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'
+    )
+);
+
+$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'
+    )
 );

+ 90 - 1
main/webservices/webservice_session.php

@@ -355,8 +355,97 @@ class WSSession extends WS
 			}
 		}
 	}
+    
+    /**
+     * 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 {
+                        $user_id = array (0 => $user_id);
+                        $result = SessionManager::removeUsersFromCourseSession($user_id, $session_id, $course_id);
+                        if (!$result) {
+                            return new WSError(303, 'There was an error unsubscribing this Teacher from the session');
+                        }
+                    }
+                    return true;
+                }
+            }
+        }
+    }
 
-	/**
+    /**
+     * Subscribe teacher to a session course
+     *
+     * @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
+     * @param string Course id field name
+     * @param string Course id value
+     */
+    public function SubscribeTeacherToSessionCourse($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 teacher to a session course
+     *
+     * @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
+     * @param string Course id field name
+     * @param string Course id value
+     */
+    public function UnsubscribeTeacherFromSessionCourse($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
 	 *
 	 * @param string Course id field name