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__.'/../forum/forumfunction.inc.php'; |
||
8 | require_once __DIR__.'/cm_webservice.php'; |
||
9 | |||
10 | /** |
||
11 | * Description of cm_soap_inbox. |
||
12 | * |
||
13 | * @author marcosousa |
||
14 | */ |
||
15 | class WSCMForum extends WSCM |
||
16 | { |
||
17 | public function get_foruns_id($username, $password, $course_code) |
||
18 | { |
||
19 | if ($this->verifyUserPass($username, $password) == "valid") { |
||
20 | $course_db = api_get_course_info($course_code); |
||
21 | $foruns_info = get_forums($id = '', $course_db['code']); |
||
22 | $foruns_id = '#'; |
||
23 | foreach ($foruns_info as $forum) { |
||
24 | if (isset($forum['forum_id'])) { |
||
25 | $foruns_id .= $forum['forum_id']."#"; |
||
26 | } |
||
27 | } |
||
28 | |||
29 | return $foruns_id; |
||
30 | } else { |
||
31 | return get_lang('InvalidId'); |
||
32 | } |
||
33 | } |
||
34 | |||
35 | public function get_forum_title( |
||
36 | $username, |
||
37 | $password, |
||
38 | $course_code, |
||
39 | $forum_id |
||
40 | ) { |
||
41 | if ($this->verifyUserPass($username, $password) == "valid") { |
||
42 | $course_db = api_get_course_info($course_code); |
||
43 | $table_forums = Database::get_course_table(TABLE_FORUM, $course_db['db_name']); |
||
44 | $table_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_db['db_name']); |
||
45 | |||
46 | $sql = "SELECT * FROM ".$table_forums." forums, ".$table_item_property." item_properties |
||
47 | WHERE item_properties.tool='".TOOL_FORUM."' |
||
48 | AND item_properties.ref='".Database::escape_string($forum_id)."' |
||
49 | AND forums.forum_id='".Database::escape_string($forum_id)."'"; |
||
50 | $result = Database::query($sql); |
||
51 | $forum_info = Database::fetch_array($result); |
||
52 | $forum_info['approval_direct_post'] = 0; // we can't anymore change this option, so it should always be activated |
||
53 | |||
54 | $forum_title = utf8_decode($forum_info['forum_title']); |
||
55 | |||
56 | return $forum_title; |
||
57 | } else { |
||
58 | return get_lang('InvalidId'); |
||
59 | } |
||
60 | } |
||
61 | |||
62 | public function get_forum_threads_id( |
||
63 | $username, |
||
64 | $password, |
||
65 | $course_code, |
||
66 | $forum_id |
||
67 | ) { |
||
68 | if ($this->verifyUserPass($username, $password) == "valid") { |
||
69 | $threads_info = get_threads($forum_id); |
||
70 | $threads_id = '#'; |
||
71 | foreach ($threads_info as $thread) { |
||
72 | if (isset($thread['thread_id'])) { |
||
73 | $threads_id .= $thread['thread_id']."#"; |
||
74 | } |
||
75 | } |
||
76 | |||
77 | return $threads_id; |
||
78 | } else { |
||
79 | return get_lang('InvalidId'); |
||
80 | } |
||
81 | } |
||
82 | |||
83 | public function get_forum_thread_data( |
||
84 | $username, |
||
85 | $password, |
||
86 | $course_code, |
||
87 | $thread_id, |
||
88 | $field |
||
89 | ) { |
||
90 | if ($this->verifyUserPass($username, $password) == "valid") { |
||
91 | $course_db = api_get_course_info($course_code); |
||
92 | $table_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_db['db_name']); |
||
93 | $table_threads = Database::get_course_table(TABLE_FORUM_THREAD, $course_db['db_name']); |
||
94 | |||
95 | $sql = "SELECT * FROM ".$table_threads." threads, ".$table_item_property." item_properties |
||
96 | WHERE item_properties.tool='".TOOL_FORUM_THREAD."' |
||
97 | AND item_properties.ref='".Database::escape_string($thread_id)."' |
||
98 | AND threads.thread_id='".Database::escape_string($thread_id)."'"; |
||
99 | $result = Database::query($sql); |
||
100 | $thread_info = Database::fetch_array($result); |
||
101 | |||
102 | switch ($field) { |
||
103 | case 'title': |
||
104 | $htmlcode = true; |
||
105 | $field_table = "thread_title"; |
||
106 | break; |
||
107 | case 'date': |
||
108 | $field_table = "thread_date"; |
||
109 | break; |
||
110 | case 'sender': |
||
111 | $field_table = "insert_user_id"; |
||
112 | break; |
||
113 | case 'sender_name': |
||
114 | $user_id = $thread_info['insert_user_id']; |
||
115 | $user_info = api_get_user_info($user_id); |
||
116 | |||
117 | return $user_info['firstname']; |
||
118 | break; |
||
0 ignored issues
–
show
|
|||
119 | default: |
||
120 | $field_table = "title"; |
||
121 | } |
||
122 | |||
123 | return $thread_info[$field_table]; |
||
124 | } else { |
||
125 | return get_lang('InvalidId'); |
||
126 | } |
||
127 | } |
||
128 | |||
129 | public function get_forum_thread_title( |
||
130 | $username, |
||
131 | $password, |
||
132 | $course_code, |
||
133 | $thread_id |
||
134 | ) { |
||
135 | if ($this->verifyUserPass($username, $password) == "valid") { |
||
136 | $course_db = api_get_course_info($course_code); |
||
137 | $table_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_db['db_name']); |
||
138 | $table_threads = Database::get_course_table(TABLE_FORUM_THREAD, $course_db['db_name']); |
||
139 | |||
140 | $sql = "SELECT * FROM ".$table_threads." threads, ".$table_item_property." item_properties |
||
141 | WHERE item_properties.tool='".TOOL_FORUM_THREAD."' |
||
142 | AND item_properties.ref='".Database::escape_string($thread_id)."' |
||
143 | AND threads.thread_id='".Database::escape_string($thread_id)."'"; |
||
144 | $result = Database::query($sql); |
||
145 | $thread_info = Database::fetch_array($result); |
||
146 | |||
147 | $htmlcode = true; |
||
148 | $field_table = "thread_title"; |
||
149 | |||
150 | return $thread_info[$field_table]; |
||
151 | } else { |
||
152 | return get_lang('InvalidId'); |
||
153 | } |
||
154 | } |
||
155 | |||
156 | public function get_posts_id($username, $password, $course_code, $thread_id) |
||
157 | { |
||
158 | if ($this->verifyUserPass($username, $password) == "valid") { |
||
159 | $course_db = api_get_course_info($course_code); |
||
160 | |||
161 | $table_users = Database::get_main_table(TABLE_MAIN_USER); |
||
162 | $table_posts = Database::get_course_table(TABLE_FORUM_POST, $course_db['db_name']); |
||
163 | |||
164 | // note: change these SQL so that only the relevant fields of the user table are used |
||
165 | if (api_is_allowed_to_edit(null, true)) { |
||
166 | $sql = "SELECT * FROM $table_posts posts |
||
167 | LEFT JOIN $table_users users |
||
168 | ON posts.poster_id=users.user_id |
||
169 | WHERE posts.thread_id='".Database::escape_string($thread_id)."' |
||
170 | ORDER BY posts.post_id ASC"; |
||
171 | } else { |
||
172 | // students can only se the posts that are approved (posts.visible='1') |
||
173 | $sql = "SELECT * FROM $table_posts posts |
||
174 | LEFT JOIN $table_users users |
||
175 | ON posts.poster_id=users.user_id |
||
176 | WHERE posts.thread_id='".Database::escape_string($thread_id)."' |
||
177 | AND posts.visible='1' |
||
178 | ORDER BY posts.post_id ASC"; |
||
179 | } |
||
180 | $result = Database::query($sql); |
||
181 | while ($row = Database::fetch_array($result)) { |
||
182 | $posts_info[] = $row; |
||
183 | } |
||
184 | |||
185 | $posts_id = '#'; |
||
186 | |||
187 | foreach ($posts_info as $post) { |
||
188 | if (isset($post['post_id'])) { |
||
189 | $posts_id .= $post['post_id']."#"; |
||
190 | } |
||
191 | } |
||
192 | |||
193 | return $posts_id; |
||
194 | } else { |
||
195 | return get_lang('InvalidId'); |
||
196 | } |
||
197 | } |
||
198 | |||
199 | public function get_post_data( |
||
200 | $username, |
||
201 | $password, |
||
202 | $course_code, |
||
203 | $post_id, |
||
204 | $field |
||
205 | ) { |
||
206 | if ($this->verifyUserPass($username, $password) == "valid") { |
||
207 | $table_posts = Database::get_course_table(TABLE_FORUM_POST); |
||
208 | $table_users = Database::get_main_table(TABLE_MAIN_USER); |
||
209 | |||
210 | $sql = "SELECT * FROM ".$table_posts."posts, ".$table_users." users |
||
211 | WHERE posts.poster_id=users.user_id AND posts.post_id='".Database::escape_string($post_id)."'"; |
||
212 | $result = Database::query($sql); |
||
213 | $post_info = Database::fetch_array($result); |
||
214 | |||
215 | $htmlcode = false; |
||
216 | switch ($field) { |
||
217 | case 'title': |
||
218 | $htmlcode = true; |
||
219 | $field_table = "post_title"; |
||
220 | break; |
||
221 | case 'text': |
||
222 | $htmlcode = true; |
||
223 | $field_table = "post_text"; |
||
224 | break; |
||
225 | case 'date': |
||
226 | $field_table = "post_date"; |
||
227 | break; |
||
228 | case 'sender': |
||
229 | $field_table = "user_id"; |
||
230 | break; |
||
231 | case 'sender_name': |
||
232 | $field_table = "firstname"; |
||
233 | break; |
||
234 | default: |
||
235 | $htmlcode = true; |
||
236 | $field_table = "title"; |
||
237 | } |
||
238 | |||
239 | return ($htmlcode) ? html_entity_decode($post_info[$field_table]) : $post_info[$field_table]; |
||
240 | } else { |
||
241 | return get_lang('InvalidId'); |
||
242 | } |
||
243 | } |
||
244 | |||
245 | public function send_post( |
||
246 | $username, |
||
247 | $password, |
||
248 | $course_code, |
||
249 | $forum_id, |
||
250 | $thread_id, |
||
251 | $title, |
||
252 | $content |
||
253 | ) { |
||
254 | if ($this->verifyUserPass($username, $password) == "valid") { |
||
255 | $em = Database::getManager(); |
||
256 | $course_db = api_get_course_info($course_code); |
||
257 | |||
258 | $user_id = UserManager::get_user_id_from_username($username); |
||
259 | $table_threads = Database::get_course_table(TABLE_FORUM_THREAD, $course_db['db_name']); |
||
260 | $forum_table_attachment = Database::get_course_table(TABLE_FORUM_ATTACHMENT, $course_db['db_name']); |
||
261 | $table_posts = Database::get_course_table(TABLE_FORUM_POST, $course_db['db_name']); |
||
262 | $post_date = date('Y-m-d H:i:s'); |
||
263 | $visible = 1; |
||
264 | $has_attachment = false; |
||
265 | $my_post = ''; |
||
266 | $post_notification = ''; |
||
267 | |||
268 | $content = nl2br($content); |
||
269 | |||
270 | $title = htmlentities($title); |
||
271 | $content = htmlentities($content); |
||
272 | |||
273 | $postDate = new DateTime(api_get_utc_datetime(), new DateTimeZone('UTC')); |
||
274 | $post = new \Chamilo\CourseBundle\Entity\CForumPost(); |
||
275 | $post |
||
276 | ->setPostTitle($title) |
||
277 | ->setPostText(isset($content) ? (api_html_entity_decode($content)) : null) |
||
278 | ->setThreadId($thread_id) |
||
279 | ->setForumId($forum_id) |
||
280 | ->setPosterId($user_id) |
||
281 | ->setPostDate($postDate) |
||
282 | ->setPostNotification(isset($post_notification) ? $post_notification : null) |
||
283 | ->setPostParentId(isset($my_post) ? $my_post : null) |
||
284 | ->setVisible($visible); |
||
285 | |||
286 | $em->persist($post); |
||
287 | $em->flush(); |
||
288 | |||
289 | return "Post enviado!"; |
||
290 | } else { |
||
291 | return get_lang('InvalidId'); |
||
292 | } |
||
293 | } |
||
294 | } |
||
295 | |||
296 | /* |
||
297 | echo "aqui: "; |
||
298 | $aqui = new WSCMForum(); |
||
299 | echo "<pre>"; |
||
300 | |||
301 | //print_r($aqui->unreadMessage("aluno", "e695f51fe3dd6b7cf2be3188a614f10f")); |
||
302 | //print_r($aqui->get_post_data("aluno", "c4ca4238a0b923820dcc509a6f75849b", "95", "sender_name")); |
||
303 | |||
304 | print_r($aqui->send_post("aluno", "c4ca4238a0b923820dcc509a6f75849b", "P0304", "3", "15", "títle", "conteúdo222222")); |
||
305 | echo "</pre>"; |
||
306 | */ |
||
307 |
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.