Moodle release 4.3rc1
[moodle.git] / tag / user.php
blob50806ec1e6dcc4019c6164f99902f0fda762713d
1 <?php
3 require_once('../config.php');
4 require_once('lib.php');
6 $action = optional_param('action', '', PARAM_ALPHA);
8 require_login();
10 if (empty($CFG->usetags)) {
11 throw new \moodle_exception('tagdisabled');
14 if (isguestuser()) {
15 throw new \moodle_exception('noguest');
18 if (!confirm_sesskey()) {
19 throw new \moodle_exception('sesskey');
22 $usercontext = context_user::instance($USER->id);
24 switch ($action) {
25 case 'addinterest':
26 if (!core_tag_tag::is_enabled('core', 'user')) {
27 throw new \moodle_exception('tagdisabled');
29 $tag = required_param('tag', PARAM_TAG);
30 core_tag_tag::add_item_tag('core', 'user', $USER->id, $usercontext, $tag);
31 $tc = core_tag_area::get_collection('core', 'user');
32 redirect(core_tag_tag::make_url($tc, $tag));
33 break;
35 case 'removeinterest':
36 if (!core_tag_tag::is_enabled('core', 'user')) {
37 throw new \moodle_exception('tagdisabled');
39 $tag = required_param('tag', PARAM_TAG);
40 core_tag_tag::remove_item_tag('core', 'user', $USER->id, $tag);
41 $tc = core_tag_area::get_collection('core', 'user');
42 redirect(core_tag_tag::make_url($tc, $tag));
43 break;
45 case 'flaginappropriate':
46 require_capability('moodle/tag:flag', context_system::instance());
47 $id = required_param('id', PARAM_INT);
48 $tagobject = core_tag_tag::get($id, '*', MUST_EXIST);
49 $tagobject->flag();
50 redirect($tagobject->get_view_url(), get_string('responsiblewillbenotified', 'tag'));
51 break;
53 default:
54 throw new \moodle_exception('unknowaction');
55 break;