I am trying to extract the name of an actor agent from LRS records using the Tin Can PHP library. I only have the mbox value (email address) of the person so my retrieval attempt proceeds like this:
$actor = new TinCan\Agent();
$actor
->setMbox('mailto:bob@downe.com');
// return raw statement
$retrieve = $lrs->queryStatements(['agent' => $actor]);
If I print out the value of $retrieve
I get the following raw statement (truncated for brevity):
TinCan\LRSResponse Object (
[success] => 1
[content] => TinCan\StatementsResult Object
(
[statements:protected] => Array
(
[0] => TinCan\Statement Object
(
[id:protected] => 4c707377-384d-4547-a858-61696b386b6d
[stored:protected] => 2016-10-24T15:57:43.358Z
[authority:protected] => TinCan\Agent Object
(
[objectType:protected] => Agent
[name:protected] => Grant
[mbox:protected] =>
[mbox_sha1sum:protected] =>
[openid:protected] =>
[account:protected] => TinCan\AgentAccount Object
(
[name:protected] => ###
[homePage:protected] => http://cloud.scorm.com/
)
)
[version:protected] => 1.0.0
[attachments:protected] => Array
(
)
[actor:protected] => TinCan\Agent Object
(
[objectType:protected] => Agent
[name:protected] => Bob Downe
[mbox:protected] => mailto:bob@downe.com
[mbox_sha1sum:protected] =>
[openid:protected] =>
[account:protected] =>
)
I then try to extract the name from the raw statement as follows:
// take content from raw statements using getStatements() method
$further_output = $retrieve->content->getStatements();
This produces an array of objects of the Statement class, in this case an array of one value.
I then have to get the object out of the array somehow in order to access the methods used to extract the information I want. This is how I have done it:
// Get actor out of object
$extracted = $further_output[0]->getActor()->getName();
echo "<p>$extracted</p>"; // produces 'Bob Downe'
This seems very inefficient and I am sure that there must be a better way of doing it.
I have two questions:
What is the most efficient way of extracting the information that I want?
Why does the raw statement display 'protected' for each of the properties e.g. [statements:protected], [id:protected], [stored:protected] etc?
I have studied these links of relevance but they have not resolved my issue:
how to execute a query on tin-can statements
Fetching statements from Learning Locker LRS using TinCan API
I would be grateful for any assistance.