OXID eShop CE  4.9.7
 All Classes Files Functions Variables Pages
oxgbentry.php
Go to the documentation of this file.
1 <?php
2 
8 class oxGbEntry extends oxBase
9 {
10 
16  //to skip oxcreate we must change this field to 'CURRENT_TIMESTAMP'
17  //protected $_aSkipSaveFields = array( 'oxcreate' );
18 
24  protected $_sClassName = 'oxgbentry';
25 
30  public function __construct()
31  {
33  $this->init('oxgbentries');
34  }
35 
43  public function assign($dbRecord)
44  {
45 
46  $blRet = parent::assign($dbRecord);
47 
48  if (isset($this->oxgbentries__oxuserid) && $this->oxgbentries__oxuserid->value) {
49  $oDb = oxDb::getDb();
50  $this->oxuser__oxfname = new oxField($oDb->getOne("select oxfname from oxuser where oxid=" . $oDb->quote($this->oxgbentries__oxuserid->value)));
51  }
52 
53  return $blRet;
54  }
55 
61  protected function _insert()
62  {
63  // set oxcreate
64  $this->oxgbentries__oxcreate = new oxField(date('Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime()));
65 
66  return parent::_insert();
67  }
68 
78  public function getAllEntries($iStart, $iNrofCatArticles, $sSortBy)
79  {
80  $myConfig = $this->getConfig();
81 
82  // loading entries
83  $sSelect = 'select oxgbentries.*, oxuser.oxfname,
84  `oxuser`.`oxusername` AS `author`, `oxgbentries`.`oxcreate` AS `date`
85  from oxgbentries left join oxuser on oxgbentries.oxuserid = oxuser.oxid ';
86  $sSelect .= 'where oxuser.oxid is not null and oxgbentries.oxshopid = "' . $myConfig->getShopId() . '" ';
87 
88  // setting GB entry view restirction rules
89  if ($myConfig->getConfigParam('blGBModerate')) {
90  $oUser = $this->getUser();
91  $sSelect .= " and ( oxgbentries.oxactive = '1' ";
92  $sSelect .= $oUser ? " or oxgbentries.oxuserid = " . oxDb::getDb()->quote($oUser->getId()) : '';
93  $sSelect .= " ) ";
94  }
95 
96  // setting sort
97  if ($sSortBy) {
98  $sSelect .= "order by $sSortBy ";
99  }
100 
101 
102  $oEntries = oxNew('oxlist');
103  $oEntries->init('oxgbentry');
104 
105  $oEntries->setSqlLimit($iStart, $iNrofCatArticles);
106  $oEntries->selectString($sSelect);
107 
108  return $oEntries;
109  }
110 
116  public function getEntryCount()
117  {
118  $myConfig = $this->getConfig();
119  $oDb = oxDb::getDb();
120 
121  // loading entries
122  $sSelect = 'select count(*) from oxgbentries left join oxuser on oxgbentries.oxuserid = oxuser.oxid ';
123  $sSelect .= 'where oxuser.oxid is not null and oxgbentries.oxshopid = "' . $myConfig->getShopId() . '" ';
124 
125  // setting GB entry view restirction rules
126  if ($myConfig->getConfigParam('blGBModerate')) {
127  $oUser = $this->getUser();
128  $sSelect .= " and ( oxgbentries.oxactive = '1' ";
129  $sSelect .= $oUser ? " or oxgbentries.oxuserid = " . $oDb->quote($oUser->getId()) : '';
130  $sSelect .= " ) ";
131  }
132 
133  // loading only if there is some data
134  $iRecCnt = (int) $oDb->getOne($sSelect);
135 
136  return $iRecCnt;
137  }
138 
149  public function floodProtection($sShopid = 0, $sUserId = null)
150  {
151  $result = true;
152  if ($sUserId && $sShopid) {
153  $oDb = oxDb::getDb();
154  $sToday = date('Y-m-d');
155  $sSelect = "select count(*) from oxgbentries ";
156  $sSelect .= "where oxgbentries.oxuserid = " . $oDb->quote($sUserId) . " and oxgbentries.oxshopid = " . $oDb->quote($sShopid) . " ";
157  $sSelect .= "and oxgbentries.oxcreate >= '$sToday 00:00:00' and oxgbentries.oxcreate <= '$sToday 23:59:59' ";
158  $iCnt = $oDb->getOne($sSelect);
159 
160  $myConfig = $this->getConfig();
161  if ((!$myConfig->getConfigParam('iMaxGBEntriesPerDay')) || ($iCnt < $myConfig->getConfigParam('iMaxGBEntriesPerDay'))) {
162  $result = false;
163  }
164  }
165 
166  return $result;
167  }
168 
169 }