Exemplo n.º 1
0
 public function toPlayers(Battle $battle)
 {
     if (is_array($this->players) && !empty($this->players)) {
         foreach ($this->players as $form) {
             if (!$form instanceof PostBattlePlayerForm) {
                 throw new \Exception('Logic error: assert: instanceof PostBattlePlayerForm');
             }
             $weapon = $form->weapon == '' ? null : Weapon::findOne(['key' => $form->weapon]);
             $rank = $form->rank == '' ? null : Rank::findOne(['key' => $form->rank]);
             $player = new BattlePlayer();
             $player->attributes = ['battle_id' => $battle->id, 'is_my_team' => $form->team === 'my', 'is_me' => $form->is_me === 'yes', 'weapon_id' => $weapon ? $weapon->id : null, 'rank_id' => $rank ? $rank->id : null, 'level' => (string) $form->level === '' ? null : (int) $form->level, 'rank_in_team' => (string) $form->rank_in_team === '' ? null : (int) $form->rank_in_team, 'kill' => (string) $form->kill === '' ? null : (int) $form->kill, 'death' => (string) $form->death === '' ? null : (int) $form->death, 'point' => (string) $form->point === '' ? null : (int) $form->point];
             (yield $player);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRank()
 {
     $lastPromotion = Promotion::find()->where(['student_id' => $this->id, 'active' => 1])->orderBy(['promotion.date' => SORT_DESC])->one();
     return Rank::findOne($lastPromotion->rank_id);
 }
Exemplo n.º 3
0
 /**
  * Finds the Rank model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Rank the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Rank::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 4
0
 public function toBattle()
 {
     $o = new Battle();
     $o->user_id = $this->getUser()->id;
     $o->lobby_id = $this->lobby ? Lobby::findOne(['key' => $this->lobby])->id : null;
     $o->rule_id = $this->rule ? Rule::findOne(['key' => $this->rule])->id : null;
     $o->map_id = $this->map ? Map::findOne(['key' => $this->map])->id : null;
     $o->weapon_id = $this->weapon ? Weapon::findOne(['key' => $this->weapon])->id : null;
     $o->level = $this->level ? (int) $this->level : null;
     $o->level_after = $this->level_after ? (int) $this->level_after : null;
     $o->rank_id = $this->rank ? Rank::findOne(['key' => $this->rank])->id : null;
     $o->rank_after_id = $this->rank_after ? Rank::findOne(['key' => $this->rank_after])->id : null;
     $o->rank_exp = (string) $this->rank_exp != '' ? (int) $this->rank_exp : null;
     $o->rank_exp_after = (string) $this->rank_exp_after != '' ? (int) $this->rank_exp_after : null;
     $o->cash = (string) $this->cash != '' ? (int) $this->cash : null;
     $o->cash_after = (string) $this->cash_after != '' ? (int) $this->cash_after : null;
     $o->is_win = $this->result === 'win' ? true : ($this->result === 'lose' ? false : null);
     $o->rank_in_team = $this->rank_in_team ? (int) $this->rank_in_team : null;
     $o->kill = (string) $this->kill != '' ? (int) $this->kill : null;
     $o->death = (string) $this->death != '' ? (int) $this->death : null;
     $o->gender_id = $this->fest_gender === 'boy' ? 1 : ($this->fest_gender === 'girl' ? 2 : null);
     $o->fest_title_id = $this->fest_rank ? FestTitle::findOne(['key' => $this->fest_rank])->id : null;
     $o->my_team_color_hue = $this->my_team_color ? $this->my_team_color['hue'] : null;
     $o->my_team_color_rgb = $this->my_team_color ? vsprintf('%02x%02x%02x', $this->my_team_color['rgb']) : null;
     $o->his_team_color_hue = $this->his_team_color ? $this->his_team_color['hue'] : null;
     $o->his_team_color_rgb = $this->his_team_color ? vsprintf('%02x%02x%02x', $this->his_team_color['rgb']) : null;
     $o->start_at = $this->start_at != '' ? gmdate('Y-m-d H:i:sP', (int) $this->start_at) : null;
     $o->end_at = $this->end_at != '' ? gmdate('Y-m-d H:i:sP', (int) $this->end_at) : new Now();
     $o->agent_id = null;
     $o->at = new Now();
     return $o;
 }