<?php
namespace App\Controller;
use App\Entity\Ceviri;
use App\Entity\Dil;
use Gumlet\ImageResize;
use FPDF;
use Kreait\Firebase\Factory;
use Kreait\Firebase\Messaging\CloudMessage;
use Kreait\Firebase\Messaging\Notification;
use Kreait\Firebase\Messaging\AndroidConfig;
use Kreait\Firebase\Messaging\ApnsConfig;
use setasign\Fpdi\Fpdi;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use App\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class BaseController extends AbstractController
{
function smsGonder($no,$mesaj)
{
$response="";
if ($no == '' or $mesaj == ''){}
else {
$no = str_replace(array('(',')',' '),array('','',''),$no);
$no = substr($no,1,strlen($no));
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.netgsm.com.tr/sms/send/get',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array('usercode' => '8503092043', 'password' => 'AF#351B', 'gsmno' => $no, 'message' => $mesaj, 'msgheader' => 'OZMENTIC.', 'filter' => '0', 'startdate' => '', 'stopdate' => '', 'dil'=>'TR'),
));
$response = curl_exec($curl);
curl_close($curl);
}
return $response;
}
function GetIP()
{
if (getenv("HTTP_CLIENT_IP")) {
$ip = getenv("HTTP_CLIENT_IP");
} elseif (getenv("HTTP_X_FORWARDED_FOR")) {
$ip = getenv("HTTP_X_FORWARDED_FOR");
if (strstr($ip, ',')) {
$tmp = explode(',', $ip);
$ip = trim($tmp[0]);
}
} else {
$ip = getenv("REMOTE_ADDR");
}
return $ip;
}
function ayarlar($alan)
{
$em=$this->getDoctrine()->getManager();
$qb = $em->createQueryBuilder();
$ayarlar=$qb->select("e.$alan")
->from('App:Ayarlar', 'e')
->getQuery()
->getScalarResult();
return $ayarlar[0][$alan];
}
function firmaAyarlari($alan)
{
$em=$this->getDoctrine()->getManager();
$qb = $em->createQueryBuilder();
$ayarlar=$qb->select("e.$alan")
->from('App:FirmaAyarlari', 'e')
->getQuery()
->getScalarResult();
return $ayarlar[0][$alan];
}
function uzantiBul($type){
if($type=='application/pdf'){ return '.pdf'; }
if($type=='image/jpeg'){ return '.jpg'; }
elseif($type=='image/png'){ return '.png'; }
elseif($type=='image/gif'){ return '.gif'; }
elseif($type=='video/mp4'){ return '.mp4'; }
elseif($type=='application/rtf'){ return '.rtf'; }
elseif($type=='text/plain'){ return '.txt'; }
elseif($type=='application/vnd.ms-powerpoint'){ return '.ppt'; }
elseif($type=='application/vnd.openxmlformats-officedocument.presentationml.presentation'){ return '.pptx'; }
elseif($type=='application/xml'){ return '.xml'; }
elseif($type=='text/xml'){ return '.xml'; }
elseif($type=='application/vnd.ms-excel'){ return '.xls'; }
elseif($type=='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'){ return '.xlsx'; }
elseif($type=='application/msword'){ return '.doc'; }
elseif($type=='application/vnd.openxmlformats-officedocument.wordprocessingml.document'){ return '.docx'; }
else{ return '.belirsiz'; }
}
function rasgele($uzunluk)
{
$key='';
$karakterler = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for($i=0;$i<$uzunluk;$i++)
{
$key .= $karakterler[rand(0,35)];
}
return $key;
}
function rasgeleSayi($uzunluk)
{
$key='';
$karakterler = "1234567890";
for($i=0;$i<$uzunluk;$i++)
{
$key .= $karakterler[rand(0,9)];
}
return $key;
}
function seo($url,$dil=1){
if($dil==1) {
$tr = array('ş', 'Ş', 'ı', 'I', 'İ', 'ğ', 'Ğ', 'ü', 'Ü', 'ö', 'Ö', 'Ç', 'ç', '(', ')', '/', ':', ',');
$eng = array('s', 's', 'i', 'i', 'i', 'g', 'g', 'u', 'u', 'o', 'o', 'c', 'c', '', '', '-', '-', '');
$s = str_replace($tr, $eng, $url);
$find = array('/[^A-Za-z0-9\-<>]/', '/[\-]+/', '/<[^>]*>/');
$repl = array('-', '-', '-');
$s = preg_replace($find, $repl, $s);
$s = strtolower($s);
$s = preg_replace('/&amp;amp;amp;amp;amp;amp;amp;amp;.+?;/', '', $s);
$s = preg_replace('/\s+/', '-', $s);
$s = preg_replace('|-+|', '-', $s);
$s = preg_replace('/#/', '', $s);
$s = str_replace('.', '', $s);
$s = trim($s, '-');
$s = strtolower($s);
return $s;
}else{
$tr = array('(', ')', '/', ':', ',',' ');
$eng = array('', '', '-', '-', '','-');
$s = str_replace($tr, $eng, $url);
$s = strtolower($s);
return $s;
}
}
function imageResizer($resim,$resim2,$boyut=800){
$resimBol = explode('.',$resim);
$uzanti = $resimBol[count($resimBol)-1];
$yol = 'gecici_yukleme/'.$resim;
$yol2 = 'gecici_yukleme/'.$resim2.'.webp';
list($width, $height) = getimagesize($yol);
$oran = $width / $boyut;
$yeni_genislik = $width / $oran;
$yeni_yukseklik = $height / $oran;
if ($uzanti=='jpeg' or $uzanti=='jpg' or $uzanti=='JPEG' or $uzanti=='JPG'){
$mevcut_resim = imagecreatefromjpeg($yol);
}else{
$mevcut_resim = imagecreatefrompng($yol);
}
$yeni_resim = imagecreatetruecolor($yeni_genislik, $yeni_yukseklik);
imageAlphaBlending($yeni_resim, false);
imageSaveAlpha($yeni_resim, true);
// By default, the canvas is black, so make it transparent
$trans = imagecolorallocatealpha($yeni_resim, 0, 0, 0, 127);
imagefilledrectangle($yeni_resim, 0, 0, $yeni_genislik - 1, $yeni_yukseklik - 1, $trans);
imagecopyresampled($yeni_resim, $mevcut_resim, 0, 0, 0, 0, $yeni_genislik, $yeni_yukseklik, $width, $height);
@unlink($yol);
imagewebp($yeni_resim, $yol2 );
return $resim2.'.webp';
}
function removeEntity($veriler){
$em = $this->getDoctrine()->getManager();
foreach ($veriler as $veri){
$em->remove($veri);
}
}
function uploadFile($file){
$username = 'rvcloudstorage';
$password = 'rvrv/*-2020';
$url = 'https://j15502zk.ni.net.tr:2083';
$yukleme_yeri = $this->ayarlar('uploadFolder');
$filePath = 'gecici_yukleme/'.$file;
$curl = curl_init();
$upload_file = realpath($filePath);
$destination_dir = "public_html/".$yukleme_yeri;
if (function_exists('curl_file_create')) {
$cf = curl_file_create($upload_file);
} else {
$cf = "@/" . $upload_file;
}
$payload = array(
'dir' => $destination_dir,
'file-1' => $cf
);
$actionUrl = $url . "/execute/Fileman/upload_files";
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // Allow self-signed certs
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // Allow certs that do not match the hostname
curl_setopt($curl, CURLOPT_HEADER, 0); // Do not include header in output
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // Return contents of transfer on curl_exec
$header[0] = "Authorization: Basic " . base64_encode($username . ":" . $password) . "\n\r";
curl_setopt($curl, CURLOPT_HTTPHEADER, $header); // set the username and password
curl_setopt($curl, CURLOPT_URL, $actionUrl); // execute the query
// Set up a POST request with the payload.
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
if ($result == false) {
error_log("curl_exec threw error \"" . curl_error($curl) . "\" for $actionUrl");
// log error if curl exec fails
}
curl_close($curl);
@unlink($filePath);
return json_decode($result, true);
}
function deleteFile($file)
{
if ($file!='') {
$curl = curl_init();
$destination_dir = 'public_html/'.$this->ayarlar('uploadFolder').'/' . $file;
$username = 'root';
$password = 'suleyman1995ilgin***';
$url = 'https://j15502zk.ni.net.tr:2083';
$user = 'rvcloudstorage';
$actionUrl = 'https://j15502zk.ni.net.tr:2087/json-api/cpanel?cpanel_jsonapi_user=' . $user . '&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=Fileman&cpanel_jsonapi_func=fileop&op=unlink&sourcefiles=' . $destination_dir . '&doubledecode=1';
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // Allow self-signed certs
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // Allow certs that do not match the hostname
curl_setopt($curl, CURLOPT_HEADER, 0); // Do not include header in output
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // Return contents of transfer on curl_exec
$header[0] = "Authorization: Basic " . base64_encode($username . ":" . $password) . "\n\r";
curl_setopt($curl, CURLOPT_HTTPHEADER, $header); // set the username and password
curl_setopt($curl, CURLOPT_URL, $actionUrl); // execute the query
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
if ($result == false) {
error_log("curl_exec threw error \"" . curl_error($curl) . "\" for $actionUrl");
// log error if curl exec fails
}
curl_close($curl);
return json_decode($result, true);
}
}
function fpdf_turkce($k)
{
return iconv('UTF-8', 'ISO-8859-9//TRANSLIT', $k);
}
function belgeDogrulama($belgeNo,$belgeTipi,$kanal,$dogrulamaAraci,$kanal2="",$dogrulamaAraci2=""){
$em=$this->getDoctrine()->getManager();
if ($belgeTipi==1){
$qb = $em->createQueryBuilder();
$basvurular = $qb->select('b.id,b.basvuruBelgesi,b.basvuruDK')
->from('App:Basvurular', 'b')
->join('b.sube', 's')
->join('b.cihaz', 'c')
->join('s.bolge', 'bol')
->join('s.sorumlu', 'sor')
->where("b.basvuruNo='$belgeNo'")
->getQuery()
->getScalarResult();
$belge = $basvurular[0]['basvuruBelgesi'];
$pdf = new Fpdi();
$pdf->AddFont('arial_tr','','arial_tr.php');
$pdf->AddFont('arial_tr','B','arial_tr_bold.php');
copy($this->ayarlar('siteYolu').'storage/'.$belge, 'gecici_yukleme/'.$belge);
$pageCount = $pdf->setSourceFile('gecici_yukleme/'.$belge);
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
$tplIdx = $pdf->importPage($pageNo);
$pdf->addPage();
$pdf->useTemplate($tplIdx, 5, 5, 200);
if($kanal!="") {
$pdf->SetFont('arial_tr', 'B', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->setY(235);
$pdf->SetX(10);
$pdf->Cell(90, 6, $this->fpdf_turkce($kanal), 0, 0, 'C', false); // Sorumlu E-Posta
}else{
$pdf->SetFont('arial_tr', 'B', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->setY(235);
$pdf->SetX(10);
$pdf->Cell(90, 6, $this->fpdf_turkce("Sistem tarafından doğrulanmıştır."), 0, 0, 'C', false); // Sorumlu E-Posta
}
if($kanal!="") {
$pdf->SetFont('arial_tr', '', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->setY(250);
$pdf->SetX(10);
if ($dogrulamaAraci == 1) {
$pdf->MultiCell(90, 6, $this->fpdf_turkce('Üstte yazılı sorumlu e-posta adresi tarafından doğrulama kodu ile doğrulanmıştır.'), 0, 'C', false); // Üstte yazılı sorumlu e-posta adresi tarafından doğrulama kodu ile doğrulanmıştır.
} else {
$pdf->MultiCell(90, 6, $this->fpdf_turkce('Üstte yazılı sorumlu telefon numarası tarafından doğrulama kodu ile doğrulanmıştır.'), 0, 'C', false); // Üstte yazılı sorumlu e-posta adresi tarafından doğrulama kodu ile doğrulanmıştır.
}
$pdf->SetFont('arial_tr', 'B', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->setY(240);
$pdf->SetX(10);
$pdf->Cell(90, 6, $this->fpdf_turkce('D.K. : ' . $basvurular[0]['basvuruDK']), 0, 0, 'C', false); // D.K. : 245 658 E-Posta doğrulama kodu
}
}
$pdf->Output('F', 'gecici_yukleme/'.$belge,true);
$this->deleteFile($belge);
$this->uploadFile($belge);
}
if ($belgeTipi==2){
$qb = $em->createQueryBuilder();
$basvurular = $qb->select('b.id,b.muayeneBelgesi,b.muayeneDK')
->from('App:Basvurular', 'b')
->join('b.sube', 's')
->join('b.cihaz', 'c')
->join('s.bolge', 'bol')
->join('s.sorumlu', 'sor')
->where("b.muayeneNo='$belgeNo'")
->getQuery()
->getScalarResult();
$belge = $basvurular[0]['muayeneBelgesi'];
$pdf = new Fpdi();
$pdf->AddFont('arial_tr','','arial_tr.php');
$pdf->AddFont('arial_tr','B','arial_tr_bold.php');
copy($this->ayarlar('siteYolu').'storage/'.$belge, 'gecici_yukleme/'.$belge);
$pageCount = $pdf->setSourceFile('gecici_yukleme/'.$belge);
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
$tplIdx = $pdf->importPage($pageNo);
$pdf->addPage();
$pdf->useTemplate($tplIdx, 5, 5, 200);
$pdf->SetFont('arial_tr', 'B', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->setY(247);
$pdf->SetX(10);
$pdf->Cell(90, 6, $this->fpdf_turkce($kanal), 0, 0, 'C', false); // bilgi@suleymanilgin.com.tr
$pdf->SetFont('arial_tr', '', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->setY(257);
$pdf->SetX(10);
if ($dogrulamaAraci == 1) {
$pdf->MultiCell(90, 4, $this->fpdf_turkce('Üstte yazılı sorumlu e-posta adresi tarafından doğrulama kodu ile doğrulanmıştır.'), 0, 'C', false); // Üstte yazılı sorumlu e-posta adresi tarafından doğrulama kodu ile doğrulanmıştır.
} else {
$pdf->MultiCell(90, 4, $this->fpdf_turkce('Üstte yazılı sorumlu telefon numarası tarafından doğrulama kodu ile doğrulanmıştır.'), 0, 'C', false); // Üstte yazılı sorumlu e-posta adresi tarafından doğrulama kodu ile doğrulanmıştır.
}
$pdf->SetFont('arial_tr', 'B', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->setY(252);
$pdf->SetX(10);
$pdf->Cell(90, 6, $this->fpdf_turkce('D.K. : ' . $basvurular[0]['muayeneDK']), 0, 0, 'C', false); // D.K. : 245 658
}
$pdf->Output('F', 'gecici_yukleme/'.$belge,true);
$this->deleteFile($belge);
$this->uploadFile($belge);
}
if ($belgeTipi==3){
$qb = $em->createQueryBuilder();
$basvurular = $qb->select('b.id,b.kontrolBelgesi,b.kontrolDK')
->from('App:Basvurular', 'b')
->join('b.sube', 's')
->join('b.cihaz', 'c')
->join('s.bolge', 'bol')
->join('s.sorumlu', 'sor')
->where("b.kontrolNo='$belgeNo'")
->getQuery()
->getScalarResult();
$belge = $basvurular[0]['kontrolBelgesi'];
$pdf = new Fpdi();
$pdf->AddFont('arial_tr','','arial_tr.php');
$pdf->AddFont('arial_tr','B','arial_tr_bold.php');
copy($this->ayarlar('siteYolu').'storage/'.$belge, 'gecici_yukleme/'.$belge);
$pageCount = $pdf->setSourceFile('gecici_yukleme/'.$belge);
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
$tplIdx = $pdf->importPage($pageNo);
$pdf->addPage();
$pdf->useTemplate($tplIdx, 5, 5, 200);
$pdf->SetFont('arial_tr', 'B', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->setY(247);
$pdf->SetX(10);
$pdf->Cell(90, 6, $this->fpdf_turkce($kanal), 0, 0, 'C', false); // bilgi@suleymanilgin.com.tr
$pdf->SetFont('arial_tr', '', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->setY(257);
$pdf->SetX(10);
if ($dogrulamaAraci == 1) {
$pdf->MultiCell(90, 4, $this->fpdf_turkce('Üstte yazılı sorumlu e-posta adresi tarafından doğrulama kodu ile doğrulanmıştır.'), 0, 'C', false); // Üstte yazılı sorumlu e-posta adresi tarafından doğrulama kodu ile doğrulanmıştır.
} else {
$pdf->MultiCell(90, 4, $this->fpdf_turkce('Üstte yazılı sorumlu telefon numarası tarafından doğrulama kodu ile doğrulanmıştır.'), 0, 'C', false); // Üstte yazılı sorumlu e-posta adresi tarafından doğrulama kodu ile doğrulanmıştır.
}
$pdf->SetFont('arial_tr', 'B', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->setY(252);
$pdf->SetX(10);
$pdf->Cell(90, 6, $this->fpdf_turkce('D.K. : ' . $basvurular[0]['kontrolDK']), 0, 0, 'C', false); // D.K. : 245 658
}
$pdf->Output('F', 'gecici_yukleme/'.$belge,true);
$this->deleteFile($belge);
$this->uploadFile($belge);
}
if ($belgeTipi==4){
$qb = $em->createQueryBuilder();
$basvurular = $qb->select('b.id,b.tahsilatBelgesi,b.tahsilatDK,b.tahsilatDK2')
->from('App:Basvurular', 'b')
->join('b.sube', 's')
->join('b.cihaz', 'c')
->join('s.bolge', 'bol')
->join('s.sorumlu', 'sor')
->where("b.tahsilatNo='$belgeNo'")
->getQuery()
->getScalarResult();
$belge = $basvurular[0]['tahsilatBelgesi'];
$pdf = new Fpdi();
$pdf->AddFont('arial_tr','','arial_tr.php');
$pdf->AddFont('arial_tr','B','arial_tr_bold.php');
copy($this->ayarlar('siteYolu').'storage/'.$belge, 'gecici_yukleme/'.$belge);
$pageCount = $pdf->setSourceFile('gecici_yukleme/'.$belge);
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
$tplIdx = $pdf->importPage($pageNo);
$pdf->addPage();
$pdf->useTemplate($tplIdx, 5, 5, 200);
$pdf->SetFont('arial_tr', 'B', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->setY(123);
$pdf->SetX(10);
$pdf->Cell(90, 6, $this->fpdf_turkce($kanal), 0, 0, 'C', false); // bilgi@suleymanilgin.com.tr
$pdf->SetFont('arial_tr', 'B', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->setY(127);
$pdf->SetX(10);
$pdf->Cell(90, 6, $this->fpdf_turkce('D.K. : ' . $basvurular[0]['tahsilatDK']), 0, 0, 'C', false); // D.K. : 245 658
$pdf->SetFont('arial_tr', '', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->setY(133);
$pdf->SetX(10);
if ($dogrulamaAraci == 1) {
$pdf->MultiCell(90, 4, $this->fpdf_turkce('Üstte yazılı sorumlu e-posta adresi tarafından doğrulama kodu ile doğrulanmıştır.'), 0, 'C', false); // Üstte yazılı sorumlu e-posta adresi tarafından doğrulama kodu ile doğrulanmıştır.
} else {
$pdf->MultiCell(90, 4, $this->fpdf_turkce('Üstte yazılı sorumlu telefon numarası tarafından doğrulama kodu ile doğrulanmıştır.'), 0, 'C', false); // Üstte yazılı sorumlu e-posta adresi tarafından doğrulama kodu ile doğrulanmıştır.
}
$pdf->SetFont('arial_tr', 'B', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->setY(123);
$pdf->SetX(110);
$pdf->Cell(90, 6, $this->fpdf_turkce($kanal2), 0, 0, 'C', false); // bilgi@suleymanilgin.com.tr
$pdf->SetFont('arial_tr', 'B', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->setY(127);
$pdf->SetX(110);
$pdf->Cell(90, 6, $this->fpdf_turkce('D.K. : ' . $basvurular[0]['tahsilatDK2']), 0, 0, 'C', false); // D.K. : 245 658
$pdf->SetFont('arial_tr', '', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->setY(133);
$pdf->SetX(110);
if ($dogrulamaAraci2 == 1) {
$pdf->MultiCell(90, 4, $this->fpdf_turkce('Üstte yazılı sorumlu e-posta adresi tarafından doğrulama kodu ile doğrulanmıştır.'), 0, 'C', false); // Üstte yazılı sorumlu e-posta adresi tarafından doğrulama kodu ile doğrulanmıştır.
} else {
$pdf->MultiCell(90, 4, $this->fpdf_turkce('Üstte yazılı sorumlu telefon numarası tarafından doğrulama kodu ile doğrulanmıştır.'), 0, 'C', false); // Üstte yazılı sorumlu e-posta adresi tarafından doğrulama kodu ile doğrulanmıştır.
}
}
$pdf->Output('F', 'gecici_yukleme/'.$belge,true);
$this->deleteFile($belge);
$this->uploadFile($belge);
}
return "";
}
public function replaceSpace($string)
{
$string = preg_replace("/\s+/", " ", $string);
$string = trim($string);
return $string;
}
public function subeSay($id,$roles){
$sql = "s.id is not null";
if ($roles=='ROLE_KULLANICI'){
$sql .= ' and k.id='.$id;
}
$em = $this->getDoctrine()->getManager();
$qb = $em->createQueryBuilder();
$veriler=$qb->select("s.id")
->from('App:Subeler', 's')
->join('s.bolge','b')
->join('b.kullanici','k')
->where($sql)
->getQuery()
->getScalarResult();
return intval(@count($veriler));
}
public function basvuruSay($id,$roles){
$sql = 'bas.id is not null and bas.basvuruNo is not null';
if ($roles=='ROLE_KULLANICI'){
$sql .= ' and k.id='.$id;
}
$em = $this->getDoctrine()->getManager();
$qb = $em->createQueryBuilder();
$veriler=$qb->select("bas.id")
->from('App:Basvurular', 'bas')
->join('bas.cihaz','c')
->join('c.sube','s')
->join('s.bolge','b')
->join('b.kullanici','k')
->where($sql)
->addGroupBy('bas.basvuruNo')
->getQuery()
->getScalarResult();
return intval(@count($veriler));
}
public function muayeneSay($id,$roles){
$sql = 'bas.id is not null and bas.muayeneNo is not null';
if ($roles=='ROLE_KULLANICI'){
$sql .= ' and k.id='.$id;
}
$em = $this->getDoctrine()->getManager();
$qb = $em->createQueryBuilder();
$veriler=$qb->select("bas.id")
->from('App:Basvurular', 'bas')
->join('bas.cihaz','c')
->join('c.sube','s')
->join('s.bolge','b')
->join('b.kullanici','k')
->where($sql)
->addGroupBy('bas.muayeneNo')
->getQuery()
->getScalarResult();
return intval(@count($veriler));
}
public function kontrolSay($id,$roles){
$sql = 'bas.id is not null and bas.kontrolNo is not null';
if ($roles=='ROLE_KULLANICI'){
$sql .= ' and k.id='.$id;
}
$em = $this->getDoctrine()->getManager();
$qb = $em->createQueryBuilder();
$veriler=$qb->select("bas.id")
->from('App:Basvurular', 'bas')
->join('bas.cihaz','c')
->join('c.sube','s')
->join('s.bolge','b')
->join('b.kullanici','k')
->where($sql)
->addGroupBy('bas.kontrolNo')
->getQuery()
->getScalarResult();
return intval(@count($veriler));
}
public function bad_request($mesaj){
return $this->json([
'error' => $mesaj,
], Response::HTTP_BAD_REQUEST);
}
public function ok_request(){
return $this->json([
'status' => 1,
], Response::HTTP_OK);
}
public function sorumluSay($id){
$em = $this->getDoctrine()->getManager();
$qb = $em->createQueryBuilder();
$veriler=$qb->select("k.id")
->from('App:User', 'k')
->where("(k.roles like '%ROLE_ADMIN%' or k.roles like '%ROLE_KULLANICI%') and k.id not in(".$id.")")
->getQuery()
->getScalarResult();
return intval(@count($veriler));
}
public function bolgeSay($id,$roles){
$sql = "b.id is not null";
if ($roles=='ROLE_KULLANICI'){
$sql .= ' and k.id='.$id;
}
$em = $this->getDoctrine()->getManager();
$qb = $em->createQueryBuilder();
$veriler=$qb->select("b.id")
->from('App:Bolgeler', 'b')
->join('b.kullanici','k')
->where($sql)
->getQuery()
->getScalarResult();
return intval(@count($veriler));
}
public function cihazSay($id,$roles){
$sql = "c.id is not null";
if ($roles=='ROLE_KULLANICI'){
$sql .= ' and k.id='.$id;
}
$em = $this->getDoctrine()->getManager();
$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($sql)
->getQuery()
->getScalarResult();
return intval(@count($veriler));
}
public function kullaniciDetay($id,$alan)
{
if ($id!=''){
$em = $this->getDoctrine()->getManager();
$qb = $em->createQueryBuilder();
$ayarlar=$qb->select("e.$alan")
->from('App:User', 'e')
->where('e.id='.$id)
->getQuery()
->setResultCacheId($alan)
->setResultCacheLifetime(60)
->getScalarResult();
return $ayarlar[0][$alan];
}else{
return "";
}
}
function mobilBildirimGonder($baslik,$metin,$kullanici)
{
$em = $this->getDoctrine()->getManager();
$token = $this->kullaniciDetay($kullanici,'fbToken');
if($token!=""){
$qb = $em->createQueryBuilder();
$bildirimSay=$qb->select("b.id")
->from('App:Bildirimler', 'b')
->join('b.kullanici','k')
->where('b.okuma = 0 and k.id='.$kullanici)
->getQuery()
->getScalarResult();
$factory = (new Factory)
->withServiceAccount('ozmenkalibrasyon-firebase-adminsdk-ek3dg-3edc106485.json')
->withDatabaseUri('firebase-adminsdk-ek3dg@ozmenkalibrasyon.iam.gserviceaccount.com');
$auth = $factory->createAuth();
$cloudMessaging = $factory->createMessaging();
$message = CloudMessage::withTarget('token', $token)
->withNotification(Notification::create($baslik, $metin)) // optional
->withData(['payload' => ""])
->withAndroidConfig(AndroidConfig::fromArray([
'ttl' => '3600s',
'priority' => 'normal',
'notification' => [
'color' => '#ff0000',
'sound' => 'default',
],
]))
->withApnsConfig(ApnsConfig::fromArray([
'headers' => [
'apns-priority' => '10',
],
'payload' => [
'aps' => [
'badge' => count($bildirimSay),
'sound' => 'default',
],
],
]));
try {
$cloudMessaging->send($message);
}catch (\Exception $e){}
}
return "";
}
function d2ArrayConvert($array){
$array = unserialize($array);
return $array;
}
}