function showReports($searchInfo = '') { $userId = isLoggedIn(); if (!empty($searchInfo['from_time'])) { $fromTime = strtotime($searchInfo['from_time'] . ' 00:00:00'); } else { $fromTime = mktime(0, 0, 0, date('m'), date('d') - 30, date('Y')); } if (!empty($searchInfo['to_time'])) { $toTime = strtotime($searchInfo['to_time'] . ' 23:59:59'); } else { $toTime = mktime(); } $this->set('fromTime', date('Y-m-d', $fromTime)); $this->set('toTime', date('Y-m-d', $toTime)); $keywordController = new KeywordController(); if (!empty($searchInfo['keyword_id']) && !empty($searchInfo['rep'])) { $searchInfo['keyword_id'] = intval($searchInfo['keyword_id']); $keywordInfo = $keywordController->__getKeywordInfo($searchInfo['keyword_id']); $searchInfo['website_id'] = $keywordInfo['website_id']; } $websiteController = new WebsiteController(); $websiteList = $websiteController->__getAllWebsitesWithActiveKeywords($userId, true); $this->set('websiteList', $websiteList); $websiteId = empty($searchInfo['website_id']) ? $websiteList[0]['id'] : intval($searchInfo['website_id']); $this->set('websiteId', $websiteId); $keywordList = $keywordController->__getAllKeywords($userId, $websiteId, true); $this->set('keywordList', $keywordList); $keywordId = empty($searchInfo['keyword_id']) ? $keywordList[0]['id'] : $searchInfo['keyword_id']; $this->set('keywordId', $keywordId); $seController = new SearchEngineController(); $seList = $seController->__getAllSearchEngines(); $this->set('seList', $seList); $seId = empty($searchInfo['se_id']) ? $seList[0]['id'] : intval($searchInfo['se_id']); $this->set('seId', $seId); $this->set('seInfo', $seController->__getsearchEngineInfo($seId)); $conditions = empty($keywordId) ? "" : " and s.keyword_id={$keywordId}"; $conditions .= empty($seId) ? "" : " and s.searchengine_id={$seId}"; $sql = "select s.*,sd.url,sd.title,sd.description \r\n\t\t\t\t\t\t\t\tfrom searchresults s,searchresultdetails sd \r\n\t\t\t\t\t\t\t\twhere s.id=sd.searchresult_id \r\n\t\t\t\t\t\t\t\tand time>= {$fromTime} and time<={$toTime} {$conditions} \r\n\t\t\t\t\t\t\t\torder by s.time"; $repList = $this->db->select($sql); $reportList = array(); foreach ($repList as $repInfo) { $var = 'se' . $seId . $repInfo['keyword_id'] . $repInfo['time']; if (empty($reportList[$var])) { $reportList[$var] = $repInfo; } else { if ($repInfo['rank'] < $reportList[$var]['rank']) { $reportList[$var] = $repInfo; } } } $prevRank = 0; $i = 0; foreach ($reportList as $key => $repInfo) { $rankDiff = ''; if ($i > 0) { $rankDiff = $prevRank - $repInfo['rank']; if ($rankDiff > 0) { $rankDiff = "<font class='green'>({$rankDiff})</font>"; } elseif ($rankDiff < 0) { $rankDiff = "<font class='red'>({$rankDiff})</font>"; } } $reportList[$key]['rank_diff'] = empty($rankDiff) ? '' : $rankDiff; $prevRank = $repInfo['rank']; $i++; } $this->set('list', array_reverse($reportList, true)); $this->render('report/report'); }