Example #1
0
/**
 * Print a row of contactlist displaying user picture, messages waiting and
 * block links etc
 * @param object $contact contact object containing all fields required for $OUTPUT->user_picture()
 * @param bool $incontactlist is the user a contact of ours?
 * @param bool $isblocked is the user blocked?
 * @param string $selectcontacturl the url to send the user to when a contact's name is clicked
 * @param bool $showactionlinks display action links next to the other users (add contact, block user etc)
 * @param object $selecteduser the user the current user is viewing (if any). They will be highlighted.
 */
function message_print_contactlist_user($contact, $incontactlist = true, $isblocked = false, $selectcontacturl = null, $showactionlinks = true, $selecteduser=null) {
    global $OUTPUT, $USER;
    $fullname  = fullname($contact);
    $fullnamelink  = $fullname;

    $linkclass = '';
    if (!empty($selecteduser) && $contact->id == $selecteduser->id) {
        $linkclass = 'messageselecteduser';
    }

    /// are there any unread messages for this contact?
    if ($contact->messagecount > 0 ){
        $fullnamelink = '<strong>'.$fullnamelink.' ('.$contact->messagecount.')</strong>';
    }

    $strcontact = $strblock = $strhistory = null;

    if ($showactionlinks) {
        $strcontact = message_get_contact_add_remove_link($incontactlist, $isblocked, $contact);
        $strblock   = message_get_contact_block_link($incontactlist, $isblocked, $contact);
        $strhistory = message_history_link($USER->id, $contact->id, true, '', '', 'icon');
    }

    echo html_writer::start_tag('tr');
    echo html_writer::start_tag('td', array('class' => 'pix'));
    echo $OUTPUT->user_picture($contact, array('size' => 20, 'courseid' => SITEID));
    echo html_writer::end_tag('td');

    echo html_writer::start_tag('td', array('class' => 'contact'));

    $popupoptions = array(
            'height' => MESSAGE_DISCUSSION_HEIGHT,
            'width' => MESSAGE_DISCUSSION_WIDTH,
            'menubar' => false,
            'location' => false,
            'status' => true,
            'scrollbars' => true,
            'resizable' => true);

    $link = $action = null;
    if (!empty($selectcontacturl)) {
        $link = new moodle_url($selectcontacturl.'&user2='.$contact->id);
    } else {
        //can $selectcontacturl be removed and maybe the be removed and hardcoded?
        $link = new moodle_url("/message/index.php?id=$contact->id");
        $action = new popup_action('click', $link, "message_$contact->id", $popupoptions);
    }
    echo $OUTPUT->action_link($link, $fullnamelink, $action, array('class' => $linkclass,'title' => get_string('sendmessageto', 'message', $fullname)));

    echo html_writer::end_tag('td');

    echo html_writer::tag('td', '&nbsp;'.$strcontact.$strblock.'&nbsp;'.$strhistory, array('class' => 'link'));

    echo html_writer::end_tag('tr');
}
Example #2
0
/**
 * Print a row of contactlist displaying user picture, messages waiting and
 * block links etc
 *
 * @param object $contact contact object containing all fields required for $OUTPUT->user_picture()
 * @param bool $incontactlist is the user a contact of ours?
 * @param bool $isblocked is the user blocked?
 * @param string $selectcontacturl the url to send the user to when a contact's name is clicked
 * @param bool $showactionlinks display action links next to the other users (add contact, block user etc)
 * @param object $selecteduser the user the current user is viewing (if any). They will be highlighted.
 * @return void
 */
function message_print_contactlist_user($contact, $incontactlist = true, $isblocked = false, $selectcontacturl = null, $showactionlinks = true, $selecteduser = null)
{
    global $OUTPUT, $USER, $COURSE;
    $fullname = fullname($contact);
    $fullnamelink = $fullname;
    $output = '';
    $linkclass = '';
    if (!empty($selecteduser) && $contact->id == $selecteduser->id) {
        $linkclass = 'messageselecteduser';
    }
    // Are there any unread messages for this contact?
    if ($contact->messagecount > 0) {
        $fullnamelink = '<strong>' . $fullnamelink . ' (' . $contact->messagecount . ')</strong>';
    }
    $strcontact = $strblock = $strhistory = null;
    if ($showactionlinks) {
        // Show block and delete links if user is real user.
        if (core_user::is_real_user($contact->id)) {
            $strcontact = message_get_contact_add_remove_link($incontactlist, $isblocked, $contact);
            $strblock = message_get_contact_block_link($incontactlist, $isblocked, $contact);
        }
        $strhistory = message_history_link($USER->id, $contact->id, true, '', '', 'icon');
    }
    $output .= html_writer::start_tag('div', array('class' => 'pix'));
    $output .= $OUTPUT->user_picture($contact, array('size' => 20, 'courseid' => $COURSE->id));
    $output .= html_writer::end_tag('div');
    $popupoptions = array('height' => MESSAGE_DISCUSSION_HEIGHT, 'width' => MESSAGE_DISCUSSION_WIDTH, 'menubar' => false, 'location' => false, 'status' => true, 'scrollbars' => true, 'resizable' => true);
    $link = $action = null;
    if (!empty($selectcontacturl)) {
        $link = new moodle_url($selectcontacturl . '&user2=' . $contact->id);
    } else {
        //can $selectcontacturl be removed and maybe the be removed and hardcoded?
        $link = new moodle_url("/message/index.php?id={$contact->id}");
        $action = new popup_action('click', $link, "message_{$contact->id}", $popupoptions);
    }
    if (strlen($strcontact . $strblock . $strhistory) > 0) {
        $output .= html_writer::tag('div', $strcontact . $strblock . $strhistory, array('class' => 'link'));
        $output .= html_writer::start_tag('div', array('class' => 'contact'));
        $linkattr = array('class' => $linkclass, 'title' => get_string('sendmessageto', 'message', $fullname));
        $output .= $OUTPUT->action_link($link, $fullnamelink, $action, $linkattr);
        $output .= html_writer::end_tag('div');
    } else {
        $output .= html_writer::start_tag('div', array('class' => 'contact nolinks'));
        $linkattr = array('class' => $linkclass, 'title' => get_string('sendmessageto', 'message', $fullname));
        $output .= $OUTPUT->action_link($link, $fullnamelink, $action, $linkattr);
        $output .= html_writer::end_tag('div');
    }
    return $output;
}