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