|
|
|
|
@ -249,6 +249,8 @@ class SystemAnnouncementManager |
|
|
|
|
* @param int $send_mail Whether to send an e-mail to all users (1) or not (0) |
|
|
|
|
* @param bool $add_to_calendar |
|
|
|
|
* @param bool $sendEmailTest |
|
|
|
|
* @param int $careerId |
|
|
|
|
* @param int $promotionId |
|
|
|
|
* |
|
|
|
|
* @return mixed insert_id on success, false on failure |
|
|
|
|
*/ |
|
|
|
|
@ -261,7 +263,9 @@ class SystemAnnouncementManager |
|
|
|
|
$lang = '', |
|
|
|
|
$send_mail = 0, |
|
|
|
|
$add_to_calendar = false, |
|
|
|
|
$sendEmailTest = false |
|
|
|
|
$sendEmailTest = false, |
|
|
|
|
$careerId = 0, |
|
|
|
|
$promotionId = 0 |
|
|
|
|
) { |
|
|
|
|
$original_content = $content; |
|
|
|
|
$a_dateS = explode(' ', $date_start); |
|
|
|
|
@ -336,6 +340,11 @@ class SystemAnnouncementManager |
|
|
|
|
'access_url_id' => $current_access_url_id, |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
if (api_get_configuration_value('allow_careers_in_global_announcements') && !empty($careerId)) { |
|
|
|
|
$params['career_id'] = (int) $careerId; |
|
|
|
|
$params['promotion_id'] = (int) $promotionId; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
foreach ($visibility as $key => $value) { |
|
|
|
|
$params[$key] = $value; |
|
|
|
|
} |
|
|
|
|
@ -345,19 +354,15 @@ class SystemAnnouncementManager |
|
|
|
|
if ($resultId) { |
|
|
|
|
if ($sendEmailTest) { |
|
|
|
|
self::send_system_announcement_by_email( |
|
|
|
|
$title, |
|
|
|
|
$content, |
|
|
|
|
$resultId, |
|
|
|
|
$visibility, |
|
|
|
|
$lang, |
|
|
|
|
true |
|
|
|
|
); |
|
|
|
|
} else { |
|
|
|
|
if ($send_mail == 1) { |
|
|
|
|
self::send_system_announcement_by_email( |
|
|
|
|
$title, |
|
|
|
|
$content, |
|
|
|
|
$visibility, |
|
|
|
|
$lang |
|
|
|
|
$resultId, |
|
|
|
|
$visibility |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -454,6 +459,8 @@ class SystemAnnouncementManager |
|
|
|
|
* @param array $lang |
|
|
|
|
* @param int $send_mail |
|
|
|
|
* @param bool $sendEmailTest |
|
|
|
|
* @param int $careerId |
|
|
|
|
* @param int $promotionId |
|
|
|
|
* |
|
|
|
|
* @return bool True on success, false on failure |
|
|
|
|
*/ |
|
|
|
|
@ -466,7 +473,9 @@ class SystemAnnouncementManager |
|
|
|
|
$visibility, |
|
|
|
|
$lang = null, |
|
|
|
|
$send_mail = 0, |
|
|
|
|
$sendEmailTest = false |
|
|
|
|
$sendEmailTest = false, |
|
|
|
|
$careerId = 0, |
|
|
|
|
$promotionId = 0 |
|
|
|
|
) { |
|
|
|
|
$em = Database::getManager(); |
|
|
|
|
$announcement = $em->find('ChamiloCoreBundle:SysAnnouncement', $id); |
|
|
|
|
@ -525,26 +534,6 @@ class SystemAnnouncementManager |
|
|
|
|
$content |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if ($sendEmailTest) { |
|
|
|
|
self::send_system_announcement_by_email( |
|
|
|
|
$title, |
|
|
|
|
$content, |
|
|
|
|
null, |
|
|
|
|
null, |
|
|
|
|
$lang, |
|
|
|
|
$sendEmailTest |
|
|
|
|
); |
|
|
|
|
} else { |
|
|
|
|
if ($send_mail == 1) { |
|
|
|
|
self::send_system_announcement_by_email( |
|
|
|
|
$title, |
|
|
|
|
$content, |
|
|
|
|
$visibility, |
|
|
|
|
$lang |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$dateStart = new DateTime($start, new DateTimeZone('UTC')); |
|
|
|
|
$dateEnd = new DateTime($end, new DateTimeZone('UTC')); |
|
|
|
|
|
|
|
|
|
@ -565,12 +554,40 @@ class SystemAnnouncementManager |
|
|
|
|
// Update visibility |
|
|
|
|
$list = self::getVisibilityList(); |
|
|
|
|
$table = Database::get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
|
|
|
|
|
|
|
|
if (api_get_configuration_value('allow_careers_in_global_announcements') && !empty($careerId)) { |
|
|
|
|
$params = []; |
|
|
|
|
$params['career_id'] = (int) $careerId; |
|
|
|
|
$params['promotion_id'] = (int) $promotionId; |
|
|
|
|
Database::update( |
|
|
|
|
$table, |
|
|
|
|
$params, |
|
|
|
|
['id = ? ' => $id] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
foreach ($list as $key => $title) { |
|
|
|
|
$value = isset($visibility[$key]) && $visibility[$key] ? 1 : 0; |
|
|
|
|
$sql = "UPDATE $table SET $key = '$value' WHERE id = $id"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($sendEmailTest) { |
|
|
|
|
self::send_system_announcement_by_email( |
|
|
|
|
$id, |
|
|
|
|
$visibility, |
|
|
|
|
true |
|
|
|
|
); |
|
|
|
|
} else { |
|
|
|
|
if ($send_mail == 1) { |
|
|
|
|
self::send_system_announcement_by_email( |
|
|
|
|
$id, |
|
|
|
|
$visibility |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -584,7 +601,7 @@ class SystemAnnouncementManager |
|
|
|
|
public static function delete_announcement($id) |
|
|
|
|
{ |
|
|
|
|
$table = Database::get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
|
|
|
$id = intval($id); |
|
|
|
|
$id = (int) $id; |
|
|
|
|
$sql = "DELETE FROM $table WHERE id =".$id; |
|
|
|
|
$res = Database::query($sql); |
|
|
|
|
if ($res === false) { |
|
|
|
|
@ -604,7 +621,7 @@ class SystemAnnouncementManager |
|
|
|
|
public static function get_announcement($id) |
|
|
|
|
{ |
|
|
|
|
$table = Database::get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
|
|
|
$id = intval($id); |
|
|
|
|
$id = (int) $id; |
|
|
|
|
$sql = "SELECT * FROM ".$table." WHERE id = ".$id; |
|
|
|
|
$announcement = Database::fetch_object(Database::query($sql)); |
|
|
|
|
|
|
|
|
|
@ -646,22 +663,28 @@ class SystemAnnouncementManager |
|
|
|
|
/** |
|
|
|
|
* Send a system announcement by e-mail to all teachers/students depending on parameters. |
|
|
|
|
* |
|
|
|
|
* @param string $title |
|
|
|
|
* @param string $content |
|
|
|
|
* @param array $visibility |
|
|
|
|
* @param string $language Language (optional, considered for all languages if left empty) |
|
|
|
|
* @param bool $sendEmailTest |
|
|
|
|
* @param int $id |
|
|
|
|
* @param array $visibility |
|
|
|
|
* @param bool $sendEmailTest |
|
|
|
|
* |
|
|
|
|
* @return bool True if the message was sent or there was no destination matching. |
|
|
|
|
* False on database or e-mail sending error. |
|
|
|
|
*/ |
|
|
|
|
public static function send_system_announcement_by_email( |
|
|
|
|
$title, |
|
|
|
|
$content, |
|
|
|
|
$id, |
|
|
|
|
$visibility, |
|
|
|
|
$language = null, |
|
|
|
|
$sendEmailTest = false |
|
|
|
|
) { |
|
|
|
|
$announcement = self::get_announcement($id); |
|
|
|
|
|
|
|
|
|
if (empty($announcement)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$title = $announcement->title; |
|
|
|
|
$content = $announcement->content; |
|
|
|
|
$language = $announcement->lang; |
|
|
|
|
|
|
|
|
|
$content = str_replace(['\r\n', '\n', '\r'], '', $content); |
|
|
|
|
$now = api_get_utc_datetime(); |
|
|
|
|
$teacher = $visibility['visible_teacher']; |
|
|
|
|
@ -712,6 +735,29 @@ class SystemAnnouncementManager |
|
|
|
|
// Expiration date |
|
|
|
|
$sql .= " AND (expiration_date = '' OR expiration_date IS NULL OR expiration_date > '$now') "; |
|
|
|
|
|
|
|
|
|
// @todo check if other filters will apply for the career/promotion option. |
|
|
|
|
if (isset($announcement->career_id) && !empty($announcement->career_id)) { |
|
|
|
|
$promotion = new Promotion(); |
|
|
|
|
$promotionList = $promotion->get_all_promotions_by_career_id($announcement->career_id); |
|
|
|
|
if (isset($announcement->promotion_id) && !empty($announcement->promotion_id)) { |
|
|
|
|
$promotionList = []; |
|
|
|
|
$promotionList[] = $promotion->get($announcement->promotion_id); |
|
|
|
|
} |
|
|
|
|
if (!empty($promotionList)) { |
|
|
|
|
foreach ($promotionList as $promotion) { |
|
|
|
|
$sessionList = SessionManager::get_all_sessions_by_promotion($promotion['id']); |
|
|
|
|
foreach ($sessionList as $session) { |
|
|
|
|
$users = SessionManager::get_users_by_session($session['id'], 0); |
|
|
|
|
foreach ($users as $user) { |
|
|
|
|
MessageManager::send_message_simple($user['user_id'], $title, $content); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ((empty($teacher) || $teacher == '0') && (empty($student) || $student == '0')) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|