Issues (2128)

main/webservices/user_info.soap.php (3 issues)

1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
/**
6
 * This script provides the caller service with user details.
7
 * It is set to work with the Chamilo module for Drupal:
8
 * http://drupal.org/project/chamilo.
9
 *
10
 * @author Yannick Warnier <[email protected]>
11
 */
12
require_once __DIR__.'/../inc/global.inc.php';
13
14
api_protect_webservices();
15
16
// Create the server instance
17
$server = new soap_server();
18
// Initialize WSDL support
19
$server->configureWSDL('WSUserInfo', 'urn:WSUserInfo');
20
21
/* Register WSCourseList function */
22
// Register the data structures used by the service
23
24
$server->wsdl->addComplexType(
25
    'courseDetails',
26
    'complexType',
27
    'struct',
28
    'all',
29
    '',
30
    [
31
        'name' => 'code',
32
        'type' => 'xsd:string',
33
        'name' => 'title',
34
        'type' => 'xsd:string',
35
        'name' => 'url',
36
        'type' => 'xsd:string',
37
        'name' => 'teacher',
38
        'type' => 'xsd:string',
39
        'name' => 'language',
40
        'type' => 'xsd:string',
41
    ]
42
);
43
44
$server->wsdl->addComplexType(
45
    'courseList',
46
    'complexType',
47
    'array',
48
    '',
49
    'SOAP-ENC:Array',
50
    [],
51
    [
52
        [
53
            'ref' => 'SOAP-ENC:arrayType',
54
            'wsdl:arrayType' => 'tns:courseDetails[]',
55
        ],
56
    ],
57
    'tns:courseDetails'
58
);
59
60
// Register the method to expose
61
$server->register(
62
    'WSCourseListOfUser', // method name
63
    [
64
        'username' => 'xsd:string',
65
        'signature' => 'xsd:string',
66
    ], // input parameters
67
    ['return' => 'xsd:Array'], // output parameters
68
    'urn:WSUserInfo', // namespace
69
    'urn:WSUserInfo#WSUserInfo', // soapaction
70
    'rpc', // style
71
    'encoded', // use
72
    'This service returns a list of courses'    // documentation
73
);
74
75
/**
76
 * Get a list of courses (code, url, title, teacher, language) for a specific
77
 * user and return to caller
78
 * Function registered as service. Returns strings in UTF-8.
79
 *
80
 * @param string User name in Chamilo
81
 * @param string Signature (composed of the sha1(username+apikey)
82
 *
83
 * @return array Courses list (code=>[title=>'title',url='http://...',teacher=>'...',language=>''],code=>[...],...)
84
 */
