本文整理汇总了PHP中message_unblock_contact函数的典型用法代码示例。如果您正苦于以下问题:PHP message_unblock_contact函数的具体用法?PHP message_unblock_contact怎么用?PHP message_unblock_contact使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了message_unblock_contact函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: unblock_contacts
/**
* Unblock contacts.
*
* @param array $userids array of user IDs.
* @return null
* @since Moodle 2.5
*/
public static function unblock_contacts($userids)
{
global $CFG;
// Check if messaging is enabled.
if (!$CFG->messaging) {
throw new moodle_exception('disabled', 'message');
}
$params = array('userids' => $userids);
$params = self::validate_parameters(self::unblock_contacts_parameters(), $params);
foreach ($params['userids'] as $id) {
message_unblock_contact($id);
}
return null;
}
示例2: message_add_contact
if (!empty($user2->id) && $user2realuser && $user2->id != $USER->id) {
$PAGE->navigation->extend_for_user($user2);
}
/// Process any contact maintenance requests there may be
if ($addcontact and confirm_sesskey()) {
message_add_contact($addcontact);
redirect($CFG->wwwroot . '/message/index.php?viewing=contacts&id=' . $addcontact);
}
if ($removecontact and confirm_sesskey()) {
message_remove_contact($removecontact);
}
if ($blockcontact and confirm_sesskey()) {
message_block_contact($blockcontact);
}
if ($unblockcontact and confirm_sesskey()) {
message_unblock_contact($unblockcontact);
}
//was a message sent? Do NOT allow someone looking at someone else's messages to send them.
$messageerror = null;
if ($currentuser && !empty($user2) && has_capability('moodle/site:sendmessage', $systemcontext)) {
// Check that the user is not blocking us!!
if ($contact = $DB->get_record('message_contacts', array('userid' => $user2->id, 'contactid' => $user1->id))) {
if ($contact->blocked and !has_capability('moodle/site:readallmessages', $systemcontext)) {
$messageerror = get_string('userisblockingyou', 'message');
}
}
$userpreferences = get_user_preferences(NULL, NULL, $user2->id);
if (!empty($userpreferences['message_blocknoncontacts'])) {
// User is blocking non-contacts
if (empty($contact)) {
// We are not a contact!
示例3: test_message_unblock_contact
/**
* Test message_unblock_contact.
*/
public function test_message_unblock_contact()
{
// Set this user as the admin.
$this->setAdminUser();
// Create a user to add to the admin's contact list.
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
// Add users to the admin's contact list.
message_add_contact($user1->id);
message_add_contact($user2->id, 1);
// Add blocked contact.
$this->assertEquals(1, message_count_blocked_users());
// Unblock user.
message_unblock_contact($user2->id);
$this->assertEquals(0, message_count_blocked_users());
}
示例4: unblock_contacts
/**
* Unblock contacts.
*
* @param array $userids array of user IDs.
* @return null
* @since 2.5
*/
public static function unblock_contacts($userids) {
$params = array('userids' => $userids);
$params = self::validate_parameters(self::unblock_contacts_parameters(), $params);
foreach ($params['userids'] as $id) {
message_unblock_contact($id);
}
return null;
}
示例5: test_message_contact_unblocked
/**
* Test the message contact unblocked event.
*/
public function test_message_contact_unblocked()
{
// Set this user as the admin.
$this->setAdminUser();
// Create a user to add to the admin's contact list.
$user = $this->getDataGenerator()->create_user();
// Add the user to the admin's contact list.
message_add_contact($user->id);
// Block the user.
message_block_contact($user->id);
// Make sure that we have 1 blocked user.
$this->assertEquals(1, message_count_blocked_users());
// Trigger and capture the event when unblocking a contact.
$sink = $this->redirectEvents();
message_unblock_contact($user->id);
$events = $sink->get_events();
$event = reset($events);
// Check that the event data is valid.
$this->assertInstanceOf('\\core\\event\\message_contact_unblocked', $event);
$this->assertEquals(context_user::instance(2), $event->get_context());
$expected = array(SITEID, 'message', 'unblock contact', 'index.php?user1=' . $user->id . '&user2=2', $user->id);
$this->assertEventLegacyLogData($expected, $event);
$url = new moodle_url('/message/index.php', array('user1' => $event->userid, 'user2' => $event->relateduserid));
$this->assertEquals($url, $event->get_url());
// Make sure that we have no blocked users.
$this->assertEmpty(message_count_blocked_users());
// Make sure that the contact unblocked event is not triggered again.
$sink->clear();
message_unblock_contact($user->id);
$events = $sink->get_events();
$event = reset($events);
$this->assertEmpty($event);
// Make sure that we still have no blocked users.
$this->assertEmpty(message_count_blocked_users());
}
示例6: unblock_contacts
/**
* Unblock contacts.
*
* @param array $userids array of user IDs.
* @param int $userid The id of the user we are unblocking the contacts for
* @return null
* @since Moodle 2.5
*/
public static function unblock_contacts($userids, $userid = 0)
{
global $CFG, $USER;
// Check if messaging is enabled.
if (empty($CFG->messaging)) {
throw new moodle_exception('disabled', 'message');
}
if (empty($userid)) {
$userid = $USER->id;
}
// Validate context.
$context = context_system::instance();
self::validate_context($context);
$capability = 'moodle/site:manageallmessaging';
if ($USER->id != $userid && !has_capability($capability, $context)) {
throw new required_capability_exception($context, $capability, 'nopermissions', '');
}
$params = array('userids' => $userids, 'userid' => $userid);
$params = self::validate_parameters(self::unblock_contacts_parameters(), $params);
foreach ($params['userids'] as $id) {
message_unblock_contact($id, $userid);
}
return null;
}
示例7: test_is_user_blocked
/**
* Tests that we return true when a user is blocked, or false
* if they are not blocked.
*/
public function test_is_user_blocked()
{
// Create some users.
$user1 = self::getDataGenerator()->create_user();
$user2 = self::getDataGenerator()->create_user();
// Set the user.
$this->setUser($user1);
// User shouldn't be blocked.
$this->assertFalse(\core_message\api::is_user_blocked($user1->id, $user2->id));
// Block the user.
message_block_contact($user2->id);
// User should be blocked.
$this->assertTrue(\core_message\api::is_user_blocked($user1->id, $user2->id));
// Unblock the user.
message_unblock_contact($user2->id);
$this->assertFalse(\core_message\api::is_user_blocked($user1->id, $user2->id));
}