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 #7 from cjcox17/master
Browse files Browse the repository at this point in the history
Add new function for Vtiger Lookup API
  • Loading branch information
Chris-Pratt-Clystnet authored Jul 23, 2019
2 parents a0e6900 + 27a1bc6 commit 5d24150
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ $obj = Vtiger::retrieve($id);
var_dump($obj);
```

#### Lookup

This function uses the Vtiger Lookup API endpoint to search for a single piece of information within multiple columns of a Vtiger module. This function is often multitudes faster than the search function.


```php
$dataType = 'phone';
$phoneNumber = '1234567890';
$module = 'Leads';
$columns = ['phone', 'fax']; //Must be an array

Vtiger::lookup($dataType, $phoneNumber, $module, $columns);
```

#### Search

This function is a sql query builder wrapped around the query function. Accepts instance of laravels QueryBuilder.
Expand Down
41 changes: 38 additions & 3 deletions src/Vtiger.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,50 @@ public function search($query, $quote = true)
$queryString = $queryString . ' limit ' . $matchOffset[2] . ',' . $matchLimit[2];
}

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

return $this->query($queryString);
}

public function lookup($dataType, $value, $module, $columns)
{
$sessionId = $this->sessionId();

//Update columns into the proper format
$columnsText = '';
foreach ($columns as $column) {
$columnsText .= '"'.$column.'",';
}

//Trim the last comma from the string
$columnsText = substr($columnsText, 0, (strlen($columnsText) - 1));

//Lookup the data
try {
// send a request to retrieve a record
$response = $this->guzzleClient->request('GET', $this->url, [
'query' => [
'operation' => 'lookup',
'sessionName' => $sessionId,
'type' => $dataType,
'value' => $value,
'searchIn' => '{"'.$module.'":['.$columnsText.']}',
],
]);

} catch (GuzzleException $e) {
throw VtigerError::init($this->vTigerErrors, 7, $e->getMessage());
}

$this->close($sessionId);

return $this->_processResult($response);
}

/**
* Retreive a record from the VTiger API
* Format of id must be {moudler_code}x{item_id}, e.g 4x12
* Retrieve a record from the VTiger API
* Format of id must be {module_code}x{item_id}, e.g 4x12
*
* @param string $id
*
Expand Down

0 comments on commit 5d24150

Please sign in to comment.