[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/tag/ -> index.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  /**
  19   * @package    core_tag
  20   * @category   tag
  21   * @copyright  2007 Luiz Cruz <[email protected]>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require_once('../config.php');
  26  require_once ('lib.php');
  27  require_once ('locallib.php');
  28  require_once($CFG->dirroot.'/lib/weblib.php');
  29  require_once($CFG->dirroot.'/blog/lib.php');
  30  
  31  require_login();
  32  
  33  if (empty($CFG->usetags)) {
  34      print_error('tagsaredisabled', 'tag');
  35  }
  36  
  37  $tagid       = optional_param('id', 0, PARAM_INT); // tag id
  38  $tagname     = optional_param('tag', '', PARAM_TAG); // tag
  39  
  40  $edit        = optional_param('edit', -1, PARAM_BOOL);
  41  $userpage    = optional_param('userpage', 0, PARAM_INT); // which page to show
  42  $perpage     = optional_param('perpage', 24, PARAM_INT);
  43  
  44  $systemcontext   = context_system::instance();
  45  
  46  if ($tagname) {
  47      $tag = tag_get('name', $tagname, '*');
  48  } else if ($tagid) {
  49      $tag = tag_get('id', $tagid, '*');
  50  }
  51  unset($tagid);
  52  if (empty($tag)) {
  53      redirect($CFG->wwwroot.'/tag/search.php');
  54  }
  55  
  56  $PAGE->set_url('/tag/index.php', array('id' => $tag->id));
  57  $PAGE->set_subpage($tag->id);
  58  $PAGE->set_context($systemcontext);
  59  $PAGE->set_pagelayout('standard');
  60  $PAGE->set_blocks_editing_capability('moodle/tag:editblocks');
  61  
  62  if (($edit != -1) and $PAGE->user_allowed_editing()) {
  63      $USER->editing = $edit;
  64  }
  65  
  66  $tagname = tag_display_name($tag);
  67  $title = get_string('tag', 'tag') .' - '. $tagname;
  68  
  69  $button = '';
  70  if ($PAGE->user_allowed_editing() ) {
  71      $button = $OUTPUT->edit_button(new moodle_url("$CFG->wwwroot/tag/index.php", array('id' => $tag->id)));
  72  }
  73  
  74  $PAGE->navbar->add(get_string('tags', 'tag'), new moodle_url('/tag/search.php'));
  75  $PAGE->navbar->add($tagname);
  76  $PAGE->set_title($title);
  77  $PAGE->set_heading($COURSE->fullname);
  78  $PAGE->set_button($button);
  79  $courserenderer = $PAGE->get_renderer('core', 'course');
  80  echo $OUTPUT->header();
  81  
  82  // Manage all tags links
  83  if (has_capability('moodle/tag:manage', $systemcontext)) {
  84      echo '<div class="managelink"><a href="'. $CFG->wwwroot .'/tag/manage.php">'. get_string('managetags', 'tag') .'</a></div>' ;
  85  }
  86  
  87  $tagname  = tag_display_name($tag);
  88  
  89  if ($tag->flag > 0 && has_capability('moodle/tag:manage', $systemcontext)) {
  90      $tagname =  '<span class="flagged-tag">' . $tagname . '</span>';
  91  }
  92  
  93  echo $OUTPUT->heading($tagname, 2);
  94  tag_print_management_box($tag);
  95  tag_print_description_box($tag);
  96  // Check what type of results are avaialable
  97  require_once($CFG->dirroot.'/tag/coursetagslib.php');
  98  $courses = $courserenderer->tagged_courses($tag->id);
  99  
 100  if (!empty($CFG->enableblogs) && has_capability('moodle/blog:view', $systemcontext)) {
 101      require_once($CFG->dirroot.'/blog/lib.php');
 102      require_once($CFG->dirroot.'/blog/locallib.php');
 103  
 104      $bloglisting = new blog_listing(array('tag' => $tag->id));
 105      $limit = 10;
 106      $start = 0;
 107      $blogs = $bloglisting->get_entries($start, $limit);
 108  }
 109  $usercount = tag_record_count('user', $tag->id);
 110  
 111  // Only include <a href />'s to those anchors that actually will be shown
 112  $relatedpageslink = "";
 113  $countanchors = 0;
 114  if (!empty($courses)) {
 115      $relatedpageslink = '<a href="#course">'.get_string('courses').'</a>';
 116      $countanchors++;
 117  }
 118  if (!empty($blogs)) {
 119      if ($countanchors > 0) {
 120          $relatedpageslink .= ' | ';
 121      }
 122      $relatedpageslink .= '<a href="#blog">'.get_string('relatedblogs', 'tag').'</a>';
 123      $countanchors++;
 124  }
 125  if ($usercount > 0) {
 126      if ($countanchors > 0) {
 127          $relatedpageslink .= ' | ';
 128      }
 129      $relatedpageslink .= '<a href="#user">'.get_string('users').'</a>';
 130      $countanchors++;
 131  }
 132  // If only one anchor is present, no <a href /> is needed
 133  if ($countanchors == 0) {
 134      echo '<div class="relatedpages"><p>'.get_string('noresultsfor', 'tag', $tagname).'</p></div>';
 135  } elseif ($countanchors > 1) {
 136      echo '<div class="relatedpages"><p>'.$relatedpageslink.'</p></div>';
 137  }
 138  
 139  // Display courses tagged with the tag
 140  if (!empty($courses)) {
 141  
 142      echo $OUTPUT->box_start('generalbox', 'tag-blogs'); //could use an id separate from tag-blogs, but would have to copy the css style to make it look the same
 143  
 144      echo "<a name='course'></a>";
 145      echo $courses;
 146  
 147      echo $OUTPUT->box_end();
 148  }
 149  
 150  // Print up to 10 previous blogs entries
 151  
 152  if (!empty($blogs)) {
 153      echo $OUTPUT->box_start('generalbox', 'tag-blogs');
 154      $heading = get_string('relatedblogs', 'tag', $tagname). ' ' . get_string('taggedwith', 'tag', $tagname);
 155      echo "<a name='blog'></a>";
 156      echo $OUTPUT->heading($heading, 3);
 157  
 158      echo '<ul id="tagblogentries">';
 159      foreach ($blogs as $blog) {
 160          if ($blog->publishstate == 'draft') {
 161              $class = 'class="dimmed"';
 162          } else {
 163              $class = '';
 164          }
 165          echo '<li '.$class.'>';
 166          echo '<a '.$class.' href="'.$CFG->wwwroot.'/blog/index.php?entryid='.$blog->id.'">';
 167          echo format_string($blog->subject);
 168          echo '</a>';
 169          echo ' - ';
 170          echo '<a '.$class.' href="'.$CFG->wwwroot.'/user/view.php?id='.$blog->userid.'">';
 171          echo fullname($blog);
 172          echo '</a>';
 173          echo ', '. userdate($blog->lastmodified);
 174          echo '</li>';
 175      }
 176      echo '</ul>';
 177  
 178      $allblogsurl = new moodle_url('/blog/index.php', array('tagid' => $tag->id));
 179      echo '<p class="moreblogs"><a href="'.$allblogsurl->out().'">'.get_string('seeallblogs', 'tag', $tagname).'</a></p>';
 180  
 181      echo $OUTPUT->box_end();
 182  }
 183  
 184  if ($usercount > 0) {
 185  
 186      //user table box
 187      echo $OUTPUT->box_start('generalbox', 'tag-user-table');
 188  
 189      $heading = get_string('users'). ' ' . get_string('taggedwith', 'tag', $tagname) . ': ' . $usercount;
 190      echo "<a name='user'></a>";
 191      echo $OUTPUT->heading($heading, 3);
 192  
 193      $baseurl = new moodle_url('/tag/index.php', array('id' => $tag->id));
 194      $pagingbar = new paging_bar($usercount, $userpage, $perpage, $baseurl);
 195      $pagingbar->pagevar = 'userpage';
 196      echo $OUTPUT->render($pagingbar);
 197      tag_print_tagged_users_table($tag, $userpage * $perpage, $perpage);
 198      echo $OUTPUT->box_end();
 199  }
 200  
 201  echo $OUTPUT->footer();


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