<?php
namespace App\Controller;
use App\Entity\Bildirimler;
use App\Entity\Duyurular;
use App\Entity\MobilBildirimler;
use App\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Imagick;
class PanelDefaultController extends BaseController
{
/**
* @Route("/storage/{file}", name="panel_storage")
*/
public function storage($file): Response
{
$link = 'https://rvcloudstorage.com/'.$this->ayarlar('uploadFolder').'/'.$file;
if ($file=='resimyok.webp'){
$link = 'https://rvcloudstorage.com/'.$file;
}
$ch = curl_init($link);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$ch_header = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
return new Response( $response,Response::HTTP_OK, ['content-type' => $ch_header]);
}
/**
* @Route("/panel/wait", name="panel_wait")
*/
public function wait(): Response
{
return $this->redirectToRoute('panel_homepage');
}
/**
* @Route("/panel", name="panel_homepage")
*/
public function index(): Response
{
return $this->render('panel/anasayfa/index.html.twig');
}
/**
* @Route("/panel/cacheClear", name="panel_cacheClear")
*/
public function cacheClear(): Response
{
shell_exec("php ".$_SERVER['DOCUMENT_ROOT']."/bin/console make:migration");
shell_exec("php ".$_SERVER['DOCUMENT_ROOT']."/bin/console doctrine:migrations:migrate");
shell_exec("php ".$_SERVER['DOCUMENT_ROOT']."/bin/console cache:clear");
shell_exec("php ".$_SERVER['DOCUMENT_ROOT']."/bin/console cache:clear --env=prod");
shell_exec("".$_SERVER['DOCUMENT_ROOT']."/chmod 777 -R var/");
shell_exec("".$_SERVER['DOCUMENT_ROOT']."/chmod 777 -R var");
return new Response('');
}
/**
* @Route("/ilceGetir", name="panel_ilceGetir")
*/
public function ilceGetir(Request $request): Response
{
$em = $this->getDoctrine()->getManager();
$id = $request->request->get('id');
$ilce = $request->request->get('ilce');
if ($id==""){
$ilceler = "";
}else {
$qb = $em->createQueryBuilder();
$ilceler = $qb->select('i.id,i.name')
->from('App:Ilce', 'i')
->join('i.il', 'il')
->where('il.id=' . $id)
->getQuery()
->getScalarResult();
}
return $this->render('panel/anasayfa/ilceGetir.html.twig',array('ilceler'=>$ilceler,'ilce'=>$ilce));
}
/**
* @Route("/panel/grafikGetir", name="panel_grafikGetir")
*/
public function grafikGetir(Request $request): Response
{
$em = $this->getDoctrine()->getManager();
$yil = $request->request->get('yil');
$yil = explode(' - ',$yil);
$yil = $yil[0];
$verilerD = [];
$verilerM = [];
for ($i=0;$i<5;$i++) {
$tt = "";
$tt = "(c.damgaYili = $yil) and ";
$sql = "k.id is not null";
if ($this->getUser()->getRoles()[0]=='ROLE_KULLANICI'){
$sql .=" and k.id=".$this->getUser()->getId();
}
$qb = $em->createQueryBuilder();
$veriler = $qb->select('c.id')
->from('App:Cihazlar', 'c')
->join('c.sube', 's')
->join('s.bolge', 'b')
->join('b.kullanici', 'k')
->where($tt.$sql)
->getQuery()
->getScalarResult();
$verilerD[$yil] = intval(@count($veriler));
$tt = "((c.damgaYili+2) = $yil) and ";
$qb = $em->createQueryBuilder();
$veriler2 = $qb->select('c.id')
->from('App:Cihazlar', 'c')
->join('c.sube', 's')
->join('s.bolge', 'b')
->join('b.kullanici', 'k')
->where($tt.$sql)
->getQuery()
->getScalarResult();
$verilerM[$yil] = intval(@count($veriler2));
$yil = $yil+1;
}
return $this->render('panel/anasayfa/grafikGetir.html.twig',array('verilerM'=>$verilerM,'verilerD'=>$verilerD));
}
/**
* @Route("/panel/duyuruOkuma", name="panel_duyuruOkuma")
*/
public function duyuruOkuma(Request $request): Response
{
$em = $this->getDoctrine()->getManager();
$id = $request->request->get('id');
$duyuru = $em->getRepository(Duyurular::class)->find($id);
$okuma = $duyuru->getOkuma();
if (empty($okuma)){
$okuma[] = $this->getUser()->getId();
}else {
if (!in_array($this->getUser()->getId(), $okuma)) {
$okuma[] = $this->getUser()->getId();
}
}
$duyuru->setOkuma($okuma);
$em->persist($duyuru);
$em->flush();
return new Response('');
}
/**
* @Route("/bildirimGonder", name="panel_bildirimGonder")
*/
public function bildirimGonder(Request $request,EntityManagerInterface $em,RequestStack $session): Response
{
$qb = $em->createQueryBuilder();
$mobilBildirimler = $qb->select('b.id,b.baslik,b.metin,b.tarih,b.kullanicilar')
->from('App:MobilBildirimler', 'b')
->where('b.durum=0')
->getQuery()
->getScalarResult();
foreach ($mobilBildirimler as $bildirim){
$ok = 1;
if($bildirim['tarih']!=null){
$suan = new \DateTime('now');
$tarih = new \DateTime($bildirim['tarih']);
if($suan->format('U')<$tarih->format('U')){
$ok = 0;
}
}
if($ok==1) {
$kullanicilar = $this->d2ArrayConvert($bildirim['kullanicilar']);
if ($kullanicilar == "") {
$kullanicilar = [];
$qb = $em->createQueryBuilder();
$bulunanKullanicilar = $qb->select('k.id')
->from('App:User', 'k')
->getQuery()
->getScalarResult();
foreach ($bulunanKullanicilar as $bk) {
$kullanicilar[] = $bk['id'];
}
}
foreach ($kullanicilar as $kk) {
$qb = $em->createQueryBuilder();
$bildirimSor = $qb->select('b.id')
->from('App:Bildirimler', 'b')
->where('b.mobilBildirim='.$bildirim['id'].' and b.kullanici='.$kk)
->setMaxResults(1)
->getQuery()
->getScalarResult();
if(count($bildirimSor)==0) {
$uu = $em->getReference(User::class, $kk);
$mb = $em->getReference(MobilBildirimler::class, $bildirim['id']);
$bb = new Bildirimler();
$bb->setBaslik($bildirim['baslik']);
$bb->setMetin($bildirim['metin']);
$bb->setTarih(new \DateTime('now'));
$bb->setOkuma(0);
$bb->setKullanici($uu);
$bb->setMobilBildirim($mb);
$bb->setYonlendirme("");
$em->persist($bb);
$em->flush();
$this->mobilBildirimGonder($bildirim['baslik'], $bildirim['metin'], $kk);
}
}
$mbb = $em->getRepository(MobilBildirimler::class)->find($bildirim['id']);
$mbb->setDurum(1);
$em->persist($mbb);
$em->flush();
}
}
return new Response('');
}
}