public function getRatingAction() { $id = $this->_getParam("id"); $type = $this->_getParam("type"); if ($type == "object") { $target = Object_Abstract::getById($id); } else { if ($type == "page" || $type == "snippet") { $target = Document::getById($id); } else { //try asset $target = Asset::getById($id); } } $result = null; if ($target != null) { $ratingAmount = RatingsComments_Plugin::getRatingAmountForTarget($target); $ratingValue = RatingsComments_Plugin::getRatingValueForTarget($target); if ($ratingAmount > 0) { $result['success'] = true; $average = number_format($ratingValue / $ratingAmount, 2); $result['total'] = $ratingAmount; $result['average'] = $average; } } echo Zend_Json::encode($result); $this->removeViewRenderer(); }
public function getRating($withAmount = false, $withComments = false) { if (class_exists('RatingsComments_Plugin') and RatingsComments_Plugin::isInstalled()) { if ($withAmount == true) { if ($this->ratingAvgAmount !== null) { return $this->ratingAvgAmount; } } else { if ($this->ratingAvg !== null) { return $this->ratingAvg; } } if (!$this->isVariant()) { $object = $this; } elseif ($this->getType() == Object_Abstract::OBJECT_TYPE_OBJECT) { $object = $this->getParent(); } elseif ($this->getType() == Object_Abstract::OBJECT_TYPE_VARIANT && $this->getParent()->getType() == Object_Abstract::OBJECT_TYPE_OBJECT) { $object = $this->getParent()->getParent(); } if ($withAmount == true) { $rating = RatingsComments_Plugin::getRatingValueForTarget($object); $amount = RatingsComments_Plugin::getRatingAmountForTarget($object); $ratingAverage = $amount['total'] ? $rating / $amount['total'] : null; $this->ratingAvgAmount = array('rating' => $ratingAverage, 'amount' => $amount); return $this->ratingAvgAmount; } else { $this->ratingAvg = RatingsComments_Plugin::getRatingAverageForTarget($object); return $this->ratingAvg; // return number_format(RatingsComments_Plugin::getRatingAverageForTarget($object), 2, '.', ''); } } else { return null; } }