예제 #1
0
/**
 * Print the specified user's avatar.
 *
 * @deprecated since Moodle 2.0
 *
 * @global object
 * @global object
 * @param mixed $user Should be a $user object with at least fields id, picture, imagealt, firstname, lastname
 *      If any of these are missing, or if a userid is passed, the the database is queried. Avoid this
 *      if at all possible, particularly for reports. It is very bad for performance.
 * @param int $courseid The course id. Used when constructing the link to the user's profile.
 * @param boolean $picture The picture to print. By default (or if NULL is passed) $user->picture is used.
 * @param int $size Size in pixels. Special values are (true/1 = 100px) and (false/0 = 35px) for backward compatibility
 * @param boolean $return If false print picture to current page, otherwise return the output as string
 * @param boolean $link enclose printed image in a link the user's profile (default true).
 * @param string $target link target attribute. Makes the profile open in a popup window.
 * @param boolean $alttext add non-blank alt-text to the image. (Default true, set to false for purely
 *      decorative images, or where the username will be printed anyway.)
 * @return string|void String or nothing, depending on $return.
 */
function print_user_picture($user, $courseid, $picture = NULL, $size = 0, $return = false, $link = true, $target = '', $alttext = true)
{
    global $CFG, $DB, $OUTPUT;
    debugging('print_user_picture() has been deprecated. Please change your code to use $OUTPUT->user_picture($user, $courseid).');
    $userpic = new moodle_user_picture();
    $userpic->user = $user;
    $userpic->courseid = $courseid;
    $userpic->size = $size;
    $userpic->link = $link;
    $userpic->alttext = $alttext;
    if (!empty($picture)) {
        $userpic->image->src = $picture;
    }
    if (!empty($target)) {
        $userpic->add_action(new popup_action('click', new moodle_url($target)));
    }
    $output = $OUTPUT->user_picture($userpic);
    if ($return) {
        return $output;
    } else {
        echo $output;
    }
}