Skip to content
This repository has been archived by the owner on Sep 28, 2020. It is now read-only.

Commit

Permalink
Merge pull request #6 from cjcox17/master
Browse files Browse the repository at this point in the history
Update to support offsets in search()
  • Loading branch information
Chris-Pratt-Clystnet authored Nov 14, 2018
2 parents 817c9a9 + 640d34d commit a0e6900
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions src/Vtiger.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __construct()
2 => new VtigerErrorElement('Success property not set on VTiger response', 2),
3 => new VtigerErrorElement('Error property not set on VTiger response when success is false', 3),
4 => new VtigerErrorElement('There are no search fields in the array', 4),
5 => new VtigerErrorElement('Could not complete login request within ' . $this->maxRetries . ' tries', 5),
5 => new VtigerErrorElement('Could not complete login request within ' . $this->maxRetries . ' tries', 5),
6 => new VtigerErrorElement(
'Could not complete get token request within ' . $this->maxRetries . ' tries',
6
Expand Down Expand Up @@ -153,8 +153,8 @@ protected function login($sessionData)
'form_params' => [
'operation' => 'login',
'username' => $this->username,
'accessKey' => $generatedKey
]
'accessKey' => $generatedKey,
],
]);
} catch (GuzzleException $e) {
throw VtigerError::init($this->vTigerErrors, 7, $e->getMessage());
Expand Down Expand Up @@ -231,8 +231,8 @@ protected function getToken()
$response = $this->guzzleClient->request('GET', $this->url, [
'query' => [
'operation' => 'getchallenge',
'username' => $this->username
]
'username' => $this->username,
],
]);
} catch (GuzzleException $e) {
throw VtigerError::init($this->vTigerErrors, 7, $e->getMessage());
Expand Down Expand Up @@ -279,8 +279,8 @@ protected function close($sessionId)
[
'query' => [
'operation' => 'logout',
'sessionName' => $sessionId
]
'sessionName' => $sessionId,
],
]
);
} catch (GuzzleException $e) {
Expand Down Expand Up @@ -308,8 +308,8 @@ public function query($query)
'query' => [
'operation' => 'query',
'sessionName' => $sessionId,
'query' => $query
]
'query' => $query,
],
]);
} catch (GuzzleException $e) {
throw VtigerError::init($this->vTigerErrors, 7, $e->getMessage());
Expand All @@ -332,6 +332,18 @@ public function search($query, $quote = true)
$queryString = preg_replace('/\?/', $binding, $queryString, 1);
}
}

//In the event there is a offset, append it to the front of the limit
//Vtiger does not support the offset keyword
$matchOffset = [];
$matchLimit = [];
if (preg_match('/(\s[o][f][f][s][e][t]) (\d*)/', $queryString, $matchOffset) && preg_match('/(\s[l][i][m][i][t]) (\d*)/', $queryString, $matchLimit)) {
$queryString = preg_replace('/(\s[o][f][f][s][e][t]) (\d*)/', '', $queryString);
$queryString = preg_replace('/(\s[l][i][m][i][t]) (\d*)/', '', $queryString);
$queryString = $queryString . ' limit ' . $matchOffset[2] . ',' . $matchLimit[2];
}

//Remove the backticks and add simicolon
$queryString = str_replace('`', '', $queryString) . ';';

return $this->query($queryString);
Expand All @@ -356,8 +368,8 @@ public function retrieve($id)
'query' => [
'operation' => 'retrieve',
'sessionName' => $sessionId,
'id' => $id
]
'id' => $id,
],
]);
} catch (GuzzleException $e) {
throw VtigerError::init($this->vTigerErrors, 7, $e->getMessage());
Expand Down Expand Up @@ -398,8 +410,8 @@ public function create($elem, $data)
'operation' => 'create',
'sessionName' => $sessionId,
'element' => $data,
'elementType' => $elem
]
'elementType' => $elem,
],
]);
} catch (GuzzleException $e) {
throw VtigerError::init($this->vTigerErrors, 7, $e->getMessage());
Expand Down Expand Up @@ -431,7 +443,7 @@ public function update($object)
'operation' => 'update',
'sessionName' => $sessionId,
'element' => json_encode($object),
]
],
]);
} catch (GuzzleException $e) {
throw VtigerError::init($this->vTigerErrors, 7, $e->getMessage());
Expand Down Expand Up @@ -461,8 +473,8 @@ public function delete($id)
'query' => [
'operation' => 'delete',
'sessionName' => $sessionId,
'id' => $id
]
'id' => $id,
],
]);
} catch (GuzzleException $e) {
throw VtigerError::init($this->vTigerErrors, 7, $e->getMessage());
Expand Down Expand Up @@ -494,8 +506,8 @@ public function describe($elementType)
'query' => [
'operation' => 'describe',
'sessionName' => $sessionId,
'elementType' => $elementType
]
'elementType' => $elementType,
],
]
);
} catch (GuzzleException $e) {
Expand Down

0 comments on commit a0e6900

Please sign in to comment.