ticket = $ticket; } public function store() { global $db; $data = array( 'ticket_id' => $this->ticket->ID, 'sport' => $this->sport, 'team1' => $this->team1, 'team2' => $this->team2, 'exchange' => $this->exchange, 'prediction' => $this->prediction, 'bet' => $this->bet, 'datetime' => $this->datetime->format('U'), 'text' => $this->desc, ); $sql = 'INSERT INTO ' . BETS_TABLE . ' ' . $db->sql_build_array('INSERT', $data); $db->sql_query($sql); $sql = 'UPDATE ' . TICKETS_TABLE . ' SET last_bet_datetime = ' . $data['datetime'] . ' WHERE id = ' . $data['ticket_id'] . ' AND last_bet_datetime < ' . $data['datetime']; $db->sql_query($sql); $this->ID = $db->sql_nextid(); $this->ticket->bets[] = $this; } public function loadFromRow($row) { $this->ID = (int) $row['id']; $this->sport = $row['sport']; $this->team1 = $row['team1']; $this->team2 = $row['team2']; $this->exchange = (int) $row['exchange']; $this->prediction = (int) $row['prediction']; $this->result = $row['result']; $this->bet = $row['bet']; $this->datetime = new DateTime('@' . $row['datetime']); $this->desc = $row['text']; $this->ticket->bets[] = $this; } public function setResult($team1, $team2) { global $db; $this->result = ((int) $team1) . ':' . ((int) $team2); $data = array( 'result' => $this->result, ); $sql = 'UPDATE ' . BETS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $data) . ' WHERE id = ' . $this->ID; $db->sql_query($sql); } public function won() { if (empty($this->result)) return true; $result = explode(':', $this->result); switch ($this->bet) { case '1': return $result[0] > $result[1]; case 'X': return $result[0] == $result[1]; case '2': return $result[0] < $result[1]; case '1X': return $result[0] >= $result[1]; case 'X2': return $result[0] <= $result[1]; case '12': return $result[0] <> $result[1]; } switch ($this->bet[0]) { case '<': return $result[0] + $result[1] < substr($this->bet, 1); case '>': return $result[0] + $result[1] > substr($this->bet, 1); case '=': return $result[0] + $result[1] == substr($this->bet, 1); case '!': return $result[0] + $result[1] != substr($this->bet, 1); } if (strpos($this->bet, 'STG') === 0) { return $result[$this->bet[3] - 1] > 0; } return false; } public function setTemplate($prefix = '') { global $template; $template->assign_block_vars($prefix . 'bet', array( 'ID' => $this->ID, 'DATETIME' => $this->datetime->format('d.m G:i'), 'SPORT' => $this->sport, 'TEAM1' => $this->team1, 'TEAM2' => $this->team2, 'BET' => $this->bet, 'EXCHANGE' => $this->exchange / 100, 'PREDICTION' => $this->prediction, 'RESULT' => $this->result, 'WON' => $this->won(), )); } public function unsetTemplate($prefix = '') { $template->destroy_block_vars($prefix . 'bet'); } }