-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from TheWhite147/feature/stats-banner
Feature/stats banner
- Loading branch information
Showing
10 changed files
with
566 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php header('Access-Control-Allow-Origin: *'); ?> | ||
|
||
<?php | ||
$pdo = new PDO('sqlite:/home/pi/pi-score-counter/pi-score-counter.db'); | ||
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); | ||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | ||
|
||
$stmt = $pdo->prepare("SELECT id, id_player_1, id_player_2, created_date FROM games"); | ||
$stmt->execute(); | ||
|
||
while ($row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT)) { | ||
$data = "id=" . $row[0] . "#id_player_1=" . $row[1] . "#id_player_2=" . $row[2] . "#created_date=" . $row[3] . "|"; | ||
print $data; | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php header('Access-Control-Allow-Origin: *'); ?> | ||
|
||
<?php | ||
$pdo = new PDO('sqlite:/home/pi/pi-score-counter/pi-score-counter.db'); | ||
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); | ||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | ||
|
||
$stmt = $pdo->prepare("SELECT id, id_game, id_serving_player, score_player_1, score_player_2, created_date FROM scores"); | ||
$stmt->execute(); | ||
|
||
while ($row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT)) { | ||
$data = "id=" . $row[0] . "#id_game=" . $row[1] . "#id_serving_player=" . $row[2] . "#score_player_1=" . $row[3] . "#score_player_2=" . $row[4] . "#created_date=" . $row[5] . "|"; | ||
print $data; | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
|
||
if (typeof Api === "undefined") { Api = {}; } | ||
if (typeof Api.GetPlayersList === "undefined") { Api.GetPlayersList = {}; } | ||
if (typeof Api.GetUIControls === "undefined") { Api.GetUIControls = {}; } | ||
|
||
(function () { | ||
|
||
// // Gets UI controls from database | ||
Api.GetUIControls = function(callback) { | ||
$.get("http://localhost/api/get_ui_controls.php", function(data) { | ||
var objects = stripLastChar(data).split("|"); | ||
callback(objects); | ||
}); | ||
} | ||
|
||
// Gets the list of players from database | ||
Api.GetPlayersList = function(callback){ | ||
var tmpLstPlayers = []; | ||
$.get("http://localhost/api/get_players.php", function(data) { | ||
var objects = stripLastChar(data).split("|"); | ||
for (var i = 0; i < objects.length; i++) { | ||
var id = objects[i].split("=")[0]; | ||
var name = objects[i].split("=")[1]; | ||
tmpLstPlayers.push({ id: id, name: decodeURIComponent(name)}); | ||
} | ||
callback(tmpLstPlayers); | ||
}); | ||
} | ||
|
||
// // Gets all games from database | ||
Api.GetGames = function(callback) { | ||
var tmpGames = []; | ||
$.get("http://localhost/api/get_games.php", function(data) { | ||
var objects = stripLastChar(data).split("|"); | ||
|
||
for (var i = 0; i < objects.length; i++) { | ||
var newObject = {}; | ||
|
||
var columns = objects[i].split("#"); | ||
for (var j = 0; j < columns.length; j++) { | ||
var keyValue = columns[j].split("="); | ||
newObject[keyValue[0]] = keyValue[1]; | ||
} | ||
|
||
tmpGames.push(newObject); | ||
} | ||
|
||
callback(tmpGames); | ||
}); | ||
} | ||
|
||
// // Gets all scores from database | ||
Api.GetScores = function(callback) { | ||
var tmpScores = []; | ||
$.get("http://localhost/api/get_scores.php", function(data) { | ||
var objects = stripLastChar(data).split("|"); | ||
|
||
for (var i = 0; i < objects.length; i++) { | ||
var newObject = {}; | ||
|
||
var columns = objects[i].split("#"); | ||
for (var j = 0; j < columns.length; j++) { | ||
var keyValue = columns[j].split("="); | ||
newObject[keyValue[0]] = keyValue[1]; | ||
} | ||
|
||
tmpScores.push(newObject); | ||
} | ||
|
||
callback(tmpScores); | ||
}); | ||
} | ||
|
||
// Strips last char of string | ||
function stripLastChar(myString) { | ||
return myString.substring(0, myString.length - 1).trim(); | ||
} | ||
|
||
})(); |
Oops, something went wrong.