src/Controller/DefaultController.php line 353

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. //use App\Config;
  4. //use App\Controller\MongoClient;
  5. //use App\Entity\AffiliateInfo;
  6. //use App\Entity\AffiliateOfferBlock;
  7. //use App\Entity\Alerts;
  8. //use App\Entity\AppInfo;
  9. //use App\Entity\AppsflyerWatcher;
  10. //use App\Entity\Employees;
  11. //use App\Entity\HoAffiliateMmpPartnerMapping;
  12. //use App\Entity\HyperAffiliateData;
  13. //use App\Entity\MmpAdvertisers;
  14. //use App\Entity\MmpMobileApps;
  15. //use App\Entity\MmpNotifications;
  16. //use App\Entity\MmpOffers;
  17. //use App\Entity\MmpPartnerRules;
  18. //use App\Entity\MmpPartners;
  19. //use App\Entity\MmpReports;
  20. //use App\Entity\OfferInfo;
  21. //use App\Entity\OfferTagRelationship;
  22. //use App\Entity\PayoutControl;
  23. //use App\Entity\PayoutControlAffiliateHyperData;
  24. //use App\Entity\PayoutTotal;
  25. //use App\Entity\RevenueControl;
  26. //use App\Entity\RevenueControlAdvertiserHyperData;
  27. //use App\Entity\RevenueTotal;
  28. //use App\Entity\SkadNetworkPostbackLogs;
  29. //use App\Entity\OfferScheduledChangesLogs;
  30. //use App\Entity\UsersHierarchy;
  31. use App\Config;
  32. use App\Entity\AdvertiserInfo;
  33. use App\Entity\AffiliateInfo;
  34. use App\Entity\AffiliateRating;
  35. use App\Entity\AppInfo;
  36. use App\Entity\AppsflyerDatalocker;
  37. use App\Entity\Employees;
  38. use App\Entity\HyperClientInfo;
  39. use App\Entity\MafoAdvertisers;
  40. use App\Entity\MafoAdvertisersMapping;
  41. use App\Entity\MafoAffiliatesMapping;
  42. use App\Entity\MmpFraudReports;
  43. use App\Entity\MmpMobileApps;
  44. use App\Entity\MmpReports;
  45. use App\Entity\ObjectMappingWithTuneWebAccount;
  46. use App\Entity\OfferInfo;
  47. use App\Entity\OfferTagRelationship;
  48. use App\Entity\RecommendationsByObject;
  49. use App\Entity\Tag;
  50. use App\Entity\UsersHierarchy;
  51. use App\Entity\HoAffiliateMmpPartnerMapping;
  52. use App\Entity\MafoAffiliateMmpPartnerMapping;
  53. use App\Services\AdjustAPI;
  54. use App\Services\AffiliateHasofferAPI;
  55. use App\Services\Alerts;
  56. use App\Services\AppsflyerAPI;
  57. use App\Services\Aws\ElasticCache;
  58. use App\Services\Aws\S3;
  59. use App\Services\BrandHasofferAPI;
  60. use App\Services\Common;
  61. use App\Services\FinancialToolsComponents;
  62. use App\Services\HyperApis;
  63. use App\Services\ImpressionsApis;
  64. use App\Services\Integrations\CjAPI;
  65. use App\Services\Mailer;
  66. use App\Services\Metrics24APICalls;
  67. use App\Services\MmpComponents;
  68. use App\Services\MysqlQueries;
  69. use App\Services\Scraper;
  70. use App\Services\UsersComponents;
  71. use Doctrine\Persistence\ManagerRegistry;
  72. use Exception;
  73. use Mmoreram\GearmanBundle\Service\GearmanClientInterface;
  74. use MongoClient;
  75. use MongoDB\Client as Mongo;
  76. use Ramsey\Uuid\Uuid;
  77. use Symfony\Component\HttpKernel\KernelInterface;
  78. use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
  79. use Symfony\Component\Mailer\Header\MetadataHeader;
  80. use Symfony\Component\Mailer\MailerInterface;
  81. use Symfony\Component\Mercure\Authorization;
  82. use Symfony\Component\Mercure\Discovery;
  83. use Symfony\Component\Mercure\HubInterface;
  84. use Symfony\Component\Mercure\Publisher;
  85. use Symfony\Component\Mercure\Update;
  86. use Symfony\Component\Mime\Email;
  87. use Symfony\Component\Mime\Part\DataPart;
  88. use Symfony\Component\Mime\Part\File;
  89. use Symfony\Component\Routing\Annotation\Route;
  90. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  91. use Symfony\Component\HttpFoundation\JsonResponse;
  92. use Symfony\Component\HttpFoundation\Request;
  93. use Symfony\Component\HttpFoundation\Response;
  94. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  95. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  96. use App\Services\NewAdjustAPI;
  97. use Symfony\Contracts\HttpClient\HttpClientInterface;
  98. use Twig\Environment;
  99. //use Ramsey\Uuid\Uuid;
  100. class DefaultController extends AbstractController
  101. {
  102.     private $commonCalls;
  103.     private $doctrine;
  104.     private $brandHasofferApi;
  105.     private $tuneApi;
  106.     private $projectDir;
  107.     private $mmpComponents;
  108.     private $financialToolsComponents;
  109.     private $gearmanClientInterface;
  110.     private $alerts;
  111.     private $rootPath;
  112.     private $afApi;
  113.     private $s3;
  114.     private AdjustAPI $adjustApi;
  115.     public function __construct(GearmanClientInterface $gearmanClientInterfaceCommon $commonCallsManagerRegistry $doctrineBrandHasofferApi $brandHasofferApistring $projectDirMmpComponents $mmpComponentsAlerts $alertsParameterBagInterface $paramsAppsflyerAPI $afApiAdjustAPI $adjustApiFinancialToolsComponents $financialToolsComponentsS3 $s3)
  116.     {
  117.         $this->commonCalls $commonCalls;
  118.         $this->doctrine $doctrine;
  119.         $this->brandHasofferApi $brandHasofferApi;
  120.         $this->tuneApi $brandHasofferApi;
  121.         $this->projectDir $projectDir;
  122.         $this->mmpComponents $mmpComponents;
  123.         $this->financialToolsComponents $financialToolsComponents;
  124.         $this->gearmanClientInterface $gearmanClientInterface;
  125.         $this->alerts $alerts;
  126.         $this->rootPath $params->get('kernel.project_dir');
  127.         $this->afApi $afApi;
  128.         $this->s3 $s3;
  129.         $this->adjustApi $adjustApi;
  130.     }
  131.     /**
  132.      * @Route("/", name="agent_homepage", host="%agents_subdomain%")
  133.      */
  134.     public function indexAgentAction(Request $request)
  135.     {
  136.         return $this->render('base_agent.html.twig', [
  137.             'template' => '/templates/dashboard.html.twig',
  138.         ]);
  139.     }
  140.     /**
  141.      * @Route("/", name="mafo_publisher_homepage", host="%publishers_subdomain%")
  142.      */
  143.     public function indexPublisherAction(Request $request)
  144.     {
  145.         return $this->render('base_mafo_publisher.html.twig', [
  146.             'template' => '/base_mafo_publisher.html.twig',
  147.         ]);
  148.     }
  149.     /**
  150.      * @Route("/", name="mafo_advertiser_homepage", host="%advertisers_subdomain%")
  151.      */
  152.     public function indexAdvertiserAction(Request $request)
  153.     {
  154.         return $this->render('base_mafo_advertiser_cabinet.html.twig', [
  155.             'template' => '/base_mafo_advertiser_cabinet.html.twig',
  156.         ]);
  157.     }
  158.     /**
  159.      * @Route("/", name="homepage")
  160.      */
  161.     public function indexAction(Request $request)
  162.     {
  163.         return $this->render('base.html.twig', [
  164.             'template' => '/templates/dashboard.html.twig',
  165.         ]);
  166.     }
  167.     /**
  168.      * @Route("/login", name="mafo_form_login")
  169.      */
  170.     public function mafoFormLoginAction(AuthenticationUtils $authenticationUtilsRequest $request)
  171.     {
  172.         //        $authenticationUtils = $authenticationUtils->get('security.authentication_utils');
  173.         // get the login error if there is one
  174.         $error $authenticationUtils->getLastAuthenticationError();
  175.         // last username entered by the user
  176.         $lastUsername $authenticationUtils->getLastUsername();
  177.         return $this->render('/form_login.html.twig', [
  178.             'last_username' => $lastUsername,
  179.             'error' => $error,
  180.             'errorFromParam' => $request->query->get('error')
  181.         ]);
  182.     }
  183.     /**
  184.      * @Route("/test", name="test_")
  185.      * @throws TransportExceptionInterface
  186.      */
  187.     public function testAction(Request $requestHyperApis $hyper)
  188.     {
  189.         
  190.         die;
  191.     }
  192.     private function migrateMmpMobileAppsAdvertiserId()
  193.     {
  194.         $mmpMobileApps $this->doctrine->getRepository(MmpMobileApps::class)->getMmpMobileAppsForAdvertiserMigration();
  195.         foreach ($mmpMobileApps as $mmpMobileApp) {
  196.             if ($mmpMobileApp['advertiserId']) {
  197.                 $checkMafoAdvertiserMappingExists $this->doctrine->getRepository(MafoAdvertisersMapping::class)->findOneBy([
  198.                     'systemIdentifier' => Config::MAFO_SYSTEM_IDENTIFIER_TUNE_MOBILE,
  199.                     'systemIdentifierId' => $mmpMobileApp['advertiserId']
  200.                 ]);
  201.                 if($checkMafoAdvertiserMappingExists) {
  202.                     $this->doctrine->getRepository(MmpMobileApps::class)->updateMmpMobileAppsById($mmpMobileApp['id'], [
  203.                         'mafoAdvertiserId' => $checkMafoAdvertiserMappingExists->getMafoAdvertiserId()->getId()
  204.                     ]);
  205.                 }
  206.             }
  207.         }
  208.     }
  209.     private function processCohortCsv()
  210.     {
  211.         ini_set('memory_limit''256M');
  212.         $fileDirectory $this->rootPath '/public/temp';
  213.         $files scandir($fileDirectory);
  214.         foreach ($files as $file) {
  215.             if (!$this->commonCalls->checkForString($file'cohort')) {
  216.                 continue;
  217.             }
  218.             $filePath $fileDirectory '/' $file;
  219.             //            $fileData = file_get_contents($filePath);
  220.             $file fopen($filePath'r');
  221.             $data = [];
  222.             while (($line fgetcsv($file)) !== FALSE) {
  223.                 //$line is an array of the csv elements
  224.                 $data[] = $line;
  225.                 if (sizeof($data) > 100) {
  226.                     break;
  227.                 }
  228.             }
  229.             fclose($file);
  230.             $dataHeaders $data[0];
  231.             unset($data[0]);
  232.             echo json_encode($data);
  233.             die;
  234.         }
  235.     }
  236.     /**
  237.      * @Route("/advertiser-list", name="advertiser_list")
  238.      */
  239.     public
  240.     function getAdvertiserListAction(Request $request)
  241.     {
  242.         $advertiserData $this->commonCalls->getAdvertisersListByStatusWithKeys();
  243.         $response = [];
  244.         foreach ($advertiserData as $key => $value) {
  245.             $response[$value['id']] = [
  246.                 'value' => $value['id'],
  247.                 'label' => $value['id'] . ' - ' $value['name']
  248.             ];
  249.         }
  250.         ksort($response);
  251.         header('Access-Control-Allow-Origin: *');
  252.         return new JsonResponse(array_values($response));
  253.     }
  254.     /**
  255.      * @Route("/affiliate-list", name="affiliate_list")
  256.      */
  257.     public
  258.     function getAffiliateListAction(Request $request)
  259.     {
  260.         $advertiserData $this->commonCalls->getAffiliateListByStatusWithKeys();
  261.         $response = [];
  262.         foreach ($advertiserData as $key => $value) {
  263.             $response[$value['id']] = [
  264.                 'value' => $value['id'],
  265.                 'label' => $value['id'] . ' - ' $value['name']
  266.             ];
  267.         }
  268.         ksort($response);
  269.         header('Access-Control-Allow-Origin: *');
  270.         return new JsonResponse(array_values($response));
  271.     }
  272.     /**
  273.      * @Route("/oauth", name="oauth")
  274.      */
  275.     public
  276.     function oauthAction()
  277.     {
  278.         return new JsonResponse(true);
  279.     }
  280.     /**
  281.      * @Route("/appsflyer/skadnetwork", name="appsflyer_skadnetwork")
  282.      */
  283.     public
  284.     function appsflyerSkadnetworkAction(Request $request)
  285.     {
  286.         if ($_SERVER['REQUEST_METHOD'] === Config::HTTP_METHOD_POST) {
  287.             $payload json_decode($request->getContent(), true);
  288.         } else if ($_SERVER['REQUEST_METHOD'] === Config::HTTP_METHOD_GET) {
  289.             $payload['transaction-id'] = $request->query->get('transaction-id');
  290.         }
  291.         if (isset($payload['transaction-id'])) {
  292.             $data $this->doctrine->getRepository(SkadNetworkPostbackLogs::class)->findOneBy([
  293.                 'transactionId' => $payload['transaction-id']
  294.             ]);
  295.             if ($data) {
  296.                 $this->doctrine->getRepository(SkadNetworkPostbackLogs::class)->updateSkadNetworkPostbackLogs($data->getId(), [
  297.                     'isPostbackAcknowledgedFromAppsflyer' => true
  298.                 ]);
  299.             }
  300.         }
  301.         return new JsonResponse(true);
  302.     }
  303.     /**
  304.      * Serve the SPA for any front-end route so React Router can handle it client-side
  305.      * This should be placed LAST in your routing to act as a catch-all
  306.      *
  307.      * @Route("/{reactRouting}", name="spa_catch_all", requirements={"reactRouting"="^(?!api|admin|_wdt|_profiler).*"}, methods={"GET"}, priority=-1)
  308.      */
  309.     public function spaCatchAll(): Response
  310.     {
  311.         return $this->render('base.html.twig', [
  312.             'template' => '/templates/dashboard.html.twig',
  313.         ]);
  314.     }
  315. }