From 6ff756a317f171aa80a5d58dee7ea464ed0a4f2c Mon Sep 17 00:00:00 2001 From: kirkj Date: Wed, 17 Jan 2018 09:42:59 -1000 Subject: [PATCH 1/4] Add alert toggle This creates an option in the settings page that allows alerts to either be displayed as an alert or written as console.log statements. On a production site the error alerts could ruin user experience so this can be unchecked to give alerts without interferring with UX. --- src/template/settings.tpl.php | 8 ++++++++ wp-h5p-xapi.js | 7 +++++-- wp-h5p-xapi.php | 7 ++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/template/settings.tpl.php b/src/template/settings.tpl.php index 5af73a7..bd03e14 100644 --- a/src/template/settings.tpl.php +++ b/src/template/settings.tpl.php @@ -94,6 +94,14 @@ class="regular-text"/> class="regular-text"/> + + Alerts On (un-checking will make debug statements happen to console instead of alert) + + /> + + + diff --git a/wp-h5p-xapi.js b/wp-h5p-xapi.js index 1156cef..02314df 100644 --- a/wp-h5p-xapi.js +++ b/wp-h5p-xapi.js @@ -25,8 +25,11 @@ jQuery(function($) { */ function showError(message, code) { console.error("Unable to save xAPI statement"); - - alert("Unable to save result data.\n\nMessage: " + message + "\n" + "Code: " + code); + if( WP_H5P_XAPI_ALERTS == true ){ + alert("Unable to save result data.\n\nMessage: " + message + "\n" + "Code: " + code); + } else { + console.log("Unable to save result data.\n\nMessage: " + message + "\n" + "Code: " + code); + } } /** diff --git a/wp-h5p-xapi.php b/wp-h5p-xapi.php index 43f582b..f8a9556 100644 --- a/wp-h5p-xapi.php +++ b/wp-h5p-xapi.php @@ -35,7 +35,11 @@ function h5pxapi_enqueue_scripts() { $s.="WP_H5P_XAPI_STATEMENT_URL=null;"; $s.="\n"; - + + $s.= "WP_H5P_XAPI_ALERTS="; + $s .= ($settings['h5pxapi_alerts'] == "on") ? "true;" : "false;"; + $s.= "\n"; + // Permalink is not available in the admin interface. if (get_permalink()) { $s.="WP_H5P_XAPI_CONTEXTACTIVITY= { @@ -81,6 +85,7 @@ function h5pxapi_admin_init() { register_setting("h5pxapi","h5pxapi_endpoint_url"); register_setting("h5pxapi","h5pxapi_username"); register_setting("h5pxapi","h5pxapi_password"); + register_setting("h5pxapi", "h5pxapi_alerts"); } /** From ac29eeb33c152c7ca229c16a302ce78725089414 Mon Sep 17 00:00:00 2001 From: kirkj Date: Tue, 3 Apr 2018 11:53:41 -1000 Subject: [PATCH 2/4] Adjusted code to match master Upstream modified changes on code so this modifies our code to work with the way they changed theirs. --- plugin.php | 5 +++-- process-xapi-statement.php | 2 +- wp-h5p-xapi.js | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/plugin.php b/plugin.php index c33b802..d5b264e 100644 --- a/plugin.php +++ b/plugin.php @@ -17,9 +17,10 @@ function h5pxapi_get_auth_settings() { $settings=array( "endpoint_url"=>get_option("h5pxapi_endpoint_url"), "username"=>get_option("h5pxapi_username"), - "password"=>get_option("h5pxapi_password") + "password"=>get_option("h5pxapi_password"), + "alerts" => get_option("h5pxapi_alerts"), ); } return $settings; -} \ No newline at end of file +} diff --git a/process-xapi-statement.php b/process-xapi-statement.php index cfeada3..fa60747 100644 --- a/process-xapi-statement.php +++ b/process-xapi-statement.php @@ -21,7 +21,7 @@ && !$statementObject["context"]["extensions"]) unset($statementObject["context"]["extensions"]); -if (has_filter("h5p-xapi-pre-save")) { +if ( has_filter("h5p-xapi-pre-save")) { $statementObject=apply_filters("h5p-xapi-pre-save",$statementObject); if (!$statementObject) { diff --git a/wp-h5p-xapi.js b/wp-h5p-xapi.js index df3ba6d..a1bb2c6 100644 --- a/wp-h5p-xapi.js +++ b/wp-h5p-xapi.js @@ -25,7 +25,7 @@ jQuery(function($) { */ function showError(message, code) { console.error("Unable to save xAPI statement"); - if( WP_H5P_XAPI_ALERTS == true ){ + if( xapi_settings.alerts == true ){ alert("Unable to save result data.\n\nMessage: " + message + "\n" + "Code: " + code); } else { console.log("Unable to save result data.\n\nMessage: " + message + "\n" + "Code: " + code); @@ -127,4 +127,4 @@ jQuery(function($) { $("body").append("
Saving...
"); $("#wp-h5p-xapi-spinner").hide(); }); -}); \ No newline at end of file +}); From 6a8368d67c02c80e6027c96429a07b733a21e25b Mon Sep 17 00:00:00 2001 From: kirkj Date: Tue, 3 Apr 2018 13:14:23 -1000 Subject: [PATCH 3/4] Add response to post-save-filter Adds lrs response to h5p-xapi-post-save filter so that if needing to store returned uuid for later voiding are modifying this is possible. --- process-xapi-statement.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/process-xapi-statement.php b/process-xapi-statement.php index fa60747..8a30cab 100644 --- a/process-xapi-statement.php +++ b/process-xapi-statement.php @@ -95,7 +95,7 @@ exit; } -$h5pxapi_response_message = apply_filters("h5p-xapi-post-save",$statementObject); +$h5pxapi_response_message = apply_filters("h5p-xapi-post-save",$statementObject,$response); $response=array( "ok"=>1, From a324a9811f21b628b52c2f548c140ee32412fb44 Mon Sep 17 00:00:00 2001 From: kirkj Date: Wed, 4 Apr 2018 10:38:19 -1000 Subject: [PATCH 4/4] Corrected the variable being sent --- process-xapi-statement.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/process-xapi-statement.php b/process-xapi-statement.php index 8a30cab..854b8ba 100644 --- a/process-xapi-statement.php +++ b/process-xapi-statement.php @@ -95,7 +95,7 @@ exit; } -$h5pxapi_response_message = apply_filters("h5p-xapi-post-save",$statementObject,$response); +$h5pxapi_response_message = apply_filters("h5p-xapi-post-save",$statementObject,$decoded); $response=array( "ok"=>1,