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.             }else if($this->getUser()->getRoles()[0]=='ROLE_SORUMLU'){
  97.                 $sql .=" and b.id=".$this->getUser()->getBolge()->getId();
  98.             }
  99.             $qb $em->createQueryBuilder();
  100.             $veriler $qb->select('c.id')
  101.                 ->from('App:Cihazlar''c')
  102.                 ->join('c.sube''s')
  103.                 ->join('s.bolge''b')
  104.                 ->join('b.kullanici''k')
  105.                 ->where($tt.$sql)
  106.                 ->getQuery()
  107.                 ->getScalarResult();
  108.             $verilerD[$yil] = intval(@count($veriler));
  109.             $tt "((c.damgaYili+2) = $yil) and ";
  110.             $qb $em->createQueryBuilder();
  111.             $veriler2 $qb->select('c.id')
  112.                 ->from('App:Cihazlar''c')
  113.                 ->join('c.sube''s')
  114.                 ->join('s.bolge''b')
  115.                 ->join('b.kullanici''k')
  116.                 ->where($tt.$sql)
  117.                 ->getQuery()
  118.                 ->getScalarResult();
  119.             $verilerM[$yil] = intval(@count($veriler2));
  120.             $yil $yil+1;
  121.         }
  122.         return $this->render('panel/anasayfa/grafikGetir.html.twig',array('verilerM'=>$verilerM,'verilerD'=>$verilerD));
  123.     }
  124.     /**
  125.      * @Route("/panel/duyuruOkuma", name="panel_duyuruOkuma")
  126.      */
  127.     public function duyuruOkuma(Request $request): Response
  128.     {
  129.         $em $this->getDoctrine()->getManager();
  130.         $id  $request->request->get('id');
  131.         $duyuru $em->getRepository(Duyurular::class)->find($id);
  132.         $okuma $duyuru->getOkuma();
  133.         if (empty($okuma)){
  134.             $okuma[] = $this->getUser()->getId();
  135.         }else {
  136.             if (!in_array($this->getUser()->getId(), $okuma)) {
  137.                 $okuma[] = $this->getUser()->getId();
  138.             }
  139.         }
  140.         $duyuru->setOkuma($okuma);
  141.         $em->persist($duyuru);
  142.         $em->flush();
  143.         return new Response('');
  144.     }
  145.     /**
  146.      * @Route("/bildirimGonder", name="panel_bildirimGonder")
  147.      */
  148.     public function bildirimGonder(Request $request,EntityManagerInterface $em,RequestStack $session): Response
  149.     {
  150.         $qb $em->createQueryBuilder();
  151.         $mobilBildirimler $qb->select('b.id,b.baslik,b.metin,b.tarih,b.kullanicilar')
  152.             ->from('App:MobilBildirimler''b')
  153.             ->where('b.durum=0')
  154.             ->getQuery()
  155.             ->getScalarResult();
  156.         foreach ($mobilBildirimler as $bildirim){
  157.             $ok 1;
  158.             if($bildirim['tarih']!=null){
  159.                 $suan = new \DateTime('now');
  160.                 $tarih = new \DateTime($bildirim['tarih']);
  161.                 if($suan->format('U')<$tarih->format('U')){
  162.                     $ok 0;
  163.                 }
  164.             }
  165.             if($ok==1) {
  166.                 $kullanicilar $this->d2ArrayConvert($bildirim['kullanicilar']);
  167.                 if ($kullanicilar == "") {
  168.                     $kullanicilar = [];
  169.                     $qb $em->createQueryBuilder();
  170.                     $bulunanKullanicilar $qb->select('k.id')
  171.                         ->from('App:User''k')
  172.                         ->getQuery()
  173.                         ->getScalarResult();
  174.                     foreach ($bulunanKullanicilar as $bk) {
  175.                         $kullanicilar[] = $bk['id'];
  176.                     }
  177.                 }
  178.                 foreach ($kullanicilar as $kk) {
  179.                     $qb $em->createQueryBuilder();
  180.                     $bildirimSor $qb->select('b.id')
  181.                         ->from('App:Bildirimler''b')
  182.                         ->where('b.mobilBildirim='.$bildirim['id'].' and b.kullanici='.$kk)
  183.                         ->setMaxResults(1)
  184.                         ->getQuery()
  185.                         ->getScalarResult();
  186.                     if(count($bildirimSor)==0) {
  187.                         $uu $em->getReference(User::class, $kk);
  188.                         $mb $em->getReference(MobilBildirimler::class, $bildirim['id']);
  189.                         $bb = new Bildirimler();
  190.                         $bb->setBaslik($bildirim['baslik']);
  191.                         $bb->setMetin($bildirim['metin']);
  192.                         $bb->setTarih(new \DateTime('now'));
  193.                         $bb->setOkuma(0);
  194.                         $bb->setKullanici($uu);
  195.                         $bb->setMobilBildirim($mb);
  196.                         $bb->setYonlendirme("");
  197.                         $em->persist($bb);
  198.                         $em->flush();
  199.                         $this->mobilBildirimGonder($bildirim['baslik'], $bildirim['metin'], $kk);
  200.                     }
  201.                 }
  202.                 $mbb $em->getRepository(MobilBildirimler::class)->find($bildirim['id']);
  203.                 $mbb->setDurum(1);
  204.                 $em->persist($mbb);
  205.                 $em->flush();
  206.             }
  207.         }
  208.         return new Response('');
  209.     }
  210. }