Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.
   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  namespace mod_bigbluebuttonbn\task;
  17  use core_user;
  18  use html_writer;
  19  
  20  /**
  21   * This adhoc task will send emails to guest users with the meeting's details
  22   *
  23   * @package   mod_bigbluebuttonbn
  24   * @copyright  2022 onwards, Blindside Networks Inc
  25   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  26   * @author     Laurent David  (laurent [at] call-learning [dt] fr)
  27   */
  28  class send_guest_emails extends base_send_notification {
  29  
  30      /**
  31       * Get the notification type.
  32       *
  33       * @return string
  34       */
  35      protected function get_notification_type(): string {
  36          return 'guest_invited';
  37      }
  38  
  39      /**
  40       * Send all the emails
  41       */
  42      protected function send_all_notifications(): void {
  43          $customdata = $this->get_custom_data();
  44          if (!empty($customdata->emails)) {
  45              foreach ($customdata->emails as $email) {
  46                  $user = core_user::get_noreply_user();
  47                  $user->email = $email;
  48                  $user->mailformat = 1; // HTML format.
  49  
  50                  email_to_user(
  51                          $user,
  52                          core_user::get_noreply_user(),
  53                          $this->get_subject(),
  54                          $this->get_small_message(),
  55                          $this->get_html_message()
  56                  );
  57              }
  58          }
  59  
  60      }
  61  
  62      /**
  63       * Get the subject of the notification.
  64       *
  65       * @return string
  66       */
  67      protected function get_subject(): string {
  68          return get_string('guest_invitation_subject', 'mod_bigbluebuttonbn', $this->get_string_vars());
  69      }
  70  
  71      /**
  72       * Get variables to make available to strings.
  73       *
  74       * @return array
  75       */
  76      protected function get_string_vars(): array {
  77          $customdata = $this->get_custom_data();
  78          $sender = core_user::get_user($customdata->useridfrom);
  79          return [
  80                  'course_fullname' => $this->get_instance()->get_course()->fullname,
  81                  'course_shortname' => $this->get_instance()->get_course()->shortname,
  82                  'name' => $this->get_instance()->get_cm()->name,
  83                  'guestjoinurl' => $this->get_instance()->get_guest_access_url()->out(false),
  84                  'guestpassword' => $this->get_instance()->get_guest_access_password(),
  85                  'sender' => fullname($sender)
  86          ];
  87      }
  88  
  89      /**
  90       * Get the short summary message.
  91       *
  92       * @return string
  93       */
  94      protected function get_small_message(): string {
  95          return get_string('guest_invitation_small_message', 'mod_bigbluebuttonbn', $this->get_string_vars());
  96      }
  97  
  98      /**
  99       * Get the HTML message content.
 100       *
 101       * @return string
 102       */
 103      protected function get_html_message(): string {
 104          return html_writer::tag(
 105                  'p',
 106                  get_string('guest_invitation_full_message', 'mod_bigbluebuttonbn', $this->get_string_vars())
 107          );
 108      }
 109  }