Beispiel #1
0
function pullData($userData)
{
    require_once 'lib/helpers/visits-setup.inc.php';
    $BrowsersToPull = new BrowserTableGateway($dbAdapter);
    $ContinentsToPull = new ContinentsTableGateway($dbAdapter);
    $CountriesToPull = new CountriesTableGateway($dbAdapter);
    $DeviceBrandToPull = new DeviceBrandTableGateway($dbAdapter);
    $DeviceTypeToPull = new DeviceTypesTableGateway($dbAdapter);
    $OperatingSystemsToPull = new OperatingSystemsTableGateway($dbAdapter);
    $ReferrersToPull = new ReferrersTableGateway($dbAdapter);
    $VisitsToPull = new VisitsTableGateway($dbAdapter);
    $dataSets = array("Browsers", "Continents", "Countries", "Devicebrand", "Devicetype", "Operatingsystems", "Referrers", "Visits");
    if (in_array($userData, $dataSets)) {
        switch ($userData) {
            case "Browsers":
                $array = $BrowsersToPull->findAll();
                echo json_encode($array);
                break;
            case "Continents":
                $array = $ContinentsToPull->findAll();
                echo json_encode($array);
                break;
            case "Countries":
                $array = $CountriesToPull->findAll();
                echo json_encode($array);
                break;
            case "Devicebrand":
                $array = $DeviceBrandToPull->findAll();
                echo json_encode($array);
                break;
            case "Devicetype":
                $array = $DeviceTypeToPull->findAll();
                echo json_encode($array);
                break;
            case "Operatingsystems":
                $array = $OperatingSystemsToPull->findAll();
                echo json_encode($array);
                break;
            case "Referrers":
                $array = $ReferrersToPull->findAll();
                echo json_encode($array);
                break;
            case "Visits":
                $array = $VisitsToPull->findAll();
                echo json_encode($array);
                break;
        }
    }
}
function outputBrandCounts($dbAdapter)
{
    $id = $_GET[brand_id];
    if (!empty($id) && is_numeric($id) && $id >= 1 && $id <= 12) {
        $gateBrand = new DeviceBrandTableGateway($dbAdapter);
        $result = $gateBrand->findBrandWithCountsById($id);
        echo '<table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp">
          <thead>
            <tr>
              <th class="mdl-data-table__cell--non-numeric">Device Brand</th>
              <th>Visits</th>
            </tr>
          </thead>
          <tbody>';
        echo '<tr>
              <td class="mdl-data-table__cell--non-numeric">' . $result->name . '</td>
              <td>' . $result->DeviceVisits . '</td>
              </tr>';
        echo '</tbody>
            </table>';
    } else {
        echo "<h2>Device brand does not exist</h2>";
    }
}
Beispiel #3
0
$browserVisits = array();
$browsersGateway = new BrowserTableGateway($dbAdapter);
$results = $browsersGateway->findAll();
$totalVisits = 0;
foreach ($results as $result) {
    $browserVisits[$result->name] = $visitsGateway->countByBrowser($result->id);
    $totalVisits += $browserVisits[$result->name];
}
foreach ($browserVisits as $key => $value) {
    $browserVisits[$key] = round($value / $totalVisits * 100, 2) . "%";
}
$browserHeaders = array("Browser", "Visits");
/*
 * Retrieves all visit information for a specific brand
 */
$brandsGateway = new DeviceBrandTableGateway($dbAdapter);
$brandList = $brandsGateway->findAll();
if (isset($_GET["brandId"]) && $_GET["brandId"] != "") {
    $brandId = $_GET["brandId"];
    $brand = $brandsGateway->findById($brandId);
    $brandResults = array($brand->name => $visitsGateway->countByDeviceBrand($brandId));
    $brandHeaders = array("Brand", "Visits");
}
/*
 * Retrieves all visit information for a specific continent
 */
$continentsGateway = new ContinentsTableGateway($dbAdapter);
$continentList = $continentsGateway->findAll();
if (isset($_GET["continentCode"]) && $_GET["continentCode"] != "") {
    $continentCode = $_GET["continentCode"];
    $countriesGateway = new CountriesTableGateway($dbAdapter);
    foreach ($dropdownarray as $option) {
        $optionValue = $option->{$arrayId};
        $optionText = $option->{$arrayName};
        $listHtml .= "<option value=\"{$optionText}\">{$optionText}</option>";
    }
    $listHtml .= "</select>";
    return $listHtml;
}
/*
 * Visits table gateway
 */
$visitsGateway = new VisitsTableGateway($dbAdapter);
/*
 * Retrieves all visit information to be used for browser visits table
 */
