Exemplo n.º 1
0
 /**
  * Constructor
  *
  * @param core_tag_tag|stdClass $tag
  * @param string $component
  * @param string $itemtype
  * @param string $content
  * @param bool $exclusivemode
  * @param int $fromctx context id where the link was displayed, may be used by callbacks
  *            to display items in the same context first
  * @param int $ctx context id where we need to search for items
  * @param int $rec search items in sub contexts as well
  * @param int $page
  * @param bool $totalpages
  */
 public function __construct($tag, $component, $itemtype, $content, $exclusivemode = false, $fromctx = 0, $ctx = 0, $rec = 1, $page = 0, $totalpages = 1)
 {
     $this->record = new stdClass();
     $this->tag = $tag;
     $tagareas = \core_tag_area::get_areas();
     if (!isset($tagareas[$itemtype][$component])) {
         throw new \coding_exception('Tag area for component ' . $component . ' and itemtype ' . $itemtype . ' is not defined');
     }
     $this->tagarea = $tagareas[$itemtype][$component];
     $this->record->tagid = $tag->id;
     $this->record->ta = $this->tagarea->id;
     $this->record->itemtype = $itemtype;
     $this->record->component = $component;
     $a = (object) array('tagarea' => \core_tag_area::display_name($component, $itemtype), 'tag' => \core_tag_tag::make_display_name($tag));
     if ($exclusivemode) {
         $this->record->title = get_string('itemstaggedwith', 'tag', $a);
     } else {
         $this->record->title = (string) $a->tagarea;
     }
     $this->record->content = $content;
     $this->record->nextpageurl = null;
     $this->record->prevpageurl = null;
     $this->record->exclusiveurl = null;
     $url = core_tag_tag::make_url($tag->tagcollid, $tag->rawname, $exclusivemode, $fromctx, $ctx, $rec);
     $urlparams = array('ta' => $this->tagarea->id);
     if ($totalpages > $page + 1) {
         $this->record->nextpageurl = new moodle_url($url, $urlparams + array('page' => $page + 1));
     }
     if ($page > 0) {
         $this->record->prevpageurl = new moodle_url($url, $urlparams + array('page' => $page - 1));
     }
     if (!$exclusivemode && ($totalpages > 1 || $page)) {
         $this->record->exclusiveurl = new moodle_url($url, $urlparams + array('excl' => 1));
     }
     $this->record->exclusivetext = get_string('exclusivemode', 'tag', $a);
     $this->record->hascontent = $totalpages > 1 || $page || $content;
     $this->record->anchor = $component . '_' . $itemtype;
 }
Exemplo n.º 2
0
/**
 * Get a comma-separated list of tags related to another tag.
 *
 * @package  core_tag
 * @deprecated since 3.1
 * @param    array    $related_tags the array returned by tag_get_related_tags
 * @param    int      $html    either TAG_RETURN_HTML (default) or TAG_RETURN_TEXT : return html links, or just text.
 * @return   string   comma-separated list
 */
