1 | <?php |
||
2 | /* For licensing terms, see /license.txt */ |
||
3 | /** |
||
4 | * @package chamilo.webservices |
||
5 | */ |
||
6 | require_once __DIR__.'/../inc/global.inc.php'; |
||
7 | require_once __DIR__.'/cm_webservice.php'; |
||
8 | |||
9 | /** |
||
10 | * Description of cm_soap_user. |
||
11 | * |
||
12 | * @author marcosousa |
||
13 | */ |
||
14 | class WSCMUser extends WSCM |
||
15 | { |
||
16 | public function find_id_user($username, $password, $name) |
||
17 | { |
||
18 | if ($this->verifyUserPass($username, $password) == "valid") { |
||
19 | $listResult = "#"; |
||
20 | |||
21 | $listArrayResult = []; |
||
22 | $listArray = []; |
||
23 | |||
24 | $list = $this->get_user_list_like_start( |
||
25 | ['firstname' => $name], |
||
26 | ['firstname'] |
||
27 | ); |
||
28 | foreach ($list as $userData) { |
||
29 | $listArray[] = $userData['user_id']; |
||
30 | } |
||
31 | |||
32 | $list = $this->get_user_list_like_start( |
||
33 | ['lastname' => $name], |
||
34 | ['firstname'] |
||
35 | ); |
||
36 | foreach ($list as $userData) { |
||
37 | $listArray[] = $userData['user_id']; |
||
38 | } |
||
39 | |||
40 | $list = $this->get_user_list_like_start( |
||
41 | ['email' => $name], |
||
42 | ['firstname'] |
||
43 | ); |
||
44 | foreach ($list as $userData) { |
||
45 | $listArray[] = $userData['user_id']; |
||
46 | } |
||
47 | |||
48 | $listArrayResult = array_unique($listArray); |
||
49 | foreach ($listArrayResult as $result) { |
||
50 | $listResult .= $result."#"; |
||
51 | } |
||
52 | |||
53 | return $listResult; |
||
54 | } |
||
55 | |||
56 | return "0"; |
||
57 | } |
||
58 | |||
59 | public function get_link_user_picture($username, $password, $id) |
||
60 | { |
||
61 | if ($this->verifyUserPass($username, $password) == "valid") { |
||
62 | $userPic = UserManager::getUserPicture($id); |
||
63 | if (empty($userPic)) { |
||
64 | return "0"; |
||
65 | } |
||
66 | |||
67 | return $userPic; |
||
68 | } |
||
69 | |||
70 | return "0"; |
||
71 | } |
||
72 | |||
73 | public function get_user_name($username, $password, $id, $field) |
||
74 | { |
||
75 | if ($this->verifyUserPass($username, $password) == "valid") { |
||
76 | $userInfo = api_get_user_info($id); |
||
77 | switch ($field) { |
||
78 | case 'firstname': |
||
79 | return $userInfo['firstname']; |
||
80 | break; |
||
0 ignored issues
–
show
|
|||
81 | case 'lastname': |
||
82 | return $userInfo['lastname']; |
||
83 | break; |
||
84 | case 'bothfl': |
||
85 | return $userInfo['firstname']." ".$userInfo['lastname']; |
||
86 | break; |
||
87 | case 'bothlf': |
||
88 | return $userInfo['lastname']." ".$userInfo['firstname']; |
||
89 | break; |
||
90 | default: |
||
91 | return $userInfo['firstname']; |
||
92 | } |
||
93 | |||
94 | return "0"; |
||
0 ignored issues
–
show
return '0' is not reachable.
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed. Unreachable code is most often the result of function fx() {
try {
doSomething();
return true;
}
catch (\Exception $e) {
return false;
}
return false;
}
In the above example, the last
Loading history...
|
|||
95 | } |
||
96 | |||
97 | return "0"; |
||
98 | } |
||
99 | |||
100 | public function send_invitation( |
||
101 | $username, |
||
102 | $password, |
||
103 | $userfriend_id, |
||
104 | $content_message = '' |
||
105 | ) { |
||
106 | global $charset; |
||
107 | if ($this->verifyUserPass($username, $password) == "valid") { |
||
108 | $user_id = UserManager::get_user_id_from_username($username); |
||
109 | $message_title = get_lang('Invitation'); |
||
110 | $count_is_true = SocialManager::send_invitation_friend( |
||
111 | $user_id, |
||
112 | $userfriend_id, |
||
113 | $message_title, |
||
114 | $content_message |
||
115 | ); |
||
116 | |||
117 | if ($count_is_true) { |
||
118 | return Display::return_message( |
||
119 | api_htmlentities( |
||
120 | get_lang('InvitationHasBeenSent'), |
||
121 | ENT_QUOTES, |
||
122 | $charset |
||
123 | ), |
||
124 | 'normal', |
||
125 | false |
||
126 | ); |
||
127 | } else { |
||
128 | return Display::return_message( |
||
129 | api_htmlentities( |
||
130 | get_lang('YouAlreadySentAnInvitation'), |
||
131 | ENT_QUOTES, |
||
132 | $charset |
||
133 | ), |
||
134 | 'error', |
||
135 | false |
||
136 | ); |
||
137 | } |
||
138 | } |
||
139 | |||
140 | return get_lang('InvalidId'); |
||
141 | } |
||
142 | |||
143 | public function accept_friend($username, $password, $userfriend_id) |
||
144 | { |
||
145 | if ($this->verifyUserPass($username, $password) == "valid") { |
||
146 | $user_id = UserManager::get_user_id_from_username($username); |
||
147 | UserManager::relate_users( |
||
148 | $userfriend_id, |
||
149 | $user_id, |
||
150 | USER_RELATION_TYPE_FRIEND |
||
151 | ); |
||
152 | SocialManager::invitation_accepted($userfriend_id, $user_id); |
||
153 | |||
154 | return get_lang('AddedContactToList'); |
||
155 | } |
||
156 | |||
157 | return get_lang('InvalidId'); |
||
158 | } |
||
159 | |||
160 | public function denied_invitation($username, $password, $userfriend_id) |
||
161 | { |
||
162 | if ($this->verifyUserPass($username, $password) == "valid") { |
||
163 | $user_id = UserManager::get_user_id_from_username($username); |
||
164 | SocialManager::invitation_denied($userfriend_id, $user_id); |
||
165 | |||
166 | return get_lang('InvitationDenied'); |
||
167 | } |
||
168 | |||
169 | return get_lang('InvalidId'); |
||
170 | } |
||
171 | |||
172 | /** |
||
173 | * Get a list of users of which the given conditions match with a LIKE '%cond%'. |
||
174 | * |
||
175 | * @param array $conditions a list of condition (exemple : status=>STUDENT) |
||
176 | * @param array $order_by a list of fields on which sort |
||
177 | * |
||
178 | * @return array an array with all users of the platform |
||
179 | * |
||
180 | * @todo optional course code parameter, optional sorting parameters... |
||
181 | *@todo Use the UserManager class |
||
182 | * @todo security filter order by |
||
183 | */ |
||
184 | private static function get_user_list_like_start($conditions = [], $order_by = []) |
||
185 | { |
||
186 | $user_table = Database::get_main_table(TABLE_MAIN_USER); |
||
187 | $return_array = []; |
||
188 | $sql_query = "SELECT * FROM $user_table"; |
||
189 | if (count($conditions) > 0) { |
||
190 | $sql_query .= ' WHERE '; |
||
191 | foreach ($conditions as $field => $value) { |
||
192 | $field = Database::escape_string($field); |
||
193 | $value = Database::escape_string($value); |
||
194 | $sql_query .= $field.' LIKE \''.$value.'%\''; |
||
195 | } |
||
196 | } |
||
197 | $order = ''; |
||
198 | foreach ($order_by as $orderByItem) { |
||
199 | $order .= Database::escape_string($orderByItem).', '; |
||
200 | } |
||
201 | $order = substr($order, 0, -2); |
||
202 | if (count($order_by) > 0) { |
||
203 | $sql_query .= ' ORDER BY '.$order; |
||
204 | } |
||
205 | |||
206 | $sql_result = Database::query($sql_query); |
||
207 | while ($result = Database::fetch_array($sql_result)) { |
||
208 | $return_array[] = $result; |
||
209 | } |
||
210 | |||
211 | return $return_array; |
||
212 | } |
||
213 | } |
||
214 |
The
break
statement is not necessary if it is preceded for example by areturn
statement:If you would like to keep this construct to be consistent with other
case
statements, you can safely mark this issue as a false-positive.