diff --git a/h5p/classes/core.php b/h5p/classes/core.php
index c3a9a884fec..3d806119f23 100644
--- a/h5p/classes/core.php
+++ b/h5p/classes/core.php
@@ -190,6 +190,13 @@ class core extends \H5PCore {
'minorVersion' => $type->version->minor,
'patchVersion' => $type->version->patch,
];
+ // Add example and tutorial to the library, to store this information too.
+ if (isset($type->example)) {
+ $library['example'] = $type->example;
+ }
+ if (isset($type->tutorial)) {
+ $library['tutorial'] = $type->tutorial;
+ }
$shoulddownload = true;
if ($framework->getLibraryId($type->id, $type->version->major, $type->version->minor)) {
@@ -221,6 +228,8 @@ class core extends \H5PCore {
* @return int|null Returns the id of the content type library installed, null otherwise.
*/
public function fetch_content_type(array $library): ?int {
+ global $DB;
+
$factory = new factory();
// Download the latest content type from the H5P official repository.
@@ -250,6 +259,18 @@ class core extends \H5PCore {
$librarykey = static::libraryToString($library);
$libraryid = $factory->get_storage()->h5pC->librariesJsonData[$librarykey]["libraryId"];
+ // Update example and tutorial (if any of them are defined in $library).
+ $params = ['id' => $libraryid];
+ if (array_key_exists('example', $library)) {
+ $params['example'] = $library['example'];
+ }
+ if (array_key_exists('tutorial', $library)) {
+ $params['tutorial'] = $library['tutorial'];
+ }
+ if (count($params) > 1) {
+ $DB->update_record('h5p_libraries', $params);
+ }
+
return $libraryid;
}
diff --git a/h5p/classes/editor_ajax.php b/h5p/classes/editor_ajax.php
index 6f293d01dc7..43e42480d73 100644
--- a/h5p/classes/editor_ajax.php
+++ b/h5p/classes/editor_ajax.php
@@ -76,8 +76,23 @@ class editor_ajax implements H5PEditorAjaxInterface {
* @return mixed|null Returns results from querying the database
*/
public function getContentTypeCache($machinename = null) {
- // This is to be implemented when the Hub client is used.
- return [];
+ global $DB;
+
+ // Added some extra fields to the result because they are expected by functions calling this. They have been
+ // taken from method getCachedLibsMap() in h5peditor.class.php.
+ $sql = "SELECT l.id, l.machinename AS machine_name, l.majorversion AS major_version,
+ l.minorversion AS minor_version, l.patchversion AS patch_version, l.coremajor AS h5p_major_version,
+ l.coreminor AS h5p_minor_version, l.title, l.tutorial, l.example,
+ '' AS summary, '' AS description, '' AS icon, 0 AS created_at, 0 AS updated_at, 0 AS is_recommended,
+ 0 AS popularity, '' AS screenshots, '' AS license, '' AS owner
+ FROM {h5p_libraries} l";
+ $params = [];
+ if (!empty($machinename)) {
+ $sql .= ' WHERE l.machinename = :machine_name';
+ $params = ['machine_name' => $machinename];
+ }
+
+ return $DB->get_records_sql($sql, $params);
}
/**
diff --git a/h5p/classes/editor_framework.php b/h5p/classes/editor_framework.php
index 8f97a36a89e..587b83490f5 100644
--- a/h5p/classes/editor_framework.php
+++ b/h5p/classes/editor_framework.php
@@ -228,7 +228,7 @@ class editor_framework implements H5peditorStorage {
if ($libraries !== null) {
// Get details for the specified libraries.
$librariesin = [];
- $fields = 'title, runnable, metadatasettings';
+ $fields = 'title, runnable, metadatasettings, example, tutorial';
foreach ($libraries as $library) {
$params = [
@@ -243,11 +243,13 @@ class editor_framework implements H5peditorStorage {
$library->title = $details->title;
$library->runnable = $details->runnable;
$library->metadataSettings = json_decode($details->metadatasettings);
+ $library->example = $details->example;
+ $library->tutorial = $details->tutorial;
$librariesin[] = $library;
}
}
} else {
- $fields = 'id, machinename as name, title, majorversion, minorversion, metadatasettings';
+ $fields = 'id, machinename as name, title, majorversion, minorversion, metadatasettings, example, tutorial';
$librariesin = api::get_contenttype_libraries($fields);
}
diff --git a/h5p/classes/framework.php b/h5p/classes/framework.php
index 25d0ad9650d..d4b0d6ad1e1 100644
--- a/h5p/classes/framework.php
+++ b/h5p/classes/framework.php
@@ -115,7 +115,16 @@ class framework implements \H5PFrameworkInterface {
* @param string $url
*/
public function setLibraryTutorialUrl($libraryname, $url) {
- // Tutorial url is currently not being used or stored in libraries.
+ global $DB;
+
+ $sql = 'UPDATE {h5p_libraries}
+ SET tutorial = :tutorial
+ WHERE machinename = :machinename';
+ $params = [
+ 'tutorial' => $url,
+ 'machinename' => $libraryname,
+ ];
+ $DB->execute($sql, $params);
}
/**
diff --git a/lib/db/install.xml b/lib/db/install.xml
index bcc3e18afce..478146184cc 100644
--- a/lib/db/install.xml
+++ b/lib/db/install.xml
@@ -4198,6 +4198,8 @@
+
+
diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php
index 54eecc81e81..c1f539b36c6 100644
--- a/lib/db/upgrade.php
+++ b/lib/db/upgrade.php
@@ -2762,5 +2762,25 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2020100700.00);
}
+ if ($oldversion < 2020101300.01) {
+ // Define fields tutorial and example to be added to h5p_libraries.
+ $table = new xmldb_table('h5p_libraries');
+
+ // Add tutorial field.
+ $field = new xmldb_field('tutorial', XMLDB_TYPE_TEXT, null, null, null, null, null, 'metadatasettings');
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ // Add example field.
+ $field = new xmldb_field('example', XMLDB_TYPE_TEXT, null, null, null, null, null, 'tutorial');
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ // Main savepoint reached.
+ upgrade_main_savepoint(true, 2020101300.01);
+ }
+
return true;
}
diff --git a/version.php b/version.php
index a7d851b991e..4b0925e10fe 100644
--- a/version.php
+++ b/version.php
@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
-$version = 2020101300.00; // YYYYMMDD = weekly release date of this DEV branch.
+$version = 2020101300.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '3.10dev+ (Build: 20201013)';// Human-friendly version name