OXID eShop CE  4.8.10
 All Classes Files Functions Variables Pages
oxrating.php
Go to the documentation of this file.
1 <?php
2 
8 class oxRating extends oxBase
9 {
15  protected $_blDisableShopCheck = true;
16 
22  protected $_sClassName = 'oxrating';
23 
27  public function __construct()
28  {
30  $this->init( 'oxratings' );
31  }
32 
42  public function allowRating( $sUserId, $sType, $sObjectId)
43  {
44  $oDb = oxDb::getDb();
45  $myConfig = $this->getConfig();
46 
47  if ( $iRatingLogsTimeout = $myConfig->getConfigParam( 'iRatingLogsTimeout' ) ) {
48  $sExpDate = date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime() - $iRatingLogsTimeout*24*60*60);
49  $oDb->execute( "delete from oxratings where oxtimestamp < '$sExpDate'" );
50  }
51  $sSelect = "select oxid from oxratings where oxuserid = ".$oDb->quote( $sUserId )." and oxtype=".$oDb->quote( $sType )." and oxobjectid = ".$oDb->quote( $sObjectId );
52  if ( $oDb->getOne( $sSelect ) ) {
53  return false;
54  }
55 
56  return true;
57  }
58 
59 
69  public function getRatingAverage( $sObjectId, $sType, $aIncludedObjectsIds = null )
70  {
71  $oDb = oxDb::getDb();
72 
73  $sQuerySnipet = '';
74  if ( is_array( $aIncludedObjectsIds ) && count( $aIncludedObjectsIds ) > 0 ) {
75  $sQuerySnipet = " AND ( `oxobjectid` = ".$oDb->quote( $sObjectId ) . " OR `oxobjectid` in ('" .implode("', '", $aIncludedObjectsIds). "') )";
76  } else {
77  $sQuerySnipet = " AND `oxobjectid` = ".$oDb->quote( $sObjectId );
78  }
79 
80  $sSelect = "
81  SELECT
82  AVG(`oxrating`)
83  FROM `oxreviews`
84  WHERE `oxrating` > 0
85  AND `oxtype` = " . $oDb->quote( $sType )
86  . $sQuerySnipet . "
87  LIMIT 1";
88 
89  $fRating = 0;
90  if ( $fRating = $oDb->getOne( $sSelect, false, false ) ) {
91  $fRating = round( $fRating, 1 );
92  }
93 
94  return $fRating;
95  }
96 
106  public function getRatingCount( $sObjectId, $sType, $aIncludedObjectsIds = null )
107  {
108  $oDb = oxDb::getDb();
109 
110  $sQuerySnipet = '';
111  if ( is_array( $aIncludedObjectsIds ) && count( $aIncludedObjectsIds ) > 0 ) {
112  $sQuerySnipet = " AND ( `oxobjectid` = ".$oDb->quote( $sObjectId ) . " OR `oxobjectid` in ('" .implode("', '", $aIncludedObjectsIds). "') )";
113  } else {
114  $sQuerySnipet = " AND `oxobjectid` = ".$oDb->quote( $sObjectId );
115  }
116 
117  $sSelect = "
118  SELECT
119  COUNT(*)
120  FROM `oxreviews`
121  WHERE `oxrating` > 0
122  AND `oxtype` = " . $oDb->quote( $sType )
123  . $sQuerySnipet . "
124  LIMIT 1";
125 
126  $iCount = 0;
127  $iCount = $oDb->getOne( $sSelect, false, false );
128 
129  return $iCount;
130  }
131 
137  public function getObjectType()
138  {
139  return $this->oxratings__oxtype->value;
140  }
141 
147  public function getObjectId()
148  {
149  return $this->oxratings__oxobjectid->value;
150  }
151 
152 }