public static function getElementsByScoreType(EScoreType $score_type, $sort = true) { $score_type->score_type = (int) $score_type->getValue(); if ($sort) { $sql = "SELECT COUNT(*) AS `count`, `element_id`, `element_type`, `user_id` FROM `scores` GROUP BY `element_id` ORDER BY 1 DESC;"; $ptr = Scores::findBySql($sql)->all(); } else { $ptr = Scores::find()->select(['element_id', 'element_type', 'user_id'])->where(['score_type' => (int) $score_type->getValue()])->distinct()->all(); } $ptr2 = []; foreach ($ptr as $row) { $elemType = $row->element_type; $elemt = EScoreElem::search($elemType); $score = new Score($score_type, $row->score_id, EScoreElem::$elemt(), $row->element_id, new UserId($row->user_id)); $ptr2[] = $score; } return $ptr2; }
/** * @return \yii\db\ActiveQuery */ public function getScores() { return $this->hasOne(Scores::className(), ['score_id' => 'score_id']); }
/** * @return \yii\db\ActiveQuery */ public function getScores() { return $this->hasMany(Scores::className(), ['element_type' => 'elem_id']); }