moodle/admin/tool/lp/plans.php
Frederic Massart 5159d6794b MDL-51965 tool_lp: Revisit capabilities to read/manage plans
Templates can no longer be linked to the plan via the plan editing
page because we will need to handle plan linking/unlinking directly.
2016-04-18 10:58:37 +08:00

61 lines
2 KiB
PHP

<?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 page lets users see their learning plans.
*
* @package tool_lp
* @copyright 2015 David Monllao
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../../config.php');
require_login(null, false);
if (isguestuser()) {
throw new require_login_exception('Guests are not allowed here.');
}
$userid = optional_param('userid', $USER->id, PARAM_INT);
// Check that the user is a valid user.
$user = core_user::get_user($userid);
if (!$user || !core_user::is_real_user($userid)) {
throw new moodle_exception('invaliduser', 'error');
}
$context = context_user::instance($userid);
if (!\tool_lp\plan::can_read_user($userid) && !\tool_lp\plan::can_read_user_draft($userid)) {
throw new required_capability_exception($context, 'tool/lp:planview', 'nopermissions', '');
}
$url = new moodle_url('/admin/tool/lp/plans.php', array('userid' => $userid));
$title = get_string('learningplans', 'tool_lp');
$PAGE->set_context($context);
$PAGE->set_pagelayout('admin');
$PAGE->set_url($url);
$PAGE->set_title($title);
$PAGE->set_heading($title);
$output = $PAGE->get_renderer('tool_lp');
echo $output->header();
echo $output->heading($title);
$page = new \tool_lp\output\plans_page($userid);
echo $output->render($page);
echo $output->footer();