Prechádzať zdrojové kódy

Outstanding bets added

Axel Nordh 3 rokov pred
rodič
commit
6fae52038c
4 zmenil súbory, kde vykonal 203 pridanie a 21 odobranie
  1. 60 0
      Bet.php
  2. 38 0
      Database.php
  3. 79 19
      WebFunctions.php
  4. 26 2
      index.php

+ 60 - 0
Bet.php

@@ -0,0 +1,60 @@
+<?php
+
+class Bet
+{
+    private string $gameDate;
+    private string $leagueName;
+    private string $teams;
+    private string $betOn;
+    private float $betAmount;
+    private float $betOdds;
+    private string $betStatus;
+
+    public function __construct(
+        string $gameDate,
+        string $leagueName,
+        string $teams,
+        string $betOn,
+        float $betAmount,
+        float $betOdds,
+        string $betStatus
+    ) {
+        $this->gameDate = $gameDate;
+        $this->leagueName = $leagueName;
+        $this->teams = $teams;
+        $this->betOn = $betOn;
+        $this->betAmount = $betAmount;
+        $this->betOdds = $betOdds;
+        $this->betStatus = $betStatus;
+    }
+
+    public function getGameDate()
+    {
+        return $this->gameDate;
+    }
+
+    public function getLeagueName()
+    {
+        return $this->leagueName;
+    }
+    public function getTeams()
+    {
+        return $this->teams;
+    }
+    public function getBetOn()
+    {
+        return $this->betOn;
+    }
+    public function getBetAmount()
+    {
+        return $this->betAmount;
+    }
+    public function getOdds()
+    {
+        return $this->betOdds;
+    }
+    public function getStatus()
+    {
+        return $this->betStatus;
+    }
+}

+ 38 - 0
Database.php

@@ -3,6 +3,7 @@
 include_once 'Team.php';
 include_once 'SoccerMatch.php';
 include_once 'League.php';
+include_once 'Bet.php';
 
 class Database
 {
@@ -197,4 +198,41 @@ class Database
         $this->closeConnection($this->conn);
         return $result;
     }
+
+    public function getOutstandingBets()
+    {
+        $result = null;
+        $this->openConnection();
+        $sql = 'SELECT sr.gameDate as gameDate, l.name as leagueName,
+            ht.name as homeTeamName, awt.name as awayTeamName,
+            abt.bet as betOn, abt.betAmount as betAmount, abt.betOdds as betOdds, abt.status as betStatus
+            FROM AnalysisBetTable abt
+            INNER JOIN SoccerResults sr ON abt.matchId = sr.id
+            INNER JOIN League l ON l.id = sr.leagueId
+            INNER JOIN Team ht on ht.id = sr.homeTeamId
+            INNER JOIN Team awt on awt.id = sr.awayTeamId
+            WHERE status IN ("LOST", "OPEN", "COVERED")';
+        try {
+            $stat = $this->conn->prepare($sql);
+            $stat->execute();
+
+            while ($row = $stat->fetch()) {
+                $result[] = new Bet(
+                    $row['gameDate'],
+                    $row['leagueName'],
+                    $row['homeTeamName'] . '-' . $row['awayTeamName'],
+                    $row['betOn'],
+                    $row['betAmount'],
+                    $row['betOdds'],
+                    $row['betStatus']
+                );
+            }
+        } catch (Exception $e) {
+            echo 'Getting outstanding bets failed ' . $e->getMessage();
+        }
+
+        $this->closeConnection($this->conn);
+
+        return $result;
+    }
 }

+ 79 - 19
WebFunctions.php

