/** * Renders the tag search page * * @param string $query * @param int $tagcollid * @return string */ public function tag_search_page($query = '', $tagcollid = 0) { $rv = $this->output->heading(get_string('searchtags', 'tag'), 2); $searchbox = $this->search_form($query, $tagcollid); $rv .= html_writer::div($searchbox, '', array('id' => 'tag-search-box')); $tagcloud = core_tag_collection::get_tag_cloud($tagcollid, '', 150, 'name', $query); $searchresults = ''; if ($tagcloud->get_count()) { $searchresults = $this->output->render_from_template('core_tag/tagcloud', $tagcloud->export_for_template($this->output)); $rv .= html_writer::div($searchresults, '', array('id' => 'tag-search-results')); } else { if (strval($query) !== '') { $rv .= '<div class="tag-search-empty">' . get_string('notagsfound', 'tag', s($query)) . '</div>'; } } return $rv; }
/** * Prints or returns a HTML tag cloud with varying classes styles depending on the popularity and type of each tag. * * @deprecated since 3.1 * * @param array $tagset Array of tags to display * @param int $nr_of_tags Limit for the number of tags to return/display, used if $tagset is null * @param bool $return if true the function will return the generated tag cloud instead of displaying it. * @param string $sort (optional) selected sorting, default is alpha sort (name) also timemodified or popularity * @return string|null a HTML string or null if this function does the output */ function tag_print_cloud($tagset = null, $nr_of_tags = 150, $return = false, $sort = '') { global $OUTPUT; debugging('Function tag_print_cloud() is deprecated and replaced with function core_tag_collection::get_tag_cloud(), ' . 'templateable core_tag\\output\\tagcloud and template core_tag/tagcloud.', DEBUG_DEVELOPER); // Set up sort global - used to pass sort type into core_tag_collection::cloud_sort through usort() avoiding multiple sort functions. if ($sort == 'popularity') { $sort = 'count'; } else { if ($sort == 'date') { $sort = 'timemodified'; } else { $sort = 'name'; } } if (is_null($tagset)) { // No tag set received, so fetch tags from database. // Always add query by tagcollid even when it's not known to make use of the table index. $tagcloud = core_tag_collection::get_tag_cloud(0, false, $nr_of_tags, $sort); } else { $tagsincloud = $tagset; $etags = array(); foreach ($tagsincloud as $tag) { $etags[] = $tag; } core_tag_collection::$cloudsortfield = $sort; usort($tagsincloud, "core_tag_collection::cloud_sort"); $tagcloud = new \core_tag\output\tagcloud($tagsincloud); } $output = $OUTPUT->render_from_template('core_tag/tagcloud', $tagcloud->export_for_template($OUTPUT)); if ($return) { return $output; } else { echo $output; } }
public function get_content() { global $CFG, $COURSE, $USER, $SCRIPT, $OUTPUT; if (empty($CFG->usetags)) { $this->content = new stdClass(); $this->content->text = ''; if ($this->page->user_is_editing()) { $this->content->text = get_string('disabledtags', 'block_tags'); } return $this->content; } if (!isset($this->config)) { $this->config = new stdClass(); } if (empty($this->config->numberoftags)) { $this->config->numberoftags = 80; } if (empty($this->config->showstandard)) { $this->config->showstandard = core_tag_tag::BOTH_STANDARD_AND_NOT; } if (empty($this->config->ctx)) { $this->config->ctx = 0; } if (empty($this->config->rec)) { $this->config->rec = 1; } if (empty($this->config->tagcoll)) { $this->config->tagcoll = 0; } if ($this->content !== NULL) { return $this->content; } if (empty($this->instance)) { $this->content = ''; return $this->content; } $this->content = new stdClass(); $this->content->text = ''; $this->content->footer = ''; // Get a list of tags. $tagcloud = core_tag_collection::get_tag_cloud($this->config->tagcoll, $this->config->showstandard == core_tag_tag::STANDARD_ONLY, $this->config->numberoftags, 'name', '', $this->page->context->id, $this->config->ctx, $this->config->rec); $this->content->text = $OUTPUT->render_from_template('core_tag/tagcloud', $tagcloud->export_for_template($OUTPUT)); return $this->content; }