OXID eShop CE  4.9.8
 All Classes Files Functions Variables Pages
oxtsratings.php
Go to the documentation of this file.
1 <?php
2 
6 class oxTsRatings extends oxSuperCfg
7 {
8 
12  const CACHE_TTL = 43200;
13 
17  const TS_RATINGS = 'TS_RATINGS';
18 
25  protected $_aChannel = array();
26 
32  protected $_sTsId = null;
33 
39  public function getTsId()
40  {
41  return $this->_sTsId;
42  }
43 
49  public function setTsId($sId)
50  {
51  $this->_sTsId = $sId;
52  }
53 
61  protected function _executeCurl($sUrl)
62  {
63  $oCurl = oxNew('oxCurl');
64  $oCurl->setMethod("GET");
65  $oCurl->setUrl($sUrl);
66  $oCurl->setOption('CURLOPT_HEADER', false);
67  $oCurl->setOption('CURLOPT_POST', false);
68  $sOutput = $oCurl->execute();
69 
70  return $sOutput;
71  }
72 
79  public function getRatings()
80  {
81  if (($this->_aChannel = oxRegistry::getUtils()->fromFileCache(self::TS_RATINGS))) {
82  return $this->_aChannel;
83  }
84  $sTsId = $this->getTsId();
85 
86  $sUrl = "https://www.trustedshops.com/bewertung/show_xml.php?tsid=" . $sTsId;
87  $sOutput = $this->_executeCurl($sUrl);
88 
89  $this->_aChannel['empty'] = true;
90 
91  try {
92  $oDomFile = oxNew("oxSimpleXml");
93  if ($oXml = $oDomFile->xmlToObject($sOutput)) {
94  $aResult = $oXml->ratings->xpath('//result[@name="average"]');
95 
96  $this->_aChannel['empty'] = false;
97  $this->_aChannel['result'] = (float) $aResult[0];
98  $this->_aChannel['max'] = "5.00";
99  $this->_aChannel['count'] = (int) $oXml->ratings["amount"];
100  $this->_aChannel['shopName'] = (string) $oXml->name;
101  oxRegistry::getUtils()->toFileCache(self::TS_RATINGS, $this->_aChannel, self::CACHE_TTL);
102  }
103  } catch (Exception $oEx) {
104  $oEx = oxNew("oxException");
105  $oEx->setMessage($oEx->getMessage());
106  $oEx->debugOut();
107  }
108 
109  return $this->_aChannel;
110  }
111 }