Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
namespace core\exception;
18
 
19
/**
20
 * Exceptions indicating user does not have permissions to do something
21
 * and the execution can not continue.
22
 *
23
 * @package    core
24
 * @subpackage exception
25
 * @copyright  2009 Petr Skoda  {@link http://skodak.org}
26
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 */
28
class required_capability_exception extends moodle_exception {
29
    /**
30
     * Constructor.
31
     *
32
     * @param \core\context $context The context used for the capability check
33
     * @param string $capability The required capability
34
     * @param string $errormessage The error message to show the user
35
     * @param string $stringfile
36
     */
37
    public function __construct($context, $capability, $errormessage, $stringfile) {
38
        $capabilityname = get_capability_string($capability);
39
        if ($context->contextlevel == CONTEXT_MODULE && preg_match('/:view$/', $capability)) {
40
            // Cannot redirect to mod/xx/view.php because we most probably do not have cap to view it.
41
            // Redirect to the course instead.
42
            $parentcontext = $context->get_parent_context();
43
            $link = $parentcontext->get_url();
44
        } else {
45
            $link = $context->get_url();
46
        }
47
        parent::__construct($errormessage, $stringfile, $link, $capabilityname);
48
    }
49
}
50
 
51
// Alias this class to the old name.
52
// This file will be autoloaded by the legacyclasses autoload system.
53
// In future all uses of this class will be corrected and the legacy references will be removed.
54
class_alias(required_capability_exception::class, \required_capability_exception::class);