Esempio n. 1
0
 /**
  * Creating fight
  * @return bool
  */
 public function create()
 {
     if (!$this->validate()) {
         return false;
     }
     $transaction = Yii::$app->getDb()->beginTransaction();
     $saved = false;
     try {
         $fight = new Fight();
         if ($fight->save()) {
             $fightOwner = new FightUser(['user_id' => Yii::$app->getUser()->getIdentity()->cid, 'deck_id' => $this->deck_id, 'is_owner' => 1, 'fight_id' => $fight->id]);
             if ($fightOwner->save()) {
                 $saved = true;
                 $this->_fight = $fight;
             }
         }
     } catch (Exception $e) {
         $transaction->rollback();
     }
     if ($saved) {
         $transaction->commit();
     } else {
         $transaction->rollback();
     }
     return $saved;
 }
Esempio n. 2
0
 /**
  * Connect
  * @return bool
  */
 public function connect()
 {
     $this->updateAttributes(['status' => self::STATUS_CONNECTED]);
     $fightUser = new FightUser(['fight_id' => $this->id, 'deck_id' => $this->owner->deck_id, 'is_owner' => 0, 'user_id' => Yii::$app->user->getIdentity()->cid]);
     return $fightUser->save();
 }