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 library list 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
$pageurl = new moodle_url('/mod/hvp/library_list.php');
32
$PAGE->set_url($pageurl);
33
 
34
// Inform moodle which menu entry currently is active!
35
admin_externalpage_setup('h5plibraries');
36
 
37
$PAGE->set_title("{$SITE->shortname}: " . get_string('libraries', 'hvp'));
38
 
39
// Create upload libraries form.
40
$uploadform = new \mod_hvp\upload_libraries_form();
41
if ($formdata = $uploadform->get_data()) {
42
    // Handle submitted valid form.
43
    $h5pstorage = \mod_hvp\framework::instance('storage');
44
    $h5pstorage->savePackage(null, null, true);
45
}
46
 
47
$core = \mod_hvp\framework::instance();
48
 
49
$hubon = $core->h5pF->getOption('hub_is_enabled', true);
50
if ($hubon) {
51
    // Create content type cache form.
52
    $ctcacheform = new \mod_hvp\content_type_cache_form();
53
 
54
    // On form submit.
55
    if ($ctcacheform->get_data()) {
56
        // Update cache and reload page.
57
        $core->updateContentTypeCache();
58
        redirect($pageurl);
59
    }
60
}
61
 
62
$numnotfiltered = $core->h5pF->getNumNotFiltered();
63
$libraries = $core->h5pF->loadLibraries();
64
 
65
// Add settings for each library.
66
$settings = array();
67
$i = 0;
68
foreach ($libraries as $versions) {
69
    foreach ($versions as $library) {
70
        $usage = $core->h5pF->getLibraryUsage($library->id, $numnotfiltered ? true : false);
71
        if ($library->runnable) {
72
            $upgrades = $core->getUpgrades($library, $versions);
73
            $upgradeurl = empty($upgrades) ? false : (new moodle_url('/mod/hvp/upgrade_content_page.php', array(
74
                'library_id' => $library->id
75
            )))->out(false);
76
 
77
            $restricted = (isset($library->restricted) && $library->restricted == 1 ? true : false);
78
            $restrictedurl = (new moodle_url('/mod/hvp/ajax.php', array(
79
                'action' => 'restrict_library',
80
                'token' => \H5PCore::createToken('library_' . $library->id),
81
                'restrict' => ($restricted ? 0 : 1),
82
                'library_id' => $library->id
83
            )))->out(false);
84
        } else {
85
            $upgradeurl = null;
86
            $restricted = null;
87
            $restrictedurl = null;
88
        }
89
 
90
        $settings['libraryList']['listData'][] = array(
91
            'title' => $library->title . ' (' . \H5PCore::libraryVersion($library) . ')',
92
            'restricted' => $restricted,
93
            'restrictedUrl' => $restrictedurl,
94
            'numContent' => $core->h5pF->getNumContent($library->id),
95
            'numContentDependencies' => $usage['content'] === -1 ? '' : $usage['content'],
96
            'numLibraryDependencies' => $usage['libraries'],
97
            'upgradeUrl' => $upgradeurl,
98
            'detailsUrl' => null, // Not implemented in Moodle.
99
            'deleteUrl' => null // Not implemented in Moodle.
100
        );
101
 
102
        $i++;
103
    }
104
}
105
 
106
// All translations are made server side.
107
$settings['libraryList']['listHeaders'] = array(
108
    get_string('librarylisttitle', 'hvp'),
109
    get_string('librarylistrestricted', 'hvp'),
110
    get_string('librarylistinstances', 'hvp'),
111
    get_string('librarylistinstancedependencies', 'hvp'),
112
    get_string('librarylistlibrarydependencies', 'hvp'),
113
    get_string('librarylistactions', 'hvp')
114
);
115
 
116
// Add js.
117
$liburl = \mod_hvp\view_assets::getsiteroot() . '/mod/hvp/library/';
118
 
119
hvp_admin_add_generic_css_and_js($PAGE, $liburl, $settings);
120
$PAGE->requires->js(new moodle_url($liburl . 'js/h5p-library-list.js' . hvp_get_cache_buster()), true);
121
 
122
// RENDER PAGE OUTPUT.
123
 
124
echo $OUTPUT->header();
125
 
126
// Print any messages.
127
\mod_hvp\framework::printMessages('info', \mod_hvp\framework::messages('info'));
128
\mod_hvp\framework::printMessages('error', \mod_hvp\framework::messages('error'));
129
 
130
// Page Header.
131
echo '<h2>' . get_string('libraries', 'hvp') . '</h2>';
132
 
133
if ($hubon) {
134
    // Content type cache form.
135
    echo '<h3>' . get_string('contenttypecacheheader', 'hvp') . '</h3>';
136
    $ctcacheform->display();
137
}
138
 
139
// Upload Form.
140
echo '<h3 class="h5p-admin-header">' . get_string('uploadlibraries', 'hvp') . '</h3>';
141
$uploadform->display();
142
 
143
// Installed Libraries List.
144
echo '<h3 class="h5p-admin-header">' . get_string('installedlibraries', 'hvp')  . '</h3>';
145
echo '<div id="h5p-admin-container"></div>';
146
 
147
echo $OUTPUT->footer();