Example #1
0
    public function Invite()
    {
        $Check = new Invite();
        // If this invite already exists, skip it
        if ($Check->where(array("email" => $this->email, "fixture_id" => $this->fixture_id))->get()->result_count() > 0) {
            return false;
        }
        // Try saving it
        if ($this->save()) {
            $CI =& get_instance();
            $CI->load->library("email");
            $CI->email->from('*****@*****.**', 'Game Manager');
            $CI->email->to($this->email);
            $CI->email->subject('Invitation to a Game!');
            $CI->email->message('Dear Player<br/><br/>' . ucwords(strtolower($this->Inviter->first_name . ' ' . $this->Inviter->last_name)) . ' has invited you to play at ' . $this->Fixture->location . ' on ' . $this->Fixture->day . ' at ' . $this->Fixture->time . '. If you would

				like to join the team please click here and signup to the really easy ' . $this->Fixture->type . ' tool.
				<br/><br/>
				Signup now <a href="' . url("fixtures/join_game/" . $this->tracking_code) . '">Click Here</a>');
            $CI->email->send();
        }
    }
Example #2
0
 public function Join($block = 0)
 {
     Auth::RequireLogin(true);
     if (!$this->auth->isLogged()) {
         $this->json->error("You need to be logged in.");
     }
     $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.");
     }
     $this->Account = new Account(Auth::Get("id"));
     if (!$this->Account->exists()) {
         $this->json->error("Your account 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 are already playing this block.");
     }
     // Get the Fixture
     $this->Fixture = $this->Block->fixture->get();
     // Make sure the fixture exists
     if (!$this->Fixture->exists()) {
         $this->json->error("Fixture could not be loaded.");
     }
     // Check the limit of this block
     $this->PlayersCount = $this->Block->account->include_join_fields()->where(array("active" => 1))->count();
     if ($this->PlayersCount >= (int) $this->Fixture->type * 2) {
         $this->json->error("This game is already full!");
     }
     if ($this->Fixture->payp_cost > 0 && (!$this->Related_Account->exists() || $this->Related_Account->join_type == "game")) {
         $this->Account->credits -= $this->Fixture->payp_cost;
         $this->Account->save();
         // Add Payment Record
         $payment = new Payment();
         $payment->account_id = Auth::Get("id");
         $payment->game_block_id = $this->Block->id;
         $payment->amount = $this->Fixture->payp_cost;
         $payment->date = time();
         $payment->type = "game";
         $payment->fixture_id = $this->Fixture->id;
         $payment->paid = 0;
         $payment->status = "active";
         $payment->save();
     }
     // Cancel refund if there is one
     if ($this->Related_Account->exists() && $this->Related_Account->join_type == "block") {
         $this->LastPayment = new Payment();
         $this->LastPayment->where(array("account_id" => Auth::Get("id"), "game_block_id" => $this->Block->id, "amount <" => 0))->order_by("id", "DESC")->limit(1)->get();
         if ($this->LastPayment->exists()) {
             $this->LastPayment->status = "canceled";
             $this->LastPayment->save();
         }
     }
     // Make all invites inactive for this fixture
     $Invite = new Invite();
     $Invite->where(array("email" => Auth::Get("email"), "fixture_id" => $this->Fixture->id, "valid" => 1, "joined" => 0))->limit(1)->get();
     // Check for Invitation
     if ($Invite->exists()) {
         $Invite->joined = 1;
         $Invite->valid = 0;
         $Invite->joined_on = time();
         $Invite->joined_account = Auth::Get("id");
         // If invitation exists, mark it as accepted
         $Invite->save();
     }
     // Relate this player with a manager
     $this->PlayerManager = new Player_Manager();
     $this->PlayerManager->player_id = Auth::Get("id");
     $this->PlayerManager->manager_id = $this->Fixture->owner;
     $this->PlayerManager->save();
     // Relate Account
     $this->Block->save($this->Account);
     $this->Block->set_join_field($this->Account, "active", 1);
     if (!$this->Related_Account->exists()) {
         $this->Block->set_join_field($this->Account, "type", "game");
     }
     // Send success response
     $this->json->success();
 }