|
|
|
@ -17,8 +17,7 @@ class AnnouncementEmail |
|
|
|
|
* |
|
|
|
|
* @return AnnouncementEmail |
|
|
|
|
*/ |
|
|
|
|
public static function create($course, $announcement) |
|
|
|
|
{ |
|
|
|
|
public static function create($course, $announcement) { |
|
|
|
|
return new self($course, $announcement); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -26,8 +25,7 @@ class AnnouncementEmail |
|
|
|
|
protected $announcement = null; |
|
|
|
|
public $session_id = null; |
|
|
|
|
|
|
|
|
|
function __construct($course, $announcement) |
|
|
|
|
{ |
|
|
|
|
function __construct($course, $announcement) { |
|
|
|
|
if (empty($course)) { |
|
|
|
|
$course = api_get_course_int_id(); |
|
|
|
|
$course = CourseManager::get_course_information_by_id($course); |
|
|
|
@ -49,8 +47,7 @@ class AnnouncementEmail |
|
|
|
|
* @param string $key |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
public function course($key = '') |
|
|
|
|
{ |
|
|
|
|
public function course($key = '') { |
|
|
|
|
$result = $key ? $this->course[$key] : $this->course; |
|
|
|
|
$result = $key == 'id' ? intval($result) : $result; |
|
|
|
|
return $result; |
|
|
|
@ -62,8 +59,7 @@ class AnnouncementEmail |
|
|
|
|
* @param string $key |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
public function announcement($key = '') |
|
|
|
|
{ |
|
|
|
|
public function announcement($key = '') { |
|
|
|
|
$result = $key ? $this->announcement[$key] : $this->announcement; |
|
|
|
|
$result = $key == 'id' ? intval($result) : $result; |
|
|
|
|
return $result; |
|
|
|
@ -75,8 +71,7 @@ class AnnouncementEmail |
|
|
|
|
* |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
public function all_users() |
|
|
|
|
{ |
|
|
|
|
public function all_users() { |
|
|
|
|
$course_code = $this->course('code'); |
|
|
|
|
if (empty($this->session_id)) { |
|
|
|
|
$group_id = api_get_group_id(); |
|
|
|
@ -101,8 +96,7 @@ class AnnouncementEmail |
|
|
|
|
* |
|
|
|
|
* @return array Array of users and groups to whom the element has been sent |
|
|
|
|
*/ |
|
|
|
|
public function sent_to_info() |
|
|
|
|
{ |
|
|
|
|
public function sent_to_info() { |
|
|
|
|
$result = array(); |
|
|
|
|
$result['groups'] = array(); |
|
|
|
|
$result['users'] = array(); |
|
|
|
@ -139,8 +133,7 @@ class AnnouncementEmail |
|
|
|
|
* |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
public function sent_to() |
|
|
|
|
{ |
|
|
|
|
public function sent_to() { |
|
|
|
|
$sent_to = $this->sent_to_info(); |
|
|
|
|
$users = $sent_to['users']; |
|
|
|
|
$users = $users ? $users : array(); |
|
|
|
@ -179,8 +172,7 @@ class AnnouncementEmail |
|
|
|
|
* @param string $key |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
public function sender($key = '') |
|
|
|
|
{ |
|
|
|
|
public function sender($key = '') { |
|
|
|
|
global $_user; |
|
|
|
|
return $key ? $_user[$key] : $_user; |
|
|
|
|
} |
|
|
|
@ -190,8 +182,7 @@ class AnnouncementEmail |
|
|
|
|
* |
|
|
|
|
* @return string |
|
|
|
|
*/ |
|
|
|
|
public function subject() |
|
|
|
|
{ |
|
|
|
|
public function subject() { |
|
|
|
|
$result = $this->course('title').' - '.$this->announcement('title'); |
|
|
|
|
$result = stripslashes($result); |
|
|
|
|
return $result; |
|
|
|
@ -202,8 +193,7 @@ class AnnouncementEmail |
|
|
|
|
* |
|
|
|
|
* @return string |
|
|
|
|
*/ |
|
|
|
|
public function message() |
|
|
|
|
{ |
|
|
|
|
public function message() { |
|
|
|
|
$title = $this->announcement('title'); |
|
|
|
|
$title = stripslashes($title); |
|
|
|
|
|
|
|
|
@ -236,8 +226,7 @@ class AnnouncementEmail |
|
|
|
|
* |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
public function attachement() |
|
|
|
|
{ |
|
|
|
|
public function attachement() { |
|
|
|
|
$result = array(); |
|
|
|
|
$tbl_announcement_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT); |
|
|
|
|
$id = $this->announcement('id'); |
|
|
|
@ -258,8 +247,7 @@ class AnnouncementEmail |
|
|
|
|
/** |
|
|
|
|
* Send emails to users. |
|
|
|
|
*/ |
|
|
|
|
public function send() |
|
|
|
|
{ |
|
|
|
|
public function send() { |
|
|
|
|
$sender = $this->sender(); |
|
|
|
|
$subject = $this->subject(); |
|
|
|
|
$message = $this->message(); |
|
|
|
@ -276,8 +264,7 @@ class AnnouncementEmail |
|
|
|
|
/** |
|
|
|
|
* Store that emails where sent |
|
|
|
|
*/ |
|
|
|
|
public function log_mail_sent() |
|
|
|
|
{ |
|
|
|
|
public function log_mail_sent() { |
|
|
|
|
$id = $this->announcement('id'); |
|
|
|
|
$course_id = $this->course('id'); |
|
|
|
|
|
|
|
|
@ -285,5 +272,4 @@ class AnnouncementEmail |
|
|
|
|
$sql = "UPDATE $tbl_announcement SET email_sent=1 WHERE c_id = $course_id AND id=$id AND session_id = {$this->session_id} "; |
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |