diff --git a/main/inc/lib/sessionmanager.lib.php b/main/inc/lib/sessionmanager.lib.php index 51cf69d49e..fb2bea0b9a 100755 --- a/main/inc/lib/sessionmanager.lib.php +++ b/main/inc/lib/sessionmanager.lib.php @@ -5438,4 +5438,48 @@ class SessionManager )); } + /** + * Returns the list of session (name, short description, start date, end date) from category. + * The short description is an extra field value + * @param $categoryId + * @return mixed + */ + public static function getSessionBriefListByCategory($categoryId) + { + $categoryId = (int) $categoryId; + $sessionList = array(); + if ($categoryId > 0) { + $sTable = Database::get_main_table(TABLE_MAIN_SESSION); + $sfTable = Database::get_main_table(TABLE_MAIN_SESSION_FIELD); + $sfvTable = Database::get_main_table(TABLE_MAIN_SESSION_FIELD_VALUES); + $joinTable = $sfTable . ' sf INNER JOIN ' . $sfvTable . ' sfv ON sf.id = sfv.field_id'; + $sessionList = Database::select( + 'id, name, date_start, date_end', + $sTable, + array( + 'where' => array( + 'session_category_id = ?' => $categoryId + ) + ) + ); + $sessionFieldValueList = Database::select( + 'sfv.session_id AS id, sfv.field_value AS description', + $joinTable, + array( + 'where' => array( + 'sf.field_variable = ?' => 'as_description' + ) + ) + ); + + } + + foreach ($sessionList as $id => &$session) { + $session['description'] = isset($sessionFieldValueList[$id]) ? + $sessionFieldValueList[$id]['description'] : + ''; + } + + return $sessionList; + } } diff --git a/main/webservices/registration.soap.php b/main/webservices/registration.soap.php index 931c521aec..85ee140762 100755 --- a/main/webservices/registration.soap.php +++ b/main/webservices/registration.soap.php @@ -13,6 +13,9 @@ require_once $libpath.'add_course.lib.inc.php'; $debug = false; define('WS_ERROR_SECRET_KEY', 1); +define('WS_ERROR_NOT_FOUND_RESULT', 2); +define('WS_ERROR_INVALID_INPUT', 3); + function return_error($code) { $fault = null; @@ -20,6 +23,12 @@ function return_error($code) { case WS_ERROR_SECRET_KEY: $fault = new soap_fault('Server', '', 'Secret key is not correct or params are not correctly set'); break; + case WS_ERROR_NOT_FOUND_RESULT: + $fault = new soap_fault('Server', '', 'Not found any result from the query'); + break; + case WS_ERROR_INVALID_INPUT: + $fault = new soap_fault('Server', '', 'The input variables are invalid o are not correctly set'); + break; } return $fault; } @@ -5437,7 +5446,7 @@ $server->wsdl->addComplexType( 'SOAP-ENC:Array', array(), array( - array('ref'=>'SOAP:ENC:arrayType', + array('ref'=>'SOAP-ENC:arrayType', 'wsdl:arrayType'=>'tns:session[]') ), 'tns:session' @@ -5542,6 +5551,103 @@ function WSUserSubscribedInCourse ($params) return (CourseManager::is_user_subscribed_in_course($userId,$courseCode)); } +/** WSSessionListInCategory */ + +// Output params for WSSessionListInCategory +$server->wsdl->addComplexType( + 'sessionBrief', + 'complexType', + 'struct', + 'all', + '', + array( + 'name' => array('name' => 'name', 'type' => 'xsd:string'), //Course string code + 'description' => array('name' => 'description', 'type' => 'xsd:string'), //Chamilo user_id + 'date_start' => array('name' => 'start_date', 'type' => 'xsd:string'), + 'date_end' => array('name' => 'end_date', 'type' => 'xsd:string'), + ) +); + +$server->wsdl->addComplexType( + 'sessionBriefList', + 'complexType', + 'array', + '', + 'SOAP-ENC:Array', + array(), + array( + array('ref'=>'SOAP-ENC:arrayType', + 'wsdl:arrayType'=>'tns:sessionBrief[]') + ), + 'tns:sessionBrief' +); + +// Input params for editing users +$server->wsdl->addComplexType( + 'sessionCategoryInput', + 'complexType', + 'struct', + 'all', + '', + array( + 'id' => array('name' => 'id', 'type' => 'xsd:string'), //Course string code + 'name' => array('name' => 'name', 'type' => 'xsd:string'), //Chamilo user_id + 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string') + ) +); + +// Register the method to expose +$server->register('WSSessionListInCategory', // method name + array('sessionCategoryInput' => 'tns:sessionCategoryInput'), // input parameters + array('return' => 'tns:sessionBriefList'), // output parameters + 'urn:WSRegistration', // namespace + 'urn:WSRegistration#WSSessionListInCategory', // soapaction + 'rpc', // style + 'encoded', // use + 'This service checks if user assigned to course' // documentation +); + + +/** + * @param $params + * @return null|soap_fault + */ +function WSSessionListInCategory($params) { + global $debug; + + if ($debug) error_log('WSUserSubscribedInCourse'); + if ($debug) error_log('Params '. print_r($params, 1)); + if (!WSHelperVerifyKey($params)) { + + return return_error(WS_ERROR_SECRET_KEY); + } + // Check if category ID is set + if (!empty($params['id']) && empty($params['category_name'])) { + $sessionCategoryId = $params['id']; + } elseif (!empty($params['category_name'])) { + // Check if category name is set + $sessionCategoryId = SessionManager::getSessionCategoryIdByName($params['category_name']); + if (is_array($sessionCategoryId)) { + $sessionCategoryId = current($sessionCategoryId); + } + } else { + // Return soap fault Not valid input params + + return return_error(WS_ERROR_INVALID_INPUT); + } + + // Get the session brief List by category + + $sessionList = SessionManager::getSessionBriefListByCategory($sessionCategoryId); + + if (empty($sessionList)) { + + return return_error(WS_ERROR_NOT_FOUND_RESULT); + } + + return $sessionList; +} + // Add more webservices by Hooks if (!empty($hook)) { $hook->setEventData(array('server' => $server));