Esempio n. 1
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getBattleDeathReasons()
 {
     return $this->hasMany(BattleDeathReason::className(), ['reason_id' => 'id']);
 }
Esempio n. 2
0
 public function beforeDelete()
 {
     if (!parent::beforeDelete()) {
         return false;
     }
     foreach ($this->battleImages as $img) {
         if (!$img->delete()) {
             return false;
         }
     }
     BattleDeathReason::deleteAll(['battle_id' => $this->id]);
     BattlePlayer::deleteAll(['battle_id' => $this->id]);
     if ($this->weapon_id) {
         $userWeapon = UserWeapon::findOne(['user_id' => $this->user_id, 'weapon_id' => $this->weapon_id]);
         if ($userWeapon) {
             if ($userWeapon->count <= 1) {
                 if (!$userWeapon->delete()) {
                     return false;
                 }
             } else {
                 $userWeapon->count--;
                 if (!$userWeapon->save()) {
                     return false;
                 }
             }
         }
     }
     return true;
 }