php-xapi/client parse getStatements method object - php

I am using php-xapi/client library to get all the statements stored in LRS.
Code:
$results = $statementsApiClient->getStatements();
Document link:
https://github.com/php-xapi/client/blob/master/doc/statements.md
It returns the StatementResult object. But I'm not able to access it's private properties. Nothing is mentioned in their document.
Below is the output:
Xabbuh\XApi\Model\StatementResult Object
(
[statements:Xabbuh\XApi\Model\StatementResult:private] => Array
(
[0] => Xabbuh\XApi\Model\Statement Object
(
[id:Xabbuh\XApi\Model\Statement:private] => Xabbuh\XApi\Model\StatementId Object
(
[uuid:Xabbuh\XApi\Model\StatementId:private] => Rhumsaa\Uuid\Uuid Object
(
[fields:protected] => Array
(
[time_low] => e994a27f
[time_mid] => cbfe
[time_hi_and_version] => 4272
[clock_seq_hi_and_reserved] => bf
[clock_seq_low] => d7
[node] => 147d334723b3
)
)
)
[verb:Xabbuh\XApi\Model\Statement:private] => Xabbuh\XApi\Model\Verb Object
(
[id:Xabbuh\XApi\Model\Verb:private] => Xabbuh\XApi\Model\IRI Object
(
[value:Xabbuh\XApi\Model\IRI:private] => http://adlnet.gov/expapi/verbs/experienced
)
[display:Xabbuh\XApi\Model\Verb:private] => Xabbuh\XApi\Model\LanguageMap Object
(
[map:Xabbuh\XApi\Model\LanguageMap:private] => Array
(
[en-US] => experienced
)
)
)
[actor:Xabbuh\XApi\Model\Statement:private] => Xabbuh\XApi\Model\Agent Object
(
[iri:Xabbuh\XApi\Model\Actor:private] => Xabbuh\XApi\Model\InverseFunctionalIdentifier Object
(
[mbox:Xabbuh\XApi\Model\InverseFunctionalIdentifier:private] => Xabbuh\XApi\Model\IRI Object
(
[value:Xabbuh\XApi\Model\IRI:private] => mailto:cwaghmare#xento.com
)
[mboxSha1Sum:Xabbuh\XApi\Model\InverseFunctionalIdentifier:private] =>
[openId:Xabbuh\XApi\Model\InverseFunctionalIdentifier:private] =>
[account:Xabbuh\XApi\Model\InverseFunctionalIdentifier:private] =>
)
[name:Xabbuh\XApi\Model\Actor:private] => Chinmay
)
[object:Xabbuh\XApi\Model\Statement:private] => Xabbuh\XApi\Model\Activity Object
(
[id:Xabbuh\XApi\Model\Activity:private] => Xabbuh\XApi\Model\IRI Object
(
[value:Xabbuh\XApi\Model\IRI:private] => http:///68DFljpCPci
)
[definition:Xabbuh\XApi\Model\Activity:private] => Xabbuh\XApi\Model\Definition Object
(
[name:Xabbuh\XApi\Model\Definition:private] => Xabbuh\XApi\Model\LanguageMap Object
(
[map:Xabbuh\XApi\Model\LanguageMap:private] => Array
(
[und] => Video Slide 1
)
)
[description:Xabbuh\XApi\Model\Definition:private] => Xabbuh\XApi\Model\LanguageMap Object
(
[map:Xabbuh\XApi\Model\LanguageMap:private] => Array
(
[und] => Video Slide 1
)
)
[type:Xabbuh\XApi\Model\Definition:private] => Xabbuh\XApi\Model\IRI Object
(
[value:Xabbuh\XApi\Model\IRI:private] => http://adlnet.gov/expapi/activities/module
)
[moreInfo:Xabbuh\XApi\Model\Definition:private] =>
[extensions:Xabbuh\XApi\Model\Definition:private] =>
)
)
[result:Xabbuh\XApi\Model\Statement:private] =>
[authority:Xabbuh\XApi\Model\Statement:private] => Xabbuh\XApi\Model\Agent Object
(
[iri:Xabbuh\XApi\Model\Actor:private] => Xabbuh\XApi\Model\InverseFunctionalIdentifier Object
(
[mbox:Xabbuh\XApi\Model\InverseFunctionalIdentifier:private] => Xabbuh\XApi\Model\IRI Object
(
[value:Xabbuh\XApi\Model\IRI:private] => mailto:hello#learninglocker.net
)
[mboxSha1Sum:Xabbuh\XApi\Model\InverseFunctionalIdentifier:private] =>
[openId:Xabbuh\XApi\Model\InverseFunctionalIdentifier:private] =>
[account:Xabbuh\XApi\Model\InverseFunctionalIdentifier:private] =>
)
[name:Xabbuh\XApi\Model\Actor:private] => New Client
)
[created:Xabbuh\XApi\Model\Statement:private] => DateTime Object
(
[date] => 2018-04-11 06:46:15.231000
[timezone_type] => 2
[timezone] => Z
)
[stored:Xabbuh\XApi\Model\Statement:private] => DateTime Object
(
[date] => 2018-04-11 06:46:14.746000
[timezone_type] => 2
[timezone] => Z
)
[context:Xabbuh\XApi\Model\Statement:private] => Xabbuh\XApi\Model\Context Object
(
[registration:Xabbuh\XApi\Model\Context:private] =>
[instructor:Xabbuh\XApi\Model\Context:private] =>
[team:Xabbuh\XApi\Model\Context:private] =>
[contextActivities:Xabbuh\XApi\Model\Context:private] => Xabbuh\XApi\Model\ContextActivities Object
(
[parentActivities:Xabbuh\XApi\Model\ContextActivities:private] => Array
(
[0] => Xabbuh\XApi\Model\Activity Object
(
[id:Xabbuh\XApi\Model\Activity:private] => Xabbuh\XApi\Model\IRI Object
(
[value:Xabbuh\XApi\Model\IRI:private] => http://
)
[definition:Xabbuh\XApi\Model\Activity:private] =>
)
)
[groupingActivities:Xabbuh\XApi\Model\ContextActivities:private] => Array
(
[0] => Xabbuh\XApi\Model\Activity Object
(
[id:Xabbuh\XApi\Model\Activity:private] => Xabbuh\XApi\Model\IRI Object
(
[value:Xabbuh\XApi\Model\IRI:private] => http://
)
[definition:Xabbuh\XApi\Model\Activity:private] =>
)
)
[categoryActivities:Xabbuh\XApi\Model\ContextActivities:private] =>
[otherActivities:Xabbuh\XApi\Model\ContextActivities:private] =>
)
[revision:Xabbuh\XApi\Model\Context:private] =>
[platform:Xabbuh\XApi\Model\Context:private] =>
[language:Xabbuh\XApi\Model\Context:private] =>
[statement:Xabbuh\XApi\Model\Context:private] =>
[extensions:Xabbuh\XApi\Model\Context:private] =>
)
[attachments:Xabbuh\XApi\Model\Statement:private] =>
)
)
[moreUrlPath:Xabbuh\XApi\Model\StatementResult:private] => Xabbuh\XApi\Model\IRL Object
(
[value:Xabbuh\XApi\Model\IRL:private] =>
)
)
How can I access Id, Actor and Verb properties of the above StatementResult Object?
Any help would be highy appreciated.

