public static function requireTurn($user, $fight) { self::requireFight($fight); $request = new \Fight\Data\Request(); $request->Sort[] = new \Fight\Data\Sort("action_id", "DESC"); $request->Filter[] = new \Fight\Data\Filter("fight_id", $fight->fight_id); $request->Filter[] = new \Fight\Data\Filter("created_at", date('Y-m-d H:i:s', strtotime('-5 minutes')), ">="); $lastAction = FightActionModel::findOne($request); if ($lastAction->actor_id === $user->user_id) { throw new Exception("It's not your turn! (if your opponent does not go for 5 minutes, it will become your turn)"); } }
public static function registerAction($user, $fight_id, $description) { $action = FightActionModel::build(["fight_id" => $fight_id, "description" => $description, "actor_id" => $user->user_id]); return $action->save(); }