Skip to content

Commit

Permalink
Merge pull request #47 from adlnet/better-handle-errors
Browse files Browse the repository at this point in the history
Better handle errors
  • Loading branch information
ADLMeganBohland authored Aug 15, 2024
2 parents 971b25a + 6c91c90 commit 587323b
Show file tree
Hide file tree
Showing 23 changed files with 3,728 additions and 1,236 deletions.
129 changes: 75 additions & 54 deletions AUview.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,24 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Prints an AUs session information annd allows start of new one.
* Prints an AUs session information and allows start of new one.
* @copyright 2023 Megan Bohland
* @copyright Based on work by 2013 Andrew Downes
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use mod_cmi5launch\local\session_helpers;
use mod_cmi5launch\local\customException;
use mod_cmi5launch\local\au_helpers;

require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
require('header.php');
require_once("$CFG->dirroot/lib/outputcomponents.php");


// Include the errorover (error override) funcs.
require_once ($CFG->dirroot . '/mod/cmi5launch/classes/local/errorover.php');


require_login($course, false, $cm);

global $cmi5launch, $USER;
Expand All @@ -36,7 +41,6 @@
$auhelper = new au_helpers;
$sessionhelper = new session_helpers;
$retrievesession = $sessionhelper->cmi5launch_get_retrieve_sessions_from_db();
$updatesession = $sessionhelper->cmi5launch_get_update_session();
$retrieveaus = $auhelper->get_cmi5launch_retrieve_aus_from_db();

