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 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 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; }