function launch() { global $interface; global $analytics; //Setup filters $this->setupFilters(); $topSearches = $analytics->getTopSearches(true); $interface->assign('topSearches', $topSearches); $session = $analytics->getSessionFilters(); $search = new Analytics_Search(); $search->selectAdd(); $search->selectAdd("count(analytics_search.id) as numSearches"); $search->selectAdd("lookfor"); if ($session != null) { $search->joinAdd($session); } $search->whereAdd("numResults = 0"); $search->groupBy('lookfor'); $search->orderBy('numSearches DESC'); $search->limit(0, 20); $search->find(); $topNoHitSearches = array(); while ($search->fetch()) { if (!is_null($search->lookfor) || strlen(trim($search->lookfor)) > 0) { $topNoHitSearches[] = "{$search->lookfor} ({$search->numSearches})"; } else { $topNoHitSearches[] = "<blank> ({$search->numSearches})"; } } $interface->assign('topNoHitSearches', $topNoHitSearches); $search = new Analytics_Search(); $search->selectAdd(); $search->selectAdd("lookfor"); $search->selectAdd("MAX(searchTime) as lastSearch "); if ($session != null) { $search->joinAdd($session); } $search->groupBy('lookfor'); $search->orderBy('lastSearch DESC'); $search->limit(0, 20); $search->find(); $latestSearches = array(); while ($search->fetch()) { if (!is_null($search->lookfor) || strlen(trim($search->lookfor)) > 0) { $latestSearches[] = "{$search->lookfor} {$search->searchTime}"; } else { $latestSearches[] = "<blank>"; } } $interface->assign('latestSearches', $latestSearches); $search = new Analytics_Search(); $search->selectAdd(); $search->selectAdd("lookfor"); $search->selectAdd("MAX(searchTime) as lastSearch "); if ($session != null) { $search->joinAdd($session); } $search->whereAdd("numResults = 0"); $search->groupBy('lookfor'); $search->orderBy('lastSearch DESC'); $search->limit(0, 20); $search->find(); $latestNoHitSearches = array(); while ($search->fetch()) { if (!is_null($search->lookfor) || strlen(trim($search->lookfor)) > 0) { $latestNoHitSearches[] = "{$search->lookfor} {$search->searchTime}"; } else { $latestNoHitSearches[] = "<blank>"; } } $interface->assign('latestNoHitSearches', $latestNoHitSearches); $interface->setPageTitle('Report - Searches'); $interface->setTemplate('searches.tpl'); $interface->display('layout.tpl'); }
function getTopSearches($forGraph) { $search = new Analytics_Search(); $search->selectAdd(); $search->selectAdd("count(analytics_search.id) as numSearches"); $search->selectAdd("lookfor"); $session = $this->getSessionFilters(); if ($session != null) { $search->joinAdd($session); } $search->addDateFilters(); $search->whereAdd("numResults > 0"); $search->groupBy('lookfor'); $search->orderBy('numSearches DESC'); if ($forGraph) { $search->limit(0, 20); } else { $search->limit(0, 50); } $search->find(); $topSearches = array(); while ($search->fetch()) { if (!is_null($search->lookfor) && strlen(trim($search->lookfor)) > 0) { $searchTerm = $search->lookfor; } else { $searchTerm = "<blank>"; } if ($forGraph) { $topSearches[] = "{$searchTerm} ({$search->numSearches})"; } else { $topSearches[] = array($searchTerm, $search->numSearches); } } return $topSearches; }