src/ShopBundle/objects/WebModules/MTShopArticleCatalogCore/MTShopArticleCatalogCoreEndPoint.class.php
public function WriteReview()
    {
        // validate user input...
        $bDataValide = false;
        $oMsgManager = TCMSMessageManager::GetInstance();
        $oGlobal = TGlobal::instance();
        $aUserData = $oGlobal->GetUserData(TdbShopArticleReview::INPUT_BASE_NAME);
        if (is_array($aUserData)) {
            $bDataValide = true;

            $sCaptcha = '';
            if (array_key_exists('captcha', $aUserData)) {
                $sCaptcha = trim($aUserData['captcha']);
            }
            if (empty($sCaptcha) || $sCaptcha != $this->GetCaptchaValue()) {
                $bDataValide = false;
                $oMsgManager->AddMessage(
                    TdbShopArticleReview::MSG_CONSUMER_BASE_NAME.'-captcha',
                    'INPUT-ERROR-INVALID-CAPTCHA'
                );
            }

            $aRequiredFields = array('rating', 'author_name', 'author_email');
            foreach ($aRequiredFields as $sFieldName) {
                $sVal = '';
                if (array_key_exists($sFieldName, $aUserData)) {
                    $sVal = trim($aUserData[$sFieldName]);
                }
                if (empty($sVal)) {
                    $bDataValide = false;
                    $oMsgManager->AddMessage(
                        TdbShopArticleReview::MSG_CONSUMER_BASE_NAME.'-'.$sFieldName,
                        'ERROR-USER-REQUIRED-FIELD-MISSING'
                    );
                }
            }
        }
        if ($bDataValide) {
            if (!preg_match('#^[0-5]$#', $aUserData['rating'])) {
                $oMsgManager->AddMessage(
                    TdbShopArticleReview::MSG_CONSUMER_BASE_NAME.'-rating',
                    'ERROR-INVALID-FIELD-VALUE-RATING'
                );
                $bDataValide = false;
            }
        }

        if ($bDataValide) {
            // save item
            $oReviewItem = TdbShopArticleReview::GetNewInstance();
            /** @var $oReviewItem TdbShopArticleReview */
            $aUserData['shop_article_id'] = $this->iItemId;
            $oReviewItem->LoadFromRowProtected($aUserData);
            $oReviewItem->AllowEditByAll(true);
            $oReviewItem->Save();

            // notify the shop owner
            $oReviewItem->SendNewReviewNotification();

            $oMsgManager->AddMessage(self::MSG_CONSUMER_NAME, 'ARTICLE-REVIEW-SUBMITTED', $aUserData);
            $oActiveItm = static::GetActiveItem();
            $oActiveCategory = static::GetActiveCategory();
            $iActiveCategoryId = null;
            if (is_object($oActiveCategory)) {
                $iActiveCategoryId = $oActiveCategory->id;
            }
            $sURL = $oActiveItm->GetDetailLink(true, $iActiveCategoryId);
            $this->controller->HeaderURLRedirect($sURL);
        }
    }
public function WriteReview()
    {
        // validate user input...
        $bDataValide = false;
        $oMsgManager = TCMSMessageManager::GetInstance();
        $oGlobal = TGlobal::instance();
        $aUserData = $oGlobal->GetUserData(TdbShopArticleReview::INPUT_BASE_NAME);
        if (is_array($aUserData)) {
            $bDataValide = true;

            $sCaptcha = '';
            if (array_key_exists('captcha', $aUserData)) {
                $sCaptcha = trim($aUserData['captcha']);
            }
            if (empty($sCaptcha) || $sCaptcha != $this->GetCaptchaValue()) {
                $bDataValide = false;
                $oMsgManager->AddMessage(
                    TdbShopArticleReview::MSG_CONSUMER_BASE_NAME.'-captcha',
                    'INPUT-ERROR-INVALID-CAPTCHA'
                );
            }

            $aRequiredFields = array('rating', 'author_name', 'author_email');
            foreach ($aRequiredFields as $sFieldName) {
                $sVal = '';
                if (array_key_exists($sFieldName, $aUserData)) {
                    $sVal = trim($aUserData[$sFieldName]);
                }
                if (empty($sVal)) {
                    $bDataValide = false;
                    $oMsgManager->AddMessage(
                        TdbShopArticleReview::MSG_CONSUMER_BASE_NAME.'-'.$sFieldName,
                        'ERROR-USER-REQUIRED-FIELD-MISSING'
                    );
                }
            }
        }
        if ($bDataValide) {
            if (!preg_match('#^[0-5]$#', $aUserData['rating'])) {
                $oMsgManager->AddMessage(
                    TdbShopArticleReview::MSG_CONSUMER_BASE_NAME.'-rating',
                    'ERROR-INVALID-FIELD-VALUE-RATING'
                );
                $bDataValide = false;
            }
        }

        if ($bDataValide) {
            // save item
            $oReviewItem = TdbShopArticleReview::GetNewInstance();
            /** @var $oReviewItem TdbShopArticleReview */
            $aUserData['shop_article_id'] = $this->iItemId;
            $oReviewItem->LoadFromRowProtected($aUserData);
            $oReviewItem->AllowEditByAll(true);
            $oReviewItem->Save();

            // notify the shop owner
            $oReviewItem->SendNewReviewNotification();

            $oMsgManager->AddMessage(self::MSG_CONSUMER_NAME, 'ARTICLE-REVIEW-SUBMITTED', $aUserData);
            $oActiveItm = static::GetActiveItem();
            $oActiveCategory = static::GetActiveCategory();
            $iActiveCategoryId = null;
            if (is_object($oActiveCategory)) {
                $iActiveCategoryId = $oActiveCategory->id;
            }
            $sURL = $oActiveItm->GetDetailLink(true, $iActiveCategoryId);
            $this->controller->HeaderURLRedirect($sURL);
        }
    }
