Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
/**
18
 * Import models tool frontend.
19
 *
20
 * @package tool_analytics
21
 * @copyright 2017 onwards Ankit Agarwal
22
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
require_once(__DIR__ . '/../../../config.php');
26
 
27
require_login();
28
\core_analytics\manager::check_can_manage_models();
29
 
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();
34
    exit(0);
35
}
36
 
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');
40
 
41
\tool_analytics\output\helper::set_navbar($title, $url);
42
 
43
$form = new \tool_analytics\output\form\import_model();
44
if ($form->is_cancelled()) {
45
    redirect($returnurl);
46
} else if ($data = $form->get_data()) {
47
 
48
    $modelconfig = new \core_analytics\model_config();
49
 
50
    $zipfilepath = $form->save_temp_file('modelfile');
51
 
52
    list ($modeldata, $unused) = $modelconfig->extract_import_contents($zipfilepath);
53
 
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);
57
    }
58
    \core_analytics\model::import_model($zipfilepath);
59
 
60
    redirect($returnurl, get_string('importedsuccessfully', 'tool_analytics'), 0,
61
        \core\output\notification::NOTIFY_SUCCESS);
62
}
63
 
64
echo $OUTPUT->header();
65
$form->display();
66
echo $OUTPUT->footer();