/** * Display details for a given content library. * * @since 1.1.0 */ private function display_library_details() { global $wpdb; $library = $this->get_library(); H5P_Plugin_Admin::print_messages(); if (!$library) { return; } // Add settings and translations $plugin = H5P_Plugin::get_instance(); $interface = $plugin->get_h5p_instance('interface'); $settings = array('containerSelector' => '#h5p-admin-container'); // Build the translations needed $settings['libraryInfo']['translations'] = array('noContent' => __('No content is using this library', $this->plugin_slug), 'contentHeader' => __('Content using this library', $this->plugin_slug), 'pageSizeSelectorLabel' => __('Elements per page', $this->plugin_slug), 'filterPlaceholder' => __('Filter content', $this->plugin_slug), 'pageXOfY' => __('Page $x of $y', $this->plugin_slug)); $notCached = $interface->getNumNotFiltered(); if ($notCached) { $settings['libraryInfo']['notCached'] = $this->get_not_cached_settings($notCached); } else { // List content which uses this library $contents = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT hc.id, hc.title\n FROM {$wpdb->prefix}h5p_contents_libraries hcl\n JOIN {$wpdb->prefix}h5p_contents hc ON hcl.content_id = hc.id\n WHERE hcl.library_id = %d\n ORDER BY hc.title", $library->id)); foreach ($contents as $content) { $settings['libraryInfo']['content'][] = array('title' => $content->title, 'url' => admin_url('admin.php?page=h5p&task=show&id=' . $content->id)); } } // Build library info $settings['libraryInfo']['info'] = array(__('Version', $this->plugin_slug) => H5PCore::libraryVersion($library), __('Fullscreen', $this->plugin_slug) => $library->fullscreen ? __('Yes', $this->plugin_slug) : __('No', $this->plugin_slug), __('Content library', $this->plugin_slug) => $library->runnable ? __('Yes', $this->plugin_slug) : __('No', $this->plugin_slug), __('Used by', $this->plugin_slug) => isset($contents) ? sprintf(_n('1 content', '%d contents', count($contents), $this->plugin_slug), count($contents)) : __('N/A', $this->plugin_slug)); $this->add_admin_assets(); H5P_Plugin_Admin::add_script('library-list', 'h5p-php-library/js/h5p-library-details.js'); include_once 'views/library-details.php'; $plugin->print_settings($settings, 'H5PAdminIntegration'); }
$settings = array(); $i = 0; foreach ($libraries as $versions) { foreach ($versions as $library) { $usage = $core->h5pF->getLibraryUsage($library->id, $numNotFiltered ? true : false); if ($library->runnable) { $upgrades = $core->getUpgrades($library, $versions); $upgradeUrl = empty($upgrades) ? false : (new moodle_url('/mod/hvp/upgrade_content_page.php', array('library_id' => $library->id)))->out(false); $restricted = isset($library->restricted) && $library->restricted == 1 ? true : false; $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
/** * Detemine which versions content with the given library can be upgraded to. * * @param object $library * @param array $versions * @return array */ public function getUpgrades($library, $versions) { $upgrades = array(); foreach ($versions as $upgrade) { if ($upgrade->major_version > $library->major_version || $upgrade->major_version === $library->major_version && $upgrade->minor_version > $library->minor_version) { $upgrades[$upgrade->id] = H5PCore::libraryVersion($upgrade); } } return $upgrades; }
$PAGE->set_title("{$SITE->shortname}: " . get_string('upgrade', 'hvp')); // Inform moodle which menu entry currently is active! $core = \mod_hvp\framework::instance(); global $DB; $results = $DB->get_records_sql('SELECT hl2.id as id, hl2.machine_name as name, hl2.title, hl2.major_version, hl2.minor_version, hl2.patch_version 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);