require_once("feedActivityList.class.php"); FeedActivityList::MoveFeedsToDB(); ?>
if(empty($_REQUEST['fromDate']) && empty($_REQUEST['toDate'])) { header("Location:UserActivityDetails.php?metroId=1&fromDate=2015-01-01&toDate=".date('Y-m-d')."&submit=GO"); die(); } if(isset($_REQUEST['submit']) && $_REQUEST['submit'] == 'GO') { Get(); } if(isset($_REQUEST['submit']) && $_REQUEST['submit'] == 'EXPORT') { Get(); $fileName = "UserActivityDetails_".date("d-m-Y").".csv"; ob_clean(); header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="'.$fileName.'"'); $file = fopen('php://output', 'w'); $header1[] = 'Date'; $header2[] = ''; $total[] = 'Total'; foreach($activities as $activityRow) { $header1[] = ''; $header1[] = $activityRow["Activity"]; $header1[] = ''; $header2[] = 'Activities'; $header2[] = 'Users'; $header2[] = $targetNames[$activityRow["Activity"]]; $total[] = $totalActivities[$activityRow["Activity"]."_activity"]; $total[] = $totalActivities[$activityRow["Activity"]."_users"]; $total[] = $totalActivities[$activityRow["Activity"]."_contents"]; } fputcsv($file,$header1); fputcsv($file,$header2); fputcsv($file,$total); foreach($dayWiseActivities as $dayWiseActivity) { unset($data); $data[] = str_replace(" ", " ", $dayWiseActivity["Date"]); foreach($activities as $activityRow) { $data[] = $dayWiseActivity[$activityRow["Activity"]."_activity"]; $data[] = $dayWiseActivity[$activityRow["Activity"]."_users"]; $data[] = $dayWiseActivity[$activityRow["Activity"]."_contents"]; } fputcsv($file,$data); } fputcsv($file,$total); fclose($file); ob_flush(); exit; } function Get() { $contentIDs = array( "became_follower"=>"FollowedUserID", "been_here"=>"EstID", "checkin"=>"EstID", "follower_added"=>"FollowerUserID", "want_to_try"=>"EstID", "photo_upload"=>"EstID", "reviews"=>"EstID" ); $targetNames = array( "became_follower"=>"Following", "been_here"=>"Establishments", "checkin"=>"Establishments", "dislike_dish"=>"Dishes", "dislike_review"=>"Reviews", "dislike_tip"=>"Tips", "follower_added"=>"Followers", "like_dish"=>"Dishes", "like_photo"=>"Photos", "like_review"=>"Reviews", "like_tip"=>"Tips", "photo_upload"=>"Establishments", "reviews"=>"Establishments", "want_to_try"=>"Establishments" ); global $fromDate,$toDate,$activities,$dayWiseActivities,$targetNames,$totalActivities; $fromDate = isset($_REQUEST["fromDate"])?$_REQUEST["fromDate"]:"2015-01-01"; $toDate = isset($_REQUEST["toDate"])?$_REQUEST["toDate"]:date("Y-m-d"); ; $dbh=new PDO('mysql:host=172.18.8.111;dbname=burrp_sw;charset=utf8', 'burrp_rw', 'Js2g0DwhlqUoIWm', array( PDO::ATTR_PERSISTENT => false)); $stmtActivities = $dbh->prepare("SELECT DISTINCT Activity FROM TempFeedActivityList order by Activity"); $stmtActivities->execute(); $activities = $stmtActivities->fetchAll(); $query = "SELECT "; foreach($activities as $activityRow) { if(!isset($targetNames[$activityRow["Activity"]])) $targetNames[$activityRow["Activity"]] = "Targets"; $activity = str_replace("reviews", $activityRow["Activity"], " SUM(T.Activity = 'reviews') reviews_activity, count(distinct case when T.Activity = 'reviews' THEN T.UserID ELSE NULL END) reviews_users, count(distinct case when T.Activity = 'reviews' THEN NULLIF(T.ContentID, '') ELSE NULL END) reviews_contents,"); if(isset($contentIDs[$activityRow["Activity"]])) $activity = str_replace("ContentID", $contentIDs[$activityRow["Activity"]], $activity); $query .= $activity; } $query .= " 1 AS Filler FROM TempFeedActivityList T WHERE T.InsertDate >= '".$fromDate."' AND T.InsertDate < DATE_ADD('".$toDate."', INTERVAL 1 DAY)"; $stmtTotalActivities =$dbh->prepare($query); $stmtTotalActivities->execute(); $totalActivities = $stmtTotalActivities->fetchAll(); $totalActivities = $totalActivities[0]; $query = "SELECT DATE_FORMAT(DATE(InsertDate), '%a, %d-%b-%Y') `Date`, "; foreach($activities as $activityRow) { $activity = str_replace("reviews", $activityRow["Activity"], " SUM(T.Activity = 'reviews') reviews_activity, count(distinct case when T.Activity = 'reviews' THEN T.UserID ELSE NULL END) reviews_users, count(distinct case when T.Activity = 'reviews' THEN NULLIF(T.ContentID, '') ELSE NULL END) reviews_contents,"); if(isset($contentIDs[$activityRow["Activity"]])) $activity = str_replace("ContentID", $contentIDs[$activityRow["Activity"]], $activity); $query .= $activity; } $query .= " 1 AS Filler FROM TempFeedActivityList T WHERE T.InsertDate >= '".$fromDate."' AND T.InsertDate < DATE_ADD('".$toDate."', INTERVAL 1 DAY) GROUP BY DATE(InsertDate) ORDER BY DATE(InsertDate) DESC"; $stmtDayWiseActivities =$dbh->prepare($query); $stmtDayWiseActivities->execute(); $dayWiseActivities = $stmtDayWiseActivities->fetchAll(); } ?>Date | foreach($activities as $activityRow) { ?>} ?> | ||
Activities | Users | } ?> | |
Total | foreach($activities as $activityRow) { ?>} ?> | ||
foreach($activities as $activityRow) { ?> | } ?> | ||
Total | foreach($activities as $activityRow) { ?>} ?> |