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.
Related
I am getting below json data thru Shiprocket API. Now I want to extract value of below variables in PHP code from this json.
I have tried to use json_decode but it did not work and show null value:
$data = json_decode($json);
$sr_status = $data['shipment_status'];
Please suggest the code to retrieve below variables value.
shipment_status , awb_code , courier_company_id
Array
(
[0] => stdClass Object
(
[tracking_data] => stdClass Object
(
[track_status] => 1
[shipment_status] => 7
[shipment_track] => Array
(
[0] => stdClass Object
(
[id] => 180339484
[awb_code] => 11150911492
[courier_company_id] => 55
[shipment_id] => 1711169662
[order_id] => 233223781187
[pickup_date] => 2023-01-11 03:02:00
[delivered_date] => 2023-01-16 12:22:00
[weight] => 0.25
[packages] => 1
[current_status] => Delivered
[delivered_to] => Solapur
[destination] => Solapur
[consignee_name] => ABC
[origin] => Ludhiana
[courier_agent_details] =>
[edd] =>
)
)
[shipment_track_activities] => Array
(
[0] => stdClass Object
(
[date] => 2023-01-16 12:22:00
[status] => 000-T-DL
[activity] => SHIPMENT DELIVERED
[location] => SOLAPUR
[sr-status] => 7
[sr-status-label] => DELIVERED
)
[1] => stdClass Object
(
[date] => 2023-01-16 11:34:00
[status] => 002-S-UD
[activity] => SHIPMENT OUTSCAN
[location] => SOLAPUR
[sr-status] => 17
[sr-status-label] => OUT FOR DELIVERY
)
)
[track_url] => https://shiprocket.co//tracking/11150911492
[etd] => 2023-01-14 17:02:00
[qc_response] => stdClass Object
(
[qc_image] =>
[qc_failed_reason] =>
)
)
)
)
you can try this:
$array = ...; // Your array here
$data= json_decode($array);
$shipment_status = $data[0]->tracking_data->shipment_status;
$awb_code = $data[0]->tracking_data->shipment_track[0]->awb_code;
$courier_company_id = $data[0]->tracking_data->shipment_track[0]->courier_company_id;
Or use $data = json_decode($json,true); which return an array where you can use
foreach($data as $val) {
$shipment_status = $val['tracking_data']['shipment_status'];
foreach ($val['shipment_track'] as $value) {
$awb_code = $value['awb_code'];
$courier_company_id = $value['courier_company_id'];
}
}
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)
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.
This is my sample associative array:
Array (
[0] => Array (
[Name] => ALCOIN
[BasePlugin] => HTTP
[Version] => 1
[Description] => Plugin for ALCO_IN operations
[ImagePath] => ./resources
[xip] => http://www.example.org/XIP
[xsi] => http://www.w3.org/2001/XMLSchema-instance
[schemaLocation] => http://www.example.org/XIP XIP.xsd
)
[1] => Array (
[xip:Action] => Array (
[#attributes] => Array (
[Name] => OfferActivationByOfferID
[Version] => 1.0
[ImagePath] => ./resources
)
)
)
)
In that array I need to get the BasePlugin value and the name attribute value.
It seems you might need this:
$basePlugin = $yourArray[0]['BasePlugin'];
$attributes = $yourArray[1]['xip:Action']['#attributes'];
Assuming you are assigned to $yourVar like:
$yourVar = Array (
[0] => Array (
[Name] => ALCOIN
[BasePlugin] => HTTP
[Version] => 1
[Description] => Plugin for ALCO_IN operations
[ImagePath] => ./resources
[xip] => http://www.example.org/XIP
[xsi] => http://www.w3.org/2001/XMLSchema-instance
[schemaLocation] => http://www.example.org/XIP XIP.xsd
)
[1] => Array (
[xip:Action] => Array (
[#attributes] => Array (
[Name] => OfferActivationByOfferID
[Version] => 1.0
[ImagePath] => ./resources
)
)
)
)
You would use:
echo $yourVar[0]["BasePlugin"];
echo $yourVar[1]["xip:Action"]["#attributes"]["Name"];
echo $yourVar[1]["xip:Action"]["#attributes"]["Version"];
echo $yourVar[1]["xip:Action"]["#attributes"]["ImagePath"];
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;