Exemple #1
0
 function submit_review()
 {
     $nDealId = JRequest::getVar('nDealId');
     $nRating = JRequest::getVar('nRating');
     $sReviewBody = JRequest::getVar('sReviewBody');
     // Be sure this is a valid deal id
     if ($nDealId > 0) {
         // Check for a valid rating number and review content
         // User has to select his/her rating (the number is from 1 to 5)
         // and has enter his/her review
         if ($nRating <= 0 || $nRating > 5) {
             $sMessage = JText::_('PLEASE_RATE');
             $sRedirectUrl = JRoute::_('index.php?option=com_enmasse&controller=deal&task=comment&id=' . $nDealId, false);
         } elseif ($sReviewBody == '') {
             $sMessage = JText::_('PLEASE_ENTER_REVIEW');
             $sRedirectUrl = JRoute::_('index.php?option=com_enmasse&controller=deal&task=comment&id=' . $nDealId, false);
         } else {
             if (EnmasseHelper::checkSpammer(JFactory::getUser()->get('id'))) {
                 // If this user is a spammer, lie to him/her that the review is submitted but actually we store nothing
                 $sMessage = JText::_('REVIEW_SUBMITTED_SUCCESSFULLY');
                 $sRedirectUrl = JRoute::_('index.php?option=com_enmasse&controller=deal&task=comment&id=' . $nDealId, false);
             } else {
                 $aComment = array();
                 $aComment['deal_id'] = $nDealId;
                 $aComment['user_id'] = JFactory::getUser()->get('id');
                 $aComment['comment'] = $sReviewBody;
                 $aComment['rating'] = $nRating;
                 $aComment['created_at'] = DatetimeWrapper::getDatetimeOfNow();
                 $aComment['status'] = 0;
                 $oRow = JModel::getInstance('comment', 'enmasseModel')->store($aComment);
                 if ($oRow->success) {
                     $sMessage = JText::_('REVIEW_SUBMITTED_SUCCESSFULLY');
                 } else {
                     $sMessage = JText::_('SAVE_REVIEW_FAILED');
                 }
                 $sRedirectUrl = JRoute::_('index.php?option=com_enmasse&controller=deal&task=comment&id=' . $nDealId, false);
             }
         }
     } else {
         $sMessage = JText::_('SAVE_REVIEW_FAILED');
         $sRedirectUrl = JRoute::_('index.php?option=com_enmasse&view=dealtoday', false);
     }
     $this->setRedirect($sRedirectUrl, $sMessage);
 }
 public static function markUserAsSpammer($nCommentId)
 {
     $comment = JModel::getInstance('Comment', 'EnmasseModel')->getCommentById($nCommentId);
     $user = JFactory::getUser($comment->user_id);
     if (EnmasseHelper::checkSpammer($comment->user_id)) {
         $sMessage = JText::sprintf('COMMENT_USER_ALREADY_SPAMMER', $user->name);
     } else {
         $db = JFactory::getDBO();
         $query = "SELECT id FROM #__enmasse_comment WHERE user_id = " . $comment->user_id;
         $db->setQuery($query);
         $aIDs = $db->loadResultArray();
         $sCommentIds = implode(',', $aIDs);
         $bResult = JModel::getInstance('Comment', 'EnmasseModel')->changeCommentStatus($sCommentIds, 3);
         if ($bResult) {
             $sMessage = JText::_('COMMENT_SPAMMED_SUCCESSFULLY');
         } else {
             $sMessage = JText::_('COMMENT_SPAMMED_FAILED');
         }
         $query = "INSERT INTO #__enmasse_comment_spammer VALUES ('', {$comment->user_id}) ";
         $db->setQuery($query);
         $db->query();
         if ($db->getErrorNum()) {
             $sMessage = JText::sprintf('COMMENT_USER_SPAMMED_FAILED', $user->name);
             JJFactory::getApplication()->redirect('index.php?option=com_enmasse&controller=comment', $sMessage, 'error');
         }
         $sMessage = JText::sprintf('COMMENT_MARK_SPAMMER_SUCCESSFULLY', $user->name);
     }
     JFactory::getApplication()->redirect('index.php?option=com_enmasse&controller=comment', $sMessage);
 }