示例#1
0
 /**
  * Fetches content for the block when displayed
  * @global Object $CFG Moodle config object
  * @global Object $USER Moodle user object
  * @return string Block content
  * @version 2012071701
  * @since 2010081801
  */
 public function get_content()
 {
     global $CFG, $USER;
     // If content has already been created, return that
     if ($this->content !== NULL) {
         return $this->content;
     }
     // Get renderer
     $output = $this->page->get_renderer('block_moodletxt');
     // Get some user details
     $user = $this->userDAO->getUserById($USER->id);
     // Initialise content class
     $this->content = new stdClass();
     // Check that specialization has been done
     $this->specialization();
     $userIsAdmin = false;
     $userCanReceive = false;
     // Check for admin
     $userIsAdmin = has_capability('block/moodletxt:adminsettings', $this->context, $USER->id) || has_capability('block/moodletxt:adminusers', $this->context, $USER->id);
     // Check that user has send access
     $checkSend = has_capability('block/moodletxt:sendmessages', $this->context, $USER->id);
     // Check user is allowed to set their signature/templates up
     $checkPrefs = has_capability('block/moodletxt:personalsettings', $this->context, $USER->id);
     $unreadFrag = '';
     if (has_capability('block/moodletxt:receivemessages', $this->context, $USER->id)) {
         $userCanReceive = true;
         $unreadMessages = $this->receivedMessagesDAO->countMessagesInUsersInbox($USER->id, true);
         if ($unreadMessages > 0) {
             $unreadFrag = html_writer::tag('b', '(' . $unreadMessages . ')');
         }
     }
     // Initialise content object
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     // Add links to block dependent on user permissions/access level
     if ($checkSend) {
         $icon = new moodletxt_icon(moodletxt_icon::$ICON_MESSAGE_COMPOSE, get_string('altcompose', 'block_moodletxt'), array('title' => get_string('imgtitlecompose', 'block_moodletxt')));
         array_push($this->content->items, html_writer::tag('a', get_string('blocklinksend', 'block_moodletxt'), array('href' => $CFG->wwwroot . '/blocks/moodletxt/send.php?course=' . $this->page->course->id . '&instance=' . $this->instance->id)));
         array_push($this->content->icons, $output->render($icon));
         $icon = new moodletxt_icon(moodletxt_icon::$ICON_MESSAGES_SENT, get_string('altsentmessages', 'block_moodletxt'), array('title' => get_string('imgtitlesentmessages', 'block_moodletxt')));
         array_push($this->content->items, html_writer::tag('a', get_string('blocklinksent', 'block_moodletxt'), array('href' => $CFG->wwwroot . '/blocks/moodletxt/sent.php?course=' . $this->page->course->id . '&instance=' . $this->instance->id)));
         array_push($this->content->icons, $output->render($icon));
         $icon = new moodletxt_icon(moodletxt_icon::$ICON_ADDRESSBOOK, get_string('altaddressbook', 'block_moodletxt'), array('title' => get_string('imgtitleaddressbook', 'block_moodletxt')));
         array_push($this->content->items, html_writer::tag('a', get_string('blocklinkaddressbook', 'block_moodletxt'), array('href' => $CFG->wwwroot . '/blocks/moodletxt/addressbooks.php?course=' . $this->page->course->id . '&instance=' . $this->instance->id)));
         array_push($this->content->icons, $output->render($icon));
     }
     if ($userCanReceive) {
         $icon = new moodletxt_icon(moodletxt_icon::$ICON_MESSAGES_INBOX, get_string('altinbox', 'block_moodletxt'), array('title' => get_string('imgtitleinbox', 'block_moodletxt')));
         array_push($this->content->items, html_writer::tag('a', get_string('blocklinkinbox', 'block_moodletxt') . $unreadFrag, array('href' => $CFG->wwwroot . '/blocks/moodletxt/received.php?course=' . $this->page->course->id . '&instance=' . $this->instance->id)));
         array_push($this->content->icons, $output->render($icon));
     }
     if ($checkPrefs) {
         $icon = new moodletxt_icon(moodletxt_icon::$ICON_PREFERENCES, get_string('altpreferences', 'block_moodletxt'), array('title' => get_string('imgtitlepreferences', 'block_moodletxt')));
         array_push($this->content->items, html_writer::tag('a', get_string('blocklinkpreferences', 'block_moodletxt'), array('href' => $CFG->wwwroot . '/blocks/moodletxt/preferences.php?course=' . $this->page->course->id . '&instance=' . $this->instance->id)));
         array_push($this->content->icons, $output->render($icon));
     }
     if ($userIsAdmin) {
         //            $icon = new moodletxt_icon(moodletxt_icon::$ICON_STATS, get_string('altstats', 'block_moodletxt'), array('title' => get_string('imgtitlestats', 'block_moodletxt')));
         //            array_push($this->content->items, html_writer::tag('a', get_string('blocklinkstats', 'block_moodletxt'), array('href' => $CFG->wwwroot . '/blocks/moodletxt/userstats.php?course=' . $this->page->course->id . '&instance=' . $this->instance->id)));
         //            array_push($this->content->icons, $output->render($icon));
         $icon = new moodletxt_icon(moodletxt_icon::$ICON_SETTINGS, get_string('altsettings', 'block_moodletxt'), array('title' => get_string('imgtitlesettings', 'block_moodletxt')));
         array_push($this->content->items, html_writer::tag('a', get_string('blocklinksettings', 'block_moodletxt'), array('href' => $CFG->wwwroot . '/admin/settings.php?section=blocksettingmoodletxt')));
         array_push($this->content->icons, $output->render($icon));
     }
     // If some form of content has been added, set up block
     if (count($this->content->items) > 0) {
         $this->content->footer = get_string('blockfooter', 'block_moodletxt');
         // Check whether config info has been previously defined
         if (!isset($this->config->title) || empty($this->config->title)) {
             // Set up default configuration
             $this->title = get_string('blocktitle', 'block_moodletxt');
         } else {
             // Use user configuration
             $this->title = $this->config->title;
         }
     }
     return $this->content;
 }