Example #1
0
/**
 * Pull the data by the platform of the games from the database.
 * Can pull from multiple games at once.
 *
 * pullDataByPlat(arrayOfObject, string, string, int, string)
 */
function pullDataByPlat($games, $metricType, $aggr, $days, $platform)
{
    // game_found variable needed to check that there was a game found at the end
    $game_found = false;
    // initialize total beforehand to be updated afterwards and returned at the end
    $total = '';
    // check if each game in the database is an inputted platform game, and if true, update total
    $key = array_keys($games);
    $size = sizeOf($key);
    for ($g = 0; $g < $size; $g++) {
        if (isset($games[$g]->platform[$platform])) {
            $result = pullData($metricType, $aggr, $days, $games[$g]);
            // account for the update differences depending on the aggregate type/whether total is empty or not
            if ($aggr === 'sum' || $aggr === 'mean') {
                if ($game_found) {
                    $total = $total + $result;
                } else {
                    $total = $result;
                }
            } else {
                if ($aggr === 'none') {
                    $key = array_keys($result);
                    $size = sizeOf($key);
                    for ($i = 0; $i < $size; $i++) {
                        if ($game_found) {
                            if (isset($total[$i]['total']) && isset($result[$i]['total'])) {
                                $total[$i]['total'] = $total[$i]['total'] + $result[$i]['total'];
                            } else {
                                if (isset($result[$i]['total'])) {
                                    $total[$i]['total'] = $result[$i]['total'];
                                }
                            }
                        } else {
                            $total[$i] = $result[$i];
                        }
                    }
                } else {
                    $key = array_keys($result);
                    $size = sizeOf($key);
                    for ($i = 0; $i < $size; $i++) {
                        if ($game_found) {
                            $total[$i]['value'] = $total[$i]['value'] + $result[$i]['value'];
                        } else {
                            $total[$i] = $result[$i];
                        }
                    }
                }
            }
            $game_found = true;
        }
    }
    // error if game not found
    if (!$game_found) {
        echo 'Error: No game with this platform was found';
    }
    // close the handle after making the query calls
    global $curl_handle;
    curl_close($curl_handle);
    // uncomment to print the total
    // print_r ($total);
    return $total;
}
<?php

$id = filter_input(INPUT_GET, 'id');
$results = pullData($id, $_SESSION['id']);
Example #3
0
    if (isset($_GET['action'])) {
        $action = $_GET['action'];
        if (!isset($_GET['param']) || $_GET['param'] == "") {
            if (isset($_GET['param2'])) {
                echo json_encode("Invalid Parameter values");
            } else {
                actionData($data, $action, null, null);
            }
        } elseif (isset($_GET['param']) && !isset($_GET['param2'])) {
            $param = $_GET['param'];
            $pos = strpos($param, ',');
            if ($pos !== false) {
                $param = explode(',', $param);
            }
            actionData($data, $action, $param, null);
        } else {
            if (isset($_GET['param2'])) {
                $param = $_GET['param'];
                $param2 = $_GET['param2'];
                $param = explode(',', $param);
                $param2 = explode(',', $param2);
                actionData($data, $action, $param, $param2);
            }
        }
    } else {
        pullData($data);
    }
}
?>

function check()
{
    // if any field is empty or incorrectly formatted, return an error message via JS
    if (isset($_POST['id'])) {
        $id = $_POST['id'];
    } else {
        echo '<script type="text/javascript"> 
	                alert("Please enter a game ID");
	                window.location.href = "newGame.php";
	              </script>;';
    }
    if (isset($_POST['name'])) {
        $name = $_POST['name'];
    } else {
        echo '<script type="text/javascript"> 
	                alert("Please enter a game name");
	                window.location.href = "newGame.php";
	              </script>;';
    }
    if (isset($_POST['platform'])) {
        $platform = $_POST['platform'];
    } else {
        echo '<script type="text/javascript"> 
	                alert("Please select a platform");
	                window.location.href = "newGame.php";
	              </script>;';
    }
    if (isset($_POST['api_key'])) {
        if (strlen($_POST['api_key']) === 40) {
            $api_key = $_POST['api_key'];
        } else {
            echo '<script type="text/javascript"> 
	                alert("Entered API Key is not valid: Must be 40 characters");
	                window.location.href = "newGame.php";
	              </script>;';
        }
    } else {
        echo '<script type="text/javascript"> 
	                alert("Please enter an API Key");
	                window.location.href = "newGame.php";
	              </script>;';
    }
    if (isset($_POST['category'])) {
        $category = $_POST['category'];
    } else {
        echo '<script type="text/javascript"> 
	                alert("Please select one or more categories");
	                window.location.href = "newGame.php";
	              </script>;';
    }
    // create a new Game object with the info submitted and see if it pulls from gameAnalytics
    $newGame = new Game($name, $id, $api_key, $platform);
    $check = pullData('DAU', 'none', 1, $newGame);
    if ($check == false) {
        return false;
    } else {
        return true;
    }
}