OXID eShop CE  4.9.10
 All Classes Files Functions Variables Pages
guestbook.php
Go to the documentation of this file.
1 <?php
2 
7 class GuestBook extends oxUBase
8 {
9 
15  protected $_iCntPages = null;
16 
22  protected $_blShowLogin = false;
23 
29  protected $_aSortColumns = null;
30 
36  protected $_sListOrderBy = false;
37 
43  protected $_sListOrderDir = false;
44 
50  protected $_blFloodProtection = null;
51 
57  protected $_aEntries = null;
58 
64  protected $_sThisTemplate = 'page/guestbook/guestbook.tpl';
65 
71  protected $_sThisLoginTemplate = 'page/guestbook/guestbook_login.tpl';
72 
78  protected $_blShowSorting = true;
79 
85  protected $_oPageNavigation = null;
86 
93 
94 
102  public function render()
103  {
104  parent::render();
105 
106  // #774C no user mail and password check in guesbook
107  if ($this->_blShowLogin) {
108  //no valid login
110  }
111 
112  $this->getEntries();
113 
114  return $this->_sThisTemplate;
115  }
116 
122  public function getSortColumns()
123  {
124  if ($this->_aSortColumns === null) {
125  $this->setSortColumns(array('author', 'date'));
126  }
127 
128  return $this->_aSortColumns;
129  }
130 
136  public function getGbSortBy()
137  {
138  return $this->_sListOrderBy;
139  }
140 
146  public function getGbSortDir()
147  {
148  return $this->_sListOrderDir;
149  }
150 
156  public function getEntries()
157  {
158  if ($this->_aEntries === null) {
159  $this->_aEntries = false;
160  $iNrofCatArticles = (int) $this->getConfig()->getConfigParam('iNrofCatArticles');
161  $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
162 
163  // loading only if there is some data
165  $oEntries = oxNew('oxgbentry');
166  if ($iCnt = $oEntries->getEntryCount()) {
167  $this->_iCntPages = round($iCnt / $iNrofCatArticles + 0.49);
168  $this->_aEntries = $oEntries->getAllEntries(
169  $this->getActPage() * $iNrofCatArticles,
170  $iNrofCatArticles,
171  $this->getSortingSql($this->getSortIdent())
172  );
173  }
174  }
175 
176  return $this->_aEntries;
177  }
178 
184  public function floodProtection()
185  {
186  if ($this->_blFloodProtection === null) {
187  $this->_blFloodProtection = false;
188  // is user logged in ?
189  $sUserId = oxRegistry::getSession()->getVariable('usr');
190  $sUserId = $sUserId ? $sUserId : 0;
191 
192  $oEntries = oxNew('oxgbentry');
193  $this->_blFloodProtection = $oEntries->floodProtection($this->getConfig()->getShopId(), $sUserId);
194  }
195 
197  }
198 
204  public function getSortOrderByParameterName()
205  {
206  return 'gborderby';
207  }
208 
214  public function getSortOrderParameterName()
215  {
216  return 'gborder';
217  }
218 
224  public function getSortIdent()
225  {
226  return 'oxgb';
227  }
228 
234  public function getDefaultSorting()
235  {
236  $aSorting = array('sortby' => 'date', 'sortdir' => 'desc');
237 
238  return $aSorting;
239  }
240 
246  public function getPageNavigation()
247  {
248  if ($this->_oPageNavigation === null) {
249  $this->_oPageNavigation = false;
250  $this->_oPageNavigation = $this->generatePageNavigation();
251  }
252 
254  }
255 
263  public function saveEntry()
264  {
265  if (!oxRegistry::getSession()->checkSessionChallenge()) {
266  return;
267  }
268 
269  $sReviewText = trim(( string ) oxRegistry::getConfig()->getRequestParameter('rvw_txt', true));
270  $sShopId = $this->getConfig()->getShopId();
271  $sUserId = oxRegistry::getSession()->getVariable('usr');
272 
273  // guest book`s entry is validated
274  $oUtilsView = oxRegistry::get("oxUtilsView");
275  if (!$sUserId) {
276  $oUtilsView->addErrorToDisplay('ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_LOGIN_TO_WRITE_ENTRY');
277 
278  //return to same page
279  return;
280  }
281 
282  if (!$sShopId) {
283  $oUtilsView->addErrorToDisplay('ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_UNDEFINED_SHOP');
284 
285  return 'guestbookentry';
286  }
287 
288  // empty entries validation
289  if ('' == $sReviewText) {
290  $oUtilsView->addErrorToDisplay('ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_REVIEW_CONTAINS_NO_TEXT');
291 
292  return 'guestbook';
293  }
294 
295  // flood protection
296  $oEntrie = oxNew('oxgbentry');
297  if ($oEntrie->floodProtection($sShopId, $sUserId)) {
298  $oUtilsView->addErrorToDisplay('ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_MAXIMUM_NUMBER_EXCEEDED');
299 
300  return 'guestbookentry';
301  }
302 
303  // double click protection
304  if ($this->canAcceptFormData()) {
305  // here the guest book entry is saved
306  $oEntry = oxNew('oxgbentry');
307  $oEntry->oxgbentries__oxshopid = new oxField($sShopId);
308  $oEntry->oxgbentries__oxuserid = new oxField($sUserId);
309  $oEntry->oxgbentries__oxcontent = new oxField($sReviewText);
310  $oEntry->save();
311  }
312 
313  return 'guestbook';
314  }
315 
321  public function getBreadCrumb()
322  {
323  $aPaths = array();
324  $aPath = array();
325 
326  $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
327  $aPath['title'] = oxRegistry::getLang()->translateString('GUESTBOOK', $iBaseLanguage, false);
328  $aPath['link'] = $this->getLink();
329  $aPaths[] = $aPath;
330 
331  return $aPaths;
332  }
333 }