コード例 #1
0
ファイル: events_test.php プロジェクト: uniedpa/moodle
    /**
     * Test the message contact removed event.
     */
    public function test_message_contact_removed() {
        // 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);

        // Trigger and capture the event when adding a contact.
        $sink = $this->redirectEvents();
        message_remove_contact($user->id);
        $events = $sink->get_events();
        $event = reset($events);

        // Check that the event data is valid.
        $this->assertInstanceOf('\core\event\message_contact_removed', $event);
        $this->assertEquals(context_user::instance(2), $event->get_context());
        $expected = array(SITEID, 'message', 'remove 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());
    }
コード例 #2
0
    $PAGE->set_pagelayout('standard');
    $PAGE->set_context(context_user::instance($user1->id));
}
if (!empty($user1->id) && $user1->id != $USER->id) {
    $PAGE->navigation->extend_for_user($user1);
}
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');
        }
コード例 #3
0
ファイル: externallib.php プロジェクト: evltuma/moodle
 /**
  * Delete contacts.
  *
  * @param array $userids array of user IDs.
  * @return null
  * @since Moodle 2.5
  */
 public static function delete_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::delete_contacts_parameters(), $params);
     foreach ($params['userids'] as $id) {
         message_remove_contact($id);
     }
     return null;
 }
コード例 #4
0
 /**
  * Test message_remove_contact.
  */
 public function test_message_remove_contact()
 {
     // 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);
     $this->assertNotEmpty(message_get_contact($user->id));
     // Remove user from admin's contact list.
     message_remove_contact($user->id);
     $this->assertEquals(false, message_get_contact($user->id));
 }
コード例 #5
0
ファイル: externallib.php プロジェクト: Burick/moodle
    /**
     * Delete contacts.
     *
     * @param array $userids array of user IDs.
     * @return null
     * @since 2.5
     */
    public static function delete_contacts($userids) {
        $params = array('userids' => $userids);
        $params = self::validate_parameters(self::delete_contacts_parameters(), $params);

        foreach ($params['userids'] as $id) {
            message_remove_contact($id);
        }

        return null;
    }
コード例 #6
0
ファイル: externallib.php プロジェクト: lucaboesch/moodle
 /**
  * Delete contacts.
  *
  * @param array $userids array of user IDs.
  * @param int $userid The id of the user we are deleting the contacts for
  * @return null
  * @since Moodle 2.5
  */
 public static function delete_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::delete_contacts_parameters(), $params);
     foreach ($params['userids'] as $id) {
         message_remove_contact($id, $userid);
     }
     return null;
 }