commerceguys_marketplace.addon.inc in Commerce Guys Marketplace 7
File
includes/commerceguys_marketplace.addon.inc
View source
<?php
class CommerceGuysMarketplaceAddonManager extends CommerceGuysMarketplaceManagerBase {
function __construct($client, $endpoint, $resource = NULL) {
parent::__construct($client, $endpoint, 'addons');
}
public function query($search = '', $only_featured = FALSE, $category = 0, $sorts = array(), $offset = 0, $limit = 10) {
$params = array(
'offset' => $offset,
'limit' => $limit,
);
if (!empty($search)) {
$params['search'] = $search;
}
if (!empty($only_featured)) {
$params['only_featured'] = $only_featured;
}
if (!empty($category)) {
$params['category'] = $category;
}
if ($sorts) {
$sort_by = array_keys($sorts);
$sort_order = array_values($sorts);
$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,
);
}
public function getCategories($reset = FALSE) {
if (!$reset && ($cached_data = cache_get('marketplace_addon_categories'))) {
$categories = $cached_data->data;
}
else {
$response = drupal_http_request($this->endpoint . '/addon_categories');
$categories = json_decode($response->data);
cache_set('marketplace_addon_categories', $categories, CACHE_TEMPORARY);
}
return $categories;
}
public function getLicenses($category = 0) {
$access_token = $this
->getAccessToken();
$options = array(
'headers' => array(
'Authorization' => 'Bearer ' . $access_token['token'],
),
);
$params = array();
if (!empty($category)) {
$params['category'] = $category;
}
$url = url($this->endpoint . '/addon_licenses', array(
'query' => $params,
));
$response = drupal_http_request($url, $options);
$result = json_decode($response->data);
return array(
'results' => $result->results,
'result_count' => $result->result_count,
);
}
public function getPromotions($reset = FALSE) {
if (!$reset && ($cached_data = cache_get('marketplace_addon_promotions'))) {
$promotions = $cached_data->data;
}
else {
$response = drupal_http_request($this->endpoint . '/addon_promotions');
$promotions = json_decode($response->data);
cache_set('marketplace_addon_categories', $promotions, CACHE_TEMPORARY);
}
return $promotions;
}
}