function get_content()
 {
     global $USER, $CFG, $DB, $OUTPUT, $PAGE;
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->text = '';
     $this->content->footer = '';
     if (empty($this->instance)) {
         return $this->content;
     }
     $timetoshowusers = 300;
     //Seconds default
     if (isset($CFG->block_online_users_timetosee)) {
         $timetoshowusers = $CFG->block_online_users_timetosee * 60;
     }
     $now = time();
     //Calculate if we are in separate groups
     $isseparategroups = $this->page->course->groupmode == SEPARATEGROUPS && $this->page->course->groupmodeforce && !has_capability('moodle/site:accessallgroups', $this->page->context);
     //Get the user current group
     $currentgroup = $isseparategroups ? groups_get_course_group($this->page->course) : NULL;
     $sitelevel = $this->page->course->id == SITEID || $this->page->context->contextlevel < CONTEXT_COURSE;
     $onlineusers = new fetcher($currentgroup, $now, $timetoshowusers, $this->page->context, $sitelevel, $this->page->course->id);
     //Calculate minutes
     $minutes = floor($timetoshowusers / 60);
     // Verify if we can see the list of users, if not just print number of users
     if (!has_capability('block/online_users:viewlist', $this->page->context)) {
         if (!($usercount = $onlineusers->count_users())) {
             $usercount = get_string("none");
         }
         $this->content->text = "<div class=\"info\">" . get_string("periodnminutes", "block_online_users", $minutes) . ": {$usercount}</div>";
         return $this->content;
     }
     $userlimit = 50;
     // We'll just take the most recent 50 maximum.
     if ($users = $onlineusers->get_users($userlimit)) {
         foreach ($users as $user) {
             $users[$user->id]->fullname = fullname($user);
         }
     } else {
         $users = array();
     }
     if (count($users) < $userlimit) {
         $usercount = "";
     } else {
         $usercount = $onlineusers->count_users();
         $usercount = ": {$usercount}";
     }
     $this->content->text = "<div class=\"info\">(" . get_string("periodnminutes", "block_online_users", $minutes) . "{$usercount})</div>";
     //Now, we have in users, the list of users to show
     //Because they are online
     if (!empty($users)) {
         //Accessibility: Don't want 'Alt' text for the user picture; DO want it for the envelope/message link (existing lang string).
         //Accessibility: Converted <div> to <ul>, inherit existing classes & styles.
         $this->content->text .= "<ul class='list'>\n";
         if (isloggedin() && has_capability('moodle/site:sendmessage', $this->page->context) && !empty($CFG->messaging) && !isguestuser()) {
             $canshowicon = true;
             message_messenger_requirejs();
         } else {
             $canshowicon = false;
         }
         foreach ($users as $user) {
             $this->content->text .= '<li class="listentry">';
             $timeago = format_time($now - $user->lastaccess);
             //bruno to calculate correctly on frontpage
             if (isguestuser($user)) {
                 $this->content->text .= '<div class="user">' . $OUTPUT->user_picture($user, array('size' => 16, 'alttext' => false));
                 $this->content->text .= get_string('guestuser') . '</div>';
             } else {
                 $this->content->text .= '<div class="user">';
                 $this->content->text .= '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $user->id . '&amp;course=' . $this->page->course->id . '" title="' . $timeago . '">';
                 $this->content->text .= $OUTPUT->user_picture($user, array('size' => 16, 'alttext' => false, 'link' => false)) . $user->fullname . '</a></div>';
             }
             if ($canshowicon and $USER->id != $user->id and !isguestuser($user)) {
                 // Only when logged in and messaging active etc
                 $anchortagcontents = '<img class="iconsmall" src="' . $OUTPUT->pix_url('t/message') . '" alt="' . get_string('messageselectadd') . '" />';
                 $anchorurl = new moodle_url('/message/index.php', array('id' => $user->id));
                 $anchortag = html_writer::link($anchorurl, $anchortagcontents, array_merge(message_messenger_sendmessage_link_params($user), array('title' => get_string('messageselectadd'))));
                 $this->content->text .= '<div class="message">' . $anchortag . '</div>';
             }
             $this->content->text .= "</li>\n";
         }
         $this->content->text .= '</ul><div class="clearer"><!-- --></div>';
     } else {
         $this->content->text .= "<div class=\"info\">" . get_string("none") . "</div>";
     }
     return $this->content;
 }
 function get_content()
 {
     global $USER, $CFG, $DB, $OUTPUT, $PAGE;
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->text = '';
     $this->content->footer = '';
     if (empty($this->instance)) {
         return $this->content;
     }
     $timetoshowusers = 300;
     //Seconds default
     if (isset($CFG->block_online_users_timetosee)) {
         $timetoshowusers = $CFG->block_online_users_timetosee * 60;
     }
     $now = time();
     $timefrom = 100 * floor(($now - $timetoshowusers) / 100);
     // Round to nearest 100 seconds for better query cache
     //Calculate if we are in separate groups
     $isseparategroups = $this->page->course->groupmode == SEPARATEGROUPS && $this->page->course->groupmodeforce && !has_capability('moodle/site:accessallgroups', $this->page->context);
     //Get the user current group
     $currentgroup = $isseparategroups ? groups_get_course_group($this->page->course) : NULL;
     $groupmembers = "";
     $groupselect = "";
     $params = array();
     //Add this to the SQL to show only group users
     if ($currentgroup !== NULL) {
         $groupmembers = ", {groups_members} gm";
         $groupselect = "AND u.id = gm.userid AND gm.groupid = :currentgroup";
         $params['currentgroup'] = $currentgroup;
     }
     $userfields = user_picture::fields('u', array('username'));
     $params['now'] = $now;
     $params['timefrom'] = $timefrom;
     if ($this->page->course->id == SITEID or $this->page->context->contextlevel < CONTEXT_COURSE) {
         // Site-level
         $sql = "SELECT {$userfields}, MAX(u.lastaccess) AS lastaccess\n                      FROM {user} u {$groupmembers}\n                     WHERE u.lastaccess > :timefrom\n                           AND u.lastaccess <= :now\n                           AND u.deleted = 0\n                           {$groupselect}\n                  GROUP BY {$userfields}\n                  ORDER BY lastaccess DESC ";
         $csql = "SELECT COUNT(u.id)\n                      FROM {user} u {$groupmembers}\n                     WHERE u.lastaccess > :timefrom\n                           AND u.lastaccess <= :now\n                           AND u.deleted = 0\n                           {$groupselect}";
     } else {
         // Course level - show only enrolled users for now
         // TODO: add a new capability for viewing of all users (guests+enrolled+viewing)
         list($esqljoin, $eparams) = get_enrolled_sql($this->page->context);
         $params = array_merge($params, $eparams);
         $sql = "SELECT {$userfields}, MAX(ul.timeaccess) AS lastaccess\n                      FROM {user_lastaccess} ul {$groupmembers}, {user} u\n                      JOIN ({$esqljoin}) euj ON euj.id = u.id\n                     WHERE ul.timeaccess > :timefrom\n                           AND u.id = ul.userid\n                           AND ul.courseid = :courseid\n                           AND ul.timeaccess <= :now\n                           AND u.deleted = 0\n                           {$groupselect}\n                  GROUP BY {$userfields}\n                  ORDER BY lastaccess DESC";
         $csql = "SELECT COUNT(u.id)\n                      FROM {user_lastaccess} ul {$groupmembers}, {user} u\n                      JOIN ({$esqljoin}) euj ON euj.id = u.id\n                     WHERE ul.timeaccess > :timefrom\n                           AND u.id = ul.userid\n                           AND ul.courseid = :courseid\n                           AND ul.timeaccess <= :now\n                           AND u.deleted = 0\n                           {$groupselect}";
         $params['courseid'] = $this->page->course->id;
     }
     //Calculate minutes
     $minutes = floor($timetoshowusers / 60);
     // Verify if we can see the list of users, if not just print number of users
     if (!has_capability('block/online_users:viewlist', $this->page->context)) {
         if (!($usercount = $DB->count_records_sql($csql, $params))) {
             $usercount = get_string("none");
         }
         $this->content->text = "<div class=\"info\">" . get_string("periodnminutes", "block_online_users", $minutes) . ": {$usercount}</div>";
         return $this->content;
     }
     if ($users = $DB->get_records_sql($sql, $params, 0, 50)) {
         // We'll just take the most recent 50 maximum
         foreach ($users as $user) {
             $users[$user->id]->fullname = fullname($user);
         }
     } else {
         $users = array();
     }
     if (count($users) < 50) {
         $usercount = "";
     } else {
         $usercount = $DB->count_records_sql($csql, $params);
         $usercount = ": {$usercount}";
     }
     $this->content->text = "<div class=\"info\">(" . get_string("periodnminutes", "block_online_users", $minutes) . "{$usercount})</div>";
     //Now, we have in users, the list of users to show
     //Because they are online
     if (!empty($users)) {
         //Accessibility: Don't want 'Alt' text for the user picture; DO want it for the envelope/message link (existing lang string).
         //Accessibility: Converted <div> to <ul>, inherit existing classes & styles.
         $this->content->text .= "<ul class='list'>\n";
         if (isloggedin() && has_capability('moodle/site:sendmessage', $this->page->context) && !empty($CFG->messaging) && !isguestuser()) {
             $canshowicon = true;
             message_messenger_requirejs();
         } else {
             $canshowicon = false;
         }
         foreach ($users as $user) {
             $this->content->text .= '<li class="listentry">';
             $timeago = format_time($now - $user->lastaccess);
             //bruno to calculate correctly on frontpage
             if (isguestuser($user)) {
                 $this->content->text .= '<div class="user">' . $OUTPUT->user_picture($user, array('size' => 16, 'alttext' => false));
                 $this->content->text .= get_string('guestuser') . '</div>';
             } else {
                 $this->content->text .= '<div class="user">';
                 $this->content->text .= '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $user->id . '&amp;course=' . $this->page->course->id . '" title="' . $timeago . '">';
                 $this->content->text .= $OUTPUT->user_picture($user, array('size' => 16, 'alttext' => false, 'link' => false)) . $user->fullname . '</a></div>';
             }
             if ($canshowicon and $USER->id != $user->id and !isguestuser($user)) {
                 // Only when logged in and messaging active etc
                 $anchortagcontents = '<img class="iconsmall" src="' . $OUTPUT->pix_url('t/message') . '" alt="' . get_string('messageselectadd') . '" />';
                 $anchorurl = new moodle_url('/message/index.php', array('id' => $user->id));
                 $anchortag = html_writer::link($anchorurl, $anchortagcontents, array_merge(message_messenger_sendmessage_link_params($user), array('title' => get_string('messageselectadd'))));
                 $this->content->text .= '<div class="message">' . $anchortag . '</div>';
             }
             $this->content->text .= "</li>\n";
         }
         $this->content->text .= '</ul><div class="clearer"><!-- --></div>';
     } else {
         $this->content->text .= "<div class=\"info\">" . get_string("none") . "</div>";
     }
     return $this->content;
 }
