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 $_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
00095 if ( $this->_blShowLogin ) {
00096
00097 return $this->_sThisLoginTemplate;
00098 }
00099
00100 $this->getEntries();
00101 return $this->_sThisTemplate;
00102 }
00103
00109 public function getSortColumns()
00110 {
00111 return $this->_aSortColumns;
00112 }
00113
00119 public function getGbSortBy()
00120 {
00121 return $this->_sListOrderBy;
00122 }
00123
00129 public function getGbSortDir()
00130 {
00131 return $this->_sListOrderDir;
00132 }
00133
00139 public function getEntries()
00140 {
00141 if ( $this->_aEntries === null) {
00142 $this->_aEntries = false;
00143 $iNrofCatArticles = (int) $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00144 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00145
00146
00147 $oEntries = oxNew( 'oxgbentry' );
00148 if ( $iCnt = $oEntries->getEntryCount() ) {
00149 $this->_iCntPages = round( $iCnt / $iNrofCatArticles + 0.49 );
00150 $this->_aEntries = $oEntries->getAllEntries( $this->getActPage() * $iNrofCatArticles, $iNrofCatArticles, $this->getSortingSql( 'oxgb' ) );
00151 }
00152 }
00153
00154 return $this->_aEntries;
00155 }
00156
00162 public function floodProtection()
00163 {
00164 if ( $this->_blFloodProtection === null ) {
00165 $this->_blFloodProtection = false;
00166
00167 $sUserId = oxSession::getVar( 'usr' );
00168 $sUserId = $sUserId ? $sUserId : 0;
00169
00170 $oEntries = oxNew( 'oxgbentry' );
00171 $this->_blFloodProtection = $oEntries->floodProtection( $this->getConfig()->getShopId(), $sUserId );
00172 }
00173 return $this->_blFloodProtection;
00174 }
00175
00181 public function getSortOrderByParameterName()
00182 {
00183 return 'gborderby';
00184 }
00185
00191 public function getSortOrderParameterName()
00192 {
00193 return 'gborder';
00194 }
00195
00209 public function prepareSortColumns()
00210 {
00211 $oUtils = oxRegistry::getUtils();
00212
00213 $this->_aSortColumns = array( 'author', 'date' );
00214
00215 $sSortBy = oxConfig::getParameter( $this->getSortOrderByParameterName() );
00216 $sSortDir = oxConfig::getParameter( $this->getSortOrderParameterName() );
00217
00218 if ( !$sSortBy && $aSorting = $this->getSorting( 'oxgb' ) ) {
00219 $sSortBy = $aSorting['sortby'];
00220 $sSortDir = $aSorting['sortdir'];
00221 }
00222
00223
00224 if ( !$sSortBy ) {
00225 $sSortBy = 'date';
00226 $sSortDir = 'desc';
00227 }
00228
00229 if ( $sSortBy && oxDb::getInstance()->isValidFieldName( $sSortBy ) &&
00230 $sSortDir && oxRegistry::getUtils()->isValidAlpha( $sSortDir ) ) {
00231
00232 $this->_sListOrderBy = $sSortBy;
00233 $this->_sListOrderDir = $sSortDir;
00234
00235
00236 $this->setItemSorting( 'oxgb', $sSortBy, $sSortDir );
00237 }
00238 }
00239
00245 public function getPageNavigation()
00246 {
00247 if ( $this->_oPageNavigation === null ) {
00248 $this->_oPageNavigation = false;
00249 $this->_oPageNavigation = $this->generatePageNavigation();
00250 }
00251 return $this->_oPageNavigation;
00252 }
00253
00261 public function saveEntry()
00262 {
00263 $sReviewText = trim( ( string ) oxConfig::getParameter( 'rvw_txt', true ) );
00264 $sShopId = $this->getConfig()->getShopId();
00265 $sUserId = oxSession::getVar( 'usr' );
00266
00267
00268 if ( !$sUserId ) {
00269 oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'EXCEPTION_GUESTBOOKENTRY_ERRLOGGINTOWRITEENTRY' );
00270
00271 return;
00272 }
00273
00274 if ( !$sShopId ) {
00275 oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'EXCEPTION_GUESTBOOKENTRY_ERRUNDEFINEDSHOP' );
00276 return 'guestbookentry';
00277 }
00278
00279
00280 if ( '' == $sReviewText ) {
00281 oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'EXCEPTION_GUESTBOOKENTRY_ERRREVIEWCONTAINSNOTEXT' );
00282 return 'guestbookentry';
00283 }
00284
00285
00286 $oEntrie = oxNew( 'oxgbentry' );
00287 if ( $oEntrie->floodProtection( $sShopId, $sUserId ) ) {
00288 oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'EXCEPTION_GUESTBOOKENTRY_ERRMAXIMUMNOMBEREXCEEDED' );
00289 return 'guestbookentry';
00290 }
00291
00292
00293 if ( $this->canAcceptFormData() ) {
00294
00295 $oEntry = oxNew( 'oxgbentry' );
00296 $oEntry->oxgbentries__oxshopid = new oxField($sShopId);
00297 $oEntry->oxgbentries__oxuserid = new oxField($sUserId);
00298 $oEntry->oxgbentries__oxcontent = new oxField($sReviewText);
00299 $oEntry->save();
00300 }
00301
00302 return 'guestbook';
00303 }
00304
00310 public function getBreadCrumb()
00311 {
00312 $aPaths = array();
00313 $aPath = array();
00314
00315 $aPath['title'] = oxRegistry::getLang()->translateString( 'PAGE_GUESTBOOK_LIST_GUESTBOOK', oxRegistry::getLang()->getBaseLanguage(), false );
00316 $aPath['link'] = $this->getLink();
00317 $aPaths[] = $aPath;
00318
00319 return $aPaths;
00320 }
00321 }