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', oxRegistry::get("oxUtilsDate")->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,
00082                     `oxuser`.`oxusername` AS `author`, `oxgbentries`.`oxcreate` AS `date`
00083             from oxgbentries left join oxuser on oxgbentries.oxuserid = oxuser.oxid ';
00084         $sSelect .= 'where oxuser.oxid is not null and oxgbentries.oxshopid = "'.$myConfig->getShopId().'" ';
00085 
00086         // setting GB entry view restirction rules
00087         if ( $myConfig->getConfigParam( 'blGBModerate') ) {
00088             $oUser = $this->getUser();
00089             $sSelect .= " and ( oxgbentries.oxactive = '1' ";
00090             $sSelect .= $oUser?" or oxgbentries.oxuserid = " . oxDb::getDb()->quote( $oUser->getId() ) : '';
00091             $sSelect .= " ) ";
00092         }
00093 
00094         // setting sort
00095         if ( $sSortBy ) {
00096             $sSelect .= "order by $sSortBy ";
00097         }
00098 
00099 
00100         $oEntries = oxNew( 'oxlist' );
00101         $oEntries->init( 'oxgbentry' );
00102 
00103         $oEntries->setSqlLimit( $iStart, $iNrofCatArticles );
00104         $oEntries->selectString( $sSelect );
00105 
00106         return $oEntries;
00107     }
00108 
00114     public function getEntryCount()
00115     {
00116         $myConfig = $this->getConfig();
00117         $oDb = oxDb::getDb();
00118 
00119         // loading entries
00120         $sSelect  = 'select count(*) from oxgbentries left join oxuser on oxgbentries.oxuserid = oxuser.oxid ';
00121         $sSelect .= 'where oxuser.oxid is not null and oxgbentries.oxshopid = "'.$myConfig->getShopId().'" ';
00122 
00123         // setting GB entry view restirction rules
00124         if ( $myConfig->getConfigParam( 'blGBModerate') ) {
00125             $oUser = $this->getUser();
00126             $sSelect .= " and ( oxgbentries.oxactive = '1' ";
00127             $sSelect .= $oUser?" or oxgbentries.oxuserid = ".$oDb->quote( $oUser->getId() ):'';
00128             $sSelect .= " ) ";
00129         }
00130 
00131         // loading only if there is some data
00132         $iRecCnt = (int) $oDb->getOne( $sSelect );
00133         return $iRecCnt;
00134     }
00135 
00146     public function floodProtection( $sShopid = 0, $sUserId = null )
00147     {
00148         $result = true;
00149         if ( $sUserId && $sShopid) {
00150             $oDb = oxDb::getDb();
00151             $sToday = date( 'Y-m-d' );
00152             $sSelect  = "select count(*) from oxgbentries ";
00153             $sSelect .= "where oxgbentries.oxuserid = " . $oDb->quote( $sUserId ) . " and oxgbentries.oxshopid = " . $oDb->quote( $sShopid ) . " ";
00154             $sSelect .= "and oxgbentries.oxcreate >= '$sToday 00:00:00' and oxgbentries.oxcreate <= '$sToday 23:59:59' ";
00155             $iCnt = $oDb->getOne( $sSelect );
00156 
00157             $myConfig = $this->getConfig();
00158             if ( ( !$myConfig->getConfigParam( 'iMaxGBEntriesPerDay' ) ) || ( $iCnt < $myConfig->getConfigParam( 'iMaxGBEntriesPerDay' ) ) ) {
00159                 $result = false;
00160             }
00161         }
00162         return $result;
00163     }
00164 
00165 }