85
function WSCourseListOfUser($username, $signature)
86
{
87
    if (empty($username) or empty($signature)) {
88
        return -1;
89
    }
90
    $info = api_get_user_info_from_username($username);
91
    $user_id = $info['user_id'];
92
    $list = UserManager::get_api_keys($user_id, 'dokeos');
93
    $key = '';
94
    foreach ($list as $key) {
95
        break;
96
    }
97
98
    $local_key = $username.$key;
99
100
    if (!api_is_valid_secret_key($signature, $local_key)) {
101
        return -1; // The secret key is incorrect.
102
    }
103
104
    $courses_list = [];
105
    $courses_list_tmp = CourseManager::get_courses_list_by_user_id($user_id);
106
    foreach ($courses_list_tmp as $index => $course) {
107
        $course_info = CourseManager::get_course_information($course['code']);
0 ignored issues
show
Deprecated Code introduced by
The function CourseManager::get_course_information() has been deprecated: Use api_get_course_info() instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

107
        $course_info = /** @scrutinizer ignore-deprecated */ CourseManager::get_course_information($course['code']);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
108
        $courses_list[] = [
109
            'code' => $course['code'],
110
            'title' => api_utf8_encode($course_info['title']),
111
            'url' => api_get_path(WEB_COURSE_PATH).$course_info['directory'].'/',
112
            'teacher' => api_utf8_encode($course_info['tutor_name']),
113
            'language' => $course_info['course_language'],
114
        ];
115
    }
116
117
    return $courses_list;
118
}
119
120
/* Register WSEventsList function */
121
// Register the data structures used by the service
122
$server->wsdl->addComplexType(
123
    'eventDetails',
124
    'complexType',
125
    'struct',
126
    'all',
127
    '',
128
    [
129
        'name' => 'datestart',
130
        'type' => 'xsd:string',
131
        'name' => 'dateend',
132
        'type' => 'xsd:string',
133
        'name' => 'title',
134
        'type' => 'xsd:string',
135
        'name' => 'link',
136
        'type' => 'xsd:string',
137
        'name' => 'coursetitle',
138
        'type' => 'xsd:string',
139
    ]
140
);
141
142
$server->wsdl->addComplexType(
143
    'eventsList',
144
    'complexType',
145
    'array',
146
    '',
147
    'SOAP-ENC:Array',
148
    [],
149
    [
150
        [
151
            'ref' => 'SOAP-ENC:arrayType',
152
            'wsdl:arrayType' => 'tns:eventDetails[]',
153
        ],
154
    ],
155
    'tns:eventDetails'
156
);
157
158
// Register the method to expose
159
$server->register(
160
    'WSEventsList',
161
    // method name
162
    [
163
        'username' => 'xsd:string',
164
        'signature' => 'xsd:string',
165
        'datestart' => 'xsd:int',
166
        'dateend' => 'xsd:int',
167
    ],
168
    // input parameters
169
    ['return' => 'xsd:Array'],
170
    // output parameters
171
    'urn:WSUserInfo',
172
    // namespace
173
    'urn:WSUserInfo#WSEventsList',
174
    // soapaction
175
    'rpc',
176
    // style
177
    'encoded',
178
    // use
179
    'This service returns a list of events of the courses the given user is subscribed to'      // documentation
180
);
181
182
/**
183
 * Get a list of events between two dates for the given username
184
 * Function registered as service. Returns strings in UTF-8.
185
 *
186
 * @param string Username
187
 * @param string User's API key (the user's API key)
0 ignored issues
show
Documentation Bug introduced by
The doc comment User's at position 0 could not be parsed: Unknown type name 'User's' at position 0 in User's.
Loading history...
188
 * @param int    Start date, in YYYYMMDD format
189
 * @param int    End date, in YYYYMMDD format
190
 *
191
 * @return array Events list
192
 */
193
function WSEventsList($username, $signature, $datestart = 0, $dateend = 0)
194
{
195
    if (empty($username) or empty($signature)) {
196
        return -1;
197
    }
198
199
    $info = api_get_user_info_from_username($username);
200
    $user_id = $info['user_id'];
201
    $list = UserManager::get_api_keys($user_id, 'dokeos');
202
    $key = '';
203
    foreach ($list as $key) {
204
        break;
205
    }
206
207
    $local_key = $username.$key;
208
209
    if (!api_is_valid_secret_key($signature, $local_key)) {
210
        return -1; // The secret key is incorrect.
211
    }
212
    $events_list = [];
213
214
    $user_id = UserManager::get_user_id_from_username($username);
215
    if ($user_id === false) {
216
        return $events_list;
217
    } // Error in user id recovery.
218
    $ds = substr($datestart, 0, 4).'-'.substr($datestart, 4, 2).'-'.substr($datestart, 6, 2).' 00:00:00';
219
    $de = substr($dateend, 0, 4).'-'.substr($dateend, 4, 2).'-'.substr($dateend, 6, 2).' 00:00:00';
220
    $events_list = Agenda::get_personal_agenda_items_between_dates(
0 ignored issues
show
Deprecated Code introduced by
The function Agenda::get_personal_agenda_items_between_dates() has been deprecated: use agenda events ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

220
    $events_list = /** @scrutinizer ignore-deprecated */ Agenda::get_personal_agenda_items_between_dates(

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
221
        $user_id,
222
        $ds,
223
        $de
224
    );
225
226
    return $events_list;
227
}
228
229
// Use the request to (try to) invoke the service.
230
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
231
$server->service($HTTP_RAW_POST_DATA);
232