-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfollow.php
44 lines (38 loc) · 1.56 KB
/
follow.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This block generates a simple list of links based on the users profile.
*
* @package block_links
* @copyright 2016 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../../config.php');
require_once($CFG->dirroot.'/blocks/links/lib.php');
$id = required_param('id', PARAM_INT);
$record = $DB->get_record('block_links', array('id' => $id), '*', MUST_EXIST);
require_login();
// Verify link is actually available, and user can follow it.
if (block_links_check_permissions($record)) {
$context = context_system::instance();
$params = array('context' => $context, 'objectid' => $id);
$event = \block_links\event\link_followed::create($params);
$event->trigger();
redirect($record->url);
} else {
// User has no access to this link. Print an error.
throw new moodle_exception('linkunavailable', 'block_links');
}