src/Controller/PanelDefaultController.php line 191

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Bildirimler;
  4. use App\Entity\Duyurular;
  5. use App\Entity\MobilBildirimler;
  6. use App\Entity\User;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\RequestStack;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Imagick;
  14. class PanelDefaultController extends BaseController
  15. {
  16.     /**
  17.      * @Route("/storage/{file}", name="panel_storage")
  18.      */
  19.     public function storage($file): Response
  20.     {
  21.         $link 'https://rvcloudstorage.com/'.$this->ayarlar('uploadFolder').'/'.$file;
  22.         if ($file=='resimyok.webp'){
  23.             $link 'https://rvcloudstorage.com/'.$file;
  24.         }
  25.         $ch curl_init($link);
  26.         curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  27.         $response curl_exec($ch);
  28.         $ch_header =  curl_getinfo($chCURLINFO_CONTENT_TYPE);
  29.         return new Response$response,Response::HTTP_OK, ['content-type' => $ch_header]);
  30.     }
  31.     /**
  32.      * @Route("/panel/wait", name="panel_wait")
  33.      */
  34.     public function wait(): Response
  35.     {
  36.         return $this->redirectToRoute('panel_homepage');
  37.     }
  38.     /**
  39.      * @Route("/panel", name="panel_homepage")
  40.      */
  41.     public function index(): Response
  42.     {
  43.         return $this->render('panel/anasayfa/index.html.twig');
  44.     }
  45.     /**
  46.      * @Route("/panel/cacheClear", name="panel_cacheClear")
  47.      */
  48.     public function cacheClear(): Response
  49.     {
  50.         shell_exec("php ".$_SERVER['DOCUMENT_ROOT']."/bin/console make:migration");
  51.         shell_exec("php ".$_SERVER['DOCUMENT_ROOT']."/bin/console doctrine:migrations:migrate");
  52.         shell_exec("php ".$_SERVER['DOCUMENT_ROOT']."/bin/console cache:clear");
  53.         shell_exec("php ".$_SERVER['DOCUMENT_ROOT']."/bin/console cache:clear --env=prod");
  54.         shell_exec("".$_SERVER['DOCUMENT_ROOT']."/chmod 777 -R var/");
  55.         shell_exec("".$_SERVER['DOCUMENT_ROOT']."/chmod 777 -R var");
  56.         return new Response('');
  57.     }
  58.     /**
  59.      * @Route("/ilceGetir", name="panel_ilceGetir")
  60.      */
  61.     public function ilceGetir(Request $request): Response
  62.     {
  63.         $em $this->getDoctrine()->getManager();
  64.         $id $request->request->get('id');
  65.         $ilce $request->request->get('ilce');
  66.         if ($id==""){
  67.             $ilceler "";
  68.         }else {
  69.             $qb $em->createQueryBuilder();
  70.             $ilceler $qb->select('i.id,i.name')
  71.                 ->from('App:Ilce''i')
  72.                 ->join('i.il''il')
  73.                 ->where('il.id=' $id)
  74.                 ->getQuery()
  75.                 ->getScalarResult();
  76.         }
  77.         return $this->render('panel/anasayfa/ilceGetir.html.twig',array('ilceler'=>$ilceler,'ilce'=>$ilce));
  78.     }
  79.     /**
  80.      * @Route("/panel/grafikGetir", name="panel_grafikGetir")
  81.      */
  82.     public function grafikGetir(Request $request): Response
  83.     {
  84.         $em $this->getDoctrine()->getManager();
  85.         $yil $request->request->get('yil');
  86.         $yil explode(' - ',$yil);
  87.         $yil $yil[0];
  88.         $verilerD = [];
  89.         $verilerM = [];
  90.         for ($i=0;$i<5;$i++) {
  91.             $tt "";
  92.             $tt "(c.damgaYili = $yil) and ";
  93.             $sql "k.id is not null";
  94.             if ($this->getUser()->getRoles()[0]=='ROLE_KULLANICI'){
  95.                 $sql .=" and k.id=".$this->getUser()->getId();
  96.             }
  97.             $qb $em->createQueryBuilder();
  98.             $veriler $qb->select('c.id')
  99.                 ->from('App:Cihazlar''c')
  100.                 ->join('c.sube''s')
  101.                 ->join('s.bolge''b')
  102.                 ->join('b.kullanici''k')
  103.                 ->where($tt.$sql)
  104.                 ->getQuery()
  105.                 ->getScalarResult();
  106.             $verilerD[$yil] = intval(@count($veriler));
  107.             $tt "((c.damgaYili+2) = $yil) and ";
  108.             $qb $em->createQueryBuilder();
  109.             $veriler2 $qb->select('c.id')
  110.                 ->from('App:Cihazlar''c')
  111.                 ->join('c.sube''s')
  112.                 ->join('s.bolge''b')
  113.                 ->join('b.kullanici''k')
  114.                 ->where($tt.$sql)
  115.                 ->getQuery()
  116.                 ->getScalarResult();
  117.             $verilerM[$yil] = intval(@count($veriler2));
  118.             $yil $yil+1;
  119.         }
  120.         return $this->render('panel/anasayfa/grafikGetir.html.twig',array('verilerM'=>$verilerM,'verilerD'=>$verilerD));
  121.     }
  122.     /**
  123.      * @Route("/panel/duyuruOkuma", name="panel_duyuruOkuma")
  124.      */
  125.     public function duyuruOkuma(Request $request): Response
  126.     {
  127.         $em $this->getDoctrine()->getManager();
  128.         $id  $request->request->get('id');
  129.         $duyuru $em->getRepository(Duyurular::class)->find($id);
  130.         $okuma $duyuru->getOkuma();
  131.         if (empty($okuma)){
  132.             $okuma[] = $this->getUser()->getId();
  133.         }else {
  134.             if (!in_array($this->getUser()->getId(), $okuma)) {
  135.                 $okuma[] = $this->getUser()->getId();
  136.             }
  137.         }
  138.         $duyuru->setOkuma($okuma);
  139.         $em->persist($duyuru);
  140.         $em->flush();
  141.         return new Response('');
  142.     }
  143.     /**
  144.      * @Route("/bildirimGonder", name="panel_bildirimGonder")
  145.      */
  146.     public function bildirimGonder(Request $request,EntityManagerInterface $em,RequestStack $session): Response
  147.     {
  148.         $qb $em->createQueryBuilder();
  149.         $mobilBildirimler $qb->select('b.id,b.baslik,b.metin,b.tarih,b.kullanicilar')
  150.             ->from('App:MobilBildirimler''b')
  151.             ->where('b.durum=0')
  152.             ->getQuery()
  153.             ->getScalarResult();
  154.         foreach ($mobilBildirimler as $bildirim){
  155.             $ok 1;
  156.             if($bildirim['tarih']!=null){
  157.                 $suan = new \DateTime('now');
  158.                 $tarih = new \DateTime($bildirim['tarih']);
  159.                 if($suan->format('U')<$tarih->format('U')){
  160.                     $ok 0;
  161.                 }
  162.             }
  163.             if($ok==1) {
  164.                 $kullanicilar $this->d2ArrayConvert($bildirim['kullanicilar']);
  165.                 if ($kullanicilar == "") {
  166.                     $kullanicilar = [];
  167.                     $qb $em->createQueryBuilder();
  168.                     $bulunanKullanicilar $qb->select('k.id')
  169.                         ->from('App:User''k')
  170.                         ->getQuery()
  171.                         ->getScalarResult();
  172.                     foreach ($bulunanKullanicilar as $bk) {
  173.                         $kullanicilar[] = $bk['id'];
  174.                     }
  175.                 }
  176.                 foreach ($kullanicilar as $kk) {
  177.                     $qb $em->createQueryBuilder();
  178.                     $bildirimSor $qb->select('b.id')
  179.                         ->from('App:Bildirimler''b')
  180.                         ->where('b.mobilBildirim='.$bildirim['id'].' and b.kullanici='.$kk)
  181.                         ->setMaxResults(1)
  182.                         ->getQuery()
  183.                         ->getScalarResult();
  184.                     if(count($bildirimSor)==0) {
  185.                         $uu $em->getReference(User::class, $kk);
  186.                         $mb $em->getReference(MobilBildirimler::class, $bildirim['id']);
  187.                         $bb = new Bildirimler();
  188.                         $bb->setBaslik($bildirim['baslik']);
  189.                         $bb->setMetin($bildirim['metin']);
  190.                         $bb->setTarih(new \DateTime('now'));
  191.                         $bb->setOkuma(0);
  192.                         $bb->setKullanici($uu);
  193.                         $bb->setMobilBildirim($mb);
  194.                         $bb->setYonlendirme("");
  195.                         $em->persist($bb);
  196.                         $em->flush();
  197.                         $this->mobilBildirimGonder($bildirim['baslik'], $bildirim['metin'], $kk);
  198.                     }
  199.                 }
  200.                 $mbb $em->getRepository(MobilBildirimler::class)->find($bildirim['id']);
  201.                 $mbb->setDurum(1);
  202.                 $em->persist($mbb);
  203.                 $em->flush();
  204.             }
  205.         }
  206.         return new Response('');
  207.     }
  208. }