OXID eShop CE  4.8.11
 All Classes Files Functions Variables Pages
oxtsratings.php
Go to the documentation of this file.
1 <?php
2 
3 class oxTsRatings extends oxSuperCfg
4 {
5 
9  const CACHE_TTL = 43200;
10 
14  const TS_RATINGS = 'TS_RATINGS';
15 
22  protected $_aChannel = array();
23 
29  protected $_sTsId = null;
30 
36  public function getTsId()
37  {
38  return $this->_sTsId;
39  }
40 
46  public function setTsId( $sId )
47  {
48  $this->_sTsId = $sId;
49  }
50 
58  protected function _executeCurl( $sUrl )
59  {
60  $oCurl = oxNew('oxCurl');
61  $oCurl->setMethod("GET");
62  $oCurl->setUrl($sUrl);
63  $oCurl->setOption('CURLOPT_HEADER', false);
64  $oCurl->setOption('CURLOPT_POST', false);
65  $sOutput = $oCurl->execute();
66 
67  return $sOutput;
68  }
69 
76  public function getRatings()
77  {
78  if ( ( $this->_aChannel = oxRegistry::getUtils()->fromFileCache( self::TS_RATINGS ) ) ) {
79  return $this->_aChannel;
80  }
81  $sTsId = $this->getTsId();
82 
83  $sUrl = "https://www.trustedshops.com/bewertung/show_xml.php?tsid=" . $sTsId;
84  $sOutput = $this->_executeCurl( $sUrl );
85 
86  $this->_aChannel['empty'] = true;
87 
88  try {
89  $oDomFile = oxNew( "oxSimpleXml" );
90  if ( $oXml = $oDomFile->xmlToObject( $sOutput ) ) {
91  $aResult = $oXml->ratings->xpath('//result[@name="average"]');
92 
93  $this->_aChannel['empty'] = false;
94  $this->_aChannel['result'] = (float)$aResult[0];
95  $this->_aChannel['max'] = "5.00";
96  $this->_aChannel['count'] = (int)$oXml->ratings["amount"];
97  $this->_aChannel['shopName'] = (string)$oXml->name;
98  oxRegistry::getUtils()->toFileCache( self::TS_RATINGS, $this->_aChannel, self::CACHE_TTL );
99  }
100  } catch ( Exception $oEx ) {
101  $oEx = oxNew( "oxException" );
102  $oEx->setMessage( $oEx->getMessage() );
103  $oEx->debugOut();
104  }
105  return $this->_aChannel;
106  }
107 }