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 = " . oxDb::getDb()->quote( $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         $oDb = oxDb::getDb();
00115 
00116         // loading entries
00117         $sSelect  = 'select count(*) from oxgbentries left join oxuser on oxgbentries.oxuserid = oxuser.oxid ';
00118         $sSelect .= 'where oxuser.oxid is not null and oxgbentries.oxshopid = "'.$myConfig->getShopId().'" ';
00119 
00120         // setting GB entry view restirction rules
00121         if ( $myConfig->getConfigParam( 'blGBModerate') ) {
00122             $oUser = $this->getUser();
00123             $sSelect .= " and ( oxgbentries.oxactive = '1' ";
00124             $sSelect .= $oUser?" or oxgbentries.oxuserid = ".$oDb->quote( $oUser->getId() ):'';
00125             $sSelect .= " ) ";
00126         }
00127 
00128         // loading only if there is some data
00129         $iRecCnt = (int) $oDb->getOne( $sSelect );
00130         return $iRecCnt;
00131     }
00132 
00143     public function floodProtection( $sShopid = 0, $sUserId = null )
00144     {
00145         $result = true;
00146         if ( $sUserId && $sShopid) {
00147             $oDb = oxDb::getDb();
00148             $sToday = date( 'Y-m-d' );
00149             $sSelect  = "select count(*) from oxgbentries ";
00150             $sSelect .= "where oxgbentries.oxuserid = " . $oDb->quote( $sUserId ) . " and oxgbentries.oxshopid = " . $oDb->quote( $sShopid ) . " ";
00151             $sSelect .= "and oxgbentries.oxcreate >= '$sToday 00:00:00' and oxgbentries.oxcreate <= '$sToday 23:59:59' ";
00152             $iCnt = $oDb->getOne( $sSelect );
00153 
00154             $myConfig = $this->getConfig();
00155             if ( ( !$myConfig->getConfigParam( 'iMaxGBEntriesPerDay' ) ) || ( $iCnt < $myConfig->getConfigParam( 'iMaxGBEntriesPerDay' ) ) ) {
00156                 $result = false;
00157             }
00158         }
00159         return $result;
00160     }
00161 }