我想從LRS記錄中使用錫罐PHP庫中提取演員代理的名稱。我只有人的MBOX值(電子郵件地址),所以我的檢索嘗試過程是這樣的:錫罐PHP庫:查詢處理結果
$actor = new TinCan\Agent();
$actor
->setMbox('mailto:[email protected]');
// return raw statement
$retrieve = $lrs->queryStatements(['agent' => $actor]);
如果我打印出來,我得到以下原始聲明(截斷簡潔)的的$retrieve
值:
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:[email protected]
[mbox_sha1sum:protected] =>
[openid:protected] =>
[account:protected] =>
)
然後我嘗試從原始聲明提取名稱如下:
// take content from raw statements using getStatements() method
$further_output = $retrieve->content->getStatements();
這將產生Statement類的對象的數組,在這個CAS e是一個值的數組。
然後,我必須以某種方式將對象從數組中取出,以訪問用於提取我想要的信息的方法。這是我如何做它:
// Get actor out of object
$extracted = $further_output[0]->getActor()->getName();
echo "<p>$extracted</p>"; // produces 'Bob Downe'
這似乎是非常低效的,我相信,一定有這樣做的更好的方法。
我有兩個問題:
什麼是提取我想要的信息的最有效方法是什麼?
爲什麼raw語句對每個屬性顯示「protected」,例如[聲明:保護],[編號:保護],[儲存:保護]等?
我已經研究了相關的這些鏈接,但他們並沒有解決我的問題:
how to execute a query on tin-can statements
Fetching statements from Learning Locker LRS using TinCan API
我會的任何援助表示感謝。
非常感謝Brian。我以爲我忽視了圖書館中的一些功能,它有非常方便的方法。關於'受保護'問題,我很高興這不是一些認證問題。很明顯,我對OOP的瞭解有很大的差距。 –