public function getOutput($options = array()) { if (!$this->isPublished()) { return ""; } $options = new JRegistry($options); $this->initMultipleRatingField(); $this->loadDefaultAssets(); if ($this->doc->cat_id) { $this->criteriaGroupId = JUDownloadFrontHelperCriteria::getCriteriaGroupIdByCategoryId($this->doc->cat_id); } if (JUDownloadHelper::hasMultiRating()) { if ($this->criteriaGroupId) { $this->criteriaObjectList = JUDownloadFrontHelperCriteria::getCriteriasByCatId($this->doc->cat_id); } } $this->selectedStar = round($this->doc->rating * $this->totalStars / 10, 2); if ($this->isDetailsView($options)) { $this->canRateDocument = JUDownloadFrontHelperPermission::canRateDocument($this->doc_id); $document = JFactory::getDocument(); $document->addStyleSheet(JUri::root(true) . "/components/com_judownload/assets/css/jquery.rating.css"); $document->addScript(JUri::root(true) . "/components/com_judownload/assets/js/jquery.MetaData.js"); $document->addScript(JUri::root(true) . "/components/com_judownload/assets/js/jquery.rating.js"); $singleRatingScript = ' jQuery(document).ready(function ($) { $(".judl-single-rating").rating({ callback: function (value) { var str = $(this).attr("name"); var patt = /^judl-document-rating-result-(.*)$/i; var result = str.match(patt); var documentId = result[1]; var ratingValue = $(this).val(); var objectDocument = {}; var token = $("#judl-single-rating-token").attr("name"); objectDocument.doc_id = documentId; objectDocument.ratingValue = ratingValue; if ($.isNumeric(documentId) && (ratingValue > 0 && ratingValue <= 10)) { $.ajax({ type: "POST", url : "index.php?option=com_judownload&task=document.singleRating&" + token + "=1", data: objectDocument }).done(function (msg) { alert(msg); }); } } }); });'; if ($this->canRateDocument) { $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__); } }
public static function canRateDocument($documentId) { $documentObject = JUDownloadHelper::getDocumentById($documentId); if (!is_object($documentObject)) { return false; } $params = JUDownloadHelper::getParams(null, $documentId); if (!$params->get('enable_document_rate', 1)) { return false; } $userCanViewDocument = JUDownloadFrontHelperPermission::userCanDoDocument($documentId, true); if (!$userCanViewDocument) { return false; } $ratingField = new JUDownloadFieldCore_rating(); if (!$ratingField->canView()) { return false; } $user = JFactory::getUser(); $criteriaGroupId = JUDownloadFrontHelperCriteria::getCriteriaGroupIdByCategoryId($documentObject->cat_id); if ($criteriaGroupId == 0 || !JUDownloadHelper::hasMultiRating()) { $assetName = 'com_judownload.category.' . $documentObject->cat_id; if ($user->authorise('judl.single.rate', $assetName) || (JUDownloadFrontHelperPermission::canDownloadDocument($documentId) && $params->get('can_download_can_rate', 0))) { if ($user->authorise('judl.single.rate.many_times', $assetName)) { return true; } else { if ($user->get('guest')) { $session = JFactory::getSession(); if (!$session->has('judl-document-rated-' . $documentId)) { return true; } } else { $totalVoteTimes = JUDownloadFrontHelperRating::getTotalDocumentVotesOfUser($user->id, $documentId); if ($totalVoteTimes == 0) { return true; } } } } } else { $assetName = 'com_judownload.criteriagroup.' . $criteriaGroupId; if ($user->authorise('judl.criteria.rate', $assetName) || (JUDownloadFrontHelperPermission::canDownloadDocument($documentId) && $params->get('can_download_can_rate', 0))) { if ($user->authorise('judl.criteria.rate.many_times', $assetName)) { return true; } else { if ($user->get('guest')) { $session = JFactory::getSession(); if (!$session->has('judl-document-rated-' . $documentId)) { return true; } } else { $totalVoteTimes = JUDownloadFrontHelperRating::getTotalDocumentVotesOfUser($user->id, $documentId); if ($totalVoteTimes == 0) { return true; } } } } } return false; }