} 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"); }
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; } } }