// MB - Not currently using events, but may in future.
Expand Down Expand Up @@ -100,12 +104,10 @@ function mod_cmi5launch_launchexperience(registration) {
</script>
<?php

// Is this all necessary? Cant the data come through on its own

// Retrieve the registration and AU ID from view.php.
$fromview = required_param('AU_view', PARAM_TEXT);
// Break it into array (AU is first index).
$fromview = explode(",", $fromview);
// Retrieve AU ID.
$auid = array_shift($fromview);
$auid = required_param('AU_view', PARAM_TEXT);

// First thing check for updates.
cmi5launch_update_grades($cmi5launch, $USER->id);
Expand All @@ -122,58 +124,77 @@ function mod_cmi5launch_launchexperience(registration) {
// Reload user course instance.
$userscourse = $DB->get_record('cmi5launch_usercourse', ['courseid' => $record->courseid, 'userid' => $USER->id]);

// Retrieve the registration id.
$regid = $userscourse->registrationid;

// If it is null there have been no previous sessions.
if (!$au->sessions == null) {

// Array to hold info for table population.
$tabledata = array();
try{

// Set error and exception handler to catch and override the default PHP error messages, to make messages more user friendly.
set_error_handler('mod_cmi5launch\local\custom_warningAU', E_WARNING);
set_exception_handler('mod_cmi5launch\local\custom_warningAU');

// Array to hold info for table population.
$tabledata = array();

// Build table.
$table = new html_table();
$table->id = 'cmi5launch_auSessionTable';
$table->caption = get_string('modulenameplural', 'cmi5launch');
$table->head = array(
get_string('cmi5launchviewfirstlaunched', 'cmi5launch'),
get_string('cmi5launchviewlastlaunched', 'cmi5launch'),
get_string('cmi5launchviewprogress', 'cmi5launch'),
get_string('cmi5launchviewgradeheader', 'cmi5launch'),
);
// Build table.
$table = new html_table();
$table->id = 'cmi5launch_auSessionTable';
$table->caption = get_string('modulenameplural', 'cmi5launch');
$table->head = array(
get_string('cmi5launchviewfirstlaunched', 'cmi5launch'),
get_string('cmi5launchviewlastlaunched', 'cmi5launch'),
get_string('cmi5launchviewprogress', 'cmi5launch'),
get_string('cmi5launchviewgradeheader', 'cmi5launch'),
);

// Retrieve session ids.
$sessionids = json_decode($au->sessions);

// Iterate through each session by id.
foreach ($sessionids as $key => $sessionid) {
// Retrieve session ids.
$sessionids = json_decode($au->sessions);

// Get the session from DB with session id.
$session = $retrievesession($sessionid);
// Iterate through each session by id.
foreach ($sessionids as $key => $sessionid) {

// Array to hold data for table.
$sessioninfo = array();
// Get the session from DB with session id.
$session = $DB->get_record('cmi5launch_sessions', array('sessionid' => $sessionid));

// Retrieve createdAt and format.
$date = new DateTime($session->createdat, new DateTimeZone('US/Eastern'));
$date->setTimezone(new DateTimeZone('America/New_York'));
$sessioninfo[] = $date->format('D d M Y H:i:s');
// Array to hold data for table.
$sessioninfo = array();

// Retrieve lastRequestTime and format.
$date = new DateTime($session->lastrequesttime, new DateTimeZone('US/Eastern'));
$date->setTimezone(new DateTimeZone('America/New_York'));
$sessioninfo[] = $date->format('D d M Y H:i:s');
if ($session->createdat != null) {

// Add progress to table.
$sessioninfo[] = ("<pre>" . implode("\n ", json_decode($session->progress) ) . "</pre>");
// Retrieve createdAt and format.
$date = new DateTime($session->createdat, new DateTimeZone('US/Eastern'));
$date->setTimezone(new DateTimeZone('America/New_York'));
// date_timezone_set($date, new DateTimeZone('America/New_York'));
$sessioninfo[] = $date->format('D d M Y H:i:s');
}

if ($session->lastrequesttime != null) {

// Retrieve lastRequestTime and format.
$date = new DateTime($session->lastrequesttime, new DateTimeZone('US/Eastern'));
$date->setTimezone(new DateTimeZone('America/New_York'));
$sessioninfo[] = $date->format('D d M Y H:i:s');
}
// Add progress to table.
$sessioninfo[] = ("<pre>" . implode("\n ", json_decode($session->progress)) . "</pre>");

// Add score to table.
$sessioninfo[] = $session->score;
// Add score to array for AU.
$sessionscores[] = $session->score;
// Add score to table.
$sessioninfo[] = $session->score;
// Add score to array for AU.
$sessionscores[] = $session->score;

// Add to be fed to table.
$tabledata[] = $sessioninfo;
// Add to be fed to table.
$tabledata[] = $sessioninfo;
}
} catch (Exception $e) {

// Restore default hadlers.
restore_exception_handler();
restore_error_handler();

// Throw an exception.
throw new customException('loading session table on AUview page. Report this to system administrator: ' . $e->getMessage() . 'Check that session information is present in DB and session id is correct.' , 0);
}

// Write table.
Expand All @@ -182,17 +203,17 @@ function mod_cmi5launch_launchexperience(registration) {

// Update AU in table with new info.
$DB->update_record('cmi5launch_aus', $au);
}

// Build the new session link.
$newsession = "true";
// Create a string to pass the auid and new session info to next page (launch.php).
$infofornextpage = $auid . "," . $newsession;
// Restore default hadlers.
restore_exception_handler();
restore_error_handler();
}

// Pass the auid and new session info to next page (launch.php).
// New attempt button.
echo "<p tabindex=\"0\"onkeyup=\"key_test('"
. $infofornextpage . "')\"id='cmi5launch_newattempt'><button onclick=\"mod_cmi5launch_launchexperience('"
. $infofornextpage
. $auid . "')\"id='cmi5launch_newattempt'><button onclick=\"mod_cmi5launch_launchexperience('"
. $auid
. "')\" style=\"cursor: pointer;\">"
. get_string('cmi5launch_attempt', 'cmi5launch')
. "</button></p>";
Expand Down
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@ cmi5launch




A plug in for Moodle that enables tracking for cmi5 content.This plugin acts as a bridge between Moodle and a cmi5 player, as well as Moodle and an LRS, enabling recording and tracking of cmi5 statements. It utilizes the CATAPULT suite's cmi5 player which launches the content as well as handles AU satisfication statements. It also links with an LRS to display those statements and others generated by moodle.


A plug in for Moodle that enables tracking for cmi5 content.This polugin acts as a bridge between Moodle and a cmi5 player, as well as Moodle and an LRS, enabling recording and tracking of cmi5 statements. It utilizes the CATAPULT suite's cmi5 player which launches the content as well as handles AU satisfication statements. It also links with an LRS to display those statements and others generated by moodle.

Users can upload the cmi5 content as a Moodle activity. It also integrates with Moodles Gradebook API for grading purposes.




### Thanks


Expand Down
Loading

0 comments on commit 587323b

Please sign in to comment.