Example #1
0
 public function Get()
 {
     // Require Login
     Auth::RequireLogin(true);
     if (Auth::Get("manager")) {
         // Get Next Game
         $this->NextGame = new Game_Block();
         $this->NextGame->include_related("fixture", array("id"))->include_related_count("account", "players_count", array("active" => 1))->where(array("fixtures.owner" => Auth::Get("id"), "game_blocks.time > " => time()))->limit(1)->order_by("game_blocks.time", "ASC")->get();
         // Count connected players
         $this->ConnectedPlayers = new Player_Manager();
         $this->ConnectedPlayers = $this->ConnectedPlayers->where(array("manager_id" => Auth::Get("id")))->count();
         // Get Next Game
         $NextGameTime = false;
         if ($this->NextGame->exists() && $this->NextGame->time) {
             $NextGameTime = date(TIME_FORMAT, $this->NextGame->time);
         }
         // Get Confirmed Games
         $this->ConfirmedGames = new Game_Block();
         $this->ConfirmedGames->include_related("fixture", array("owner", "id", "location"))->where(array("fixtures.owner" => Auth::Get("id"), "game_blocks.time >=" => time()))->get_iterated();
         $ConfirmedGames = array();
         foreach ($this->ConfirmedGames as $Game) {
             $ConfirmedGames[] = array("day" => date("l", $Game->time), "date" => date(TIME_FORMAT, $Game->time), "future" => $Game->time > time() ? true : false, "game_id" => $Game->id, "location" => $Game->fixture_location);
         }
         $this->json->send(array("success" => "OK", "ConnectedPlayers" => $this->ConnectedPlayers, "NextGame" => $NextGameTime, "ConfirmedGames" => $ConfirmedGames));
     } else {
         // Get Next Game Block
         $this->NextGame = new Account();
         $this->NextGame->game_block->where(array("accounts.id" => Auth::Get("id"), "game_blocks.time >" => time()))->limit(1)->order_by("game_blocks.time", "ASC")->get();
         // Count connected players
         $this->ConnectedPlayers = $this->db->query("\n\t\t\t\t\tSELECT count(DISTINCT accounts_game_blocks.account_id) as ConnectedPlayers\n\t\t\t\t\tFROM fixtures\n\t\t\t\t\tLEFT JOIN game_blocks ON game_blocks.fixture_id = fixtures.id\n\t\t\t\t\tLEFT JOIN accounts_game_blocks ON accounts_game_blocks.game_block_id = game_blocks.id\n\t\t\t\t\tWHERE accounts_game_blocks.account_id != " . Auth::Get("id") . "\n\t\t\t\t")->result();
         $this->ConnectedPlayers = $this->ConnectedPlayers[0]->ConnectedPlayers;
         // Get Next Game
         $NextGameTime = false;
         if ($this->NextGame->exists() && $this->NextGame->time) {
             $NextGameTime = date(TIME_FORMAT, $this->NextGame->time);
         }
         // Get Confirmed Games
         $this->ConfirmedGames = new Game_Block();
         $this->ConfirmedGames = $this->ConfirmedGames->where(array("time >=" => time()))->include_related("fixture", array("location", "id"))->get_iterated();
         $ConfirmedGames = array();
         foreach ($this->ConfirmedGames as $Game) {
             $ConfirmedGames = array("day" => date("l", $Game->time), "date" => date(TIME_FORMAT, $Game->time), "game_id" => $Game->id, "location" => $Game->fixture_location);
         }
         $this->json->send(array("success" => "OK", "ConnectedPlayers" => $this->ConnectedPlayers, "NextGame" => $NextGameTime, "ConfirmedGames" => $ConfirmedGames));
     }
 }
