-1
Array
(
    [0] => TinCan\Statement Object
        (
            [id:protected] => 0a53e06c-64a7-4902-930e-993bb228cd49
            [stored:protected] => 2018-02-24T04:21:22.456Z
            [authority:protected] => TinCan\Agent Object
                (
                    [objectType:protected] => Agent
                    [name:protected] => sabarish
                    [mbox:protected] => 
                    [mbox_sha1sum:protected] => 
                    [openid:protected] => 
                    [account:protected] => TinCan\AgentAccount Object
                        (
                            [name:protected] => 248a06f20aa62f
                            [homePage:protected] => https://sandbox.watershedlrs.com
                        )
            )

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

        [actor:protected] => TinCan\Agent Object
            (
                [objectType:protected] => Agent
                [name:protected] => Akshaya Manikandan
                [mbox:protected] => mailto:aksh.m14@gmail.com
                [mbox_sha1sum:protected] => 
                [openid:protected] => 
                [account:protected] => 
            )

        [verb:protected] => TinCan\Verb Object
            (
                [id:protected] => http://adlnet.gov/expapi/verbs/skipped
                [display:protected] => TinCan\LanguageMap Object
                    (
                        [_map:protected] => Array
                            (
                                [en] => skipped
                            )

                    )

            )

        [target:protected] => TinCan\Activity Object
            (
                [objectType:TinCan\Activity:private] => Activity
                [id:protected] => https://app.acuizen.com/populate_form/965/1573/4690
                [definition:protected] => 
            )

        [result:protected] => 
        [context:protected] => TinCan\Context Object
            (
                [registration:protected] => 
                [instructor:protected] => 
                [team:protected] => 
                [contextActivities:protected] => TinCan\ContextActivities Object
                    (
                        [category:protected] => Array
                            (
                                [0] => TinCan\Activity Object
                                    (
                                        [objectType:TinCan\Activity:private] => Activity
                                        [id:protected] => http://acuizen.com/ActivitySkipped
                                        [definition:protected] => TinCan\ActivityDefinition Object
                                            (
                                                [type:protected] => http://id.tincanapi.com/activitytype/Assignment
                                                [name:protected] => TinCan\LanguageMap Object
                                                    (
                                                        [_map:protected] => Array
                                                            (
                                                            )

                                                    )

                                                [description:protected] => TinCan\LanguageMap Object
                                                    (
                                                        [_map:protected] => Array
                                                            (
                                                            )

                                                    )

                                                [moreInfo:protected] => 
                                                [extensions:protected] => TinCan\Extensions Object
                                                    (
                                                        [_map:protected] => Array
                                                            (
                                                            )

                                                    )

                                                [interactionType:protected] => 
                                                [correctResponsesPattern:protected] => 
                                                [choices:protected] => 
                                                [scale:protected] => 
                                                [source:protected] => 
                                                [target:protected] => 
                                                [steps:protected] => 
                                            )

                                    )

                            )

                        [parent:protected] => Array
                            (
                            )

                        [grouping:protected] => Array
                            (
                            )

                        [other:protected] => Array
                            (
                            )

                    )

                [revision:protected] => 
                [platform:protected] => 
                [language:protected] => 
                [statement:protected] => 
                [extensions:protected] => TinCan\Extensions Object
                    (
                        [_map:protected] => Array
                            (
                            )

                    )

            )

        [timestamp:protected] => 2018-02-24T04:21:22.456Z
    )

... + 100 more like these.

I get this output after running my php code to retrive all information from the LRS. How to change this into PHP ARRAY?

slash197
  • 9,028
  • 6
  • 41
  • 70
  • Is there some kind of SDK in play that you're getting that kind of structure? Because i'm sure there's a bunch of getters documented for whatever those objects are. – Scuzzy Feb 24 '18 at 09:44
  • http://rusticisoftware.github.io/TinCanPHP/ looks like something that needs reading. – Scuzzy Feb 24 '18 at 09:48
  • @Scuzzy No SDK. I just sent the data through PHP statements into the LRS and when I retrieve the same, I get this. Also the given link doesn't have any reference to converting the JSON output to PHP Array – sabarish swaminathan Feb 24 '18 at 09:54
  • syntax like `[context:protected] => TinCan\Context Object` leads to to belive there's a class definition _somewhere_? – Scuzzy Feb 24 '18 at 10:04
  • @Scuzzy Nope. Doesn't have anything to deal with classes and objects. Those are inner notations to the LRS I use. All I want is the name, mbox,verb id, and the object ID – sabarish swaminathan Feb 24 '18 at 10:09
  • What you are showing us is 100% the notation of an array of objects bound to a class, do you see that though?, it has protected properties which are not accessible except form within the class itself or if you start messing with the php reflection class. Can you please show code examples on how you call this API? – Scuzzy Feb 24 '18 at 10:39
  • queryStatements(null); return $answer; } $arr = getAllActivity()->content->getStatements(); echo "
    ";
      print_r($arr);
      echo "
    "; ?>
    – sabarish swaminathan Feb 24 '18 at 10:45
  • what libraries exist as part of `autoload.php`? are you using composer? Are you using this? https://rusticisoftware.github.io/TinCanPHP/ – Scuzzy Feb 24 '18 at 10:46
  • Yes. Using that only – sabarish swaminathan Feb 24 '18 at 10:54
  • I've posted an aswer with an example of how to extract one of the pices of data from the API. – Scuzzy Feb 24 '18 at 11:10

2 Answers2

0

Without your php code I can only assume you are using json_decode($response) instead of json_decode($response, true). Second parameter in this function decides whether to decode into a class as you have or simple array.

slash197
  • 9,028
  • 6
  • 41
  • 70
0

You need to learn how to use their API documentation, There is no simple "get all the data" that I can see because everything is wrapped in a class with private/protected properties....

Using your provided sample, here is an example of how to "get the actors"

$Statements = getAllActivity()->content->getStatements();

foreach( $Statements as $Statement )
{
  print_r( $Statement->getActor() );
  print_r( $Statement->getActor()->getName() );
  print_r( $Statement->getActor()->getMbox() );
}

Review the script \src\StatementBase.php, this is where I found the getAcator() method

Scuzzy
  • 12,186
  • 1
  • 46
  • 46