Skip to content

Commit

Permalink
Merge branch 'improved-embed-and-download'
Browse files Browse the repository at this point in the history
  • Loading branch information
fnoks committed Dec 21, 2016
2 parents a49114d + eabad50 commit 41e22df
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 41 deletions.
17 changes: 17 additions & 0 deletions classes/framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -1227,4 +1227,21 @@ public function getNumAuthors() {
*/
public function afterExportCreated() {
}

/**
* Implements hasPermission
* @method hasPermission
* @param [H5PPermission] $permission
* @param [int] $contentId
* @return boolean
*/
public function hasPermission($permission, $content_id = NULL) {
switch ($permission) {
case \H5PPermission::DOWNLOAD_H5P:
global $DB;
$context = \context_course::instance($DB->get_field('hvp', 'course', array('id' => $content_id)));
return has_capability('mod/hvp:getexport', $context);
}
return FALSE;
}
}
6 changes: 6 additions & 0 deletions lang/de/hvp.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,19 @@
$string['removeoldlogentries'] = 'Entfernen alter H5P-Logdateien';

// Admin settings.
$string['displayoptionnevershow'] = 'Never show';
$string['displayoptionalwaysshow'] = 'Always show';
$string['displayoptionpermissions'] = 'Show only if user has permissions to export H5P';
$string['displayoptionauthoron'] = 'Controlled by author, default is on';
$string['displayoptionauthoroff'] = 'Controlled by author, default is off';
$string['displayoptions'] = 'Optionen anzeigen';
$string['enableframe'] = 'Menüleiste und Rahmen anzeigen.';
$string['enabledownload'] = 'Download-Knopf';
$string['enableembed'] = 'Einbetten-Knopf';
$string['enablecopyright'] = 'Urheberrecht-Knopf';
$string['enableabout'] = 'Über-H5P-Knopf';


$string['externalcommunication'] = 'Externe Kommunikation';
$string['externalcommunication_help'] = 'Die Entwicklung von H5P durch die Übermittlung von anonymen Nutzungsdaten unterstützen. Wenn diese Option ausgeschalten wird, wird diese Seite nicht mehr die akutellsten H5P-Updates erhalten. Mehr Informationen darüber,<a {$a}>welche Daten gesammelt werden</a> sind auf h5p.org verfügbar.';
$string['enablesavecontentstate'] = 'Inhalte automatisch speichern';
Expand Down
5 changes: 5 additions & 0 deletions lang/en/hvp.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@
$string['removeoldlogentries'] = 'Remove old H5P log entries';

// Admin settings.
$string['displayoptionnevershow'] = 'Never show';
$string['displayoptionalwaysshow'] = 'Always show';
$string['displayoptionpermissions'] = 'Show only if user has permissions to export H5P';
$string['displayoptionauthoron'] = 'Controlled by author, default is on';
$string['displayoptionauthoroff'] = 'Controlled by author, default is off';
$string['displayoptions'] = 'Display Options';
$string['enableframe'] = 'Display action bar and frame';
$string['enabledownload'] = 'Download button';
Expand Down
5 changes: 5 additions & 0 deletions lang/fr/hvp.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@
$string['removeoldlogentries'] = 'Supprimer les anciennes entrées de logs H5P';

// Admin settings.
$string['displayoptionnevershow'] = 'Never show';
$string['displayoptionalwaysshow'] = 'Always show';
$string['displayoptionpermissions'] = 'Show only if user has permissions to export H5P';
$string['displayoptionauthoron'] = 'Controlled by author, default is on';
$string['displayoptionauthoroff'] = 'Controlled by author, default is off';
$string['displayoptions'] = 'Afficher les options';
$string['enableframe'] = 'Afficher la barre de menu des actions';
$string['enabledownload'] = 'Bouton de téléchargement';
Expand Down
5 changes: 5 additions & 0 deletions lang/he/hvp.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
$string['removeoldlogentries'] = 'Remove old H5P log entries';

// Admin settings.
$string['displayoptionnevershow'] = 'Never show';
$string['displayoptionalwaysshow'] = 'Always show';
$string['displayoptionpermissions'] = 'Show only if user has permissions to export H5P';
$string['displayoptionauthoron'] = 'Controlled by author, default is on';
$string['displayoptionauthoroff'] = 'Controlled by author, default is off';
$string['displayoptions'] = 'Display Options';
$string['enableframe'] = 'Display action bar and frame';
$string['enabledownload'] = 'Download button';
Expand Down
5 changes: 5 additions & 0 deletions lang/no/hvp.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
$string['removetmpfiles'] = 'Fjern gamle midlertidige filer';