Example #3
0
    /**
     * Returns the header bar.
     *
     * @since Moodle 2.9
     * @param array $headerinfo An array of header information, dependant on what type of header is being displayed. The following
     *                          array example is user specific.
     *                          heading => Override the page heading.
     *                          user => User object.
     *                          usercontext => user context.
     * @param int $headinglevel What level the 'h' tag will be.
     * @return string HTML for the header bar.
     */
    public function context_header($headerinfo = null, $headinglevel = 1) {
        global $DB, $USER, $CFG;
        $context = $this->page->context;
        // Make sure to use the heading if it has been set.
        if (isset($headerinfo['heading'])) {
            $heading = $headerinfo['heading'];
        } else {
            $heading = null;
        }
        $imagedata = null;
        $subheader = null;
        $userbuttons = null;
        // The user context currently has images and buttons. Other contexts may follow.
        if (isset($headerinfo['user']) || $context->contextlevel == CONTEXT_USER) {
            if (isset($headerinfo['user'])) {
                $user = $headerinfo['user'];
            } else {
                // Look up the user information if it is not supplied.
                $user = $DB->get_record('user', array('id' => $context->instanceid));
            }
            // If the user context is set, then use that for capability checks.
            if (isset($headerinfo['usercontext'])) {
                $context = $headerinfo['usercontext'];
            }
            // Use the user's full name if the heading isn't set.
            if (!isset($heading)) {
                $heading = fullname($user);
            }

            $imagedata = $this->user_picture($user, array('size' => 100));
            // Check to see if we should be displaying a message button.
            if (!empty($CFG->messaging) && $USER->id != $user->id && has_capability('moodle/site:sendmessage', $context)) {
                $userbuttons = array(
                    'messages' => array(
                        'buttontype' => 'message',
                        'title' => get_string('message', 'message'),
                        'url' => new moodle_url('/message/index.php', array('id' => $user->id)),
                        'image' => 'message',
                        'linkattributes' => message_messenger_sendmessage_link_params($user),
                        'page' => $this->page
                    )
                );
                $this->page->requires->string_for_js('changesmadereallygoaway', 'moodle');
            }
        }

        $contextheader = new context_header($heading, $headinglevel, $imagedata, $userbuttons);
        return $this->render_context_header($contextheader);
    }
