OXID eShop CE  4.10.6
 All Classes Namespaces Files Functions Variables Pages
guestbook.php
Go to the documentation of this file.
1 <?php
2 
9 class GuestBook extends oxUBase
10 {
11 
17  protected $_iCntPages = null;
18 
24  protected $_blShowLogin = false;
25 
31  protected $_aSortColumns = null;
32 
38  protected $_sListOrderBy = false;
39 
45  protected $_sListOrderDir = false;
46 
52  protected $_blFloodProtection = null;
53 
59  protected $_aEntries = null;
60 
66  protected $_sThisTemplate = 'page/guestbook/guestbook.tpl';
67 
73  protected $_sThisLoginTemplate = 'page/guestbook/guestbook_login.tpl';
74 
80  protected $_blShowSorting = true;
81 
87  protected $_oPageNavigation = null;
88 
95 
96 
104  public function render()
105  {
106  parent::render();
107 
108  // #774C no user mail and password check in guesbook
109  if ($this->_blShowLogin) {
110  //no valid login
112  }
113 
114  $this->getEntries();
115 
116  return $this->_sThisTemplate;
117  }
118 
124  public function getSortColumns()
125  {
126  if ($this->_aSortColumns === null) {
127  $this->setSortColumns(array('author', 'date'));
128  }
129 
130  return $this->_aSortColumns;
131  }
132 
138  public function getGbSortBy()
139  {
140  return $this->_sListOrderBy;
141  }
142 
148  public function getGbSortDir()
149  {
150  return $this->_sListOrderDir;
151  }
152 
158  public function getEntries()
159  {
160  if ($this->_aEntries === null) {
161  $this->_aEntries = false;
162  $iNrofCatArticles = (int) $this->getConfig()->getConfigParam('iNrofCatArticles');
163  $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
164 
165  // loading only if there is some data
167  $oEntries = oxNew('oxgbentry');
168  if ($iCnt = $oEntries->getEntryCount()) {
169  $this->_iCntPages = round($iCnt / $iNrofCatArticles + 0.49);
170  $this->_aEntries = $oEntries->getAllEntries(
171  $this->getActPage() * $iNrofCatArticles,
172  $iNrofCatArticles,
173  $this->getSortingSql($this->getSortIdent())
174  );
175  }
176  }
177 
178  return $this->_aEntries;
179  }
180 
186  public function floodProtection()
187  {
188  if ($this->_blFloodProtection === null) {
189  $this->_blFloodProtection = false;
190  // is user logged in ?
191  $sUserId = oxRegistry::getSession()->getVariable('usr');
192  $sUserId = $sUserId ? $sUserId : 0;
193 
194  $oEntries = oxNew('oxgbentry');
195  $this->_blFloodProtection = $oEntries->floodProtection($this->getConfig()->getShopId(), $sUserId);
196  }
197 
199  }
200 
206  public function getSortOrderByParameterName()
207  {
208  return 'gborderby';
209  }
210 
216  public function getSortOrderParameterName()
217  {
218  return 'gborder';
219  }
220 
226  public function getSortIdent()
227  {
228  return 'oxgb';
229  }
230 
236  public function getDefaultSorting()
237  {
238  $aSorting = array('sortby' => 'date', 'sortdir' => 'desc');
239 
240  return $aSorting;
241  }
242 
248  public function getPageNavigation()
249  {
250  if ($this->_oPageNavigation === null) {
251  $this->_oPageNavigation = false;
252  $this->_oPageNavigation = $this->generatePageNavigation();
253  }
254 
256  }
257 
265  public function saveEntry()
266  {
267  if (!oxRegistry::getSession()->checkSessionChallenge()) {
268  return;
269  }
270 
271  $sReviewText = trim(( string ) oxRegistry::getConfig()->getRequestParameter('rvw_txt', true));
272  $sShopId = $this->getConfig()->getShopId();
273  $sUserId = oxRegistry::getSession()->getVariable('usr');
274 
275  // guest book`s entry is validated
276  $oUtilsView = oxRegistry::get("oxUtilsView");
277  if (!$sUserId) {
278  $oUtilsView->addErrorToDisplay('ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_LOGIN_TO_WRITE_ENTRY');
279 
280  //return to same page
281  return;
282  }
283 
284  if (!$sShopId) {
285  $oUtilsView->addErrorToDisplay('ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_UNDEFINED_SHOP');
286 
287  return 'guestbookentry';
288  }
289 
290  // empty entries validation
291  if ('' == $sReviewText) {
292  $oUtilsView->addErrorToDisplay('ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_REVIEW_CONTAINS_NO_TEXT');
293 
294  return 'guestbook';
295  }
296 
297  // flood protection
298  $oEntrie = oxNew('oxgbentry');
299  if ($oEntrie->floodProtection($sShopId, $sUserId)) {
300  $oUtilsView->addErrorToDisplay('ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_MAXIMUM_NUMBER_EXCEEDED');
301 
302  return 'guestbookentry';
303  }
304 
305  // double click protection
306  if ($this->canAcceptFormData()) {
307  // here the guest book entry is saved
308  $oEntry = oxNew('oxgbentry');
309  $oEntry->oxgbentries__oxshopid = new oxField($sShopId);
310  $oEntry->oxgbentries__oxuserid = new oxField($sUserId);
311  $oEntry->oxgbentries__oxcontent = new oxField($sReviewText);
312  $oEntry->save();
313  }
314 
315  return 'guestbook';
316  }
317 
323  public function getBreadCrumb()
324  {
325  $aPaths = array();
326  $aPath = array();
327 
328  $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
329  $aPath['title'] = oxRegistry::getLang()->translateString('GUESTBOOK', $iBaseLanguage, false);
330  $aPath['link'] = $this->getLink();
331  $aPaths[] = $aPath;
332 
333  return $aPaths;
334  }
335 }