public function getWeapons(array $weaponIdList) { $list = Weapon::find()->andWhere(['in', '{{weapon}}.[[id]]', $weaponIdList])->all(); $ret = []; foreach ($list as $weapon) { $ret[$weapon->id] = $weapon; } return $ret; }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { // return Input::all(); $datacase = new DataCase(); $datacase->fill(Input::except(["weapon", "vehicle"])); $datacase->save(); $data_vehicle = Input::get('vehicle'); $data_weapon = Input::get('weapon'); foreach ($data_vehicle as $datavehicle) { $vechicle = new Vehicle(); $vechicle->fill($datavehicle); $vechicle->datacase()->associate($datacase); $vechicle->save(); } foreach ($data_weapon as $dataweapon) { $weapom = new Weapon(); $weapom->fill($dataweapon); $weapom->datacase()->associate($datacase); $weapom->save(); } return $datacase; }
public function rules() { return [[['screen_name'], 'exist', 'targetClass' => User::className(), 'targetAttribute' => 'screen_name'], [['lobby'], 'exist', 'targetClass' => Lobby::className(), 'targetAttribute' => 'key'], [['rule'], 'exist', 'targetClass' => Rule::className(), 'targetAttribute' => 'key', 'when' => function () { return substr($this->rule, 0, 1) !== '@'; }], [['rule'], 'validateGameMode', 'when' => function () { return substr($this->rule, 0, 1) === '@'; }], [['map'], 'exist', 'targetClass' => Map::className(), 'targetAttribute' => 'key'], [['weapon'], 'exist', 'targetClass' => Weapon::className(), 'targetAttribute' => 'key', 'when' => function () { return !in_array(substr($this->weapon, 0, 1), ['@', '+', '*'], true); }], [['weapon'], 'validateWeapon', 'params' => ['modelClass' => WeaponType::className()], 'when' => function () { return substr($this->weapon, 0, 1) === '@'; }], [['weapon'], 'validateWeapon', 'params' => ['modelClass' => Subweapon::className()], 'when' => function () { return substr($this->weapon, 0, 1) === '+'; }], [['weapon'], 'validateWeapon', 'params' => ['modelClass' => Special::className()], 'when' => function () { return substr($this->weapon, 0, 1) === '*'; }], [['result'], 'boolean', 'trueValue' => 'win', 'falseValue' => 'lose'], [['term'], 'in', 'range' => ['this-period', 'last-period', '24h', 'today', 'yesterday', 'term']], [['term_from', 'term_to'], 'date', 'format' => 'yyyy-M-d H:m:s']]; }
public function run() { $response = Yii::$app->getResponse(); $response->format = 'json'; $form = new WeaponGetForm(); $form->attributes = Yii::$app->getRequest()->get(); if (!$form->validate()) { $response->statusCode = 400; return ['error' => $form->getErrors()]; } $query = Weapon::find()->with(['type', 'subweapon', 'special'])->orderBy('[[id]]'); $form->filterQuery($query); return array_map(function ($weapon) { return $weapon->toJsonArray(); }, $query->all()); }
public function rules() { return [[['screen_name'], 'exist', 'targetClass' => User::className(), 'targetAttribute' => 'screen_name'], [['rule'], 'exist', 'targetClass' => Rule::className(), 'targetAttribute' => 'key', 'when' => function () { return substr($this->rule, 0, 1) !== '@'; }], [['rule'], 'validateGameMode', 'when' => function () { return substr($this->rule, 0, 1) === '@'; }], [['map'], 'exist', 'targetClass' => Map::className(), 'targetAttribute' => 'key'], [['weapon'], 'exist', 'targetClass' => Weapon::className(), 'targetAttribute' => 'key', 'when' => function () { return !in_array(substr($this->weapon, 0, 1), ['@', '+', '*'], true); }], [['weapon'], 'validateWeapon', 'params' => ['modelClass' => WeaponType::className()], 'when' => function () { return substr($this->weapon, 0, 1) === '@'; }], [['weapon'], 'validateWeapon', 'params' => ['modelClass' => Subweapon::className()], 'when' => function () { return substr($this->weapon, 0, 1) === '+'; }], [['weapon'], 'validateWeapon', 'params' => ['modelClass' => Special::className()], 'when' => function () { return substr($this->weapon, 0, 1) === '*'; }], [['result'], 'boolean', 'trueValue' => 'win', 'falseValue' => 'lose']]; }
public function makeUpdate() { $currentSpecialId = null; $fh = fopen(__FILE__, 'rt'); fseek($fh, __COMPILER_HALT_OFFSET__, SEEK_SET); while (!feof($fh)) { $line = rtrim(fgets($fh)); if ($line != '') { if (substr($line, 0, 1) !== ' ') { $currentSpecialId = Special::findOne(['key' => $line])->id; } else { $line = trim($line); $weaponId = Weapon::findOne(['key' => $line])->id; (yield [$weaponId, $currentSpecialId]); } } } fclose($fh); }
private function makeWeaponsListWeaponsAndTypes() { $ret = []; $types = WeaponType::find()->orderBy('[[id]] ASC')->all(); foreach ($types as $type) { $typeName = Yii::t('app-weapon', $type->name); $tmp = []; $weapons = Weapon::find()->andWhere(['type_id' => $type->id])->all(); foreach ($weapons as $weapon) { $tmp[$weapon->key] = Yii::t('app-weapon', $weapon->name); } asort($tmp); if (count($tmp) > 1) { $ret[$typeName] = array_merge(['@' . $type->key => Yii::t('app-weapon', 'All of {0}', $typeName)], $tmp); } else { $ret[$typeName] = $tmp; } } return array_merge(['' => Yii::t('app-weapon', 'Any Weapon')], $ret); }
/** * @return \yii\db\ActiveQuery */ public function getWeapon() { return $this->hasOne(Weapon::className(), ['id' => 'weapon_id']); }
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); } } }
public function rules() { return [[['weapon'], 'exist', 'targetClass' => Weapon::className(), 'targetAttribute' => 'key'], [['type'], 'exist', 'targetClass' => WeaponType::className(), 'targetAttribute' => 'key'], [['sub'], 'exist', 'targetClass' => Subweapon::className(), 'targetAttribute' => 'key'], [['special'], 'exist', 'targetClass' => Special::className(), 'targetAttribute' => 'key']]; }
private function makeWeapons() { $ret = []; $types = WeaponType::find()->orderBy('[[id]] ASC')->all(); foreach ($types as $type) { $typeName = Yii::t('app-weapon', $type->name); $tmp = []; $weapons = Weapon::find()->andWhere(['type_id' => $type->id])->all(); foreach ($weapons as $weapon) { $tmp[$weapon->id] = Yii::t('app-weapon', $weapon->name); } asort($tmp); $ret[$typeName] = $tmp; } return static::arrayMerge(['' => Yii::t('app', 'Unknown')], $ret); }
public function rules() { return [[['team', 'is_me'], 'required'], [['team'], 'in', 'range' => ['my', 'his']], [['is_me'], 'boolean', 'trueValue' => 'yes', 'falseValue' => 'no'], [['weapon'], 'exist', 'targetClass' => Weapon::className(), 'targetAttribute' => 'key'], [['rank'], 'exist', 'targetClass' => Rank::className(), 'targetAttribute' => 'key'], [['level'], 'integer', 'min' => 1, 'max' => 50], [['rank_in_team'], 'integer', 'min' => 1, 'max' => 4], [['kill', 'death'], 'integer', 'min' => 0], [['point'], 'integer', 'min' => 0]]; }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { // return Input::all(); $caseFile = Input::get('caseFile'); $person = Input::get('person'); $name_father = Input::get('person.datafather.father_name'); $surname_father = Input::get('person.datafather.father_surname'); $name_mother = Input::get('person.datamother.mother_name'); $surname_mother = Input::get('person.datamother.mother_surname'); $name_spouse = Input::get('person.dataspouse.spouse_name'); $surname_spouse = Input::get('person.dataspouse.spouse_surname'); $present_address = Input::get('person.addresspresent.present_address'); $original_address = Input::get('person.addressoriginal.original_address'); if ($present_address != null) { $addresspresent = new AddressPresent(); $addresspresent->fill(Input::get('person.addresspresent')); $addresspresent->save(); } if ($original_address != null) { $addressoriginal = new AddressOriginal(); $addressoriginal->fill(Input::get('person.addressoriginal')); $addressoriginal->save(); } if ($name_mother != null || $surname_mother != null) { $datamother = new DataMother(); $datamother->fill(Input::get('person.datamother')); $datamother->save(); } if ($name_father != null || $surname_father != null) { $datafather = new DataFather(); $datafather->fill(Input::get('person.datafather')); $datafather->save(); } if ($name_spouse != null || $surname_spouse != null) { $dataspouse = new DataSpouse(); $dataspouse->fill(Input::get('person.dataspouse')); if (Input::has('person.dataspouse.nametitle.id')) { $nametitle = NameTitle::find(Input::get('person.dataspouse.nametitle.id')); $dataspouse->nametitle()->associate($nametitle); } $dataspouse->save(); } $criminalhistory = new CriminalHistory(); //$criminalhistory->fill(Input::except(["person.data_casefile","person.addressoffice","person.datachild"])); $criminalhistory->fill($person); if ($datamother != null) { $criminalhistory->datamother()->associate($datamother); } if ($datafather != null) { $criminalhistory->datafather()->associate($datafather); } if ($dataspouse != null) { $criminalhistory->dataspouse()->associate($dataspouse); } if ($addressoriginal != null) { $criminalhistory->addressoriginal()->associate($addressoriginal); } if ($addresspresent != null) { $criminalhistory->addresspresent()->associate($addresspresent); } if (Input::has('person.nametitle.id')) { $nametitle = NameTitle::find(Input::get('person.nametitle.id')); $criminalhistory->nametitle()->associate($nametitle); } $criminalhistory->save(); $addressoffice = Input::get('person.addressoffice'); $datachild = Input::get('person.datachild'); foreach ($addressoffice as $data_office) { $office = new AddressOffice(); $office->fill($data_office); $office->criminalhistory()->associate($criminalhistory); $office->save(); } foreach ($datachild as $data_child) { $child = new DataChild(); $child->fill($data_child); $child->criminalhistory()->associate($criminalhistory); $child->save(); } $name_case = Input::get('caseFile.name_case'); $circumstances_case = Input::get('caseFile.circumstances_case'); if ($name_case != null || $circumstances_case != null) { $datacase = new DataCase(); $datacase->fill($caseFile); $datacase->save(); $datacase->criminalhistory()->attach($criminalhistory); $data_vehicle = Input::get('caseFile.vehicle'); $data_weapon = Input::get('caseFile.weapon'); foreach ($data_vehicle as $datavehicle) { $vechicle = new Vehicle(); $vechicle->fill($datavehicle); $vechicle->datacase()->associate($datacase); $vechicle->save(); } foreach ($data_weapon as $dataweapon) { $weapom = new Weapon(); $weapom->fill($dataweapon); $weapom->datacase()->associate($datacase); $weapom->save(); } } Event::fire(new AddDataPersonCrimeEvent($criminalhistory)); return $criminalhistory; }
/** * @return \yii\db\ActiveQuery */ public function getWeapons() { return $this->hasMany(Weapon::className(), ['id' => 'weapon_id'])->viaTable('stat_weapon', ['rule_id' => 'id']); }
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; }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($caseId, $weaponId) { $datacase = DataCase::find($caseId); if ($weaponId) { $weapon = Weapon::find($weaponId)->delete(); return $datacase; } else { return null; } }
/** * @return \yii\db\ActiveQuery */ public function getWeapons() { return $this->hasMany(Weapon::className(), ['subweapon_id' => 'id']); }
public function getMainWeapon() { return $this->hasOne(Weapon::className(), ['id' => 'weapon_id'])->viaTable('user_weapon', ['user_id' => 'id'], function ($query) { $query->orderBy('{{user_weapon}}.[[count]] DESC')->limit(1); }); }
private function makeWeaponsListSpecials(User $user) { $query = Special::find()->andWhere(['in', 'id', array_map(function ($model) { return $model->special_id; }, Weapon::findAll($this->getUsedWeaponIdList($user)))]); $ret = []; foreach ($query->all() as $item) { $ret['*' . $item->key] = Yii::t('app-special', $item->name); } if (count($ret) < 2) { return []; } asort($ret); return [Yii::t('app', 'Special') => $ret]; }
public function rules() { return [[['lobby_id'], 'exist', 'targetClass' => Lobby::className(), 'targetAttribute' => 'id'], [['rule_id'], 'exist', 'targetClass' => Rule::className(), 'targetAttribute' => 'id'], [['map_id'], 'exist', 'targetClass' => Map::className(), 'targetAttribute' => 'id'], [['weapon_id'], 'exist', 'targetClass' => Weapon::className(), 'targetAttribute' => 'id']]; }