Minor - format code.

1.9.x
Julio Montoya 11 years ago
parent 28e9d64292
commit 880c3eb2bc
  1. 73
      main/announcements/announcement_email.class.php
  2. 55
      main/announcements/announcements.inc.php

@ -9,7 +9,9 @@
*/
class AnnouncementEmail
{
protected $course = null;
protected $announcement = null;
public $session_id = null;
/**
*
* @param int|array $course
@ -17,20 +19,21 @@ class AnnouncementEmail
*
* @return AnnouncementEmail
*/
public static function create($course, $announcement) {
public static function create($course, $announcement)
{
return new self($course, $announcement);
}
protected $course = null;
protected $announcement = null;
public $session_id = null;
function __construct($course, $announcement) {
/**
* @param int $course
* @param int $announcement
*/
public function __construct($course, $announcement)
{
if (empty($course)) {
$course = api_get_course_int_id();
$course = CourseManager::get_course_information_by_id($course);
} else if (is_numeric($course)) {
$course = CourseManager::get_course_information_by_id(intval($course));
$course = CourseManager::get_course_information_by_id($course);
}
$this->course = $course;
$this->session_id = api_get_session_id();
@ -47,9 +50,11 @@ 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;
}
@ -59,9 +64,11 @@ 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;
}
@ -71,7 +78,8 @@ 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();
@ -88,6 +96,7 @@ class AnnouncementEmail
} else {
$user_list = CourseManager::get_user_list_from_course_code($course_code, $this->session_id);
}
return $user_list;
}
@ -96,7 +105,8 @@ 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();
@ -107,7 +117,13 @@ class AnnouncementEmail
$id = $this->announcement('id');
$course_id = $this->course('id');
$sql = "SELECT to_group_id, to_user_id FROM $tbl_item_property WHERE c_id = $course_id AND tool = '$tool' AND ref = $id AND id_session = {$this->session_id} ";
$sql = "SELECT to_group_id, to_user_id
FROM $tbl_item_property
WHERE
c_id = $course_id AND
tool = '$tool' AND
ref = $id AND
id_session = {$this->session_id} ";
$rs = Database::query($sql);
while ($row = Database::fetch_array($rs, 'ASSOC')) {
@ -133,7 +149,8 @@ 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();
@ -182,7 +199,8 @@ class AnnouncementEmail
*
* @return string
*/
public function subject() {
public function subject()
{
$result = $this->course('title').' - '.$this->announcement('title');
$result = stripslashes($result);
return $result;
@ -193,7 +211,8 @@ class AnnouncementEmail
*
* @return string
*/
public function message() {
public function message()
{
$title = $this->announcement('title');
$title = stripslashes($title);
@ -207,7 +226,7 @@ class AnnouncementEmail
$result = "<div>$content</div>";
//Adding attachment
// Adding attachment
$attachment = $this->attachement();
if (!empty($attachment)) {
$result .= '<br />';
@ -226,7 +245,8 @@ 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');
@ -247,7 +267,8 @@ class AnnouncementEmail
/**
* Send emails to users.
*/
public function send() {
public function send()
{
$sender = $this->sender();
$subject = $this->subject();
$message = $this->message();
@ -256,7 +277,12 @@ class AnnouncementEmail
$users = $this->sent_to();
foreach ($users as $user) {
MessageManager::send_message_simple($user['user_id'], $subject, $message, $sender['user_id']);
MessageManager::send_message_simple(
$user['user_id'],
$subject,
$message,
$sender['user_id']
);
}
$this->log_mail_sent();
}
@ -264,7 +290,8 @@ 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');
@ -272,4 +299,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);
}
}
}

@ -11,18 +11,34 @@
* @author jmontoya
*
*/
class AnnouncementManager {
class AnnouncementManager
{
public function __construct()
{
}
/**
* @return array
*/
public static function get_tags()
{
return array('((user_name))', '((user_firstname))', '((user_lastname))', '((teacher_name))', '((teacher_email))', '((course_title))', '((course_link))');
return array(
'((user_name))',
'((user_firstname))',
'((user_lastname))',
'((teacher_name))',
'((teacher_email))',
'((course_title))',
'((course_link))'
);
}
/**
* @param string $content
* @param string $course_code
* @return mixed
*/
public static function parse_content($content, $course_code)
{
$reader_info = api_get_user_info(api_get_user_id());
@ -38,7 +54,7 @@ class AnnouncementManager {
}
}
$course_link = api_get_course_url();
$data['user_name'] = $reader_info['username'];
$data['user_firstname'] = $reader_info['firstname'];
$data['user_lastname'] = $reader_info['lastname'];
@ -46,25 +62,25 @@ class AnnouncementManager {
$data['teacher_email'] = $teacher_email;
$data['course_title'] = $course_info['name'];
$data['course_link'] = Display::url($course_link, $course_link);
$content = str_replace(self::get_tags(), $data, $content);
return $content;
}
/**
* parse announcement content when sending an email. It parses only teacher data
* @author yoselyn castillo
* @param string content
* @param int course code
* @param string course code
* @return string with the parsed content
*/
public static function parseEmailContent($content, $courseCode)
{
$readerInfo = api_get_user_info(api_get_user_id());
$courseInfo = api_get_course_info($courseCode);
$teacherList = CourseManager::get_teacher_list_from_course_code($courseInfo['code']);
$teacherName = '';
if (!empty($teacherList)) {
foreach ($teacherList as $teacherData) {
@ -79,7 +95,7 @@ class AnnouncementManager {
$data['teacher_name'] = $teacherName;
$data['teacher_email'] = $teacherEmail;
$data['course_title'] = $courseInfo['name'];
$data['course_link'] = Display::url($course_link, $course_link);
$data['course_link'] = Display::url($course_link, $course_link);
$content = str_replace(self::get_tags(), $data, $content);
return $content;
@ -1019,7 +1035,6 @@ class AnnouncementManager {
*/
public static function sent_to($tool, $id)
{
global $_course;
global $tbl_item_property;
$tool = Database::escape_string($tool);
@ -1029,7 +1044,9 @@ class AnnouncementManager {
$sent_to = array();
$course_id = api_get_course_int_id();
$sql = "SELECT to_group_id, to_user_id FROM $tbl_item_property WHERE c_id = $course_id AND tool = '$tool' AND ref=" . $id;
$sql = "SELECT to_group_id, to_user_id
FROM $tbl_item_property
WHERE c_id = $course_id AND tool = '$tool' AND ref=" . $id;
$result = Database::query($sql);
while ($row = Database::fetch_array($result)) {
@ -1181,17 +1198,15 @@ class AnnouncementManager {
$id = intval($id);
$course_id = api_get_course_int_id();
$sql = "DELETE FROM $tbl_announcement_attachment WHERE c_id = $course_id AND id = $id";
$result = Database::query($sql);
// update item_property
//api_item_property_update($_course, 'announcement_attachment', $id,'AnnouncementAttachmentDeleted', api_get_user_id());
Database::query($sql);
}
public static function send_email($annoucement_id)
/**
* @param $id
*/
public static function send_email($id)
{
$email = AnnouncementEmail::create(null, $annoucement_id);
$email = AnnouncementEmail::create(null, $id);
$email->send();
}
}
//end class
Loading…
Cancel
Save