Example #2
0
 public function Leave($block = 0)
 {
     Auth::RequireLogin(true);
     // Make sure the user is logged in
     if (!$this->auth->isLogged()) {
         $this->json->error("You need to be logged in.");
     }
     // Find the game
     $this->Block = new Game_Block($block);
     // Make sure the game exists
     if (!$this->Block->exists()) {
         $this->json->error("Block could not be found.");
     }
     // Make sure the game is not in the past
     if ($this->Block->time != 0 && $this->Block->time < time()) {
         $this->json->error("This block is already in the past.");
     }
     // Load your account
     $this->Account = new Account(Auth::Get("id"));
     // Make sure your account has been loaded
     if (!$this->Account->exists()) {
         $this->json->error("Your account could not be loaded.");
     }
     // Make sure you are playing this game
     if (!$this->Block->is_related_to($this->Account)) {
         $this->json->error("You are not playing this block.");
     }
     // Try getting the fixture
     $this->Fixture = $this->Block->fixture->get();
     // Make sure fixture is loaded
     if (!$this->Fixture->exists()) {
         $this->json->error("Fixture could not be loaded.");
     }
     $this->Related_Account = $this->Block->account->where("id", Auth::Get("id"))->include_join_fields()->get();
     if ($this->Related_Account->exists() && !$this->Related_Account->join_active) {
         $this->json->error("You already left this game.");
     }
     // If the fixture is not free
     if ($this->Fixture->payp_cost) {
         // Mark his last payment canceled
         $this->LastPayment = new Payment();
         $this->LastPayment = $this->LastPayment->where(array("account_id" => Auth::Get("id"), "game_block_id" => $this->Block->id))->order_by("id", "DESC")->limit(1)->get();
         if ($this->LastPayment->exists()) {
             $this->LastPayment->status = "canceled";
             $this->LastPayment->save();
         }
         // Return the money
         $Payment = new Payment();
         if ($this->Related_Account->join_type == "game") {
             $Payment->amount = $this->Fixture->payp_cost - $this->Fixture->payp_cost * 2;
         } else {
             if ($this->Related_Account->join_type == "block") {
                 $this->BlocksCount = $this->Fixture->game_block->count();
                 $Payment->amount = floor($this->Fixture->player_cost / $this->BlocksCount) - floor($this->Fixture->player_cost / $this->BlocksCount * 2);
             }
         }
         $Payment->date = time();
         $Payment->account_id = Auth::Get("id");
         $Payment->game_block_id = $this->Block->id;
         $Payment->fixture_id = $this->Fixture->id;
         $Payment->type = "game";
         $Payment->status = "active";
         $Payment->save();
         // Return credits to your account
         $this->Account->credits += $Payment->amount;
         $this->Account->save();
     }
     // Set this account inactive
     $this->Block->set_join_field($this->Account, "active", 0);
     $this->json->success();
 }
Example #3
0
 public function my_games()
 {
     Auth::RequireLogin();
     $this->template->setData("SelectedTab", "Games I play");
     $this->Account = new Account(Auth::Get("id"));
     if (!$this->Account->exists()) {
         Session::GoBack("Your account could not be loaded.");
     }
     $this->Fixtures = $this->Account->game_block->include_related("fixture", array("location", "id", "postcode", "type"))->where(array("time > " => time(), "accounts_game_blocks.active" => 1))->or_where("time", 0)->include_related_count("account", "account_count", array("active" => 1))->order_by("game_blocks.time", "ASC")->get_iterated();
     $this->load->view("fixtures/my_games");
 }
Example #4
0
 public function payments()
 {
     Auth::RequireLogin();
     $this->template->setData("SelectedTab", "Payments");
     if (Auth::Get("manager")) {
         // Get Payments - Manager
         $this->Payments = $this->db->query("\n\t\t\t\t\tSELECT fixtures.id as FixtureID, accounts.first_name, accounts.last_name, payments.amount, fixtures.location as FixtureLocation, game_blocks.time as GameBlockTime, payments.date as PaymentTime\n\t\t\t\t\tFROM payments\n\t\t\t\t\tLEFT JOIN game_blocks ON game_blocks.id = payments.game_block_id\n\t\t\t\t\tLEFT JOIN accounts ON accounts.id = payments.account_id\n\t\t\t\t\tLEFT JOIN fixtures ON fixtures.id = game_blocks.fixture_id\n\t\t\t\t\tWHERE fixtures.owner = " . Auth::Get("id") . "\n\t\t\t\t\tORDER BY payments.id DESC \n\t\t\t\t")->result();
         $this->load->view("accounts/payments_manager");
     } else {
         // Get Payments - Player
         $this->Payments = $this->db->query("\n\t\t\t\t\tSELECT fixtures.id as FixtureID, payments.amount, fixtures.location as FixtureLocation, game_blocks.time as GameBlockTime, payments.date as PaymentTime\n\t\t\t\t\tFROM payments\n\t\t\t\t\tLEFT JOIN game_blocks ON game_blocks.id = payments.game_block_id\n\t\t\t\t\tLEFT JOIN fixtures ON fixtures.id = game_blocks.fixture_id\n\t\t\t\t\tWHERE payments.account_id = " . Auth::Get("id") . "\n\t\t\t\t\tORDER BY payments.id DESC \n\t\t\t\t")->result();
         $this->load->view("accounts/payments_player");
     }
 }
Example #5
0
 public function __construct()
 {
     parent::__construct();
     Auth::RequireLogin();
 }