oxrating.php

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