David Ells
posted this on May 27, 2010 10:57 am
A question from a recent support ticket:
"Finally, I use Scorm Cloud. The sample application of php is great! But I have a little question..I want to do this:
$allResults = $regService->GetRegistrationList(null,$course->getIdScorm()); //Select registrations of selected course
foreach($allResults as $result){
if($result->getLearnerId()==$student->getDni()) $trobat = $result->getRegistrationId();
}
I want to do that if there are one student who has registered to this course yet, I don't want create another registration with the same course and student. But, the method "getLearnerId()" dosn't exist! How can do it?
Thanks..I hope that you understand my question (You know..my english is a little basic).
Thanks! Regreats!"
And the response...
Thanks for the interest and especially the willingness to jump in and get to coding! :) The answer to this is sort of two sided. There's bad news and good news...
The bad news is, the learner id currently isn't provided on the registration result that comes back from the cloud. Although... it should be! So, in response, I'm going to add that as a todo for our upcoming overhaul / release of SCORM cloud, and it will be available as a field on the registration you can fetch from the web service when that release becomes available in a few weeks...
The good news is, what you want to do should still be entirely possible. The design approach we had in mind when putting together the services goes like this: we expect the consumers of our web services to "own" the data, or at least the records of the data. That would mean, we would typically expect that if you're integrating with the services in your own custom application, your custom application (in addition to the web services) will keep track of what courses have been imported, what registrations have been created for those courses, and all the auxiliary information related to the registration, like learner information.
So, since we ask for a small set of learner information (learner id, learner first name, and learner last name) during the call to create a new SC registration, we should by all means be providing it when the registration information is later fetched from our services... but, having said that, you can persist that information and much more in your own tables. For example, let's say you had a table of learners and wanted to keep track of their address, something we don't persist in the services... you might have a table in your datastore for your application sort of like this:
Table: Students
Student Id | Student Name | Student Address
1 | Bob | 123 Test Drive, NY
2 | Dave | 456 Other Lane, NH
... and then, when you create a registration in SCORM Cloud for them, you would persist the information you provided during the create registration call to another table that links learners to registrations...
Table: StudentRegistrations
Student Id | (SCORM Cloud) Registration Id | (SCORM Cloud) Course Id
1 | SC_REG_0001 | SC_COURSE_001
1 | SC_REG_0002 | SC_COURSE_041
2 | SC_REG_0003 | SC_COURSE_041
1 | SC_REG_0004 | SC_COURSE_059
2 | SC_REG_0005 | SC_COURSE_059
....
...and so on. Above it shows Bob has 3 registrations for courses hosted on SCORM Cloud, while Dave has two.
Finally, let's assume you can look up records from StudentRegistrations with a call to your own application logic using a function called "getStudentRegistrations(scormRegistrationId)"... in your code, you could check for these registrations like this...
$allResults = $regService->GetRegistrationList(null,$course->getIdScorm()); //Select registrations of selected course
foreach($allResults as $result){
$myregs = getStudentRegistrations($result->getRegistrationId());
if($myregs.count > 0){
//This is where you could do some logic if the registration already exists...
} else {
//This is where you could do some logic if the registration doesn't exist...
}
}
...Ideally, all the records we have of your courses and registrations would also be persisted in your own local database, so that you have your own course table as well, and could avoid the call to GetRegistrationList, instead using a function that asked your local database for the information. This is not necessary, but will hugely increase the performance of the operation.
Finally, I know the approach above may seem more complicated than it is worth, but it would be entirely necessary if you wanted to do more complicated arbitrary logic in your application. For example, with the approach above, you could control access to creating and launching registrations for your students based on the state in their address, and do something especially custom like allowing only students in New York to launch registrations for a week, or whatever other sort of custom logic you'd want to implement...
Let me know if all that makes sense, and thanks for the feedback!
David