OXID eShop CE  4.8.11
 All Classes Files Functions Variables Pages
guestbook.php
Go to the documentation of this file.
1 <?php
2 
7 class GuestBook extends oxUBase
8 {
13  protected $_iCntPages = null;
14 
19  protected $_blShowLogin = false;
20 
25  protected $_aSortColumns = null;
26 
31  protected $_sListOrderBy = false;
32 
37  protected $_sListOrderDir = false;
38 
43  protected $_blFloodProtection = null;
44 
49  protected $_aEntries = null;
50 
55  protected $_sThisTemplate = 'page/guestbook/guestbook.tpl';
56 
61  protected $_sThisLoginTemplate = 'page/guestbook/guestbook_login.tpl';
62 
67  protected $_blShowSorting = true;
68 
73  protected $_oPageNavigation = null;
74 
81 
82 
90  public function render()
91  {
93 
94  // #774C no user mail and password check in guesbook
95  if ( $this->_blShowLogin ) {
96  //no valid login
98  }
99 
100  $this->getEntries();
101  return $this->_sThisTemplate;
102  }
103 
109  public function getSortColumns()
110  {
111  if ( $this->_aSortColumns === null) {
112  $this->setSortColumns( array( 'author', 'date' ) );
113  }
114  return $this->_aSortColumns;
115  }
116 
122  public function getGbSortBy()
123  {
124  return $this->_sListOrderBy;
125  }
126 
132  public function getGbSortDir()
133  {
134  return $this->_sListOrderDir;
135  }
136 
142  public function getEntries()
143  {
144  if ( $this->_aEntries === null) {
145  $this->_aEntries = false;
146  $iNrofCatArticles = (int) $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
147  $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
148 
149  // loading only if there is some data
150  $oEntries = oxNew( 'oxgbentry' );
151  if ( $iCnt = $oEntries->getEntryCount() ) {
152  $this->_iCntPages = round( $iCnt / $iNrofCatArticles + 0.49 );
153  $this->_aEntries = $oEntries->getAllEntries( $this->getActPage() * $iNrofCatArticles, $iNrofCatArticles, $this->getSortingSql( $this->getSortIdent() ) );
154  }
155  }
156 
157  return $this->_aEntries;
158  }
159 
165  public function floodProtection()
166  {
167  if ( $this->_blFloodProtection === null ) {
168  $this->_blFloodProtection = false;
169  // is user logged in ?
170  $sUserId = oxSession::getVar( 'usr' );
171  $sUserId = $sUserId ? $sUserId : 0;
172 
173  $oEntries = oxNew( 'oxgbentry' );
174  $this->_blFloodProtection = $oEntries->floodProtection( $this->getConfig()->getShopId(), $sUserId );
175  }
177  }
178 
184  public function getSortOrderByParameterName()
185  {
186  return 'gborderby';
187  }
188 
194  public function getSortOrderParameterName()
195  {
196  return 'gborder';
197  }
198 
204  public function getSortIdent()
205  {
206  return 'oxgb';
207  }
208 
214  public function getDefaultSorting()
215  {
216  $aSorting = array ( 'sortby' => 'date', 'sortdir' => 'desc' );
217  return $aSorting;
218  }
219 
235  public function prepareSortColumns()
236  {
237  $oUtils = oxRegistry::getUtils();
238 
239  $this->_aSortColumns = array( 'author', 'date' );
240 
242  $sSortDir = oxConfig::getParameter( $this->getSortOrderParameterName() );
243 
244  if ( !$sSortBy && $aSorting = $this->getSorting( 'oxgb' ) ) {
245  $sSortBy = $aSorting['sortby'];
246  $sSortDir = $aSorting['sortdir'];
247  }
248 
249  // finally setting defaults
250  if ( !$sSortBy ) {
251  $sSortBy = 'date';
252  $sSortDir = 'desc';
253  }
254 
255  if ( $sSortBy && oxDb::getInstance()->isValidFieldName( $sSortBy ) &&
256  $sSortDir && oxRegistry::getUtils()->isValidAlpha( $sSortDir ) ) {
257 
258  $this->_sListOrderBy = $sSortBy;
259  $this->_sListOrderDir = $sSortDir;
260 
261  // caching sorting config
262  $this->setItemSorting( 'oxgb', $sSortBy, $sSortDir );
263  }
264  }
265 
271  public function getPageNavigation()
272  {
273  if ( $this->_oPageNavigation === null ) {
274  $this->_oPageNavigation = false;
275  $this->_oPageNavigation = $this->generatePageNavigation();
276  }
278  }
279 
287  public function saveEntry()
288  {
289  if (!oxRegistry::getSession()->checkSessionChallenge()) {
290  return;
291  }
292 
293  $sReviewText = trim( ( string ) oxConfig::getParameter( 'rvw_txt', true ) );
294  $sShopId = $this->getConfig()->getShopId();
295  $sUserId = oxSession::getVar( 'usr' );
296 
297  // guest book`s entry is validated
298  if ( !$sUserId ) {
299  oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_LOGIN_TO_WRITE_ENTRY' );
300  //return to same page
301  return;
302  }
303 
304  if ( !$sShopId ) {
305  oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_UNDEFINED_SHOP' );
306  return 'guestbookentry';
307  }
308 
309  // empty entries validation
310  if ( '' == $sReviewText ) {
311  oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_REVIEW_CONTAINS_NO_TEXT' );
312  return 'guestbook';
313  }
314 
315  // flood protection
316  $oEntrie = oxNew( 'oxgbentry' );
317  if ( $oEntrie->floodProtection( $sShopId, $sUserId ) ) {
318  oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_MAXIMUM_NUMBER_EXCEEDED' );
319  return 'guestbookentry';
320  }
321 
322  // double click protection
323  if ( $this->canAcceptFormData() ) {
324  // here the guest book entry is saved
325  $oEntry = oxNew( 'oxgbentry' );
326  $oEntry->oxgbentries__oxshopid = new oxField($sShopId);
327  $oEntry->oxgbentries__oxuserid = new oxField($sUserId);
328  $oEntry->oxgbentries__oxcontent = new oxField($sReviewText);
329  $oEntry->save();
330  }
331 
332  return 'guestbook';
333  }
334 
340  public function getBreadCrumb()
341  {
342  $aPaths = array();
343  $aPath = array();
344 
345  $aPath['title'] = oxRegistry::getLang()->translateString( 'GUESTBOOK', oxRegistry::getLang()->getBaseLanguage(), false );
346  $aPath['link'] = $this->getLink();
347  $aPaths[] = $aPath;
348 
349  return $aPaths;
350  }
351 }