本文整理汇总了PHP中get_message_processors函数的典型用法代码示例。如果您正苦于以下问题:PHP get_message_processors函数的具体用法?PHP get_message_processors怎么用?PHP get_message_processors使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_message_processors函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: reset_all_data
/**
* Reset contents of all database tables to initial values, reset caches, etc.
*
* Note: this is relatively slow (cca 2 seconds for pg and 7 for mysql) - please use with care!
*
* @static
* @param bool $detectchanges
* true - changes in global state and database are reported as errors
* false - no errors reported
* null - only critical problems are reported as errors
* @return void
*/
public static function reset_all_data($detectchanges = false)
{
global $DB, $CFG, $USER, $SITE, $COURSE, $PAGE, $OUTPUT, $SESSION;
// Stop any message redirection.
phpunit_util::stop_message_redirection();
// Stop any message redirection.
phpunit_util::stop_phpmailer_redirection();
// Stop any message redirection.
phpunit_util::stop_event_redirection();
// We used to call gc_collect_cycles here to ensure desctructors were called between tests.
// This accounted for 25% of the total time running phpunit - so we removed it.
// Show any unhandled debugging messages, the runbare() could already reset it.
self::display_debugging_messages();
self::reset_debugging();
// reset global $DB in case somebody mocked it
$DB = self::get_global_backup('DB');
if ($DB->is_transaction_started()) {
// we can not reset inside transaction
$DB->force_transaction_rollback();
}
$resetdb = self::reset_database();
$warnings = array();
if ($detectchanges === true) {
if ($resetdb) {
$warnings[] = 'Warning: unexpected database modification, resetting DB state';
}
$oldcfg = self::get_global_backup('CFG');
$oldsite = self::get_global_backup('SITE');
foreach ($CFG as $k => $v) {
if (!property_exists($oldcfg, $k)) {
$warnings[] = 'Warning: unexpected new $CFG->' . $k . ' value';
} else {
if ($oldcfg->{$k} !== $CFG->{$k}) {
$warnings[] = 'Warning: unexpected change of $CFG->' . $k . ' value';
}
}
unset($oldcfg->{$k});
}
if ($oldcfg) {
foreach ($oldcfg as $k => $v) {
$warnings[] = 'Warning: unexpected removal of $CFG->' . $k;
}
}
if ($USER->id != 0) {
$warnings[] = 'Warning: unexpected change of $USER';
}
if ($COURSE->id != $oldsite->id) {
$warnings[] = 'Warning: unexpected change of $COURSE';
}
}
if (ini_get('max_execution_time') != 0) {
// This is special warning for all resets because we do not want any
// libraries to mess with timeouts unintentionally.
// Our PHPUnit integration is not supposed to change it either.
if ($detectchanges !== false) {
$warnings[] = 'Warning: max_execution_time was changed to ' . ini_get('max_execution_time');
}
set_time_limit(0);
}
// restore original globals
$_SERVER = self::get_global_backup('_SERVER');
$CFG = self::get_global_backup('CFG');
$SITE = self::get_global_backup('SITE');
$_GET = array();
$_POST = array();
$_FILES = array();
$_REQUEST = array();
$COURSE = $SITE;
// reinitialise following globals
$OUTPUT = new bootstrap_renderer();
$PAGE = new moodle_page();
$FULLME = null;
$ME = null;
$SCRIPT = null;
// Empty sessison and set fresh new not-logged-in user.
\core\session\manager::init_empty_session();
// reset all static caches
\core\event\manager::phpunit_reset();
accesslib_clear_all_caches(true);
get_string_manager()->reset_caches(true);
reset_text_filters_cache(true);
events_get_handlers('reset');
core_text::reset_caches();
get_message_processors(false, true);
filter_manager::reset_caches();
// Reset internal users.
core_user::reset_internal_users();
//TODO MDL-25290: add more resets here and probably refactor them to new core function
//.........这里部分代码省略.........
示例2: load_settings
public function load_settings(part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig)
{
global $CFG, $USER, $DB, $OUTPUT, $PAGE;
// In case settings.php wants to refer to them.
$ADMIN = $adminroot;
// May be used in settings.php.
$plugininfo = $this;
// Also can be used inside settings.php.
if (!$this->is_installed_and_upgraded()) {
return;
}
if (!$hassiteconfig) {
return;
}
$section = $this->get_settings_section_name();
$settings = null;
$processors = get_message_processors();
if (isset($processors[$this->name])) {
$processor = $processors[$this->name];
if ($processor->available && $processor->hassettings) {
$settings = new admin_settingpage($section, $this->displayname, 'moodle/site:config', $this->is_enabled() === false);
include $this->full_path('settings.php');
// This may also set $settings to null.
}
}
if ($settings) {
$ADMIN->add($parentnodename, $settings);
}
}
示例3: test_send_instant_messages
/**
* Test send_instant_messages
*/
public function test_send_instant_messages()
{
global $DB, $USER, $CFG;
$this->resetAfterTest(true);
// Transactions used in tests, tell phpunit use alternative reset method.
$this->preventResetByRollback();
// Turn off all message processors (so nothing is really sent)
require_once $CFG->dirroot . '/message/lib.php';
$messageprocessors = get_message_processors();
foreach ($messageprocessors as $messageprocessor) {
$messageprocessor->enabled = 0;
$DB->update_record('message_processors', $messageprocessor);
}
// Set the required capabilities by the external function
$contextid = context_system::instance()->id;
$roleid = $this->assignUserCapability('moodle/site:sendmessage', $contextid);
$user1 = self::getDataGenerator()->create_user();
// Create test message data.
$message1 = array();
$message1['touserid'] = $user1->id;
$message1['text'] = 'the message.';
$message1['clientmsgid'] = 4;
$messages = array($message1);
$sentmessages = core_message_external::send_instant_messages($messages);
// We need to execute the return values cleaning process to simulate the web service server.
$sentmessages = external_api::clean_returnvalue(core_message_external::send_instant_messages_returns(), $sentmessages);
$themessage = $DB->get_record('message', array('id' => $sentmessages[0]['msgid']));
// Confirm that the message was inserted correctly.
$this->assertEquals($themessage->useridfrom, $USER->id);
$this->assertEquals($themessage->useridto, $message1['touserid']);
$this->assertEquals($themessage->smallmessage, $message1['text']);
$this->assertEquals($sentmessages[0]['clientmsgid'], $message1['clientmsgid']);
}
示例4: test_send_instant_messages
/**
* Test send_instant_messages
*/
public function test_send_instant_messages() {
global $DB, $USER, $CFG;
$this->resetAfterTest(true);
// Turn off all message processors (so nothing is really sent)
require_once($CFG->dirroot . '/message/lib.php');
$messageprocessors = get_message_processors();
foreach($messageprocessors as $messageprocessor) {
$messageprocessor->enabled = 0;
$DB->update_record('message_processors', $messageprocessor);
}
// Set the required capabilities by the external function
$contextid = context_system::instance()->id;
$roleid = $this->assignUserCapability('moodle/site:sendmessage', $contextid);
$user1 = self::getDataGenerator()->create_user();
// Create test message data.
$message1 = array();
$message1['touserid'] = $user1->id;
$message1['text'] = 'the message.';
$message1['clientmsgid'] = 4;
$messages = array($message1);
$sentmessages = core_message_external::send_instant_messages($messages);
$themessage = $DB->get_record('message', array('id' => $sentmessages[0]['msgid']));
// Confirm that the message was inserted correctly.
$this->assertEquals($themessage->useridfrom, $USER->id);
$this->assertEquals($themessage->useridto, $message1['touserid']);
$this->assertEquals($themessage->smallmessage, $message1['text']);
$this->assertEquals($sentmessages[0]['clientmsgid'], $message1['clientmsgid']);
}
示例5: test_message_processors_reset
public function test_message_processors_reset()
{
global $DB;
$this->resetAfterTest(true);
// Get all processors first.
$processors1 = get_message_processors();
// Add a new message processor and get all processors again.
$processor = new stdClass();
$processor->name = 'test_processor';
$processor->enabled = 1;
$DB->insert_record('message_processors', $processor);
$processors2 = get_message_processors();
// Assert that new processor still haven't been added to the list.
$this->assertSame($processors1, $processors2);
// Reset message processors data.
$processors3 = get_message_processors(false, true);
// Now, list of processors should not be the same any more,
// And we should have one more message processor in the list.
$this->assertNotSame($processors1, $processors3);
$this->assertEquals(count($processors1) + 1, count($processors3));
}
示例6: message_send
//.........这里部分代码省略.........
} else {
$savemessage->contexturlname = null;
}
$savemessage->timecreated = time();
if (PHPUNIT_TEST and class_exists('phpunit_util')) {
// Add some more tests to make sure the normal code can actually work.
$componentdir = core_component::get_component_directory($eventdata->component);
if (!$componentdir or !is_dir($componentdir)) {
throw new coding_exception('Invalid component specified in message-send(): '.$eventdata->component);
}
if (!file_exists("$componentdir/db/messages.php")) {
throw new coding_exception("$eventdata->component does not contain db/messages.php necessary for message_send()");
}
$messageproviders = null;
include("$componentdir/db/messages.php");
if (!isset($messageproviders[$eventdata->name])) {
throw new coding_exception("Missing messaging defaults for event '$eventdata->name' in '$eventdata->component' messages.php file");
}
unset($componentdir);
unset($messageproviders);
// Now ask phpunit if it wants to catch this message.
if (phpunit_util::is_redirecting_messages()) {
$savemessage->timeread = time();
$messageid = $DB->insert_record('message_read', $savemessage);
$message = $DB->get_record('message_read', array('id'=>$messageid));
phpunit_util::message_sent($message);
return $messageid;
}
}
// Fetch enabled processors
$processors = get_message_processors(true);
// Preset variables
$processorlist = array();
// Fill in the array of processors to be used based on default and user preferences
foreach ($processors as $processor) {
// Skip adding processors for internal user, if processor doesn't support sending message to internal user.
if (!$usertoisrealuser && !$processor->object->can_send_to_any_users()) {
continue;
}
// First find out permissions
$defaultpreference = $processor->name.'_provider_'.$preferencebase.'_permitted';
if (isset($defaultpreferences->{$defaultpreference})) {
$permitted = $defaultpreferences->{$defaultpreference};
} else {
// MDL-25114 They supplied an $eventdata->component $eventdata->name combination which doesn't
// exist in the message_provider table (thus there is no default settings for them).
$preferrormsg = "Could not load preference $defaultpreference. Make sure the component and name you supplied
to message_send() are valid.";
throw new coding_exception($preferrormsg);
}
// Find out if user has configured this output
// Some processors cannot function without settings from the user
$userisconfigured = $processor->object->is_user_configured($eventdata->userto);
// DEBUG: notify if we are forcing unconfigured output
if ($permitted == 'forced' && !$userisconfigured) {
debugging('Attempt to force message delivery to user who has "'.$processor->name.'" output unconfigured', DEBUG_NORMAL);
}
// Populate the list of processors we will be using
示例7: message_send
//.........这里部分代码省略.........
} else {
$savemessage->contexturlname = null;
}
$savemessage->timecreated = time();
if (PHPUNIT_TEST and class_exists('phpunit_util')) {
// Add some more tests to make sure the normal code can actually work.
$componentdir = get_component_directory($eventdata->component);
if (!$componentdir or !is_dir($componentdir)) {
throw new coding_exception('Invalid component specified in message-send(): '.$eventdata->component);
}
if (!file_exists("$componentdir/db/messages.php")) {
throw new coding_exception("$eventdata->component does not contain db/messages.php necessary for message_send()");
}
$messageproviders = null;
include("$componentdir/db/messages.php");
if (!isset($messageproviders[$eventdata->name])) {
throw new coding_exception("Missing messaging defaults for event '$eventdata->name' in '$eventdata->component' messages.php file");
}
unset($componentdir);
unset($messageproviders);
// Now ask phpunit if it wants to catch this message.
if (phpunit_util::is_redirecting_messages()) {
$savemessage->timeread = time();
$messageid = $DB->insert_record('message_read', $savemessage);
$message = $DB->get_record('message_read', array('id'=>$messageid));
phpunit_util::message_sent($message);
return $messageid;
}
}
// Fetch enabled processors
$processors = get_message_processors(true);
// Fetch default (site) preferences
$defaultpreferences = get_message_output_default_preferences();
// Preset variables
$processorlist = array();
$preferencebase = $eventdata->component.'_'.$eventdata->name;
// Fill in the array of processors to be used based on default and user preferences
foreach ($processors as $processor) {
// First find out permissions
$defaultpreference = $processor->name.'_provider_'.$preferencebase.'_permitted';
if (isset($defaultpreferences->{$defaultpreference})) {
$permitted = $defaultpreferences->{$defaultpreference};
} else {
//MDL-25114 They supplied an $eventdata->component $eventdata->name combination which doesn't
//exist in the message_provider table (thus there is no default settings for them)
$preferrormsg = get_string('couldnotfindpreference', 'message', $defaultpreference);
throw new coding_exception($preferrormsg,'blah');
}
// Find out if user has configured this output
// Some processors cannot function without settings from the user
$userisconfigured = $processor->object->is_user_configured($eventdata->userto);
// DEBUG: notify if we are forcing unconfigured output
if ($permitted == 'forced' && !$userisconfigured) {
debugging('Attempt to force message delivery to user who has "'.$processor->name.'" output unconfigured', DEBUG_NORMAL);
}
// Warn developers that necessary data is missing regardless of how the processors are configured
if (!isset($eventdata->userto->emailstop)) {
debugging('userto->emailstop is not set. Retrieving it from the user table');
$eventdata->userto->emailstop = $DB->get_field('user', 'emailstop', array('id'=>$eventdata->userto->id));
示例8: test_send_message
public function test_send_message()
{
global $DB, $CFG;
$this->preventResetByRollback();
$this->resetAfterTest();
unset_config('noemailever');
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
// Test basic email redirection.
$this->assertFileExists("{$CFG->dirroot}/message/output/email/version.php");
$this->assertFileExists("{$CFG->dirroot}/message/output/popup/version.php");
$DB->set_field_select('message_processors', 'enabled', 0, "name <> 'email' AND name <> 'popup'");
get_message_processors(true, true);
$eventsink = $this->redirectEvents();
set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'none', $user2);
$message = new stdClass();
$message->component = 'moodle';
$message->name = 'instantmessage';
$message->userfrom = $user1;
$message->userto = $user2;
$message->subject = 'message subject 1';
$message->fullmessage = 'message body';
$message->fullmessageformat = FORMAT_MARKDOWN;
$message->fullmessagehtml = '<p>message body</p>';
$message->smallmessage = 'small message';
$message->notification = '0';
$sink = $this->redirectEmails();
$messageid = message_send($message);
$emails = $sink->get_messages();
$this->assertCount(0, $emails);
$savedmessage = $DB->get_record('message', array('id' => $messageid), '*', MUST_EXIST);
$sink->clear();
$this->assertFalse($DB->record_exists('message_read', array()));
$DB->delete_records('message', array());
$events = $eventsink->get_events();
$this->assertCount(1, $events);
$this->assertInstanceOf('\\core\\event\\message_sent', $events[0]);
$eventsink->clear();
$CFG->messaging = 0;
$message = new stdClass();
$message->component = 'moodle';
$message->name = 'instantmessage';
$message->userfrom = $user1;
$message->userto = $user2;
$message->subject = 'message subject 1';
$message->fullmessage = 'message body';
$message->fullmessageformat = FORMAT_MARKDOWN;
$message->fullmessagehtml = '<p>message body</p>';
$message->smallmessage = 'small message';
$message->notification = '0';
$messageid = message_send($message);
$emails = $sink->get_messages();
$this->assertCount(0, $emails);
$savedmessage = $DB->get_record('message_read', array('id' => $messageid), '*', MUST_EXIST);
$sink->clear();
$this->assertFalse($DB->record_exists('message', array()));
$DB->delete_records('message_read', array());
$events = $eventsink->get_events();
$this->assertCount(2, $events);
$this->assertInstanceOf('\\core\\event\\message_sent', $events[0]);
$this->assertInstanceOf('\\core\\event\\message_viewed', $events[1]);
$eventsink->clear();
$CFG->messaging = 1;
$message = new stdClass();
$message->component = 'moodle';
$message->name = 'instantmessage';
$message->userfrom = $user1;
$message->userto = $user2;
$message->subject = 'message subject 1';
$message->fullmessage = 'message body';
$message->fullmessageformat = FORMAT_MARKDOWN;
$message->fullmessagehtml = '<p>message body</p>';
$message->smallmessage = 'small message';
$message->notification = '1';
$messageid = message_send($message);
$emails = $sink->get_messages();
$this->assertCount(0, $emails);
$savedmessage = $DB->get_record('message_read', array('id' => $messageid), '*', MUST_EXIST);
$sink->clear();
$this->assertFalse($DB->record_exists('message', array()));
$DB->delete_records('message_read', array());
$events = $eventsink->get_events();
$this->assertCount(2, $events);
$this->assertInstanceOf('\\core\\event\\message_sent', $events[0]);
$this->assertInstanceOf('\\core\\event\\message_viewed', $events[1]);
$eventsink->clear();
set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'email', $user2);
$message = new stdClass();
$message->component = 'moodle';
$message->name = 'instantmessage';
$message->userfrom = $user1;
$message->userto = $user2;
$message->subject = 'message subject 1';
$message->fullmessage = 'message body';
$message->fullmessageformat = FORMAT_MARKDOWN;
$message->fullmessagehtml = '<p>message body</p>';
$message->smallmessage = 'small message';
$message->notification = '0';
$user2->emailstop = '1';
$sink = $this->redirectEmails();
//.........这里部分代码省略.........
示例9: get_uninstall_url
/**
* @see plugintype_interface::get_uninstall_url()
*/
public function get_uninstall_url() {
$processors = get_message_processors();
if (isset($processors[$this->name])) {
return new moodle_url('/admin/message.php', array('uninstall' => $processors[$this->name]->id, 'sesskey' => sesskey()));
} else {
return parent::get_uninstall_url();
}
}
示例10: is_user_enabled
/**
* Test method is_user_enabled.
*/
public function is_user_enabled()
{
$processors = get_message_processors();
if (empty($processors)) {
$this->markTestSkipped("No message processors found");
}
list($name, $testprocessor) = each($processors);
// Enable.
\core_message\api::update_processor_status($testprocessor, 1);
$status = \core_message\api::is_processor_enabled($name);
$this->assertEquals(1, $status);
// Disable.
\core_message\api::update_processor_status($testprocessor, 0);
$status = \core_message\api::is_processor_enabled($name);
$this->assertEquals(0, $status);
// Enable again.
\core_message\api::update_processor_status($testprocessor, 1);
$status = \core_message\api::is_processor_enabled($name);
$this->assertEquals(1, $status);
}
示例11: render_badges
/**
* Render badges.
* @return string
*/
protected function render_badges()
{
$mprocs = get_message_processors(true);
if (!isset($mprocs['badge'])) {
// Badge message processor is not enabled - exit.
return null;
}
$badgerend = $this->get_badge_renderer();
$badges = '';
if ($badgerend && $badgerend instanceof \theme_snap\output\message_badge_renderer) {
$badges = '<div class="alert_stream">
' . $badgerend->messagestitle() . '
<div class="message_badge_container"></div>
</div>';
}
return $badges;
}
示例12: message_send
/**
* Called when a message provider wants to send a message.
* This functions checks the user's processor configuration to send the given type of message,
* then tries to send it.
*
* Required parameter $eventdata structure:
* component string component name. must exist in message_providers
* name string message type name. must exist in message_providers
* userfrom object|int the user sending the message
* userto object|int the message recipient
* subject string the message subject
* fullmessage - the full message in a given format
* fullmessageformat - the format if the full message (FORMAT_MOODLE, FORMAT_HTML, ..)
* fullmessagehtml - the full version (the message processor will choose with one to use)
* smallmessage - the small version of the message
* contexturl - if this is a notification then you can specify a url to view the event. For example the forum post the user is being notified of.
* contexturlname - the display text for contexturl
*
* @param object $eventdata information about the message (component, userfrom, userto, ...)
* @return int|false the ID of the new message or false if there was a problem with a processor
*/
function message_send($eventdata) {
global $CFG, $DB;
//new message ID to return
$messageid = false;
//TODO: we need to solve problems with database transactions here somehow, for now we just prevent transactions - sorry
$DB->transactions_forbidden();
if (is_int($eventdata->userto)) {
$eventdata->userto = $DB->get_record('user', array('id' => $eventdata->userto));
}
if (is_int($eventdata->userfrom)) {
$eventdata->userfrom = $DB->get_record('user', array('id' => $eventdata->userfrom));
}
//after how long inactive should the user be considered logged off?
if (isset($CFG->block_online_users_timetosee)) {
$timetoshowusers = $CFG->block_online_users_timetosee * 60;
} else {
$timetoshowusers = 300;//5 minutes
}
// Work out if the user is logged in or not
if (!empty($eventdata->userto->lastaccess) && (time()-$timetoshowusers) < $eventdata->userto->lastaccess) {
$userstate = 'loggedin';
} else {
$userstate = 'loggedoff';
}
// Create the message object
$savemessage = new stdClass();
$savemessage->useridfrom = $eventdata->userfrom->id;
$savemessage->useridto = $eventdata->userto->id;
$savemessage->subject = $eventdata->subject;
$savemessage->fullmessage = $eventdata->fullmessage;
$savemessage->fullmessageformat = $eventdata->fullmessageformat;
$savemessage->fullmessagehtml = $eventdata->fullmessagehtml;
$savemessage->smallmessage = $eventdata->smallmessage;
if (!empty($eventdata->notification)) {
$savemessage->notification = $eventdata->notification;
} else {
$savemessage->notification = 0;
}
if (!empty($eventdata->contexturl)) {
$savemessage->contexturl = $eventdata->contexturl;
} else {
$savemessage->contexturl = null;
}
if (!empty($eventdata->contexturlname)) {
$savemessage->contexturlname = $eventdata->contexturlname;
} else {
$savemessage->contexturlname = null;
}
$savemessage->timecreated = time();
// Fetch enabled processors
$processors = get_message_processors(true);
// Fetch default (site) preferences
$defaultpreferences = get_message_output_default_preferences();
// Preset variables
$processorlist = array();
$preferencebase = $eventdata->component.'_'.$eventdata->name;
// Fill in the array of processors to be used based on default and user preferences
foreach ($processors as $processor) {
// First find out permissions
$defaultpreference = $processor->name.'_provider_'.$preferencebase.'_permitted';
if (isset($defaultpreferences->{$defaultpreference})) {
$permitted = $defaultpreferences->{$defaultpreference};
} else {
//MDL-25114 They supplied an $eventdata->component $eventdata->name combination which doesn't
//exist in the message_provider table (thus there is no default settings for them)
$preferrormsg = get_string('couldnotfindpreference', 'message', $preferencename);
throw new coding_exception($preferrormsg,'blah');
//.........这里部分代码省略.........
示例13: dirname
/**
* Default message outputs configuration page
*
* @package core_message
* @copyright 2011 Lancaster University Network Services Limited
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once dirname(__FILE__) . '/../config.php';
require_once $CFG->dirroot . '/message/lib.php';
require_once $CFG->libdir . '/adminlib.php';
// This is an admin page
admin_externalpage_setup('defaultmessageoutputs');
// Require site configuration capability
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
// Fetch processors
$processors = get_message_processors(true);
// Fetch message providers
$providers = get_message_providers();
if (($form = data_submitted()) && confirm_sesskey()) {
$preferences = array();
// Prepare default message outputs settings
foreach ($providers as $provider) {
$componentproviderbase = $provider->component . '_' . $provider->name;
foreach (array('permitted', 'loggedin', 'loggedoff') as $setting) {
$value = null;
$componentprovidersetting = $componentproviderbase . '_' . $setting;
if ($setting == 'permitted') {
// if we deal with permitted select element, we need to create individual
// setting for each possible processor. Note that this block will
// always be processed first after entring parental foreach iteration
// so we can change form values on this stage.
示例14: test_get_all_message_preferences
/**
* Tests deleting a conversation.
*/
public function test_get_all_message_preferences()
{
$user = self::getDataGenerator()->create_user();
$this->setUser($user);
// Set a couple of preferences to test.
set_user_preference('message_provider_mod_assign_assign_notification_loggedin', 'popup', $user);
set_user_preference('message_provider_mod_assign_assign_notification_loggedoff', 'email', $user);
$processors = get_message_processors();
$providers = message_get_providers_for_user($user->id);
$prefs = \core_message\api::get_all_message_preferences($processors, $providers, $user);
$this->assertEquals(1, $prefs->mod_assign_assign_notification_loggedin['popup']);
$this->assertEquals(1, $prefs->mod_assign_assign_notification_loggedoff['email']);
}
示例15: get_user_message_preferences
/**
* Get the notification preferences for a given user.
*
* @param int $userid id of the user, 0 for current user
* @return external_description
* @throws moodle_exception
* @since 3.2
*/
public static function get_user_message_preferences($userid = 0)
{
global $PAGE;
$params = self::validate_parameters(self::get_user_message_preferences_parameters(), array('userid' => $userid));
$user = self::validate_preferences_permissions($params['userid']);
// Filter out enabled, available system_configured and user_configured processors only.
$readyprocessors = array_filter(get_message_processors(), function ($processor) {
return $processor->enabled && $processor->configured && $processor->object->is_user_configured() && $processor->object->has_message_preferences();
});
$providers = array_filter(message_get_providers_for_user($user->id), function ($provider) {
return $provider->component === 'moodle';
});
$preferences = \core_message\api::get_all_message_preferences($readyprocessors, $providers, $user);
$notificationlistoutput = new \core_message\output\preferences\message_notification_list($readyprocessors, $providers, $preferences, $user);
$renderer = $PAGE->get_renderer('core_message');
$result = array('warnings' => array(), 'preferences' => $notificationlistoutput->export_for_template($renderer), 'blocknoncontacts' => get_user_preferences('message_blocknoncontacts', '', $user->id) ? true : false);
return $result;
}