// Admin settings.
$string['displayoptionnevershow'] = 'Vis aldri';
$string['displayoptionalwaysshow'] = 'Vis alltid';
$string['displayoptionpermissions'] = 'Vis kun for brukere som har tilgang til å eksportere H5Per';
$string['displayoptionauthoron'] = 'Settes av forfatter, standard på';
$string['displayoptionauthoroff'] = 'Settes av forfatter, standard av';
$string['displayoptions'] = 'Visningsinnstillinger';
$string['enableframe'] = 'Vis handlingslinjen og rammen';
$string['enabledownload'] = 'Nedlastings-knapp';
Expand Down
5 changes: 5 additions & 0 deletions lang/tr/hvp.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@
$string['removeoldlogentries'] = 'Eski H5P kütük girdilerini kaldır';

// Admin settings.
$string['displayoptionnevershow'] = 'Never show';
$string['displayoptionalwaysshow'] = 'Always show';
$string['displayoptionpermissions'] = 'Show only if user has permissions to export H5P';
$string['displayoptionauthoron'] = 'Controlled by author, default is on';
$string['displayoptionauthoroff'] = 'Controlled by author, default is off';
$string['displayoptions'] = 'Seçenekleri Göster';
$string['enableframe'] = 'Eylem çubuğunu ve çerçevesini göster';
$string['enabledownload'] = 'İndirme tuşu';
Expand Down
9 changes: 4 additions & 5 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,12 @@ function hvp_save_content($hvp) {
*/
function hvp_get_disabled_content_features($hvp) {
$disablesettings = array(
\H5PCore::$disable[\H5PCore::DISABLE_FRAME] => isset($hvp->frame) ? $hvp->frame : 0,
\H5PCore::$disable[\H5PCore::DISABLE_DOWNLOAD] => isset($hvp->download) ? $hvp->download : 0,
\H5PCore::$disable[\H5PCore::DISABLE_COPYRIGHT] => isset($hvp->copyright) ? $hvp->copyright : 0
\H5PCore::DISPLAY_OPTION_FRAME => isset($hvp->frame) ? $hvp->frame : 0,
\H5PCore::DISPLAY_OPTION_DOWNLOAD => isset($hvp->download) ? $hvp->download : 0,
\H5PCore::DISPLAY_OPTION_COPYRIGHT => isset($hvp->copyright) ? $hvp->copyright : 0
);

$core = \mod_hvp\framework::instance();
return $core->getDisable($disablesettings, 0);
return $core->getStorableDisplayOptions($disablesettings, 0);
}

/**
Expand Down
40 changes: 24 additions & 16 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,30 @@ public function definition() {
$mform->addElement('hidden', 'h5pparams', '');
$mform->setType('h5pparams', PARAM_RAW);

// Display options group.
$mform->addElement('header', 'displayoptions', get_string('displayoptions', 'hvp'));

$mform->addElement('checkbox', 'frame', get_string('enableframe', 'hvp'));
$mform->setType('frame', PARAM_BOOL);
$mform->setDefault('frame', true);

$mform->addElement('checkbox', 'download', get_string('enabledownload', 'hvp'));
$mform->setType('download', PARAM_BOOL);
$mform->setDefault('download', true);
$mform->disabledIf('download', 'frame');

$mform->addElement('checkbox', 'copyright', get_string('enablecopyright', 'hvp'));
$mform->setType('copyright', PARAM_BOOL);
$mform->setDefault('copyright', true);
$mform->disabledIf('copyright', 'frame');
$core = \mod_hvp\framework::instance();
$displayOptions = $core->getDisplayOptionsForEdit();
if (isset($displayOptions[\H5PCore::DISPLAY_OPTION_FRAME])) {
// Display options group.
$mform->addElement('header', 'displayoptions', get_string('displayoptions', 'hvp'));

$mform->addElement('checkbox', 'frame', get_string('enableframe', 'hvp'));
$mform->setType('frame', PARAM_BOOL);
$mform->setDefault('frame', true);

if (isset($displayOptions[\H5PCore::DISPLAY_OPTION_DOWNLOAD])) {
$mform->addElement('checkbox', 'download', get_string('enabledownload', 'hvp'));
$mform->setType('download', PARAM_BOOL);
$mform->setDefault('download', $displayOptions[\H5PCore::DISPLAY_OPTION_DOWNLOAD]);
$mform->disabledIf('download', 'frame');
}

if (isset($displayOptions[\H5PCore::DISPLAY_OPTION_COPYRIGHT])) {
$mform->addElement('checkbox', 'copyright', get_string('enablecopyright', 'hvp'));
$mform->setType('copyright', PARAM_BOOL);
$mform->setDefault('copyright', $displayOptions[\H5PCore::DISPLAY_OPTION_COPYRIGHT]);
$mform->disabledIf('copyright', 'frame');
}
}

$this->standard_coursemodule_elements();

Expand Down
13 changes: 12 additions & 1 deletion settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

require_once($CFG->dirroot . '/mod/hvp/lib.php');

// Make sure core is loaded:
$core = \mod_hvp\framework::instance('core');

// Redefine the H5P admin menu entry to be expandable.
$modltifolder = new admin_category('modhvpfolder', new lang_string('pluginname', 'mod_hvp'), $module->is_enabled() === false);
// Add the Settings admin menu entry.
Expand Down Expand Up @@ -62,10 +65,18 @@
get_string('enabledlrscontenttypes', 'hvp'),
get_string('enabledlrscontenttypes_help', 'hvp'), 0));

$choices = array(
H5PDisplayOptionBehaviour::NEVER_SHOW => get_string('displayoptionnevershow', 'hvp'),
H5PDisplayOptionBehaviour::ALWAYS_SHOW => get_string('displayoptionalwaysshow', 'hvp'),
H5PDisplayOptionBehaviour::CONTROLLED_BY_PERMISSIONS => get_string('displayoptionpermissions', 'hvp'),
H5PDisplayOptionBehaviour::CONTROLLED_BY_AUTHOR_DEFAULT_ON => get_string('displayoptionauthoron', 'hvp'),
H5PDisplayOptionBehaviour::CONTROLLED_BY_AUTHOR_DEFAULT_OFF => get_string('displayoptionauthoroff', 'hvp')
);

// Display options for H5P frame.
$settings->add(new admin_setting_heading('mod_hvp/display_options', get_string('displayoptions', 'hvp'), ''));
$settings->add(new admin_setting_configcheckbox('mod_hvp/frame', get_string('enableframe', 'hvp'), '', 1));
$settings->add(new admin_setting_configcheckbox('mod_hvp/export', get_string('enabledownload', 'hvp'), '', 1));
$settings->add(new admin_setting_configselect('mod_hvp/export', get_string('enabledownload', 'hvp'), '', H5PDisplayOptionBehaviour::ALWAYS_SHOW, $choices));
$settings->add(new admin_setting_configcheckbox('mod_hvp/copyright', get_string('enablecopyright', 'hvp'), '', 1));
$settings->add(new admin_setting_configcheckbox('mod_hvp/icon', get_string('enableabout', 'hvp'), '', 1));
}
Expand Down
27 changes: 8 additions & 19 deletions view.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,32 +65,21 @@
// Attach scripts, styles, etc. from core.
$settings = hvp_get_core_assets();

// Add global disable settings.
if (!isset($content['disable'])) {
$content['disable'] = $core->getGlobalDisable();
} else {
$content['disable'] |= $core->getGlobalDisable();
}

// Display options:
$displayOptions = $core->getDisplayOptionsForView($content['disable'], $content['id']);
// Embed is not supported in Moodle.
$content['disable'] |= \H5PCore::DISABLE_EMBED;
$displayOptions[\H5PCore::DISPLAY_OPTION_EMBED] = false;

// Filter content parameters.
$safeparameters = $core->filterParameters($content);

$export = '';
if (!isset($CFG->mod_hvp_export) || $CFG->mod_hvp_export === true) {
if ($displayOptions[\H5PCore::DISPLAY_OPTION_DOWNLOAD] && (!isset($CFG->mod_hvp_export) || $CFG->mod_hvp_export === true)) {
// Find course context.
$context = \context_course::instance($course->id);
if (has_capability('mod/hvp:getexport', $context)) {
$hvppath = "{$CFG->httpswwwroot}/pluginfile.php/{$context->id}/mod_hvp";
$exportfilename = ($content['slug'] ? $content['slug'] . '-' : '') . $content['id'] . '.h5p';
$export = "{$hvppath}/exports/{$exportfilename}";
}
}
if (empty($export)) {
// Remove Download button when there's no export URL
$content['disable'] |= \H5PCore::DISABLE_DOWNLOAD;
$hvppath = "{$CFG->httpswwwroot}/pluginfile.php/{$context->id}/mod_hvp";
$exportfilename = ($content['slug'] ? $content['slug'] . '-' : '') . $content['id'] . '.h5p';
$export = "{$hvppath}/exports/{$exportfilename}";
}

// Find cm context
Expand All @@ -104,7 +93,7 @@
'fullScreen' => $content['library']['fullscreen'],
'exportUrl' => $export,
'title' => $content['title'],
'disable' => $content['disable'],
'displayOptions' => $displayOptions,
'url' => "{$CFG->httpswwwroot}/mod/hvp/view.php?id={$id}",
'contentUrl' => "{$CFG->httpswwwroot}/pluginfile.php/{$context->id}/mod_hvp/content/" . $content['id'],
'contentUserData' => array(
Expand Down

0 comments on commit 41e22df

Please sign in to comment.