bebeboutik/modules/trustedshopsbbb/lib/ReviewIndicatorCollector.php
2017-02-17 12:58:11 +01:00

48 lines
1.9 KiB
PHP
Executable File

<?php
class ReviewIndicatorCollector
{
private $id_lang;
public function __construct($id_lang)
{
$this->id_lang = $id_lang;
}
public function getResults()
{
$returnedArray = array();
$tsId = Configuration::get('TRUSTED_SHOP_' . strtoupper(Language::getIsoById((int)$this->id_lang)) . '_ID');
try{
// $jsonResult = $this->getApiResult($tsId);
// $jsonObject = json_decode($jsonResult,true);
// $returnedArray['result'] = $jsonObject['response']['data']['shop']['qualityIndicators']['reviewIndicator']['overallMark'];
// $returnedArray['count'] = $jsonObject['response']['data']['shop']['qualityIndicators']['reviewIndicator']['activeReviewCount'];
// $returnedArray['shop_name'] = $jsonObject['response']['data']['shop']['name'];
$xmlResult = $this->getApiResult($tsId);
$xml = new SimpleXMLElement($xmlResult);
$returnedArray['result'] = $xml->data->shop->qualityIndicators->reviewIndicator->{'overallMark'};
$returnedArray['count'] = $xml->data->shop->qualityIndicators->reviewIndicator->activeReviewCount;
$returnedArray['shop_name'] = $xml->data->shop->name;
}catch(Exception $ex){
Logger::AddLog("file ReviewIndicatorCollector.php - " .$ex->getMessage(), 4, '0000001', 'User', '0');
}
return $returnedArray;
}
private function getApiResult($ts_id)
{
$apiUrl = 'http://api.trustedshops.com/rest/public/v2/shops/' . $ts_id . '/quality/reviews';
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, FALSE);
curl_setopt($ch, CURLOPT_URL, $apiUrl);
$returnedJson = curl_exec($ch);
curl_close($ch);
return $returnedJson;
}
}