/**
 * Prints the tag search results
 *
 * @param string $query text that tag names will be matched against
 * @param int $page current page
 * @param int $perpage nr of users displayed per page
 * @param $return if true return html string
 */
function tag_print_search_results($query, $page, $perpage, $return = false)
{
    global $CFG, $USER;
    $query = array_shift(tag_normalize($query, TAG_CASE_ORIGINAL));
    $count = sizeof(tag_find_tags($query, false));
    $tags = array();
    if ($found_tags = tag_find_tags($query, true, $page * $perpage, $perpage)) {
        $tags = array_values($found_tags);
    }
    $baseurl = $CFG->wwwroot . '/tag/search.php?query=' . rawurlencode($query);
    $output = '';
    // link "Add $query to my interests"
    $addtaglink = '';
    if (!tag_record_tagged_with('user', $USER->id, $query)) {
        $addtaglink = '<a href="' . $CFG->wwwroot . '/tag/user.php?action=addinterest&amp;sesskey=' . sesskey() . '&amp;tag=' . rawurlencode($query) . '">';
        $addtaglink .= get_string('addtagtomyinterests', 'tag', htmlspecialchars($query)) . '</a>';
    }
    if (!empty($tags)) {
        // there are results to display!!
        $output .= print_heading(get_string('searchresultsfor', 'tag', htmlspecialchars($query)) . " : {$count}", '', 3, 'main', true);
        //print a link "Add $query to my interests"
        if (!empty($addtaglink)) {
            $output .= print_box($addtaglink, 'box', 'tag-management-box', true);
        }
        $nr_of_lis_per_ul = 6;
        $nr_of_uls = ceil(sizeof($tags) / $nr_of_lis_per_ul);
        $output .= '<ul id="tag-search-results">';
        for ($i = 0; $i < $nr_of_uls; $i++) {
            $output .= '<li>';
            foreach (array_slice($tags, $i * $nr_of_lis_per_ul, $nr_of_lis_per_ul) as $tag) {
                $tag_link = ' <a href="' . $CFG->wwwroot . '/tag/index.php?id=' . $tag->id . '">' . tag_display_name($tag) . '</a>';
                $output .= '&#8226;' . $tag_link . '<br/>';
            }
            $output .= '</li>';
        }
        $output .= '</ul>';
        $output .= '<div>&nbsp;</div>';
        // <-- small layout hack in order to look good in Firefox
        $output .= print_paging_bar($count, $page, $perpage, $baseurl . '&amp;', 'page', false, true);
    } else {
        //no results were found!!
        $output .= print_heading(get_string('noresultsfor', 'tag', htmlspecialchars($query)), '', 3, 'main', true);
        //print a link "Add $query to my interests"
        if (!empty($addtaglink)) {
            $output .= print_box($addtaglink, 'box', 'tag-management-box', true);
        }
    }
    if ($return) {
        return $output;
    } else {
        echo $output;
    }
}
Beispiel #2
0
/**
 * Prints the tag search results
 *
 * @deprecated since 3.1
 * @param string       $query text that tag names will be matched against
 * @param int          $page current page
 * @param int          $perpage nr of users displayed per page
 * @param bool         $return if true return html string
 * @return string|null a HTML string or null if this function does the output
 */
function tag_print_search_results($query, $page, $perpage, $return = false)
{
    global $CFG, $USER, $OUTPUT;
    debugging('Function tag_print_search_results() is deprecated without replacement. ' . 'In /tag/search.php the search results are printed using the core_tag/tagcloud template.', DEBUG_DEVELOPER);
    $query = clean_param($query, PARAM_TAG);
    $count = count(tag_find_tags($query, false));
    $tags = array();
    if ($found_tags = tag_find_tags($query, true, $page * $perpage, $perpage)) {
        $tags = array_values($found_tags);
    }
    $baseurl = $CFG->wwwroot . '/tag/search.php?query=' . rawurlencode($query);
    $output = '';
    // link "Add $query to my interests"
    $addtaglink = '';
    if (core_tag_tag::is_enabled('core', 'user') && !core_tag_tag::is_item_tagged_with('core', 'user', $USER->id, $query)) {
        $addtaglink = html_writer::link(new moodle_url('/tag/user.php', array('action' => 'addinterest', 'sesskey' => sesskey(), 'tag' => $query)), get_string('addtagtomyinterests', 'tag', s($query)));
    }
    if (!empty($tags)) {
        // there are results to display!!
        $output .= $OUTPUT->heading(get_string('searchresultsfor', 'tag', htmlspecialchars($query)) . " : {$count}", 3, 'main');
        //print a link "Add $query to my interests"
        if (!empty($addtaglink)) {
            $output .= $OUTPUT->box($addtaglink, 'box', 'tag-management-box');
        }
        $nr_of_lis_per_ul = 6;
        $nr_of_uls = ceil(sizeof($tags) / $nr_of_lis_per_ul);
        $output .= '<ul id="tag-search-results">';
        for ($i = 0; $i < $nr_of_uls; $i++) {
            foreach (array_slice($tags, $i * $nr_of_lis_per_ul, $nr_of_lis_per_ul) as $tag) {
                $output .= '<li>';
                $tag_link = html_writer::link(core_tag_tag::make_url($tag->tagcollid, $tag->rawname), core_tag_tag::make_display_name($tag));
                $output .= $tag_link;
                $output .= '</li>';
            }
        }
        $output .= '</ul>';
        $output .= '<div>&nbsp;</div>';
        // <-- small layout hack in order to look good in Firefox
        $output .= $OUTPUT->paging_bar($count, $page, $perpage, $baseurl);
    } else {
        //no results were found!!
        $output .= $OUTPUT->heading(get_string('noresultsfor', 'tag', htmlspecialchars($query)), 3, 'main');
        //print a link "Add $query to my interests"
        if (!empty($addtaglink)) {
            $output .= $OUTPUT->box($addtaglink, 'box', 'tag-management-box');
        }
    }
    if ($return) {
        return $output;
    } else {
        echo $output;
    }
}