guestbook.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class GuestBook extends oxUBase
00008 {
00009 
00015     protected $_iCntPages = null;
00016 
00022     protected $_blShowLogin = false;
00023 
00029     protected $_aSortColumns = null;
00030 
00036     protected $_sListOrderBy = false;
00037 
00043     protected $_sListOrderDir = false;
00044 
00050     protected $_blFloodProtection = null;
00051 
00057     protected $_aEntries = null;
00058 
00064     protected $_sThisTemplate = 'page/guestbook/guestbook.tpl';
00065 
00071     protected $_sThisLoginTemplate = 'page/guestbook/guestbook_login.tpl';
00072 
00078     protected $_blShowSorting = true;
00079 
00085     protected $_oPageNavigation = null;
00086 
00092     protected $_iViewIndexState = VIEW_INDEXSTATE_NOINDEXNOFOLLOW;
00093 
00094 
00102     public function render()
00103     {
00104         parent::render();
00105 
00106         // #774C no user mail and password check in guesbook
00107         if ($this->_blShowLogin) {
00108             //no valid login
00109             return $this->_sThisLoginTemplate;
00110         }
00111 
00112         $this->getEntries();
00113 
00114         return $this->_sThisTemplate;
00115     }
00116 
00122     public function getSortColumns()
00123     {
00124         if ($this->_aSortColumns === null) {
00125             $this->setSortColumns(array('author', 'date'));
00126         }
00127 
00128         return $this->_aSortColumns;
00129     }
00130 
00136     public function getGbSortBy()
00137     {
00138         return $this->_sListOrderBy;
00139     }
00140 
00146     public function getGbSortDir()
00147     {
00148         return $this->_sListOrderDir;
00149     }
00150 
00156     public function getEntries()
00157     {
00158         if ($this->_aEntries === null) {
00159             $this->_aEntries = false;
00160             $iNrofCatArticles = (int) $this->getConfig()->getConfigParam('iNrofCatArticles');
00161             $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00162 
00163             // loading only if there is some data
00165             $oEntries = oxNew('oxgbentry');
00166             if ($iCnt = $oEntries->getEntryCount()) {
00167                 $this->_iCntPages = round($iCnt / $iNrofCatArticles + 0.49);
00168                 $this->_aEntries = $oEntries->getAllEntries(
00169                     $this->getActPage() * $iNrofCatArticles,
00170                     $iNrofCatArticles,
00171                     $this->getSortingSql($this->getSortIdent())
00172                 );
00173             }
00174         }
00175 
00176         return $this->_aEntries;
00177     }
00178 
00184     public function floodProtection()
00185     {
00186         if ($this->_blFloodProtection === null) {
00187             $this->_blFloodProtection = false;
00188             // is user logged in ?
00189             $sUserId = oxRegistry::getSession()->getVariable('usr');
00190             $sUserId = $sUserId ? $sUserId : 0;
00191 
00192             $oEntries = oxNew('oxgbentry');
00193             $this->_blFloodProtection = $oEntries->floodProtection($this->getConfig()->getShopId(), $sUserId);
00194         }
00195 
00196         return $this->_blFloodProtection;
00197     }
00198 
00204     public function getSortOrderByParameterName()
00205     {
00206         return 'gborderby';
00207     }
00208 
00214     public function getSortOrderParameterName()
00215     {
00216         return 'gborder';
00217     }
00218 
00224     public function getSortIdent()
00225     {
00226         return 'oxgb';
00227     }
00228 
00234     public function getDefaultSorting()
00235     {
00236         $aSorting = array('sortby' => 'date', 'sortdir' => 'desc');
00237 
00238         return $aSorting;
00239     }
00240 
00246     public function getPageNavigation()
00247     {
00248         if ($this->_oPageNavigation === null) {
00249             $this->_oPageNavigation = false;
00250             $this->_oPageNavigation = $this->generatePageNavigation();
00251         }
00252 
00253         return $this->_oPageNavigation;
00254     }
00255 
00263     public function saveEntry()
00264     {
00265         if (!oxRegistry::getSession()->checkSessionChallenge()) {
00266             return;
00267         }
00268 
00269         $sReviewText = trim(( string ) oxRegistry::getConfig()->getRequestParameter('rvw_txt', true));
00270         $sShopId = $this->getConfig()->getShopId();
00271         $sUserId = oxRegistry::getSession()->getVariable('usr');
00272 
00273         // guest book`s entry is validated
00274         $oUtilsView = oxRegistry::get("oxUtilsView");
00275         if (!$sUserId) {
00276             $oUtilsView->addErrorToDisplay('ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_LOGIN_TO_WRITE_ENTRY');
00277 
00278             //return to same page
00279             return;
00280         }
00281 
00282         if (!$sShopId) {
00283             $oUtilsView->addErrorToDisplay('ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_UNDEFINED_SHOP');
00284 
00285             return 'guestbookentry';
00286         }
00287 
00288         // empty entries validation
00289         if ('' == $sReviewText) {
00290             $oUtilsView->addErrorToDisplay('ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_REVIEW_CONTAINS_NO_TEXT');
00291 
00292             return 'guestbook';
00293         }
00294 
00295         // flood protection
00296         $oEntrie = oxNew('oxgbentry');
00297         if ($oEntrie->floodProtection($sShopId, $sUserId)) {
00298             $oUtilsView->addErrorToDisplay('ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_MAXIMUM_NUMBER_EXCEEDED');
00299 
00300             return 'guestbookentry';
00301         }
00302 
00303         // double click protection
00304         if ($this->canAcceptFormData()) {
00305             // here the guest book entry is saved
00306             $oEntry = oxNew('oxgbentry');
00307             $oEntry->oxgbentries__oxshopid = new oxField($sShopId);
00308             $oEntry->oxgbentries__oxuserid = new oxField($sUserId);
00309             $oEntry->oxgbentries__oxcontent = new oxField($sReviewText);
00310             $oEntry->save();
00311         }
00312 
00313         return 'guestbook';
00314     }
00315 
00321     public function getBreadCrumb()
00322     {
00323         $aPaths = array();
00324         $aPath = array();
00325 
00326         $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
00327         $aPath['title'] = oxRegistry::getLang()->translateString('GUESTBOOK', $iBaseLanguage, false);
00328         $aPath['link'] = $this->getLink();
00329         $aPaths[] = $aPath;
00330 
00331         return $aPaths;
00332     }
00333 }