oxgbentry.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class oxGbEntry extends oxBase
00009 {
00015     //to skip oxcreate we must change this field to 'CURRENT_TIMESTAMP'
00016     //protected $_aSkipSaveFields = array( 'oxcreate' );
00017 
00023     protected $_sClassName = 'oxgbentry';
00024 
00029     public function __construct()
00030     {
00031         parent::__construct();
00032         $this->init( 'oxgbentries' );
00033     }
00034 
00042     public function assign( $dbRecord )
00043     {
00044 
00045         $blRet = parent::assign( $dbRecord );
00046 
00047         if ( isset( $this->oxgbentries__oxuserid ) && $this->oxgbentries__oxuserid->value ) {
00048             $oDb = oxDb::getDb();
00049             $this->oxuser__oxfname = new oxField( $oDb->getOne( "select oxfname from oxuser where oxid=".$oDb->quote( $this->oxgbentries__oxuserid->value ) ));
00050         }
00051 
00052         return $blRet;
00053     }
00054 
00060     protected function _insert()
00061     {
00062         // set oxcreate
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         // loading entries
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         // setting GB entry view restirction rules
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         // setting sort
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         // loading entries
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         // setting GB entry view restirction rules
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         // loading only if there is some data
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 }

Generated on Wed Apr 22 12:26:31 2009 for OXID eShop CE by  doxygen 1.5.5