/*
 * Retrieves all device type
 */
$typesGateway = new DeviceTypesTableGateway($dbAdapter);
$typesList = $typesGateway->findAll();
/*
 * Retrieves all visit information for a specific brand
 */
$brandsGateway = new DeviceBrandTableGateway($dbAdapter);
$brandList = $brandsGateway->findAll();
$browsersGateway = new BrowserTableGateway($dbAdapter);
$browserList = $browsersGateway->findAll();
$referrerGateway = new ReferrersTableGateway($dbAdapter);
$referrerList = $referrerGateway->findAll();
$operatingSystemGateway = new OperatingSystemsTableGateway($dbAdapter);
$osList = $operatingSystemGateway->findAll();
<body>
<h1> Table Gateways Tester </h1>

<?php 
echo '<hr/>';
echo '<h2>Test BrowserTableGateway</h2>';
echo '<h3>Test findAll()</h3>';
$gate = new BrowserTableGateway($dbAdapter);
$result = $gate->findAll();
foreach ($result as $row) {
    echo $row->id . " - " . $row->name . "<br/>";
}
echo '<h3>Test findById(3)</h3>';
$gate = new VisitsTableGateway($dbAdapter);
$result = $gate->findByBrowserPercent();
foreach ($result as $row) {
    echo "['" . $row->name . "', " . $row->num . "],";
}
echo '<hr/>';
echo '<h2>Test DeviceBrandTableGateway</h2>';
echo '<h3>Test findAllSorted()</h3>';
$gate = new DeviceBrandTableGateway($dbAdapter);
$result = $gate->findAllSorted(true);
foreach ($result as $row) {
    echo $row->id . " - " . $row->name . "<br/>";
}
echo '<h3>Test findById(11)</h3>';
$result = $gate->findById(11);
echo $result->id . " - " . $result->name;
// all done close connection
$dbAdapter->closeConnection();
<?php

include 'dashboard1.php';
require_once 'lib/helpers/visits-setup.inc.php';
$gate = new VisitsTableGateway($dbAdapter);
$result = $gate->findByBrowserPercent();
$result4 = $gate->findAllTables();
$gate2 = new DeviceBrandTableGateway($dbAdapter);
$result2 = $gate2->findByName();
$gate3 = new ContinentTableGateway($dbAdapter);
$result3 = $gate3->findByName();
?>

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="description" content="A front-end template that helps you build fast, modern mobile web apps.">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Dashboard</title>

    <!-- Add to homescreen for Chrome on Android -->
    <meta name="mobile-web-app-capable" content="yes">
    <link rel="icon" sizes="192x192" href="images/android-desktop.png">

    <!-- Add to homescreen for Safari on iOS -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-title" content="Material Design Lite">
    <link rel="apple-touch-icon-precomposed" href="images/ios-desktop.png">
<?php

include 'partials/header.php';
require_once 'code/lib/helpers/visits-setup.inc.php';
$browserGate = new BrowserTableGateway($dbAdapter);
$visitGate = new VisitTableGateway($dbAdapter);
$continentGate = new ContinentTableGateway($dbAdapter);
$countryGate = new CountryTableGateway($dbAdapter);
$brandGate = new DeviceBrandTableGateway($dbAdapter);
$brandResult = $brandGate->findAllSorted(true);
$browserResult = $browserGate->findAllSorted(true);
$visitsByBrowser = $visitGate->getCountPercentageBy('browser_id');
$visitsByBrand = $visitGate->getCountPercentageBy('device_brand_id');
$continentResult = $continentGate->findAllSorted(true);
$dbAdapter->closeConnection();
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<div class="mui-row">
    <div class="mui-col-md-6">
        <div class="mui-panel left top">
		
		<!-- Dashboard Panel 1: Percentage of Visits by Browser -->

		<?php 
echo "<table class='mui-table' id='testtable'><thead><tr><th>Browser</th><th>Percentage of Visits</th></tr></thead><tbody>";
foreach ($visitsByBrowser as $row) {
    $browser = $browserGate->findById($row['browser_id']);
    echo "<tr><td>" . $browser->name . "</td><td>" . $row['percentage'] . "%</td></tr>";
}
echo "</tbody></table>";
?>
function outputBrandCounts($dbAdapter)
{
    $id = $_GET["brand_id"];
    if (!empty($id) && is_numeric($id) && $id >= 1 && $id <= 12) {
        $gateBrand = new DeviceBrandTableGateway($dbAdapter);
        $result = $gateBrand->findBrandWithCountsById($id);
        $visitCount = $result->DeviceVisits;
        echo json_encode($visitCount);
    }
}