The StatementResult object does not contain those properties, it contains a list of statements where each of those objects will then contain those properties. You would need to call $statements = $results->getStatements(); to retrieve an array of the Statement objects, then access those properties (id, actor, etc.) via the Statement class interface. The individual model classes are defined in a separate repo, see https://github.com/php-xapi/model/tree/master/src.

Related

Unable to get or display received sms using plivo token and auth id in php

I'm working on the PHP script where I want to get and display all message which is received on the plivo number?
I have already tried two different methods which are not working
Please guide how do I get the your_message_uuid which is necessary in Method 1?
Method 1
require 'vendor/autoload.php';
use Plivo\RestClient;
$client = new RestClient("auth id", "auth_token");
$response = $client->messages->get('your_message_uuid');
print_r($response);
Method 2
require 'vendor/autoload.php';
use Plivo\RestClient;
$client = new RestClient("auth id", "auth_token");
$response = $client->messages->list(
[
'limit' => 5,
'offset' => 0,
'subaccount' =>'subaccount_auth_id'
]
);
print_r($response);
// Prints only the message_uuid
print_r($response->getmessageUuid(0));
Result Using Method 1
Plivo\Resources\Message\Message Object ( [client:protected] => Plivo\BaseClient Object ( [timeout:protected] => [httpClientHandler:protected] => Plivo\HttpClients\PlivoGuzzleHttpClient Object ( [guzzleClient:protected] => GuzzleHttp\Client Object ( [config:GuzzleHttp\Client:private] => Array ( [handler] => GuzzleHttp\HandlerStack Object ( [handler:GuzzleHttp\HandlerStack:private] => Closure Object ( [static] => Array ( [default] => GuzzleHttp\Handler\CurlMultiHandler Object ( [factory:GuzzleHttp\Handler\CurlMultiHandler:private] => GuzzleHttp\Handler\CurlFactory Object ( [handles:GuzzleHttp\Handler\CurlFactory:private] => Array ( ) [maxHandles:GuzzleHttp\Handler\CurlFactory:private] => 50 ) [selectTimeout:GuzzleHttp\Handler\CurlMultiHandler:private] => 1 [active:GuzzleHttp\Handler\CurlMultiHandler:private] => [handles:GuzzleHttp\Handler\CurlMultiHandler:private] => Array ( ) [delays:GuzzleHttp\Handler\CurlMultiHandler:private] => Array ( ) [options:GuzzleHttp\Handler\CurlMultiHandler:private] => Array ( ) ) [sync] => GuzzleHttp\Handler\CurlHandler Object ( [factory:GuzzleHttp\Handler\CurlHandler:private] => GuzzleHttp\Handler\CurlFactory Object ( [handles:GuzzleHttp\Handler\CurlFactory:private] => Array ( [0] => Resource id #55 ) [maxHandles:GuzzleHttp\Handler\CurlFactory:private] => 3 ) ) ) [parameter] => Array ( [$request] => [$options] => ) ) [stack:GuzzleHttp\HandlerStack:private] => Array ( [0] => Array ( [0] => Closure Object ( [parameter] => Array ( [$handler] => ) ) [1] => http_errors ) [1] => Array ( [0] => Closure Object ( [parameter] => Array ( [$handler] => ) ) [1] => allow_redirects ) [2] => Array ( [0] => Closure Object ( [parameter] => Array ( [$handler] => ) ) [1] => cookies ) [3] => Array ( [0] => Closure Object ( [parameter] => Array ( [$handler] => ) ) [1] => prepare_body ) ) [cached:GuzzleHttp\HandlerStack:private] => Closure Object ( [static] => Array ( [handler] => GuzzleHttp\RedirectMiddleware Object ( [nextHandler:GuzzleHttp\RedirectMiddleware:private] => Closure Object ( [static] => Array ( [handler] => GuzzleHttp\PrepareBodyMiddleware Object ( [nextHandler:GuzzleHttp\PrepareBodyMiddleware:private] => Closure Object ( [static] => Array ( [default] => GuzzleHttp\Handler\CurlMultiHandler Object ( [factory:GuzzleHttp\Handler\CurlMultiHandler:private] => GuzzleHttp\Handler\CurlFactory Object ( [handles:GuzzleHttp\Handler\CurlFactory:private] => Array ( ) [maxHandles:GuzzleHttp\Handler\CurlFactory:private] => 50 ) [selectTimeout:GuzzleHttp\Handler\CurlMultiHandler:private] => 1 [active:GuzzleHttp\Handler\CurlMultiHandler:private] => [handles:GuzzleHttp\Handler\CurlMultiHandler:private] => Array ( ) [delays:GuzzleHttp\Handler\CurlMultiHandler:private] => Array ( ) [options:GuzzleHttp\Handler\CurlMultiHandler:private] => Array ( ) ) [sync] => GuzzleHttp\Handler\CurlHandler Object ( [factory:GuzzleHttp\Handler\CurlHandler:private] => GuzzleHttp\Handler\CurlFactory Object ( [handles:GuzzleHttp\Handler\CurlFactory:private] => Array ( [0] => Resource id #55 ) [maxHandles:GuzzleHttp\Handler\CurlFactory:private] => 3 ) ) ) [parameter] => Array ( [$request] => [$options] => ) ) ) ) [parameter] => Array ( [$request] => [$options] => ) ) ) ) [parameter] => Array ( [$request] => [$options] => ) ) ) [allow_redirects] => Array ( [max] => 5 [protocols] => Array ( [0] => http [1] => https ) [strict] => [referer] => [track_redirects] => ) [http_errors] => 1 [decode_content] => 1 [verify] => 1 [cookies] => [idn_conversion] => 1 [headers] => Array ( [User-Agent] => GuzzleHttp/6.5.5 curl/7.75.0 PHP/7.2.34 ) ) ) [authId:protected] => [authToken:protected] => ) [basicAuth:protected] => Plivo\Authentication\BasicAuth Object ( [authId:protected] => [authToken:protected] => ) ) [interface:protected] => [id:protected] => [pathParams:protected] => Array ( [authId] => [messageUuid] => ) [properties] => Array ( [from] => [to] => [messageDirection] => [messageState] => [messageTime] => [messageType] => [messageUuid] => [resourceUri] => [totalAmount] => [totalRate] => [units] => ) )
Empty Result Using Method 2
Check out Plivo's use case guide to receiving SMS messages. It explains how to
create a PHP app to read the message content
create a Plivo SMS app and assign the PHP app to it
assign the Plivo SMS app to a Plivo number (that will receive the
incoming SMS messages)
whenever an incoming SMS message is received on that Plivo number, Plivo
will send the details to his app server configured in the Plivo SMS
app (message URL)

Converting an nested xAPI JSON output into PHP Array

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?
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
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.

Get value with column names in cassandra

Hi I am using php with cassandra database. I am trying to get username and password from cassandra database. It return the below result.
Cassandra\Rows Object(
[columns:protected] => Array
(
[0] => Cassandra\ColumnSpec Object
(
[keyspace:protected] => team1_groupboxx
[tablename:protected] => gb_adminusers
[name:protected] => au_username
[type:protected] => Cassandra\TypeSpec Object
(
[type:protected] => 13
[customTypename:protected] =>
[keyType:protected] =>
[valueType:protected] =>
)
)
[1] => Cassandra\ColumnSpec Object
(
[keyspace:protected] => team1_groupboxx
[tablename:protected] => gb_adminusers
[name:protected] => au_password
[type:protected] => Cassandra\TypeSpec Object
(
[type:protected] => 13
[customTypename:protected] =>
[keyType:protected] =>
[valueType:protected] =>
)
)
)
[rowCount:protected] => 1
[columnCount:protected] => 2
[current:protected] => 0
[rows:protected] => Array
(
[0] => Array
(
[0] => k2badmin
[1] => f2c452187d4af19966187e15f1e944e1
)
)
)
But I want to get the query result in below format.
Array (
[au_username] => admin
[au_password] => f2c452187d4af19966187e15f1e944er
)
where au_username and au_password are the column names of my table.

How to refer to Class Objects in PHP

I need to refer to each of components like to,message-price... etc
stdClass Object (
[message-count] => 1
[messages] => Array (
[0] => stdClass Object (
[to] => 256754106703
[message-price] => 0.00700000
[status] => 0
[message-id] => 020000001AF86AE5
[remaining-balance] => 1.80010000
[network] => 64101
)
)
)
How do I do it ?
do:
echo $yourObj->messages[0]->{'message-price'};

Extracting data from this object/array? How to do it

Here is a snippet of the print off of $wp_scripts
WP_Scripts Object
(
[base_url] => http://*****
[content_url] => http://*****
[default_version] => 3.5.1
[in_footer] => Array
(
)
[concat] =>
[concat_version] =>
[do_concat] =>
[print_html] =>
[print_code] =>
[ext_handles] =>
[ext_version] =>
[default_dirs] => Array
(
[0] => /wp-admin/js/
[1] => /wp-includes/js/
)
[registered] => Array
(
[utils] => _WP_Dependency Object
(
[handle] => utils
[src] => /wp-includes/js/utils.min.js
[deps] => Array
(
)
How would i Extract some data, for example "/wp-includes/js/utils.min.js"??
Thanks
$wp_scripts->registered['utils']->src
Accessing object properties via ->
Accessing array elements via [/* String or integer here*/]
$object = new WP_Scripts;
$src = $object->registered['utils']->src;

Categories