/** * Prints a box that contains the management links of a tag * * @deprecated since 3.1 * @param core_tag_tag|stdClass $tag_object * @param bool $return if true the function will return the generated tag cloud instead of displaying it. * @return string|null a HTML string or null if this function does the output */ function tag_print_management_box($tag_object, $return = false) { global $USER, $CFG, $OUTPUT; debugging('Function tag_print_description_box() is deprecated without replacement. ' . 'See core_tag_renderer for similar code.', DEBUG_DEVELOPER); $tagname = core_tag_tag::make_display_name($tag_object); $output = ''; if (!isguestuser()) { $output .= $OUTPUT->box_start('box', 'tag-management-box'); $systemcontext = context_system::instance(); $links = array(); // Add a link for users to add/remove this from their interests if (core_tag_tag::is_enabled('core', 'user') && core_tag_area::get_collection('core', 'user') == $tag_object->tagcollid) { if (core_tag_tag::is_item_tagged_with('core', 'user', $USER->id, $tag_object->name)) { $links[] = '<a href="' . $CFG->wwwroot . '/tag/user.php?action=removeinterest&sesskey=' . sesskey() . '&tag=' . rawurlencode($tag_object->name) . '">' . get_string('removetagfrommyinterests', 'tag', $tagname) . '</a>'; } else { $links[] = '<a href="' . $CFG->wwwroot . '/tag/user.php?action=addinterest&sesskey=' . sesskey() . '&tag=' . rawurlencode($tag_object->name) . '">' . get_string('addtagtomyinterests', 'tag', $tagname) . '</a>'; } } // Flag as inappropriate link. Only people with moodle/tag:flag capability. if (has_capability('moodle/tag:flag', $systemcontext)) { $links[] = '<a href="' . $CFG->wwwroot . '/tag/user.php?action=flaginappropriate&sesskey=' . sesskey() . '&id=' . $tag_object->id . '">' . get_string('flagasinappropriate', 'tag', rawurlencode($tagname)) . '</a>'; } // Edit tag: Only people with moodle/tag:edit capability who either have it as an interest or can manage tags if (has_capability('moodle/tag:edit', $systemcontext) || has_capability('moodle/tag:manage', $systemcontext)) { $links[] = '<a href="' . $CFG->wwwroot . '/tag/edit.php?id=' . $tag_object->id . '">' . get_string('edittag', 'tag') . '</a>'; } $output .= implode(' | ', $links); $output .= $OUTPUT->box_end(); } if ($return) { return $output; } else { echo $output; } }
$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; }
/** * Finds the tag collection to use for standard tag selector * * @return int */ protected function get_tag_collection() { if (empty($this->tagsoptions['tagcollid']) && (empty($this->tagsoptions['itemtype']) || empty($this->tagsoptions['component']))) { debugging('You need to specify \'itemtype\' and \'component\' of the tagged ' . 'area in the tags form element options', DEBUG_DEVELOPER); } if (!empty($this->tagsoptions['tagcollid'])) { return $this->tagsoptions['tagcollid']; } if ($this->tagsoptions['itemtype']) { $this->tagsoptions['tagcollid'] = core_tag_area::get_collection($this->tagsoptions['component'], $this->tagsoptions['itemtype']); } else { $this->tagsoptions['tagcollid'] = core_tag_collection::get_default(); } return $this->tagsoptions['tagcollid']; }
/** * Returns the list of tag links available for the current user (edit, flag, etc.) * * @return array */ public function get_links() { global $USER; $links = array(); if (!isloggedin() || isguestuser()) { return $links; } $tagname = $this->get_display_name(); $systemcontext = context_system::instance(); // Add a link for users to add/remove this from their interests. if (static::is_enabled('core', 'user') && core_tag_area::get_collection('core', 'user') == $this->tagcollid) { if (static::is_item_tagged_with('core', 'user', $USER->id, $this->name)) { $url = new moodle_url('/tag/user.php', array('action' => 'removeinterest', 'sesskey' => sesskey(), 'tag' => $this->rawname)); $links[] = html_writer::link($url, get_string('removetagfrommyinterests', 'tag', $tagname), array('class' => 'removefrommyinterests')); } else { $url = new moodle_url('/tag/user.php', array('action' => 'addinterest', 'sesskey' => sesskey(), 'tag' => $this->rawname)); $links[] = html_writer::link($url, get_string('addtagtomyinterests', 'tag', $tagname), array('class' => 'addtomyinterests')); } } // Flag as inappropriate link. Only people with moodle/tag:flag capability. if (has_capability('moodle/tag:flag', $systemcontext)) { $url = new moodle_url('/tag/user.php', array('action' => 'flaginappropriate', 'sesskey' => sesskey(), 'id' => $this->id)); $links[] = html_writer::link($url, get_string('flagasinappropriate', 'tag', $tagname), array('class' => 'flagasinappropriate')); } // Edit tag: Only people with moodle/tag:edit capability who either have it as an interest or can manage tags. if (has_capability('moodle/tag:edit', $systemcontext) || has_capability('moodle/tag:manage', $systemcontext)) { $url = new moodle_url('/tag/edit.php', array('id' => $this->id)); $links[] = html_writer::link($url, get_string('edittag', 'tag'), array('class' => 'edittag')); } return $links; }
/** * Test the tag created event. */ public function test_tag_created() { global $DB; // Trigger and capture the event for creating a tag. $sink = $this->redirectEvents(); core_tag_tag::create_if_missing(core_tag_area::get_collection('core', 'course'), array('A really awesome tag!')); $events = $sink->get_events(); $event = reset($events); // Check that the tag was created and the event data is valid. $this->assertEquals(1, $DB->count_records('tag')); $this->assertInstanceOf('\\core\\event\\tag_created', $event); $this->assertEquals(context_system::instance(), $event->get_context()); }