[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/blocks/messages/ -> block_messages.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Mentees block.
  19   *
  20   * @package    block_messages
  21   * @copyright  1999 onwards Martin Dougiamas (http://dougiamas.com)
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  class block_messages extends block_base {
  26      function init() {
  27          $this->title = get_string('pluginname', 'block_messages');
  28      }
  29  
  30      function get_content() {
  31          global $USER, $CFG, $DB, $OUTPUT;
  32  
  33          if (!$CFG->messaging) {
  34              $this->content = new stdClass;
  35              $this->content->text = '';
  36              $this->content->footer = '';
  37              if ($this->page->user_is_editing()) {
  38                  $this->content->text = get_string('disabled', 'message');
  39              }
  40              return $this->content;
  41          }
  42  
  43          if ($this->content !== NULL) {
  44              return $this->content;
  45          }
  46  
  47          $this->content = new stdClass;
  48          $this->content->text = '';
  49          $this->content->footer = '';
  50  
  51          if (empty($this->instance) or !isloggedin() or isguestuser() or empty($CFG->messaging)) {
  52              return $this->content;
  53          }
  54  
  55          $link = '/message/index.php';
  56          $action = null; //this was using popup_action() but popping up a fullsize window seems wrong
  57          $this->content->footer = $OUTPUT->action_link($link, get_string('messages', 'message'), $action);
  58  
  59          $ufields = user_picture::fields('u', array('lastaccess'));
  60          $users = $DB->get_records_sql("SELECT $ufields, COUNT(m.useridfrom) AS count
  61                                           FROM {user} u, {message} m
  62                                          WHERE m.useridto = ? AND u.id = m.useridfrom AND m.notification = 0
  63                                       GROUP BY $ufields", array($USER->id));
  64  
  65  
  66          //Now, we have in users, the list of users to show
  67          //Because they are online
  68          if (!empty($users)) {
  69              $this->content->text .= '<ul class="list">';
  70              foreach ($users as $user) {
  71                  $timeago = format_time(time() - $user->lastaccess);
  72                  $this->content->text .= '<li class="listentry"><div class="user"><a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.SITEID.'" title="'.$timeago.'">';
  73                  $this->content->text .= $OUTPUT->user_picture($user, array('courseid'=>SITEID)); //TODO: user might not have capability to view frontpage profile :-(
  74                  $this->content->text .= fullname($user).'</a></div>';
  75  
  76                  $link = '/message/index.php?usergroup=unread&id='.$user->id;
  77                  $anchortagcontents = '<img class="iconsmall" src="'.$OUTPUT->pix_url('t/message') . '" alt="" />&nbsp;'.$user->count;
  78  
  79                  $action = null; // popup is gone now
  80                  $anchortag = $OUTPUT->action_link($link, $anchortagcontents, $action);
  81  
  82                  $this->content->text .= '<div class="message">'.$anchortag.'</div></li>';
  83              }
  84              $this->content->text .= '</ul>';
  85          } else {
  86              $this->content->text .= '<div class="info">';
  87              $this->content->text .= get_string('nomessages', 'message');
  88              $this->content->text .= '</div>';
  89          }
  90  
  91          return $this->content;
  92      }
  93  }
  94  
  95  


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1