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 = false;
00026 
00031     protected $_sSortBy = false;
00032 
00037     protected $_sSortDir = false;
00038 
00043     protected $_blFloodProtection = null;
00044 
00049     protected $_aEntries = null;
00050 
00055     protected $_sThisTemplate = 'guestbook.tpl';
00056 
00061     protected $_sThisLoginTemplate = 'guestbook_login.tpl';
00062 
00067     protected $_blShowSorting = true;
00068 
00073     protected $_oPageNavigation = null;
00074 
00081     protected $_iViewIndexState = 1;
00082 
00093     public function render()
00094     {
00095         parent::render();
00096 
00097         // #774C no user mail and password check in guesbook
00098         if ( $this->_blShowLogin ) {
00099             //no valid login
00100             return $this->_sThisLoginTemplate;
00101         }
00102 
00103         $myConfig = $this->getConfig();
00104 
00105 
00106         // flood protection
00107         $this->_aViewData['hideentries'] = $this->floodProtection();
00108 
00109         $this->_aViewData["allsortcolumns"] = $this->getSortColumns();
00110 
00111         $this->_aViewData['gborderby'] = $this->getGbSortBy();
00112         $this->_aViewData['gborder']   = $this->getGbSortDir();
00113 
00114         // loading GB records
00115         $this->_aViewData['entries'] = $this->getEntries();
00116 
00117         // page navigation object
00118         $this->_aViewData['pageNavigation'] = $this->getPageNavigation;
00119 
00120         return $this->_sThisTemplate;
00121     }
00122 
00128     public function showLogin()
00129     {
00130         $this->_blShowLogin = true;
00131     }
00132 
00138     public function getSortColumns()
00139     {
00140         return $this->_aSortColumns;
00141     }
00142 
00148     public function getGbSortBy()
00149     {
00150         return $this->_sSortBy;
00151     }
00152 
00158     public function getGbSortDir()
00159     {
00160         return $this->_sSortDir;
00161     }
00162 
00168     public function getEntries()
00169     {
00170         if ( $this->_aEntries === null) {
00171             $this->_aEntries  = false;
00172             $iNrofCatArticles = (int) $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00173             $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00174 
00175             // loading only if there is some data
00176             $oEntries = oxNew( 'oxgbentry' );
00177             if ( $iCnt = $oEntries->getEntryCount() ) {
00178                 $this->_iCntPages = round( $iCnt / $iNrofCatArticles + 0.49 );
00179                 $this->_aEntries  = $oEntries->getAllEntries( $this->getActPage() * $iNrofCatArticles, $iNrofCatArticles, $this->getSortingSql( 'oxgb' ) );
00180             }
00181         }
00182         return $this->_aEntries;
00183     }
00184 
00190     public function floodProtection()
00191     {
00192         if ( $this->_blFloodProtection === null ) {
00193             $this->_blFloodProtection = false;
00194             // is user logged in ?
00195             $sUserId = oxSession::getVar( 'usr' );
00196             $sUserId = $sUserId ? $sUserId : 0;
00197 
00198             $oEntries = oxNew( 'oxgbentry' );
00199             $this->_blFloodProtection = $oEntries->floodProtection( $this->getConfig()->getShopId(), $sUserId );
00200 
00201         }
00202         return $this->_blFloodProtection;
00203     }
00204 
00218     public function prepareSortColumns()
00219     {
00220         $oUtils = oxUtils::getInstance();
00221 
00222         $this->_aSortColumns  = array( 'oxuser.oxusername', 'oxgbentries.oxcreate' );
00223 
00224         $sSortBy  = oxConfig::getParameter( 'gborderby' );
00225         $sSortDir = oxConfig::getParameter( 'gborder' );
00226 
00227         if ( !$sSortBy && $aSorting = $this->getSorting( 'oxgb' ) ) {
00228             $sSortBy  = $aSorting['sortby'];
00229             $sSortDir = $aSorting['sortdir'];
00230         }
00231 
00232         // finally setting defaults
00233         if ( !$sSortBy ) {
00234             $sSortBy  = 'oxgbentries.oxcreate';
00235             $sSortDir = 'desc';
00236         }
00237 
00238         if ( $sSortBy && oxDb::getInstance()->isValidFieldName( $sSortBy ) &&
00239              $sSortDir && oxUtils::getInstance()->isValidAlpha( $sSortDir ) ) {
00240 
00241             $this->_sSortBy  = $sSortBy;
00242             $this->_sSortDir = $sSortDir;
00243 
00244             // caching sorting config
00245             $this->setItemSorting( 'oxgb', $sSortBy, $sSortDir );
00246         }
00247     }
00248 
00254     public function getPageNavigation()
00255     {
00256         if ( $this->_oPageNavigation === null ) {
00257             $this->_oPageNavigation = false;
00258             $this->_oPageNavigation = $this->generatePageNavigation();
00259         }
00260         return $this->_oPageNavigation;
00261     }
00262 
00263 }

Generated on Thu Dec 4 12:04:57 2008 for OXID eShop CE by  doxygen 1.5.5