Exemple #1
0
 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;
     }
 }