2

I am trying to execute queries on statements stored in Learning Locker via PHP and TinCanPHP API. Going by this answer, I was able to fetch a response from Learning Locker. Here is a part of the response:

TinCan\LRSResponse Object
(
    [success] => 1
    [content] => TinCan\StatementsResult Object
        (
            [statements:protected] => Array
                (
                    [0] => TinCan\Statement Object
                        (
                            [id:protected] => 9ea9e6b6-8278-4545-a02c-c46113f3ba30
                            [stored:protected] => 2016-02-28T12:04:01.670600+00:00
                            [authority:protected] => TinCan\Agent Object
                                (
                                    [objectType:protected] => Agent
                                    [name:protected] => New Client
                                    [mbox:protected] => mailto:hello@learninglocker.net
                                    [mbox_sha1sum:protected] => 
                                    [openid:protected] => 
                                    [account:protected] => 
                                )

                            [version:protected] => 1.0.0
                            [attachments:protected] => Array
                                (
                                )

                            [actor:protected] => TinCan\Agent Object
                                (
                                    [objectType:protected] => Agent
                                    [name:protected] => Subhayan Roy
                                    [mbox:protected] => mailto:subhayanroy5@gmail.com
                                    [mbox_sha1sum:protected] => 
                                    [openid:protected] => 
                                    [account:protected] => 
                                )

                            [verb:protected] => TinCan\Verb Object
                                (
                                    [id:protected] => http://activitystrea.ms/schema/1.0/search
                                    [display:protected] => TinCan\LanguageMap Object
                                        (
                                            [_map:protected] => Array
                                                (
                                                    [en-US] => Searched
                                                )

                                        )

                                )

The list of statements returned has permission protected, so I'm not being able to access them. How do I access the statements? What am I missing here?

Community
  • 1
  • 1
Poonam Anthony
  • 1,848
  • 3
  • 17
  • 27

1 Answers1

3

You need to use the methods built into the library. In this case the one you want is getStatements.

$statementResult->content->getStatements();

See the documentation here: http://rusticisoftware.github.io/TinCanPHP/doc/api/latest/classes/TinCan.StatementsResult.html#method_getStatements

To answer the question which you will ask next (Why aren't I getting all statements returned in the result?), Take a look at the Statement Result getMore method which gives you the more URL and the Remote LRS moreStatements method which accepts a more URL and fetches the next batch of statements. See this code sample: https://github.com/garemoko/TinBadgesPHP/blob/b8789042f4af23f0f7927596e8e7f2a06655db72/TinBadges/RemoteLRS.php#L84-L96

Andrew Downes
  • 1,068
  • 8
  • 20
  • 1
    thanks! that helped. going through the documentation I found out that there are methods like `$statement->getActor()->getName()`. So life is easy :) – Poonam Anthony Mar 01 '16 at 05:37
  • Andrew, so far as I can tell `getStatements()` is a method of the StatementsResult class. Poonam was evidently using the the queryStatements() method of the RemoteLRS class. Are you saying that the getStatements method is preferable for retrieving records from a remote LRS? – Grant_Bailey Oct 13 '16 at 12:21
  • 1
    No. You have to first query the statements, then get them from the returned result. I'm the same way that to make tea you need to boil the kettle and pour the water out, neither method is preferable to the other. You need to do both. – Andrew Downes Oct 18 '16 at 10:43
  • Andrew, one follow-up: in order to use the getStatements method, do you first need to invoke the StatementsResult object or is this done automatically? (Your solution seems to work without invoking the object and I was wondering why.) – Grant_Bailey Oct 24 '16 at 12:55
  • 1
    Because queryStatements returns a StatementsResult object. – Andrew Downes Oct 24 '16 at 13:59