Go to the documentation of this file.00001 <?php
00002
00008 class oxRating extends oxBase
00009 {
00015 protected $_blDisableShopCheck = true;
00016
00022 protected $_sClassName = 'oxrating';
00023
00027 public function __construct()
00028 {
00029 parent::__construct();
00030 $this->init( 'oxratings' );
00031 }
00032
00042 public function allowRating( $sUserId, $sType, $sObjectId)
00043 {
00044 $oDb = oxDb::getDb();
00045 $myConfig = $this->getConfig();
00046
00047 if ( $iRatingLogsTimeout = $myConfig->getConfigParam( 'iRatingLogsTimeout' ) ) {
00048 $sExpDate = date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime() - $iRatingLogsTimeout*24*60*60);
00049 $oDb->execute( "delete from oxratings where oxtimestamp < '$sExpDate'" );
00050 }
00051 $sSelect = "select oxid from oxratings where oxuserid = ".$oDb->quote( $sUserId )." and oxtype=".$oDb->quote( $sType )." and oxobjectid = ".$oDb->quote( $sObjectId );
00052 if ( $oDb->getOne( $sSelect ) ) {
00053 return false;
00054 }
00055
00056 return true;
00057 }
00058
00059
00069 public function getRatingAverage( $sObjectId, $sType, $aIncludedObjectsIds = null )
00070 {
00071 $oDb = oxDb::getDb();
00072
00073 $sQuerySnipet = '';
00074 if ( is_array( $aIncludedObjectsIds ) && count( $aIncludedObjectsIds ) > 0 ) {
00075 $sQuerySnipet = " AND ( `oxobjectid` = ".$oDb->quote( $sObjectId ) . " OR `oxobjectid` in ('" .implode("', '", $aIncludedObjectsIds). "') )";
00076 } else {
00077 $sQuerySnipet = " AND `oxobjectid` = ".$oDb->quote( $sObjectId );
00078 }
00079
00080 $sSelect = "
00081 SELECT
00082 AVG(`oxrating`)
00083 FROM `oxreviews`
00084 WHERE `oxrating` > 0
00085 AND `oxtype` = " . $oDb->quote( $sType )
00086 . $sQuerySnipet . "
00087 LIMIT 1";
00088
00089 $fRating = 0;
00090 if ( $fRating = $oDb->getOne( $sSelect, false, false ) ) {
00091 $fRating = round( $fRating, 1 );
00092 }
00093
00094 return $fRating;
00095 }
00096
00106 public function getRatingCount( $sObjectId, $sType, $aIncludedObjectsIds = null )
00107 {
00108 $oDb = oxDb::getDb();
00109
00110 $sQuerySnipet = '';
00111 if ( is_array( $aIncludedObjectsIds ) && count( $aIncludedObjectsIds ) > 0 ) {
00112 $sQuerySnipet = " AND ( `oxobjectid` = ".$oDb->quote( $sObjectId ) . " OR `oxobjectid` in ('" .implode("', '", $aIncludedObjectsIds). "') )";
00113 } else {
00114 $sQuerySnipet = " AND `oxobjectid` = ".$oDb->quote( $sObjectId );
00115 }
00116
00117 $sSelect = "
00118 SELECT
00119 COUNT(*)
00120 FROM `oxreviews`
00121 WHERE `oxrating` > 0
00122 AND `oxtype` = " . $oDb->quote( $sType )
00123 . $sQuerySnipet . "
00124 LIMIT 1";
00125
00126 $iCount = 0;
00127 $iCount = $oDb->getOne( $sSelect, false, false );
00128
00129 return $iCount;
00130 }
00131
00132 }