Fixed download/embed button bug when permissions are used

improved-embed-and-download
Paal Joergensen 2016-12-13 15:57:05 +01:00
parent e69a81f403
commit cfd6cb1e63
1 changed files with 26 additions and 19 deletions

View File

@ -2516,6 +2516,30 @@ class H5PCore {
return $display_options; return $display_options;
} }
/**
* Helper function used to figure out embed & download behaviour
*
* @method setDisplayOptionOverrides
* @param string $option_name
* @param H5PPermission $permission
* @param int $id
* @param bool &$value
*/
private function setDisplayOptionOverrides($option_name, $permission, $id, &$value) {
$behaviour = $this->h5pF->getOption($option_name, H5PDisplayOptionBehaviour::ALWAYS_SHOW);
// If never show globally, force hide
if ($behaviour == H5PDisplayOptionBehaviour::NEVER_SHOW) {
$value = false;
}
elseif ($behaviour == H5PDisplayOptionBehaviour::ALWAYS_SHOW) {
// If always show or permissions say so, force show
$value = true;
}
elseif ($behaviour == H5PDisplayOptionBehaviour::CONTROLLED_BY_PERMISSIONS) {
$value = $this->h5pF->hasPermission($permission, $id);
}
}
/** /**
* Determine display option visibility when viewing H5P * Determine display option visibility when viewing H5P
* *
@ -2532,25 +2556,8 @@ class H5PCore {
$display_options['showFrame'] = false; $display_options['showFrame'] = false;
} }
else { else {
$export = $this->h5pF->getOption('export', H5PDisplayOptionBehaviour::ALWAYS_SHOW); $this->setDisplayOptionOverrides('export', H5PPermission::DOWNLOAD_H5P, $id, $display_options['showDownload']);
if ($export == H5PDisplayOptionBehaviour::NEVER_SHOW) { $this->setDisplayOptionOverrides('embed', H5PPermission::EMBED_H5P, $id, $display_options['showEmbed']);
// If never show globally, force hide
$display_options['showDownload'] = false;
}
elseif ($export == H5PDisplayOptionBehaviour::ALWAYS_SHOW || ($export == H5PDisplayOptionBehaviour::CONTROLLED_BY_PERMISSIONS && $this->h5pF->hasPermission(H5PPermission::DOWNLOAD_H5P, $id))) {
// If always show or permissions say so, force show
$display_options['showDownload'] = true;
}
$embed = $this->h5pF->getOption('embed', H5PDisplayOptionBehaviour::ALWAYS_SHOW);
if ($embed == H5PDisplayOptionBehaviour::NEVER_SHOW) {
// If never show globally, force hide
$display_options['showEmbed'] = false;
}
elseif ($embed == H5PDisplayOptionBehaviour::ALWAYS_SHOW || ($embed == H5PDisplayOptionBehaviour::CONTROLLED_BY_PERMISSIONS && $this->h5pF->hasPermission(H5PPermission::EMBED_H5P, $id))) {
// If always show or permissions say so, force show
$display_options['showEmbed'] = true;
}
if ($this->h5pF->getOption('copyright', TRUE) == FALSE) { if ($this->h5pF->getOption('copyright', TRUE) == FALSE) {
$display_options['showCopyright'] = false; $display_options['showCopyright'] = false;