11<?php
22/* For licensing terms, see /license.txt */
3- /**
4- * @package chamilo.library
5- */
6- /**
7- * Code
8- */
9-
103
114/**
12- * This is the system announcements library for Dokeos.
13- *
14- * @package chamilo.library
15- */
16- class SystemAnnouncementManager {
17-
5+ * Class SystemAnnouncementManager
6+ */
7+ class SystemAnnouncementManager
8+ {
189 CONST VISIBLE_GUEST = 1 ;
1910 CONST VISIBLE_STUDENT = 2 ;
2011 CONST VISIBLE_TEACHER = 3 ;
@@ -24,7 +15,8 @@ class SystemAnnouncementManager {
2415 * @param int $visible VISIBLE_GUEST, VISIBLE_STUDENT or VISIBLE_TEACHER
2516 * @param int $id The identifier of the announcement to display
2617 */
27- public static function display_announcements ($ visible , $ id = -1 ) {
18+ public static function display_announcements ($ visible , $ id = -1 )
19+ {
2820 $ user_selected_language = api_get_interface_language ();
2921 $ db_table = Database :: get_main_table (TABLE_MAIN_SYSTEM_ANNOUNCEMENTS );
3022 $ tbl_announcement_group = Database :: get_main_table (TABLE_MAIN_SYSTEM_ANNOUNCEMENTS_GROUPS );
@@ -76,9 +68,7 @@ public static function display_announcements($visible, $id = -1) {
7668 $ query_string = ereg_replace ('&$ ' , '' , $ query_string );
7769 $ url = api_get_self ();
7870 echo '<div class="system_announcements"> ' ;
79-
8071 echo '<h3> ' .get_lang ('SystemAnnouncements ' ).'</h3> ' ;
81-
8272 echo '<div style="margin:10px;text-align:right;"><a href="news_list.php"> ' .get_lang ('More ' ).'</a></div> ' ;
8373
8474 while ($ announcement = Database::fetch_object ($ announcements )) {
@@ -107,7 +97,15 @@ public static function display_announcements($visible, $id = -1) {
10797 return ;
10898 }
10999
110- public static function display_all_announcements ($ visible , $ id = -1 , $ start = 0 ,$ user_id ='' ) {
100+ /**
101+ * @param $visible
102+ * @param $id
103+ * @param int $start
104+ * @param string $user_id
105+ * @return string
106+ */
107+ public static function display_all_announcements ($ visible , $ id = -1 , $ start = 0 ,$ user_id ='' )
108+ {
111109 $ user_selected_language = api_get_interface_language ();
112110 $ start = intval ($ start );
113111
@@ -200,7 +198,12 @@ public static function display_all_announcements($visible, $id = -1, $start = 0,
200198 return $ content ;
201199 }
202200
203- public static function display_arrow ($ user_id ) {
201+ /**
202+ * @param int $user_id
203+ * @return string
204+ */
205+ public static function display_arrow ($ user_id )
206+ {
204207 $ start = (int )$ _GET ['start ' ];
205208 $ nb_announcement = SystemAnnouncementManager :: count_nb_announcement ($ start ,$ user_id );
206209 $ next = ((int )$ _GET ['start ' ]+19 );
@@ -219,7 +222,13 @@ public static function display_arrow($user_id) {
219222 return $ content ;
220223 }
221224
222- public static function count_nb_announcement ($ start = 0 , $ user_id = '' ) {
225+ /**
226+ * @param int $start
227+ * @param string $user_id
228+ * @return int
229+ */
230+ public static function count_nb_announcement ($ start = 0 , $ user_id = '' )
231+ {
223232 $ start = intval ($ start );
224233 $ visibility = api_is_allowed_to_create_course () ? self ::VISIBLE_TEACHER : self ::VISIBLE_STUDENT ;
225234 $ user_selected_language = api_get_interface_language ();
@@ -261,7 +270,8 @@ public static function count_nb_announcement($start = 0, $user_id = '') {
261270 * @return array An array with all available system announcements (as php
262271 * objects)
263272 */
264- public static function get_all_announcements () {
273+ public static function get_all_announcements ()
274+ {
265275 $ db_table = Database :: get_main_table (TABLE_MAIN_SYSTEM_ANNOUNCEMENTS );
266276 $ now = api_get_utc_datetime ();
267277 $ sql = "SELECT *, IF( ' $ now' >= date_start AND ' $ now' <= date_end, '1', '0') AS visible FROM $ db_table " ;
@@ -295,8 +305,19 @@ public static function get_all_announcements() {
295305 * @param int Whether to send an e-mail to all users (1) or not (0)
296306 * @return mixed insert_id on success, false on failure
297307 */
298- public static function add_announcement ($ title , $ content , $ date_start , $ date_end , $ visible_teacher = 0 , $ visible_student = 0 , $ visible_guest = 0 , $ lang = null , $ send_mail = 0 , $ add_to_calendar = false , $ sendEmailTest = false ) {
299-
308+ public static function add_announcement (
309+ $ title ,
310+ $ content ,
311+ $ date_start ,
312+ $ date_end ,
313+ $ visible_teacher = 0 ,
314+ $ visible_student = 0 ,
315+ $ visible_guest = 0 ,
316+ $ lang = null ,
317+ $ send_mail = 0 ,
318+ $ add_to_calendar = false ,
319+ $ sendEmailTest = false
320+ ) {
300321 $ original_content = $ content ;
301322 $ a_dateS = explode (' ' ,$ date_start );
302323 $ a_arraySD = explode ('- ' ,$ a_dateS [0 ]);
@@ -362,12 +383,14 @@ public static function add_announcement($title, $content, $date_start, $date_end
362383 }
363384 return Database::insert_id ();
364385 }
386+
365387 /**
366388 * Makes the announcement id visible only for groups in groups_array
367389 * @param int announcement id
368390 * @param array array of group id
369391 **/
370- public static function announcement_for_groups ($ announcement_id , $ group_array ){
392+ public static function announcement_for_groups ($ announcement_id , $ group_array )
393+ {
371394 $ tbl_announcement_group = Database :: get_main_table (TABLE_MAIN_SYSTEM_ANNOUNCEMENTS_GROUPS );
372395 //first delete all group associations for this announcement
373396 $ res = Database::query ("DELETE FROM $ tbl_announcement_group where announcement_id= " .intval ($ announcement_id ));
@@ -388,12 +411,14 @@ public static function announcement_for_groups($announcement_id, $group_array){
388411 }
389412 return true ;
390413 }
391- /**
392- * Gets the groups of this announce
393- * @param int announcement id
394- * @return array array of group id
395- **/
396- public static function get_announcement_groups ($ announcement_id ){
414+
415+ /**
416+ * Gets the groups of this announce
417+ * @param int announcement id
418+ * @return array array of group id
419+ **/
420+ public static function get_announcement_groups ($ announcement_id )
421+ {
397422 $ tbl_announcement_group = Database :: get_main_table (TABLE_MAIN_SYSTEM_ANNOUNCEMENTS_GROUPS );
398423 $ tbl_group = Database :: get_main_table (TABLE_MAIN_GROUP );
399424 //first delete all group associations for this announcement
@@ -403,7 +428,7 @@ public static function get_announcement_groups($announcement_id){
403428 ." AND ag.group_id = g.id " );
404429 $ groups = Database::fetch_array ($ res );
405430 return $ groups ;
406- }
431+ }
407432
408433 /**
409434 * Updates an announcement to the database
@@ -414,7 +439,19 @@ public static function get_announcement_groups($announcement_id){
414439 * @param array $date_end : end date of announcement (0 => day ; 1 => month ; 2 => year ; 3 => hour ; 4 => minute)
415440 * @return bool True on success, false on failure
416441 */
417- public static function update_announcement ($ id , $ title , $ content , $ date_start , $ date_end , $ visible_teacher = 0 , $ visible_student = 0 , $ visible_guest = 0 ,$ lang =null , $ send_mail =0 , $ sendEmailTest = false ) {
442+ public static function update_announcement (
443+ $ id ,
444+ $ title ,
445+ $ content ,
446+ $ date_start ,
447+ $ date_end ,
448+ $ visible_teacher = 0 ,
449+ $ visible_student = 0 ,
450+ $ visible_guest = 0 ,
451+ $ lang = null ,
452+ $ send_mail = 0 ,
453+ $ sendEmailTest = false
454+ ) {
418455 $ a_dateS = explode (' ' ,$ date_start );
419456 $ a_arraySD = explode ('- ' ,$ a_dateS [0 ]);
420457 $ a_arraySH = explode (': ' ,$ a_dateS [1 ]);
@@ -432,14 +469,17 @@ public static function update_announcement($id, $title, $content, $date_start, $
432469 Display :: display_normal_message (get_lang ('InvalidStartDate ' ));
433470 return false ;
434471 }
472+
435473 if (($ date_end_to_compare [1 ] || $ date_end_to_compare [2 ] || $ date_end_to_compare [0 ]) && !checkdate ($ date_end_to_compare [1 ], $ date_end_to_compare [2 ], $ date_end_to_compare [0 ])) {
436474 Display :: display_normal_message (get_lang ('InvalidEndDate ' ));
437475 return false ;
438476 }
439- if ( strlen (trim ($ title )) == 0 ) {
477+
478+ if (strlen (trim ($ title )) == 0 ) {
440479 Display::display_normal_message (get_lang ('InvalidTitle ' ));
441480 return false ;
442481 }
482+
443483 $ start = api_get_utc_datetime ($ date_start );
444484 $ end = api_get_utc_datetime ($ date_end );
445485
@@ -468,12 +508,14 @@ public static function update_announcement($id, $title, $content, $date_start, $
468508 }
469509 return true ;
470510 }
511+
471512 /**
472513 * Deletes an announcement
473514 * @param int $id The identifier of the announcement that should be
474515 * @return bool True on success, false on failure
475516 */
476- public static function delete_announcement ($ id ) {
517+ public static function delete_announcement ($ id )
518+ {
477519 $ db_table = Database :: get_main_table (TABLE_MAIN_SYSTEM_ANNOUNCEMENTS );
478520 $ id = intval ($ id );
479521 $ sql = "DELETE FROM " .$ db_table ." WHERE id = " .$ id ;
@@ -484,25 +526,29 @@ public static function delete_announcement($id) {
484526 }
485527 return true ;
486528 }
529+
487530 /**
488531 * Gets an announcement
489532 * @param int $id The identifier of the announcement that should be
490533 * @return object Object of class StdClass or the required class, containing the query result row
491534 */
492- public static function get_announcement ($ id ) {
535+ public static function get_announcement ($ id )
536+ {
493537 $ db_table = Database :: get_main_table (TABLE_MAIN_SYSTEM_ANNOUNCEMENTS );
494538 $ id = intval ($ id );
495539 $ sql = "SELECT * FROM " .$ db_table ." WHERE id = " .$ id ;
496540 $ announcement = Database::fetch_object (Database::query ($ sql ));
497541 return $ announcement ;
498542 }
543+
499544 /**
500545 * Change the visibility of an announcement
501546 * @param int $announcement_id
502547 * @param int $user For who should the visibility be changed (possible values are VISIBLE_TEACHER, VISIBLE_STUDENT, VISIBLE_GUEST)
503548 * @return bool True on success, false on failure
504549 */
505- public static function set_visibility ($ announcement_id , $ user , $ visible ) {
550+ public static function set_visibility ($ announcement_id , $ user , $ visible )
551+ {
506552 $ db_table = Database::get_main_table (TABLE_MAIN_SYSTEM_ANNOUNCEMENTS );
507553 $ visible = intval ($ visible );
508554 $ announcement_id = intval ($ announcement_id );
@@ -531,7 +577,8 @@ public static function set_visibility($announcement_id, $user, $visible) {
531577 * @param string Language (optional, considered for all languages if left empty)
532578 * @return bool True if the message was sent or there was no destination matching. False on database or e-mail sending error.
533579 */
534- public static function send_system_announcement_by_email ($ title , $ content , $ teacher , $ student , $ language = null , $ sendEmailTest = false ) {
580+ public static function send_system_announcement_by_email ($ title , $ content , $ teacher , $ student , $ language = null , $ sendEmailTest = false )
581+ {
535582 global $ charset ;
536583
537584 $ title = api_html_entity_decode (stripslashes ($ title ), ENT_QUOTES , $ charset );
@@ -590,13 +637,13 @@ public static function send_system_announcement_by_email($title, $content, $teac
590637 return $ message_sent ; //true if at least one e-mail was sent
591638 }
592639
593-
594640 /**
595641 * Displays announcements as an slideshow
596642 * @param int $visible VISIBLE_GUEST, VISIBLE_STUDENT or VISIBLE_TEACHER
597643 * @param int $id The identifier of the announcement to display
598644 */
599- public static function display_announcements_slider ($ visible , $ id = null ) {
645+ public static function display_announcements_slider ($ visible , $ id = null )
646+ {
600647 $ user_selected_language = Database::escape_string (api_get_interface_language ());
601648 $ table = Database :: get_main_table (TABLE_MAIN_SYSTEM_ANNOUNCEMENTS );
602649
0 commit comments