<?php
namespace App\Controller;
use App\Config;
use App\Entity\AffiliateInfo;
use App\Entity\Employees;
use App\Entity\AgentControl;
use App\Entity\OfferInfo;
use App\Entity\NewsletterBuilder;
use App\Entity\OfferGeoRelationship;
use App\Services\AffiliateHasofferAPI;
use App\Services\Alerts;
use App\Services\Aws\ElasticCache;
use App\Services\Aws\S3;
use App\Services\BrandHasofferAPI;
use App\Services\Common;
use App\Services\FinancialToolsComponents;
use App\Services\ImpressionsApis;
use App\Services\Metrics24APICalls;
use App\Services\MmpComponents;
use App\Services\MysqlQueries;
use App\Services\UsersComponents;
use Doctrine\Persistence\ManagerRegistry;
use Mmoreram\GearmanBundle\Service\GearmanClientInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use App\Repository\MafoPublisherMappingWithAffiliateRepository;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use function GuzzleHttp\json_encode;
/**
*
* Offer related routes with endpoint /api/offers/{route}
*
* @Route("/api/client/publisher", name="client_publisher_", host="%publishers_subdomain%")
*/
class ClientSidePublisherController extends AbstractController
{
private $commonCalls;
private $doctrine;
private $mysqlQueries;
private $financialToolsComponents;
private $alerts;
private $brandHasofferApi;
private $mmpComponents;
private $affiliateHasofferAPI;
private $usersComponents;
private $elasticCache;
private $projectDir;
private $s3;
private $impressionsApis;
private $metrics24APICalls;
private $gearmanClientInterface;
private $mappingRepository;
public function __construct(Common $commonCalls, ManagerRegistry $doctrine, MysqlQueries $mysqlQueries, MafoPublisherMappingWithAffiliateRepository $mappingRepository,
FinancialToolsComponents $financialToolsComponents, Alerts $alerts, BrandHasofferApi $brandHasofferApi, MmpComponents $mmpComponents, AffiliateHasofferAPI $affiliateHasofferAPI, UsersComponents $usersComponents, ElasticCache $elasticCache, S3 $s3, ImpressionsApis $impressionsApis, Metrics24APICalls $metrics24APICalls, GearmanClientInterface $gearmanClientInterface, string $projectDir)
{
$this->commonCalls = $commonCalls;
$this->doctrine = $doctrine;
$this->mysqlQueries = $mysqlQueries;
$this->financialToolsComponents = $financialToolsComponents;
$this->alerts = $alerts;
$this->brandHasofferApi = $brandHasofferApi;
$this->mmpComponents = $mmpComponents;
$this->affiliateHasofferAPI = $affiliateHasofferAPI;
$this->usersComponents = $usersComponents;
$this->elasticCache = $elasticCache;
$this->s3 = $s3;
$this->impressionsApis = $impressionsApis;
$this->metrics24APICalls = $metrics24APICalls;
$this->gearmanClientInterface = $gearmanClientInterface;
$this->projectDir = $projectDir;
$this->mappingRepository = $mappingRepository;
}
/**
* @Route("/validate", name="validate", methods={"GET"})
*/
public function getValidateAction(Request $request)
{
return new JsonResponse(true);
}
/**
* @Route("/test", name="test", methods={"GET"})
*/
public function getAgentControlAction(Request $request)
{
return new JsonResponse(true);
}
/**
* @Route("/login", name="login")
*/
public function indexAction(AuthenticationUtils $authenticationUtils)
{
// $authenticationUtils = $authenticationUtils->get('security.authentication_utils');
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('/publisher/login/index.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
]);
}
/**
* @Route("/details", name="get_publisher_details", methods={"GET"})
*/
public function getPublishersDetails(Request $request): Response
{
$publisherInfo = $this->getUser();
$publisherId = $publisherInfo->getId();
$mappedAffiliateIds = $this->mappingRepository->findMappedAffiliateIdsByPublisherId($publisherId);
// Store mappedAffiliateIds in session
// $request->getSession()->set('mappedAffiliateIds', $mappedAffiliateIds);
$publisherData = [
'id' => $publisherInfo->getId(),
'email' => $publisherInfo->getEmail(),
'firstName' => $publisherInfo->getFirstName(),
'lastName' => $publisherInfo->getLastName(),
'status' => $publisherInfo->getStatus(),
'lastLoginAt' => $publisherInfo->getLastLoginAt(),
'dateUpdated' => $publisherInfo->getDateUpdated(),
];
return $this->json($publisherData);
}
/**
* @Route("/report-columns/{report}", name="get_report_columns", methods={"GET"})
*/
public function getReportColumnsAction(Request $request, $report)
{
if ($report === Config::REPORT_ADVERTISER_MACRO) {
$savedCols = Config::REPORT_ADVERTISER_COLUMNS;
$col = [];
foreach ($savedCols as $key => $value) {
$value['accessor'] = str_replace(".", Config::REPORT_ADVERTISER_ACCESSOR_SEPARATOR, $value['accessor']);
$col[] = $value;
}
return new JsonResponse($col);
} elseif (in_array($report, array_keys(Config::TABLE_COLUMNS_WITH_JSON_FILE))) {
return new JsonResponse(array_values($this->commonCalls->getDataFromJsonFile(Config::TABLE_COLUMNS_WITH_JSON_FILE[$report])));
} else {
return new JsonResponse(array_values(Config::REPORT_COLUMN_MAPPING[$report]));
}
}
/**
* @Route("/hyper-statuses", name="get_hyper_statuses", methods={"GET"})
*/
public function getHyperStatusesAction(Request $request)
{
$arr = [];
foreach (array_values(Config::HYPER_STATUS_MAFO_MACROS) as $key => $value) {
$arr[$value] = [
'value' => $value,
'label' => $value,
];
}
return new JsonResponse(array_values($arr));
}
/**
* @Route("/affiliates", name="get_affiliates", methods={"GET"})
*/
public function getAffiliatesAction(Request $request)
{
$publisherInfo = $this->getUser();
$publisherId = $publisherInfo->getId();
$mappedAffiliateIds = $this->mappingRepository->findMappedAffiliateIdsByPublisherId($publisherId);
$keyword = $request->query->get('keyword');
$dataByKeyword = [];
if($keyword) {
$dataByKeyword = $this->doctrine->getRepository(AffiliateInfo::class)->getAffiliateByKeyword($keyword);
}
$statusArr = $request->query->get('status') != '' ? $request->query->get('status') : [Config::ACTIVE_STATUS];
$affiliateData = $this->commonCalls->getPublisherAffiliateListByStatusWithKeys($statusArr, $mappedAffiliateIds);
$affiliateList = [];
foreach ($affiliateData as $key => $value) {
$affiliateList[$value['id']] = [
'value' => $value['id'],
'label' => $value['id'] . ' - ' . $value['name'],
'status' => $value['status']
];
}
foreach($dataByKeyword as $key => $value) {
if(!array_key_exists($value['affiliateId'], $affiliateList)){
$temp = [
'value' => (int)$value['affiliateId'],
'label' => $value['affiliateId'] . ' - ' . $value['company'],
'status' => $value['status']
];
$affiliateList[$value['affiliateId']] = $temp;
}
}
ksort( $affiliateList );
return new JsonResponse(array_values($affiliateList));
}
/**
* @Route("/mafo-users", name="get_mafo_users", methods={"GET"})
*/
public function getAffiliateManagersAction(Request $request)
{
$publisherInfo = $this->getUser();
$publisherId = $publisherInfo->getId();
$affiliateIds = $this->mappingRepository->findMappedAffiliateIdsByPublisherId($publisherId);
// $affiliateIds = $request->getSession()->get('mappedAffiliateIds', []);
$accountManagerIds = $this->doctrine->getRepository(AffiliateInfo::class)->getUniqueAccountManagerIds($affiliateIds);
$employeesInfo = $this->doctrine->getRepository(Employees::class)->getEmployeesByAccountManagerIds($accountManagerIds);
$responseArr = [];
foreach ($employeesInfo as $employeeId => $employee) {
$responseArr[] = [
'value' => $employee['email'] ?? '',
'label' => $employee['fullName'] ?? '',
];
}
usort($responseArr, fn($a, $b) => strcmp($a['label'], $b['label']));
return new JsonResponse($responseArr);
}
private function getAffiliateAndManagerData()
{
$publisherInfo = $this->getUser();
$publisherId = $publisherInfo->getId();
$mappedAffiliateIds = $this->mappingRepository->findMappedAffiliateIdsByPublisherId($publisherId);
$accountManagerIds = $this->doctrine->getRepository(AffiliateInfo::class)->getUniqueAccountManagerIds($mappedAffiliateIds);
// Get employees info by account manager IDs
$employeesInfo = $this->doctrine->getRepository(Employees::class)->getEmployeesByAccountManagerIds($accountManagerIds);
// Convert each affiliate ID to a string for consistency
$mappedAffiliateIds = array_map('strval', $mappedAffiliateIds);
// Extract emails from $employeesInfo for MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS
$affiliateManagerEmails = array_map(function($employee) {
return $employee['email'];
}, $employeesInfo);
// Prepare and return both the formatted array and mappedAffiliateIds
return [
'formattedArray' => [
'MULTISELECT_AFFILIATES' => $mappedAffiliateIds,
// 'MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS' => $affiliateManagerEmails,
],
'formattedTrafficReportArray' => [
'MULTISELECT_MMP_TUNE_AFFILIATES' => $mappedAffiliateIds,
// 'MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS' => $affiliateManagerEmails,
],
'mappedAffiliateIds' => $mappedAffiliateIds,
'accountManagerEmails' => $affiliateManagerEmails,
];
}
/**
* @Route("/financial-report", name="get_financial_report", methods={"GET"})
*/
public function getfinancialReportAction(Request $request)
{
$affiliateData = $this->getAffiliateAndManagerData();
$formattedArray = $affiliateData['formattedArray'];
$mappedAffiliateIds = $affiliateData['mappedAffiliateIds'];
$mappedAccountManagerEmails = $affiliateData['accountManagerEmails'];
$selectedColumns = $request->query->get('data') != '' ? $request->query->get('data') : [];
$filters = $request->query->get('filters');
$excludedFlagForFilters = $request->query->get('excludedFlagForFilters') ?? [];
// Set $filters based on the specified condition
if (is_null($filters) && !empty(array_filter($excludedFlagForFilters))) {
$filters['MULTISELECT_AFFILIATES'] = [];
} else {
$filters = $filters ?? $formattedArray;
}
// Check if MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS is present but MULTISELECT_AFFILIATES is missing
if (isset($filters['MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS']) && !isset($filters['MULTISELECT_AFFILIATES']) && $excludedFlagForFilters['MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS'] !== 'true') {
$filters['MULTISELECT_AFFILIATES'] = $mappedAffiliateIds;
} else if (isset($filters['MULTISELECT_FINANCIAL_TOOLS_HYPER_STATUS']) && !isset($filters['MULTISELECT_AFFILIATES']) && $excludedFlagForFilters['MULTISELECT_FINANCIAL_TOOLS_HYPER_STATUS'] !== 'true') {
$filters['MULTISELECT_AFFILIATES'] = $mappedAffiliateIds;
}
// Check if excludedFlagForFilters contains a true flag for MULTISELECT_AFFILIATES
if (!empty($excludedFlagForFilters['MULTISELECT_AFFILIATES']) && $excludedFlagForFilters['MULTISELECT_AFFILIATES'] === 'true') {
// Calculate the difference between mappedAffiliateIds and filters['MULTISELECT_AFFILIATES']
$filters['MULTISELECT_AFFILIATES'] = array_diff($mappedAffiliateIds, $filters['MULTISELECT_AFFILIATES']);
}
if (
!empty($filters['MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS']) &&
!empty($excludedFlagForFilters['MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS']) &&
$excludedFlagForFilters['MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS'] === 'true'
) {
$filters['MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS'] = array_diff($mappedAccountManagerEmails, $filters['MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS']);
} else if (
empty($filters['MULTISELECT_AFFILIATES']) &&
!empty($excludedFlagForFilters['MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS']) &&
$excludedFlagForFilters['MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS'] === 'true'
) {
$filters['MULTISELECT_AFFILIATES'] = array_diff($mappedAffiliateIds, $filters['MULTISELECT_AFFILIATES']);
}
if (
!empty($filters['MULTISELECT_FINANCIAL_TOOLS_HYPER_STATUS']) &&
!empty($excludedFlagForFilters['MULTISELECT_FINANCIAL_TOOLS_HYPER_STATUS']) &&
$excludedFlagForFilters['MULTISELECT_FINANCIAL_TOOLS_HYPER_STATUS'] === 'true'
) {
$filters['MULTISELECT_AFFILIATES'] = $mappedAffiliateIds;
} else if (
empty($filters['MULTISELECT_AFFILIATES']) &&
!empty($excludedFlagForFilters['MULTISELECT_FINANCIAL_TOOLS_HYPER_STATUS']) &&
$excludedFlagForFilters['MULTISELECT_FINANCIAL_TOOLS_HYPER_STATUS'] === 'true'
) {
$filters['MULTISELECT_AFFILIATES'] = array_diff($mappedAffiliateIds, $filters['MULTISELECT_AFFILIATES']);
}
$limit = $request->query->get('limit') ? $request->query->get('limit') : Config::REPORTS_PAGINATION_DEFAULT_PAGE_SIZE;
$page = $request->query->get('page') ? $request->query->get('page') : Config::REPORTS_PAGINATION_DEFAULT_PAGE_NUMBER;
$sortBy = $request->query->get('sortBy') ?? Config::REPORTS_PAGINATION_DEFAULT_SORT_BY;
$sortType = $request->query->get('sortType') ?? Config::REPORTS_PAGINATION_DEFAULT_SORT_TYPE;
$filtersToProcess = [];
if (isset($filters)) {
foreach ($filters as $key => $value) {
$key === 'MULTISELECT_AFFILIATES' ? $filtersToProcess['affiliateIds'] = $value : false;
$key === 'MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS' ? $filtersToProcess['affiliateManagerEmailArr'] = $value : false;
$key === 'MULTISELECT_FINANCIAL_TOOLS_HYPER_STATUS' ? $filtersToProcess['hyperStatuses'] = $value : false;
}
}
$excludedFlagsToProcess = [];
// if (isset($excludedFlagForFilters)) {
// foreach ($excludedFlagForFilters as $key => $value) {
// $key === 'MULTISELECT_AFFILIATES' ? $excludedFlagsToProcess['excludeAffiliateIds'] = $value : false;
// $key === 'MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS' ? $excludedFlagsToProcess['excludeAffiliateManagerEmailArr'] = $value : false;
// $key === 'MULTISELECT_FINANCIAL_TOOLS_HYPER_STATUS' ? $excludedFlagsToProcess['excludeHyperStatus'] = $value : false;
// }
// }
$dateStart = date('Y-m-d', strtotime($request->query->get('startDate')));
$dateEnd = date('Y-m-d', strtotime($request->query->get('endDate')));
if ($request->query->get('downloadCSV') == 'true') {
$limit = Config::REPORTS_PAGINATION_DEFAULT_CSV_PAGE_SIZE;
$page = Config::REPORTS_PAGINATION_DEFAULT_PAGE_NUMBER;
}
$finalArr = $this->financialToolsComponents->getPayoutTotalAggregatedData($dateStart, $dateEnd, $filtersToProcess, $excludedFlagsToProcess, $selectedColumns, $this->getUser()->getEmail());
$allowedStatuses = array_values(Config::HYPER_STATUS_AFFILIATE_MAFO_MACROS);
foreach ($finalArr as &$record) {
if (!in_array($record['hyperStatus'], $allowedStatuses)) {
$record['hyperStatus'] = '';
}
}
$tableColumns = $this->commonCalls->changeColumnVisibilityForTable(array_values($this->commonCalls->getDataFromJsonFile(Config::JSON_FILE_REPORTS_FINANCIAL_REPORT)), $selectedColumns, []);
if ($request->query->get('downloadCSV') == 'true') {
$this->commonCalls->downloadCSV($tableColumns, $finalArr, 'Financial Report ' . $dateStart . '_' . $dateEnd);
}
return new JsonResponse($this->commonCalls->getReportResponse($finalArr, $tableColumns, $limit, $page, $sortBy, $sortType));
}
/**
* @Route("/traffic-report", methods={"GET"})
*/
public function getTrafficReport(Request $request)
{
ini_set('memory_limit', '512M');
$affiliateData = $this->getAffiliateAndManagerData();
$formattedTrafficReportArray = $affiliateData['formattedTrafficReportArray'];
$mappedAffiliateIds = $affiliateData['mappedAffiliateIds'];
$mappedAccountManagerEmails = $affiliateData['accountManagerEmails'];
$filtersSelected = $request->query->get('filters');
$excludedFlagForFilters = $request->query->get('excludedFlagForFilters') ?? [];
$filters = [];
$excludedFiltersFlags = [];
// Set $filters based on the specified condition
if (is_null($filtersSelected) && !empty(array_filter($excludedFlagForFilters))) {
$filtersSelected['MULTISELECT_MMP_TUNE_AFFILIATES'] = [];
} else {
$filtersSelected = $filtersSelected ?? $formattedTrafficReportArray;
}
// Check if excludedFlagForFilters contains a true flag for MULTISELECT_AFFILIATES
if (!empty($excludedFlagForFilters['MULTISELECT_MMP_TUNE_AFFILIATES']) && $excludedFlagForFilters['MULTISELECT_MMP_TUNE_AFFILIATES'] === 'true') {
// Calculate the difference between mappedAffiliateIds and filters['MULTISELECT_AFFILIATES']
$filtersSelected['MULTISELECT_MMP_TUNE_AFFILIATES'] = array_diff($mappedAffiliateIds, $filtersSelected['MULTISELECT_MMP_TUNE_AFFILIATES']);
}
// Check if MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS is present but MULTISELECT_AFFILIATES is missing
if (isset($filtersSelected['MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS']) && !isset($filters['MULTISELECT_MMP_TUNE_AFFILIATES']) && $excludedFlagForFilters['MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS'] !== 'true') {
$filtersSelected['MULTISELECT_MMP_TUNE_AFFILIATES'] = $mappedAffiliateIds;
} else if (isset($filtersSelected['MULTISELECT_FINANCIAL_TOOLS_HYPER_STATUS']) && !isset($filtersSelected['MULTISELECT_MMP_TUNE_AFFILIATES']) && $excludedFlagForFilters['MULTISELECT_FINANCIAL_TOOLS_HYPER_STATUS'] !== 'true') {
$filtersSelected['MULTISELECT_MMP_TUNE_AFFILIATES'] = $mappedAffiliateIds;
}
if (
!empty($filtersSelected['MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS']) &&
!empty($excludedFlagForFilters['MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS']) &&
$excludedFlagForFilters['MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS'] === 'true'
) {
$filtersSelected['MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS'] = array_diff($mappedAccountManagerEmails, $filtersSelected['MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS']);
// $filtersSelected = $formattedTrafficReportArray;
} else if (
empty($filtersSelected['MULTISELECT_MMP_TUNE_AFFILIATES']) &&
!empty($excludedFlagForFilters['MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS']) &&
$excludedFlagForFilters['MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS'] === 'true'
) {
$filtersSelected['MULTISELECT_MMP_TUNE_AFFILIATES'] = array_diff($mappedAffiliateIds, $filtersSelected['MULTISELECT_MMP_TUNE_AFFILIATES']);
}
if (isset($filtersSelected)) {
foreach ($filtersSelected as $key => $value) {
$key === Config::MULTISELECT_MMP_STATISTICS_APP ? $filters['appIds'] = $value : false;
$key === Config::MULTISELECT_MMP_OFFERS ? $filters['offers'] = $value : false;
$key === Config::MULTISELECT_MMP_SOURCE_GLOBAL_NETWORK_REPORT ? $filters['mmpSource'] = $value : false;
$key === Config::MULTISELECT_MMP_PARTNERS ? $filters['affiliates'] = $value : false;
$key === Config::MULTISELECT_MMP_MAKER_OF_OFFER_RULE_IN_MMP_OFFERS ? $filters['users'] = $value : false;
$key === Config::MULTISELECT_GEO ? $filters['geos'] = $value : false;
$key === Config::MULTISELECT_MMP_TUNE_ADVERTISERS ? $filters['advertiserIds'] = $value : false;
$key === Config::MULTISELECT_MMP_TUNE_AFFILIATES ? $filters['hoAffiliateIds'] = $value : false;
$key === Config::MULTISELECT_MMP_EVENTS ? $filters['events'] = $value : false;
$key === Config::MULTISELECT_MMP_TUNE_OFFERS ? $filters['hoOfferIds'] = $value : false;
$key === Config::MULTISELECT_ADVERTISER_MANAGER_FROM_MAFO_USERS ? $filters['advertiserManagerEmailIds'] = $value : false;
$key === Config::MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS ? $filters['affiliateManagerEmailIds'] = $value : false;
$key === Config::MULTISELECT_ADVERTISER_MOBUPPS_TEAM ? $filters['advertiserMobuppsTeam'] = $value : false;
$key === Config::MULTISELECT_AFFILIATE_MOBUPPS_TEAM ? $filters['affiliateMobuppsTeam'] = $value : false;
$key === Config::MULTISELECT_AFFILIATE_CATEGORIES ? $filters['affiliateCategories'] = $value : false;
$key === Config::MULTISELECT_TUNE_PIDS ? $filters['tunePids'] = $value : false;
$key === Config::MULTISELECT_GLOBAL_REPORT_EXCLUDE_ZERO_VALUES ? $filters['excludeResultsWithZeroValues'] = $value : false;
$key === Config::MULTISELECT_MMP_IS_RETARGETED ? $filters['isRetargeted'] = $value : false;
}
}
if (isset($excludedFlagForFilters)) {
// foreach ($excludedFlagForFilters as $key => $value) {
// $value = (int)$value;
// $key === Config::MULTISELECT_MMP_STATISTICS_APP ? $excludedFiltersFlags['appIds'] = $value : false;
// $key === Config::MULTISELECT_MMP_OFFERS ? $excludedFiltersFlags['offers'] = $value : false;
// $key === Config::MULTISELECT_MMP_SOURCE_GLOBAL_NETWORK_REPORT ? $excludedFiltersFlags['mmpSource'] = $value : false;
// $key === Config::MULTISELECT_MMP_PARTNERS ? $excludedFiltersFlags['affiliates'] = $value : false;
// $key === Config::MULTISELECT_MMP_MAKER_OF_OFFER_RULE_IN_MMP_OFFERS ? $excludedFiltersFlags['users'] = $value : false;
// $key === Config::MULTISELECT_GEO ? $excludedFiltersFlags['geos'] = $value : false;
// $key === Config::MULTISELECT_MMP_TUNE_ADVERTISERS ? $excludedFiltersFlags['advertiserIds'] = $value : false;
// $key === Config::MULTISELECT_MMP_TUNE_AFFILIATES ? $excludedFiltersFlags['hoAffiliateIds'] = $value : false;
// $key === Config::MULTISELECT_MMP_EVENTS ? $excludedFiltersFlags['events'] = $value : false;
// $key === Config::MULTISELECT_MMP_TUNE_OFFERS ? $excludedFiltersFlags['hoOfferIds'] = $value : false;
// $key === Config::MULTISELECT_ADVERTISER_MANAGER_FROM_MAFO_USERS ? $excludedFiltersFlags['advertiserManagerEmailIds'] = $value : false;
// $key === Config::MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS ? $excludedFiltersFlags['affiliateManagerEmailIds'] = $value : false;
// $key === Config::MULTISELECT_ADVERTISER_MOBUPPS_TEAM ? $excludedFiltersFlags['advertiserMobuppsTeam'] = $value : false;
// $key === Config::MULTISELECT_AFFILIATE_MOBUPPS_TEAM ? $excludedFiltersFlags['affiliateMobuppsTeam'] = $value : false;
// $key === Config::MULTISELECT_AFFILIATE_CATEGORIES ? $excludedFiltersFlags['affiliateCategories'] = $value : false;
// $key === Config::MULTISELECT_TUNE_PIDS ? $excludedFiltersFlags['tunePids'] = $value : false;
// $key === Config::MULTISELECT_GLOBAL_REPORT_EXCLUDE_ZERO_VALUES ? $excludedFiltersFlags['excludeResultsWithZeroValues'] = $value : false;
// }
}
$selectedColumns = $request->query->get('data') != '' ? $request->query->get('data') : [];
$groupedColumns = $request->query->get('groups') != '' ? $request->query->get('groups') : [];
$dateStart = date('Y-m-d', strtotime($request->query->get('startDate')));
$dateEnd = date('Y-m-d', strtotime($request->query->get('endDate')));
$eventTimestampFrom = strtotime($dateStart);
$eventTimeStampTo = strtotime($dateEnd);
$sortBy = $request->query->get('sortBy') ?? Config::REPORTS_PAGINATION_MMP_REPORT_DEFAULT_SORT_BY;
$sortType = $request->query->get('sortType') ?? Config::REPORTS_PAGINATION_DEFAULT_SORT_TYPE;
$page = $request->query->get('page') ?? Config::REPORTS_PAGINATION_DEFAULT_PAGE_NUMBER;
$limit = $request->query->get('limit') ?? Config::REPORTS_PAGINATION_DEFAULT_PAGE_SIZE;
$downloadDataAsCSV = $request->query->get('downloadCSV') == 'true';
$ajaxRequestTimeout = $request->query->get('ajaxRequestTimeout') == 1;
$tableColumns = $this->commonCalls->changeColumnVisibilityForTable(
array_values($this->commonCalls->getDataFromJsonFile(Config::JSON_FILE_GLOBAL_NETWORK_REPORT)),
$selectedColumns, []
);
$finalReportData = [];
if ($ajaxRequestTimeout) {
$this->gearmanClientInterface->doBackgroundJob('AppWorkersMmpReportsWorker~generateGlobalReportAndSendMail', json_encode([
'reportParams' => [
$filters,
$excludedFiltersFlags,
$eventTimestampFrom,
$eventTimeStampTo,
$selectedColumns,
$groupedColumns
],
'tableColumns' => $tableColumns,
'sendMailTo' => $this->getUser()->getEmail(),
'dateStart' => $dateStart,
'dateEnd' => $dateEnd,
'requestedAt' => date('Y-m-d H:i:s', strtotime('now'))
]));
return new JsonResponse([
'response' => [
'success' => true,
'httpStatus' => Config::HTTP_STATUS_CODE_OK,
'data' => [
'tableColumns' => $tableColumns,
'data' => [],
'metaData' => [
'total' => 0,
'limit' => (int)$limit,
'page' => (int)$page,
'pages' => 1,
]
],
'error' => null
]
], Config::HTTP_STATUS_CODE_OK);
} elseif (
strtotime(date('m', strtotime($request->query->get('startDate'))))
>= strtotime(date(
'm', strtotime("-" . Config::MMP_REPORTS_TABLE_DATA_MONTH_LIMIT . " months")
))) {
ini_set('mysqlnd.net_read_timeout', '1');
$finalReportData = $this->mmpComponents->getMmpCumulativeData(
$filters,
$excludedFiltersFlags,
$eventTimestampFrom,
$eventTimeStampTo,
$selectedColumns,
$groupedColumns
);
}
$finalReportData = $this->mmpComponents->normalizeMmpSource($finalReportData);
foreach ($tableColumns as $key => $value) {
if (isset($value['aggregate']) && $value['aggregate'] == 'sum') {
$num = round(array_sum(array_column($finalReportData, $value['accessor'])), 2);
if ($value['category'] == 'statistics') {
$tableColumns[$key]['Footer'] = number_format($num);
} else {
$tableColumns[$key]['Footer'] = number_format($num, 2);
}
}
}
if ($downloadDataAsCSV) {
$this->commonCalls->downloadCSV($tableColumns, $finalReportData, 'Traffic Report ' . $dateStart . '_' . $dateEnd);
} else {
$finalReportData = array_values($finalReportData);
if (sizeof($finalReportData)) {
$entity = $finalReportData[0];
if (array_key_exists($sortBy, $entity)) {
$sortFlag = 3;
if ($sortType == Config::SORT_TYPE_ASC) {
$sortFlag = 4;
}
array_multisort(array_column($finalReportData, $sortBy), $sortFlag, $finalReportData);
}
}
$offset = $limit * ($page - 1);
$totalRecordCount = sizeof($finalReportData);
$noOfPages = ceil($totalRecordCount / $limit);
return new JsonResponse([
'response' => [
'success' => true,
'httpStatus' => Config::HTTP_STATUS_CODE_OK,
'data' => [
'tableColumns' => $tableColumns,
'data' => array_slice($finalReportData, $offset, $limit),
'metaData' => [
'total' => $totalRecordCount,
'limit' => (int)$limit,
'page' => (int)$page,
'pages' => (int)$noOfPages,
]
],
'error' => null
]
], Config::HTTP_STATUS_CODE_OK);
}
}
}