Skip to content

Commit

Permalink
Finished updating code with try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
ADLMeganBohland committed Aug 15, 2024
1 parent f6db111 commit 58f5601
Show file tree
Hide file tree
Showing 4 changed files with 258 additions and 181 deletions.
1 change: 0 additions & 1 deletion AUview.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ function mod_cmi5launch_launchexperience(registration) {
// Array to hold data for table.
$sessioninfo = array();


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

// Retrieve createdAt and format.
Expand Down
15 changes: 15 additions & 0 deletions classes/local/errorover.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,21 @@ function custom_warning($errno, $errstr, $errfile, $errline)

}

/**
* An warning handler to use to post better warnings to users for troubleshooting.
* @param mixed $errno
* @param mixed $errstr
* @param mixed $errfile
* @param mixed $errline
* @throws \mod_cmi5launch\local\nullException
* @return never
*/
function custom_warningview($errno, $errstr, $errfile, $errline)
{

throw new customException('error on main view page. Report this to system administrator: <br> '. $errstr .' at '. $errfile .' on ' .$errline, 0);

}
/**
* An exception handler to use in AU cases when many different exceptions for data errors may be thrown.
* @param mixed $errno
Expand Down
20 changes: 20 additions & 0 deletions classes/local/session_helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,22 @@ public function cmi5launch_update_sessions($progress, $cmi5, $sessionid, $cmi5la
$sessioninfo = json_decode($getsessioninfo($sessionid, $cmi5launchid), true);
// Update session.
foreach ($sessioninfo as $key => $value) {

// Is the problem key value is not matching due to caps?
// We don't want to overwrite ids.
// If the property exists and it's not id or sessionid, set it to lowercase and
// encode value if it is array. (DB needs properties in lowercase, but player returns camelcase).


// If it's an array, encode it so it can be saved to DB.
if (is_array($value)) {
$value = json_encode($value);
}

if (is_string($key)) {
$key = mb_convert_case($key, MB_CASE_LOWER, "UTF-8");
}

if (property_exists($session, $key) && $key != 'id' && $key != 'sessionid') {

// If it's an array, encode it so it can be saved to DB.
Expand Down Expand Up @@ -152,6 +165,13 @@ public function cmi5launch_create_session($sessionid, $launchurl, $launchmethod)
// Save record to table.
$newid = $DB->insert_record($table, $newrecord, true);

// Instantiate progress and cmi5_connectors class to pass.
$progress = new progress;
$cmi5 = new cmi5_connectors;

// Retrieve new info (if any) from CMI5 player and LRS on session.
$session = $this->cmi5launch_update_sessions($progress, $cmi5, $sessionid, $cmi5launch->id, $USER);

// Restore default handlers.
restore_exception_handler();
restore_error_handler();
Expand Down
Loading

0 comments on commit 58f5601

Please sign in to comment.