Make export work

namespaces
Svein-Tore Griff With 2013-11-18 17:45:31 +01:00
parent f32ae3a4d4
commit bdb508c877
1 changed files with 28 additions and 19 deletions

View File

@ -242,7 +242,7 @@ interface H5PFrameworkInterface {
* 'preloaded' => int(0|1), * 'preloaded' => int(0|1),
* 'language' => string, * 'language' => string,
*/ */
public function getExportData($contentId, $title, $language); public function getExportData($contentId);
/** /**
* Check if export is enabled. * Check if export is enabled.
*/ */
@ -1005,7 +1005,7 @@ class H5PStorage {
* @param boolean $dynamic * @param boolean $dynamic
* Whether or not the current library is a dynamic dependency * Whether or not the current library is a dynamic dependency
*/ */
public function getLibraryUsage(&$librariesInUse, $jsonData, $dynamic = FALSE) { public function getLibraryUsage(&$librariesInUse, $jsonData, $dynamic = FALSE, $editor = FALSE) {
if (isset($jsonData['preloadedDependencies'])) { if (isset($jsonData['preloadedDependencies'])) {
foreach ($jsonData['preloadedDependencies'] as $preloadedDependency) { foreach ($jsonData['preloadedDependencies'] as $preloadedDependency) {
$library = $this->h5pF->loadLibrary($preloadedDependency['machineName'], $preloadedDependency['majorVersion'], $preloadedDependency['minorVersion']); $library = $this->h5pF->loadLibrary($preloadedDependency['machineName'], $preloadedDependency['majorVersion'], $preloadedDependency['minorVersion']);
@ -1013,7 +1013,7 @@ class H5PStorage {
'library' => $library, 'library' => $library,
'preloaded' => $dynamic ? 0 : 1, 'preloaded' => $dynamic ? 0 : 1,
); );
$this->getLibraryUsage($librariesInUse, $library, $dynamic); $this->getLibraryUsage($librariesInUse, $library, $dynamic, $editor);
} }
} }
if (isset($jsonData['dynamicDependencies'])) { if (isset($jsonData['dynamicDependencies'])) {
@ -1025,7 +1025,19 @@ class H5PStorage {
'preloaded' => 0, 'preloaded' => 0,
); );
} }
$this->getLibraryUsage($librariesInUse, $library, TRUE); $this->getLibraryUsage($librariesInUse, $library, TRUE, $editor);
}
}
if (isset($jsonData['editorDependencies']) && $editor) {
foreach ($jsonData['editorDependencies'] as $editorDependency) {
if (!isset($librariesInUse[$editorDependency['machineName']])) {
$library = $this->h5pF->loadLibrary($editorDependency['machineName'], $editorDependency['majorVersion'], $editorDependency['minorVersion']);
$librariesInUse[$editorDependency['machineName']] = array(
'library' => $library,
'preloaded' => $dynamic ? 0 : 1,
);
}
$this->getLibraryUsage($librariesInUse, $library, $dynamic, TRUE);
} }
} }
} }
@ -1057,26 +1069,27 @@ Class H5PExport {
* The data to be exported. * The data to be exported.
* @return H5P package. * @return H5P package.
*/ */
public function getExportPath($exportData) { public function getExportPath($contentId, $title, $language) {
$h5pDir = $this->h5pF->getH5pPath() . DIRECTORY_SEPARATOR; $h5pDir = $this->h5pF->getH5pPath() . DIRECTORY_SEPARATOR;
$tempPath = $h5pDir . 'temp' . DIRECTORY_SEPARATOR . $exportData['contentId']; $tempPath = $h5pDir . 'temp' . DIRECTORY_SEPARATOR . $contentId;
$zipPath = $h5pDir . 'exports' . DIRECTORY_SEPARATOR . $exportData['contentId'] . '.h5p'; $zipPath = $h5pDir . 'exports' . DIRECTORY_SEPARATOR . $contentId . '.h5p';
// Check if h5p-package already exists. // Check if h5p-package already exists.
if (!file_exists($zipPath)) { if (!file_exists($zipPath)) {
// Temp dir to put the h5p files in // Temp dir to put the h5p files in
@mkdir($tempPath); @mkdir($tempPath);
$exportData = $this->h5pF->getExportData($contentId);
// Create content folder // Create content folder
$this->h5pC->copyTree($h5pDir . 'content' . DIRECTORY_SEPARATOR . $exportData['contentId'], $tempPath . DIRECTORY_SEPARATOR . 'content'); $this->h5pC->copyTree($h5pDir . 'content' . DIRECTORY_SEPARATOR . $contentId, $tempPath . DIRECTORY_SEPARATOR . 'content');
file_put_contents($tempPath . DIRECTORY_SEPARATOR . 'content' . DIRECTORY_SEPARATOR . 'content.json', $exportData['jsonContent']); file_put_contents($tempPath . DIRECTORY_SEPARATOR . 'content' . DIRECTORY_SEPARATOR . 'content.json', $exportData['jsonContent']);
// Make embedTypes into an array // Make embedTypes into an array
$embedTypes = explode(', ', $exportData['embedType']); $embedTypes = explode(', ', $exportData['embedType']);
// Build h5p.json // Build h5p.json
$h5pJson = array ( $h5pJson = array (
'title' => $exportData['title'], 'title' => $title,
'language' => $exportData['language'], 'language' => $exportData['language'] ? $exportData['language'] : 'und',
'mainLibrary' => $exportData['mainLibrary'], 'mainLibrary' => $exportData['mainLibrary'],
'embedTypes' => $embedTypes, 'embedTypes' => $embedTypes,
); );
@ -1109,7 +1122,7 @@ Class H5PExport {
// Add the editor libraries to the list of libraries // Add the editor libraries to the list of libraries
// TODO: Add support for dependencies or editor libraries // TODO: Add support for dependencies or editor libraries
$exportData['libraries'] = $this->addEditorLibraries($exportData['libraries']); $exportData['libraries'] = $this->addEditorLibraries($exportData['libraries'], $exportData['editorLibraries']);
// Copies libraries to temp dir and create mention in h5p.json // Copies libraries to temp dir and create mention in h5p.json
foreach($exportData['libraries'] as $library) { foreach($exportData['libraries'] as $library) {
@ -1143,14 +1156,10 @@ Class H5PExport {
return str_replace(DIRECTORY_SEPARATOR, '/', $zipPath); return str_replace(DIRECTORY_SEPARATOR, '/', $zipPath);
} }
private function addEditorLibraries($libraries) { private function addEditorLibraries($libraries, $editorLibraries) {
foreach ($libraries as $library) { foreach ($editorLibraries as $editorLibrary) {
if (isset($library['editorLibraries'])) {
foreach ($library['editorLibraries'] as $editorLibrary) {
$libraries[$editorLibrary['machineName']] = $editorLibrary; $libraries[$editorLibrary['machineName']] = $editorLibrary;
} }
}
}
return $libraries; return $libraries;
} }
} }