Skip to content

Commit

Permalink
Merge pull request #38 from adlnet/Unit-testing
Browse files Browse the repository at this point in the history
Fixed issue with new func
  • Loading branch information
ADLMeganBohland authored Apr 15, 2024
2 parents 3b47946 + 66842eb commit 15fcdcf
Show file tree
Hide file tree
Showing 5 changed files with 662 additions and 59 deletions.
8 changes: 4 additions & 4 deletions classes/local/cmi5_connectors.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ public function cmi5launch_send_request_to_cmi5_player_post($databody, $url, $fi

// Sends the stream to the specified URL and stores results.
// The false is use_include_path, which we dont want in this case, we want to go to the url.
$result = $this->cmi5launch_stream_and_send( $url, $options );
$result = $this->cmi5launch_stream_and_send( $options, $url );


// Else the args are what we need for posting a course.
Expand Down Expand Up @@ -386,7 +386,7 @@ public function cmi5launch_send_request_to_cmi5_player_post($databody, $url, $fi

// Sends the stream to the specified URL and stores results.
// The false is use_include_path, which we dont want in this case, we want to go to the url.
$result = $this->cmi5launch_stream_and_send( $url, $options );
$result = $this->cmi5launch_stream_and_send( $options, $url);

}

Expand Down Expand Up @@ -418,7 +418,7 @@ public function cmi5launch_send_request_to_cmi5_player_get($token, $url) {

// Sends the stream to the specified URL and stores results.
// The false is use_include_path, which we dont want in this case, we want to go to the url.
$launchresponse = $this->cmi5launch_stream_and_send( $url, $options );
$launchresponse = $this->cmi5launch_stream_and_send( $options, $url );

$sessiondecoded = json_decode($launchresponse, true);

Expand Down Expand Up @@ -518,7 +518,7 @@ public static function cmi5launch_connectors_error_message($resulttotest, $type)
public function cmi5launch_stream_and_send($options, $url) {

// The options are placed into a stream to be sent.
$context = stream_context_create(($options));
$context = stream_context_create($options);

// Sends the stream to the specified URL and stores results.
// The false is use_include_path, which we dont want in this case, we want to go to the url.
Expand Down
40 changes: 11 additions & 29 deletions classes/local/grade_helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,40 +54,22 @@ public function cmi5launch_average_grade($scores) {
if (is_string($scores)) {

$scores = json_decode($scores, true);
echo"<br>";
echo "Scores were a string and are: ";
var_dump($scores);
echo "<br>";
}

// If it isn't an array it (array_sum) doesn't work.
if (!$scores == null && is_array($scores)) {

// Find the average of the scores.
$averagegrade = (array_sum($scores) / count($scores));
echo "<br>";
echo "Average grade in 1 branch: ";
echo $averagegrade;
echo "<br>";

} else if (!$scores == null && !is_array($scores)) {

echo "<br>";
echo "Average grade in 2 branch before it becomes average rade: ";
echo $scores;
echo "<br>";
// If it's an int, it's a single value so average is itself.
$averagegrade = $scores;

echo "<br>";
echo "Average grade in 2 branch: ";
echo $averagegrade;
echo "<br>";
} else {
$averagegrade = 0;
echo "<br>";
echo "Average grade in 3 branch: ";
echo $averagegrade;
echo "<br>";

}

// Now apply intval.
Expand Down Expand Up @@ -150,21 +132,21 @@ public function cmi5launch_check_user_grades_for_updates($user) {
// Check if record already exists.
$exists = $DB->record_exists('cmi5launch_usercourse', ['courseid' => $cmi5launch->courseid, 'userid' => $user->id]);

// If it exists, we want to update it.
// If it exists, we want to update it.
if (!$exists == false) {

// Retrieve the record.
$userscourse = $DB->get_record('cmi5launch_usercourse', ['courseid' => $cmi5launch->courseid, 'userid' => $user->id]);

// User record may be null if user has not participated in course yet.
if (!$userscourse == null) {

// Retrieve AU ids.
$auids = (json_decode($userscourse->aus));
//if (!$userscourse == null) {
// should never be null if exosts?
// Retrieve AU ids.
$auids = (json_decode($userscourse->aus));

// Array to hold AU scores.
$auscores = array();
$overallgrade = array();
// Array to hold AU scores.
$auscores = array();
$overallgrade = array();

// Go through each Au, each Au will be responsible for updating its own session.
foreach ($auids as $key => $auid) {
Expand Down Expand Up @@ -251,7 +233,7 @@ public function cmi5launch_check_user_grades_for_updates($user) {
// Update course record.
$userscourse->ausgrades = json_encode($auscores);
$DB->update_record("cmi5launch_usercourse", $userscourse);
}
// }

// Return scores.
return $overallgrade;
Expand Down
Loading

0 comments on commit 15fcdcf

Please sign in to comment.