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; } } }
$optionText = $option->{$arrayName}; $listHtml .= "<option value=\"{$optionValue}\">{$optionText}</option>"; } $listHtml .= "</select>"; return $listHtml; } /* * Visits table gateway */ $visitsGateway = new VisitsTableGateway($dbAdapter); /* * Retrieves all visit information to be used for browser visits table */ $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"] != "") {
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();
/* Use this page to test each one of your table gateway classes. */ require_once 'lib/helpers/visits-setup.inc.php'; ?> <html> <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) {