Example #1
0
 private function getStatus(array $actions)
 {
     $errors = array();
     $return = array('sessionParam' => \RightNow\Utils\Url::sessionParameter(), 'transaction' => array());
     if ($contact = $actions['contact']) {
         if (is_object($contact) && $contact->ID) {
             $return['transaction']['contact'] = array('value' => $contact->ID);
             if ($actions['contactCreated'] && $contact->Login !== null && !$this->cookiesEnabled()) {
                 $return['redirectOverride'] = '/app/error/error_id/7';
             }
         } else {
             unset($return['transaction']);
             $errors = $contact;
         }
     }
     if (!$errors && ($incident = $actions['incident'])) {
         if (is_object($incident) && $incident->ID) {
             $return['transaction']['incident'] = Framework::isLoggedIn() ? array('key' => 'i_id', 'value' => $incident->ID) : array('key' => 'refno', 'value' => $incident->ReferenceNumber);
         } else {
             if (is_array($incident)) {
                 unset($return['transaction']);
                 if ($actions['incidentCreated']) {
                     // Smart Assistant results
                     $return['sa'] = $incident;
                     if ($actions['contactCreated'] && is_object($contact) && $contact->ID) {
                         // Generate a new token if SA results were returned and a new contact was created. A new token is needed
                         // because it's generated based off the contact ID of the logged-in user. When the first token was generated
                         // there wasn't a logged-in user, but during the first submit when SA results are returned, the user does become
                         // logged in (if a new contact was created). Therefore, during the second submit, the original token is no longer valid.
                         $return['newFormToken'] = Framework::createTokenWithExpiration(0);
                     }
                 } else {
                     $errors += $incident;
                 }
             }
         }
     }
     if (!$errors && ($asset = $actions['asset'])) {
         if (is_object($asset) && $asset->ID) {
             $return['transaction']['asset'] = array('value' => $asset->ID);
         } else {
             unset($return['transaction']);
             $errors += $asset;
         }
     }
     return $this->getResponseObject($return, 'is_array', $errors);
 }