예제 #1
2
 public function run()
 {
     $modelName = $this->modelName;
     $ratingArray = AggregateRating::find()->select('target_id, rating')->where('model_id = :modelId', ['modelId' => Rating::getModelIdByName($modelName)])->orderBy('rating DESC')->limit($this->limit)->asArray()->all();
     $ids = ArrayHelper::getColumn($ratingArray, 'target_id');
     $models = $modelName::find()->joinWith('aggregate')->where(['in', $modelName::tableName() . '.' . $modelName::primaryKey()[0], $ids])->orderBy('rating DESC')->all();
     return $this->render('topRated', ['models' => $models, 'title' => $this->title, 'titleField' => $this->titleField, 'path' => $this->path]);
 }