Exemplo n.º 1
0
 /**
  * Export this data so it can be used as the context for a mustache template.
  *
  * @param renderer_base $output
  * @return stdClass
  */
 public function export_for_template(renderer_base $output)
 {
     global $CFG;
     require_once $CFG->libdir . '/externallib.php';
     $r = new stdClass();
     $r->id = (int) $this->record->id;
     $r->tagcollid = clean_param($this->record->tagcollid, PARAM_INT);
     $r->rawname = clean_param($this->record->rawname, PARAM_TAG);
     $r->name = clean_param($this->record->name, PARAM_TAG);
     $format = clean_param($this->record->descriptionformat, PARAM_INT);
     list($r->description, $r->descriptionformat) = external_format_text($this->record->description, $format, \context_system::instance()->id, 'core', 'tag', $r->id);
     $r->flag = clean_param($this->record->flag, PARAM_INT);
     if (isset($this->record->official)) {
         $r->official = clean_param($this->record->official, PARAM_INT);
     } else {
         $r->official = $this->record->tagtype === 'official' ? 1 : 0;
     }
     $url = \core_tag_tag::make_url($r->tagcollid, $r->rawname);
     $r->viewurl = $url->out(false);
     $manageurl = new moodle_url('/tag/manage.php', array('sesskey' => sesskey(), 'tagid' => $this->record->id));
     $url = new moodle_url($manageurl);
     $url->param('action', 'changetype');
     $url->param('tagtype', $r->official ? 'default' : 'official');
     $r->changetypeurl = $url->out(false);
     $url = new moodle_url($manageurl);
     $url->param('action', $this->record->flag ? 'resetflag' : 'setflag');
     $r->changeflagurl = $url->out(false);
     return $r;
 }
Exemplo n.º 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;
    }
}
Exemplo n.º 3
0
$usercontext = context_user::instance($USER->id);
switch ($action) {
    case 'addinterest':
        if (!core_tag_tag::is_enabled('core', 'user')) {
            print_error('tagdisabled');
        }
        $tag = required_param('tag', PARAM_TAG);
        core_tag_tag::add_item_tag('core', 'user', $USER->id, $usercontext, $tag);
        $tc = core_tag_area::get_collection('core', 'user');
        redirect(core_tag_tag::make_url($tc, $tag));
        break;
    case 'removeinterest':
        if (!core_tag_tag::is_enabled('core', 'user')) {
            print_error('tagdisabled');
        }
        $tag = required_param('tag', PARAM_TAG);
        core_tag_tag::remove_item_tag('core', 'user', $USER->id, $tag);
        $tc = core_tag_area::get_collection('core', 'user');
        redirect(core_tag_tag::make_url($tc, $tag));
        break;
    case 'flaginappropriate':
        require_capability('moodle/tag:flag', context_system::instance());
        $id = required_param('id', PARAM_INT);
        $tagobject = core_tag_tag::get($id, '*', MUST_EXIST);
        $tagobject->flag();
        redirect($tagobject->get_view_url(), get_string('responsiblewillbenotified', 'tag'));
        break;
    default:
        print_error('unknowaction');
        break;
}