src/Controller/UtilitiesController.php line 2053

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Config;
  4. use App\Entity\Tune\AdvertiserAccountManager;
  5. use App\Entity\Tune\AffiliateAccountManager;
  6. use App\Entity\Tune\AffiliateInfo;
  7. use App\Entity\AffiliateTags;
  8. use App\Entity\AlertLogs;
  9. use App\Entity\MafoId\MafoAdvertisers;
  10. use App\Entity\MafoId\MafoAffiliates;
  11. use App\Entity\MafoId\MafoOffers;
  12. use App\Entity\PublisherCabinet\MafoPublisherCabinetManager;
  13. use App\Entity\SavedReport;
  14. use App\Entity\RecommendationsByObject;
  15. use App\Services\AffiliateHasofferAPI;
  16. use App\Services\Alerts;
  17. use App\Entity\MmpOffers;
  18. use App\Entity\MmpReports;
  19. use App\Entity\Tune\OfferInfo;
  20. use App\Entity\AppInfo;
  21. use App\Entity\Tune\AdvertiserInfo;
  22. use App\Entity\MafoId\MafoAffiliateMmpPartnerMapping;
  23. use App\Entity\MafoId\MafoOffersMapping;
  24. use App\Entity\SkadNetworkPostbackLogs;
  25. use App\Entity\SourceTags;
  26. use App\Entity\Tag;
  27. use App\Entity\Users;
  28. use App\Entity\UsersHierarchy;
  29. use App\Services\Aws\ElasticCache;
  30. use App\Services\Aws\S3;
  31. use App\Services\BrandHasofferAPI;
  32. use App\Services\Common;
  33. use App\Services\FinancialToolsComponents;
  34. use App\Services\HyperApis;
  35. use App\Services\ImpressionsApis;
  36. use App\Services\MachineLearning;
  37. use App\Services\Metrics24APICalls;
  38. use App\Services\MmpComponents;
  39. use App\Services\MysqlQueries;
  40. use App\Services\UsersComponents;
  41. use Doctrine\ODM\MongoDB\DocumentManager;
  42. use Doctrine\Persistence\ManagerRegistry;
  43. use Mmoreram\GearmanBundle\Service\GearmanClientInterface;
  44. use PhpOffice\PhpSpreadsheet\IOFactory;
  45. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  46. use Symfony\Component\Routing\Annotation\Route;
  47. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  48. use Symfony\Component\HttpFoundation\JsonResponse;
  49. use Symfony\Component\HttpFoundation\Request;
  50. use Symfony\Component\HttpFoundation\Response;
  51. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  52. use Symfony\Component\Security\Core\Authentication\Token\SwitchUserToken;
  53. use Symfony\Component\Security\Core\Security;
  54. /**
  55. *
  56. * Utilities and common routes which are used throughout the project with endpoint /api/utilities/{route}
  57. *
  58. * @Route("/api/utilities", name="aff", host="%main_subdomain%")
  59. */
  60. class UtilitiesController extends AbstractController
  61. {
  62. private $commonCalls;
  63. private $doctrine;
  64. private $usersComponents;
  65. private $s3;
  66. private $mongoDbDoctrine;
  67. private $security;
  68. private $machineLearning;
  69. private HyperApis $hyperApis;
  70. public function __construct(Common $commonCalls, ManagerRegistry $doctrine, UsersComponents $usersComponents, S3 $s3, DocumentManager $mongoDbDoctrine, Security $security, MachineLearning $machineLearning, HyperApis $hyperApis)
  71. {
  72. $this->commonCalls = $commonCalls;
  73. $this->doctrine = $doctrine;
  74. $this->usersComponents = $usersComponents;
  75. $this->s3 = $s3;
  76. $this->mongoDbDoctrine = $mongoDbDoctrine;
  77. $this->machineLearning = $machineLearning;
  78. $this->security = $security;
  79. $this->hyperApis = $hyperApis;
  80. }
  81. /**
  82. * @Route("/aff-offer-cap-type", name="affiliate_offer_cap_type", methods={"GET"})
  83. */
  84. public function getAffiliateOfferCapTypeAction(Request $request)
  85. {
  86. $affOfferCapType = [];
  87. foreach (Config::AFFILIATE_OFFER_CAP_TYPE as $key => $value) {
  88. $affOfferCapType[] = [
  89. 'value' => $value,
  90. 'label' => ucwords(str_replace("_", " ", $value))
  91. ];
  92. }
  93. return new JsonResponse($affOfferCapType);
  94. }
  95. /**
  96. * @Route("/adv-managers", name="get_adv_managers", methods={"GET"})
  97. */
  98. public function getAdvertiserManagersAction(Request $request)
  99. {
  100. $tuneAccount = $request->query->get('tuneAccount');
  101. $advertiserManagers = [];
  102. $data = $this->doctrine->getRepository(AdvertiserAccountManager::class)->getAccountManagerData($tuneAccount !== null ? $tuneAccount : null);
  103. foreach ($data as $key => $value) {
  104. $advertiserManagers[$value['employeeId']] = [
  105. 'value' => $value['employeeId'],
  106. 'label' => $value['firstName'] . ' ' . $value['lastName']
  107. ];
  108. }
  109. return new JsonResponse(array_values($advertiserManagers));
  110. }
  111. /**
  112. * @Route("/aff-managers", name="get_aff_managers", methods={"GET"})
  113. */
  114. public function getAffiliateManagersAction(Request $request)
  115. {
  116. $affiliateManagers = [];
  117. $dataAffiliateAccountManagers = $this->doctrine->getRepository(AffiliateAccountManager::class)->getAffiliateAccountManagerData();
  118. $data = [];
  119. foreach ($dataAffiliateAccountManagers as $key => $value) {
  120. $tuneAccount = Config::MAFO_SYSTEM_IDENTIFIER_PRETTY[$value['tuneAccount']] ?? "";
  121. $data[$tuneAccount]['label'] = strtoupper($tuneAccount) . ' ACCOUNT MANAGERS';
  122. $data[$tuneAccount]['options'][$value['employeeId']] = [
  123. 'value' => $value['employeeId'],
  124. 'label' => $value['firstName'] . ' ' . $value['lastName'],
  125. 'tuneAccount' => $tuneAccount,
  126. 'tuneAccountRaw' => $value['tuneAccount'],
  127. 'color' => Config::MAFO_SYSTEM_IDENTIFIER_TUNE_ACCOUNTS_COLORS[$tuneAccount] ?? "#000"
  128. ];
  129. ksort($data[$tuneAccount]['options']);
  130. }
  131. $finalArr = [];
  132. foreach ($data as $key => $value) {
  133. $finalArr[] = [
  134. 'label' => $value['label'],
  135. 'options' => array_values($value['options']),
  136. ];
  137. }
  138. return new JsonResponse(array_values($finalArr));
  139. }
  140. /**
  141. * @Route("/source-tags-list", name="get_source_tags_list", methods={"GET"})
  142. */
  143. public function getSourceTagListAction()
  144. {
  145. $sourceTagsData = $this->doctrine->getRepository(SourceTags::class)->getSourceTagsByIsDeleted(0);
  146. $uniqueSourceTagNames = [];
  147. foreach ($sourceTagsData as $key => $value) {
  148. if (!in_array($value['tagName'], $uniqueSourceTagNames)) {
  149. array_push($uniqueSourceTagNames, $value['tagName']);
  150. }
  151. }
  152. $multiselectList = [];
  153. foreach ($uniqueSourceTagNames as $tagName) {
  154. $multiselectList[] = [
  155. 'value' => $tagName,
  156. 'label' => $tagName
  157. ];
  158. }
  159. return new JsonResponse($multiselectList);
  160. }
  161. /**
  162. * @Route("/affiliate-tags-list", name="get_affiliate_tags_list", methods={"GET"})
  163. */
  164. public function getAffiliateTagListAction()
  165. {
  166. $affiliateTagsData = $this->doctrine->getRepository(AffiliateTags::class)->getAffiliateTagsByIsDeleted(0);
  167. $uniqueAffiliateTagNames = [];
  168. foreach ($affiliateTagsData as $key => $value) {
  169. if (!in_array($value['tagName'], $uniqueAffiliateTagNames)) {
  170. array_push($uniqueAffiliateTagNames, $value['tagName']);
  171. }
  172. }
  173. $multiselectList = [];
  174. foreach ($uniqueAffiliateTagNames as $tagName) {
  175. $multiselectList[] = [
  176. 'value' => $tagName,
  177. 'label' => $tagName
  178. ];
  179. }
  180. return new JsonResponse($multiselectList);
  181. }
  182. /**
  183. * @Route("/cr-optimisation-cr-relationship-types", name="get_cr_optimisation_cr_relationship_types", methods={"GET"})
  184. */
  185. public function getCrOptimisationCrRelationshipTypesAction()
  186. {
  187. $crOptimisationCrRelationshipType = Config::CR_OPTIMISATION_CR_RELATIONSHIP_TYPE;
  188. $multiselectList = [];
  189. foreach ($crOptimisationCrRelationshipType as $tagName) {
  190. $multiselectList[] = [
  191. 'value' => $tagName,
  192. 'label' => ucwords(str_replace("_", " ", $tagName))
  193. ];
  194. }
  195. return new JsonResponse($multiselectList);
  196. }
  197. /**
  198. * @Route("/goal-id-optimisation-comparison-macros", name="get_goal_id_optimisation_comparison_macros", methods={"GET"})
  199. */
  200. public function getGoalIdOptimisationComparisonMacrosAction()
  201. {
  202. $multiselectList = [];
  203. foreach (Config::GOAL_ID_OPTIMISATION_OPERATOR_COMPARISON_MACROS as $tagName) {
  204. $multiselectList[] = [
  205. 'value' => $tagName,
  206. 'label' => strtoupper(str_replace("_", " ", $tagName))
  207. ];
  208. }
  209. return new JsonResponse($multiselectList);
  210. }
  211. /**
  212. * @Route("/goal-id-optimisation-rule-time-period", name="get_goal_id_optimisation_rule_time_period", methods={"GET"})
  213. */
  214. public function getGoalIdOptimisationRuleTimePeriodAction()
  215. {
  216. $multiselectList = [];
  217. foreach (Config::GOAL_ID_OPTIMISATION_RULE_TIME_PERIOD as $tagName) {
  218. $multiselectList[] = [
  219. 'value' => $tagName,
  220. 'label' => strtoupper(str_replace("_", " ", $tagName))
  221. ];
  222. }
  223. return new JsonResponse($multiselectList);
  224. }
  225. /**
  226. * @Route("/offer-category", name="get_offer_category", methods={"GET"})
  227. */
  228. public function getAllOfferCategoriesByStatus(Request $request)
  229. {
  230. $tuneAccount = $request->query->get('tuneAccount') ?? Config::MAFO_SYSTEM_IDENTIFIER_TUNE_MOBILE;
  231. $offerCategoriesData = $this->commonCalls->getOfferCategoriesListByStatusWithKeys($tuneAccount);
  232. $categoryList = [];
  233. foreach ($offerCategoriesData as $key => $value) {
  234. $categoryList[$key] = [
  235. 'label' => ucwords($value['name']),
  236. 'value' => $value['id']
  237. ];
  238. }
  239. ksort($categoryList);
  240. return new JsonResponse(array_values($categoryList));
  241. }
  242. /**
  243. * @Route("/countries", name="get_countries", methods={"GET"})
  244. */
  245. public function getCountriesAction()
  246. {
  247. $countryList = [];
  248. foreach (Config::COUNTRIES as $key => $value) {
  249. $countryList[$key] = [
  250. 'value' => $key,
  251. 'label' => $key . ' - ' . $value['name']
  252. ];
  253. }
  254. ksort($countryList);
  255. return new JsonResponse(array_values($countryList));
  256. }
  257. /**
  258. * @Route("/currencies", name="get_currencies", methods={"GET"})
  259. */
  260. public function getCurrenciesAction()
  261. {
  262. $currencyList = [];
  263. foreach (Config::CURRENCIES as $key => $value) {
  264. $currencyList[$key] = [
  265. 'value' => $key,
  266. 'label' => $key . ' - ' . $value
  267. ];
  268. }
  269. ksort($currencyList);
  270. return new JsonResponse(array_values($currencyList));
  271. }
  272. /**
  273. * @Route("/tag", name="get_tag", methods={"GET"})
  274. */
  275. public function getTagAction()
  276. {
  277. $tagsInDb = $this->doctrine->getRepository(Tag::class)->getTags(1, 1, null, null);
  278. $tagList = [];
  279. foreach ($tagsInDb as $key => $value) {
  280. $tagList[] = [
  281. 'value' => $value['tagId'],
  282. 'label' => $value['name']
  283. ];
  284. }
  285. ksort($tagList);
  286. return new JsonResponse(array_values($tagList));
  287. }
  288. /**
  289. * @Route("/advertiser-tags", name="get_advertiser_tags", methods={"GET"})
  290. */
  291. public function getAdvertiserTAgsAction(Request $request)
  292. {
  293. $tuneAccount = $request->query->get('tuneAccount');
  294. $tagsInDb = $this->doctrine->getRepository(Tag::class)->getTags(1, null, 1, null, $tuneAccount);
  295. $tagList = [];
  296. foreach ($tagsInDb as $key => $value) {
  297. $tagList[] = [
  298. 'value' => $value['tagId'],
  299. 'label' => $value['name']
  300. ];
  301. }
  302. ksort($tagList);
  303. return new JsonResponse(array_values($tagList));
  304. }
  305. /**
  306. * @Route("/offer-tags", name="get_offer_tags", methods={"GET"})
  307. */
  308. public function getOfferTagsAction()
  309. {
  310. $tagsInDb = $this->doctrine->getRepository(Tag::class)->getTags(1, 1, null, null);
  311. $tagList = [];
  312. foreach ($tagsInDb as $key => $value) {
  313. $tagList[] = [
  314. 'value' => $value['tagId'],
  315. 'label' => $value['name']
  316. ];
  317. }
  318. ksort($tagList);
  319. return new JsonResponse(array_values($tagList));
  320. }
  321. /**
  322. * @Route("/affiliate-tags", name="get_affiliate_ho_tags", methods={"GET"})
  323. */
  324. public function getAffiliateHoTagsAction(Request $request)
  325. {
  326. $tagsInDb = $this->doctrine->getRepository(Tag::class)->getTags(1, null, null, 1, null);
  327. $data = [];
  328. foreach ($tagsInDb as $key => $value) {
  329. $tuneAccount = Config::MAFO_SYSTEM_IDENTIFIER_PRETTY[$value['tuneAccount']] ?? "";
  330. $data[$tuneAccount]['label'] = strtoupper($tuneAccount) . ' ACCOUNT TAGS';
  331. $data[$tuneAccount]['options'][$value['tagId']] = [
  332. 'value' => $value['tagId'],
  333. 'label' => $value['name'],
  334. 'tuneAccount' => $tuneAccount,
  335. 'tuneAccountRaw' => $value['tuneAccount'],
  336. 'color' => Config::MAFO_SYSTEM_IDENTIFIER_TUNE_ACCOUNTS_COLORS[$value['tuneAccount']] ?? "#000"
  337. ];
  338. ksort($data[$tuneAccount]['options']);
  339. }
  340. $finalArr = [];
  341. foreach ($data as $key => $value) {
  342. $finalArr[] = [
  343. 'label' => $value['label'],
  344. 'options' => array_values($value['options']),
  345. ];
  346. }
  347. return new JsonResponse(array_values($finalArr));
  348. }
  349. /**
  350. * @Route("/app-ids", name="get_app_ids", methods={"GET"})
  351. */
  352. public function getAppIdsAction()
  353. {
  354. $appIds = $this->doctrine->getRepository(AppInfo::class)->getAppIds();
  355. $appList = [
  356. [
  357. 'value' => 'Not Found',
  358. 'label' => 'Not Found'
  359. ]
  360. ];
  361. foreach ($appIds as $key => $value) {
  362. $appList[$value['appId']] = [
  363. 'value' => $value['appId'],
  364. 'label' => $value['title']
  365. ];
  366. }
  367. return new JsonResponse(array_values($appList));
  368. }
  369. /**
  370. * @Route("/offer-blocked-from-list", name="get_offer_blocked_from_list", methods={"GET"})
  371. */
  372. public function getOfferBlockedFromList()
  373. {
  374. $offerBlockedFromList = [];
  375. foreach (Config::OFFER_AFFILIATE_BLOCK_FROM_LIST as $key => $value) {
  376. $offerBlockedFromList[] = [
  377. 'value' => $key,
  378. 'label' => $value
  379. ];
  380. }
  381. return new JsonResponse($offerBlockedFromList);
  382. }
  383. /**
  384. * @Route("/approval-control-approval-types", name="get_approval_control_approval_types", methods={"GET"})
  385. */
  386. public function getApprovalControlApprovalTypeAction()
  387. {
  388. $approvalTypes = [];
  389. foreach (Config::APPROVAL_CONTROL_APPROVAL_TYPE as $key => $value) {
  390. $approvalTypes[] = [
  391. 'value' => $key,
  392. 'label' => $value
  393. ];
  394. }
  395. return new JsonResponse($approvalTypes);
  396. }
  397. /**
  398. * @Route("/affiliate-offer-block-types", name="get_affiliate_offer_block_types", methods={"GET"})
  399. */
  400. public function getAffiliateOfferBlockTypesAction()
  401. {
  402. $blockTypes = [
  403. [
  404. 'value' => Config::AFFILIATE_OFFER_BLOCK_MACRO,
  405. 'label' => ucfirst(Config::AFFILIATE_OFFER_BLOCK_MACRO),
  406. ],
  407. [
  408. 'value' => Config::AFFILIATE_OFFER_UNBLOCK_MACRO,
  409. 'label' => ucfirst(Config::AFFILIATE_OFFER_UNBLOCK_MACRO),
  410. ]
  411. ];
  412. return new JsonResponse($blockTypes);
  413. }
  414. /**
  415. * @Route("/platform-types", name="get_platform_types", methods={"GET"})
  416. */
  417. public function getPlatformTypesAction()
  418. {
  419. $platformTypes = [
  420. [
  421. 'value' => Config::PLATFORM_IOS,
  422. 'label' => strtoupper(Config::PLATFORM_IOS)
  423. ],
  424. [
  425. 'value' => Config::PLATFORM_ANDROID,
  426. 'label' => strtoupper(Config::PLATFORM_ANDROID)
  427. ]
  428. ];
  429. return new JsonResponse($platformTypes);
  430. }
  431. /**
  432. * @Route("/mmp-tracking-system", name="get_mmp_tracking_system", methods={"GET"})
  433. */
  434. public function getMmpTrackingSystemAction()
  435. {
  436. $mmpTrackingSystem = [];
  437. foreach (Config::MMP_TRACKING_SYSTEM_PRETTY as $key => $value) {
  438. $mmpTrackingSystem[] = [
  439. 'value' => $key,
  440. 'label' => $value
  441. ];
  442. }
  443. return new JsonResponse($mmpTrackingSystem);
  444. }
  445. /**
  446. * @Route("/mmp-tracking-system-global-network-report", name="get_mmp-tracking-system-global-network-report", methods={"GET"})
  447. */
  448. public function getMmpTrackingSystemForGlobalNetworkReportAction(Request $request)
  449. {
  450. $mmpTrackingSystem = [];
  451. foreach (Config::MMP_TRACKING_SYSTEM_GLOBAL_NETWORK_REPORT_PRETTY as $key => $value) {
  452. $mmpTrackingSystem[] = [
  453. 'value' => $key,
  454. 'label' => $value
  455. ];
  456. }
  457. return new JsonResponse($mmpTrackingSystem);
  458. }
  459. /**
  460. * @Route("/app-info/{appId}", name="get_app_info", methods={"GET"})
  461. */
  462. public function geAppInfoAction(Request $request, $appId)
  463. {
  464. $appInfoData = $this->doctrine->getRepository(AppInfo::class)->getDataByAppIds([$appId]);
  465. $appInfo = [];
  466. foreach ($appInfoData as $key => $value) {
  467. $appInfo[$value['appId']] = $value;
  468. }
  469. return new JsonResponse($appInfo);
  470. }
  471. /**
  472. * @Route("/tag-attributes/{attributeType}", name="get_tag_attributes", methods={"GET"})
  473. */
  474. public function getOperatingSystemAction(Request $request, $attributeType)
  475. {
  476. $tuneAccount = $request->query->get('tuneAccount');
  477. $attributes = [];
  478. if (array_key_exists($attributeType, Config::TAG_ATTRIBUTES)) {
  479. $attributeData = $this->doctrine->getRepository(Tag::class)->getTagsByAttribute(Config::TAG_ATTRIBUTES[$attributeType], $tuneAccount);
  480. foreach ($attributeData as $key => $value) {
  481. $attributes[] = [
  482. 'value' => (string)$value['tagId'],
  483. 'label' => $value['name']
  484. ];
  485. }
  486. }
  487. return new JsonResponse($attributes);
  488. }
  489. /**
  490. * @Route("/timezones", name="get_timezone", methods={"GET"})
  491. */
  492. public function getTimezonesAction(Request $request)
  493. {
  494. $timezones = [];
  495. foreach (Config::TIMEZONES as $key => $value) {
  496. $timezones[] = [
  497. 'value' => $key,
  498. 'label' => $value
  499. ];
  500. }
  501. return new JsonResponse($timezones);
  502. }
  503. /**
  504. * @Route("/advertisers", name="get_advertisers", methods={"GET"})
  505. */
  506. public function getAdvertisersAction(Request $request)
  507. {
  508. $keyword = $request->query->get('keyword');
  509. $tuneAccount = $request->query->get('tuneAccount') ?? Config::MAFO_SYSTEM_IDENTIFIER_TUNE_MOBILE;
  510. $dataByKeyword = $this->doctrine->getRepository(AdvertiserInfo::class)->getAdvertiserByKeyword($keyword, $tuneAccount);
  511. $arr = [];
  512. foreach ($dataByKeyword as $key => $value) {
  513. $temp = [
  514. 'value' => (int)$value['advertiserId'],
  515. 'label' => $value['advertiserId'] . ' - ' . $value['company'],
  516. 'status' => $value['status']
  517. ];
  518. $arr[$value['advertiserId']] = $temp;
  519. }
  520. ksort($arr);
  521. return new JsonResponse(array_values($arr));
  522. }
  523. /**
  524. * @Route("/cohorttype", name="get_cohorttype", methods={"GET"})
  525. */
  526. public function getCohortTypeAction(Request $request)
  527. {
  528. $temp = [
  529. [
  530. 'value' => 'cohort_user_acquisition_agency',
  531. 'label' => 'User acquisition',
  532. ],
  533. [
  534. 'value' => 'cohort_retargeting_agency',
  535. 'label' => 'Retargeting',
  536. ],
  537. [
  538. 'value' => 'cohort_unified_agency',
  539. 'label' => 'Unified',
  540. ],
  541. ];
  542. $arr = [];
  543. foreach ($temp as $item) {
  544. $arr[$item['label']] = [
  545. 'value' => $item['value'],
  546. 'label' => $item['label'],
  547. ];
  548. }
  549. ksort($arr);
  550. return new JsonResponse(array_values($arr));
  551. }
  552. /**
  553. * @Route("/affiliates", name="get_affiliates", methods={"GET"})
  554. */
  555. public
  556. function getAffiliatesAction(Request $request)
  557. {
  558. $keyword = $request->query->get('keyword');
  559. $tuneAccount = $request->query->get('tuneAccount') ?? Config::MAFO_SYSTEM_IDENTIFIER_TUNE_MOBILE;
  560. $dataByKeyword = $this->doctrine->getRepository(AffiliateInfo::class)->getAffiliateByKeyword($keyword, $tuneAccount);
  561. $arr = [];
  562. foreach ($dataByKeyword as $key => $value) {
  563. $temp = [
  564. 'value' => (int)$value['affiliateId'],
  565. 'label' => $value['affiliateId'] . ' - ' . $value['company'],
  566. 'status' => $value['status']
  567. ];
  568. $arr[$value['affiliateId']] = $temp;
  569. }
  570. ksort($arr);
  571. return new JsonResponse(array_values($arr));
  572. }
  573. /**
  574. * @Route("/user", name="get_user", methods={"GET"})
  575. */
  576. public
  577. function getUerAction(Request $request, TokenStorageInterface $tokenStorage)
  578. {
  579. $roles = $this->getUser()->getRoles();
  580. // if (is_array($this->getUser()->getRoles()) && in_array(Config::ROLE_DIRECTOR, $this->getUser()->getRoles())) {
  581. // $roles = array_values(array_unique(array_merge( $this->getUser()->getRoles(), [Config::ROLE_ADMIN])));
  582. // }
  583. $token = $this->security->getToken();
  584. $loggedAsImpersonator = false;
  585. if ($token instanceof SwitchUserToken) {
  586. $loggedAsImpersonator = true;
  587. }
  588. $userData = [
  589. 'name' => $this->getUser()->getName(),
  590. 'email' => $this->getUser()->getEmail(),
  591. 'roles' => $roles,
  592. 'isAdmin' => $this->isGranted(Config::ROLE_ADMIN),
  593. 'profilePicture' => $this->getUser()->getPicture(),
  594. 'env' => $this->getParameter('kernel.environment'),
  595. 'isLoggedIntoMts' => true,
  596. 'token' => $this->getUser()->getJwtToken()
  597. ];
  598. if ($loggedAsImpersonator) {
  599. $userData['loggedInAsImpersonator'] = true;
  600. }
  601. return new JsonResponse($userData);
  602. }
  603. /**
  604. * @Route("/offers-by-advertiser/{advertiserId}", name="get_offers_by_advertiser_id", methods={"GET"})
  605. */
  606. public
  607. function getOffersByAdvertiserAction(Request $request, $advertiserId)
  608. {
  609. $offers = [];
  610. $status = $request->query->get('status') != '' ? $request->query->get('status') : [Config::ACTIVE_STATUS];
  611. $tuneAccount = $request->query->get('tuneAccount') != '' ? $request->query->get('tuneAccount') : [Config::TUNE_DEFAULT_ACCOUNT_LABEL];
  612. $search = $request->query->get('search', '');
  613. $offersByAdvertiser = $this->doctrine->getRepository(OfferInfo::class)->getOfferIdsByAdvertiserIdAndStatusArr($advertiserId, $status, $tuneAccount, $search);
  614. foreach ($offersByAdvertiser as $key => $value) {
  615. $offers[] = [
  616. 'value' => $value['offerId'],
  617. 'label' => $value['offerId'] . ' - ' . $value['name']
  618. ];
  619. }
  620. return new JsonResponse($offers);
  621. }
  622. /**
  623. * @Route("/mafo-offers-by-advertiser/{advertiserId}", name="get_mafo_offers_by_advertiser_id", methods={"GET"})
  624. */
  625. public
  626. function getMafoOffersByAdvertiserAction(Request $request, $advertiserId)
  627. {
  628. $offers = [];
  629. $status = $request->query->all('status') != '' ? [] : [Config::ACTIVE_STATUS];
  630. $search = $request->query->get('search', '');
  631. $offersByAdvertiser = $this->doctrine->getRepository(MafoOffers::class)->getOfferIdsByAdvertiserIdAndStatusArr($advertiserId, $status, $search);
  632. foreach ($offersByAdvertiser as $key => $value) {
  633. $offers[$value['systemIdentifier']]['label'] = strtoupper($value['systemIdentifier']) . ' ACCOUNT OFFERS';
  634. $offers[$value['systemIdentifier']]['options'][$value['id']] = [
  635. 'value' => $value['id'],
  636. 'label' => $value['id'] . ' - ' . $value['name'] . ' [' . $value['systemIdentifierId'] . ']',
  637. 'systemIdentifier' => $value['systemIdentifier'],
  638. 'systemIdentifierId' => $value['systemIdentifierId'],
  639. ];
  640. ksort($offers[$value['systemIdentifier']]['options']);
  641. }
  642. $finalArr = [];
  643. foreach ($offers as $key => $value) {
  644. $finalArr[] = [
  645. 'label' => $value['label'],
  646. 'options' => array_values($value['options']),
  647. ];
  648. }
  649. return new JsonResponse($finalArr);
  650. }
  651. /**
  652. * @Route("/deduction-control-activity-source", name="get_deduction_control_activity_source", methods={"GET"})
  653. */
  654. public
  655. function getDeductionControlActivitySourceAction(Request $request)
  656. {
  657. $arr = [];
  658. foreach (Config::DEDUCTION_CONTROL_ACTIVITY_SOURCE_ARRAY as $activitySource) {
  659. $arr[] = [
  660. 'value' => $activitySource,
  661. 'label' => $activitySource
  662. ];
  663. }
  664. return new JsonResponse($arr);
  665. }
  666. /**
  667. * @Route("/deduction-control-status", name="get_deduction_control_status", methods={"GET"})
  668. */
  669. public
  670. function getDeductionControlStatusAction(Request $request)
  671. {
  672. $arr = [];
  673. foreach (Config::DEDUCTION_CONTROL_STATUS as $status) {
  674. $arr[] = [
  675. 'value' => $status,
  676. 'label' => ucfirst($status)
  677. ];
  678. }
  679. return new JsonResponse($arr);
  680. }
  681. /**
  682. * @Route("/file-download", name="get_file_download", methods={"GET"})
  683. */
  684. public
  685. function getFileDownloadAction(Request $request)
  686. {
  687. $fileKey = $request->query->get('fileKey');
  688. $directory = $request->query->get('directory');
  689. echo ($this->s3->getFileFromS3($directory, $fileKey));
  690. exit;
  691. }
  692. /**
  693. * @Route("/offer-search", name="get_offer_search_empty", methods={"GET"})
  694. */
  695. public
  696. function getOfferSearchEmptyAction(Request $request)
  697. {
  698. return new JsonResponse([]);
  699. }
  700. /**
  701. * @Route("/offer-search/{keyword}", name="get_offer_search", methods={"GET"})
  702. */
  703. public
  704. function getOfferSearchBYKeywordAction(Request $request, $keyword)
  705. {
  706. $offerInfo = $this->doctrine->getRepository(OfferInfo::class)->getOffersWhereNameLike(Config::ACTIVE_STATUS, $keyword);
  707. $data = [];
  708. foreach ($offerInfo as $key => $value) {
  709. $data[] = [
  710. 'value' => $value['offerId'],
  711. 'label' => $value['offerId'] . ' - ' . $value['name'],
  712. 'skadNetworkMmp' => $value['skadNetworkMmp']
  713. ];
  714. }
  715. return new JsonResponse($data);
  716. }
  717. /**
  718. * @Route("/offer-search-by-tune-accounts/{keyword}", methods={"GET"})
  719. */
  720. public
  721. function getOfferSearchByTuneAccountsAndKeywordAction(Request $request, $keyword)
  722. {
  723. $offerInfo = $this->doctrine->getRepository(OfferInfo::class)->getOffersWhereNameLike(Config::ACTIVE_STATUS, $keyword);
  724. if (empty($offerInfo)) {
  725. $offerInfoPending = $this->doctrine->getRepository(OfferInfo::class)->getOffersWhereNameLike(Config::PENDING_STATUS, $keyword);
  726. $offerInfoPaused = $this->doctrine->getRepository(OfferInfo::class)->getOffersWhereNameLike(Config::PAUSED_STATUS, $keyword);
  727. $offerInfo = array_merge($offerInfoPending, $offerInfoPaused);
  728. }
  729. $data = [];
  730. foreach ($offerInfo as $key => $value) {
  731. $tuneAccount = Config::MAFO_SYSTEM_IDENTIFIER_PRETTY[$value['tuneAccount']] ?? "";
  732. $offerIdToDisplay = $value['offerId'];
  733. $data[$tuneAccount]['label'] = strtoupper($tuneAccount) . ' ACCOUNT OFFER IDS';
  734. $data[$tuneAccount]['options'][$value['offerId']] = [
  735. 'value' => $value['offerId'],
  736. 'label' => $offerIdToDisplay . ' - ' . $value['name'],
  737. 'tuneAccount' => $value['tuneAccount'],
  738. 'tuneAccountRaw' => $value['tuneAccount'],
  739. 'color' => Config::MAFO_SYSTEM_IDENTIFIER_TUNE_ACCOUNTS_COLORS[$tuneAccount] ?? "#000"
  740. ];
  741. ksort($data[$tuneAccount]['options']);
  742. }
  743. $finalArr = [];
  744. foreach ($data as $key => $value) {
  745. $finalArr[] = [
  746. 'label' => $value['label'],
  747. 'options' => array_values($value['options']),
  748. ];
  749. }
  750. return new JsonResponse($finalArr);
  751. }
  752. /**
  753. * @Route("/click-cap-block-period-list", name="get_click_cap_block_period_list", methods={"GET"})
  754. */
  755. public
  756. function getClickCapBlockPeriodListAction(Request $request)
  757. {
  758. $list = [];
  759. foreach (Config::CLICK_CAP_BLOCK_PERIOD_LIST as $key => $value) {
  760. $list[] = [
  761. 'value' => $key,
  762. 'label' => $value
  763. ];
  764. }
  765. return new JsonResponse($list);
  766. }
  767. /**
  768. * @Route("/skadnetwork-mmp-list", name="get_skadnetwork_mmp_list", methods={"GET"})
  769. */
  770. public
  771. function getSkadnetworkMmpListAction(Request $request)
  772. {
  773. $list = [];
  774. foreach (Config::SKADNETOWRK_MMP as $key => $value) {
  775. $list[] = [
  776. 'value' => $value,
  777. 'label' => ucfirst($value)
  778. ];
  779. }
  780. return new JsonResponse($list);
  781. }
  782. /**
  783. * @Route("/skadnetwork-enabled-offer-by-app-id/{appId}", name="get_skadnetwork_enabled-offer_by_app_id", methods={"GET"})
  784. */
  785. public
  786. function getSkadNetworkEnabledOfferByAppId(Request $request, $appId)
  787. {
  788. $offerInfo = [];
  789. if ($appId) {
  790. $offerInfo = $this->doctrine->getRepository('App\Entity\Tune\OfferInfo')->getSkadEnaledOfferInfoByAppId($appId, 1);
  791. }
  792. $offerIds = [];
  793. foreach ($offerInfo as $key => $value) {
  794. $offerIds[] = $value['offerId'];
  795. }
  796. return new JsonResponse($offerIds);
  797. }
  798. /**
  799. * @Route("/mafo-users", name="get_mafo_users", methods={"GET"})
  800. */
  801. public
  802. function getMafoUsersAction(Request $request)
  803. {
  804. $role = $request->query->get('role') !== 'undefined' ? $request->query->get('role') : false;
  805. $users = $this->doctrine->getRepository('App\Entity\Users')->getUsers();
  806. $roles = [];
  807. if ($role === Config::ROLE_SALES) {
  808. $roles = [$role, Config::ROLE_ADMIN];
  809. }
  810. $arr = [];
  811. foreach ($users as $key => $value) {
  812. if ($roles) {
  813. if (array_intersect($roles, $value['roles'])) {
  814. $arr[$value['email']] = [
  815. 'value' => $value['email'],
  816. 'label' => $value['name'] . "[{$value['email']}]"
  817. ];
  818. }
  819. } else {
  820. $arr[$value['email']] = [
  821. 'value' => $value['email'],
  822. 'label' => $value['name'] . " [{$value['email']}]"
  823. ];
  824. }
  825. }
  826. ksort($arr);
  827. return new JsonResponse(array_values($arr));
  828. }
  829. /**
  830. * @Route("/mafo-users-position", name="get_mafo_users_position", methods={"GET"})
  831. */
  832. public
  833. function getMafoUsersPostionAction(Request $request)
  834. {
  835. $users = $this->doctrine->getRepository('App\Entity\Users')->getUsers([
  836. 'status' => ['value' => [Config::ACTIVE_STATUS], 'excludeFlag' => false]
  837. ]);
  838. $arr = [];
  839. foreach ($users as $key => $value) {
  840. if ($value['position']) {
  841. $arr[$value['position']] = [
  842. 'value' => $value['position'],
  843. 'label' => $value['position']
  844. ];
  845. }
  846. }
  847. ksort($arr);
  848. return new JsonResponse(array_values($arr));
  849. }
  850. /**
  851. * @Route("/report-columns/{report}", name="get_report_columns", methods={"GET"})
  852. */
  853. public
  854. function getReportColumnsAction(Request $request, $report)
  855. {
  856. if ($report === Config::REPORT_ADVERTISER_MACRO) {
  857. $savedCols = Config::REPORT_ADVERTISER_COLUMNS;
  858. $col = [];
  859. foreach ($savedCols as $key => $value) {
  860. $value['accessor'] = str_replace(".", Config::REPORT_ADVERTISER_ACCESSOR_SEPARATOR, $value['accessor']);
  861. $col[] = $value;
  862. }
  863. return new JsonResponse($col);
  864. } elseif (in_array($report, array_keys(Config::TABLE_COLUMNS_WITH_JSON_FILE))) {
  865. // echo json_Encode(Config::TABLE_COLUMNS_WITH_JSON_FILE[$report]);die;
  866. return new JsonResponse(array_values($this->commonCalls->getDataFromJsonFile(Config::TABLE_COLUMNS_WITH_JSON_FILE[$report])));
  867. } else {
  868. return new JsonResponse(array_values(Config::REPORT_COLUMN_MAPPING[$report]));
  869. }
  870. }
  871. /**
  872. * @Route("/table-columns/{table}", name="get_table_columns", methods={"GET"})
  873. */
  874. public
  875. function getTableColumnsAction(Request $request, $table)
  876. {
  877. return new JsonResponse(array_values($this->commonCalls->getDataFromJsonFile(Config::TABLE_COLUMNS_WITH_JSON_FILE[$table])));
  878. }
  879. /**
  880. * @Route("/skad-network-endpoints", name="get_skad_network_endpoints", methods={"GET"})
  881. */
  882. public
  883. function getSkadNetworkEndpointsAction(Request $request)
  884. {
  885. $arr = [];
  886. foreach (Config::SKADNETWORK_POSTBACK_ENDPOINT as $key => $value) {
  887. $arr[] = [
  888. 'value' => $value,
  889. 'label' => $value
  890. ];
  891. }
  892. return new JsonResponse($arr);
  893. }
  894. /**
  895. * @Route("/deduction-insights-statuses", name="get_deduction_insights_status_filter", methods={"GET"})
  896. */
  897. public
  898. function getDeductionInsightsStatusesAction(Request $request)
  899. {
  900. $data = [];
  901. foreach (Config::DEDUCTION_INSIGHTS_STATUS_ARRAY as $value) {
  902. $data[] = [
  903. 'value' => $value,
  904. 'label' => $value,
  905. ];
  906. }
  907. return new JsonResponse($data);
  908. }
  909. /**
  910. * @Route("/adjust-mmp-accounts", name="get_adjust_mmp_accounts", methods={"GET"})
  911. */
  912. public
  913. function getAdjustMmpAccountsAction(Request $request)
  914. {
  915. $data = [];
  916. foreach (array_keys(Config::MMP_ADJUST_ACCOUNT_TOKEN_MAPPING) as $value) {
  917. $data[] = [
  918. 'value' => $value,
  919. 'label' => ucfirst($value) . " [" . Config::MMP_ADJUST_ACCOUNT_EMAIL_MAPPING[$value] . "]",
  920. ];
  921. }
  922. return new JsonResponse($data);
  923. }
  924. /**
  925. * @Route("/mmp-notification-rule-by-field", name="get_mmp_notification_rule_by_field", methods={"GET"})
  926. */
  927. public
  928. function getMmpNotificationRuleByFieldAction(Request $request)
  929. {
  930. $data = [];
  931. foreach (Config::MMP_NOTIFICATION_RULE_BY_FIELD_ARRAY as $key => $value) {
  932. $data[] = [
  933. 'value' => $key,
  934. 'label' => $value
  935. ];
  936. }
  937. return new JsonResponse($data);
  938. }
  939. /**
  940. * @Route("/mmp-notification-rule-by-type", name="get_mmp_notification_rule_by_type", methods={"GET"})
  941. */
  942. public
  943. function getMmpNotificationRuleByTypeAction(Request $request)
  944. {
  945. $data = [];
  946. foreach (Config::MMP_NOTIFICATION_RULE_BY_TYPE_ARRAY as $key => $value) {
  947. $data[] = [
  948. 'value' => $key,
  949. 'label' => $value
  950. ];
  951. }
  952. return new JsonResponse($data);
  953. }
  954. /**
  955. * @Route("/mmp-offer-events", name="get_mmp_offer_events", methods={"GET"})
  956. */
  957. public
  958. function getMmpOfferEventsAction(Request $request)
  959. {
  960. // $mmpStatisticsEvents = $this->doctrine->getRepository(MmpOffers::class)->getDistinctEvents();
  961. $mmpReportsEvents = $this->doctrine->getRepository(MmpReports::class)->getDistinctEvents();
  962. $arr = [];
  963. foreach ($mmpReportsEvents as $key => $value) {
  964. $eventName = $value['mmpSource'] == (Config::MMP_TRACKING_SYSTEM_TUNE_MOBILE || $value['mmpSource'] == Config::MMP_TRACKING_SYSTEM_TUNE_WEB) ? $value['mmpOfferDefaultRevenueEventName'] : $value['event'];
  965. $index = $value['event'] . '#' . $eventName;
  966. $arr[$index] = [
  967. 'value' => $value['event'],
  968. 'label' => $eventName . " [ID: {$value['event']}]" . " [MMP: {$value['mmpSource']}]"
  969. ];
  970. }
  971. return new JsonResponse(array_values($arr));
  972. }
  973. /**
  974. * @Route("/mmp-offer-list", name="get_mmp_offer_list", methods={"GET"})
  975. */
  976. public
  977. function getMmpOfferListAction(Request $request)
  978. {
  979. $data = $this->doctrine->getRepository(MmpOffers::class)->getMmpOffersDataByIsDeleted(0);
  980. $arr = [];
  981. foreach ($data as $key => $value) {
  982. $arr[$value['id']] = [
  983. 'value' => $value['id'],
  984. 'label' => $value['id'] . ' - ' . $value['offerName']
  985. ];
  986. }
  987. ksort($arr);
  988. return new JsonResponse(array_values($arr));
  989. }
  990. /**
  991. * @Route("/mmp-notification-period", name="get_mmp_notifications_period", methods={"GET"})
  992. */
  993. public
  994. function getMmpNotificationsPeriodAction(Request $request)
  995. {
  996. $arr = [];
  997. foreach (Config::MMP_NOTIFICATION_PERIOD_ARRAY as $key => $value) {
  998. $arr[] = [
  999. 'value' => $key,
  1000. 'label' => $value
  1001. ];
  1002. }
  1003. return new JsonResponse($arr);
  1004. }
  1005. /**
  1006. * @Route("/skad-postback-app-ids", name="get_skad_postback_app_ids", methods={"GET"})
  1007. */
  1008. public
  1009. function getSkadPostbacksAppIdsAction(Request $request)
  1010. {
  1011. $postbackLogsData = $this->doctrine->getRepository(SkadNetworkPostbackLogs::class)->getSkadNetworkPostbackAppIds();
  1012. $arr = [];
  1013. foreach ($postbackLogsData as $key => $value) {
  1014. if ($value['appId']) {
  1015. $arr[] = [
  1016. 'value' => $value['appId'],
  1017. 'label' => "id" . $value['appId'],
  1018. ];
  1019. }
  1020. }
  1021. return new JsonResponse($arr);
  1022. }
  1023. /**
  1024. * @Route("/skad-postback-campaign-ids", name="get_skad_postback_campaign_ids", methods={"GET"})
  1025. */
  1026. public
  1027. function getSkadPostbacksCampaignIdsAction(Request $request)
  1028. {
  1029. $postbackLogsData = $this->doctrine->getRepository(SkadNetworkPostbackLogs::class)->getSkadNetworkPostbackCampaignIds();
  1030. $arr = [];
  1031. foreach ($postbackLogsData as $key => $value) {
  1032. $arr[] = [
  1033. 'value' => (string)$value['campaignId'],
  1034. 'label' => (string)$value['campaignId'],
  1035. ];
  1036. }
  1037. return new JsonResponse($arr);
  1038. }
  1039. /**
  1040. * @Route("/organisation-chart", name="get_org_chart", methods={"GET"})
  1041. */
  1042. public
  1043. function getTestAction(Request $request)
  1044. {
  1045. $parentChildRelationship = $this->doctrine->getRepository(UsersHierarchy::class)->checkChildParentRelationship();
  1046. $usersInfo = $this->usersComponents->getUsersDataByEmailIdAsKey(true);
  1047. $organisationData = [];
  1048. foreach ($parentChildRelationship as $key => $value) {
  1049. $organisationData[] = [
  1050. 'name' => array_key_exists($value['child'], $usersInfo) ? $usersInfo[$value['child']]['name'] : '',
  1051. 'imageUrl' => array_key_exists($value['child'], $usersInfo) ? $usersInfo[$value['child']]['picture'] : '',
  1052. 'area' => array_key_exists($value['child'], $usersInfo) ? $usersInfo[$value['child']]['userInfo'] : '',
  1053. 'profileUrl' => array_key_exists($value['child'], $usersInfo) ? $usersInfo[$value['child']]['picture'] : '',
  1054. 'office' => array_key_exists($value['child'], $usersInfo) ? $usersInfo[$value['child']]['userInfo'] : '',
  1055. 'tags' => '',
  1056. 'positionName' => array_key_exists($value['child'], $usersInfo) ? ($usersInfo[$value['child']]['position'] ?? '') : '',
  1057. 'id' => $value['child'],
  1058. 'parentId' => $value['parent'] ?? '',
  1059. 'parentName' => $value['parent'] ? $usersInfo[$value['parent']]['name'] : '',
  1060. 'team' => array_key_exists($value['child'], $usersInfo) ? $usersInfo[$value['child']]['team'] : '',
  1061. 'userInfo' => array_key_exists($value['child'], $usersInfo) ? $usersInfo[$value['child']]['userInfo'] : '',
  1062. 'size' => '',
  1063. ];
  1064. }
  1065. return new JsonResponse($organisationData);
  1066. }
  1067. /**
  1068. * @Route("/revenue-control-statuses", name="get_revenue_control_statuses", methods={"GET"})
  1069. */
  1070. public
  1071. function getRevenueControlStatusesAction(Request $request)
  1072. {
  1073. $arr = [];
  1074. foreach (Config::REVENUE_CONTROL_STATUSES as $key => $value) {
  1075. $arr[] = [
  1076. 'value' => $value,
  1077. 'label' => ucfirst($value),
  1078. ];
  1079. }
  1080. return new JsonResponse($arr);
  1081. }
  1082. /**
  1083. * @Route("/payout-control-statuses", name="get_payout_control_statuses", methods={"GET"})
  1084. */
  1085. public
  1086. function getPayoutControlStatusesAction(Request $request)
  1087. {
  1088. $arr = [];
  1089. foreach (Config::PAYOUT_CONTROL_STATUSES as $key => $value) {
  1090. $arr[] = [
  1091. 'value' => $value,
  1092. 'label' => ucfirst($value),
  1093. ];
  1094. }
  1095. return new JsonResponse($arr);
  1096. }
  1097. /**
  1098. * @Route("/hyper-statuses", name="get_hyper_statuses", methods={"GET"})
  1099. */
  1100. public
  1101. function getHyperStatusesAction(Request $request)
  1102. {
  1103. $arr = [];
  1104. foreach (array_values(Config::HYPER_STATUS_MAFO_MACROS) as $key => $value) {
  1105. $arr[$value] = [
  1106. 'value' => $value,
  1107. 'label' => $value,
  1108. ];
  1109. }
  1110. return new JsonResponse(array_values($arr));
  1111. }
  1112. /**
  1113. * @Route("/affiliate-hyper-statuses", name="get_affiliate_hyper_statuses", methods={"GET"})
  1114. */
  1115. public
  1116. function getAffiliateHyperStatusesAction(Request $request)
  1117. {
  1118. $arr = [];
  1119. foreach (array_values(Config::HYPER_STATUS_AFFILIATE_MAFO_MACROS) as $key => $value) {
  1120. $arr[$value] = [
  1121. 'value' => $value,
  1122. 'label' => $value,
  1123. ];
  1124. }
  1125. return new JsonResponse(array_values($arr));
  1126. }
  1127. /**
  1128. * @Route("/oauth", name="get_oauth", methods={"GET"})
  1129. */
  1130. public
  1131. function getOauthAction(Request $request)
  1132. {
  1133. return new JsonResponse(true);
  1134. }
  1135. /**
  1136. * @Route("/revenue-total-billing-statuses", name="get_revenue_total_billing_statuses", methods={"GET"})
  1137. */
  1138. public
  1139. function getRevenueTotalBillingStatusesAction(Request $request)
  1140. {
  1141. $arr = [];
  1142. foreach (Config::REVENUE_TOTAL_BILLING_STATUSES as $key => $value) {
  1143. $arr[] = [
  1144. 'value' => $key,
  1145. 'label' => $value
  1146. ];
  1147. }
  1148. return new JsonResponse($arr);
  1149. }
  1150. /**
  1151. * @Route("/mobupps-teams", name="get_mobupps_teams_utilities", methods={"GET"})
  1152. */
  1153. public
  1154. function getMobuppsTeamUtilitiesAction(Request $request)
  1155. {
  1156. return new JsonResponse(array_values($this->usersComponents->getTeamsByTeamIdWithNonEmptyTeams()));
  1157. }
  1158. /**
  1159. * @Route("/empty-list", name="get_empty_list", methods={"GET"})
  1160. */
  1161. public
  1162. function getEmptyListAction(Request $request)
  1163. {
  1164. return new JsonResponse([]);
  1165. }
  1166. /**
  1167. * @Route("/gap-control-cost-type", name="get_gap_control_cost_type", methods={"GET"})
  1168. */
  1169. public
  1170. function getGapControlCostType(Request $request)
  1171. {
  1172. return new JsonResponse([
  1173. [
  1174. 'value' => 'gross',
  1175. 'label' => 'Gross Cost'
  1176. ],
  1177. [
  1178. 'value' => 'approved',
  1179. 'label' => 'Approved Cost'
  1180. ],
  1181. ]);
  1182. }
  1183. /**
  1184. * @Route("/log-entities", name="get_log_entities", methods={"GET"})
  1185. */
  1186. public
  1187. function getLogEntitiesAction(Request $request)
  1188. {
  1189. $arr = [];
  1190. foreach (Config::ENTITIES_TO_LOG as $key => $value) {
  1191. $arr[$value] = [
  1192. 'value' => $value,
  1193. 'label' => $value
  1194. ];
  1195. }
  1196. ksort($arr);
  1197. return new JsonResponse(array_values($arr));
  1198. }
  1199. /**
  1200. * @Route("/alert-medium", name="get_alert_mediums", methods={"GET"})
  1201. */
  1202. public
  1203. function getAlertMediumsAction(Request $request)
  1204. {
  1205. $arr = [];
  1206. foreach (Config::ALERT_MEDIUMS as $key => $value) {
  1207. $arr[$value] = [
  1208. 'value' => $value,
  1209. 'label' => strtoupper($value)
  1210. ];
  1211. }
  1212. ksort($arr);
  1213. return new JsonResponse(array_values($arr));
  1214. }
  1215. /**
  1216. * @Route("/alert-categories", name="get_alert_categories", methods={"GET"})
  1217. */
  1218. public
  1219. function getAlertCategoriesAction(Request $request)
  1220. {
  1221. $arr = [];
  1222. foreach (Config::ALERT_CATEGORIES as $key => $value) {
  1223. $arr[$value] = [
  1224. 'value' => $value,
  1225. 'label' => $value
  1226. ];
  1227. }
  1228. ksort($arr);
  1229. return new JsonResponse(array_values($arr));
  1230. }
  1231. /**
  1232. * @Route("/alert-names", name="get_alert_names", methods={"GET"})
  1233. */
  1234. public
  1235. function getAlertNameAction(Request $request)
  1236. {
  1237. $arr = [];
  1238. foreach (Config::ALERTS_LIST as $key => $value) {
  1239. $arr[] = [
  1240. 'value' => $value,
  1241. 'label' => $value
  1242. ];
  1243. }
  1244. ksort($arr);
  1245. return new JsonResponse(array_values($arr));
  1246. }
  1247. /**
  1248. * @Route("/boolean-select", name="get_boolean_select", methods={"GET"})
  1249. */
  1250. public
  1251. function getBooleanSelectAction(Request $request)
  1252. {
  1253. return new JsonResponse([
  1254. [
  1255. 'value' => true,
  1256. 'label' => 'YES',
  1257. ],
  1258. [
  1259. 'value' => false,
  1260. 'label' => 'NO',
  1261. ],
  1262. ]);
  1263. }
  1264. /**
  1265. * @Route("/site-id-select", name="get_site_id_select", methods={"GET"})
  1266. */
  1267. public
  1268. function getSiteIdSelectAction(Request $request)
  1269. {
  1270. $siteIds = $this->doctrine->getRepository(MmpReports::class)->getDistinctSiteIds();
  1271. $arr = [];
  1272. foreach ($siteIds as $siteIdRow) {
  1273. if (!empty($siteIdRow["siteId"])) {
  1274. $arr[$siteIdRow["siteId"]] = [
  1275. 'value' => $siteIdRow["siteId"],
  1276. 'label' => $siteIdRow["siteId"]
  1277. ];
  1278. }
  1279. }
  1280. ksort($arr);
  1281. return new JsonResponse(array_values($arr));
  1282. }
  1283. /**
  1284. * @Route("/alert-view/{id}", name="get_alert_view", methods={"GET"})
  1285. */
  1286. public
  1287. function getAlertViewAction(Request $request, $id)
  1288. {
  1289. $alertData = $this->doctrine->getRepository(AlertLogs::class)->findOneBy(['md5' => $id]);
  1290. $mailToName = '';
  1291. $userInfo = $this->doctrine->getRepository(Users::class)->findOneBy(['email' => $alertData->getMailTo() ?? null]);
  1292. if ($userInfo) {
  1293. $mailToName = $userInfo->getName();
  1294. }
  1295. return $this->render('/alerts/defaultAlertWithTableData.html.twig', [
  1296. 'headers' => is_string($alertData->getMailHeaderJson()) ? json_decode($alertData->getMailHeaderJson(), true) : $alertData->getMailHeaderJson(),
  1297. 'tableData' => is_string($alertData->getMailBodyJson()) ? json_decode($alertData->getMailBodyJson(), true) : $alertData->getMailBodyJson(),
  1298. 'name' => $mailToName,
  1299. 'corollary' => $alertData->getAlertForward()
  1300. ]);
  1301. }
  1302. /**
  1303. * @Route("/alert-csv-download/{id}", name="get_alert_csv_download", methods={"GET"})
  1304. */
  1305. public
  1306. function getAlertCsvDownloadAction(Request $request, $id)
  1307. {
  1308. $alertData = $this->doctrine->getRepository(\App\Entity\AlertLogs::class)->findOneBy(['md5' => $id]);
  1309. $alertName = $alertData->getAlertAction();
  1310. // var_dump($alertData);die;
  1311. $headers = is_string($alertData->getMailHeaderJson()) ? json_decode($alertData->getMailHeaderJson(), true) : $alertData->getMailHeaderJson();
  1312. $tableData = is_string($alertData->getMailBodyJson()) ? json_decode($alertData->getMailBodyJson(), true) : $alertData->getMailBodyJson();
  1313. // echo json_encode($tableData);die;
  1314. $rows = [array_column($headers, 'label')];
  1315. foreach ($tableData as $key => $value) {
  1316. $temp = [];
  1317. foreach ($headers as $k => $v) {
  1318. if (is_array($value[$k]['value'])) {
  1319. $tempArr = [];
  1320. foreach ($value[$k]['value'] as $subKey => $subValue) {
  1321. $tempArr[] = "$subKey: $subValue";
  1322. }
  1323. $temp[] = implode("\n", $tempArr);
  1324. } else {
  1325. $temp[] = $value[$k]['value'];
  1326. }
  1327. }
  1328. $rows[] = $temp;
  1329. }
  1330. $spreadsheet = new Spreadsheet();
  1331. $spreadsheet->getProperties()->setCreator('MAFO')
  1332. ->setLastModifiedBy('MAFO')
  1333. ->setTitle($alertName)
  1334. ->setSubject($alertName)
  1335. ->setDescription($alertName);
  1336. $spreadsheet->getActiveSheet()
  1337. ->fromArray(
  1338. $rows,
  1339. NULL,
  1340. 'A1'
  1341. );
  1342. header('Content-Type: application/vnd.ms-excel');
  1343. header('Content-Disposition: attachment;filename="' . $alertName . '.xls"');
  1344. header('Cache-Control: max-age=0');
  1345. $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
  1346. $writer->save('php://output');
  1347. exit;
  1348. }
  1349. /**
  1350. * @Route("/affiliate-categories", name="get_affiliate_categories", methods={"GET"})
  1351. */
  1352. public
  1353. function getAffiliateCategoriesAction(Request $request)
  1354. {
  1355. $arr = [
  1356. [
  1357. 'value' => Config::HASOFFER_AFFILIATE_CATEGORY_UNCATEGORISED_TAG_NAME,
  1358. 'label' => Config::HASOFFER_AFFILIATE_CATEGORY_UNCATEGORISED_TAG_NAME
  1359. ]
  1360. ];
  1361. foreach (Config::HASOFFER_AFFILIATE_CATEGORY_ARRAY as $key => $value) {
  1362. $arr[] = [
  1363. 'value' => $value,
  1364. 'label' => $value
  1365. ];
  1366. }
  1367. return new JsonResponse($arr);
  1368. }
  1369. /**
  1370. * @Route("/alert-frequency-types", name="get_alert_frequency_types", methods={"GET"})
  1371. */
  1372. public
  1373. function getAlertFrequencyTypesAction(Request $request)
  1374. {
  1375. $arr = [];
  1376. foreach (Config::ALERT_CONTROL_ALERT_FREQUENCY_TYPES as $type) {
  1377. $arr[] = [
  1378. 'value' => $type,
  1379. 'label' => strtoupper($type)
  1380. ];
  1381. }
  1382. return new JsonResponse($arr);
  1383. }
  1384. /**
  1385. * @Route("/global-report-exclude-zero-values", name="get_global_report_Exclude_zero_values", methods={"GET"})
  1386. */
  1387. public
  1388. function getGlobalReportExcludeZeroValuesAction(Request $request)
  1389. {
  1390. $arr = [];
  1391. $columns = $this->commonCalls->getDataFromJsonFile(Config::JSON_FILE_GLOBAL_NETWORK_REPORT);
  1392. foreach ($columns as $key => $value) {
  1393. if (in_array($value['category'], ['statistics', 'calculations'])) {
  1394. $arr[] = [
  1395. 'value' => $value['accessor'],
  1396. 'label' => 'Exclude results with zero ' . $value['header']
  1397. ];
  1398. }
  1399. }
  1400. return new JsonResponse($arr);
  1401. }
  1402. /**
  1403. * @Route("/hyper-client-list", name="get_hyper_client_list", methods={"GET"})
  1404. */
  1405. public
  1406. function getHyperClientList(Request $request, HyperApis $hyperApis)
  1407. {
  1408. $hyperData = $this->commonCalls->getHyperClientCachedListByKeys();
  1409. $clientId = $request->query->get('clientId');
  1410. if ($clientId > 0) {
  1411. $clientInfo = $hyperApis->getHyperClientByClientId($clientId);
  1412. if ($clientInfo && isset($clientInfo['Result']) && $clientInfo['Result'] == 'Ok') {
  1413. foreach ($clientInfo['ResultData']['Data'] as $key => $value) {
  1414. if ($value['ClientNumber'] == $clientId) {
  1415. $countryCode = null;
  1416. foreach (Config::COUNTRIES as $k => $v) {
  1417. if ($this->commonCalls->checkForString($value['Country'], $v['name'])) {
  1418. $countryCode = $k;
  1419. break;
  1420. }
  1421. }
  1422. $value['countryCode'] = $countryCode;
  1423. $hyperData[$clientId] = $value;
  1424. break;
  1425. }
  1426. }
  1427. }
  1428. }
  1429. $arr = [];
  1430. foreach ($hyperData as $key => $value) {
  1431. $arr[] = [
  1432. 'value' => $key,
  1433. 'label' => $value['ClientFullName'] . ' [' . $value['ClientNumber'] . ']',
  1434. 'clientFullName' => $value['ClientFullName'],
  1435. 'countryCode' => $value['countryCode'],
  1436. 'city' => $value['City'],
  1437. 'address' => $value['StreetAddress']
  1438. ];
  1439. }
  1440. return new JsonResponse($arr);
  1441. }
  1442. /**
  1443. * @Route("/hyper-publisher-list", name="get_hyper_publisher_list", methods={"GET"})
  1444. */
  1445. public
  1446. function getHyperPublisherList(Request $request, HyperApis $hyperApis)
  1447. {
  1448. $hyperPublisherData = $this->commonCalls->getHyperPublisherCachedListByKeys();
  1449. $arr = [];
  1450. foreach ($hyperPublisherData as $key => $value) {
  1451. $arr[$value['SupplierNumber']] = [
  1452. 'value' => (int) $value['SupplierNumber'],
  1453. 'label' => $value['SupplierFullName'] . ' [' . $value['SupplierNumber'] . ']'
  1454. ];
  1455. }
  1456. ksort($arr);
  1457. return new JsonResponse(array_values($arr));
  1458. }
  1459. /**
  1460. * @Route("/tune-advertisers-by-hyper-client/{clientId}", name="get_tune_advertisers_by_hyper_client", methods={"GET"})
  1461. */
  1462. public
  1463. function getTuneAdvertisersByHyperClient(Request $request, $clientId)
  1464. {
  1465. $hyperData = $this->commonCalls->getHyperClientCachedListByKeys();
  1466. $linkedAdvertisers = [];
  1467. foreach ($hyperData as $key => $value) {
  1468. $value['Io_numbers'] = str_replace("\n\r", " ", $value['Io_numbers']);
  1469. $hyperData[$key]['Io_numbers'] = explode(" ", $value['Io_numbers']);
  1470. $linkedAdvertisers = array_values(array_unique(array_merge($linkedAdvertisers, $hyperData[$key]['Io_numbers'])));
  1471. }
  1472. $unlinedAdvertisers = $this->doctrine->getRepository(AdvertiserInfo::class)->getAdvertiserListByArrToSearch([
  1473. 'advertiserId' => ['value' => $linkedAdvertisers, 'excludeFlag' => true]
  1474. ]);
  1475. $clientLinkedMutiselectList = [];
  1476. $clientLinkedMutiselectList['label'] = 'Tune Advertisers Linked With HYPER';
  1477. $clientLinkedMutiselectList['options'] = [];
  1478. if (isset($hyperData[$clientId]) && sizeof($hyperData[$clientId]['Io_numbers'])) {
  1479. $clientLinkedMutiselectList['label'] = 'Tune Advertisers Linked With HYPER Client ' . $hyperData[$clientId]['ClientFullName'];
  1480. $clientLinkedMutiselectList['options'] = [];
  1481. $clientLinkedAdvertisers = $this->doctrine->getRepository(AdvertiserInfo::class)->getAdvertiserListByArrToSearch([
  1482. 'advertiserId' => ['value' => $hyperData[$clientId]['Io_numbers'], 'excludeFlag' => false]
  1483. ]);
  1484. if ($clientLinkedAdvertisers) {
  1485. foreach ($clientLinkedAdvertisers as $key => $value) {
  1486. $clientLinkedMutiselectList['options'][] = [
  1487. 'value' => $value['advertiserId'],
  1488. 'label' => $value['advertiserId'] . " - " . $value['company'],
  1489. 'color' => "#e55353"
  1490. ];
  1491. }
  1492. }
  1493. }
  1494. $unlinkedMultiselectList = [];
  1495. $unlinkedMultiselectList['label'] = 'Tune Advertisers Unlinked In HYPER';
  1496. $unlinkedMultiselectList['options'] = [];
  1497. foreach ($unlinedAdvertisers as $key => $value) {
  1498. $unlinkedMultiselectList['options'][] = [
  1499. 'value' => $value['advertiserId'],
  1500. 'label' => $value['advertiserId'] . " - " . $value['company'],
  1501. 'color' => "#3399ff"
  1502. ];
  1503. }
  1504. $finalArr = [$clientLinkedMutiselectList, $unlinkedMultiselectList];
  1505. return new JsonResponse($finalArr);
  1506. }
  1507. /**
  1508. * @Route("/tune-accounts", methods={"GET"})
  1509. */
  1510. public
  1511. function getTuneAccountsAction(Request $request)
  1512. {
  1513. $arr = [];
  1514. foreach (Config::MAFO_SYSTEM_IDENTIFIER_TUNE_ACCOUNTS as $key => $value) {
  1515. $arr[$value] = [
  1516. 'value' => $value,
  1517. 'label' => $value === Config::MAFO_SYSTEM_IDENTIFIER_TUNE_MOBILE ? Config::MAFO_SYSTEM_IDENTIFIER_TUNE_MOBILE_PRETTY : Config::MAFO_SYSTEM_IDENTIFIER_TUNE_WEB_PRETTY,
  1518. ];
  1519. }
  1520. return new JsonResponse(array_values($arr));
  1521. }
  1522. /**
  1523. * @Route("/advertisers-by-tune-account/{keyword}", methods={"GET"})
  1524. */
  1525. public
  1526. function getTuneWebAccountAdvertisersAction(Request $request, $keyword)
  1527. {
  1528. $advertisersByTuneAccount = $this->doctrine->getRepository(AdvertiserInfo::class)->getAdvertisersByTuneAccount([Config::ACTIVE_STATUS], $keyword);
  1529. $advertiserList = [];
  1530. foreach ($advertisersByTuneAccount as $key => $value) {
  1531. $advertiserList[$value['tuneAccount']]['label'] = (Config::MAFO_SYSTEM_IDENTIFIER_PRETTY[$value['tuneAccount']] ?? "") . ' ACCOUNT';
  1532. $advertiserList[$value['tuneAccount']]['options'][$value['advertiserId']] = [
  1533. 'value' => $value['advertiserId'],
  1534. 'label' => $value['advertiserId'] . ' - ' . $value['advertiserName'],
  1535. 'tuneAccount' => $value['tuneAccount'],
  1536. 'color' => Config::MAFO_SYSTEM_IDENTIFIER_TUNE_ACCOUNTS_COLORS[$value['tuneAccount']]
  1537. ];
  1538. ksort($advertiserList[$value['tuneAccount']]['options']);
  1539. }
  1540. $data = [];
  1541. foreach ($advertiserList as $key => $value) {
  1542. $data[] = [
  1543. 'label' => $value['label'],
  1544. 'options' => array_values($value['options']),
  1545. ];
  1546. }
  1547. return new JsonResponse($data);
  1548. }
  1549. /**
  1550. * @Route("/advertisers-by-tune-account", methods={"GET"})
  1551. */
  1552. public
  1553. function getTuneMobileAccountAdvertisersAction(Request $request)
  1554. {
  1555. $advertisersByTuneAccount = $this->doctrine->getRepository(AdvertiserInfo::class)->getAdvertisersByTuneAccount([Config::ACTIVE_STATUS], null);
  1556. $advertiserList = [];
  1557. foreach ($advertisersByTuneAccount as $key => $value) {
  1558. $advertiserList[$value['tuneAccount']]['label'] = (Config::MAFO_SYSTEM_IDENTIFIER_PRETTY[$value['tuneAccount']] ?? "") . ' ACCOUNT';
  1559. $advertiserList[$value['tuneAccount']]['options'][$value['advertiserId']] = [
  1560. 'value' => $value['advertiserId'],
  1561. 'label' => $value['advertiserId'] . ' - ' . $value['advertiserName'],
  1562. 'tuneAccount' => $value['tuneAccount'],
  1563. 'color' => Config::MAFO_SYSTEM_IDENTIFIER_TUNE_ACCOUNTS_COLORS[$value['tuneAccount']]
  1564. ];
  1565. if (sizeof($advertiserList[$value['tuneAccount']]['options']) > 1200) {
  1566. continue;
  1567. }
  1568. ksort($advertiserList[$value['tuneAccount']]['options']);
  1569. }
  1570. $data = [];
  1571. foreach ($advertiserList as $key => $value) {
  1572. $data[] = [
  1573. 'label' => $value['label'],
  1574. 'options' => array_values($value['options']),
  1575. ];
  1576. }
  1577. return new JsonResponse($data);
  1578. }
  1579. /**
  1580. * @Route("/affiliates-by-tune-account/{keyword}", methods={"GET"})
  1581. */
  1582. public
  1583. function getTuneWebAccountAffiliatesAction(Request $request, $keyword)
  1584. {
  1585. $affiliatesByTuneAccount = $this->doctrine->getRepository(AffiliateInfo::class)->getAffiliatesByTuneAccount([Config::ACTIVE_STATUS], $keyword);
  1586. $affiliateList = [];
  1587. foreach ($affiliatesByTuneAccount as $key => $value) {
  1588. $affiliateList[$value['tuneAccount']]['label'] = (Config::MAFO_SYSTEM_IDENTIFIER_PRETTY[$value['tuneAccount']] ?? "") . ' ACCOUNT AFFILIATE IDS';
  1589. $affiliateList[$value['tuneAccount']]['options'][$value['affiliateId']] = [
  1590. 'value' => $value['affiliateId'],
  1591. 'label' => $value['affiliateId'] . ' - ' . $value['affiliateName'],
  1592. 'tuneAccount' => $value['tuneAccount'],
  1593. 'color' => Config::MAFO_SYSTEM_IDENTIFIER_TUNE_ACCOUNTS_COLORS[$value['tuneAccount']] ?? "#000"
  1594. ];
  1595. ksort($affiliateList[$value['tuneAccount']]['options']);
  1596. }
  1597. $data = [];
  1598. foreach ($affiliateList as $key => $value) {
  1599. $data[] = [
  1600. 'label' => $value['label'],
  1601. 'options' => array_values($value['options']),
  1602. ];
  1603. }
  1604. return new JsonResponse($data);
  1605. }
  1606. /**
  1607. * @Route("/saved-report", name="saved_report_get", methods={"GET"})
  1608. */
  1609. public
  1610. function getSavedReportAction(Request $request)
  1611. {
  1612. $reportName = $request->query->get('reportName');
  1613. $data = $this->doctrine->getRepository(SavedReport::class)->getReportByEmailIdAndReportName($this->getUser()->getEmail(), $reportName);
  1614. return new JsonResponse($data);
  1615. }
  1616. /**
  1617. * @Route("/saved-report", name="saved_report_post", methods={"POST"})
  1618. */
  1619. public
  1620. function postSavedReportAction(Request $request)
  1621. {
  1622. $payload = json_decode($request->getContent(), true);
  1623. if (
  1624. !array_key_exists($payload['reportName'], Config::TABLE_COLUMNS_WITH_JSON_FILE) ||
  1625. !is_array($payload['payload']) ||
  1626. !$payload['reportGivenName'] ||
  1627. !$payload['reportPeriod']
  1628. ) {
  1629. return new JsonResponse(false, Config::HTTP_STATUS_CODE_BAD_REQUEST);
  1630. }
  1631. $this->doctrine->getRepository(SavedReport::class)->insert(
  1632. $this->getUser()->getEmail(),
  1633. $payload['reportName'],
  1634. $payload['reportGivenName'],
  1635. $payload['reportPeriod'],
  1636. $payload['payload']
  1637. );
  1638. return new JsonResponse(true);
  1639. }
  1640. /**
  1641. * @Route("/saved-report/{id}", name="saved_report_delete", methods={"DELETE"})
  1642. */
  1643. public
  1644. function deleteSavedReportAction(Request $request, $id)
  1645. {
  1646. $recordExist = $this->doctrine->getRepository(SavedReport::class)->findOneBy([
  1647. 'id' => $id,
  1648. 'savedByEmailId' => $this->getUser()->getEmail()
  1649. ]);
  1650. if ($recordExist) {
  1651. $this->doctrine->getRepository(SavedReport::class)->updateSavedReportDataById($id, [
  1652. 'isDeleted' => 1
  1653. ]);
  1654. }
  1655. return new JsonResponse(true);
  1656. }
  1657. /**
  1658. * @Route("/recommendations", methods={"GET"})
  1659. */
  1660. public
  1661. function getRecommendationsAction(Request $request)
  1662. {
  1663. $objectType = $request->query->get('objectType');
  1664. $objectValue = $request->query->get('objectValue');
  1665. $recommendedObjectType = $request->query->get('recommendedObjectType');
  1666. $recommendedData = $this->machineLearning->getRecommendations($objectType, $objectValue, $recommendedObjectType, Config::MMP_TRACKING_SYSTEM_TUNE);
  1667. return new JsonResponse($recommendedData);
  1668. }
  1669. /**
  1670. * @Route("/new-recommendations", methods={"GET"})
  1671. */
  1672. public
  1673. function getNewRecommendationsAction(Request $request)
  1674. {
  1675. $objectType = $request->query->get('objectType');
  1676. $objectValue = $request->query->get('objectValue');
  1677. $recommendedObjectType = $request->query->get('recommendedObjectType');
  1678. $mmpSource = $request->query->get('mmpSource');
  1679. // $recommendedData = [];
  1680. // if ($objectType == Config::RECOMMENDATIONS_OBJECT_TYPE_OFFER && $recommendedObjectType == Config::RECOMMENDATIONS_OBJECT_TYPE_AFFILIATE) {
  1681. $recommendedData = $this->machineLearning->getRecommendedAffiliatesByOffer($objectValue, $objectType, $mmpSource);
  1682. // }
  1683. return new JsonResponse($recommendedData);
  1684. }
  1685. /**
  1686. * @Route("/advertiser-discount-types", methods={"GET"})
  1687. */
  1688. public
  1689. function getAdvertiserDiscountTypes(Request $request)
  1690. {
  1691. $arr = [];
  1692. foreach (Config::ADVERTISER_DISCOUNT_TYPES as $discountType) {
  1693. $arr[] = [
  1694. 'value' => $discountType,
  1695. 'label' => ucwords(str_replace("_", " ", $discountType))
  1696. ];
  1697. }
  1698. return new JsonResponse($arr);
  1699. }
  1700. /**
  1701. * @Route("/mafo-advertisers", methods={"GET"})
  1702. */
  1703. public
  1704. function getMafoAdvertisersAction(Request $request)
  1705. {
  1706. $showAssociatedAdvertisers = $request->query->get('showAssociatedAdvertisers');
  1707. $showAssociatedAdvertisers = $showAssociatedAdvertisers === '1' ? true : false;
  1708. $accountManagerIds = [];
  1709. if (!in_array(Config::ROLE_ADMIN, $this->getUser()->getRoles()) && $showAssociatedAdvertisers) {
  1710. $childUsersByUser = $this->usersComponents->getChildUsersByUser();
  1711. if (array_key_exists($this->getUser()->getEmail(), $childUsersByUser)) {
  1712. $accountManagerIds = array_values(array_unique(array_merge($accountManagerIds, [$this->getUser()->getRoles()], $childUsersByUser[$this->getUser()->getEmail()])));
  1713. }
  1714. $accountManagerIds[] = $this->getUser()->getEmail();
  1715. }
  1716. $filters = [];
  1717. if ($accountManagerIds) {
  1718. $filters['accountManagerEmail'] = $accountManagerIds;
  1719. }
  1720. $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);
  1721. $arr = [];
  1722. foreach ($advertisers as $key => $value) {
  1723. $arr[] = [
  1724. 'value' => $value['id'],
  1725. 'label' => $value['id'] . ' - ' . $value['name']
  1726. ];
  1727. }
  1728. return new JsonResponse($arr);
  1729. }
  1730. /**
  1731. * @Route("/mafo-affiliates", methods={"GET"})
  1732. */
  1733. public
  1734. function getMafoAffiliatesAction(Request $request)
  1735. {
  1736. $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);
  1737. $arr = [];
  1738. foreach ($affiliates as $key => $value) {
  1739. $arr[] = [
  1740. 'value' => $value['id'],
  1741. 'label' => $value['id'] . ' - ' . $value['name']
  1742. ];
  1743. }
  1744. return new JsonResponse($arr);
  1745. }
  1746. /**
  1747. * @Route("/mafo-offers", methods={"GET"})
  1748. */
  1749. public
  1750. function getMafoOffersAction(Request $request)
  1751. {
  1752. $offers = $this->doctrine->getRepository(MafoOffers::class)->getOffersList();
  1753. $arr = [];
  1754. foreach ($offers as $key => $value) {
  1755. $arr[] = [
  1756. 'value' => $value['id'],
  1757. 'label' => $value['id'] . ' - ' . $value['name']
  1758. ];
  1759. }
  1760. return new JsonResponse($arr);
  1761. }
  1762. /**
  1763. * @Route("/offer-type", name="get_offer_type", methods={"GET"})
  1764. */
  1765. public function getOfferTypeAction()
  1766. {
  1767. $offerTypes = array_map(function ($type) {
  1768. return [
  1769. 'value' => strtolower($type),
  1770. 'label' => $type
  1771. ];
  1772. }, Config::OFFER_TYPES);
  1773. return new JsonResponse($offerTypes);
  1774. }
  1775. /**
  1776. * @Route("/publisher-list", name="get_publishers_dropdown", methods={"GET"})
  1777. */
  1778. public function getPublishersDropdownAction(Request $request)
  1779. {
  1780. $mappedAffiliateId = $request->query->get('mappedAffiliateId');
  1781. if ($mappedAffiliateId) {
  1782. // Fetch publishers for the given mappedAffiliateId and not deleted
  1783. $data = $this->doctrine->getRepository(MafoPublisherCabinetManager::class)->getPublishersByAffiliateId($mappedAffiliateId);
  1784. } else {
  1785. $data = $this->doctrine->getRepository(MafoPublisherCabinetManager::class)->getAllPublishers();
  1786. }
  1787. $dropdownData = $this->commonCalls->transformToDropdownFormat($data);
  1788. return new JsonResponse($dropdownData);
  1789. }
  1790. }