Merge branch 'master' of github.com:h5p/h5p-php-library

HFP-2095-Fix-table-styling
Frode Petterson 2018-09-24 10:18:40 +02:00
commit cb2acb21c8
3 changed files with 39 additions and 10 deletions

View File

@ -84,11 +84,14 @@ class H5PDevelopment {
// TODO: Validate props? Not really needed, is it? this is a dev site.
// Save/update library.
$library['libraryId'] = $this->h5pF->getLibraryId($library['machineName'], $library['majorVersion'], $library['minorVersion']);
if (!isset($library['metadata'])) {
$library['metadata'] = 1;
}
// Convert metadataSettings values to boolean & json_encode it before saving
$library['metadataSettings'] = isset($library['metadataSettings']) ?
H5PMetadata::boolifyAndEncodeSettings($library['metadataSettings']) :
NULL;
// Save/update library.
$this->h5pF->saveLibraryData($library, $library['libraryId'] === FALSE);
$library['path'] = 'development/' . $contents[$i];

View File

@ -114,4 +114,24 @@ abstract class H5PMetadata {
return $fields;
}
/**
* The metadataSettings field in libraryJson uses 1 for true and 0 for false.
* Here we are converting these to booleans, and also doing JSON encoding.
* This is invoked before the library data is beeing inserted/updated to DB.
*
* @param array $metadataSettings
* @return string
*/
public static function boolifyAndEncodeSettings($metadataSettings) {
// Convert metadataSettings values to boolean
if (isset($metadataSettings['disable'])) {
$metadataSettings['disable'] = $metadataSettings['disable'] === 1;
}
if (isset($metadataSettings['disable'])) {
$metadataSettings['disableExtraTitleField'] = $metadataSettings['disableExtraTitleField'] === 1;
}
return json_encode($metadataSettings);
}
}

View File

@ -210,7 +210,9 @@ interface H5PFrameworkInterface {
* - minorVersion: The library's minorVersion
* - patchVersion: The library's patchVersion
* - runnable: 1 if the library is a content type, 0 otherwise
* - metadata: 1 if the library should support setting metadata (copyright etc)
* - metadataSettings: Associative array containing:
* - disable: 1 if the library should not support setting metadata (copyright etc)
* - disableExtraTitleField: 1 if the library don't need the extra title field
* - fullscreen(optional): 1 if the library supports fullscreen, 0 otherwise
* - embedTypes(optional): list of supported embed types
* - preloadedJs(optional): list of associative arrays containing:
@ -681,7 +683,10 @@ class H5PValidator {
'author' => '/^.{1,255}$/',
'license' => '/^(cc-by|cc-by-sa|cc-by-nd|cc-by-nc|cc-by-nc-sa|cc-by-nc-nd|pd|cr|MIT|GPL1|GPL2|GPL3|MPL|MPL2)$/',
'description' => '/^.{1,}$/',
'metadata' => '/^(0|1)$/',
'metadataSettings' => array(
'disable' => '/^(0|1)$/',
'disableExtraTitleField' => '/^(0|1)$/'
),
'dynamicDependencies' => array(
'machineName' => '/^[\w0-9\-\.]{1,255}$/i',
'majorVersion' => '/^[0-9]{1,5}$/',
@ -1440,10 +1445,11 @@ class H5PStorage {
// Indicate that the dependencies of this library should be saved.
$library['saveDependencies'] = TRUE;
// Save library meta data
if (!isset($library['metadata'])) {
$library['metadata'] = 1;
}
// Convert metadataSettings values to boolean & json_encode it before saving
$library['metadataSettings'] = isset($library['metadataSettings']) ?
H5PMetadata::boolifyAndEncodeSettings($library['metadataSettings']) :
NULL;
$this->h5pF->saveLibraryData($library, $new);
// Save library folder