FROM {hvp_libraries} hl1 JOIN {hvp_libraries} hl2 ON hl1.machine_name = hl2.machine_name
                                  WHERE hl1.id = ?
                               ORDER BY hl2.title ASC, hl2.major_version ASC, hl2.minor_version ASC', array($libraryid));
$versions = array();
foreach ($results as $result) {
    $versions[$result->id] = $result;
}
$library = $versions[$libraryid];
$upgrades = $core->getUpgrades($library, $versions);
$PAGE->set_heading(get_string('upgradeheading', 'hvp', $library->title . ' (' . \H5PCore::libraryVersion($library) . ')'));
// Get num of contents that can be upgraded.
$numcontents = $core->h5pF->getNumContent($libraryid);
if (count($versions) < 2) {
    echo $OUTPUT->header();
    echo get_string('upgradenoavailableupgrades', 'hvp');
} else {
    if ($numcontents === 0) {
        echo $OUTPUT->header();
        echo get_string('upgradenothingtodo', 'hvp');
    } else {
        $settings = array('libraryInfo' => array('message' => get_string('upgrademessage', 'hvp', $numcontents), 'inProgress' => get_string('upgradeinprogress', 'hvp'), 'error' => get_string('upgradeerror', 'hvp'), 'errorData' => get_string('upgradeerrordata', 'hvp'), 'errorScript' => get_string('upgradeerrorscript', 'hvp'), 'errorContent' => get_string('upgradeerrorcontent', 'hvp'), 'errorParamsBroken' => get_string('upgradeerrorparamsbroken', 'hvp'), 'done' => get_string('upgradedone', 'hvp', $numcontents) . ' <a href="' . (new moodle_url('/mod/hvp/library_list.php'))->out(false) . '">' . get_string('upgradereturn', 'hvp') . '</a>', 'library' => array('name' => $library->name, 'version' => $library->major_version . '.' . $library->minor_version), 'libraryBaseUrl' => (new moodle_url('/mod/hvp/ajax.php', array('action' => 'getlibrarydataforupgrade')))->out(false) . '&library=', 'scriptBaseUrl' => (new moodle_url('/mod/hvp/library/js'))->out(false), 'buster' => hvp_get_cache_buster(), 'versions' => $upgrades, 'contents' => $numcontents, 'buttonLabel' => get_string('upgradebuttonlabel', 'hvp'), 'infoUrl' => (new moodle_url('/mod/hvp/ajax.php', array('action' => 'libraryupgradeprogress', 'library_id' => $libraryid)))->out(false), 'total' => $numcontents, 'token' => \H5PCore::createToken('contentupgrade')));
        // Add JavaScripts.
        $liburl = $CFG->httpswwwroot . '/mod/hvp/library/';
        hvp_admin_add_generic_css_and_js($PAGE, $liburl, $settings);
        $PAGE->requires->js(new moodle_url($liburl . 'js/h5p-version.js' . hvp_get_cache_buster()), true);
        $PAGE->requires->js(new moodle_url($liburl . 'js/h5p-content-upgrade.js' . hvp_get_cache_buster()), true);
        echo $OUTPUT->header();
        echo '<div id="h5p-admin-container">' . get_string('enablejavascript', 'hvp') . '</div>';
    }
}
echo $OUTPUT->footer();
            $restricted_url = (new moodle_url('/mod/hvp/ajax.php', array('action' => 'restrict_library', 'token' => \H5PCore::createToken('library_' . $library->id), 'restrict' => $restricted ? 0 : 1, 'library_id' => $library->id)))->out(false);
        } else {
            $upgradeUrl = null;
            $restricted = null;
            $restricted_url = null;
        }
        $settings['libraryList']['listData'][] = array('title' => $library->title . ' (' . \H5PCore::libraryVersion($library) . ')', 'restricted' => $restricted, 'restrictedUrl' => $restricted_url, 'numContent' => $core->h5pF->getNumContent($library->id), 'numContentDependencies' => $usage['content'] === -1 ? '' : $usage['content'], 'numLibraryDependencies' => $usage['libraries'], 'upgradeUrl' => $upgradeUrl, 'detailsUrl' => null, 'deleteUrl' => null);
        $i++;
    }
}
// All translations are made server side
$settings['libraryList']['listHeaders'] = array(get_string('librarylisttitle', 'hvp'), get_string('librarylistrestricted', 'hvp'), get_string('librarylistinstances', 'hvp'), get_string('librarylistinstancedependencies', 'hvp'), get_string('librarylistlibrarydependencies', 'hvp'), get_string('librarylistactions', 'hvp'));
// Add js
$lib_url = $CFG->httpswwwroot . '/mod/hvp/library/';
hvp_admin_add_generic_css_and_js($PAGE, $lib_url, $settings);
$PAGE->requires->js(new moodle_url($lib_url . 'js/h5p-library-list.js' . hvp_get_cache_buster()), true);
// RENDER PAGE OUTPUT
echo $OUTPUT->header();
// Print any messages
\mod_hvp\framework::printMessages('info', \mod_hvp\framework::messages('info'));
\mod_hvp\framework::printMessages('error', \mod_hvp\framework::messages('error'));
// Page Header
echo '<h2>' . get_string('libraries', 'hvp') . '</h2>';
if (isset($updateform)) {
    // Update All Libraries
    echo '<h3 class="h5p-admin-header">' . get_string('updatelibraries', 'hvp') . '</h3>';
    $updateform->display();
}
// Upload Form
echo '<h3 class="h5p-admin-header">' . get_string('uploadlibraries', 'hvp') . '</h3>';
$uploadform->display();
Esempio n. 3
0
/**
 * Add core JS and CSS to page.
 *
 * @param moodle_page $page
 * @param moodle_url|string $liburl
 * @param array|null $settings
 * @throws \coding_exception
 */
function hvp_admin_add_generic_css_and_js($page, $liburl, $settings = null)
{
    foreach (\H5PCore::$adminScripts as $script) {
        $page->requires->js(new moodle_url($liburl . $script . hvp_get_cache_buster()), true);
    }
    if ($settings === null) {
        $settings = array();
    }
    $settings['containerSelector'] = '#h5p-admin-container';
    $settings['l10n'] = array('NA' => get_string('notapplicable', 'hvp'), 'viewLibrary' => '', 'deleteLibrary' => '', 'upgradeLibrary' => get_string('upgradelibrarycontent', 'hvp'));
    $page->requires->data_for_js('H5PAdminIntegration', $settings, true);
    $page->requires->css(new moodle_url($liburl . 'styles/h5p.css' . hvp_get_cache_buster()));
    $page->requires->css(new moodle_url($liburl . 'styles/h5p-admin.css' . hvp_get_cache_buster()));
    // Add settings:
    $page->requires->data_for_js('h5p', hvp_get_core_settings(), true);
}