示例#1
0
    public function getOutput($options = array())
    {
        if (!$this->isPublished()) {
            return "";
        }
        $options = new JRegistry($options);
        $this->initMultipleRatingField();
        $this->loadDefaultAssets();
        if ($this->listing->cat_id) {
            $this->criteriaGroupId = JUDirectoryFrontHelperCriteria::getCriteriaGroupIdByCategoryId($this->listing->cat_id);
        }
        if (JUDirectoryHelper::hasMultiRating()) {
            if ($this->criteriaGroupId) {
                $this->criteriaObjectList = JUDirectoryFrontHelperCriteria::getCriteriasByCatId($this->listing->cat_id);
            }
        }
        $this->selectedStar = round($this->listing->rating * $this->totalStars / 10, 2);
        if ($this->isDetailsView($options)) {
            $this->canRateListing = JUDirectoryFrontHelperPermission::canRateListing($this->listing_id);
            $document = JFactory::getDocument();
            $document->addStyleSheet(JUri::root(true) . "/components/com_judirectory/assets/css/jquery.rating.css");
            $document->addScript(JUri::root(true) . "/components/com_judirectory/assets/js/jquery.MetaData.js");
            $document->addScript(JUri::root(true) . "/components/com_judirectory/assets/js/jquery.rating.js");
            $singleRatingScript = '
				jQuery(document).ready(function ($) {
					$(".judir-single-rating").rating({
						callback: function (value) {
									var str = $(this).attr("name");
									var patt = /^judir-listing-rating-result-(.*)$/i;
							var result = str.match(patt);
							var listingId = result[1];
							var ratingValue = $(this).val();
							var objectListing = {};
							var token = $("#judir-single-rating-token").attr("name");
							objectListing.listing_id = listingId;
							objectListing.ratingValue = ratingValue;
							if ($.isNumeric(listingId) && (ratingValue > 0 && ratingValue <= 10)) {
								$.ajax({
									type: "POST",
									url : "index.php?option=com_judirectory&task=listing.singleRating&" + token + "=1",
									data: objectListing
								}).done(function (msg) {
									alert(msg);
									
								});
							}
						}
					});
				});';
            if ($this->canRateListing) {
                $document->addScriptDeclaration($singleRatingScript);
            }
        }
        if (is_object($this->multiRating)) {
            return $this->multiRating->getOutput($options);
        } else {
            $this->setVariable('options', $options);
            $this->setVariable('className', __CLASS__);
            return $this->fetch('output.php', __CLASS__);
        }
    }
示例#2
0
 public function validateCriteria($data)
 {
     $listingId = $data['listing_id'];
     $params = JUDirectoryHelper::getParams(null, $listingId);
     $dataValid = array();
     $canRateListing = JUDirectoryFrontHelperPermission::canRateListing($listingId);
     if ($canRateListing && $params->get('enable_listing_rate_in_comment_form', 1)) {
         $mainCatId = JUDirectoryFrontHelperCategory::getMainCategoryId($listingId);
         $criteriaArray = JUDirectoryFrontHelperCriteria::getCriteriasByCatId($mainCatId);
         $postCriteria = $data['criteria'];
         if (count($criteriaArray) > 0) {
             foreach ($criteriaArray as $key => $criteria) {
                 if ($criteria->required) {
                     if (isset($postCriteria[$criteria->id]) && $postCriteria[$criteria->id] > 0 && $postCriteria[$criteria->id] <= 10) {
                         $criteria->value = $postCriteria[$criteria->id];
                     } else {
                         echo JText::_('Invalid Field ' . $criteria->title);
                         exit;
                     }
                 } else {
                     if (isset($postCriteria[$criteria->id]) && $postCriteria[$criteria->id] > 0 && $postCriteria[$criteria->id] <= 10) {
                         $criteria->value = $postCriteria[$criteria->id];
                     } else {
                         unset($criteriaArray[$key]);
                     }
                 }
             }
             $dataValid['criteria_array'] = $criteriaArray;
         } else {
             if ($params->get('require_listing_rate_in_comment_form', 1)) {
                 if ($data['judir_comment_rating_single'] <= 0 && $data['judir_comment_rating_single'] > 10) {
                     return false;
                 }
                 $dataValid['ratingValue'] = $data['judir_comment_rating_single'];
             }
         }
     }
     return $dataValid;
 }
