Example #1
0
if (isguestuser()) {
    print_error('noguest');
}
if (!confirm_sesskey()) {
    print_error('sesskey');
}
switch ($action) {
    case 'addinterest':
        if (empty($tag) && $id) {
            // for backward-compatibility (people saving bookmarks, mostly..)
            $tag = tag_get_name($id);
        }
        tag_set_add('user', $USER->id, $tag);
        redirect($CFG->wwwroot . '/tag/index.php?tag=' . rawurlencode($tag));
        break;
    case 'removeinterest':
        if (empty($tag) && $id) {
            // for backward-compatibility (people saving bookmarks, mostly..)
            $tag = tag_get_name($id);
        }
        tag_set_delete('user', $USER->id, $tag);
        redirect($CFG->wwwroot . '/tag/index.php?tag=' . rawurlencode($tag));
        break;
    case 'flaginappropriate':
        tag_set_flag(tag_get_id($tag));
        redirect($CFG->wwwroot . '/tag/index.php?tag=' . rawurlencode($tag), get_string('responsiblewillbenotified', 'tag'));
        break;
    default:
        print_error('unknowaction');
        break;
}
 /**
  * Test the tag unflagged event.
  */
 public function test_tag_unflagged()
 {
     global $DB;
     $this->setAdminUser();
     // Create tags we are going to unflag.
     $tag = $this->getDataGenerator()->create_tag();
     $tag2 = $this->getDataGenerator()->create_tag();
     // Flag it.
     tag_set_flag($tag->id);
     // Trigger and capture the event for unsetting the flag of a tag.
     $sink = $this->redirectEvents();
     tag_unset_flag($tag->id);
     $events = $sink->get_events();
     $event = reset($events);
     // Check that the flag was updated.
     $tag = $DB->get_record('tag', array('id' => $tag->id));
     $this->assertEquals(0, $tag->flag);
     // Check that the event data is valid.
     $this->assertInstanceOf('\\core\\event\\tag_unflagged', $event);
     $this->assertEquals(context_system::instance(), $event->get_context());
     // Set the flag back for both.
     tag_set_flag(array($tag->id, $tag2->id));
     // Trigger and capture the event for unsetting the flag for multiple tags.
     $sink = $this->redirectEvents();
     tag_unset_flag(array($tag->id, $tag2->id));
     $events = $sink->get_events();
     // Check that the flags were updated.
     $tag = $DB->get_record('tag', array('id' => $tag->id));
     $this->assertEquals(0, $tag->flag);
     $tag2 = $DB->get_record('tag', array('id' => $tag2->id));
     $this->assertEquals(0, $tag2->flag);
     // Confirm the events.
     $event = $events[0];
     $this->assertInstanceOf('\\core\\event\\tag_unflagged', $event);
     $this->assertEquals(context_system::instance(), $event->get_context());
     $event = $events[1];
     $this->assertInstanceOf('\\core\\event\\tag_unflagged', $event);
     $this->assertEquals(context_system::instance(), $event->get_context());
 }
Example #3
0
    print_error('sesskey');
}
switch ($action) {
    case 'addinterest':
        if (empty($tag) && $id) {
            // for backward-compatibility (people saving bookmarks, mostly..)
            $tag = tag_get_name($id);
        }
        tag_set_add('user', $USER->id, $tag);
        redirect($CFG->wwwroot . '/tag/index.php?tag=' . rawurlencode($tag));
        break;
    case 'removeinterest':
        if (empty($tag) && $id) {
            // for backward-compatibility (people saving bookmarks, mostly..)
            $tag = tag_get_name($id);
        }
        tag_set_delete('user', $USER->id, $tag);
        redirect($CFG->wwwroot . '/tag/index.php?tag=' . rawurlencode($tag));
        break;
    case 'flaginappropriate':
        require_capability('moodle/tag:flag', context_system::instance());
        $tagid = tag_get_id($tag);
        // Add flaging action to logs
        add_to_log(SITEID, 'tag', 'flag', 'index.php?id=' . $tagid, $tagid, '', $USER->id);
        tag_set_flag($tagid);
        redirect($CFG->wwwroot . '/tag/index.php?tag=' . rawurlencode($tag), get_string('responsiblewillbenotified', 'tag'));
        break;
    default:
        print_error('unknowaction');
        break;
}