H5PEditorAjaxImport.php in Opigno module 3.x
File
src/H5PImportClasses/H5PEditorAjaxImport.php
View source
<?php
namespace Drupal\opigno_module\H5PImportClasses;
class H5PEditorAjaxImport extends \H5PEditorAjax {
public function isValidPackage($skipContent = FALSE) {
$validator = new H5PValidatorImport($this->core->h5pF, $this->core);
if (!$validator
->isValidPackage($skipContent, FALSE)) {
$this->storage
->removeTemporarilySavedFiles($this->core->h5pF
->getUploadedH5pPath());
\Drupal::logger('opigno_groups_migration')
->error('Validating h5p package failed.');
return FALSE;
}
return TRUE;
}
private function isContentTypeCacheUpdated() {
$ct_cache_last_update = $this->core->h5pF
->getOption('content_type_cache_updated_at', 0);
$outdated_cache = $ct_cache_last_update + 60 * 60 * 24 * 7;
if (time() > $outdated_cache) {
$success = $this->core
->updateContentTypeCache();
if (!$success) {
return false;
}
}
return true;
}
private function getContentTypeCache($cacheOutdated = FALSE) {
$canUpdateOrInstall = $this->core->h5pF
->hasPermission(\H5PPermission::INSTALL_RECOMMENDED) || $this->core->h5pF
->hasPermission(\H5PPermission::UPDATE_LIBRARIES);
return array(
'outdated' => $cacheOutdated && $canUpdateOrInstall,
'libraries' => $this->editor
->getLatestGlobalLibrariesData(),
'recentlyUsed' => $this->editor->ajaxInterface
->getAuthorsRecentlyUsedLibraries(),
'apiVersion' => array(
'major' => \H5PCore::$coreApi['majorVersion'],
'minor' => \H5PCore::$coreApi['minorVersion'],
),
'details' => $this->core->h5pF
->getMessages('info'),
);
}
private function isHubOn() {
if (!$this->core->h5pF
->getOption('hub_is_enabled', TRUE)) {
\H5PCore::ajaxError($this->core->h5pF
->t('The hub is disabled. You can enable it in the H5P settings.'), 'HUB_DISABLED', 403);
return false;
}
return true;
}
public function h5pLibariesList() {
if (!$this
->isHubOn()) {
return;
}
return $this
->getContentTypeCache(!$this
->isContentTypeCacheUpdated());
}
}