$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"] != "") { $brandId = $_GET["brandId"]; $brand = $brandsGateway->findById($brandId); $brandResults = array($brand->name => $visitsGateway->countByDeviceBrand($brandId));
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; } } }