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