Пример #1
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;
 }
Пример #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUserWeapons()
 {
     return $this->hasMany(UserWeapon::className(), ['user_id' => 'id'])->with(['weapon']);
 }