<?php
namespace App\Controller;
//use App\Config;
//use App\Controller\MongoClient;
//use App\Entity\AffiliateInfo;
//use App\Entity\AffiliateOfferBlock;
//use App\Entity\Alerts;
//use App\Entity\AppInfo;
//use App\Entity\AppsflyerWatcher;
//use App\Entity\Employees;
//use App\Entity\HoAffiliateMmpPartnerMapping;
//use App\Entity\HyperAffiliateData;
//use App\Entity\MmpAdvertisers;
//use App\Entity\MmpMobileApps;
//use App\Entity\MmpNotifications;
//use App\Entity\MmpOffers;
//use App\Entity\MmpPartnerRules;
//use App\Entity\MmpPartners;
//use App\Entity\MmpReports;
//use App\Entity\OfferInfo;
//use App\Entity\OfferTagRelationship;
//use App\Entity\PayoutControl;
//use App\Entity\PayoutControlAffiliateHyperData;
//use App\Entity\PayoutTotal;
//use App\Entity\RevenueControl;
//use App\Entity\RevenueControlAdvertiserHyperData;
//use App\Entity\RevenueTotal;
//use App\Entity\SkadNetworkPostbackLogs;
//use App\Entity\OfferScheduledChangesLogs;
//use App\Entity\UsersHierarchy;
use App\Config;
use App\Entity\AdvertiserInfo;
use App\Entity\AffiliateInfo;
use App\Entity\AffiliateRating;
use App\Entity\AppInfo;
use App\Entity\AppsflyerDatalocker;
use App\Entity\Employees;
use App\Entity\HyperClientInfo;
use App\Entity\MafoAdvertisers;
use App\Entity\MafoAdvertisersMapping;
use App\Entity\MafoAffiliatesMapping;
use App\Entity\MmpFraudReports;
use App\Entity\MmpMobileApps;
use App\Entity\MmpReports;
use App\Entity\ObjectMappingWithTuneWebAccount;
use App\Entity\OfferInfo;
use App\Entity\OfferTagRelationship;
use App\Entity\RecommendationsByObject;
use App\Entity\Tag;
use App\Entity\UsersHierarchy;
use App\Entity\HoAffiliateMmpPartnerMapping;
use App\Entity\MafoAffiliateMmpPartnerMapping;
use App\Services\AdjustAPI;
use App\Services\AffiliateHasofferAPI;
use App\Services\Alerts;
use App\Services\AppsflyerAPI;
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\Integrations\CjAPI;
use App\Services\Mailer;
use App\Services\Metrics24APICalls;
use App\Services\MmpComponents;
use App\Services\MysqlQueries;
use App\Services\Scraper;
use App\Services\UsersComponents;
use Doctrine\Persistence\ManagerRegistry;
use Exception;
use Mmoreram\GearmanBundle\Service\GearmanClientInterface;
use MongoClient;
use MongoDB\Client as Mongo;
use Ramsey\Uuid\Uuid;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
use Symfony\Component\Mailer\Header\MetadataHeader;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mercure\Authorization;
use Symfony\Component\Mercure\Discovery;
use Symfony\Component\Mercure\HubInterface;
use Symfony\Component\Mercure\Publisher;
use Symfony\Component\Mercure\Update;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\Part\DataPart;
use Symfony\Component\Mime\Part\File;
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\Http\Authentication\AuthenticationUtils;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use App\Services\NewAdjustAPI;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Twig\Environment;
//use Ramsey\Uuid\Uuid;
class DefaultController extends AbstractController
{
private $commonCalls;
private $doctrine;
private $brandHasofferApi;
private $tuneApi;
private $projectDir;
private $mmpComponents;
private $financialToolsComponents;
private $gearmanClientInterface;
private $alerts;
private $rootPath;
private $afApi;
private $s3;
private AdjustAPI $adjustApi;
public function __construct(GearmanClientInterface $gearmanClientInterface, Common $commonCalls, ManagerRegistry $doctrine, BrandHasofferApi $brandHasofferApi, string $projectDir, MmpComponents $mmpComponents, Alerts $alerts, ParameterBagInterface $params, AppsflyerAPI $afApi, AdjustAPI $adjustApi, FinancialToolsComponents $financialToolsComponents, S3 $s3)
{
$this->commonCalls = $commonCalls;
$this->doctrine = $doctrine;
$this->brandHasofferApi = $brandHasofferApi;
$this->tuneApi = $brandHasofferApi;
$this->projectDir = $projectDir;
$this->mmpComponents = $mmpComponents;
$this->financialToolsComponents = $financialToolsComponents;
$this->gearmanClientInterface = $gearmanClientInterface;
$this->alerts = $alerts;
$this->rootPath = $params->get('kernel.project_dir');
$this->afApi = $afApi;
$this->s3 = $s3;
$this->adjustApi = $adjustApi;
}
/**
* @Route("/", name="agent_homepage", host="%agents_subdomain%")
*/
public function indexAgentAction(Request $request)
{
return $this->render('base_agent.html.twig', [
'template' => '/templates/dashboard.html.twig',
]);
}
/**
* @Route("/", name="mafo_publisher_homepage", host="%publishers_subdomain%")
*/
public function indexPublisherAction(Request $request)
{
return $this->render('base_mafo_publisher.html.twig', [
'template' => '/base_mafo_publisher.html.twig',
]);
}
/**
* @Route("/", name="mafo_advertiser_homepage", host="%advertisers_subdomain%")
*/
public function indexAdvertiserAction(Request $request)
{
return $this->render('base_mafo_advertiser_cabinet.html.twig', [
'template' => '/base_mafo_advertiser_cabinet.html.twig',
]);
}
/**
* @Route("/", name="homepage")
*/
public function indexAction(Request $request)
{
return $this->render('base.html.twig', [
'template' => '/templates/dashboard.html.twig',
]);
}
/**
* @Route("/login", name="mafo_form_login")
*/
public function mafoFormLoginAction(AuthenticationUtils $authenticationUtils, Request $request)
{
// $authenticationUtils = $authenticationUtils->get('security.authentication_utils');
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('/form_login.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
'errorFromParam' => $request->query->get('error')
]);
}
/**
* @Route("/test", name="test_")
* @throws TransportExceptionInterface
*/
public function testAction(Request $request, HyperApis $hyper)
{
die;
}
private function migrateMmpMobileAppsAdvertiserId()
{
$mmpMobileApps = $this->doctrine->getRepository(MmpMobileApps::class)->getMmpMobileAppsForAdvertiserMigration();
foreach ($mmpMobileApps as $mmpMobileApp) {
if ($mmpMobileApp['advertiserId']) {
$checkMafoAdvertiserMappingExists = $this->doctrine->getRepository(MafoAdvertisersMapping::class)->findOneBy([
'systemIdentifier' => Config::MAFO_SYSTEM_IDENTIFIER_TUNE_MOBILE,
'systemIdentifierId' => $mmpMobileApp['advertiserId']
]);
if($checkMafoAdvertiserMappingExists) {
$this->doctrine->getRepository(MmpMobileApps::class)->updateMmpMobileAppsById($mmpMobileApp['id'], [
'mafoAdvertiserId' => $checkMafoAdvertiserMappingExists->getMafoAdvertiserId()->getId()
]);
}
}
}
}
private function processCohortCsv()
{
ini_set('memory_limit', '256M');
$fileDirectory = $this->rootPath . '/public/temp';
$files = scandir($fileDirectory);
foreach ($files as $file) {
if (!$this->commonCalls->checkForString($file, 'cohort')) {
continue;
}
$filePath = $fileDirectory . '/' . $file;
// $fileData = file_get_contents($filePath);
$file = fopen($filePath, 'r');
$data = [];
while (($line = fgetcsv($file)) !== FALSE) {
//$line is an array of the csv elements
$data[] = $line;
if (sizeof($data) > 100) {
break;
}
}
fclose($file);
$dataHeaders = $data[0];
unset($data[0]);
echo json_encode($data);
die;
}
}
/**
* @Route("/advertiser-list", name="advertiser_list")
*/
public
function getAdvertiserListAction(Request $request)
{
$advertiserData = $this->commonCalls->getAdvertisersListByStatusWithKeys();
$response = [];
foreach ($advertiserData as $key => $value) {
$response[$value['id']] = [
'value' => $value['id'],
'label' => $value['id'] . ' - ' . $value['name']
];
}
ksort($response);
header('Access-Control-Allow-Origin: *');
return new JsonResponse(array_values($response));
}
/**
* @Route("/affiliate-list", name="affiliate_list")
*/
public
function getAffiliateListAction(Request $request)
{
$advertiserData = $this->commonCalls->getAffiliateListByStatusWithKeys();
$response = [];
foreach ($advertiserData as $key => $value) {
$response[$value['id']] = [
'value' => $value['id'],
'label' => $value['id'] . ' - ' . $value['name']
];
}
ksort($response);
header('Access-Control-Allow-Origin: *');
return new JsonResponse(array_values($response));
}
/**
* @Route("/oauth", name="oauth")
*/
public
function oauthAction()
{
return new JsonResponse(true);
}
/**
* @Route("/appsflyer/skadnetwork", name="appsflyer_skadnetwork")
*/
public
function appsflyerSkadnetworkAction(Request $request)
{
if ($_SERVER['REQUEST_METHOD'] === Config::HTTP_METHOD_POST) {
$payload = json_decode($request->getContent(), true);
} else if ($_SERVER['REQUEST_METHOD'] === Config::HTTP_METHOD_GET) {
$payload['transaction-id'] = $request->query->get('transaction-id');
}
if (isset($payload['transaction-id'])) {
$data = $this->doctrine->getRepository(SkadNetworkPostbackLogs::class)->findOneBy([
'transactionId' => $payload['transaction-id']
]);
if ($data) {
$this->doctrine->getRepository(SkadNetworkPostbackLogs::class)->updateSkadNetworkPostbackLogs($data->getId(), [
'isPostbackAcknowledgedFromAppsflyer' => true
]);
}
}
return new JsonResponse(true);
}
/**
* Serve the SPA for any front-end route so React Router can handle it client-side
* This should be placed LAST in your routing to act as a catch-all
*
* @Route("/{reactRouting}", name="spa_catch_all", requirements={"reactRouting"="^(?!api|admin|_wdt|_profiler).*"}, methods={"GET"}, priority=-1)
*/
public function spaCatchAll(): Response
{
return $this->render('base.html.twig', [
'template' => '/templates/dashboard.html.twig',
]);
}
}