-
Notifications
You must be signed in to change notification settings - Fork 31
/
course_reminder.class.php
152 lines (132 loc) · 5.58 KB
/
course_reminder.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Course event reminder handler.
*
* @package local_reminders
* @copyright 2012 Isuru Madushanka Weerarathna
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
global $CFG;
require_once($CFG->dirroot . '/local/reminders/reminder.class.php');
/**
* Class to specify the reminder message object for course events.
*
* @package local_reminders
* @copyright 2012 Isuru Madushanka Weerarathna
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_reminder extends local_reminder {
/**
* Course reference.
*
* @var object
*/
protected $course;
/**
* Creates a new course reminder instance.
*
* @param object $event calendar event.
* @param object $course course instance.
* @param integer $aheaddays number of days ahead.
* @param object $customtime contains the custom time value and unit (if configured).
*/
public function __construct($event, $course, $aheaddays = 1, $customtime = null) {
parent::__construct($event, $aheaddays, $customtime);
$this->course = $course;
}
/**
* Generates a message content as a HTML for course email.
*
* @param object $user The user object
* @param object $changetype change type (add/update/removed)
* @param stdClass $ctxinfo additional context info needed to process.
* @return string Message content as HTML text.
*/
public function get_message_html($user=null, $changetype=null, $ctxinfo=null) {
$htmlmail = $this->get_html_header();
$htmlmail .= html_writer::start_tag('body', ['id' => 'email']);
$htmlmail .= $this->get_reminder_header();
$htmlmail .= html_writer::start_tag('div');
$htmlmail .= html_writer::start_tag('table',
['cellspacing' => 0, 'cellpadding' => 8, 'style' => $this->tbodycssstyle]);
$contenttitle = $this->get_message_title();
if (!isemptystring($changetype)) {
$titleprefixlangstr = get_string('calendarevent'.strtolower($changetype).'prefix', 'local_reminders');
$contenttitle = "[$titleprefixlangstr]: $contenttitle";
}
$htmlmail .= html_writer::start_tag('tr');
$htmlmail .= html_writer::start_tag('td', ['colspan' => 2]);
$htmlmail .= html_writer::link($this->generate_event_link(),
html_writer::tag('h3', $contenttitle, ['style' => $this->titlestyle]),
['style' => 'text-decoration: none']);
$htmlmail .= html_writer::end_tag('td').html_writer::end_tag('tr');
$htmlmail .= $this->write_table_row(get_string('contentwhen', 'local_reminders'),
format_event_time_duration($user, $this->event));
$htmlmail .= $this->write_location_info($this->event);
$htmlmail .= $this->write_table_row(get_string('contenttypecourse', 'local_reminders'), $this->course->fullname);
$description = $this->event->description;
$htmlmail .= $this->write_description($description, $this->event);
$htmlmail .= $this->get_html_footer();
return $htmlmail.html_writer::end_tag('table').
html_writer::end_tag('div').
html_writer::end_tag('body').
html_writer::end_tag('html');
}
/**
* Generates a message content as a plain-text for course.
*
* @param object $user The user object
* @param object $changetype change type (add/update/removed)
* @return string Message content as plain-text.
*/
public function get_message_plaintext($user=null, $changetype=null) {
$text = $this->get_message_title().' '.$this->get_aheaddays_plain()."\n";
$text .= get_string('contentwhen', 'local_reminders').': '.$this->get_tzinfo_plain($user, $this->event)."\n";
$text .= get_string('contenttypecourse', 'local_reminders').': '.$this->course->fullname."\n";
$text .= get_string('contentdescription', 'local_reminders').': '.$this->event->description."\n";
return $text;
}
/**
* Returns 'reminders_course' name.
*
* @return string Message provider name
*/
protected function get_message_provider() {
return 'reminders_course';
}
/**
* Generates a message title for the course reminder.
*
* @param string $type type of message to be send (null=reminder cron)
* @return string Message title as a plain-text.
*/
public function get_message_title($type=null) {
return '('.$this->course->shortname.') '.$this->event->name;
}
/**
* Adds course id and name to header.
*
* @return array additional headers.
*/
public function get_custom_headers() {
$headers = parent::get_custom_headers();
$headers[] = 'X-Course-Id: '.$this->course->id;
$headers[] = 'X-Course-Name: '.format_string($this->course->fullname, true);
return $headers;
}
}