/////////////////////////////////////////////////////
// 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));
    }
}
Esempio n. 2
0
 function extract_standard_logs($course_id, $last_notification_time)
 {
     global $DB, $CFG;
     $course_registration = $this->get_registration($course_id);
     $global_config = get_config('block_notifications');
     // use the block_notification_courses table value if the passed time is null
     if (is_null($last_notification_time)) {
         $last_notification_time = $course_registration->last_notification_time;
     }
     $events = '';
     //$standard_names = SupportedEvents::getStandardNames();
     foreach (SupportedEvents::getShortNames() as $block_instance_setting => $platform_event_name) {
         $eventname = preg_replace('/\\\\/', '_', $platform_event_name);
         $eventname = preg_replace('/^_/', '', $eventname);
         if ($global_config->{$eventname} == 1 and $course_registration->{$block_instance_setting} == 1) {
             $events .= "'" . addslashes($platform_event_name) . "',";
         }
     }
     // remove the last comma
     if (empty($events)) {
         return false;
     } else {
         $events = rtrim($events, ',');
         $logs = $this->logger->get_events_select("courseid = {$course_id} and eventname in ({$events}) and timecreated > {$last_notification_time}", array(), '', 0, 0);
         return $logs;
     }
 }
 function set_data($defaults)
 {
     $block_config = new Object();
     $block_config->notify_by_email = file_get_submitted_draft_itemid('notify_by_email');
     $block_config->notify_by_sms = file_get_submitted_draft_itemid('notify_by_sms');
     $block_config->notify_by_rss = file_get_submitted_draft_itemid('notify_by_rss');
     $block_config->rss_shortname_url_param = file_get_submitted_draft_itemid('rss_shortname_url_param');
     $block_config->email_notification_preset = file_get_submitted_draft_itemid('email_notification_preset');
     $block_config->sms_notification_preset = file_get_submitted_draft_itemid('sms_notification_preset');
     foreach (\block_notifications\SupportedEvents::getShortNames() as $block_instance_setting => $platform_event_name) {
         $block_config->{$block_instance_setting} = file_get_submitted_draft_itemid($block_instance_setting);
     }
     unset($this->block->config->text);
     parent::set_data($defaults);
     $this->block->config = $block_config;
 }