public function WriteReview ( ) { // validate user input... $ bDataValide = false ; $ oMsgManager = TCMSMessageManager :: GetInstance ( ) ; $ oGlobal = TGlobal :: instance ( ) ; $ aUserData = $ oGlobal -> GetUserData ( TdbShopArticleReview :: INPUT_BASE_NAME ) ; if ( is_array ( $ aUserData ) ) { $ bDataValide = true ; $ sCaptcha = '' ; if ( array_key_exists ( 'captcha' , $ aUserData ) ) { $ sCaptcha = trim ( $ aUserData [ 'captcha' ] ) ; } if ( empty ( $ sCaptcha ) || $ sCaptcha != $ this -> GetCaptchaValue ( ) ) { $ bDataValide = false ; $ oMsgManager -> AddMessage ( TdbShopArticleReview :: MSG_CONSUMER_BASE_NAME . '-captcha' , 'INPUT-ERROR-INVALID-CAPTCHA' ) ; } $ aRequiredFields = array ( 'rating' , 'author_name' , 'author_email' ) ; foreach ( $ aRequiredFields as $ sFieldName ) { $ sVal = '' ; if ( array_key_exists ( $ sFieldName , $ aUserData ) ) { $ sVal = trim ( $ aUserData [ $ sFieldName ] ) ; } if ( empty ( $ sVal ) ) { $ bDataValide = false ; $ oMsgManager -> AddMessage ( TdbShopArticleReview :: MSG_CONSUMER_BASE_NAME . '-' . $ sFieldName , 'ERROR-USER-REQUIRED-FIELD-MISSING' ) ; } } } if ( $ bDataValide ) { if ( ! preg_match ( '#^[0-5]$#' , $ aUserData [ 'rating' ] ) ) { $ oMsgManager -> AddMessage ( TdbShopArticleReview :: MSG_CONSUMER_BASE_NAME . '-rating' , 'ERROR-INVALID-FIELD-VALUE-RATING' ) ; $ bDataValide = false ; } } if ( $ bDataValide ) { // save item $ oReviewItem = TdbShopArticleReview :: GetNewInstance ( ) ; /** @var $oReviewItem TdbShopArticleReview */ $ aUserData [ 'shop_article_id' ] = $ this -> iItemId ; $ oReviewItem -> LoadFromRowProtected ( $ aUserData ) ; $ oReviewItem -> AllowEditByAll ( true ) ; $ oReviewItem -> Save ( ) ; // notify the shop owner $ oReviewItem -> SendNewReviewNotification ( ) ; $ oMsgManager -> AddMessage ( self :: MSG_CONSUMER_NAME , 'ARTICLE-REVIEW-SUBMITTED' , $ aUserData ) ; $ oActiveItm = static :: GetActiveItem ( ) ; $ oActiveCategory = static :: GetActiveCategory ( ) ; $ iActiveCategoryId = null ; if ( is_object ( $ oActiveCategory ) ) { $ iActiveCategoryId = $ oActiveCategory -> id ; } $ sURL = $ oActiveItm -> GetDetailLink ( true , $ iActiveCategoryId ) ; $ this -> controller -> HeaderURLRedirect ( $ sURL ) ; } }
write a review.
write a review .