public function cash() { $this->live_cash = 0; $this->played = 0; $this->cash = 0; $this->transactions = transaction::from_account($this->account_id); # här kommer transaktionerna foreach ($this->transactions as $transaction) { $transactions[] = $transaction; if ($transaction->type == "cash_in") { $this->cash += $transaction->amount; } elseif ($transaction->type == "bonus") { $this->cash += $transaction->amount; } elseif ($transaction->type == "cash_out") { $this->cash -= $transaction->amount; } } # här kommer betsen $this->bets = bet::from_account($this->account_id); foreach ($this->bets as $bet) { $bet->match = match::from_id($bet->match_id); $bet->account = account::from_id($bet->account_id); $bet->account->site = site::from_id($bet->account->site_id); $this->played += $bet->bet; if ($bet->match->result == "undecided") { $this->live_cash += $bet->bet; $this->cash -= $bet->bet; } else { $this->cash -= $bet->bet; $this->cash += $bet->result; } } return $this->cash; }
function result() { $match_id = $_GET['match_id']; $match = match::from_id($match_id); $result = $_GET['result']; $match->result = $result; $match->update(); $bets = bet::from_match($match_id); foreach ($bets as $bet) { $bet->account = account::from_id($bet->account_id); #$bet->account->site=site::from_id($bet->account->site_id); if ($bet->choice == $result) { $bet->result = $bet->bet * $bet->odds; } else { $bet->result = 0; } $bet->update(); } header("location:index.php"); }
function profile() { $id = $_GET['user_id']; $user = user::from_id($id); $user->accounts = account::from_user($user->user_id); $bets = array(); $calculation['cash_in'] = 0; $calculation['cash_out'] = 0; $calculation['bonus'] = 0; foreach ($user->accounts as $account) { # räkna ut alla pengar $account->transactions = transaction::from_account($account->account_id); foreach ($account->transactions as $transaction) { $transactions[] = $transaction; if ($transaction->type == "cash_in") { $calculation['cash_in'] += $transaction->amount; } elseif ($transaction->type == "bonus") { $calculation['bonus'] += $transaction->amount; } elseif ($transaction->type == "cash_out") { $calculation['cash_out'] -= $transaction->amount; } } $account->cash(); } $bets = bet::from_user($id); foreach ($bets as $bet) { $bet->match = match::from_id($bet->match_id); $bet->account = account::from_id($bet->account_id); $bet->account->site = site::from_id($bet->account->site_id); } $data['calculation'] = $calculation; $data['user'] = $user; $data['bets'] = $bets; if (!empty($transactions)) { $data['transactions'] = $transactions; } $this->view('users/profile_view.php', $data, 'main_template.php'); }