Skip to content

Commit c9cc276

Browse files
committed
Fix webservice to work with plugin prestashop with sessions see BT#11040
1 parent a36f700 commit c9cc276

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

main/inc/lib/sessionmanager.lib.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2574,7 +2574,7 @@ public static function delete_session_category($id_checked, $delete_session = fa
25742574
* @return array An array with all sessions of the platform.
25752575
* @todo optional course code parameter, optional sorting parameters...
25762576
*/
2577-
public static function get_sessions_list($conditions = array(), $order_by = array())
2577+
public static function get_sessions_list($conditions = array(), $order_by = array(), $from = null, $to = null)
25782578
{
25792579
$session_table = Database::get_main_table(TABLE_MAIN_SESSION);
25802580
$session_category_table = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
@@ -2643,6 +2643,12 @@ public static function get_sessions_list($conditions = array(), $order_by = arra
26432643
}
26442644
}
26452645

2646+
if (!is_null($from) && !is_null($to)) {
2647+
$to = intval($to);
2648+
$from = intval($from);
2649+
$sql_query .= "LIMIT $from, $to";
2650+
}
2651+
26462652
$sql_result = Database::query($sql_query);
26472653
if (Database::num_rows($sql_result) > 0) {
26482654
while ($result = Database::fetch_array($sql_result)) {

main/webservices/registration.soap.php

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5379,6 +5379,21 @@ function WSUnsuscribeCoursesFromSession($params) {
53795379

53805380
/** WSListCourses **/
53815381

5382+
$server->wsdl->addComplexType(
5383+
'listCourseInput',
5384+
'complexType',
5385+
'struct',
5386+
'all',
5387+
'',
5388+
array(
5389+
'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string'),
5390+
'original_course_id_name' => array('name' => 'original_course_id_name', 'type' => 'xsd:string'),
5391+
'from' => array('name' => 'from', 'type' => 'xsd:int'),
5392+
'to' => array('name' => 'to', 'type' => 'xsd:int')
5393+
)
5394+
);
5395+
5396+
53825397
$server->wsdl->addComplexType(
53835398
'course',
53845399
'complexType',
@@ -5411,7 +5426,7 @@ function WSUnsuscribeCoursesFromSession($params) {
54115426

54125427
// Register the method to expose
54135428
$server->register('WSListCourses', // method name
5414-
array('secret_key' => 'xsd:string', 'original_course_id_name' => 'xsd:string'), // input parameters
5429+
array('listCourseInput' => 'tns:listCourseInput'), // input parameters
54155430
array('return' => 'tns:courses'), // output parameters
54165431
'urn:WSRegistration', // namespace
54175432
'urn:WSRegistration#WSListCourses', // soapaction
@@ -5422,16 +5437,20 @@ function WSUnsuscribeCoursesFromSession($params) {
54225437

54235438
// define the method WSListCourses
54245439
function WSListCourses($params) {
5425-
if(!WSHelperVerifyKey($params)) {
5440+
if (!WSHelperVerifyKey($params)) {
54265441
return return_error(WS_ERROR_SECRET_KEY);
54275442
}
54285443

5429-
$course_field_name = $params['original_course_id_name'];
5444+
$course_field_name = isset($params['original_course_id_name']) ? $params['original_course_id_name'] : '';
54305445

54315446
$courses_result = array();
54325447
$category_names = array();
54335448

5434-
$courses = CourseManager::get_courses_list();
5449+
$from = isset($params['from']) ? $params['from'] : null;
5450+
$to = isset($params['to']) ? $params['to'] : null;
5451+
5452+
$courses = CourseManager::get_courses_list($from, $to);
5453+
54355454
foreach($courses as $course) {
54365455
$course_tmp = array();
54375456
$course_tmp['id'] = $course['id'];
@@ -5441,7 +5460,7 @@ function WSListCourses($params) {
54415460
$course_tmp['visibility'] = $course['visibility'];
54425461

54435462
// Determining category name
5444-
if($category_names[$course['category_code']]) {
5463+
if ($category_names[$course['category_code']]) {
54455464
$course_tmp['category_name'] = $category_names[$course['category_code']];
54465465
} else {
54475466
$category = CourseManager::get_course_category($course['category_code']);
@@ -5455,7 +5474,6 @@ function WSListCourses($params) {
54555474
// Determining external course id
54565475
$course_tmp['external_course_id'] = CourseManager::get_course_extra_field_value($course_field_name, $course['code']);
54575476

5458-
54595477
$courses_result[] = $course_tmp;
54605478
}
54615479

@@ -5534,6 +5552,8 @@ function WSUpdateUserApiKey($params) {
55345552
'all',
55355553
'',
55365554
array(
5555+
'from' => array('name' => 'from', 'type' => 'xsd:int'),
5556+
'to' => array('name' => 'to', 'type' => 'xsd:int'),
55375557
'date_start' => array('name' => 'date_start', 'type' => 'xsd:string'),
55385558
'date_end' => array('name' => 'date_end', 'type' => 'xsd:string'),
55395559
'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
@@ -5590,8 +5610,9 @@ function WSUpdateUserApiKey($params) {
55905610
* @param array List of parameters (security key, date_start and date_end)
55915611
* @return array Sessions list (id=>[title=>'title',url='http://...',date_start=>'...',date_end=>''])
55925612
*/
5593-
function WSListSessions($params) {
5594-
if(!WSHelperVerifyKey($params)) {
5613+
function WSListSessions($params)
5614+
{
5615+
if (!WSHelperVerifyKey($params)) {
55955616
return return_error(WS_ERROR_SECRET_KEY);
55965617
}
55975618
$sql_params = array();
@@ -5602,7 +5623,11 @@ function WSListSessions($params) {
56025623
if (!empty($params['date_end'])) {
56035624
$sql_params['s.date_end'] = array('operator' => '<=', 'value' => $params['date_end']);
56045625
}
5605-
$sessions_list = SessionManager::get_sessions_list($sql_params);
5626+
5627+
$from = isset($params['from']) ? $params['from'] : null;
5628+
$to = isset($params['to']) ? $params['to'] : null;
5629+
5630+
$sessions_list = SessionManager::get_sessions_list($sql_params, null, $from, $to);
56065631
$return_list = array();
56075632
foreach ($sessions_list as $session) {
56085633
$return_list[] = array(

0 commit comments

Comments
 (0)