Ejemplo n.º 1
0
 private function runGet()
 {
     $request = Yii::$app->getRequest();
     $model = DynamicModel::validateData(['id' => $request->get('id'), 'screen_name' => $request->get('screen_name'), 'count' => $request->get('count'), 'newer_than' => $request->get('newer_than'), 'older_than' => $request->get('older_than')], [[['id'], 'exist', 'targetClass' => Battle::className(), 'targetAttribute' => 'id'], [['screen_name'], 'exist', 'targetClass' => User::className(), 'targetAttribute' => 'screen_name'], [['newer_than', 'older_than'], 'integer'], [['count'], 'default', 'value' => 10], [['count'], 'integer', 'min' => 1, 'max' => 100]]);
     if (!$model->validate()) {
         return $this->formatError($model->getErrors(), 400);
     }
     $query = Battle::find()->innerJoinWith('user')->with(['user', 'user.userStat', 'lobby', 'rule', 'map', 'weapon', 'weapon.subweapon', 'weapon.special', 'rank', 'battleImageResult', 'battleImageJudge'])->orderBy('{{battle}}.[[id]] DESC')->limit((int) $model->count);
     if ($model->id != '') {
         $query->andWhere(['{{battle}}.[[id]]' => $model->id]);
     }
     if ($model->screen_name != '') {
         $query->andWhere(['{{user}}.[[screen_name]]' => $model->screen_name]);
     }
     if ($model->newer_than > 0) {
         $query->andWhere(['>', '{{battle}}.[[id]]', $model->newer_than]);
     }
     if ($model->older_than > 0) {
         $query->andWhere(['<', '{{battle}}.[[id]]', $model->older_than]);
     }
     $list = $query->all();
     if ($model->id != '') {
         return empty($list) ? null : $this->runGetImpl(array_shift($list));
     }
     $resp = Yii::$app->getResponse();
     $resp->format = 'json';
     return array_map(function ($model) {
         return $model->toJsonArray();
     }, $list);
 }
Ejemplo n.º 2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getBattles()
 {
     return $this->hasMany(Battle::className(), ['fest_title_id' => 'id']);
 }
Ejemplo n.º 3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getBattles()
 {
     return $this->hasMany(Battle::className(), ['gender_id' => 'id']);
 }
Ejemplo n.º 4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getBattles()
 {
     return $this->hasMany(Battle::className(), ['id' => 'battle_id'])->viaTable('battle_death_reason', ['reason_id' => 'id']);
 }
Ejemplo n.º 5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getBattle()
 {
     return $this->hasOne(Battle::className(), ['id' => 'battle_id']);
 }
Ejemplo n.º 6
0
 public function getLatestBattle()
 {
     return $this->hasOne(Battle::className(), ['user_id' => 'id'])->orderBy('{{battle}}.[[id]] DESC')->limit(1);
 }