[ Index ]

PHP Cross Reference of moodle-2.8

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->text = '';
  35              if ($this->page->user_is_editing()) {
  36                  $this->content->text = get_string('disabled', 'message');
  37              }
  38              return $this->content;
  39          }
  40  
  41          if ($this->content !== NULL) {
  42              return $this->content;
  43          }
  44  
  45          $this->content = new stdClass;
  46          $this->content->text = '';
  47          $this->content->footer = '';
  48  
  49          if (empty($this->instance) or !isloggedin() or isguestuser() or empty($CFG->messaging)) {
  50              return $this->content;
  51          }
  52  
  53          $link = '/message/index.php';
  54          $action = null; //this was using popup_action() but popping up a fullsize window seems wrong
  55          $this->content->footer = $OUTPUT->action_link($link, get_string('messages', 'message'), $action);
  56  
  57          $ufields = user_picture::fields('u', array('lastaccess'));
  58          $users = $DB->get_records_sql("SELECT $ufields, COUNT(m.useridfrom) AS count
  59                                           FROM {user} u, {message} m
  60                                          WHERE m.useridto = ? AND u.id = m.useridfrom AND m.notification = 0
  61                                       GROUP BY $ufields", array($USER->id));
  62  
  63  
  64          //Now, we have in users, the list of users to show
  65          //Because they are online
  66          if (!empty($users)) {
  67              $this->content->text .= '<ul class="list">';
  68              foreach ($users as $user) {
  69                  $timeago = format_time(time() - $user->lastaccess);
  70                  $this->content->text .= '<li class="listentry"><div class="user"><a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.SITEID.'" title="'.$timeago.'">';
  71                  $this->content->text .= $OUTPUT->user_picture($user, array('courseid'=>SITEID)); //TODO: user might not have capability to view frontpage profile :-(
  72                  $this->content->text .= fullname($user).'</a></div>';
  73  
  74                  $link = '/message/index.php?usergroup=unread&id='.$user->id;
  75                  $anchortagcontents = '<img class="iconsmall" src="'.$OUTPUT->pix_url('t/message') . '" alt="" />&nbsp;'.$user->count;
  76  
  77                  $action = null; // popup is gone now
  78                  $anchortag = $OUTPUT->action_link($link, $anchortagcontents, $action);
  79  
  80                  $this->content->text .= '<div class="message">'.$anchortag.'</div></li>';
  81              }
  82              $this->content->text .= '</ul>';
  83          } else {
  84              $this->content->text .= '<div class="info">';
  85              $this->content->text .= get_string('nomessages', 'message');
  86              $this->content->text .= '</div>';
  87          }
  88  
  89          return $this->content;
  90      }
  91  }
  92  
  93  


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1