} 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); $countries = $countriesGateway->filterByContinentCode($continentCode); $countryResults = array(); foreach ($countries as $result) { $countryResults[$result->CountryName] = $visitsGateway->countByCountryCode($result->ISO); } $countryHeaders = array("Country", "Visits"); }
//$result = $gate->findById(3); //echo $result->id . " - " . $result->ip_address; // //echo '<h3>Test filterByBrowser(2)</h3>'; //$gate = new VisitsTableGateway($dbAdapter); //$result = $gate->filterByBrowser(2); //foreach ($result as $row) { // echo $row->id . " - " . $row->browser_id .' - '. $row->ip_address . "<br/>"; //} //echo '<h3>Test filterByOS(4)</h3>'; //$gate = new VisitsTableGateway($dbAdapter); //$result = $gate->filterByReferrer(5); //foreach ($result as $row) { // echo $row->id . " - " . $row->referrer_id . ' - ' . $row->ip_address . "<br/>"; //} $gate = new VisitsTableGateway($dbAdapter); echo '<h3>Test countryLike</h3>'; $gate = new CountriesTableGateway($dbAdapter); $result = $gate->countryLike('ja'); foreach ($result as $row) { echo $row->CountryName . ' - ' . $row->ISO . "<br/>"; } $gate = new CountriesTableGateway($dbAdapter); echo '<h3>Test countryLike</h3>'; $gate = new BrowserTableGateway($dbAdapter); $result = $gate->visitsByCountryFromContinent(); foreach ($result as $row) { echo $row->Name . $row->Visits . "<br/>"; } // all done close connection $dbAdapter->closeConnection();
function actionData($userData, $actionType, $param, $param2) { require_once 'lib/helpers/visits-setup.inc.php'; $BrowsersToPull = new BrowserTableGateway($dbAdapter); $CountriesToPull = new CountriesTableGateway($dbAdapter); $VisitsToPull = new VisitsTableGateway($dbAdapter); $dataSets = array("Browsers", "Continents", "Countries", "DeviceBrand", "DeviceType", "OperatingSystems", "Referrers", "Visits"); if (in_array($userData, $dataSets)) { switch ($userData) { case "Visits": if ($actionType == "countmonth") { $dataOutput = $VisitsToPull->countByMonth($param); } elseif ($actionType == "countmonthbyday") { $dataOutput = $VisitsToPull->visitsByDayForMonth($param); } elseif ($actionType == "countbycountrycode") { $dataOutput = $VisitsToPull->countByCountryCode($param); } elseif ($actionType == "countbydevicetype") { $dataOutput = $VisitsToPull->countByDeviceType($param); } elseif ($actionType == "countbydevicebrand") { $dataOutput = $VisitsToPull->countByDeviceBrand($param); } elseif ($actionType == "countbybrowser") { $dataOutput = $VisitsToPull->countByBrowser($param); } elseif ($actionType == "countbyreferrer") { $dataOutput = $VisitsToPull->countByReferrer($param); } elseif ($actionType == "countbyos") { $dataOutput = $VisitsToPull->countByOS($param); } elseif ($actionType == "filtervisitsdata") { $dataOutput = $VisitsToPull->filterVisitsData($param, $param2); } elseif ($actionType == "visitsforbarchart") { $dataOutput = $VisitsToPull->visitsForBarChart($param); } else { $dataOutput = null; } echo json_encode($dataOutput); break; case "Countries": if ($actionType == "filterbycontinentcode") { $dataOutput = $CountriesToPull->filterByContinentCode($param); } elseif ($actionType == "countrieslike") { $dataOutput = $CountriesToPull->countryLike($param); } elseif ($actionType == "visitsbycountry") { $dataOutput = $CountriesToPull->visitsByCountry($param); } elseif ($actionType == "fetchcountrynames") { $dataOutput = $CountriesToPull->fetchCountryNames(); } elseif ($actionType == "fetchcountrynamestop10visits") { $dataOutput = $CountriesToPull->fetchCountryNamesTop10Visits(); } elseif ($actionType == "visitsbycountryfromcontinent") { $dataOutput = $CountriesToPull->visitsByCountryFromContinent($param); } else { $dataOutput = "Invalid Input"; } echo json_encode($dataOutput); break; case "Browsers": if ($actionType == "visitsbybrowser") { $dataOutput = $BrowsersToPull->visitsByBrowser(); } else { $dataOutput = "Invalid Input"; } echo json_encode($dataOutput); break; } } }
<?php require_once 'lib/helpers/visits-setup.inc.php'; header('Content-type: application/json'); $gate = new CountriesTableGateway($dbAdapter); $result = $gate->findForAuto(); echo json_encode($result);
<?php require_once 'lib/helpers/visits-setup.inc.php'; header('Content-type: application/json'); $id = $_GET['id']; $gate4 = new CountriesTableGateway($dbAdapter); $result4 = $gate4->findByBrowserContinent($id); //var_dump($result4); echo json_encode($result4); ?>