oxtsratings.php

Go to the documentation of this file.
00001 <?php
00002 
00003 class oxTsRatings extends oxSuperCfg
00004 {
00005 
00009     const CACHE_TTL = 43200;
00010 
00014     const TS_RATINGS    = 'TS_RATINGS';
00015 
00022     protected $_aChannel = array();
00023 
00029     protected $_sTsId = null;
00030 
00036     public function getTsId()
00037     {
00038         return $this->_sTsId;
00039     }
00040 
00046     public function setTsId( $sId )
00047     {
00048         $this->_sTsId = $sId;
00049     }
00050 
00058     protected function _executeCurl( $sUrl )
00059     {
00060         $oCurl = oxNew('oxCurl');
00061         $oCurl->setMethod("GET");
00062         $oCurl->setUrl($sUrl);
00063         $oCurl->setOption('CURLOPT_HEADER', false);
00064         $oCurl->setOption('CURLOPT_POST', false);
00065         $sOutput = $oCurl->execute();
00066 
00067         return $sOutput;
00068     }
00069 
00076     public function getRatings()
00077     {
00078         if ( ( $this->_aChannel = oxRegistry::getUtils()->fromFileCache( self::TS_RATINGS ) ) ) {
00079             return $this->_aChannel;
00080         }
00081         $sTsId = $this->getTsId();
00082 
00083         $sUrl = "https://www.trustedshops.com/bewertung/show_xml.php?tsid=" . $sTsId;
00084         $sOutput = $this->_executeCurl( $sUrl );
00085 
00086         $this->_aChannel['empty'] = true;
00087 
00088         try {
00089             $oDomFile = oxNew( "oxSimpleXml" );
00090             if ( $oXml = $oDomFile->xmlToObject( $sOutput ) ) {
00091                 $aResult = $oXml->ratings->xpath('//result[@name="average"]');
00092 
00093                 $this->_aChannel['empty'] = false;
00094                 $this->_aChannel['result'] = (float)$aResult[0];
00095                 $this->_aChannel['max'] = "5.00";
00096                 $this->_aChannel['count'] = (int)$oXml->ratings["amount"];
00097                 $this->_aChannel['shopName'] = (string)$oXml->name;
00098                 oxRegistry::getUtils()->toFileCache( self::TS_RATINGS, $this->_aChannel, self::CACHE_TTL );
00099             }
00100         } catch ( Exception $oEx ) {
00101             $oEx = oxNew( "oxException" );
00102             $oEx->setMessage( $oEx->getMessage() );
00103             $oEx->debugOut();
00104         }
00105         return $this->_aChannel;
00106     }
00107 }