guestbookentry.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class GuestbookEntry extends GuestBook
00008 {
00013     protected $_sThisTemplate = 'page/guestbook/guestbookentry.tpl';
00014 
00019     protected $_sGbFormId = null;
00020 
00028     public function saveEntry()
00029     {
00030         $sReviewText = trim( ( string ) oxConfig::getParameter( 'rvw_txt', true ) );
00031         $sShopId     = $this->getConfig()->getShopId();
00032         $sUserId     = oxSession::getVar( 'usr' );
00033 
00034         // guest book`s entry is validated
00035         if ( !$sUserId ) {
00036             oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_LOGIN_TO_WRITE_ENTRY' );
00037             //return to same page
00038             return;
00039         }
00040 
00041         if ( !$sShopId ) {
00042             oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_UNDEFINED_SHOP' );
00043             return 'guestbookentry';
00044         }
00045 
00046         // empty entries validation
00047         if ( '' == $sReviewText ) {
00048             oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_REVIEW_CONTAINS_NO_TEXT' );
00049             return 'guestbookentry';
00050         }
00051 
00052         // flood protection
00053         $oEntrie = oxNew( 'oxgbentry' );
00054         if ( $oEntrie->floodProtection( $sShopId, $sUserId ) ) {
00055             oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_MAXIMUM_NUMBER_EXCEEDED' );
00056             return 'guestbookentry';
00057         }
00058 
00059         // double click protection
00060         if ( $this->canAcceptFormData() ) {
00061             // here the guest book entry is saved
00062             $oEntry = oxNew( 'oxgbentry' );
00063             $oEntry->oxgbentries__oxshopid  = new oxField($sShopId);
00064             $oEntry->oxgbentries__oxuserid  = new oxField($sUserId);
00065             $oEntry->oxgbentries__oxcontent = new oxField($sReviewText);
00066             $oEntry->save();
00067         }
00068 
00069         return 'guestbook';
00070     }
00071 }