00001 <?php
00002
00009 class oxGbEntry extends oxBase
00010 {
00016
00017
00018
00024 protected $_sClassName = 'oxgbentry';
00025
00030 public function __construct()
00031 {
00032 parent::__construct();
00033 $this->init( 'oxgbentries' );
00034 }
00035
00043 public function assign( $dbRecord )
00044 {
00045
00046 $blRet = parent::assign( $dbRecord );
00047
00048 if ( isset( $this->oxgbentries__oxuserid ) && $this->oxgbentries__oxuserid->value ) {
00049 $this->oxuser__oxfname = new oxField(oxDb::getDb()->getOne( "select oxfname from oxuser where oxid=".oxDb::getDb()->quote( $this->oxgbentries__oxuserid->value ) ));
00050 }
00051
00052 return $blRet;
00053 }
00054
00060 protected function _insert()
00061 {
00062
00063 $this->oxgbentries__oxcreate = new oxField( date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() ));
00064 return parent::_insert();
00065 }
00066
00076 public function getAllEntries( $iStart, $iNrofCatArticles, $sSortBy)
00077 {
00078 $myConfig = $this->getConfig();
00079
00080
00081 $sSelect = 'select oxgbentries.*, oxuser.oxfname from oxgbentries left join oxuser on oxgbentries.oxuserid = oxuser.oxid ';
00082 $sSelect .= 'where oxuser.oxid is not null and oxgbentries.oxshopid = "'.$myConfig->getShopId().'" ';
00083
00084
00085 if ( $myConfig->getConfigParam( 'blGBModerate') ) {
00086 $oUser = $this->getUser();
00087 $sSelect .= " and ( oxgbentries.oxactive = '1' ";
00088 $sSelect .= $oUser?" or oxgbentries.oxuserid = '".$oUser->getId()."' ":'';
00089 $sSelect .= " ) ";
00090 }
00091
00092
00093 if ( $sSortBy ) {
00094 $sSelect .= "order by $sSortBy ";
00095 }
00096
00097 $oEntries = oxNew( 'oxlist' );
00098 $oEntries->init( 'oxgbentry' );
00099
00100 $oEntries->setSqlLimit( $iStart, $iNrofCatArticles );
00101 $oEntries->selectString( $sSelect );
00102
00103 return $oEntries;
00104 }
00105
00111 public function getEntryCount()
00112 {
00113 $myConfig = $this->getConfig();
00114
00115
00116 $sSelect = 'select count(*) from oxgbentries left join oxuser on oxgbentries.oxuserid = oxuser.oxid ';
00117 $sSelect .= 'where oxuser.oxid is not null and oxgbentries.oxshopid = "'.$myConfig->getShopId().'" ';
00118
00119
00120 if ( $myConfig->getConfigParam( 'blGBModerate') ) {
00121 $oUser = $this->getUser();
00122 $sSelect .= " and ( oxgbentries.oxactive = '1' ";
00123 $sSelect .= $oUser?" or oxgbentries.oxuserid = '".$oUser->getId()."' ":'';
00124 $sSelect .= " ) ";
00125 }
00126
00127
00128 $iRecCnt = (int) oxDb::getDb()->getOne( $sSelect );
00129 return $iRecCnt;
00130 }
00131
00142 public function floodProtection( $sShopid = 0, $sUserId = null )
00143 {
00144 $result = true;
00145 if ( $sUserId && $sShopid) {
00146 $sToday = date( 'Y-m-d' );
00147 $sSelect = "select count(*) from oxgbentries ";
00148 $sSelect .= "where oxgbentries.oxuserid = '$sUserId' and oxgbentries.oxshopid = '$sShopid' ";
00149 $sSelect .= "and oxgbentries.oxcreate >= '$sToday 00:00:00' and oxgbentries.oxcreate <= '$sToday 23:59:59' ";
00150 $iCnt = oxDb::getDb()->getOne( $sSelect );
00151
00152 $myConfig = $this->getConfig();
00153 if ( ( !$myConfig->getConfigParam( 'iMaxGBEntriesPerDay' ) ) || ( $iCnt < $myConfig->getConfigParam( 'iMaxGBEntriesPerDay' ) ) ) {
00154 $result = false;
00155 }
00156 }
00157 return $result;
00158 }
00159 }