Esempio n. 1
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     parent::run();
     if (!is_null($this->objectModel)) {
         $groupedRatingValues = RatingValues::getValuesByObjectModel($this->objectModel);
         if (!empty($groupedRatingValues)) {
             $groups = [];
             foreach ($groupedRatingValues as $groupId => $group) {
                 $ratingItem = RatingItem::findById($groupId);
                 $groups[] = ['name' => !is_null($ratingItem) ? $ratingItem->name : Yii::t('app', 'Unknown rating'), 'rating' => call_user_func($this->calcFunction, $group), 'votes' => count($group)];
             }
         } else {
             $groups = null;
         }
         return $this->render($this->viewFile, ['groups' => $groups]);
     } elseif (!is_null($this->reviewModel)) {
         $value = RatingValues::findOne(['rating_id' => $this->reviewModel->rating_id]);
         $groups = [];
         $ratingItem = RatingItem::findById(ArrayHelper::getValue($value, 'rating_item_id', 0));
         $group = [ArrayHelper::getValue($value, 'value')];
         $groups[] = ['name' => !is_null($ratingItem) ? $ratingItem->name : Yii::t('app', 'Unknown rating'), 'rating' => call_user_func($this->calcFunction, $group)];
         return $this->render($this->viewFile, ['groups' => $groups]);
     } else {
         return '';
     }
 }
Esempio n. 2
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     parent::run();
     if (null === $this->objectModel) {
         return '';
     }
     $groupedRatingValues = RatingValues::getValuesByObjectModel($this->objectModel);
     if (!empty($groupedRatingValues)) {
         $groups = [];
         foreach ($groupedRatingValues as $groupId => $group) {
             $ratingItem = RatingItem::findById($groupId);
             $groups[] = ['name' => !is_null($ratingItem) ? $ratingItem->name : Yii::t('app', 'Unknown rating'), 'rating' => call_user_func($this->calcFunction, $group), 'votes' => count($group)];
         }
     } else {
         $groups = null;
     }
     return $this->render($this->viewFile, ['groups' => $groups]);
 }