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 function setSessionCommentForm($documentId) { $session = JFactory::getSession(); $app = JFactory::getApplication(); $criteriaRatingValues = array('judl-comment-rating-single' => $app->input->getFloat('judl_comment_rating_single', 0)); $mainCatId = JUDownloadFrontHelperCategory::getMainCategoryId($documentId); $criteriaArray = JUDownloadFrontHelperCriteria::getCriteriasByCatId($mainCatId); if (count($criteriaArray)) { foreach ($criteriaArray AS $value) { $criteriaRatingValues[$value->id] = $app->input->getString('criteria-' . $value->id, ''); } } $commentForm = array(); $commentForm['rating'] = $criteriaRatingValues; $commentForm['title'] = $app->input->getString('title', ''); $commentForm['guest_name'] = $app->input->getString('guest_name', ''); $commentForm['guest_email'] = $app->input->getString('guest_email', ''); $commentForm['comment'] = $app->input->getString('comment', ''); $commentForm['parent_id'] = $app->input->getInt('parent_id', ''); $commentForm['comment_language'] = $app->input->getString('comment_language', '*'); if ($app->input->getString('website', '')) { $commentForm['website'] = $app->input->getString('website', ''); } $session->set('judownload_commentform_' . $documentId, $commentForm); }
public function saveCategoryPrepareCriteriaGroup($pk, $newParentObject, $table, &$data) { $app = JFactory::getApplication(); if ($pk > 0) { if ($data['selected_criteriagroup'] == -1) { if ($table->selected_criteriagroup == -1) { if ($table->parent_id == $data['parent_id']) { $data['criteriagroup_id'] = $table->criteriagroup_id; } else { $newCriteriaGroupId = $newParentObject->criteriagroup_id; if ($table->criteriagroup_id == $newCriteriaGroupId) { $data['criteriagroup_id'] = $table->criteriagroup_id; } else { if ($data['changeCriteriaGroupAction'] == 1) { $data['criteriagroup_id'] = $table->criteriagroup_id; $data['selected_criteriagroup'] = $table->criteriagroup_id; $criteriaGroupObject = JUDownloadFrontHelperCriteria::getCriteriaGroupById($table->criteriagroup_id); $app->enqueueMessage(JText::sprintf('COM_JUDOWNLOAD_INHERITED_CRITERIA_GROUP_HAS_BEEN_CHANGED_TO_X', $criteriaGroupObject->name ? $criteriaGroupObject->name : JText::_("COM_JUDOWNLOAD_NONE")), 'Notice'); } else { $data['criteriagroup_id'] = $newParentObject->criteriagroup_id; } } } } else { $data['criteriagroup_id'] = $newParentObject->criteriagroup_id; } } else { $data['criteriagroup_id'] = $data['selected_criteriagroup']; } } else { if ($data['selected_criteriagroup'] == -1) { $data['criteriagroup_id'] = $newParentObject->criteriagroup_id; } else { $data['criteriagroup_id'] = $data['selected_criteriagroup']; } } }
public function validateCriteria($data) { $documentId = $data['doc_id']; $params = JUDownloadHelper::getParams(null, $documentId); $dataValid = array(); $canRateDocument = JUDownloadFrontHelperPermission::canRateDocument($documentId); if ($canRateDocument && $params->get('enable_doc_rate_in_comment_form', 1)) { $mainCatId = JUDownloadFrontHelperCategory::getMainCategoryId($documentId); $criteriaArray = JUDownloadFrontHelperCriteria::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_doc_rate_in_comment_form', 1)) { if (($data['judl_comment_rating_single'] <= 0) && ($data['judl_comment_rating_single'] > 10)) { return false; } $dataValid['ratingValue'] = $data['judl_comment_rating_single']; } } } return $dataValid; }
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; }