Exemple #1
0
 public function test_guess_tag()
 {
     global $DB;
     $user = $this->getDataGenerator()->create_user();
     $this->setUser($user);
     $tag1 = $this->getDataGenerator()->create_tag(array('name' => 'Cat'));
     $tc = core_tag_collection::create((object) array('name' => 'tagcoll'));
     $tag2 = $this->getDataGenerator()->create_tag(array('name' => 'Cat', 'tagcollid' => $tc->id));
     $this->assertEquals(2, count($DB->get_records('tag')));
     $this->assertEquals(2, count(core_tag_tag::guess_by_name('Cat')));
     $this->assertEquals(core_tag_collection::get_default(), core_tag_tag::get_by_name(0, 'Cat')->tagcollid);
 }
Exemple #2
0
require_once 'edit_form.php';
$tagid = optional_param('id', 0, PARAM_INT);
$tagname = optional_param('tag', '', PARAM_TAG);
$returnurl = optional_param('returnurl', '', PARAM_LOCALURL);
require_login();
if (empty($CFG->usetags)) {
    print_error('tagsaredisabled', 'tag');
}
//Editing a tag requires moodle/tag:edit capability
$systemcontext = context_system::instance();
require_capability('moodle/tag:edit', $systemcontext);
if ($tagname) {
    $tagcollid = optional_param('tc', 0, PARAM_INT);
    if (!$tagcollid) {
        // Tag name specified but tag collection was not. Try to guess it.
        $tags = core_tag_tag::guess_by_name($tagname, '*');
        if (count($tags) > 1) {
            // This tag was found in more than one collection, redirect to search.
            redirect(new moodle_url('/tag/search.php', array('tag' => $tagname)));
        } else {
            if (count($tags) == 1) {
                $tag = reset($tags);
            }
        }
    } else {
        if (!($tag = core_tag_tag::get_by_name($tagcollid, $tagname, '*'))) {
            redirect(new moodle_url('/tag/search.php', array('tagcollid' => $tagcollid)));
        }
    }
} else {
    if ($tagid) {