[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/tag/classes/ -> renderer.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   * Contains class core_tag_renderer
  19   *
  20   * @package   core_tag
  21   * @copyright 2015 Marina Glancy
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  /**
  28   * Class core_tag_renderer
  29   *
  30   * @package   core_tag
  31   * @copyright 2015 Marina Glancy
  32   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  class core_tag_renderer extends plugin_renderer_base {
  35  
  36      /**
  37       * Renders the tag search page
  38       *
  39       * @param string $query
  40       * @param int $tagcollid
  41       * @return string
  42       */
  43      public function tag_search_page($query = '', $tagcollid = 0) {
  44          $rv = $this->output->heading(get_string('searchtags', 'tag'), 2);
  45  
  46          $searchbox = $this->search_form($query, $tagcollid);
  47          $rv .= html_writer::div($searchbox, '', array('id' => 'tag-search-box'));
  48  
  49          $tagcloud = core_tag_collection::get_tag_cloud($tagcollid, false, 150, 'name', $query);
  50          $searchresults = '';
  51          if ($tagcloud->get_count()) {
  52              $searchresults = $this->output->render_from_template('core_tag/tagcloud',
  53                      $tagcloud->export_for_template($this->output));
  54              $rv .= html_writer::div($searchresults, '', array('id' => 'tag-search-results'));
  55          } else if (strval($query) !== '') {
  56              $rv .= '<div class="tag-search-empty">' . get_string('notagsfound', 'tag', s($query)) . '</div>';
  57          }
  58  
  59          return $rv;
  60      }
  61  
  62      /**
  63       * Renders the tag index page
  64       *
  65       * @param core_tag_tag $tag
  66       * @param \core_tag\output\tagindex[] $entities
  67       * @param int $tagareaid
  68       * @param bool $exclusivemode if set to true it means that no other entities tagged with this tag
  69       *             are displayed on the page and the per-page limit may be bigger
  70       * @param int $fromctx context id where the link was displayed, may be used by callbacks
  71       *            to display items in the same context first
  72       * @param int $ctx context id where to search for records
  73       * @param bool $rec search in subcontexts as well
  74       * @param int $page 0-based number of page being displayed
  75       * @return string
  76       */
  77      public function tag_index_page($tag, $entities, $tagareaid, $exclusivemode, $fromctx, $ctx, $rec, $page) {
  78          global $CFG, $OUTPUT;
  79          $this->page->requires->js_call_amd('core/tag', 'initTagindexPage');
  80  
  81          $tagname = $tag->get_display_name();
  82          $systemcontext = context_system::instance();
  83  
  84          if ($tag->flag > 0 && has_capability('moodle/tag:manage', $systemcontext)) {
  85              $tagname = '<span class="flagged-tag">' . $tagname . '</span>';
  86          }
  87  
  88          $rv = '';
  89          $rv .= $this->output->heading($tagname, 2);
  90  
  91          $rv .= $this->tag_links($tag);
  92  
  93          if ($desciption = $tag->get_formatted_description()) {
  94              $rv .= $this->output->box($desciption, 'generalbox tag-description');
  95          }
  96  
  97          $relatedtagslimit = 10;
  98          $relatedtags = $tag->get_related_tags();
  99          $taglist = new \core_tag\output\taglist($relatedtags, get_string('relatedtags', 'tag'),
 100                  'tag-relatedtags', $relatedtagslimit);
 101          $rv .= $OUTPUT->render_from_template('core_tag/taglist', $taglist->export_for_template($OUTPUT));
 102  
 103          // Display quick menu of the item types (if more than one item type found).
 104          $entitylinks = array();
 105          foreach ($entities as $entity) {
 106              if (!empty($entity->hascontent)) {
 107                  $entitylinks[] = '<li><a href="#'.$entity->anchor.'">' .
 108                          core_tag_area::display_name($entity->component, $entity->itemtype) . '</a></li>';
 109              }
 110          }
 111  
 112          if (count($entitylinks) > 1) {
 113              $rv .= '<div class="tag-index-toc"><ul class="inline-list">' . join('', $entitylinks) . '</ul></div>';
 114          } else if (!$entitylinks) {
 115              $rv .= '<div class="tag-noresults">' . get_string('noresultsfor', 'tag', $tagname) . '</div>';
 116          }
 117  
 118          // Display entities tagged with the tag.
 119          $content = '';
 120          foreach ($entities as $entity) {
 121              if (!empty($entity->hascontent)) {
 122                  $content .= $this->output->render_from_template('core_tag/index', $entity->export_for_template($this->output));
 123              }
 124          }
 125  
 126          if ($exclusivemode) {
 127              $rv .= $content;
 128          } else if ($content) {
 129              $rv .= html_writer::div($content, 'tag-index-items');
 130          }
 131  
 132          // Display back link if we are browsing one tag area.
 133          if ($tagareaid) {
 134              $url = $tag->get_view_url(0, $fromctx, $ctx, $rec);
 135              $rv .= '<div class="tag-backtoallitems">' .
 136                      html_writer::link($url, get_string('backtoallitems', 'tag', $tag->get_display_name())) .
 137                      '</div>';
 138          }
 139  
 140          return $rv;
 141      }
 142  
 143      /**
 144       * Prints a box that contains the management links of a tag
 145       *
 146       * @param core_tag_tag $tag
 147       * @return string
 148       */
 149      protected function tag_links($tag) {
 150          if ($links = $tag->get_links()) {
 151              $content = '<ul class="inline-list"><li>' . implode('</li> <li>', $links) . '</li></ul>';
 152              return html_writer::div($content, 'tag-management-box');
 153          }
 154          return '';
 155      }
 156  
 157      /**
 158       * Prints the tag search box
 159       *
 160       * @param string $query last search string
 161       * @param int $tagcollid last selected tag collection id
 162       * @return string
 163       */
 164      protected function search_form($query = '', $tagcollid = 0) {
 165          $searchurl = new moodle_url('/tag/search.php');
 166          $output = '<form action="' . $searchurl . '">';
 167          $output .= '<label class="accesshide" for="searchform_query">' . get_string('searchtags', 'tag') . '</label>';
 168          $output .= '<input id="searchform_query" name="query" type="text" size="40" value="' . s($query) . '" />';
 169          $tagcolls = core_tag_collection::get_collections_menu(false, true, get_string('inalltagcoll', 'tag'));
 170          if (count($tagcolls) > 1) {
 171              $output .= '<label class="accesshide" for="searchform_tc">' . get_string('selectcoll', 'tag') . '</label>';
 172              $output .= html_writer::select($tagcolls, 'tc', $tagcollid, null, array('id' => 'searchform_tc'));
 173          }
 174          $output .= '<input name="go" type="submit" size="40" value="' . s(get_string('search', 'tag')) . '" />';
 175          $output .= '</form>';
 176  
 177          return $output;
 178      }
 179  
 180  }


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