2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Import models tool frontend.
20 * @package tool_analytics
21 * @copyright 2017 onwards Ankit Agarwal
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once(__DIR__
. '/../../../config.php');
28 \core_analytics\manager
::check_can_manage_models();
30 if (!\core_analytics\manager
::is_analytics_enabled()) {
31 $PAGE->set_context(\context_system
::instance());
32 $renderer = $PAGE->get_renderer('tool_analytics');
33 echo $renderer->render_analytics_disabled();
37 $returnurl = new \
moodle_url('/admin/tool/analytics/index.php');
38 $url = new \
moodle_url('/admin/tool/analytics/importmodel.php');
39 $title = get_string('importmodel', 'tool_analytics');
41 \tool_analytics\output\helper
::set_navbar($title, $url);
43 $form = new \tool_analytics\output\form\
import_model();
44 if ($form->is_cancelled()) {
46 } else if ($data = $form->get_data()) {
48 $modelconfig = new \core_analytics\
model_config();
50 $zipfilepath = $form->save_temp_file('modelfile');
52 list ($modeldata, $unused) = $modelconfig->extract_import_contents($zipfilepath);
54 if ($error = $modelconfig->check_dependencies($modeldata, $data->ignoreversionmismatches
)) {
55 // The file is not available until the form is validated so we need an alternative method to show errors.
56 redirect($url, $error, 0, \core\output\notification
::NOTIFY_ERROR
);
58 \core_analytics\model
::import_model($zipfilepath);
60 redirect($returnurl, get_string('importedsuccessfully', 'tool_analytics'), 0,
61 \core\output\notification
::NOTIFY_SUCCESS
);
64 echo $OUTPUT->header();
66 echo $OUTPUT->footer();