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