@@ -6,9 +6,11 @@ include_once 'Database.php';
 
 class WebFunctions
 {
-    function createMatchTable($matches)
+    function createMatchTable($matches, $betLevel, $bankValue)
     {
-        echo '<table>';
+        echo '<table id="soccerMatchTable" class="display">';
+        echo '<thead>';
+        echo '<tr>';
         echo '<th>GameDate</th>';
         echo '<th>League</th>';
         echo '<th>Home Team</th>';
@@ -22,30 +24,49 @@ class WebFunctions
         echo '<th>Bet Amount</th>';
 
         echo '<th>Submit</th>';
+        echo '</tr>';
+        echo '</thead>';
 
+        echo '<tbody>';
         foreach ($matches as $match) {
-            $this->createMatchRow($match);
+            $this->createMatchRow($match, $betLevel, $bankValue);
         }
 
+        echo '</tbody>';
         echo '</table>';
     }
 
-    function createMatchRow(SoccerMatch $match)
-    {
-        echo '<tr>';
-
-        echo '<td>' . $match->getGameDate() . '</td>';
-        echo '<td>' . $match->getHomeTeam()->getTeamLeague() . '</td>';
-
-        echo '<td>' . $match->getHomeTeam()->getTeamName() . '</td>';
-        echo '<td>' . $match->getAwayTeam()->getTeamName() . '</td>';
-        echo '<td>' . $match->getOdds1() . '</td>';
-        echo '<td>' . $match->getOddsX() . '</td>';
-        echo '<td>' . $match->getOdds2() . '</td>';
-
-        echo '<td>' . $this->getAnalysisValue($match);
-
-        echo '</tr>';
+    function createMatchRow(
+        SoccerMatch $match,
+        float $betLevel,
+        float $bankValue
+    ) {
+        $analysisValue = $this->getAnalysisValue($match);
+
+        if ($analysisValue != 'No bet') {
+            echo '<tr>';
+
+            echo '<td>' . $match->getGameDate() . '</td>';
+            echo '<td>' . $match->getHomeTeam()->getTeamLeague() . '</td>';
+
+            echo '<td>' . $match->getHomeTeam()->getTeamName() . '</div></td>';
+            echo '<td>' . $match->getAwayTeam()->getTeamName() . '</td>';
+            echo '<td><div contenteditable>' .
+                $match->getOdds1() .
+                '</div></td>';
+            echo '<td><div contenteditable>' .
+                $match->getOddsX() .
+                '</div></td>';
+            echo '<td><div contenteditable>' .
+                $match->getOdds2() .
+                '</div></td>';
+
+            echo '<td>' . $analysisValue;
+            echo '<td>' . ($bankValue * $betLevel) / 100 . '</td>';
+            echo '<td><button id="submitRowButton">Submit</button></td>';
+
+            echo '</tr>';
+        }
     }
 
     private function getAnalysisValue(SoccerMatch $match)
@@ -121,4 +142,43 @@ class WebFunctions
 
         return $result;
     }
+
+    public function createOutstandingBetsTable()
+    {
+        $database = new Database();
+        $bets = $database->getOutstandingBets();
+        if ($bets == null) {
+            return;
+        }
+        echo '<table id="outstandingBetsTable">';
+        echo '<thead>';
+        echo '<tr>';
+        echo '<th>Game date</th>';
+        echo '<th>League</th>';
+        echo '<th>Teams</th>';
+        echo '<th>Bet On</th>';
+        echo '<th>Bet Amount</th>';
+        echo '<th>Odds</th>';
+        echo '<th>Status</th>';
+        echo '</tr>';
+        echo '</thead>';
+        foreach ($bets as $bet) {
+            $this->createOutstandingBetsRow($bet);
+        }
+        echo '<tbody>';
+        echo '</table>';
+    }
+
+    private function createOutstandingBetsRow(Bet $bet)
+    {
+        echo '<tr>';
+        echo '<td>' . $bet->getGameDate() . '</td>';
+        echo '<td>' . $bet->getLeagueName() . '</td>';
+        echo '<td>' . $bet->getTeams() . '</td>';
+        echo '<td>' . $bet->getBetOn() . '</td>';
+        echo '<td>' . $bet->getBetAmount() . '</td>';
+        echo '<td>' . $bet->getOdds() . '</td>';
+        echo '<td>' . $bet->getStatus() . '</td>';
+        echo '</tr>';
+    }
 }

+ 26 - 2
index.php

@@ -12,6 +12,10 @@ include_once 'WebFunctions.php';
     <title>Odds webspace</title>
     <meta name='viewport' content='width=device-width, initial-scale=1'>
     <link rel='stylesheet' type='text/css' media='screen' href='styles.css'>
+    <link href="https://cdn.datatables.net/1.13.3/css/jquery.dataTables.css">
+
+    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
+    <script src="https://cdn.datatables.net/1.13.3/js/jquery.dataTables.js"></script>
 </head>
 
 <body>
@@ -19,13 +23,33 @@ include_once 'WebFunctions.php';
 
 <h1> Odds better </h1>
 
-
 <?php
+$betAmount = 0.25;
+$bank = 500;
+echo '<label>Bank: </label><form><input type="number" id="bankInput" size="10" value="' .
+    $bank .
+    '"></form>';
 $database = new Database();
 $matches = $database->getTodaysPrioMatches();
 $wf = new WebFunctions();
-$wf->createMatchTable($matches);
+$wf->createMatchTable($matches, $betAmount, $bank);
+
+$wf->createOutstandingBetsTable();
 ?>
+
+<script>
+    $(document).ready( function () {
+        $('#soccerMatchTable').DataTable();
+    } );
+</script>
+<script>
+    $(document).ready( function () {
+        $('#outstandingBetsTable').DataTable();
+    } );
+</script>
+
+
+<!-- Script to handle submit button -->
 </body>
 
 </html>