<?php
namespace App\Controller;
use App\Config;
use App\Entity\Tune\AdvertiserAccountManager;
use App\Entity\Tune\AffiliateAccountManager;
use App\Entity\Tune\AffiliateInfo;
use App\Entity\AffiliateTags;
use App\Entity\AlertLogs;
use App\Entity\MafoId\MafoAdvertisers;
use App\Entity\MafoId\MafoAffiliates;
use App\Entity\MafoId\MafoOffers;
use App\Entity\PublisherCabinet\MafoPublisherCabinetManager;
use App\Entity\SavedReport;
use App\Entity\RecommendationsByObject;
use App\Services\AffiliateHasofferAPI;
use App\Services\Alerts;
use App\Entity\MmpOffers;
use App\Entity\MmpReports;
use App\Entity\Tune\OfferInfo;
use App\Entity\AppInfo;
use App\Entity\Tune\AdvertiserInfo;
use App\Entity\MafoId\MafoAffiliateMmpPartnerMapping;
use App\Entity\MafoId\MafoOffersMapping;
use App\Entity\SkadNetworkPostbackLogs;
use App\Entity\SourceTags;
use App\Entity\Tag;
use App\Entity\Users;
use App\Entity\UsersHierarchy;
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\HyperApis;
use App\Services\ImpressionsApis;
use App\Services\MachineLearning;
use App\Services\Metrics24APICalls;
use App\Services\MmpComponents;
use App\Services\MysqlQueries;
use App\Services\UsersComponents;
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\Persistence\ManagerRegistry;
use Mmoreram\GearmanBundle\Service\GearmanClientInterface;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\SwitchUserToken;
use Symfony\Component\Security\Core\Security;
/**
*
* Utilities and common routes which are used throughout the project with endpoint /api/utilities/{route}
*
* @Route("/api/utilities", name="aff", host="%main_subdomain%")
*/
class UtilitiesController extends AbstractController
{
private $commonCalls;
private $doctrine;
private $usersComponents;
private $s3;
private $mongoDbDoctrine;
private $security;
private $machineLearning;
private HyperApis $hyperApis;
public function __construct(Common $commonCalls, ManagerRegistry $doctrine, UsersComponents $usersComponents, S3 $s3, DocumentManager $mongoDbDoctrine, Security $security, MachineLearning $machineLearning, HyperApis $hyperApis)
{
$this->commonCalls = $commonCalls;
$this->doctrine = $doctrine;
$this->usersComponents = $usersComponents;
$this->s3 = $s3;
$this->mongoDbDoctrine = $mongoDbDoctrine;
$this->machineLearning = $machineLearning;
$this->security = $security;
$this->hyperApis = $hyperApis;
}
/**
* @Route("/aff-offer-cap-type", name="affiliate_offer_cap_type", methods={"GET"})
*/
public function getAffiliateOfferCapTypeAction(Request $request)
{
$affOfferCapType = [];
foreach (Config::AFFILIATE_OFFER_CAP_TYPE as $key => $value) {
$affOfferCapType[] = [
'value' => $value,
'label' => ucwords(str_replace("_", " ", $value))
];
}
return new JsonResponse($affOfferCapType);
}
/**
* @Route("/adv-managers", name="get_adv_managers", methods={"GET"})
*/
public function getAdvertiserManagersAction(Request $request)
{
$tuneAccount = $request->query->get('tuneAccount');
$advertiserManagers = [];
$data = $this->doctrine->getRepository(AdvertiserAccountManager::class)->getAccountManagerData($tuneAccount !== null ? $tuneAccount : null);
foreach ($data as $key => $value) {
$advertiserManagers[$value['employeeId']] = [
'value' => $value['employeeId'],
'label' => $value['firstName'] . ' ' . $value['lastName']
];
}
return new JsonResponse(array_values($advertiserManagers));
}
/**
* @Route("/aff-managers", name="get_aff_managers", methods={"GET"})
*/
public function getAffiliateManagersAction(Request $request)
{
$affiliateManagers = [];
$dataAffiliateAccountManagers = $this->doctrine->getRepository(AffiliateAccountManager::class)->getAffiliateAccountManagerData();
$data = [];
foreach ($dataAffiliateAccountManagers as $key => $value) {
$tuneAccount = Config::MAFO_SYSTEM_IDENTIFIER_PRETTY[$value['tuneAccount']] ?? "";
$data[$tuneAccount]['label'] = strtoupper($tuneAccount) . ' ACCOUNT MANAGERS';
$data[$tuneAccount]['options'][$value['employeeId']] = [
'value' => $value['employeeId'],
'label' => $value['firstName'] . ' ' . $value['lastName'],
'tuneAccount' => $tuneAccount,
'tuneAccountRaw' => $value['tuneAccount'],
'color' => Config::MAFO_SYSTEM_IDENTIFIER_TUNE_ACCOUNTS_COLORS[$tuneAccount] ?? "#000"
];
ksort($data[$tuneAccount]['options']);
}
$finalArr = [];
foreach ($data as $key => $value) {
$finalArr[] = [
'label' => $value['label'],
'options' => array_values($value['options']),
];
}
return new JsonResponse(array_values($finalArr));
}
/**
* @Route("/source-tags-list", name="get_source_tags_list", methods={"GET"})
*/
public function getSourceTagListAction()
{
$sourceTagsData = $this->doctrine->getRepository(SourceTags::class)->getSourceTagsByIsDeleted(0);
$uniqueSourceTagNames = [];
foreach ($sourceTagsData as $key => $value) {
if (!in_array($value['tagName'], $uniqueSourceTagNames)) {
array_push($uniqueSourceTagNames, $value['tagName']);
}
}
$multiselectList = [];
foreach ($uniqueSourceTagNames as $tagName) {
$multiselectList[] = [
'value' => $tagName,
'label' => $tagName
];
}
return new JsonResponse($multiselectList);
}
/**
* @Route("/affiliate-tags-list", name="get_affiliate_tags_list", methods={"GET"})
*/
public function getAffiliateTagListAction()
{
$affiliateTagsData = $this->doctrine->getRepository(AffiliateTags::class)->getAffiliateTagsByIsDeleted(0);
$uniqueAffiliateTagNames = [];
foreach ($affiliateTagsData as $key => $value) {
if (!in_array($value['tagName'], $uniqueAffiliateTagNames)) {
array_push($uniqueAffiliateTagNames, $value['tagName']);
}
}
$multiselectList = [];
foreach ($uniqueAffiliateTagNames as $tagName) {
$multiselectList[] = [
'value' => $tagName,
'label' => $tagName
];
}
return new JsonResponse($multiselectList);
}
/**
* @Route("/cr-optimisation-cr-relationship-types", name="get_cr_optimisation_cr_relationship_types", methods={"GET"})
*/
public function getCrOptimisationCrRelationshipTypesAction()
{
$crOptimisationCrRelationshipType = Config::CR_OPTIMISATION_CR_RELATIONSHIP_TYPE;
$multiselectList = [];
foreach ($crOptimisationCrRelationshipType as $tagName) {
$multiselectList[] = [
'value' => $tagName,
'label' => ucwords(str_replace("_", " ", $tagName))
];
}
return new JsonResponse($multiselectList);
}
/**
* @Route("/goal-id-optimisation-comparison-macros", name="get_goal_id_optimisation_comparison_macros", methods={"GET"})
*/
public function getGoalIdOptimisationComparisonMacrosAction()
{
$multiselectList = [];
foreach (Config::GOAL_ID_OPTIMISATION_OPERATOR_COMPARISON_MACROS as $tagName) {
$multiselectList[] = [
'value' => $tagName,
'label' => strtoupper(str_replace("_", " ", $tagName))
];
}
return new JsonResponse($multiselectList);
}
/**
* @Route("/goal-id-optimisation-rule-time-period", name="get_goal_id_optimisation_rule_time_period", methods={"GET"})
*/
public function getGoalIdOptimisationRuleTimePeriodAction()
{
$multiselectList = [];
foreach (Config::GOAL_ID_OPTIMISATION_RULE_TIME_PERIOD as $tagName) {
$multiselectList[] = [
'value' => $tagName,
'label' => strtoupper(str_replace("_", " ", $tagName))
];
}
return new JsonResponse($multiselectList);
}
/**
* @Route("/offer-category", name="get_offer_category", methods={"GET"})
*/
public function getAllOfferCategoriesByStatus(Request $request)
{
$tuneAccount = $request->query->get('tuneAccount') ?? Config::MAFO_SYSTEM_IDENTIFIER_TUNE_MOBILE;
$offerCategoriesData = $this->commonCalls->getOfferCategoriesListByStatusWithKeys($tuneAccount);
$categoryList = [];
foreach ($offerCategoriesData as $key => $value) {
$categoryList[$key] = [
'label' => ucwords($value['name']),
'value' => $value['id']
];
}
ksort($categoryList);
return new JsonResponse(array_values($categoryList));
}
/**
* @Route("/countries", name="get_countries", methods={"GET"})
*/
public function getCountriesAction()
{
$countryList = [];
foreach (Config::COUNTRIES as $key => $value) {
$countryList[$key] = [
'value' => $key,
'label' => $key . ' - ' . $value['name']
];
}
ksort($countryList);
return new JsonResponse(array_values($countryList));
}
/**
* @Route("/currencies", name="get_currencies", methods={"GET"})
*/
public function getCurrenciesAction()
{
$currencyList = [];
foreach (Config::CURRENCIES as $key => $value) {
$currencyList[$key] = [
'value' => $key,
'label' => $key . ' - ' . $value
];
}
ksort($currencyList);
return new JsonResponse(array_values($currencyList));
}
/**
* @Route("/tag", name="get_tag", methods={"GET"})
*/
public function getTagAction()
{
$tagsInDb = $this->doctrine->getRepository(Tag::class)->getTags(1, 1, null, null);
$tagList = [];
foreach ($tagsInDb as $key => $value) {
$tagList[] = [
'value' => $value['tagId'],
'label' => $value['name']
];
}
ksort($tagList);
return new JsonResponse(array_values($tagList));
}
/**
* @Route("/advertiser-tags", name="get_advertiser_tags", methods={"GET"})
*/
public function getAdvertiserTAgsAction(Request $request)
{
$tuneAccount = $request->query->get('tuneAccount');
$tagsInDb = $this->doctrine->getRepository(Tag::class)->getTags(1, null, 1, null, $tuneAccount);
$tagList = [];
foreach ($tagsInDb as $key => $value) {
$tagList[] = [
'value' => $value['tagId'],
'label' => $value['name']
];
}
ksort($tagList);
return new JsonResponse(array_values($tagList));
}
/**
* @Route("/offer-tags", name="get_offer_tags", methods={"GET"})
*/
public function getOfferTagsAction()
{
$tagsInDb = $this->doctrine->getRepository(Tag::class)->getTags(1, 1, null, null);
$tagList = [];
foreach ($tagsInDb as $key => $value) {
$tagList[] = [
'value' => $value['tagId'],
'label' => $value['name']
];
}
ksort($tagList);
return new JsonResponse(array_values($tagList));
}
/**
* @Route("/affiliate-tags", name="get_affiliate_ho_tags", methods={"GET"})
*/
public function getAffiliateHoTagsAction(Request $request)
{
$tagsInDb = $this->doctrine->getRepository(Tag::class)->getTags(1, null, null, 1, null);
$data = [];
foreach ($tagsInDb as $key => $value) {
$tuneAccount = Config::MAFO_SYSTEM_IDENTIFIER_PRETTY[$value['tuneAccount']] ?? "";
$data[$tuneAccount]['label'] = strtoupper($tuneAccount) . ' ACCOUNT TAGS';
$data[$tuneAccount]['options'][$value['tagId']] = [
'value' => $value['tagId'],
'label' => $value['name'],
'tuneAccount' => $tuneAccount,
'tuneAccountRaw' => $value['tuneAccount'],
'color' => Config::MAFO_SYSTEM_IDENTIFIER_TUNE_ACCOUNTS_COLORS[$value['tuneAccount']] ?? "#000"
];
ksort($data[$tuneAccount]['options']);
}
$finalArr = [];
foreach ($data as $key => $value) {
$finalArr[] = [
'label' => $value['label'],
'options' => array_values($value['options']),
];
}
return new JsonResponse(array_values($finalArr));
}
/**
* @Route("/app-ids", name="get_app_ids", methods={"GET"})
*/
public function getAppIdsAction()
{
$appIds = $this->doctrine->getRepository(AppInfo::class)->getAppIds();
$appList = [
[
'value' => 'Not Found',
'label' => 'Not Found'
]
];
foreach ($appIds as $key => $value) {
$appList[$value['appId']] = [
'value' => $value['appId'],
'label' => $value['title']
];
}
return new JsonResponse(array_values($appList));
}
/**
* @Route("/offer-blocked-from-list", name="get_offer_blocked_from_list", methods={"GET"})
*/
public function getOfferBlockedFromList()
{
$offerBlockedFromList = [];
foreach (Config::OFFER_AFFILIATE_BLOCK_FROM_LIST as $key => $value) {
$offerBlockedFromList[] = [
'value' => $key,
'label' => $value
];
}
return new JsonResponse($offerBlockedFromList);
}
/**
* @Route("/approval-control-approval-types", name="get_approval_control_approval_types", methods={"GET"})
*/
public function getApprovalControlApprovalTypeAction()
{
$approvalTypes = [];
foreach (Config::APPROVAL_CONTROL_APPROVAL_TYPE as $key => $value) {
$approvalTypes[] = [
'value' => $key,
'label' => $value
];
}
return new JsonResponse($approvalTypes);
}
/**
* @Route("/affiliate-offer-block-types", name="get_affiliate_offer_block_types", methods={"GET"})
*/
public function getAffiliateOfferBlockTypesAction()
{
$blockTypes = [
[
'value' => Config::AFFILIATE_OFFER_BLOCK_MACRO,
'label' => ucfirst(Config::AFFILIATE_OFFER_BLOCK_MACRO),
],
[
'value' => Config::AFFILIATE_OFFER_UNBLOCK_MACRO,
'label' => ucfirst(Config::AFFILIATE_OFFER_UNBLOCK_MACRO),
]
];
return new JsonResponse($blockTypes);
}
/**
* @Route("/platform-types", name="get_platform_types", methods={"GET"})
*/
public function getPlatformTypesAction()
{
$platformTypes = [
[
'value' => Config::PLATFORM_IOS,
'label' => strtoupper(Config::PLATFORM_IOS)
],
[
'value' => Config::PLATFORM_ANDROID,
'label' => strtoupper(Config::PLATFORM_ANDROID)
]
];
return new JsonResponse($platformTypes);
}
/**
* @Route("/mmp-tracking-system", name="get_mmp_tracking_system", methods={"GET"})
*/
public function getMmpTrackingSystemAction()
{
$mmpTrackingSystem = [];
foreach (Config::MMP_TRACKING_SYSTEM_PRETTY as $key => $value) {
$mmpTrackingSystem[] = [
'value' => $key,
'label' => $value
];
}
return new JsonResponse($mmpTrackingSystem);
}
/**
* @Route("/mmp-tracking-system-global-network-report", name="get_mmp-tracking-system-global-network-report", methods={"GET"})
*/
public function getMmpTrackingSystemForGlobalNetworkReportAction(Request $request)
{
$mmpTrackingSystem = [];
foreach (Config::MMP_TRACKING_SYSTEM_GLOBAL_NETWORK_REPORT_PRETTY as $key => $value) {
$mmpTrackingSystem[] = [
'value' => $key,
'label' => $value
];
}
return new JsonResponse($mmpTrackingSystem);
}
/**
* @Route("/app-info/{appId}", name="get_app_info", methods={"GET"})
*/
public function geAppInfoAction(Request $request, $appId)
{
$appInfoData = $this->doctrine->getRepository(AppInfo::class)->getDataByAppIds([$appId]);
$appInfo = [];
foreach ($appInfoData as $key => $value) {
$appInfo[$value['appId']] = $value;
}
return new JsonResponse($appInfo);
}
/**
* @Route("/tag-attributes/{attributeType}", name="get_tag_attributes", methods={"GET"})
*/
public function getOperatingSystemAction(Request $request, $attributeType)
{
$tuneAccount = $request->query->get('tuneAccount');
$attributes = [];
if (array_key_exists($attributeType, Config::TAG_ATTRIBUTES)) {
$attributeData = $this->doctrine->getRepository(Tag::class)->getTagsByAttribute(Config::TAG_ATTRIBUTES[$attributeType], $tuneAccount);
foreach ($attributeData as $key => $value) {
$attributes[] = [
'value' => (string)$value['tagId'],
'label' => $value['name']
];
}
}
return new JsonResponse($attributes);
}
/**
* @Route("/timezones", name="get_timezone", methods={"GET"})
*/
public function getTimezonesAction(Request $request)
{
$timezones = [];
foreach (Config::TIMEZONES as $key => $value) {
$timezones[] = [
'value' => $key,
'label' => $value
];
}
return new JsonResponse($timezones);
}
/**
* @Route("/advertisers", name="get_advertisers", methods={"GET"})
*/
public function getAdvertisersAction(Request $request)
{
$keyword = $request->query->get('keyword');
$tuneAccount = $request->query->get('tuneAccount') ?? Config::MAFO_SYSTEM_IDENTIFIER_TUNE_MOBILE;
$dataByKeyword = $this->doctrine->getRepository(AdvertiserInfo::class)->getAdvertiserByKeyword($keyword, $tuneAccount);
$arr = [];
foreach ($dataByKeyword as $key => $value) {
$temp = [
'value' => (int)$value['advertiserId'],
'label' => $value['advertiserId'] . ' - ' . $value['company'],
'status' => $value['status']
];
$arr[$value['advertiserId']] = $temp;
}
ksort($arr);
return new JsonResponse(array_values($arr));
}
/**
* @Route("/cohorttype", name="get_cohorttype", methods={"GET"})
*/
public function getCohortTypeAction(Request $request)
{
$temp = [
[
'value' => 'cohort_user_acquisition_agency',
'label' => 'User acquisition',
],
[
'value' => 'cohort_retargeting_agency',
'label' => 'Retargeting',
],
[
'value' => 'cohort_unified_agency',
'label' => 'Unified',
],
];
$arr = [];
foreach ($temp as $item) {
$arr[$item['label']] = [
'value' => $item['value'],
'label' => $item['label'],
];
}
ksort($arr);
return new JsonResponse(array_values($arr));
}
/**
* @Route("/affiliates", name="get_affiliates", methods={"GET"})
*/
public
function getAffiliatesAction(Request $request)
{
$keyword = $request->query->get('keyword');
$tuneAccount = $request->query->get('tuneAccount') ?? Config::MAFO_SYSTEM_IDENTIFIER_TUNE_MOBILE;
$dataByKeyword = $this->doctrine->getRepository(AffiliateInfo::class)->getAffiliateByKeyword($keyword, $tuneAccount);
$arr = [];
foreach ($dataByKeyword as $key => $value) {
$temp = [
'value' => (int)$value['affiliateId'],
'label' => $value['affiliateId'] . ' - ' . $value['company'],
'status' => $value['status']
];
$arr[$value['affiliateId']] = $temp;
}
ksort($arr);
return new JsonResponse(array_values($arr));
}
/**
* @Route("/user", name="get_user", methods={"GET"})
*/
public
function getUerAction(Request $request, TokenStorageInterface $tokenStorage)
{
$roles = $this->getUser()->getRoles();
// if (is_array($this->getUser()->getRoles()) && in_array(Config::ROLE_DIRECTOR, $this->getUser()->getRoles())) {
// $roles = array_values(array_unique(array_merge( $this->getUser()->getRoles(), [Config::ROLE_ADMIN])));
// }
$token = $this->security->getToken();
$loggedAsImpersonator = false;
if ($token instanceof SwitchUserToken) {
$loggedAsImpersonator = true;
}
$userData = [
'name' => $this->getUser()->getName(),
'email' => $this->getUser()->getEmail(),
'roles' => $roles,
'isAdmin' => $this->isGranted(Config::ROLE_ADMIN),
'profilePicture' => $this->getUser()->getPicture(),
'env' => $this->getParameter('kernel.environment'),
'isLoggedIntoMts' => true,
'token' => $this->getUser()->getJwtToken()
];
if ($loggedAsImpersonator) {
$userData['loggedInAsImpersonator'] = true;
}
return new JsonResponse($userData);
}
/**
* @Route("/offers-by-advertiser/{advertiserId}", name="get_offers_by_advertiser_id", methods={"GET"})
*/
public
function getOffersByAdvertiserAction(Request $request, $advertiserId)
{
$offers = [];
$status = $request->query->get('status') != '' ? $request->query->get('status') : [Config::ACTIVE_STATUS];
$tuneAccount = $request->query->get('tuneAccount') != '' ? $request->query->get('tuneAccount') : [Config::TUNE_DEFAULT_ACCOUNT_LABEL];
$search = $request->query->get('search', '');
$offersByAdvertiser = $this->doctrine->getRepository(OfferInfo::class)->getOfferIdsByAdvertiserIdAndStatusArr($advertiserId, $status, $tuneAccount, $search);
foreach ($offersByAdvertiser as $key => $value) {
$offers[] = [
'value' => $value['offerId'],
'label' => $value['offerId'] . ' - ' . $value['name']
];
}
return new JsonResponse($offers);
}
/**
* @Route("/mafo-offers-by-advertiser/{advertiserId}", name="get_mafo_offers_by_advertiser_id", methods={"GET"})
*/
public
function getMafoOffersByAdvertiserAction(Request $request, $advertiserId)
{
$offers = [];
$status = $request->query->all('status') != '' ? [] : [Config::ACTIVE_STATUS];
$search = $request->query->get('search', '');
$offersByAdvertiser = $this->doctrine->getRepository(MafoOffers::class)->getOfferIdsByAdvertiserIdAndStatusArr($advertiserId, $status, $search);
foreach ($offersByAdvertiser as $key => $value) {
$offers[$value['systemIdentifier']]['label'] = strtoupper($value['systemIdentifier']) . ' ACCOUNT OFFERS';
$offers[$value['systemIdentifier']]['options'][$value['id']] = [
'value' => $value['id'],
'label' => $value['id'] . ' - ' . $value['name'] . ' [' . $value['systemIdentifierId'] . ']',
'systemIdentifier' => $value['systemIdentifier'],
'systemIdentifierId' => $value['systemIdentifierId'],
];
ksort($offers[$value['systemIdentifier']]['options']);
}
$finalArr = [];
foreach ($offers as $key => $value) {
$finalArr[] = [
'label' => $value['label'],
'options' => array_values($value['options']),
];
}
return new JsonResponse($finalArr);
}
/**
* @Route("/deduction-control-activity-source", name="get_deduction_control_activity_source", methods={"GET"})
*/
public
function getDeductionControlActivitySourceAction(Request $request)
{
$arr = [];
foreach (Config::DEDUCTION_CONTROL_ACTIVITY_SOURCE_ARRAY as $activitySource) {
$arr[] = [
'value' => $activitySource,
'label' => $activitySource
];
}
return new JsonResponse($arr);
}
/**
* @Route("/deduction-control-status", name="get_deduction_control_status", methods={"GET"})
*/
public
function getDeductionControlStatusAction(Request $request)
{
$arr = [];
foreach (Config::DEDUCTION_CONTROL_STATUS as $status) {
$arr[] = [
'value' => $status,
'label' => ucfirst($status)
];
}
return new JsonResponse($arr);
}
/**
* @Route("/file-download", name="get_file_download", methods={"GET"})
*/
public
function getFileDownloadAction(Request $request)
{
$fileKey = $request->query->get('fileKey');
$directory = $request->query->get('directory');
echo ($this->s3->getFileFromS3($directory, $fileKey));
exit;
}
/**
* @Route("/offer-search", name="get_offer_search_empty", methods={"GET"})
*/
public
function getOfferSearchEmptyAction(Request $request)
{
return new JsonResponse([]);
}
/**
* @Route("/offer-search/{keyword}", name="get_offer_search", methods={"GET"})
*/
public
function getOfferSearchBYKeywordAction(Request $request, $keyword)
{
$offerInfo = $this->doctrine->getRepository(OfferInfo::class)->getOffersWhereNameLike(Config::ACTIVE_STATUS, $keyword);
$data = [];
foreach ($offerInfo as $key => $value) {
$data[] = [
'value' => $value['offerId'],
'label' => $value['offerId'] . ' - ' . $value['name'],
'skadNetworkMmp' => $value['skadNetworkMmp']
];
}
return new JsonResponse($data);
}
/**
* @Route("/offer-search-by-tune-accounts/{keyword}", methods={"GET"})
*/
public
function getOfferSearchByTuneAccountsAndKeywordAction(Request $request, $keyword)
{
$offerInfo = $this->doctrine->getRepository(OfferInfo::class)->getOffersWhereNameLike(Config::ACTIVE_STATUS, $keyword);
if (empty($offerInfo)) {
$offerInfoPending = $this->doctrine->getRepository(OfferInfo::class)->getOffersWhereNameLike(Config::PENDING_STATUS, $keyword);
$offerInfoPaused = $this->doctrine->getRepository(OfferInfo::class)->getOffersWhereNameLike(Config::PAUSED_STATUS, $keyword);
$offerInfo = array_merge($offerInfoPending, $offerInfoPaused);
}
$data = [];
foreach ($offerInfo as $key => $value) {
$tuneAccount = Config::MAFO_SYSTEM_IDENTIFIER_PRETTY[$value['tuneAccount']] ?? "";
$offerIdToDisplay = $value['offerId'];
$data[$tuneAccount]['label'] = strtoupper($tuneAccount) . ' ACCOUNT OFFER IDS';
$data[$tuneAccount]['options'][$value['offerId']] = [
'value' => $value['offerId'],
'label' => $offerIdToDisplay . ' - ' . $value['name'],
'tuneAccount' => $value['tuneAccount'],
'tuneAccountRaw' => $value['tuneAccount'],
'color' => Config::MAFO_SYSTEM_IDENTIFIER_TUNE_ACCOUNTS_COLORS[$tuneAccount] ?? "#000"
];
ksort($data[$tuneAccount]['options']);
}
$finalArr = [];
foreach ($data as $key => $value) {
$finalArr[] = [
'label' => $value['label'],
'options' => array_values($value['options']),
];
}
return new JsonResponse($finalArr);
}
/**
* @Route("/click-cap-block-period-list", name="get_click_cap_block_period_list", methods={"GET"})
*/
public
function getClickCapBlockPeriodListAction(Request $request)
{
$list = [];
foreach (Config::CLICK_CAP_BLOCK_PERIOD_LIST as $key => $value) {
$list[] = [
'value' => $key,
'label' => $value
];
}
return new JsonResponse($list);
}
/**
* @Route("/skadnetwork-mmp-list", name="get_skadnetwork_mmp_list", methods={"GET"})
*/
public
function getSkadnetworkMmpListAction(Request $request)
{
$list = [];
foreach (Config::SKADNETOWRK_MMP as $key => $value) {
$list[] = [
'value' => $value,
'label' => ucfirst($value)
];
}
return new JsonResponse($list);
}
/**
* @Route("/skadnetwork-enabled-offer-by-app-id/{appId}", name="get_skadnetwork_enabled-offer_by_app_id", methods={"GET"})
*/
public
function getSkadNetworkEnabledOfferByAppId(Request $request, $appId)
{
$offerInfo = [];
if ($appId) {
$offerInfo = $this->doctrine->getRepository('App\Entity\Tune\OfferInfo')->getSkadEnaledOfferInfoByAppId($appId, 1);
}
$offerIds = [];
foreach ($offerInfo as $key => $value) {
$offerIds[] = $value['offerId'];
}
return new JsonResponse($offerIds);
}
/**
* @Route("/mafo-users", name="get_mafo_users", methods={"GET"})
*/
public
function getMafoUsersAction(Request $request)
{
$role = $request->query->get('role') !== 'undefined' ? $request->query->get('role') : false;
$users = $this->doctrine->getRepository('App\Entity\Users')->getUsers();
$roles = [];
if ($role === Config::ROLE_SALES) {
$roles = [$role, Config::ROLE_ADMIN];
}
$arr = [];
foreach ($users as $key => $value) {
if ($roles) {
if (array_intersect($roles, $value['roles'])) {
$arr[$value['email']] = [
'value' => $value['email'],
'label' => $value['name'] . "[{$value['email']}]"
];
}
} else {
$arr[$value['email']] = [
'value' => $value['email'],
'label' => $value['name'] . " [{$value['email']}]"
];
}
}
ksort($arr);
return new JsonResponse(array_values($arr));
}
/**
* @Route("/mafo-users-position", name="get_mafo_users_position", methods={"GET"})
*/
public
function getMafoUsersPostionAction(Request $request)
{
$users = $this->doctrine->getRepository('App\Entity\Users')->getUsers([
'status' => ['value' => [Config::ACTIVE_STATUS], 'excludeFlag' => false]
]);
$arr = [];
foreach ($users as $key => $value) {
if ($value['position']) {
$arr[$value['position']] = [
'value' => $value['position'],
'label' => $value['position']
];
}
}
ksort($arr);
return new JsonResponse(array_values($arr));
}
/**
* @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))) {
// echo json_Encode(Config::TABLE_COLUMNS_WITH_JSON_FILE[$report]);die;
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("/table-columns/{table}", name="get_table_columns", methods={"GET"})
*/
public
function getTableColumnsAction(Request $request, $table)
{
return new JsonResponse(array_values($this->commonCalls->getDataFromJsonFile(Config::TABLE_COLUMNS_WITH_JSON_FILE[$table])));
}
/**
* @Route("/skad-network-endpoints", name="get_skad_network_endpoints", methods={"GET"})
*/
public
function getSkadNetworkEndpointsAction(Request $request)
{
$arr = [];
foreach (Config::SKADNETWORK_POSTBACK_ENDPOINT as $key => $value) {
$arr[] = [
'value' => $value,
'label' => $value
];
}
return new JsonResponse($arr);
}
/**
* @Route("/deduction-insights-statuses", name="get_deduction_insights_status_filter", methods={"GET"})
*/
public
function getDeductionInsightsStatusesAction(Request $request)
{
$data = [];
foreach (Config::DEDUCTION_INSIGHTS_STATUS_ARRAY as $value) {
$data[] = [
'value' => $value,
'label' => $value,
];
}
return new JsonResponse($data);
}
/**
* @Route("/adjust-mmp-accounts", name="get_adjust_mmp_accounts", methods={"GET"})
*/
public
function getAdjustMmpAccountsAction(Request $request)
{
$data = [];
foreach (array_keys(Config::MMP_ADJUST_ACCOUNT_TOKEN_MAPPING) as $value) {
$data[] = [
'value' => $value,
'label' => ucfirst($value) . " [" . Config::MMP_ADJUST_ACCOUNT_EMAIL_MAPPING[$value] . "]",
];
}
return new JsonResponse($data);
}
/**
* @Route("/mmp-notification-rule-by-field", name="get_mmp_notification_rule_by_field", methods={"GET"})
*/
public
function getMmpNotificationRuleByFieldAction(Request $request)
{
$data = [];
foreach (Config::MMP_NOTIFICATION_RULE_BY_FIELD_ARRAY as $key => $value) {
$data[] = [
'value' => $key,
'label' => $value
];
}
return new JsonResponse($data);
}
/**
* @Route("/mmp-notification-rule-by-type", name="get_mmp_notification_rule_by_type", methods={"GET"})
*/
public
function getMmpNotificationRuleByTypeAction(Request $request)
{
$data = [];
foreach (Config::MMP_NOTIFICATION_RULE_BY_TYPE_ARRAY as $key => $value) {
$data[] = [
'value' => $key,
'label' => $value
];
}
return new JsonResponse($data);
}
/**
* @Route("/mmp-offer-events", name="get_mmp_offer_events", methods={"GET"})
*/
public
function getMmpOfferEventsAction(Request $request)
{
// $mmpStatisticsEvents = $this->doctrine->getRepository(MmpOffers::class)->getDistinctEvents();
$mmpReportsEvents = $this->doctrine->getRepository(MmpReports::class)->getDistinctEvents();
$arr = [];
foreach ($mmpReportsEvents as $key => $value) {
$eventName = $value['mmpSource'] == (Config::MMP_TRACKING_SYSTEM_TUNE_MOBILE || $value['mmpSource'] == Config::MMP_TRACKING_SYSTEM_TUNE_WEB) ? $value['mmpOfferDefaultRevenueEventName'] : $value['event'];
$index = $value['event'] . '#' . $eventName;
$arr[$index] = [
'value' => $value['event'],
'label' => $eventName . " [ID: {$value['event']}]" . " [MMP: {$value['mmpSource']}]"
];
}
return new JsonResponse(array_values($arr));
}
/**
* @Route("/mmp-offer-list", name="get_mmp_offer_list", methods={"GET"})
*/
public
function getMmpOfferListAction(Request $request)
{
$data = $this->doctrine->getRepository(MmpOffers::class)->getMmpOffersDataByIsDeleted(0);
$arr = [];
foreach ($data as $key => $value) {
$arr[$value['id']] = [
'value' => $value['id'],
'label' => $value['id'] . ' - ' . $value['offerName']
];
}
ksort($arr);
return new JsonResponse(array_values($arr));
}
/**
* @Route("/mmp-notification-period", name="get_mmp_notifications_period", methods={"GET"})
*/
public
function getMmpNotificationsPeriodAction(Request $request)
{
$arr = [];
foreach (Config::MMP_NOTIFICATION_PERIOD_ARRAY as $key => $value) {
$arr[] = [
'value' => $key,
'label' => $value
];
}
return new JsonResponse($arr);
}
/**
* @Route("/skad-postback-app-ids", name="get_skad_postback_app_ids", methods={"GET"})
*/
public
function getSkadPostbacksAppIdsAction(Request $request)
{
$postbackLogsData = $this->doctrine->getRepository(SkadNetworkPostbackLogs::class)->getSkadNetworkPostbackAppIds();
$arr = [];
foreach ($postbackLogsData as $key => $value) {
if ($value['appId']) {
$arr[] = [
'value' => $value['appId'],
'label' => "id" . $value['appId'],
];
}
}
return new JsonResponse($arr);
}
/**
* @Route("/skad-postback-campaign-ids", name="get_skad_postback_campaign_ids", methods={"GET"})
*/
public
function getSkadPostbacksCampaignIdsAction(Request $request)
{
$postbackLogsData = $this->doctrine->getRepository(SkadNetworkPostbackLogs::class)->getSkadNetworkPostbackCampaignIds();
$arr = [];
foreach ($postbackLogsData as $key => $value) {
$arr[] = [
'value' => (string)$value['campaignId'],
'label' => (string)$value['campaignId'],
];
}
return new JsonResponse($arr);
}
/**
* @Route("/organisation-chart", name="get_org_chart", methods={"GET"})
*/
public
function getTestAction(Request $request)
{
$parentChildRelationship = $this->doctrine->getRepository(UsersHierarchy::class)->checkChildParentRelationship();
$usersInfo = $this->usersComponents->getUsersDataByEmailIdAsKey(true);
$organisationData = [];
foreach ($parentChildRelationship as $key => $value) {
$organisationData[] = [
'name' => array_key_exists($value['child'], $usersInfo) ? $usersInfo[$value['child']]['name'] : '',
'imageUrl' => array_key_exists($value['child'], $usersInfo) ? $usersInfo[$value['child']]['picture'] : '',
'area' => array_key_exists($value['child'], $usersInfo) ? $usersInfo[$value['child']]['userInfo'] : '',
'profileUrl' => array_key_exists($value['child'], $usersInfo) ? $usersInfo[$value['child']]['picture'] : '',
'office' => array_key_exists($value['child'], $usersInfo) ? $usersInfo[$value['child']]['userInfo'] : '',
'tags' => '',
'positionName' => array_key_exists($value['child'], $usersInfo) ? ($usersInfo[$value['child']]['position'] ?? '') : '',
'id' => $value['child'],
'parentId' => $value['parent'] ?? '',
'parentName' => $value['parent'] ? $usersInfo[$value['parent']]['name'] : '',
'team' => array_key_exists($value['child'], $usersInfo) ? $usersInfo[$value['child']]['team'] : '',
'userInfo' => array_key_exists($value['child'], $usersInfo) ? $usersInfo[$value['child']]['userInfo'] : '',
'size' => '',
];
}
return new JsonResponse($organisationData);
}
/**
* @Route("/revenue-control-statuses", name="get_revenue_control_statuses", methods={"GET"})
*/
public
function getRevenueControlStatusesAction(Request $request)
{
$arr = [];
foreach (Config::REVENUE_CONTROL_STATUSES as $key => $value) {
$arr[] = [
'value' => $value,
'label' => ucfirst($value),
];
}
return new JsonResponse($arr);
}
/**
* @Route("/payout-control-statuses", name="get_payout_control_statuses", methods={"GET"})
*/
public
function getPayoutControlStatusesAction(Request $request)
{
$arr = [];
foreach (Config::PAYOUT_CONTROL_STATUSES as $key => $value) {
$arr[] = [
'value' => $value,
'label' => ucfirst($value),
];
}
return new JsonResponse($arr);
}
/**
* @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("/affiliate-hyper-statuses", name="get_affiliate_hyper_statuses", methods={"GET"})
*/
public
function getAffiliateHyperStatusesAction(Request $request)
{
$arr = [];
foreach (array_values(Config::HYPER_STATUS_AFFILIATE_MAFO_MACROS) as $key => $value) {
$arr[$value] = [
'value' => $value,
'label' => $value,
];
}
return new JsonResponse(array_values($arr));
}
/**
* @Route("/oauth", name="get_oauth", methods={"GET"})
*/
public
function getOauthAction(Request $request)
{
return new JsonResponse(true);
}
/**
* @Route("/revenue-total-billing-statuses", name="get_revenue_total_billing_statuses", methods={"GET"})
*/
public
function getRevenueTotalBillingStatusesAction(Request $request)
{
$arr = [];
foreach (Config::REVENUE_TOTAL_BILLING_STATUSES as $key => $value) {
$arr[] = [
'value' => $key,
'label' => $value
];
}
return new JsonResponse($arr);
}
/**
* @Route("/mobupps-teams", name="get_mobupps_teams_utilities", methods={"GET"})
*/
public
function getMobuppsTeamUtilitiesAction(Request $request)
{
return new JsonResponse(array_values($this->usersComponents->getTeamsByTeamIdWithNonEmptyTeams()));
}
/**
* @Route("/empty-list", name="get_empty_list", methods={"GET"})
*/
public
function getEmptyListAction(Request $request)
{
return new JsonResponse([]);
}
/**
* @Route("/gap-control-cost-type", name="get_gap_control_cost_type", methods={"GET"})
*/
public
function getGapControlCostType(Request $request)
{
return new JsonResponse([
[
'value' => 'gross',
'label' => 'Gross Cost'
],
[
'value' => 'approved',
'label' => 'Approved Cost'
],
]);
}
/**
* @Route("/log-entities", name="get_log_entities", methods={"GET"})
*/
public
function getLogEntitiesAction(Request $request)
{
$arr = [];
foreach (Config::ENTITIES_TO_LOG as $key => $value) {
$arr[$value] = [
'value' => $value,
'label' => $value
];
}
ksort($arr);
return new JsonResponse(array_values($arr));
}
/**
* @Route("/alert-medium", name="get_alert_mediums", methods={"GET"})
*/
public
function getAlertMediumsAction(Request $request)
{
$arr = [];
foreach (Config::ALERT_MEDIUMS as $key => $value) {
$arr[$value] = [
'value' => $value,
'label' => strtoupper($value)
];
}
ksort($arr);
return new JsonResponse(array_values($arr));
}
/**
* @Route("/alert-categories", name="get_alert_categories", methods={"GET"})
*/
public
function getAlertCategoriesAction(Request $request)
{
$arr = [];
foreach (Config::ALERT_CATEGORIES as $key => $value) {
$arr[$value] = [
'value' => $value,
'label' => $value
];
}
ksort($arr);
return new JsonResponse(array_values($arr));
}
/**
* @Route("/alert-names", name="get_alert_names", methods={"GET"})
*/
public
function getAlertNameAction(Request $request)
{
$arr = [];
foreach (Config::ALERTS_LIST as $key => $value) {
$arr[] = [
'value' => $value,
'label' => $value
];
}
ksort($arr);
return new JsonResponse(array_values($arr));
}
/**
* @Route("/boolean-select", name="get_boolean_select", methods={"GET"})
*/
public
function getBooleanSelectAction(Request $request)
{
return new JsonResponse([
[
'value' => true,
'label' => 'YES',
],
[
'value' => false,
'label' => 'NO',
],
]);
}
/**
* @Route("/site-id-select", name="get_site_id_select", methods={"GET"})
*/
public
function getSiteIdSelectAction(Request $request)
{
$siteIds = $this->doctrine->getRepository(MmpReports::class)->getDistinctSiteIds();
$arr = [];
foreach ($siteIds as $siteIdRow) {
if (!empty($siteIdRow["siteId"])) {
$arr[$siteIdRow["siteId"]] = [
'value' => $siteIdRow["siteId"],
'label' => $siteIdRow["siteId"]
];
}
}
ksort($arr);
return new JsonResponse(array_values($arr));
}
/**
* @Route("/alert-view/{id}", name="get_alert_view", methods={"GET"})
*/
public
function getAlertViewAction(Request $request, $id)
{
$alertData = $this->doctrine->getRepository(AlertLogs::class)->findOneBy(['md5' => $id]);
$mailToName = '';
$userInfo = $this->doctrine->getRepository(Users::class)->findOneBy(['email' => $alertData->getMailTo() ?? null]);
if ($userInfo) {
$mailToName = $userInfo->getName();
}
return $this->render('/alerts/defaultAlertWithTableData.html.twig', [
'headers' => is_string($alertData->getMailHeaderJson()) ? json_decode($alertData->getMailHeaderJson(), true) : $alertData->getMailHeaderJson(),
'tableData' => is_string($alertData->getMailBodyJson()) ? json_decode($alertData->getMailBodyJson(), true) : $alertData->getMailBodyJson(),
'name' => $mailToName,
'corollary' => $alertData->getAlertForward()
]);
}
/**
* @Route("/alert-csv-download/{id}", name="get_alert_csv_download", methods={"GET"})
*/
public
function getAlertCsvDownloadAction(Request $request, $id)
{
$alertData = $this->doctrine->getRepository(\App\Entity\AlertLogs::class)->findOneBy(['md5' => $id]);
$alertName = $alertData->getAlertAction();
// var_dump($alertData);die;
$headers = is_string($alertData->getMailHeaderJson()) ? json_decode($alertData->getMailHeaderJson(), true) : $alertData->getMailHeaderJson();
$tableData = is_string($alertData->getMailBodyJson()) ? json_decode($alertData->getMailBodyJson(), true) : $alertData->getMailBodyJson();
// echo json_encode($tableData);die;
$rows = [array_column($headers, 'label')];
foreach ($tableData as $key => $value) {
$temp = [];
foreach ($headers as $k => $v) {
if (is_array($value[$k]['value'])) {
$tempArr = [];
foreach ($value[$k]['value'] as $subKey => $subValue) {
$tempArr[] = "$subKey: $subValue";
}
$temp[] = implode("\n", $tempArr);
} else {
$temp[] = $value[$k]['value'];
}
}
$rows[] = $temp;
}
$spreadsheet = new Spreadsheet();
$spreadsheet->getProperties()->setCreator('MAFO')
->setLastModifiedBy('MAFO')
->setTitle($alertName)
->setSubject($alertName)
->setDescription($alertName);
$spreadsheet->getActiveSheet()
->fromArray(
$rows,
NULL,
'A1'
);
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="' . $alertName . '.xls"');
header('Cache-Control: max-age=0');
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save('php://output');
exit;
}
/**
* @Route("/affiliate-categories", name="get_affiliate_categories", methods={"GET"})
*/
public
function getAffiliateCategoriesAction(Request $request)
{
$arr = [
[
'value' => Config::HASOFFER_AFFILIATE_CATEGORY_UNCATEGORISED_TAG_NAME,
'label' => Config::HASOFFER_AFFILIATE_CATEGORY_UNCATEGORISED_TAG_NAME
]
];
foreach (Config::HASOFFER_AFFILIATE_CATEGORY_ARRAY as $key => $value) {
$arr[] = [
'value' => $value,
'label' => $value
];
}
return new JsonResponse($arr);
}
/**
* @Route("/alert-frequency-types", name="get_alert_frequency_types", methods={"GET"})
*/
public
function getAlertFrequencyTypesAction(Request $request)
{
$arr = [];
foreach (Config::ALERT_CONTROL_ALERT_FREQUENCY_TYPES as $type) {
$arr[] = [
'value' => $type,
'label' => strtoupper($type)
];
}
return new JsonResponse($arr);
}
/**
* @Route("/global-report-exclude-zero-values", name="get_global_report_Exclude_zero_values", methods={"GET"})
*/
public
function getGlobalReportExcludeZeroValuesAction(Request $request)
{
$arr = [];
$columns = $this->commonCalls->getDataFromJsonFile(Config::JSON_FILE_GLOBAL_NETWORK_REPORT);
foreach ($columns as $key => $value) {
if (in_array($value['category'], ['statistics', 'calculations'])) {
$arr[] = [
'value' => $value['accessor'],
'label' => 'Exclude results with zero ' . $value['header']
];
}
}
return new JsonResponse($arr);
}
/**
* @Route("/hyper-client-list", name="get_hyper_client_list", methods={"GET"})
*/
public
function getHyperClientList(Request $request, HyperApis $hyperApis)
{
$hyperData = $this->commonCalls->getHyperClientCachedListByKeys();
$clientId = $request->query->get('clientId');
if ($clientId > 0) {
$clientInfo = $hyperApis->getHyperClientByClientId($clientId);
if ($clientInfo && isset($clientInfo['Result']) && $clientInfo['Result'] == 'Ok') {
foreach ($clientInfo['ResultData']['Data'] as $key => $value) {
if ($value['ClientNumber'] == $clientId) {
$countryCode = null;
foreach (Config::COUNTRIES as $k => $v) {
if ($this->commonCalls->checkForString($value['Country'], $v['name'])) {
$countryCode = $k;
break;
}
}
$value['countryCode'] = $countryCode;
$hyperData[$clientId] = $value;
break;
}
}
}
}
$arr = [];
foreach ($hyperData as $key => $value) {
$arr[] = [
'value' => $key,
'label' => $value['ClientFullName'] . ' [' . $value['ClientNumber'] . ']',
'clientFullName' => $value['ClientFullName'],
'countryCode' => $value['countryCode'],
'city' => $value['City'],
'address' => $value['StreetAddress']
];
}
return new JsonResponse($arr);
}
/**
* @Route("/hyper-publisher-list", name="get_hyper_publisher_list", methods={"GET"})
*/
public
function getHyperPublisherList(Request $request, HyperApis $hyperApis)
{
$hyperPublisherData = $this->commonCalls->getHyperPublisherCachedListByKeys();
$arr = [];
foreach ($hyperPublisherData as $key => $value) {
$arr[$value['SupplierNumber']] = [
'value' => (int) $value['SupplierNumber'],
'label' => $value['SupplierFullName'] . ' [' . $value['SupplierNumber'] . ']'
];
}
ksort($arr);
return new JsonResponse(array_values($arr));
}
/**
* @Route("/tune-advertisers-by-hyper-client/{clientId}", name="get_tune_advertisers_by_hyper_client", methods={"GET"})
*/
public
function getTuneAdvertisersByHyperClient(Request $request, $clientId)
{
$hyperData = $this->commonCalls->getHyperClientCachedListByKeys();
$linkedAdvertisers = [];
foreach ($hyperData as $key => $value) {
$value['Io_numbers'] = str_replace("\n\r", " ", $value['Io_numbers']);
$hyperData[$key]['Io_numbers'] = explode(" ", $value['Io_numbers']);
$linkedAdvertisers = array_values(array_unique(array_merge($linkedAdvertisers, $hyperData[$key]['Io_numbers'])));
}
$unlinedAdvertisers = $this->doctrine->getRepository(AdvertiserInfo::class)->getAdvertiserListByArrToSearch([
'advertiserId' => ['value' => $linkedAdvertisers, 'excludeFlag' => true]
]);
$clientLinkedMutiselectList = [];
$clientLinkedMutiselectList['label'] = 'Tune Advertisers Linked With HYPER';
$clientLinkedMutiselectList['options'] = [];
if (isset($hyperData[$clientId]) && sizeof($hyperData[$clientId]['Io_numbers'])) {
$clientLinkedMutiselectList['label'] = 'Tune Advertisers Linked With HYPER Client ' . $hyperData[$clientId]['ClientFullName'];
$clientLinkedMutiselectList['options'] = [];
$clientLinkedAdvertisers = $this->doctrine->getRepository(AdvertiserInfo::class)->getAdvertiserListByArrToSearch([
'advertiserId' => ['value' => $hyperData[$clientId]['Io_numbers'], 'excludeFlag' => false]
]);
if ($clientLinkedAdvertisers) {
foreach ($clientLinkedAdvertisers as $key => $value) {
$clientLinkedMutiselectList['options'][] = [
'value' => $value['advertiserId'],
'label' => $value['advertiserId'] . " - " . $value['company'],
'color' => "#e55353"
];
}
}
}
$unlinkedMultiselectList = [];
$unlinkedMultiselectList['label'] = 'Tune Advertisers Unlinked In HYPER';
$unlinkedMultiselectList['options'] = [];
foreach ($unlinedAdvertisers as $key => $value) {
$unlinkedMultiselectList['options'][] = [
'value' => $value['advertiserId'],
'label' => $value['advertiserId'] . " - " . $value['company'],
'color' => "#3399ff"
];
}
$finalArr = [$clientLinkedMutiselectList, $unlinkedMultiselectList];
return new JsonResponse($finalArr);
}
/**
* @Route("/tune-accounts", methods={"GET"})
*/
public
function getTuneAccountsAction(Request $request)
{
$arr = [];
foreach (Config::MAFO_SYSTEM_IDENTIFIER_TUNE_ACCOUNTS as $key => $value) {
$arr[$value] = [
'value' => $value,
'label' => $value === Config::MAFO_SYSTEM_IDENTIFIER_TUNE_MOBILE ? Config::MAFO_SYSTEM_IDENTIFIER_TUNE_MOBILE_PRETTY : Config::MAFO_SYSTEM_IDENTIFIER_TUNE_WEB_PRETTY,
];
}
return new JsonResponse(array_values($arr));
}
/**
* @Route("/advertisers-by-tune-account/{keyword}", methods={"GET"})
*/
public
function getTuneWebAccountAdvertisersAction(Request $request, $keyword)
{
$advertisersByTuneAccount = $this->doctrine->getRepository(AdvertiserInfo::class)->getAdvertisersByTuneAccount([Config::ACTIVE_STATUS], $keyword);
$advertiserList = [];
foreach ($advertisersByTuneAccount as $key => $value) {
$advertiserList[$value['tuneAccount']]['label'] = (Config::MAFO_SYSTEM_IDENTIFIER_PRETTY[$value['tuneAccount']] ?? "") . ' ACCOUNT';
$advertiserList[$value['tuneAccount']]['options'][$value['advertiserId']] = [
'value' => $value['advertiserId'],
'label' => $value['advertiserId'] . ' - ' . $value['advertiserName'],
'tuneAccount' => $value['tuneAccount'],
'color' => Config::MAFO_SYSTEM_IDENTIFIER_TUNE_ACCOUNTS_COLORS[$value['tuneAccount']]
];
ksort($advertiserList[$value['tuneAccount']]['options']);
}
$data = [];
foreach ($advertiserList as $key => $value) {
$data[] = [
'label' => $value['label'],
'options' => array_values($value['options']),
];
}
return new JsonResponse($data);
}
/**
* @Route("/advertisers-by-tune-account", methods={"GET"})
*/
public
function getTuneMobileAccountAdvertisersAction(Request $request)
{
$advertisersByTuneAccount = $this->doctrine->getRepository(AdvertiserInfo::class)->getAdvertisersByTuneAccount([Config::ACTIVE_STATUS], null);
$advertiserList = [];
foreach ($advertisersByTuneAccount as $key => $value) {
$advertiserList[$value['tuneAccount']]['label'] = (Config::MAFO_SYSTEM_IDENTIFIER_PRETTY[$value['tuneAccount']] ?? "") . ' ACCOUNT';
$advertiserList[$value['tuneAccount']]['options'][$value['advertiserId']] = [
'value' => $value['advertiserId'],
'label' => $value['advertiserId'] . ' - ' . $value['advertiserName'],
'tuneAccount' => $value['tuneAccount'],
'color' => Config::MAFO_SYSTEM_IDENTIFIER_TUNE_ACCOUNTS_COLORS[$value['tuneAccount']]
];
if (sizeof($advertiserList[$value['tuneAccount']]['options']) > 1200) {
continue;
}
ksort($advertiserList[$value['tuneAccount']]['options']);
}
$data = [];
foreach ($advertiserList as $key => $value) {
$data[] = [
'label' => $value['label'],
'options' => array_values($value['options']),
];
}
return new JsonResponse($data);
}
/**
* @Route("/affiliates-by-tune-account/{keyword}", methods={"GET"})
*/
public
function getTuneWebAccountAffiliatesAction(Request $request, $keyword)
{
$affiliatesByTuneAccount = $this->doctrine->getRepository(AffiliateInfo::class)->getAffiliatesByTuneAccount([Config::ACTIVE_STATUS], $keyword);
$affiliateList = [];
foreach ($affiliatesByTuneAccount as $key => $value) {
$affiliateList[$value['tuneAccount']]['label'] = (Config::MAFO_SYSTEM_IDENTIFIER_PRETTY[$value['tuneAccount']] ?? "") . ' ACCOUNT AFFILIATE IDS';
$affiliateList[$value['tuneAccount']]['options'][$value['affiliateId']] = [
'value' => $value['affiliateId'],
'label' => $value['affiliateId'] . ' - ' . $value['affiliateName'],
'tuneAccount' => $value['tuneAccount'],
'color' => Config::MAFO_SYSTEM_IDENTIFIER_TUNE_ACCOUNTS_COLORS[$value['tuneAccount']] ?? "#000"
];
ksort($affiliateList[$value['tuneAccount']]['options']);
}
$data = [];
foreach ($affiliateList as $key => $value) {
$data[] = [
'label' => $value['label'],
'options' => array_values($value['options']),
];
}
return new JsonResponse($data);
}
/**
* @Route("/saved-report", name="saved_report_get", methods={"GET"})
*/
public
function getSavedReportAction(Request $request)
{
$reportName = $request->query->get('reportName');
$data = $this->doctrine->getRepository(SavedReport::class)->getReportByEmailIdAndReportName($this->getUser()->getEmail(), $reportName);
return new JsonResponse($data);
}
/**
* @Route("/saved-report", name="saved_report_post", methods={"POST"})
*/
public
function postSavedReportAction(Request $request)
{
$payload = json_decode($request->getContent(), true);
if (
!array_key_exists($payload['reportName'], Config::TABLE_COLUMNS_WITH_JSON_FILE) ||
!is_array($payload['payload']) ||
!$payload['reportGivenName'] ||
!$payload['reportPeriod']
) {
return new JsonResponse(false, Config::HTTP_STATUS_CODE_BAD_REQUEST);
}
$this->doctrine->getRepository(SavedReport::class)->insert(
$this->getUser()->getEmail(),
$payload['reportName'],
$payload['reportGivenName'],
$payload['reportPeriod'],
$payload['payload']
);
return new JsonResponse(true);
}
/**
* @Route("/saved-report/{id}", name="saved_report_delete", methods={"DELETE"})
*/
public
function deleteSavedReportAction(Request $request, $id)
{
$recordExist = $this->doctrine->getRepository(SavedReport::class)->findOneBy([
'id' => $id,
'savedByEmailId' => $this->getUser()->getEmail()
]);
if ($recordExist) {
$this->doctrine->getRepository(SavedReport::class)->updateSavedReportDataById($id, [
'isDeleted' => 1
]);
}
return new JsonResponse(true);
}
/**
* @Route("/recommendations", methods={"GET"})
*/
public
function getRecommendationsAction(Request $request)
{
$objectType = $request->query->get('objectType');
$objectValue = $request->query->get('objectValue');
$recommendedObjectType = $request->query->get('recommendedObjectType');
$recommendedData = $this->machineLearning->getRecommendations($objectType, $objectValue, $recommendedObjectType, Config::MMP_TRACKING_SYSTEM_TUNE);
return new JsonResponse($recommendedData);
}
/**
* @Route("/new-recommendations", methods={"GET"})
*/
public
function getNewRecommendationsAction(Request $request)
{
$objectType = $request->query->get('objectType');
$objectValue = $request->query->get('objectValue');
$recommendedObjectType = $request->query->get('recommendedObjectType');
$mmpSource = $request->query->get('mmpSource');
// $recommendedData = [];
// if ($objectType == Config::RECOMMENDATIONS_OBJECT_TYPE_OFFER && $recommendedObjectType == Config::RECOMMENDATIONS_OBJECT_TYPE_AFFILIATE) {
$recommendedData = $this->machineLearning->getRecommendedAffiliatesByOffer($objectValue, $objectType, $mmpSource);
// }
return new JsonResponse($recommendedData);
}
/**
* @Route("/advertiser-discount-types", methods={"GET"})
*/
public
function getAdvertiserDiscountTypes(Request $request)
{
$arr = [];
foreach (Config::ADVERTISER_DISCOUNT_TYPES as $discountType) {
$arr[] = [
'value' => $discountType,
'label' => ucwords(str_replace("_", " ", $discountType))
];
}
return new JsonResponse($arr);
}
/**
* @Route("/mafo-advertisers", methods={"GET"})
*/
public
function getMafoAdvertisersAction(Request $request)
{
$showAssociatedAdvertisers = $request->query->get('showAssociatedAdvertisers');
$showAssociatedAdvertisers = $showAssociatedAdvertisers === '1' ? true : false;
$accountManagerIds = [];
if (!in_array(Config::ROLE_ADMIN, $this->getUser()->getRoles()) && $showAssociatedAdvertisers) {
$childUsersByUser = $this->usersComponents->getChildUsersByUser();
if (array_key_exists($this->getUser()->getEmail(), $childUsersByUser)) {
$accountManagerIds = array_values(array_unique(array_merge($accountManagerIds, [$this->getUser()->getRoles()], $childUsersByUser[$this->getUser()->getEmail()])));
}
$accountManagerIds[] = $this->getUser()->getEmail();
}
$filters = [];
if ($accountManagerIds) {
$filters['accountManagerEmail'] = $accountManagerIds;
}
$advertisers = $this->doctrine->getRepository(MafoAdvertisers::class)->getAdvertisers($filters, [], Config::REPORTS_PAGINATION_DEFAULT_CSV_PAGE_SIZE, Config::REPORTS_PAGINATION_DEFAULT_PAGE_NUMBER, Config::REPORTS_PAGINATION_DEFAULT_SORT_BY, Config::REPORTS_PAGINATION_DEFAULT_SORT_TYPE);
$arr = [];
foreach ($advertisers as $key => $value) {
$arr[] = [
'value' => $value['id'],
'label' => $value['id'] . ' - ' . $value['name']
];
}
return new JsonResponse($arr);
}
/**
* @Route("/mafo-affiliates", methods={"GET"})
*/
public
function getMafoAffiliatesAction(Request $request)
{
$affiliates = $this->doctrine->getRepository(MafoAffiliates::class)->getAffiliates([], [], Config::REPORTS_PAGINATION_DEFAULT_CSV_PAGE_SIZE, Config::REPORTS_PAGINATION_DEFAULT_PAGE_NUMBER, Config::REPORTS_PAGINATION_DEFAULT_SORT_BY, Config::REPORTS_PAGINATION_DEFAULT_SORT_TYPE);
$arr = [];
foreach ($affiliates as $key => $value) {
$arr[] = [
'value' => $value['id'],
'label' => $value['id'] . ' - ' . $value['name']
];
}
return new JsonResponse($arr);
}
/**
* @Route("/mafo-offers", methods={"GET"})
*/
public
function getMafoOffersAction(Request $request)
{
$offers = $this->doctrine->getRepository(MafoOffers::class)->getOffersList();
$arr = [];
foreach ($offers as $key => $value) {
$arr[] = [
'value' => $value['id'],
'label' => $value['id'] . ' - ' . $value['name']
];
}
return new JsonResponse($arr);
}
/**
* @Route("/offer-type", name="get_offer_type", methods={"GET"})
*/
public function getOfferTypeAction()
{
$offerTypes = array_map(function ($type) {
return [
'value' => strtolower($type),
'label' => $type
];
}, Config::OFFER_TYPES);
return new JsonResponse($offerTypes);
}
/**
* @Route("/publisher-list", name="get_publishers_dropdown", methods={"GET"})
*/
public function getPublishersDropdownAction(Request $request)
{
$mappedAffiliateId = $request->query->get('mappedAffiliateId');
if ($mappedAffiliateId) {
// Fetch publishers for the given mappedAffiliateId and not deleted
$data = $this->doctrine->getRepository(MafoPublisherCabinetManager::class)->getPublishersByAffiliateId($mappedAffiliateId);
} else {
$data = $this->doctrine->getRepository(MafoPublisherCabinetManager::class)->getAllPublishers();
}
$dropdownData = $this->commonCalls->transformToDropdownFormat($data);
return new JsonResponse($dropdownData);
}
}