guestbook.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class GuestBook extends oxUBase
00008 {
00013     protected $_iCntPages = null;
00014 
00019     protected $_blShowLogin = false;
00020 
00025     protected $_aSortColumns = null;
00026 
00031     protected $_sListOrderBy = false;
00032 
00037     protected $_sListOrderDir = false;
00038 
00043     protected $_blFloodProtection = null;
00044 
00049     protected $_aEntries = null;
00050 
00055     protected $_sThisTemplate = 'page/guestbook/guestbook.tpl';
00056 
00061     protected $_sThisLoginTemplate = 'page/guestbook/guestbook_login.tpl';
00062 
00067     protected $_blShowSorting = true;
00068 
00073     protected $_oPageNavigation = null;
00074 
00080     protected $_iViewIndexState = VIEW_INDEXSTATE_NOINDEXNOFOLLOW;
00081 
00082 
00090     public function render()
00091     {
00092         parent::render();
00093 
00094         // #774C no user mail and password check in guesbook
00095         if ( $this->_blShowLogin ) {
00096             //no valid login
00097             return $this->_sThisLoginTemplate;
00098         }
00099 
00100         $this->getEntries();
00101         return $this->_sThisTemplate;
00102     }
00103 
00109     public function getSortColumns()
00110     {
00111         if ( $this->_aSortColumns === null) {
00112             $this->setSortColumns( array( 'author', 'date' ) );
00113         }
00114         return $this->_aSortColumns;
00115     }
00116 
00122     public function getGbSortBy()
00123     {
00124         return $this->_sListOrderBy;
00125     }
00126 
00132     public function getGbSortDir()
00133     {
00134         return $this->_sListOrderDir;
00135     }
00136 
00142     public function getEntries()
00143     {
00144         if ( $this->_aEntries === null) {
00145             $this->_aEntries  = false;
00146             $iNrofCatArticles = (int) $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00147             $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00148 
00149             // loading only if there is some data
00150             $oEntries = oxNew( 'oxgbentry' );
00151             if ( $iCnt = $oEntries->getEntryCount() ) {
00152                 $this->_iCntPages = round( $iCnt / $iNrofCatArticles + 0.49 );
00153                 $this->_aEntries  = $oEntries->getAllEntries( $this->getActPage() * $iNrofCatArticles, $iNrofCatArticles, $this->getSortingSql( $this->getSortIdent() ) );
00154             }
00155         }
00156 
00157         return $this->_aEntries;
00158     }
00159 
00165     public function floodProtection()
00166     {
00167         if ( $this->_blFloodProtection === null ) {
00168             $this->_blFloodProtection = false;
00169             // is user logged in ?
00170             $sUserId = oxSession::getVar( 'usr' );
00171             $sUserId = $sUserId ? $sUserId : 0;
00172 
00173             $oEntries = oxNew( 'oxgbentry' );
00174             $this->_blFloodProtection = $oEntries->floodProtection( $this->getConfig()->getShopId(), $sUserId );
00175         }
00176         return $this->_blFloodProtection;
00177     }
00178 
00184     public function getSortOrderByParameterName()
00185     {
00186         return 'gborderby';
00187     }
00188 
00194     public function getSortOrderParameterName()
00195     {
00196         return 'gborder';
00197     }
00198 
00204     public function getSortIdent()
00205     {
00206         return 'oxgb';
00207     }
00208 
00214     public function getDefaultSorting()
00215     {
00216         $aSorting = array ( 'sortby' => 'date', 'sortdir' => 'desc' );
00217         return $aSorting;
00218     }
00219 
00235     public function prepareSortColumns()
00236     {
00237         $oUtils = oxRegistry::getUtils();
00238 
00239         $this->_aSortColumns  = array( 'author', 'date' );
00240 
00241         $sSortBy  = oxConfig::getParameter( $this->getSortOrderByParameterName() );
00242         $sSortDir = oxConfig::getParameter( $this->getSortOrderParameterName() );
00243 
00244         if ( !$sSortBy && $aSorting = $this->getSorting( 'oxgb' ) ) {
00245             $sSortBy  = $aSorting['sortby'];
00246             $sSortDir = $aSorting['sortdir'];
00247         }
00248 
00249         // finally setting defaults
00250         if ( !$sSortBy ) {
00251             $sSortBy  = 'date';
00252             $sSortDir = 'desc';
00253         }
00254 
00255         if ( $sSortBy && oxDb::getInstance()->isValidFieldName( $sSortBy ) &&
00256              $sSortDir && oxRegistry::getUtils()->isValidAlpha( $sSortDir ) ) {
00257 
00258             $this->_sListOrderBy  = $sSortBy;
00259             $this->_sListOrderDir = $sSortDir;
00260 
00261             // caching sorting config
00262             $this->setItemSorting( 'oxgb', $sSortBy, $sSortDir );
00263         }
00264     }
00265 
00271     public function getPageNavigation()
00272     {
00273         if ( $this->_oPageNavigation === null ) {
00274             $this->_oPageNavigation = false;
00275             $this->_oPageNavigation = $this->generatePageNavigation();
00276         }
00277         return $this->_oPageNavigation;
00278     }
00279 
00287     public function saveEntry()
00288     {
00289         $sReviewText = trim( ( string ) oxConfig::getParameter( 'rvw_txt', true ) );
00290         $sShopId     = $this->getConfig()->getShopId();
00291         $sUserId     = oxSession::getVar( 'usr' );
00292 
00293         // guest book`s entry is validated
00294         if ( !$sUserId ) {
00295             oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_LOGIN_TO_WRITE_ENTRY' );
00296             //return to same page
00297             return;
00298         }
00299 
00300         if ( !$sShopId ) {
00301             oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_UNDEFINED_SHOP' );
00302             return 'guestbookentry';
00303         }
00304 
00305         // empty entries validation
00306         if ( '' == $sReviewText ) {
00307             oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_REVIEW_CONTAINS_NO_TEXT' );
00308             return 'guestbook';
00309         }
00310 
00311         // flood protection
00312         $oEntrie = oxNew( 'oxgbentry' );
00313         if ( $oEntrie->floodProtection( $sShopId, $sUserId ) ) {
00314             oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_MAXIMUM_NUMBER_EXCEEDED' );
00315             return 'guestbookentry';
00316         }
00317 
00318         // double click protection
00319         if ( $this->canAcceptFormData() ) {
00320             // here the guest book entry is saved
00321             $oEntry = oxNew( 'oxgbentry' );
00322             $oEntry->oxgbentries__oxshopid  = new oxField($sShopId);
00323             $oEntry->oxgbentries__oxuserid  = new oxField($sUserId);
00324             $oEntry->oxgbentries__oxcontent = new oxField($sReviewText);
00325             $oEntry->save();
00326         }
00327 
00328         return 'guestbook';
00329     }
00330 
00336     public function getBreadCrumb()
00337     {
00338         $aPaths = array();
00339         $aPath = array();
00340 
00341         $aPath['title'] = oxRegistry::getLang()->translateString( 'GUESTBOOK', oxRegistry::getLang()->getBaseLanguage(), false );
00342         $aPath['link']  = $this->getLink();
00343         $aPaths[] = $aPath;
00344 
00345         return $aPaths;
00346     }
00347 }