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 = null;
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 if ( $this->_aSortColumns === null) {
00112 $this->setSortColumns( array( 'author', 'date' ) );
00113 }
00114 return $this->_aSortColumns;
00115 }
00116
00122 public function getGbSortBy()
00123 {
00124 return $this->_sListOrderBy;
00125 }
00126
00132 public function getGbSortDir()
00133 {
00134 return $this->_sListOrderDir;
00135 }
00136
00142 public function getEntries()
00143 {
00144 if ( $this->_aEntries === null) {
00145 $this->_aEntries = false;
00146 $iNrofCatArticles = (int) $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00147 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00148
00149
00150 $oEntries = oxNew( 'oxgbentry' );
00151 if ( $iCnt = $oEntries->getEntryCount() ) {
00152 $this->_iCntPages = round( $iCnt / $iNrofCatArticles + 0.49 );
00153 $this->_aEntries = $oEntries->getAllEntries( $this->getActPage() * $iNrofCatArticles, $iNrofCatArticles, $this->getSortingSql( $this->getSortIdent() ) );
00154 }
00155 }
00156
00157 return $this->_aEntries;
00158 }
00159
00165 public function floodProtection()
00166 {
00167 if ( $this->_blFloodProtection === null ) {
00168 $this->_blFloodProtection = false;
00169
00170 $sUserId = oxSession::getVar( 'usr' );
00171 $sUserId = $sUserId ? $sUserId : 0;
00172
00173 $oEntries = oxNew( 'oxgbentry' );
00174 $this->_blFloodProtection = $oEntries->floodProtection( $this->getConfig()->getShopId(), $sUserId );
00175 }
00176 return $this->_blFloodProtection;
00177 }
00178
00184 public function getSortOrderByParameterName()
00185 {
00186 return 'gborderby';
00187 }
00188
00194 public function getSortOrderParameterName()
00195 {
00196 return 'gborder';
00197 }
00198
00204 public function getSortIdent()
00205 {
00206 return 'oxgb';
00207 }
00208
00214 public function getDefaultSorting()
00215 {
00216 $aSorting = array ( 'sortby' => 'date', 'sortdir' => 'desc' );
00217 return $aSorting;
00218 }
00219
00235 public function prepareSortColumns()
00236 {
00237 $oUtils = oxRegistry::getUtils();
00238
00239 $this->_aSortColumns = array( 'author', 'date' );
00240
00241 $sSortBy = oxConfig::getParameter( $this->getSortOrderByParameterName() );
00242 $sSortDir = oxConfig::getParameter( $this->getSortOrderParameterName() );
00243
00244 if ( !$sSortBy && $aSorting = $this->getSorting( 'oxgb' ) ) {
00245 $sSortBy = $aSorting['sortby'];
00246 $sSortDir = $aSorting['sortdir'];
00247 }
00248
00249
00250 if ( !$sSortBy ) {
00251 $sSortBy = 'date';
00252 $sSortDir = 'desc';
00253 }
00254
00255 if ( $sSortBy && oxDb::getInstance()->isValidFieldName( $sSortBy ) &&
00256 $sSortDir && oxRegistry::getUtils()->isValidAlpha( $sSortDir ) ) {
00257
00258 $this->_sListOrderBy = $sSortBy;
00259 $this->_sListOrderDir = $sSortDir;
00260
00261
00262 $this->setItemSorting( 'oxgb', $sSortBy, $sSortDir );
00263 }
00264 }
00265
00271 public function getPageNavigation()
00272 {
00273 if ( $this->_oPageNavigation === null ) {
00274 $this->_oPageNavigation = false;
00275 $this->_oPageNavigation = $this->generatePageNavigation();
00276 }
00277 return $this->_oPageNavigation;
00278 }
00279
00287 public function saveEntry()
00288 {
00289 if (!oxRegistry::getSession()->checkSessionChallenge()) {
00290 return;
00291 }
00292
00293 $sReviewText = trim( ( string ) oxConfig::getParameter( 'rvw_txt', true ) );
00294 $sShopId = $this->getConfig()->getShopId();
00295 $sUserId = oxSession::getVar( 'usr' );
00296
00297
00298 if ( !$sUserId ) {
00299 oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_LOGIN_TO_WRITE_ENTRY' );
00300
00301 return;
00302 }
00303
00304 if ( !$sShopId ) {
00305 oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_UNDEFINED_SHOP' );
00306 return 'guestbookentry';
00307 }
00308
00309
00310 if ( '' == $sReviewText ) {
00311 oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_REVIEW_CONTAINS_NO_TEXT' );
00312 return 'guestbook';
00313 }
00314
00315
00316 $oEntrie = oxNew( 'oxgbentry' );
00317 if ( $oEntrie->floodProtection( $sShopId, $sUserId ) ) {
00318 oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_MAXIMUM_NUMBER_EXCEEDED' );
00319 return 'guestbookentry';
00320 }
00321
00322
00323 if ( $this->canAcceptFormData() ) {
00324
00325 $oEntry = oxNew( 'oxgbentry' );
00326 $oEntry->oxgbentries__oxshopid = new oxField($sShopId);
00327 $oEntry->oxgbentries__oxuserid = new oxField($sUserId);
00328 $oEntry->oxgbentries__oxcontent = new oxField($sReviewText);
00329 $oEntry->save();
00330 }
00331
00332 return 'guestbook';
00333 }
00334
00340 public function getBreadCrumb()
00341 {
00342 $aPaths = array();
00343 $aPath = array();
00344
00345 $aPath['title'] = oxRegistry::getLang()->translateString( 'GUESTBOOK', oxRegistry::getLang()->getBaseLanguage(), false );
00346 $aPath['link'] = $this->getLink();
00347 $aPaths[] = $aPath;
00348
00349 return $aPaths;
00350 }
00351 }