MDL-33552 - portfolio api E_STRICT fixes
[moodle.git] / lib / portfolio / exceptions.php
CommitLineData
87fcac8d 1<?php
93dd2725
RW
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
87fcac8d 17/**
87fcac8d 18 * This file contains all the portfolio exception classes.
93dd2725
RW
19 *
20 * @package core_portfolio
21 * @copyright 2008 Penny Leach <penny@catalyst.net.nz>, Martin Dougiamas
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
87fcac8d 23 */
24
0972665f
PS
25defined('MOODLE_INTERNAL') || die();
26
87fcac8d 27/**
93dd2725 28 * Top level portfolio exception.
18cdcdbf
SH
29 *
30 * Sometimes caught and re-thrown as portfolio_export_exception
31 * @see portfolio_export_exception
93dd2725
RW
32 *
33 * @package core_portfolio
34 * @category portfolio
35 * @copyright 2008 Penny Leach <penny@catalyst.net.nz>
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 */
87fcac8d 38class portfolio_exception extends moodle_exception {}
39
40/**
93dd2725
RW
41 * Exception to throw during an export - will clean up session and tempdata
42 *
43 * @package core_portfolio
44 * @category portfolio
45 * @copyright 2008 Penny Leach <penny@catalyst.net.nz>
46 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
47 */
87fcac8d 48class portfolio_export_exception extends portfolio_exception {
49
50 /**
93dd2725
RW
51 * Constructor.
52 *
53 * @param portfolio_exporter $exporter instance of portfolio_exporter (will handle null case)
54 * @param string $errorcode language string key
55 * @param string $module language string module (optional, defaults to moodle)
56 * @param string $continue url to continue to (optional, defaults to wwwroot)
57 * @param object $a language string data (optional, defaults to null)
58 */
87fcac8d 59 public function __construct($exporter, $errorcode, $module=null, $continue=null, $a=null) {
ea95cf9c 60 global $CFG;
bf81b168
SM
61 // This static variable is necessary because sometimes the code below
62 // which tries to obtain a continue link can cause one of these
63 // exceptions to be thrown. This would create an infinite loop (until
64 // PHP hits its stack limit). Using this static lets us make the
65 // nested constructor finish immediately without attempting to call
66 // methods that might fail.
67 static $inconstructor = false;
11e7b506 68
bf81b168
SM
69 if (!$inconstructor && !empty($exporter) &&
70 $exporter instanceof portfolio_exporter) {
71 $inconstructor = true;
72 try {
73 if (empty($continue)) {
74 $caller = $exporter->get('caller');
75 if (!empty($caller) && $caller instanceof portfolio_caller_base) {
76 $continue = $exporter->get('caller')->get_return_url();
77 }
87fcac8d 78 }
bf81b168
SM
79 // this was previously only called if we were in cron,
80 // but I think if there's always an exception, we should clean up
81 // rather than force the user to resolve the export later.
82 $exporter->process_stage_cleanup();
83 } catch(Exception $e) {
84 // Ooops, we had an exception trying to get caller
85 // information. Ignore it.
87fcac8d 86 }
bf81b168 87 $inconstructor = false;
87fcac8d 88 }
89 parent::__construct($errorcode, $module, $continue, $a);
90 }
91}
92
93/**
93dd2725 94 * Exception for callers to throw when they have a problem.
18cdcdbf
SH
95 *
96 * Usually caught and rethrown as portfolio_export_exception
97 * @see portfolio_export_exception
93dd2725
RW
98 *
99 * @package core_portfolio
100 * @category portfolio
101 * @copyright 2008 Penny Leach <penny@catalyst.net.nz>
102 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
103 */
87fcac8d 104class portfolio_caller_exception extends portfolio_exception {}
105
106/**
93dd2725 107 * Exception for portfolio plugins to throw when they have a problem.
18cdcdbf
SH
108 *
109 * Usually caught and rethrown as portfolio_export_exception
110 * @see portfolio_export_exception
93dd2725
RW
111 *
112 * @package core_portfolio
113 * @category portfolio
114 * @copyright 2008 Penny Leach <penny@catalyst.net.nz>
115 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
116 */
87fcac8d 117class portfolio_plugin_exception extends portfolio_exception {}
118
ce09fecc 119/**
93dd2725
RW
120 * Exception for interacting with the button class
121 *
122 * @package core_portfolio
123 * @category portfolio
124 * @copyright 2008 Penny Leach <penny@catalyst.net.nz>
125 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
126 */
ce09fecc 127class portfolio_button_exception extends portfolio_exception {}
59dd457e
PL
128
129/**
93dd2725
RW
130 * Leap2a exception - for invalid api calls
131 *
132 * @package core_portfolio
133 * @category portfolio
134 * @copyright 2008 Penny Leach <penny@catalyst.net.nz>
135 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
59dd457e
PL
136 */
137class portfolio_format_leap2a_exception extends portfolio_exception {}