Completed
Push — master ( 1d1df5...87b1fe )
by Jesus
07:01
created

notifier::notification_msg_html()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 22
nc 1
nop 1
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
17
/**
18
 * The mod_bigbluebuttonbn locallib/notifier.
19
 *
20
 * @author    Jesus Federico  (jesus [at] blindsidenetworks [dt] com)
21
 * @copyright 2017 - present Blindside Networks Inc
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later
23
 */
24
25
namespace mod_bigbluebuttonbn\locallib;
26
27
defined('MOODLE_INTERNAL') || die();
28
29
require_once($CFG->dirroot . '/mod/bigbluebuttonbn/locallib.php');
30
31
class notifier {
32
33
    public static function notification_process($context, $bigbluebuttonbn, $action) {
34
        global $USER;
35
36
        // Prepare message.
37
        $msg = (object) array();
38
        // Build the message_body.
39
        $msg->action = $action;
40
        $msg->activity_type = '';
41
        $msg->activity_title = $bigbluebuttonbn->name;
42
        // Add the meeting details to the message_body.
43
        $msg->action = ucfirst($action);
44
        $msg->activity_description = '';
45
        if (!empty($bigbluebuttonbn->intro)) {
46
            $msg->activity_description = trim($bigbluebuttonbn->intro);
47
        }
48
        $msg->activity_openingtime = bigbluebuttonbn_format_activity_time($bigbluebuttonbn->openingtime);
49
        $msg->activity_closingtime = bigbluebuttonbn_format_activity_time($bigbluebuttonbn->closingtime);
50
        $msg->activity_owner = fullname($USER);
51
52
        // Send notification to all users enrolled.
53
        self::notification_send($context, $USER, $bigbluebuttonbn, self::notification_msg_html($msg));
54
    }
55
56
    public static function notification_msg_html($msg) {
57
        $messagetext = '<p>'.$msg->activity_type.' &quot;'.$msg->activity_title.'&quot; '.
58
            get_string('email_body_notification_meeting_has_been', 'bigbluebuttonbn').' '.$msg->action.'.</p>'."\n";
59
        $messagetext .= '<p><b>'.$msg->activity_title.'</b> '.
60
            get_string('email_body_notification_meeting_details', 'bigbluebuttonbn').':'."\n";
61
        $messagetext .= '<table border="0" style="margin: 5px 0 0 20px"><tbody>'."\n";
62
        $messagetext .= '<tr><td style="font-weight:bold;color:#555;">'.
63
            get_string('email_body_notification_meeting_title', 'bigbluebuttonbn').': </td><td>'."\n";
64
        $messagetext .= $msg->activity_title.'</td></tr>'."\n";
65
        $messagetext .= '<tr><td style="font-weight:bold;color:#555;">'.
66
            get_string('email_body_notification_meeting_description', 'bigbluebuttonbn').': </td><td>'."\n";
67
        $messagetext .= $msg->activity_description.'</td></tr>'."\n";
68
        $messagetext .= '<tr><td style="font-weight:bold;color:#555;">'.
69
            get_string('email_body_notification_meeting_start_date', 'bigbluebuttonbn').': </td><td>'."\n";
70
        $messagetext .= $msg->activity_openingtime.'</td></tr>'."\n";
71
        $messagetext .= '<tr><td style="font-weight:bold;color:#555;">'.
72
            get_string('email_body_notification_meeting_end_date', 'bigbluebuttonbn').': </td><td>'."\n";
73
        $messagetext .= $msg->activity_closingtime.'</td></tr>'."\n";
74
        $messagetext .= '<tr><td style="font-weight:bold;color:#555;">'.$msg->action.' '.
75
            get_string('email_body_notification_meeting_by', 'bigbluebuttonbn').': </td><td>'."\n";
76
        $messagetext .= $msg->activity_owner.'</td></tr></tbody></table></p>'."\n";
77
        return $messagetext;
78
    }
79
80
    public static function notification_send($context, $sender, $bigbluebuttonbn, $message = '') {
81
        global $DB;
82
83
        $course = $DB->get_record('course', array('id' => $bigbluebuttonbn->course), '*', MUST_EXIST);
84
85
        // Complete message.
86
        $msg = (object) array();
87
        $msg->user_name = fullname($sender);
88
        $msg->user_email = $sender->email;
89
        $msg->course_name = "$course->fullname";
90
        $message .= '<p><hr/><br/>'.get_string('email_footer_sent_by', 'bigbluebuttonbn').' '.
91
            $msg->user_name.'('.$msg->user_email.') ';
92
        $message .= get_string('email_footer_sent_from', 'bigbluebuttonbn').' '.$msg->course_name.'.</p>';
93
94
        $users = (array) get_enrolled_users($context,'',0,'u.*',null,0,0,true);
95
        foreach ($users as $user) {
96
            if ($user->id != $sender->id) {
97
                message_post_message($sender, $user, $message, FORMAT_HTML);
98
            }
99
        }
100
    }
101
102
}
103