function tag_get_related_tags_csv($related_tags, $html = TAG_RETURN_HTML)
{
    global $OUTPUT;
    debugging('Method tag_get_related_tags_csv() is deprecated. Consider ' . 'looping through array or using $OUTPUT->tag_list(core_tag_tag::get_item_tags())', DEBUG_DEVELOPER);
    if ($html != TAG_RETURN_TEXT) {
        return $OUTPUT->tag_list($related_tags, '');
    }
    $tagsnames = array();
    foreach ($related_tags as $tag) {
        $tagsnames[] = core_tag_tag::make_display_name($tag, false);
    }
    return implode(', ', $tagsnames);
}
Exemplo n.º 3
0
 function get_content()
 {
     global $CFG, $SITE, $USER, $DB, $OUTPUT;
     if ($this->content !== NULL) {
         return $this->content;
     }
     // make sure blog and tags are actually enabled
     if (empty($CFG->bloglevel)) {
         $this->content = new stdClass();
         $this->content->text = '';
         if ($this->page->user_is_editing()) {
             $this->content->text = get_string('blogdisable', 'blog');
         }
         return $this->content;
     } else {
         if (!core_tag_tag::is_enabled('core', 'post')) {
             $this->content = new stdClass();
             $this->content->text = '';
             if ($this->page->user_is_editing()) {
                 $this->content->text = get_string('tagsaredisabled', 'tag');
             }
             return $this->content;
         } else {
             if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL and (!isloggedin() or isguestuser())) {
                 $this->content = new stdClass();
                 $this->content->text = '';
                 return $this->content;
             }
         }
     }
     // require the libs and do the work
     require_once $CFG->dirroot . '/blog/lib.php';
     if (empty($this->config)) {
         $this->config = new stdClass();
     }
     if (empty($this->config->timewithin)) {
         $this->config->timewithin = BLOCK_BLOG_TAGS_DEFAULTTIMEWITHIN;
     }
     if (empty($this->config->numberoftags)) {
         $this->config->numberoftags = BLOCK_BLOG_TAGS_DEFAULTNUMBEROFTAGS;
     }
     if (empty($this->config->sort)) {
         $this->config->sort = BLOCK_BLOG_TAGS_DEFAULTSORT;
     }
     $this->content = new stdClass();
     $this->content->text = '';
     $this->content->footer = '';
     /// Get a list of tags
     $timewithin = time() - $this->config->timewithin * 24 * 60 * 60;
     /// convert to seconds
     $context = $this->page->context;
     // admins should be able to read all tags
     $type = '';
     if (!has_capability('moodle/user:readuserblogs', context_system::instance())) {
         $type = " AND (p.publishstate = 'site' or p.publishstate='public')";
     }
     $sql = "SELECT t.id, t.isstandard, t.rawname, t.name, COUNT(DISTINCT ti.id) AS ct\n                   FROM {tag} t, {tag_instance} ti, {post} p, {blog_association} ba\n                  WHERE t.id = ti.tagid AND p.id = ti.itemid\n                        {$type}\n                        AND ti.itemtype = 'post'\n                        AND ti.component = 'core'\n                        AND ti.timemodified > {$timewithin}";
     if ($context->contextlevel == CONTEXT_MODULE) {
         $sql .= " AND ba.contextid = {$context->id} AND p.id = ba.blogid ";
     } else {
         if ($context->contextlevel == CONTEXT_COURSE) {
             $sql .= " AND ba.contextid = {$context->id} AND p.id = ba.blogid ";
         }
     }
     $sql .= "\n               GROUP BY t.id, t.isstandard, t.name, t.rawname\n               ORDER BY ct DESC, t.name ASC";
     if ($tags = $DB->get_records_sql($sql, null, 0, $this->config->numberoftags)) {
         /// There are 2 things to do:
         /// 1. tags with the same count should have the same size class
         /// 2. however many tags we have should be spread evenly over the
         ///    20 size classes
         $totaltags = count($tags);
         $currenttag = 0;
         $size = 20;
         $lasttagct = -1;
         $etags = array();
         foreach ($tags as $tag) {
             $currenttag++;
             if ($currenttag == 1) {
                 $lasttagct = $tag->ct;
                 $size = 20;
             } else {
                 if ($tag->ct != $lasttagct) {
                     $lasttagct = $tag->ct;
                     $size = 20 - (int) (($currenttag - 1) / $totaltags * 20);
                 }
             }
             $tag->class = ($tag->isstandard ? "standardtag " : "") . "s{$size}";
             $etags[] = $tag;
         }
         /// Now we sort the tag display order
         $CFG->tagsort = $this->config->sort;
         usort($etags, "block_blog_tags_sort");
         /// Finally we create the output
         /// Accessibility: markup as a list.
         $this->content->text .= "\n<ul class='inline-list'>\n";
         foreach ($etags as $tag) {
             $blogurl = new moodle_url('/blog/index.php');
             switch ($CFG->bloglevel) {
                 case BLOG_USER_LEVEL:
                     $blogurl->param('userid', $USER->id);
                     break;
                 default:
                     if ($context->contextlevel == CONTEXT_MODULE) {
                         $blogurl->param('modid', $context->instanceid);
                     } else {
                         if ($context->contextlevel == CONTEXT_COURSE) {
                             $blogurl->param('courseid', $context->instanceid);
                         }
                     }
                     break;
             }
             $blogurl->param('tagid', $tag->id);
             $link = html_writer::link($blogurl, core_tag_tag::make_display_name($tag), array('class' => $tag->class, 'title' => get_string('numberofentries', 'blog', $tag->ct)));
             $this->content->text .= '<li>' . $link . '</li> ';
         }
         $this->content->text .= "\n</ul>\n";
     }
     return $this->content;
 }