@@ -244,6 +244,7 @@ discard block |
||
244 | 244 | * @access public |
245 | 245 | * @static |
246 | 246 | * @param array $params Array holding entity data/search constraints |
247 | + * @param string $paramsPurpose |
|
247 | 248 | * @return boolean Returns true if params holds valid entity data/search constraints, otherwise returns false |
248 | 249 | */ |
249 | 250 | private static function checkParams(array $params, $paramsPurpose) |
@@ -263,8 +264,8 @@ discard block |
||
263 | 264 | * @static |
264 | 265 | * @param string $moduleName The name of the module / entity type |
265 | 266 | * @param array $params Data used to find matching entries |
266 | - * @return array $select The list of fields to select (defaults to SQL-like '*' - all the fields) |
|
267 | - * @return int $limit limit the list of entries to N records (acts like LIMIT in SQL) |
|
267 | + * @return string $select The list of fields to select (defaults to SQL-like '*' - all the fields) |
|
268 | + * @return string $limit limit the list of entries to N records (acts like LIMIT in SQL) |
|
268 | 269 | * @return string The query build out of the supplied parameters |
269 | 270 | */ |
270 | 271 | public static function getQueryString($moduleName, array $params, array $select = [], $limit = 0) |
@@ -32,7 +32,6 @@ |
||
32 | 32 | namespace Salaros\Vtiger\VTWSCLib; |
33 | 33 | |
34 | 34 | use Salaros\Vtiger\VTWSCLib\WSClient; |
35 | -use Salaros\Vtiger\VTWSCLib\EntityUtils; |
|
36 | 35 | |
37 | 36 | /** |
38 | 37 | * Vtiger Web Services PHP Client Session class |
@@ -240,12 +240,12 @@ |
||
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
243 | - * Checks if if params holds valid entity data/search constraints, otherwise returns false |
|
244 | - * @access public |
|
245 | - * @static |
|
246 | - * @param array $params Array holding entity data/search constraints |
|
247 | - * @return boolean Returns true if params holds valid entity data/search constraints, otherwise returns false |
|
248 | - */ |
|
243 | + * Checks if if params holds valid entity data/search constraints, otherwise returns false |
|
244 | + * @access public |
|
245 | + * @static |
|
246 | + * @param array $params Array holding entity data/search constraints |
|
247 | + * @return boolean Returns true if params holds valid entity data/search constraints, otherwise returns false |
|
248 | + */ |
|
249 | 249 | private static function checkParams(array $params, $paramsPurpose) |
250 | 250 | { |
251 | 251 | if (empty($params) || !is_array($params) || !is_assoc_array($params)) { |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * @return array $select The list of fields to select (defaults to SQL-like '*' - all the fields) |
61 | 61 | * @return boolean Entity data |
62 | 62 | */ |
63 | - public function findOneByID($moduleName, $entityID, array $select = []) |
|
63 | + public function findOneByID($moduleName, $entityID, array $select = [ ]) |
|
64 | 64 | { |
65 | 65 | return $this->findOne($moduleName, [ 'id' => $entityID ], $select); |
66 | 66 | } |
@@ -72,13 +72,13 @@ discard block |
||
72 | 72 | * @return array $select The list of fields to select (defaults to SQL-like '*' - all the fields) |
73 | 73 | * @return integer The matching record |
74 | 74 | */ |
75 | - public function findOne($moduleName, array $params, array $select = []) |
|
75 | + public function findOne($moduleName, array $params, array $select = [ ]) |
|
76 | 76 | { |
77 | 77 | $records = $this->findMany($moduleName, $params, $select, 1); |
78 | - if (false === $records || !isset($records[0])) { |
|
78 | + if (false === $records || !isset($records[ 0 ])) { |
|
79 | 79 | return false; |
80 | 80 | } |
81 | - return $records[0]; |
|
81 | + return $records[ 0 ]; |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -89,11 +89,11 @@ discard block |
||
89 | 89 | */ |
90 | 90 | public function getID($moduleName, array $params) |
91 | 91 | { |
92 | - $record = $this->findOne($moduleName, $params, ['id']); |
|
93 | - if (false === $record || !isset($record['id']) || empty($record['id'])) { |
|
92 | + $record = $this->findOne($moduleName, $params, [ 'id' ]); |
|
93 | + if (false === $record || !isset($record[ 'id' ]) || empty($record[ 'id' ])) { |
|
94 | 94 | return false; |
95 | 95 | } |
96 | - return $record['id']; |
|
96 | + return $record[ 'id' ]; |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | $entityID = $this->getID($moduleName, $params); |
108 | 108 | $entityIDParts = explode('x', $entityID, 2); |
109 | 109 | return (is_array($entityIDParts) && count($entityIDParts) === 2) |
110 | - ? intval($entityIDParts[1]) |
|
110 | + ? intval($entityIDParts[ 1 ]) |
|
111 | 111 | : -1; |
112 | 112 | } |
113 | 113 | |
@@ -124,9 +124,9 @@ discard block |
||
124 | 124 | } |
125 | 125 | |
126 | 126 | // Assign record to logged in user if not specified |
127 | - if (!isset($params['assigned_user_id'])) { |
|
127 | + if (!isset($params[ 'assigned_user_id' ])) { |
|
128 | 128 | $currentUser = $this->wsClient->getCurrentUser(); |
129 | - $params['assigned_user_id'] = $currentUser['id']; |
|
129 | + $params[ 'assigned_user_id' ] = $currentUser[ 'id' ]; |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | $requestData = [ |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | * @return integer $limit limit the list of entries to N records (acts like LIMIT in SQL) |
200 | 200 | * @return bool|array The array containing matching entries or false if nothing was found |
201 | 201 | */ |
202 | - public function findMany($moduleName, array $params, array $select = [], $limit = 0) |
|
202 | + public function findMany($moduleName, array $params, array $select = [ ], $limit = 0) |
|
203 | 203 | { |
204 | 204 | if (!self::checkParams($params, 'be able to retrieve entity(ies)')) { |
205 | 205 | return false; |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | ]; |
235 | 235 | |
236 | 236 | if (!empty($moduleName)) { |
237 | - $requestData['elementType'] = $moduleName; |
|
237 | + $requestData[ 'elementType' ] = $moduleName; |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | return $this->wsClient->invokeOperation('sync', $requestData, true); |
@@ -268,18 +268,18 @@ discard block |
||
268 | 268 | * @return int $limit limit the list of entries to N records (acts like LIMIT in SQL) |
269 | 269 | * @return string The query build out of the supplied parameters |
270 | 270 | */ |
271 | - public static function getQueryString($moduleName, array $params, array $select = [], $limit = 0) |
|
271 | + public static function getQueryString($moduleName, array $params, array $select = [ ], $limit = 0) |
|
272 | 272 | { |
273 | 273 | $criteria = array(); |
274 | - $select=(empty($select)) ? '*' : implode(',', $select); |
|
275 | - $query=sprintf("SELECT %s FROM $moduleName WHERE ", $select); |
|
274 | + $select = (empty($select)) ? '*' : implode(',', $select); |
|
275 | + $query = sprintf("SELECT %s FROM $moduleName WHERE ", $select); |
|
276 | 276 | foreach ($params as $param => $value) { |
277 | - $criteria[] = "{$param} LIKE '{$value}'"; |
|
277 | + $criteria[ ] = "{$param} LIKE '{$value}'"; |
|
278 | 278 | } |
279 | 279 | |
280 | - $query.=implode(" AND ", $criteria); |
|
280 | + $query .= implode(" AND ", $criteria); |
|
281 | 281 | if (intval($limit) > 0) { |
282 | - $query.=sprintf(" LIMIT %s", intval($limit)); |
|
282 | + $query .= sprintf(" LIMIT %s", intval($limit)); |
|
283 | 283 | } |
284 | 284 | return $query; |
285 | 285 | } |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | ); |
108 | 108 | } |
109 | 109 | |
110 | - $params['operation'] = $operation; |
|
110 | + $params[ 'operation' ] = $operation; |
|
111 | 111 | return $this->session->sendHttpRequest($params, $method); |
112 | 112 | } |
113 | 113 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | public function runQuery($query) |
127 | 127 | { |
128 | 128 | // Make sure the query ends with ; |
129 | - $query = (strripos($query, ';') != strlen($query)-1) |
|
129 | + $query = (strripos($query, ';') != strlen($query) - 1) |
|
130 | 130 | ? trim($query .= ';') |
131 | 131 | : trim($query); |
132 | 132 |
@@ -59,12 +59,12 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public function getAll() |
61 | 61 | { |
62 | - $result = $this->wsClient->invokeOperation('listtypes', [], 'GET'); |
|
63 | - $modules = $result['types']; |
|
62 | + $result = $this->wsClient->invokeOperation('listtypes', [ ], 'GET'); |
|
63 | + $modules = $result[ 'types' ]; |
|
64 | 64 | |
65 | 65 | $result = array(); |
66 | 66 | foreach ($modules as $moduleName) { |
67 | - $result[$moduleName] = ['name' => $moduleName]; |
|
67 | + $result[ $moduleName ] = [ 'name' => $moduleName ]; |
|
68 | 68 | } |
69 | 69 | return $result; |
70 | 70 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | */ |
90 | 90 | public function getTypedID($moduleName, $entityID) |
91 | 91 | { |
92 | - if (stripos((string)$entityID, 'x') !== false) { |
|
92 | + if (stripos((string) $entityID, 'x') !== false) { |
|
93 | 93 | return $entityID; |
94 | 94 | } |
95 | 95 | |
@@ -103,6 +103,6 @@ discard block |
||
103 | 103 | throw new WSException($errorMessage); |
104 | 104 | } |
105 | 105 | |
106 | - return "{$type['idPrefix']}x{$entityID}"; |
|
106 | + return "{$type[ 'idPrefix' ]}x{$entityID}"; |
|
107 | 107 | } |
108 | 108 | } |
@@ -268,6 +268,7 @@ |
||
268 | 268 | * @access private |
269 | 269 | * @static |
270 | 270 | * @param string Base URL of vTiger CRM |
271 | + * @param string $baseUrl |
|
271 | 272 | * @return boolean Returns cleaned and fixed vTiger URL |
272 | 273 | */ |
273 | 274 | private static function fixVtigerBaseUrl($baseUrl) |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | $postdata = [ |
100 | 100 | 'operation' => 'login', |
101 | 101 | 'username' => $username, |
102 | - 'accessKey' => md5($this->serviceToken . $accessKey) |
|
102 | + 'accessKey' => md5($this->serviceToken.$accessKey) |
|
103 | 103 | ]; |
104 | 104 | |
105 | 105 | $result = $this->sendHttpRequest($postdata); |
@@ -112,12 +112,12 @@ discard block |
||
112 | 112 | $this->accessKey = $accessKey; |
113 | 113 | |
114 | 114 | // Session data |
115 | - $this->sessionName = $result['sessionName']; |
|
116 | - $this->userID = $result['userId']; |
|
115 | + $this->sessionName = $result[ 'sessionName' ]; |
|
116 | + $this->userID = $result[ 'userId' ]; |
|
117 | 117 | |
118 | 118 | // Vtiger CRM and WebServices API version |
119 | - $this->vtigerApiVersion = $result['version']; |
|
120 | - $this->vtigerVersion = $result['vtigerVersion']; |
|
119 | + $this->vtigerApiVersion = $result[ 'version' ]; |
|
120 | + $this->vtigerVersion = $result[ 'vtigerVersion' ]; |
|
121 | 121 | |
122 | 122 | return true; |
123 | 123 | } |
@@ -149,8 +149,8 @@ discard block |
||
149 | 149 | } |
150 | 150 | |
151 | 151 | $this->accessKey = array_key_exists('accesskey', $result) |
152 | - ? $result['accesskey'] |
|
153 | - : $result[0]; |
|
152 | + ? $result[ 'accesskey' ] |
|
153 | + : $result[ 0 ]; |
|
154 | 154 | |
155 | 155 | return $this->login($username, $accessKey); |
156 | 156 | } |
@@ -169,12 +169,12 @@ discard block |
||
169 | 169 | ]; |
170 | 170 | $result = $this->sendHttpRequest($getdata, 'GET'); |
171 | 171 | |
172 | - if (!is_array($result) || !isset($result['token'])) { |
|
172 | + if (!is_array($result) || !isset($result[ 'token' ])) { |
|
173 | 173 | return false; |
174 | 174 | } |
175 | 175 | |
176 | - $this->serviceExpireTime = $result['expireTime']; |
|
177 | - $this->serviceToken = $result['token']; |
|
176 | + $this->serviceExpireTime = $result[ 'expireTime' ]; |
|
177 | + $this->serviceToken = $result[ 'token' ]; |
|
178 | 178 | |
179 | 179 | return true; |
180 | 180 | } |
@@ -222,30 +222,30 @@ discard block |
||
222 | 222 | */ |
223 | 223 | public function sendHttpRequest(array $requestData, $method = 'POST') |
224 | 224 | { |
225 | - if (!isset($requestData['operation'])) { |
|
225 | + if (!isset($requestData[ 'operation' ])) { |
|
226 | 226 | throw new WSException('Request data must contain the name of the operation!'); |
227 | 227 | } |
228 | 228 | |
229 | - $requestData['sessionName'] = $this->sessionName; |
|
229 | + $requestData[ 'sessionName' ] = $this->sessionName; |
|
230 | 230 | |
231 | 231 | // Perform re-login if required. |
232 | - if ('getchallenge' !== $requestData['operation'] && time() > $this->serviceExpireTime) { |
|
232 | + if ('getchallenge' !== $requestData[ 'operation' ] && time() > $this->serviceExpireTime) { |
|
233 | 233 | $this->login($this->userName, $this->accessKey); |
234 | 234 | } |
235 | 235 | |
236 | 236 | try { |
237 | 237 | switch ($method) { |
238 | 238 | case 'GET': |
239 | - $response = $this->httpClient->get($this->serviceBaseURL, ['query' => $requestData]); |
|
239 | + $response = $this->httpClient->get($this->serviceBaseURL, [ 'query' => $requestData ]); |
|
240 | 240 | break; |
241 | 241 | case 'POST': |
242 | - $response = $this->httpClient->post($this->serviceBaseURL, ['form_params' => $requestData]); |
|
242 | + $response = $this->httpClient->post($this->serviceBaseURL, [ 'form_params' => $requestData ]); |
|
243 | 243 | break; |
244 | 244 | default: |
245 | 245 | throw new WSException("Unsupported request type {$method}"); |
246 | 246 | } |
247 | 247 | } catch (RequestException $ex) { |
248 | - $urlFailed = $this->httpClient->getConfig('base_uri') . $this->serviceBaseURL; |
|
248 | + $urlFailed = $this->httpClient->getConfig('base_uri').$this->serviceBaseURL; |
|
249 | 249 | throw new WSException( |
250 | 250 | sprintf('Failed to execute %s call on "%s" URL', $method, $urlFailed), |
251 | 251 | 'FAILED_SENDING_REQUEST', |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | |
259 | 259 | return (!is_array($jsonObj) || self::checkForError($jsonObj)) |
260 | 260 | ? null |
261 | - : $jsonObj['result']; |
|
261 | + : $jsonObj[ 'result' ]; |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | if (!preg_match('/^https?:\/\//i', $baseUrl)) { |
274 | 274 | $baseUrl = sprintf('http://%s', $baseUrl); |
275 | 275 | } |
276 | - if (strripos($baseUrl, '/') !== strlen($baseUrl)-1) { |
|
276 | + if (strripos($baseUrl, '/') !== strlen($baseUrl) - 1) { |
|
277 | 277 | $baseUrl .= '/'; |
278 | 278 | } |
279 | 279 | return $baseUrl; |
@@ -288,15 +288,15 @@ discard block |
||
288 | 288 | */ |
289 | 289 | private static function checkForError(array $jsonResult) |
290 | 290 | { |
291 | - if (isset($jsonResult['success']) && (bool)$jsonResult['success'] === true) { |
|
291 | + if (isset($jsonResult[ 'success' ]) && (bool) $jsonResult[ 'success' ] === true) { |
|
292 | 292 | return false; |
293 | 293 | } |
294 | 294 | |
295 | - if (isset($jsonResult['error'])) { |
|
296 | - $error = $jsonResult['error']; |
|
295 | + if (isset($jsonResult[ 'error' ])) { |
|
296 | + $error = $jsonResult[ 'error' ]; |
|
297 | 297 | throw new WSException( |
298 | - $error['message'], |
|
299 | - $error['code'] |
|
298 | + $error[ 'message' ], |
|
299 | + $error[ 'code' ] |
|
300 | 300 | ); |
301 | 301 | } |
302 | 302 |
@@ -69,11 +69,11 @@ discard block |
||
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
72 | - * Retrieve an external iterator |
|
73 | - * @access public |
|
74 | - * @link http://php.net/manual/en/iteratoraggregate.getiterator.php |
|
75 | - * @return \Traversable An instance of an object implementing \Traversable |
|
76 | - */ |
|
72 | + * Retrieve an external iterator |
|
73 | + * @access public |
|
74 | + * @link http://php.net/manual/en/iteratoraggregate.getiterator.php |
|
75 | + * @return \Traversable An instance of an object implementing \Traversable |
|
76 | + */ |
|
77 | 77 | public function getIterator() |
78 | 78 | { |
79 | 79 | $properties = $this->getAllProperties(); |
@@ -83,10 +83,10 @@ discard block |
||
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
86 | - * Gets all the properties of the object |
|
87 | - * @access public |
|
88 | - * @return array Array of properties |
|
89 | - */ |
|
86 | + * Gets all the properties of the object |
|
87 | + * @access public |
|
88 | + * @return array Array of properties |
|
89 | + */ |
|
90 | 90 | private function getAllProperties() |
91 | 91 | { |
92 | 92 | $allProperties = get_object_vars($this); |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public function __toString() |
67 | 67 | { |
68 | - return __CLASS__ . ": [{$this->code}]: {$this->message}\n"; |
|
68 | + return __CLASS__.": [{$this->code}]: {$this->message}\n"; |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | $fullNameComponents = explode("\0", $fullName); |
96 | 96 | $propertyName = array_pop($fullNameComponents); |
97 | 97 | if ($propertyName && isset($value)) { |
98 | - $properties[$propertyName] = $value; |
|
98 | + $properties[ $propertyName ] = $value; |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 |