Skip to content

Commit

Permalink
Merge pull request #17 from RusticiSoftware/br-fix-learner-update
Browse files Browse the repository at this point in the history
Fixes Learner Update for v2 API.
  • Loading branch information
brianrogers authored Oct 13, 2021
2 parents d51e96d + 2cf5999 commit 612d1bb
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
14 changes: 14 additions & 0 deletions scormcloud/SCORMCloud_PHPLibrary/ScormEngineService2.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
require_once 'v2/Api/PingApi.php';
require_once 'v2/Api/DispatchApi.php';
require_once 'v2/Api/XapiApi.php';
require_once 'v2/Api/LearnerApi.php';

require_once 'v2/Model/ModelInterface.php';
require_once 'v2/Model/PingSchema.php';
Expand Down Expand Up @@ -86,6 +87,7 @@ class ScormEngineService
private $_dispatchService = null;
private $_invitationService = null;
private $_lrsAccountService = null;
private $_learnerService = null;

public function __construct($scormEngineServiceUrl, $appId, $securityKey, $originString, $proxy = null)
{
Expand All @@ -101,6 +103,7 @@ public function __construct($scormEngineServiceUrl, $appId, $securityKey, $origi
$this->_dispatchService = new RusticiSoftware\Cloud\V2\Api\DispatchApi(null, $this->_configuration, null);
$this->_invitationService = new RusticiSoftware\Cloud\V2\Api\InvitationsApi(null, $this->_configuration, null);
$this->_lrsAccountService = new RusticiSoftware\Cloud\V2\Api\XapiApi(null, $this->_configuration, null);
$this->_learnerService = new RusticiSoftware\Cloud\V2\Api\LearnerApi(null, $this->_configuration, null);
}

public function isValidAccount()
Expand Down Expand Up @@ -231,6 +234,17 @@ public function getLrsAccountService()
return $this->_lrsAccountService;
}

/**
* <summary>
* Contains SCORM Engine Learner functionality.
* </summary>
*/
public function getLearnerService()
{
return $this->_learnerService;
}


/**
* <summary>
* The Application ID obtained by registering with the SCORM Engine Service
Expand Down
8 changes: 7 additions & 1 deletion scormcloud/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: troyef, stuartchilds, timedwards, brianrogers
Tags: elearning, learning, scorm, aicc, education, training, cloud
Requires at least: 4.3
Tested up to: 5.8
Stable tag: 2.0.0
Stable tag: 2.0.1

Tap the power of SCORM to deliver and track training right from your WordPress-powered site.

Expand Down Expand Up @@ -48,6 +48,9 @@ The SCORM Cloud For WordPress basic functionality works with BuddyPress without


== Changelog ==
= 2.0.1 =
* Fixes bug with updating Learner info.

= 2.0.0 =
* Update to SCORM Cloud API v2.

Expand Down Expand Up @@ -156,6 +159,9 @@ The SCORM Cloud For WordPress basic functionality works with BuddyPress without
* Original Release.

== Upgrade Notice ==
= 2.0.1 =
* Fixes bug with updating Learner info.

= 2.0.0 =
* Updates to v2 Cloud API
* Updates Upload process
Expand Down
2 changes: 1 addition & 1 deletion scormcloud/scormcloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Plugin URI: http://scorm.com/wordpress
Description: Tap the power of SCORM to deliver and track training right from your WordPress-powered site. Just add the SCORM Cloud widget to the sidebar or use the SCORM Cloud button to add a link directly in a post or page.
Author: Rustici Software
Version: 2.0.0
Version: 2.0.1
Author URI: http://www.scorm.com
*/

Expand Down
15 changes: 12 additions & 3 deletions scormcloud/scormcloudcontenthandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,23 @@ public static function update_post_invite( $post_id ) {
public static function update_learner_info( $user_id ) {
global $wpdb;
$cloud_service = ScormCloudPlugin::get_cloud_service();
$registration_service = $cloud_service->getRegistrationService();
$learner_service = $cloud_service->getLearnerService();
$user_data = get_userdata( $user_id );
/* pushing blank data into SCORMCloud generates a stack trace */
if ( ! empty( $user_data->user_firstname ) &&
! empty( $user_data->user_lastname )
) {
$response = $registration_service->UpdateLearnerInfo( $user_data->user_email, $user_data->user_firstname, $user_data->user_lastname );
write_log( $response );
$learner_schema = new \RusticiSoftware\Cloud\v2\Model\LearnerSchema();
$learner_schema->setId($user_data->user_email);
$learner_schema->setEmail($user_data->user_email);
$learner_schema->setFirstName($user_first_name);
$learner_schema->setLastName($user_last_name);
try {
$response = $learner_service->updateLearnerInfo( $user_data->user_email, $learner_schema );
} catch (Exception $ex) {
// Ignore this since we don't really mind if cloud is updated if the ID isn't found.
// Wordpress will still be updated either way
}
} else {
write_log( "profile update skipped for {$user_data->user_email} due to missing first or last name" );
}
Expand Down
2 changes: 1 addition & 1 deletion scormcloud/scormcloudplugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static function get_cloud_service( $force_network_settings = false ) {
$proxy = get_option( 'proxy' );
}

$origin = ScormEngineUtilities::getCanonicalOriginString( 'Rustici Software', 'WordPress', '2.0.0' );
$origin = ScormEngineUtilities::getCanonicalOriginString( 'Rustici Software', 'WordPress', '2.0.1' );

if ( strlen( $engine_url ) < 1 ) {
$engine_url = 'https://cloud.scorm.com/api/v2';
Expand Down

0 comments on commit 612d1bb

Please sign in to comment.