Example #1
0
    if ($countunread > 0) {
        //mark the messages we're going to display as read
        message_mark_messages_read($user1->id, $user2->id);
        if ($viewing == MESSAGE_VIEW_UNREAD_MESSAGES) {
            $viewingnewmessages = true;
        }
    }
}
$countunreadtotal = message_count_unread_messages($user1);
if ($currentuser && $countunreadtotal == 0 && $viewing == MESSAGE_VIEW_UNREAD_MESSAGES && empty($user2)) {
    // If the user has no unread messages, show the search box.
    // We don't do this when a user is viewing another user's messages as search doesn't
    // handle user A searching user B's messages properly.
    $viewing = MESSAGE_VIEW_SEARCH;
}
$blockedusers = message_get_blocked_users($user1, $user2);
$countblocked = count($blockedusers);
list($onlinecontacts, $offlinecontacts, $strangers) = message_get_contacts($user1, $user2);
message_print_contact_selector($countunreadtotal, $viewing, $user1, $user2, $blockedusers, $onlinecontacts, $offlinecontacts, $strangers, $showactionlinks, $page);
echo html_writer::start_tag('div', array('class' => 'messagearea mdl-align'));
if (!empty($user2)) {
    echo html_writer::start_tag('div', array('class' => 'mdl-left messagehistory'));
    $visible = 'visible';
    $hidden = 'hiddenelement';
    //cant just use hidden as mform adds that class to its fieldset for something else
    $recentlinkclass = $recentlabelclass = $historylinkclass = $historylabelclass = $visible;
    if ($history == MESSAGE_HISTORY_ALL) {
        $displaycount = 0;
        $recentlabelclass = $historylinkclass = $hidden;
    } else {
        if ($viewingnewmessages) {
 /**
  * Test message_get_blocked_users.
  */
 public function test_message_get_blocked_users()
 {
     // 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);
     $this->assertCount(1, message_get_blocked_users());
     // Block other user.
     message_block_contact($user1->id);
     $this->assertCount(2, message_get_blocked_users());
 }
Example #3
0
 /**
  * Retrieve a list of users blocked
  *
  * @param  int $userid the user whose blocked users we want to retrieve
  * @return external_description
  * @since 2.9
  */
 public static function get_blocked_users($userid)
 {
     global $CFG, $USER, $PAGE;
     // Warnings array, it can be empty at the end but is mandatory.
     $warnings = array();
     // Validate params.
     $params = array('userid' => $userid);
     $params = self::validate_parameters(self::get_blocked_users_parameters(), $params);
     $userid = $params['userid'];
     // Validate context.
     $context = context_system::instance();
     self::validate_context($context);
     // Check if private messaging between users is allowed.
     if (empty($CFG->messaging)) {
         throw new moodle_exception('disabled', 'message');
     }
     $user = core_user::get_user($userid, '*', MUST_EXIST);
     core_user::require_active_user($user);
     // Check if we have permissions for retrieve the information.
     if ($userid != $USER->id and !has_capability('moodle/site:readallmessages', $context)) {
         throw new moodle_exception('accessdenied', 'admin');
     }
     // Now, we can get safely all the blocked users.
     $users = message_get_blocked_users($user);
     $blockedusers = array();
     foreach ($users as $user) {
         $newuser = array('id' => $user->id, 'fullname' => fullname($user));
         $userpicture = new user_picture($user);
         $userpicture->size = 1;
         // Size f1.
         $newuser['profileimageurl'] = $userpicture->get_url($PAGE)->out(false);
         $blockedusers[] = $newuser;
     }
     $results = array('users' => $blockedusers, 'warnings' => $warnings);
     return $results;
 }
Example #4
0
    /**
     * Retrieve a list of users blocked
     *
     * @param  int $userid the user whose blocked users we want to retrieve
     * @return external_description
     * @since 2.9
     */
    public static function get_blocked_users($userid) {
        global $CFG, $USER;
        require_once($CFG->dirroot . "/message/lib.php");

        // Warnings array, it can be empty at the end but is mandatory.
        $warnings = array();

        // Validate params.
        $params = array(
            'userid' => $userid
        );
        $params = self::validate_parameters(self::get_blocked_users_parameters(), $params);
        $userid = $params['userid'];

        // Validate context.
        $context = context_system::instance();
        self::validate_context($context);

        // Check if private messaging between users is allowed.
        if (empty($CFG->messaging)) {
            throw new moodle_exception('disabled', 'message');
        }

        $user = core_user::get_user($userid, '*', MUST_EXIST);
        core_user::require_active_user($user);

        // Check if we have permissions for retrieve the information.
        if ($userid != $USER->id and !has_capability('moodle/site:readallmessages', $context)) {
            throw new moodle_exception('accessdenied', 'admin');
        }

        // Now, we can get safely all the blocked users.
        $users = message_get_blocked_users($user);

        $blockedusers = array();
        foreach ($users as $user) {
            $newuser = array(
                'id' => $user->id,
                'fullname' => fullname($user),
            );

            $usercontext = context_user::instance($user->id, IGNORE_MISSING);
            if ($usercontext) {
                $newuser['profileimageurl'] = moodle_url::make_webservice_pluginfile_url(
                                                $usercontext->id, 'user', 'icon', null, '/', 'f1')->out(false);
            } else {
                $newuser['profileimageurl'] = '';
            }

            $blockedusers[] = $newuser;
        }

        $results = array(
            'users' => $blockedusers,
            'warnings' => $warnings
        );
        return $results;
    }