|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 class block_messages extends block_base { 00004 function init() { 00005 $this->title = get_string('pluginname', 'block_messages'); 00006 } 00007 00008 function get_content() { 00009 global $USER, $CFG, $DB, $OUTPUT; 00010 00011 if (!$CFG->messaging) { 00012 $this->content->text = ''; 00013 if ($this->page->user_is_editing()) { 00014 $this->content->text = get_string('disabled', 'message'); 00015 } 00016 return $this->content; 00017 } 00018 00019 if ($this->content !== NULL) { 00020 return $this->content; 00021 } 00022 00023 $this->content = new stdClass; 00024 $this->content->text = ''; 00025 $this->content->footer = ''; 00026 00027 if (empty($this->instance) or !isloggedin() or isguestuser() or empty($CFG->messaging)) { 00028 return $this->content; 00029 } 00030 00031 $link = '/message/index.php'; 00032 $action = null; //this was using popup_action() but popping up a fullsize window seems wrong 00033 $this->content->footer = $OUTPUT->action_link($link, get_string('messages', 'message'), $action); 00034 00035 $ufields = user_picture::fields('u', array('lastaccess')); 00036 $users = $DB->get_records_sql("SELECT $ufields, COUNT(m.useridfrom) AS count 00037 FROM {user} u, {message} m 00038 WHERE m.useridto = ? AND u.id = m.useridfrom AND m.notification = 0 00039 GROUP BY $ufields", array($USER->id)); 00040 00041 00042 //Now, we have in users, the list of users to show 00043 //Because they are online 00044 if (!empty($users)) { 00045 $this->content->text .= '<ul class="list">'; 00046 foreach ($users as $user) { 00047 $timeago = format_time(time() - $user->lastaccess); 00048 $this->content->text .= '<li class="listentry"><div class="user"><a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&course='.SITEID.'" title="'.$timeago.'">'; 00049 $this->content->text .= $OUTPUT->user_picture($user, array('courseid'=>SITEID)); //TODO: user might not have capability to view frontpage profile :-( 00050 $this->content->text .= fullname($user).'</a></div>'; 00051 00052 $link = '/message/index.php?usergroup=unread&id='.$user->id; 00053 $anchortagcontents = '<img class="iconsmall" src="'.$OUTPUT->pix_url('t/message') . '" alt="" /> '.$user->count; 00054 00055 $action = null; // popup is gone now 00056 $anchortag = $OUTPUT->action_link($link, $anchortagcontents, $action); 00057 00058 $this->content->text .= '<div class="message">'.$anchortag.'</div></li>'; 00059 } 00060 $this->content->text .= '</ul>'; 00061 } else { 00062 $this->content->text .= '<div class="info">'; 00063 $this->content->text .= get_string('nomessages', 'message'); 00064 $this->content->text .= '</div>'; 00065 } 00066 00067 return $this->content; 00068 } 00069 } 00070 00071