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
00080 protected $_iViewIndexState = VIEW_INDEXSTATE_NOINDEXNOFOLLOW;
00081
00092 public function render()
00093 {
00094 parent::render();
00095
00096
00097 if ( $this->_blShowLogin ) {
00098
00099 return $this->_sThisLoginTemplate;
00100 }
00101
00102
00103 $this->_aViewData['hideentries'] = $this->floodProtection();
00104
00105 $this->_aViewData["allsortcolumns"] = $this->getSortColumns();
00106
00107 $this->_aViewData['gborderby'] = $this->getGbSortBy();
00108 $this->_aViewData['gborder'] = $this->getGbSortDir();
00109
00110
00111 $this->_aViewData['entries'] = $this->getEntries();
00112
00113
00114 $this->_aViewData['pageNavigation'] = $this->getPageNavigation();
00115
00116 return $this->_sThisTemplate;
00117 }
00118
00126 public function showLogin()
00127 {
00128 $this->_blShowLogin = true;
00129 }
00130
00136 public function getSortColumns()
00137 {
00138 return $this->_aSortColumns;
00139 }
00140
00146 public function getGbSortBy()
00147 {
00148 return $this->_sSortBy;
00149 }
00150
00156 public function getGbSortDir()
00157 {
00158 return $this->_sSortDir;
00159 }
00160
00166 public function getEntries()
00167 {
00168 if ( $this->_aEntries === null) {
00169 $this->_aEntries = false;
00170 $iNrofCatArticles = (int) $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00171 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00172
00173
00174 $oEntries = oxNew( 'oxgbentry' );
00175 if ( $iCnt = $oEntries->getEntryCount() ) {
00176 $this->_iCntPages = round( $iCnt / $iNrofCatArticles + 0.49 );
00177 $this->_aEntries = $oEntries->getAllEntries( $this->getActPage() * $iNrofCatArticles, $iNrofCatArticles, $this->getSortingSql( 'oxgb' ) );
00178 }
00179 }
00180 return $this->_aEntries;
00181 }
00182
00188 public function floodProtection()
00189 {
00190 if ( $this->_blFloodProtection === null ) {
00191 $this->_blFloodProtection = false;
00192
00193 $sUserId = oxSession::getVar( 'usr' );
00194 $sUserId = $sUserId ? $sUserId : 0;
00195
00196 $oEntries = oxNew( 'oxgbentry' );
00197 $this->_blFloodProtection = $oEntries->floodProtection( $this->getConfig()->getShopId(), $sUserId );
00198
00199 }
00200 return $this->_blFloodProtection;
00201 }
00202
00216 public function prepareSortColumns()
00217 {
00218 $oUtils = oxUtils::getInstance();
00219
00220 $this->_aSortColumns = array( 'oxuser.oxusername', 'oxgbentries.oxcreate' );
00221
00222 $sSortBy = oxConfig::getParameter( 'gborderby' );
00223 $sSortDir = oxConfig::getParameter( 'gborder' );
00224
00225 if ( !$sSortBy && $aSorting = $this->getSorting( 'oxgb' ) ) {
00226 $sSortBy = $aSorting['sortby'];
00227 $sSortDir = $aSorting['sortdir'];
00228 }
00229
00230
00231 if ( !$sSortBy ) {
00232 $sSortBy = 'oxgbentries.oxcreate';
00233 $sSortDir = 'desc';
00234 }
00235
00236 if ( $sSortBy && oxDb::getInstance()->isValidFieldName( $sSortBy ) &&
00237 $sSortDir && oxUtils::getInstance()->isValidAlpha( $sSortDir ) ) {
00238
00239 $this->_sSortBy = $sSortBy;
00240 $this->_sSortDir = $sSortDir;
00241
00242
00243 $this->setItemSorting( 'oxgb', $sSortBy, $sSortDir );
00244 }
00245 }
00246
00252 public function getPageNavigation()
00253 {
00254 if ( $this->_oPageNavigation === null ) {
00255 $this->_oPageNavigation = false;
00256 $this->_oPageNavigation = $this->generatePageNavigation();
00257 }
00258 return $this->_oPageNavigation;
00259 }
00260
00261 }