Example #4
0
    } else {
        $ipstring = get_string("none");
    }
    echo html_writer::tag('dt', get_string('lastip'));
    echo html_writer::tag('dd', $ipstring);
}
echo html_writer::end_tag('dl');
echo "</div></div>";
// Closing desriptionbox and userprofilebox.
// Print messaging link if allowed.
if ($cansendmessage) {
    echo '<div class="messagebox">';
    $sendmessageurl = new moodle_url('/message/index.php', array('id' => $user->id));
    if ($courseid) {
        $sendmessageurl->param('viewing', MESSAGE_VIEW_COURSE . $courseid);
    }
    echo html_writer::link($sendmessageurl, get_string('messageselectadd'), message_messenger_sendmessage_link_params($user));
    echo '</div>';
}
if (empty($CFG->forceloginforprofiles) || $currentuser || has_capability('moodle/user:viewdetails', $usercontext) || has_coursecontact_role($id)) {
    echo '<div class="fullprofilelink">';
    echo html_writer::link($CFG->wwwroot . '/user/profile.php?id=' . $id, get_string('fullprofile'));
    echo '</div>';
}
// TODO Add more useful overview info for teachers here, see below.
// Show links to notes made about this student (must click to display, for privacy).
// Recent comments made in this course.
// Recent blogs associated with this course and items in it.
echo '</div>';
// Userprofile class.
echo $OUTPUT->footer();