[英]Tin Can PHP library: processing results of query
我正在嘗試使用Tin Can PHP庫從LRS記錄中提取參與者代理的名稱。 我只有該人的mbox值(電子郵件地址),因此我的檢索嘗試是這樣進行的:
$actor = new TinCan\Agent();
$actor
->setMbox('mailto:bob@downe.com');
// return raw statement
$retrieve = $lrs->queryStatements(['agent' => $actor]);
如果我打印出$retrieve
的值, $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:bob@downe.com
[mbox_sha1sum:protected] =>
[openid:protected] =>
[account:protected] =>
)
然后,我嘗試從原始語句中提取名稱,如下所示:
// take content from raw statements using getStatements() method
$further_output = $retrieve->content->getStatements();
這將生成Statement類的對象數組,在這種情況下為一個值的數組。
然后,我必須以某種方式將對象從數組中移出,以便訪問用於提取所需信息的方法。 這是我的方法:
// Get actor out of object
$extracted = $further_output[0]->getActor()->getName();
echo "<p>$extracted</p>"; // produces 'Bob Downe'
這似乎效率很低,我相信必須有一個更好的方法。
我有兩個問題:
提取所需信息的最有效方法是什么?
為什么原始語句為每個屬性(例如[statement:protected],[id:protected],[stored:protected]等)顯示“ protected”?
我研究了這些相關的鏈接,但是它們並沒有解決我的問題:
使用TinCan API從Learning Locker LRS提取語句
我將不勝感激。
這是從庫中提取特定信息的最有效方法。 您是否覺得公共接口效率低下? 什么會更“有效”? 請注意,您需要進行錯誤檢查,換句話說,檢查請求是否成功,數組中是否有語句以及是否定義了name屬性。 該庫無法提前知道這些內容,因此,從設計上來說,該庫被認為是與LRS通信的底層接口。
這是OOP的基礎開發,請參見http://php.net/manual/zh/language.oop5.visibility.php或Google“ OOP保護”。 最終,您可以在TinCanPHP中通過公共方法訪問數據,以便我們維護封裝。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.