public function CommerceGuysMarketplaceAddonManager::query in Commerce Guys Marketplace 7
Performs a query against the remote service.
Parameters
$search: (optional) A search query string.
$only_featured: (optional) Whether to limit the search to featured addons only.
$category: (optional) The id of the category to filter the query by.
$sorts: (optional) An array of sorts to apply to the query, in the $field => $direction format.
$offset: The number of results to skip. Defaults 0.
$limit: The number of results to return. Defaults to 10.
Return value
An array of results.
File
- includes/
commerceguys_marketplace.addon.inc, line 35
Class
- CommerceGuysMarketplaceAddonManager
- Defines the manager class for interacting with remote marketplace addons.
Code
public function query($search = '', $only_featured = FALSE, $category = 0, $sorts = array(), $offset = 0, $limit = 10) {
$params = array(
'offset' => $offset,
'limit' => $limit,
);
// Add the search query.
if (!empty($search)) {
$params['search'] = $search;
}
if (!empty($only_featured)) {
$params['only_featured'] = $only_featured;
}
// Filter by category.
if (!empty($category)) {
$params['category'] = $category;
}
// Add the sorts.
if ($sorts) {
$sort_by = array_keys($sorts);
$sort_order = array_values($sorts);
// The remote service only supports one active sort at a time.
$params['sort_by'] = $sort_by[0];
$params['sort_order'] = $sort_order[0];
}
$url = url($this->endpoint . '/addons', array(
'query' => $params,
));
$response = drupal_http_request($url);
$result = json_decode($response->data);
return array(
'results' => $result->results,
'result_count' => $result->result_count,
);
}