示例#3
0
 public function saveComment($postData = array())
 {
     $user = JFactory::getUser();
     $nowDate = JFactory::getDate()->toSql();
     $title = htmlspecialchars($postData['title']);
     $comment = htmlspecialchars($postData['comment'], ENT_NOQUOTES);
     if ($user->get('guest')) {
         $guestName = strip_tags($postData['guest_name']);
         $guestEmail = strip_tags($postData['guest_email']);
     } else {
         $guestName = '';
         $guestEmail = '';
     }
     $website = isset($postData['website']) ? strip_tags($postData['website']) : '';
     $listingId = (int) $postData['listing_id'];
     $params = JUDirectoryHelper::getParams(null, $listingId);
     $totalVotes = 0;
     $helpfulVotes = 0;
     $ipAddress = JUDirectoryFrontHelper::getIpAddress();
     $parentId = (int) $postData['parent_id'];
     $rootComment = JUDirectoryFrontHelperComment::getRootComment();
     if ($parentId == $rootComment->id) {
         $approved = JUDirectoryFrontHelperPermission::canAutoApprovalComment($listingId);
         $level = 1;
         if ($params->get('filter_comment_language', 0)) {
             $language = $postData['comment_language'];
         } else {
             $language = '*';
         }
     } else {
         $approved = JUDirectoryFrontHelperPermission::canAutoApprovalReplyComment($listingId);
         $parentComment = $this->getCommentObject($parentId);
         $level = $parentComment->level + 1;
         $language = '*';
     }
     if ($approved) {
         $approved = 1;
         $published = 1;
     } else {
         $approved = 0;
         $published = 0;
     }
     $dataComment = array('title' => $title, 'comment' => $comment, 'user_id' => $user->id, 'guest_name' => $guestName, 'guest_email' => $guestEmail, 'website' => $website, 'listing_id' => $listingId, 'created' => $nowDate, 'total_votes' => $totalVotes, 'helpful_votes' => $helpfulVotes, 'ip_address' => $ipAddress, 'approved' => $approved, 'published' => $published, 'parent_id' => $parentId, 'level' => $level, 'language' => $language);
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_judirectory/tables');
     $commentTable = JTable::getInstance('Comment', 'JUDirectoryTable');
     $commentTable->setLocation($postData['parent_id'], 'last-child');
     $commentTable->bind($dataComment);
     if (!$commentTable->check() || !$commentTable->store()) {
         $this->setError($commentTable->getError());
         return false;
     }
     $canRateListing = JUDirectoryFrontHelperPermission::canRateListing($listingId);
     if ($canRateListing && $params->get('enable_listing_rate_in_comment_form', 1) && $commentTable->parent_id == $rootComment->id) {
         $postData['approved'] = $approved;
         $criteriaArray = array();
         if (isset($postData['criteria_array'])) {
             if (JUDirectoryHelper::hasMultiRating()) {
                 $criteriaArray = $postData['criteria_array'];
                 $saveRating = $this->saveRating($postData, $listingId, $criteriaArray, $commentTable->id);
             }
         } else {
             if (isset($postData['ratingValue'])) {
                 $saveRating = $this->saveRating($postData, $listingId, $criteriaArray, $commentTable->id);
             }
         }
         if (!$saveRating) {
             $this->setError(JText::_('COM_JUDIRECTORY_SAVE_RATING_FAILED'));
             return false;
         }
     }
     if (JUDIRPROVERSION && isset($postData['subscribe']) && $postData['subscribe']) {
         $subscriptionData = array();
         $subscriptionData['user_id'] = $user->id;
         $subscriptionData['type'] = 'comment';
         $subscriptionData['comment_id'] = $commentTable->id;
         $subscriptionData['name'] = $user->id == 0 ? $guestName : $user->username;
         $subscriptionData['email'] = $user->id == 0 ? $guestEmail : $user->email;
         $subscriptionData['item_id'] = $commentTable->id;
         $subscriptionData['ip_address'] = $ipAddress;
         $subscriptionData['created'] = $nowDate;
         $subscriptionData['published'] = $user->id == 0 && $params->get('activate_subscription_by_email', 1) ? 0 : 1;
         require_once JPATH_SITE . '/components/com_judirectory/models/subscribe.php';
         JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_judirectory/models');
         $subscribeModel = JModelLegacy::getInstance('Subscribe', 'JUDirectoryModel');
         if (!$subscribeModel->add($subscriptionData)) {
             $this->setError(JText::_('COM_JUDIRECTORY_SUBSCRIBE_FAILED'));
             return false;
         }
     }
     if ($commentTable->parent_id == $rootComment->id) {
         JUDirectoryFrontHelperMail::sendEmailByEvent('comment.create', $commentTable->id);
         $logData = array('item_id' => $commentTable->id, 'listing_id' => $listingId, 'user_id' => $user->id, 'event' => 'comment.create');
         $commentSubmitType = 'create';
     } else {
         JUDirectoryFrontHelperMail::sendEmailByEvent('comment.reply', $commentTable->id);
         $logData = array('user_id' => $user->id, 'event' => 'comment.reply', 'item_id' => $commentTable->id, 'listing_id' => $listingId, 'value' => 0, 'reference' => $commentTable->parent_id);
         $commentSubmitType = 'reply';
     }
     JUDirectoryFrontHelperLog::addLog($logData);
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin('judirectory');
     $dispatcher->trigger('onCommentSubmit', array($commentTable, $commentSubmitType));
     return $commentTable->id;
 }