src/Controller/WelcomeController.php line 110

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  8. class WelcomeController extends AbstractController {
  9.     /**
  10.      * Zasób odczytuje stan konta w HRD i SMSAPI, zwraca stan JSONem, oraz modyfikuje zmienne środowiskowe.
  11.      * @Route ("/getBalance", name="get-balance", methods={"POST"})
  12.      * @isGranted ("ROLE_ADMIN")
  13.      * @param \App\Service\SMSApi $SMSAPI
  14.      * @param \App\Controller\Doctrine\ORM\EntityManagerInterface $EM
  15.      * @param \Symfony\Component\HttpKernel\KernelInterface $KERNEL
  16.      * @return \Symfony\Component\HttpFoundation\JsonResponse
  17.      */
  18.     public function getBalance (\App\Service\SMSApi $SMSAPI, \Doctrine\ORM\EntityManagerInterface $EM): \Symfony\Component\HttpFoundation\JsonResponse {
  19.         $wynik = [
  20.             "HRD" => [
  21.                 "AMOUNT" => "0,00 PLN",
  22.                 "LOCK" => "0,00 PLN",
  23.                 "AVAILABLE" => "0,00 PLN"
  24.             ],
  25.             "SMSAPI" => 0
  26.         ];
  27.         $HRD = \HRDBase\Api\HRDApi::getInstance([
  28.                     "apiHash" => $EM->getRepository(\App\Entity\Conf::class)->peek("hash"),
  29.                     "apiLogin" => $EM->getRepository(\App\Entity\Conf::class)->peek("login"),
  30.                     "apiPass" => $EM->getRepository(\App\Entity\conf::class)->peek("pass")
  31.         ]);
  32.         $HRDTOKEN $HRD->getToken();
  33.         if ($HRDTOKEN) {
  34.             $balance $HRD->partnerGetBalance();
  35.             $wynik ["HRD"]["AMOUNT"] = number_format (floatval ($balance ['balance']), 2","" ") . " PLN";
  36.             $wynik ["HRD"]["LOCK"] = number_format (floatval ($balance ['restrictedBalance']), 2","" ") . " PLN";
  37.             $wynik ["HRD"]["AVAILABLE"] = number_format (floatval ($balance ['balance']) + floatval ($balance ['restrictedBalance']), 2","" ") . " PLN";
  38.         }
  39.         $wynik ['SMSAPI'] = $SMSAPI->getBalance($EM->getRepository(\App\Entity\Conf::class));
  40.         $envLines file ("../.env");
  41.         foreach ($envLines as &$envLine) {
  42.             if (substr ($envLine012) == "HRD_AMOUNT=\"") {
  43.                 $envLine "HRD_AMOUNT=\"" $wynik ['HRD']['AMOUNT'] . "\"\n";
  44.             } elseif (substr ($envLine010) == "HRD_LOCK=\"") {
  45.                 $envLine "HRD_LOCK=\"" $wynik ['HRD']['LOCK'] . "\"\n";
  46.             } elseif (substr ($envLine015) == "HRD_AVAILABLE=\"") {
  47.                 $envLine "HRD_AVAILABLE=\"" $wynik ['HRD']['AVAILABLE'] . "\"\n";
  48.             } elseif (substr ($envLine014) == "SMSAPI_POINTS=") {
  49.                 $envLine "SMSAPI_POINTS=\"" $wynik ['SMSAPI'] . "\"\n";
  50.             }
  51.         }
  52.         file_put_contents ("../.env"implode (""$envLines));
  53.         return new \Symfony\Component\HttpFoundation\JsonResponse($wynik);
  54.     }
  55.     
  56.     /**
  57.      * @Route("/chuj")
  58.      * @param \Doctrine\ORM\EntityManagerInterface $manager
  59.      * @return Response
  60.      */
  61.     function chuj (\Doctrine\ORM\EntityManagerInterface $manager): Response {
  62.         return $this->render (
  63.             "chuj.html.twig", [
  64.                 "messages" => [
  65.                     [
  66.                         "body" => "Komunikat <b><a href='/'>1</a></b>",                        
  67.                     ],
  68.                     [
  69.                         "body" => "Komunikat <b>2</b>",
  70.                         "type" => "success",
  71.                         "icon" => '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-power"><path d="M18.36 6.64a9 9 0 1 1-12.73 0"></path><line x1="12" y1="2" x2="12" y2="12"></line></svg>'
  72.                     ],
  73.                     [
  74.                         "body" => "Komunikat <b>3</b>",
  75.                         "type" => "warning",
  76.                         "icon" => '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-shield"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"></path></svg>'
  77.                     ],
  78.                     [
  79.                         "body" => "Komunikat <b>4</b>",
  80.                         "type" => "danger"
  81.                     ]
  82.                 ]
  83.             ]
  84.         );
  85.     }
  86.     
  87.     /**
  88.      * @Route("/test")
  89.      * @return Response
  90.      */
  91.     function testTemplate (): Response {
  92.         return $this->render("_test.html.twig");
  93.     }
  94.     
  95.     /**
  96.      * @Route ("/cover");
  97.      * @return \App\Controller\response
  98.      */
  99.     function testCover (): response {
  100.         return $this->render ('_cover.html.twig');
  101.     }
  102.     
  103.     /**
  104.      * @Route("/", name="app_welcome")
  105.      */
  106.     public function index(): Response
  107.     {
  108.         return $this->render('index.html.twig', [
  109.             'controller_name' => 'WelcomeController',
  110.         ]);        
  111.     }
  112.     
  113.     /**
  114.      * @Route("/checkmail/{to}/{title}/{body}", name="check_mail")
  115.      */
  116.     public function checkMail (\Swift_Mailer $mailerstring $to "daniel@kowszun.waw.pl"string $title "MAIL TEST"string $body "Treść testowego maila"): Response {
  117.     $message = (new \Swift_Message($title))
  118.         ->setFrom("daniel@kowszun.waw.pl""INFORPOL NET")
  119.         ->setTo($to"Daniel Kowszun")
  120.         ->setBody(
  121.             /*$this->renderView(
  122.                 // templates/emails/registration.html.twig
  123.                 'emails/registration.html.twig',
  124.                 ['name' => $name]
  125.             ),*/
  126.             $body,
  127.             'text/html'
  128.         )
  129.         // you can remove the following code if you don't define a text version for your emails
  130.         /*->addPart(
  131.             $this->renderView(
  132.                 // templates/emails/registration.txt.twig
  133.                 'emails/registration.txt.twig',
  134.                 ['name' => $name]
  135.             ),
  136.             'text/plain'
  137.         )*/
  138.     ;
  139.     $mailer->send($message);
  140.         return new Response ("ODBIORCA: " $to "<br/>TEMAT: " $title "<br/>TREŚĆ: " $body "<br/>STATUS: OK");
  141.     }
  142.     
  143. }