. /** * Mentees block. * * @package block_messages * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class block_messages extends block_base { function init() { $this->title = get_string('pluginname', 'block_messages'); } function get_content() { global $USER, $CFG, $DB, $OUTPUT; if (!$CFG->messaging) { $this->content->text = ''; if ($this->page->user_is_editing()) { $this->content->text = get_string('disabled', 'message'); } return $this->content; } if ($this->content !== NULL) { return $this->content; } $this->content = new stdClass; $this->content->text = ''; $this->content->footer = ''; if (empty($this->instance) or !isloggedin() or isguestuser() or empty($CFG->messaging)) { return $this->content; } $link = '/message/index.php'; $action = null; //this was using popup_action() but popping up a fullsize window seems wrong $this->content->footer = $OUTPUT->action_link($link, get_string('messages', 'message'), $action); $ufields = user_picture::fields('u', array('lastaccess')); $users = $DB->get_records_sql("SELECT $ufields, COUNT(m.useridfrom) AS count FROM {user} u, {message} m WHERE m.useridto = ? AND u.id = m.useridfrom AND m.notification = 0 GROUP BY $ufields", array($USER->id)); //Now, we have in users, the list of users to show //Because they are online if (!empty($users)) { $this->content->text .= ''; } else { $this->content->text .= '
'; $this->content->text .= get_string('nomessages', 'message'); $this->content->text .= '
'; } return $this->content; } }