Common Objects
Params
The $params
object is assigned in every single action in any Hook. It allows you to store key-value pairs and pass them between actions.
Object Name | $params |
---|
Events | All |
---|
Actions | All |
---|
Methods
$params->set($key, $value)
- Assigns value to the specified key. It will overwrite any existing key with the same name.
$params->get($key)
- Returns stored value by key.
Example
Example
$params ->set( 'test' , 'abc123' );
$value = $params ->get( 'test' ) // returns 'abc123'
|
REST
The $rest
object is assigned in all REST hooks. It is used as a container for all HTTP requests and responses. You can use these objects to check the status of the last response and any previous request. All requests and responses are sorted by their respective labels, set in the DXP config.
Object Name | $rest |
---|
Events | REST Response Received |
---|
Actions | All |
---|
Methods
$rest->getLastRequest()
- Get the last HTTP request made. Returns a Guzzle Request Object. $rest->getLastResponse()
- Get the last HTTP response received. Returns a Guzzle Response Object. $rest->getResponse($label)
- Get the response by it's label.$rest->getRequests()
- Returns an array of all HTTP requests made$rest->getBatchId()
- Return the Batch Id for this run.$rest->getLabels()
- Returns an array of all labels.
Example
Example
$response = $rest ->getResponse( 'auth' );
if ( $response ->getStatusCode() == 200) {
// all good !
} else {
// bad response, don't copy and paste
}
|
Centre
The $centre
object is used to retrieve details relating to the current centre.
Object Name | $centre |
---|
Events | All |
---|
Actions | All |
---|
Methods
Please refer to the Centre Documentation
Example
Example
$name = $centre ->getName();
$owner = $centre ->getOwner();
|
Order
The $order
object is used to retrieve details relating to the user's order.
Object Name | $order |
---|
Events | New Order, Order Paid, Order Status Update, Installment Paid |
---|
Actions | All |
---|
Methods
Please refer to the Orders Documentation
Example
Example
$firstName = $order ->getFirstName();
$shippingPrice = $order ->getShipping();
$total = $order ->getTotal();
|
User
The $user
object is used to retrieve details relating to a user. A user object normally comes with user registration event.
Object Name | $user |
---|
Events | New User, User Updated |
---|
Actions | All |
---|
Methods
Please refer to the Users Documentation
Example
Example
$firstName = $user ->getFirstname();
$userEmail = $user ->getEmail();
$userLogin = $user ->getLogin();
|
VcsLog
The $vcsLog
is used to get details about the new build which is pushed from VCS to be deployed on a centre. This object can be used to check the status of the build, the user who created it and the centre it belongs to.
Object Name | $vcsLog |
---|
Events | VCS Commit, VCS Deploy |
---|
Actions | All |
---|
Methods
$vcsLog->getStatus()
- Returns the status of this deployment job. 1 = success, 2 = error. $vcsLog->getOwner()
- Get the name of the person who made this deploy. $vcsLog->getCentreId()
- Get the centre id for this request.$vcsLog->getPayload()
- Get payload sent by VCS.$vcsLog->getBranch
()
- Get the name of the branch pushed to.$vcsLog->getProvider
()
- Get the provider name. (eg: BitBucket github, etc)$vcsLog->getRepository
()
- Get respository name the build originated from.$vcsLog->getResult()
- Get the output from the provider. $vcsLog->getCreatedAt()
- Get the timestamp when the build was created at.$vcsLog->getCompletedAt()
- Get the timestamp when the build was completed at.$vcsLog->getId()
- Get the ID of the log.
Example
Example
$status = $vscLog ->getStatus();
if (status) {
// all good !
} else {
// bad deploy
}
|
The $form
object is used to store user data submitted in a form created with Forms module.
Object Name | $form |
---|
Events | Form Submitted |
---|
Actions | All |
---|
Public Properties
$form->id
- Unique ID of form submission (integer)$form->formId
- ID of the submitted form (integer)$form->name
- The name of the submitted form (string)$form->dateCompleted
- Timestamp of when the form was submitted (DateTime object)$form->status
- Current status of the submitted form (string)$form->fields
- A collection of field names of the form and submitted values (Collection object)$form->emails
- A collection of submitted values of the fields marked as "client e-mail address" (Collection object)
Methods
Example
Sample object JSON-encoded
{
"id" : "52573" ,
"formId" : "100" ,
"name" : "Warranty Claim" ,
"status" : "new" ,
"dateCompleted" : {
"date" : "2018-05-18 18:16:58.000000" ,
"timezone_type" : 3,
"timezone" : "Australia/Melbourne"
},
"fields" : {
"First Name" : "Dmitry" ,
"Last Name" : "Test" ,
"Address" : "348 High Street" ,
"City" : "Prahran" ,
"State" : "VIC" ,
"Zip Code" : "3148" ,
"Email Address" : "dev@coredna.com" ,
"Phone Number" : "0123456788" ,
"Product Name" : "Test" ,
"Description of the Problem" : "this is a test"
},
"emails" : {
"Email Address" : "dev@coredna.com"
},
":methods" : [
"getUser()"
]
}
|
Request
The $request
object is assigned in every single action in any Hook. It allows you use any request (form input, ajax) data within the actions. The object contains associative array that by default contains the contents of $_GET, $_POST and $_COOKIE. This allows you to perform actions such as 'user update' by setting the desired fields to update.
Object Name | $request |
---|
Events | All |
---|
Actions | All |
---|
Methods
Example
Example
$user ->setField( 'firstname' , $request ->get( 'user_firstname' ));
$user ->setField( 'address1' , $request ->get( 'user_address1' )); // set another value
$user ->updatenew(); // save
|
Log
The $log
object is used to retrieve information about a single Hook Action.
Object Name | $log |
---|
Events | HookActionFailed |
---|
Actions | All |
---|
Methods
$log->getDisplayStatus()
- Return the status of the log as one of the follow; 'Pending', 'Success', 'Failed' and 'In Progress'
$log->hasPassed()
- Return true or false if action passed
$log->hasErrored()
- Return true or false if action failed
$log->getId()
- Return the id of the log$log->getCentreId()
- Return the id of the Centre$log->getHookId()
- Return the id of the Hook$log->getActionId()
- Return the id of the Action$log->getBatchId()
- Return the id of the Batch. This will be an eight character string.$log->getEventId()
- Return the id of the Event.$log->getStatus()
- Return the status code of the log.$log->getOutput()
- Return the Output of the log as an array. The Output the is result of the action executed.$log->getPayload()
- Return the Payload of the log as an array. The Payload is all of the information a job has.$log->getCreatedAt()
- Return the Created At date.$log->getUpdatedAt()
- Return the Updated At date.
Example
Example
$pass = $log ->hasPassed();
if ( $pass ) {
// all good
} else {
// show
}
echo implode( '<br>' , $log ->getOutput());
|