oxgbentry.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class oxGbEntry extends oxBase
00009 {
00010 
00016     //to skip oxcreate we must change this field to 'CURRENT_TIMESTAMP'
00017     //protected $_aSkipSaveFields = array( 'oxcreate' );
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             $oDb = oxDb::getDb();
00050             $this->oxuser__oxfname = new oxField($oDb->getOne("select oxfname from oxuser where oxid=" . $oDb->quote($this->oxgbentries__oxuserid->value)));
00051         }
00052 
00053         return $blRet;
00054     }
00055 
00061     protected function _insert()
00062     {
00063         // set oxcreate
00064         $this->oxgbentries__oxcreate = new oxField(date('Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime()));
00065 
00066         return parent::_insert();
00067     }
00068 
00078     public function getAllEntries($iStart, $iNrofCatArticles, $sSortBy)
00079     {
00080         $myConfig = $this->getConfig();
00081 
00082         // loading entries
00083         $sSelect = 'select oxgbentries.*, oxuser.oxfname,
00084                     `oxuser`.`oxusername` AS `author`, `oxgbentries`.`oxcreate` AS `date`
00085             from oxgbentries left join oxuser on oxgbentries.oxuserid = oxuser.oxid ';
00086         $sSelect .= 'where oxuser.oxid is not null and oxgbentries.oxshopid = "' . $myConfig->getShopId() . '" ';
00087 
00088         // setting GB entry view restirction rules
00089         if ($myConfig->getConfigParam('blGBModerate')) {
00090             $oUser = $this->getUser();
00091             $sSelect .= " and ( oxgbentries.oxactive = '1' ";
00092             $sSelect .= $oUser ? " or oxgbentries.oxuserid = " . oxDb::getDb()->quote($oUser->getId()) : '';
00093             $sSelect .= " ) ";
00094         }
00095 
00096         // setting sort
00097         if ($sSortBy) {
00098             $sSelect .= "order by $sSortBy ";
00099         }
00100 
00101 
00102         $oEntries = oxNew('oxlist');
00103         $oEntries->init('oxgbentry');
00104 
00105         $oEntries->setSqlLimit($iStart, $iNrofCatArticles);
00106         $oEntries->selectString($sSelect);
00107 
00108         return $oEntries;
00109     }
00110 
00116     public function getEntryCount()
00117     {
00118         $myConfig = $this->getConfig();
00119         $oDb = oxDb::getDb();
00120 
00121         // loading entries
00122         $sSelect = 'select count(*) from oxgbentries left join oxuser on oxgbentries.oxuserid = oxuser.oxid ';
00123         $sSelect .= 'where oxuser.oxid is not null and oxgbentries.oxshopid = "' . $myConfig->getShopId() . '" ';
00124 
00125         // setting GB entry view restirction rules
00126         if ($myConfig->getConfigParam('blGBModerate')) {
00127             $oUser = $this->getUser();
00128             $sSelect .= " and ( oxgbentries.oxactive = '1' ";
00129             $sSelect .= $oUser ? " or oxgbentries.oxuserid = " . $oDb->quote($oUser->getId()) : '';
00130             $sSelect .= " ) ";
00131         }
00132 
00133         // loading only if there is some data
00134         $iRecCnt = (int) $oDb->getOne($sSelect);
00135 
00136         return $iRecCnt;
00137     }
00138 
00149     public function floodProtection($sShopid = 0, $sUserId = null)
00150     {
00151         $result = true;
00152         if ($sUserId && $sShopid) {
00153             $oDb = oxDb::getDb();
00154             $sToday = date('Y-m-d');
00155             $sSelect = "select count(*) from oxgbentries ";
00156             $sSelect .= "where oxgbentries.oxuserid = " . $oDb->quote($sUserId) . " and oxgbentries.oxshopid = " . $oDb->quote($sShopid) . " ";
00157             $sSelect .= "and oxgbentries.oxcreate >= '$sToday 00:00:00' and oxgbentries.oxcreate <= '$sToday 23:59:59' ";
00158             $iCnt = $oDb->getOne($sSelect);
00159 
00160             $myConfig = $this->getConfig();
00161             if ((!$myConfig->getConfigParam('iMaxGBEntriesPerDay')) || ($iCnt < $myConfig->getConfigParam('iMaxGBEntriesPerDay'))) {
00162                 $result = false;
00163             }
00164         }
00165 
00166         return $result;
00167     }
00168 
00169 }