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
 * Responsible for displaying the content upgrade page
18
 *
19
 * @package    mod_hvp
20
 * @copyright  2016 Joubel AS <contact@joubel.com>
21
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
 
24
require_once("../../config.php");
25
require_once($CFG->libdir.'/adminlib.php');
26
require_once("locallib.php");
27
 
28
// No guest autologin.
29
require_login(0, false);
30
 
31
$libraryid = required_param('library_id', PARAM_INT);
32
$pageurl = new moodle_url('/mod/hvp/upgrade_content_page.php', array('library_id' => $libraryid));
33
$PAGE->set_url($pageurl);
34
admin_externalpage_setup('h5plibraries');
35
$PAGE->set_title("{$SITE->shortname}: " . get_string('upgrade', 'hvp'));
36
 
37
// Inform moodle which menu entry currently is active!
38
$core = \mod_hvp\framework::instance();
39
global $DB;
40
$results = $DB->get_records_sql('SELECT hl2.id as id, hl2.machine_name as name, hl2.title, hl2.major_version,
41
                                        hl2.minor_version, hl2.patch_version
42
                                   FROM {hvp_libraries} hl1 JOIN {hvp_libraries} hl2 ON hl1.machine_name = hl2.machine_name
43
                                  WHERE hl1.id = ?
44
                               ORDER BY hl2.title ASC, hl2.major_version ASC, hl2.minor_version ASC', array($libraryid));
45
$versions = array();
46
foreach ($results as $result) {
47
    $versions[$result->id] = $result;
48
}
49
$library = $versions[$libraryid];
50
$upgrades = $core->getUpgrades($library, $versions);
51
 
52
$PAGE->set_heading(get_string('upgradeheading', 'hvp', $library->title . ' (' . \H5PCore::libraryVersion($library) . ')'));
53
 
54
// Get num of contents that can be upgraded.
55
$numcontents = $core->h5pF->getNumContent($libraryid);
56
if (count($versions) < 2) {
57
    echo $OUTPUT->header();
58
    echo get_string('upgradenoavailableupgrades', 'hvp');
59
} else if ($numcontents === 0) {
60
    echo $OUTPUT->header();
61
    echo get_string('upgradenothingtodo', 'hvp');
62
} else {
63
    $settings = array(
64
        'libraryInfo' => array(
65
            'message' => get_string('upgrademessage', 'hvp', $numcontents),
66
            'inProgress' => get_string('upgradeinprogress', 'hvp'),
67
            'error' => get_string('upgradeerror', 'hvp'),
68
            'errorData' => get_string('upgradeerrordata', 'hvp'),
69
            'errorScript' => get_string('upgradeerrorscript', 'hvp'),
70
            'errorContent' => get_string('upgradeerrorcontent', 'hvp'),
71
            'errorParamsBroken' => get_string('upgradeerrorparamsbroken', 'hvp'),
72
            'errorLibrary' => get_string('upgradeerrormissinglibrary', 'hvp'),
73
            'errorTooHighVersion' => get_string('upgradeerrortoohighversion', 'hvp'),
74
            'errorNotSupported' => get_string('upgradeerrornotsupported', 'hvp'),
75
            'done' => get_string('upgradedone', 'hvp', $numcontents) .
76
                      ' <a href="' . (new moodle_url('/mod/hvp/library_list.php'))->out(false) . '">' .
77
                      get_string('upgradereturn', 'hvp') . '</a>',
78
            'library' => array(
79
                'name' => $library->name,
80
                'version' => $library->major_version . '.' . $library->minor_version,
81
            ),
82
            'libraryBaseUrl' => (new moodle_url('/mod/hvp/ajax.php',
83
                                 array('action' => 'getlibrarydataforupgrade')))->out(false) . '&library=',
84
            'scriptBaseUrl' => (new moodle_url('/mod/hvp/library/js'))->out(false),
85
            'buster' => hvp_get_cache_buster(),
86
            'versions' => $upgrades,
87
            'contents' => $numcontents,
88
            'buttonLabel' => get_string('upgradebuttonlabel', 'hvp'),
89
            'infoUrl' => (new moodle_url('/mod/hvp/ajax.php', array('action' => 'libraryupgradeprogress',
90
                          'library_id' => $libraryid)))->out(false),
91
            'total' => $numcontents,
92
            'token' => \H5PCore::createToken('contentupgrade')
93
        )
94
    );
95
 
96
    // Add JavaScripts.
97
    $liburl = \mod_hvp\view_assets::getsiteroot() . '/mod/hvp/library/';
98
    hvp_admin_add_generic_css_and_js($PAGE, $liburl, $settings);
99
    $PAGE->requires->js(new moodle_url($liburl . 'js/h5p-version.js' . hvp_get_cache_buster()), true);
100
    $PAGE->requires->js(new moodle_url($liburl . 'js/h5p-content-upgrade.js' . hvp_get_cache_buster()), true);
101
    echo $OUTPUT->header();
102
    echo '<div id="h5p-admin-container">' . get_string('enablejavascript', 'hvp') . '</div>';
103
}
104
 
105
echo $OUTPUT->footer();