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 $myConfig = $this->getConfig();
00103
00104
00105
00106 $this->_aViewData['hideentries'] = $this->floodProtection();
00107
00108 $this->_aViewData["allsortcolumns"] = $this->getSortColumns();
00109
00110 $this->_aViewData['gborderby'] = $this->getGbSortBy();
00111 $this->_aViewData['gborder'] = $this->getGbSortDir();
00112
00113
00114 $this->_aViewData['entries'] = $this->getEntries();
00115
00116
00117 $this->_aViewData['pageNavigation'] = $this->getPageNavigation();
00118
00119 return $this->_sThisTemplate;
00120 }
00121
00129 public function showLogin()
00130 {
00131 $this->_blShowLogin = true;
00132 }
00133
00139 public function getSortColumns()
00140 {
00141 return $this->_aSortColumns;
00142 }
00143
00149 public function getGbSortBy()
00150 {
00151 return $this->_sSortBy;
00152 }
00153
00159 public function getGbSortDir()
00160 {
00161 return $this->_sSortDir;
00162 }
00163
00169 public function getEntries()
00170 {
00171 if ( $this->_aEntries === null) {
00172 $this->_aEntries = false;
00173 $iNrofCatArticles = (int) $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00174 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00175
00176
00177 $oEntries = oxNew( 'oxgbentry' );
00178 if ( $iCnt = $oEntries->getEntryCount() ) {
00179 $this->_iCntPages = round( $iCnt / $iNrofCatArticles + 0.49 );
00180 $this->_aEntries = $oEntries->getAllEntries( $this->getActPage() * $iNrofCatArticles, $iNrofCatArticles, $this->getSortingSql( 'oxgb' ) );
00181 }
00182 }
00183 return $this->_aEntries;
00184 }
00185
00191 public function floodProtection()
00192 {
00193 if ( $this->_blFloodProtection === null ) {
00194 $this->_blFloodProtection = false;
00195
00196 $sUserId = oxSession::getVar( 'usr' );
00197 $sUserId = $sUserId ? $sUserId : 0;
00198
00199 $oEntries = oxNew( 'oxgbentry' );
00200 $this->_blFloodProtection = $oEntries->floodProtection( $this->getConfig()->getShopId(), $sUserId );
00201
00202 }
00203 return $this->_blFloodProtection;
00204 }
00205
00219 public function prepareSortColumns()
00220 {
00221 $oUtils = oxUtils::getInstance();
00222
00223 $this->_aSortColumns = array( 'oxuser.oxusername', 'oxgbentries.oxcreate' );
00224
00225 $sSortBy = oxConfig::getParameter( 'gborderby' );
00226 $sSortDir = oxConfig::getParameter( 'gborder' );
00227
00228 if ( !$sSortBy && $aSorting = $this->getSorting( 'oxgb' ) ) {
00229 $sSortBy = $aSorting['sortby'];
00230 $sSortDir = $aSorting['sortdir'];
00231 }
00232
00233
00234 if ( !$sSortBy ) {
00235 $sSortBy = 'oxgbentries.oxcreate';
00236 $sSortDir = 'desc';
00237 }
00238
00239 if ( $sSortBy && oxDb::getInstance()->isValidFieldName( $sSortBy ) &&
00240 $sSortDir && oxUtils::getInstance()->isValidAlpha( $sSortDir ) ) {
00241
00242 $this->_sSortBy = $sSortBy;
00243 $this->_sSortDir = $sSortDir;
00244
00245
00246 $this->setItemSorting( 'oxgb', $sSortBy, $sSortDir );
00247 }
00248 }
00249
00255 public function getPageNavigation()
00256 {
00257 if ( $this->_oPageNavigation === null ) {
00258 $this->_oPageNavigation = false;
00259 $this->_oPageNavigation = $this->generatePageNavigation();
00260 }
00261 return $this->_oPageNavigation;
00262 }
00263
00264 }