public function message($changelist, $course)
 {
     global $CFG;
     $charmax = 160;
     $events = report_eventlist_list_generator::get_all_events_list();
     $smsbody = '';
     foreach ($changelist as $item) {
         $smsbody .= preg_replace('/\\\\.*$/', '', $events[$item->event]['raweventname']) . ': ';
         $smsbody .= $item->name . "\r\n";
     }
     return $smsbody;
 }
Example #2
0
// 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/>.
/**
 * Event documentation.
 *
 * @package   report_eventlist
 * @copyright 2014 Adrian Greeve <*****@*****.**>
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once __DIR__ . '/../../config.php';
require_once $CFG->libdir . '/adminlib.php';
admin_externalpage_setup('reporteventlists');
// Retrieve all events in a list.
$completelist = report_eventlist_list_generator::get_all_events_list();
$tabledata = array();
$components = array('0' => get_string('all', 'report_eventlist'));
$edulevel = array('0' => get_string('all', 'report_eventlist'));
$crud = array('0' => get_string('all', 'report_eventlist'));
foreach ($completelist as $value) {
    $components[] = $value['component'];
    $edulevel[] = $value['edulevel'];
    $crud[] = $value['crud'];
    $tabledata[] = (object) $value;
}
$components = array_unique($components);
$edulevel = array_unique($edulevel);
$crud = array_unique($crud);
// Create the filter form for the table.
$filtersection = new report_eventlist_filter_form(null, array('components' => $components, 'edulevel' => $edulevel, 'crud' => $crud));
/////////////////////////////////////////////////////
// GLOBAL SETTINGS
////////////////////////////////////////////////////
use block_notifications\SupportedEvents;
include_once realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . "common.php";
defined('MOODLE_INTERNAL') || die;
global $CFG;
if ($ADMIN->fulltree) {
    $settings->add(new admin_setting_heading('block_notifications_settings', '', get_string('global_configuration_comment', 'block_notifications')));
    $settings->add(new admin_setting_configcheckbox('block_notifications/email_channel', get_string('email', 'block_notifications'), '', 1));
    if (class_exists('block_notifications\\SMS')) {
        $settings->add(new admin_setting_configcheckbox('block_notifications/sms_channel', get_string('sms', 'block_notifications'), '', 1));
    } else {
        $settings->add(new admin_setting_configcheckbox('block_notifications/sms_channel', get_string('sms', 'block_notifications'), get_string('sms_class_not_implemented', 'block_notifications'), 0));
    }
    $settings->add(new admin_setting_configcheckbox('block_notifications/rss_channel', get_string('rss', 'block_notifications'), '', 1));
    $settings->add(new admin_setting_configcheckbox('block_notifications/rss_shortname_url_param', get_string('rss_by_shortname', 'block_notifications'), '', 0));
    $settings->add(new admin_setting_heading('block_notifications_presets', '', get_string('global_configuration_presets_comment', 'block_notifications')));
    $settings->add(new admin_setting_configcheckbox('block_notifications/email_notification_preset', get_string('email_notification_preset', 'block_notifications'), get_string('email_notification_preset_explanation', 'block_notifications'), 1));
    $settings->add(new admin_setting_configcheckbox('block_notifications/sms_notification_preset', get_string('sms_notification_preset', 'block_notifications'), get_string('sms_notification_preset_explanation', 'block_notifications'), 1));
    $settings->add(new admin_setting_configtext('block_notifications/history_length', get_string('history_length', 'block_notifications'), get_string('history_length_explanation', 'block_notifications'), 30, PARAM_INT));
    $settings->add(new admin_setting_heading('block_notifications_actions', '', get_string('global_events_explanation', 'block_notifications')));
    $events = report_eventlist_list_generator::get_all_events_list();
    // the default values are in the SupportedEvents class
    foreach (SupportedEvents::getStandardNames() as $name => $enabled) {
        $eventname = preg_replace('/\\\\/', '_', $name);
        $eventname = preg_replace('/^_/', '', $eventname);
        $description = preg_replace('/href="/', 'href="../report/eventlist/', $events[$name]['fulleventname']);
        $settings->add(new admin_setting_configcheckbox("block_notifications/{$eventname}", $description, '', $enabled));
    }
}
 protected function specific_definition($mform)
 {
     global $CFG;
     global $COURSE;
     $global_config = get_config('block_notifications');
     $Course = new \block_notifications\Course();
     $course_notification_setting = $Course->get_registration($COURSE->id);
     // Fields for editing HTML block title and contents.
     $mform->addElement('header', 'notificationsheader', get_string('blocksettings', 'block'));
     $attributes = array();
     $attributes['disabled'] = 'disabled';
     $attributes['group'] = 'notifications_settings';
     if ($global_config->email_channel == 1) {
         $mform->addElement('checkbox', 'notify_by_email', get_string('notify_by_email', 'block_notifications'));
     } else {
         $mform->addElement('advcheckbox', 'notify_by_email', get_string('notify_by_email', 'block_notifications'), null, $attributes);
     }
     if (isset($course_notification_setting->notify_by_email) and $course_notification_setting->notify_by_email == 1) {
         $mform->setDefault('notify_by_email', 1);
     }
     if ($global_config->sms_channel == 1 and class_exists('block_notifications\\SMS')) {
         $mform->addElement('checkbox', 'notify_by_sms', get_string('notify_by_sms', 'block_notifications'));
     } else {
         $mform->addElement('advcheckbox', 'notify_by_sms', get_string('notify_by_sms', 'block_notifications'), null, $attributes);
     }
     if (isset($course_notification_setting->notify_by_sms) and $course_notification_setting->notify_by_sms == 1) {
         $mform->setDefault('notify_by_sms', 1);
     }
     if ($global_config->rss_channel == 1) {
         $mform->addElement('checkbox', 'notify_by_rss', get_string('notify_by_rss', 'block_notifications'));
         $mform->addElement('checkbox', 'rss_shortname_url_param', get_string('rss_by_shortname', 'block_notifications'));
     } else {
         $mform->addElement('advcheckbox', 'notify_by_rss', get_string('notify_by_rss', 'block_notifications'), null, $attributes);
         $mform->addElement('advcheckbox', 'rss_shortname_url_param', get_string('rss_by_shortname', 'block_notifications'), null, $attributes);
     }
     if (isset($course_notification_setting->notify_by_rss) and $course_notification_setting->notify_by_rss == 1) {
         $mform->setDefault('notify_by_rss', 1);
     }
     if (isset($course_notification_setting->rss_shortname_url_param) and $course_notification_setting->rss_shortname_url_param == 1) {
         $mform->setDefault('rss_shortname_url_param', 1);
     }
     $mform->addElement('html', '<div class="qheader" style="margin-top: 20px">' . get_string('course_configuration_presets_comment', 'block_notifications') . '</div>');
     $mform->addElement('checkbox', 'email_notification_preset', get_string('email_notification_preset', 'block_notifications'));
     if (isset($course_notification_setting->email_notification_preset) and $course_notification_setting->email_notification_preset == 1) {
         $mform->setDefault('email_notification_preset', 1);
     } else {
         $mform->setDefault('email_notification_preset', 0);
     }
     $mform->addElement('checkbox', 'sms_notification_preset', get_string('sms_notification_preset', 'block_notifications'));
     if (isset($course_notification_setting->sms_notification_preset) and $course_notification_setting->sms_notification_preset == 1) {
         $mform->setDefault('sms_notification_preset', 1);
     } else {
         $mform->setDefault('sms_notification_preset', 0);
     }
     $mform->addElement('html', '<div class="qheader" style="margin-top: 20px;">' . get_string('events_explanation', 'block_notifications') . '</div>');
     $events = report_eventlist_list_generator::get_all_events_list();
     foreach (\block_notifications\SupportedEvents::getShortNames() as $block_instance_setting => $platform_event_name) {
         $global_setting = preg_replace('/\\\\/', '_', $platform_event_name);
         $global_setting = preg_replace('/^_/', '', $global_setting);
         $description = preg_replace('/href="/', 'href="../report/eventlist/', $events[$platform_event_name]['fulleventname']);
         if ($global_config->{$global_setting} == 1) {
             $mform->addElement('checkbox', $block_instance_setting, $description);
             if (isset($course_notification_setting->{$block_instance_setting}) and $course_notification_setting->{$block_instance_setting} == 1) {
                 $mform->setDefault($block_instance_setting, 1);
             } else {
                 $mform->setDefault($block_instance_setting, 0);
             }
         } else {
             $mform->addElement('checkbox', $block_instance_setting, $description, null, $attributes);
             $mform->setDefault($block_instance_setting, 0);
         }
     }
 }