<?php
namespace App\Controller;
use App\Entity\BusinessTime;
use App\Entity\Impressum;
use App\Entity\Invoices;
use App\Entity\Licence;
use App\Entity\LicenceType;
use App\Entity\Notifications;
use App\Entity\Orders;
use App\Entity\Pages;
use App\Entity\Playlists;
use App\Entity\Questions;
use App\Entity\ShopData;
use App\Entity\ShopRequest;
use App\Entity\Tables;
use App\Entity\Tickets;
use App\Entity\UpgradeLicenceBlitzkasse;
use App\Entity\Users;
use App\Form\BussinesTimeType;
use App\Form\ImpressumFormType;
use App\Form\RegistrationFormType;
use App\Form\ShopDataFormType;
use App\Form\UserFormType;
use Doctrine\ORM\EntityManagerInterface;
use Endroid\QrCode\Color\Color;
use Endroid\QrCode\Encoding\Encoding;
use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelLow;
use Endroid\QrCode\Label\Label;
use Endroid\QrCode\Logo\Logo;
use Endroid\QrCode\QrCode;
use Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeMargin;
use Endroid\QrCode\Writer\PngWriter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Uid\Uuid;
class MainController extends AbstractController
{
#[Route('/', name: 'main')]
public function index(EntityManagerInterface $entityManager): Response
{
//$content = $entityManager->getRepository(Pages::class)->findOneBy(['slug'=> 'index']);
return $this->render('main/index.html.twig', [
'controller_name' => 'MainController',
'user' => $this->getUser(),
// 'content' => $content
]);
}
#[Route('/registration/confirm', name: 'userNotificationBeta')]
public function confirmRegistration(): Response
{
return $this->render('security/userNotificationBeta.html.twig', [
'controller_name' => 'MainController',
'user' => $this->getUser()
]);
}
#[Route('dashboard/user/shopProfile', name:'shopProfile')]
public function shopProfile(Request $request, EntityManagerInterface $entityManager): Response
{
$currentUser = $this->getUser();
$shop = $entityManager->getRepository(ShopData::class)->findOneBy(array('createdBy'=> $this->getUser()->getId()));
$form = $this->createForm(ShopDataFormType::class, $shop);
$form->handleRequest($request);
$impressum = $entityManager->getRepository(Impressum::class)->findOneBy(['createdBy'=> $this->getUser()->getId()]);
$timeWork = $entityManager->getRepository(BusinessTime::class)->findOneBy(array('createdBy'=> $this->getUser()->getId()));
$tickets = $entityManager->getRepository(Tickets::class)->findOneBy(array('createdBy'=> $this->getUser()->getId()));
$invoices = $entityManager->getRepository(Invoices::class)->findOneBy(array('createdBy'=> $this->getUser()->getId()));
$licencesType = $entityManager->getRepository(LicenceType::class)->findAll();
$licencesMy = $entityManager->getRepository(Licence::class)->findOneBy(array('createdBy'=> $this->getUser()->getId()));
$notification = $entityManager->getRepository(Notifications::class)->findOneBy(array('createdBy'=> $this->getUser()->getId()));
$form2 = null;
$form3 = null;
$btime = new BusinessTime();
if($timeWork) {
$form2 = $this->createForm(BussinesTimeType::class, $timeWork);
} else {
$btime->setCreatedBy($this->getUser());
$form2 = $this->createForm(BussinesTimeType::class, $btime);
}
$impressumData = new Impressum();
if($impressum) {
$form3 = $this->createForm(ImpressumFormType::class, $impressum);
} else {
$impressumData->setCreatedBy($this->getUser());
$form3 = $this->createForm(ImpressumFormType::class, $impressumData);
}
$form2->handleRequest($request);
if ($form2->isSubmitted() && $form2->isValid()) {
$entityManager->persist($btime);
$entityManager->flush();
return $this->render('security/userShopProfile.html.twig', [
'name' => "Test",
'form' => $form->createView(),
'form2' => $form2->createView(),
'form3' => $form3->createView(),
'currentUser' => $currentUser,
'user' => $currentUser,
'tickets' => $tickets,
'invoices' => $invoices,
'licenses' => $licencesType,
'myLicence' => $licencesMy,
'notification' => $notification,
]);
}
$form3->handleRequest($request);
if ($form3->isSubmitted()) {
if(!$impressum) {
$entityManager->persist($impressumData);
}
$entityManager->flush();
return $this->render('security/userShopProfile.html.twig', [
'name' => "Test",
'form' => $form->createView(),
'form2' => $form2->createView(),
'form3' => $form3->createView(),
'currentUser' => $currentUser,
'user' => $currentUser,
'tickets' => $tickets,
'invoices' => $invoices,
'licenses' => $licencesType,
'myLicence' => $licencesMy,
'notification' => $notification,
]);
}
if ($form->isSubmitted()) {
// encode the plain password
$shop->setShopUrl($this->slugify($form->get('geschaftName')->getData()));
$entityManager->flush();
return $this->render('security/userShopProfile.html.twig', [
'name' => "Test",
'form' => $form->createView(),
'form2' => $form2->createView(),
'form3' => $form3->createView(),
'currentUser' => $currentUser,
'user' => $currentUser,
'tickets' => $tickets,
'invoices' => $invoices,
'licenses' => $licencesType,
'myLicence' => $licencesMy,
'notification' => $notification,
]);
}
return $this->render('security/userShopProfile.html.twig', [
'name' => "Test",
'form' => $form->createView(),
'form2' => $form2->createView(),
'form3' => $form3->createView(),
'currentUser' => $currentUser,
'tickets' => $tickets,
'invoices' => $invoices,
'licenses' => $licencesType,
'myLicence' => $licencesMy,
'notification' => $notification,
'user' => $currentUser
]);
}
public function slugify($text, string $divider = '-')
{
// replace non letter or digits by divider
$text = preg_replace('~[^\pL\d]+~u', $divider, $text);
// transliterate
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);
// trim
$text = trim($text, $divider);
// remove duplicate divider
$text = preg_replace('~-+~', $divider, $text);
// lowercase
$text = strtolower($text);
if (empty($text)) {
return 'n-a';
}
return $text;
}
#[Route('dashboard/user/profile', name:'userProfile')]
public function userProfile(Request $request, EntityManagerInterface $entityManager): Response
{
$currentUser = $this->getUser();
$form = $this->createForm(UserFormType::class, $currentUser);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// encode the plain password
$entityManager->flush();
return $this->render('security/userProfile.html.twig', [
'name' => "Test",
'form' => $form->createView(),
'currentUser' => $currentUser,
'user' => $currentUser
]);
}
return $this->render('security/userProfile.html.twig', [
'name' => "Test",
'form' => $form->createView(),
'currentUser' => $currentUser,
'user' => $currentUser
]);
}
#[Route('dashboard/shop/qrcodes', name:'allQRCodes')]
public function allQRCodes(EntityManagerInterface $entityManager): Response
{
$currentUser = $this->getUser();
$shop = new ShopData();
$quest = new Questions();
$quest = $entityManager->getRepository(Questions::class)->findOneBy(['createdBy'=>$this->getUser()]);
$shop = $entityManager->getRepository(ShopData::class)->findOneBy(['createdBy'=> $this->getUser()]);
$playlist = $entityManager->getRepository(Playlists::class)->findBy(['createdBy'=>$this->getUser()]);
// /questions/view/{id}
/// /restaurant-und-cafe/shop/Demo
///
$arrayOfQuestion = $entityManager->getRepository(Questions::class)->findBy(['createdBy'=>$this->getUser()]);
$arrayOfTische = $entityManager->getRepository(Tables::class)->findBy(['createdBy'=>$this->getUser()]);
/// /restaurant-und-cafe/menu/Demo
///
///
$arrrayQR = array();
$arrrayPlaylist = array();
$arrayTische = array();
$arrayTischeAdditional = array();
$image = "https://blitzconnect.de/images/logos/" . $shop->getImageNameLogo();
foreach($arrayOfTische as $tische) {
$tischeURl = $_SERVER['HTTP_HOST'] . "/restaurant-und-cafe/shop/" . $shop->getShopUrl() . "/" . $tische->getName();
$tischeQRCODE = QrCode::create($tischeURl)
->setEncoding(new Encoding('UTF-8'))
->setErrorCorrectionLevel(new ErrorCorrectionLevelLow())
->setSize(300)
->setMargin(10)
->setRoundBlockSizeMode(new RoundBlockSizeModeMargin())
->setForegroundColor(new Color(0, 0, 0))
->setBackgroundColor(new Color(255, 255, 255));
$writer = new PngWriter();
// Create generic label
$label = Label::create($shop->getShopUrl())
->setTextColor(new Color(255, 0, 0));
$tischeResultQR = $writer->write($tischeQRCODE);
$dataUri = $tischeResultQR->getDataUri();
array_push($arrayTische, ["url"=>$dataUri, "link"=>$tischeURl, "name"=> $tische->getName()]);
}
foreach($arrayOfTische as $tische) {
$tischeURl = $_SERVER['HTTP_HOST'] . "/restaurant-und-cafe/shops/" . $shop->getShopUrl() . "/" . $tische->getName();
$tischeQRCODE = QrCode::create($tischeURl)
->setEncoding(new Encoding('UTF-8'))
->setErrorCorrectionLevel(new ErrorCorrectionLevelLow())
->setSize(300)
->setMargin(10)
->setRoundBlockSizeMode(new RoundBlockSizeModeMargin())
->setForegroundColor(new Color(0, 0, 0))
->setBackgroundColor(new Color(255, 255, 255));
$writer = new PngWriter();
// Create generic label
$label = Label::create($shop->getGeschaftName())
->setTextColor(new Color(255, 0, 0));
$tischeResultQR = $writer->write($tischeQRCODE);
$dataUri = $tischeResultQR->getDataUri();
array_push($arrayTischeAdditional, ["url"=>$dataUri, "link"=>$tischeURl, "name"=> $tische->getName()]);
}
foreach($arrayOfQuestion as $quest1) {
$question = $_SERVER['HTTP_HOST'] . "/questions/view/" . $quest1->getId();
$qrCodeQuestionT = QrCode::create($question)
->setEncoding(new Encoding('UTF-8'))
->setErrorCorrectionLevel(new ErrorCorrectionLevelLow())
->setSize(300)
->setMargin(10)
->setRoundBlockSizeMode(new RoundBlockSizeModeMargin())
->setForegroundColor(new Color(0, 0, 0))
->setBackgroundColor(new Color(255, 255, 255));
$writer = new PngWriter();
// Create generic label
$label = Label::create('')
->setTextColor(new Color(255, 0, 0));
$resultquestion = $writer->write($qrCodeQuestionT);
$dataUri = $resultquestion->getDataUri();
array_push($arrrayQR, $dataUri);
}
$arrayPlaylistLink = array();
foreach($playlist as $p) {
$url = $p->getPlaylistUrl();
array_push($arrayPlaylistLink, $p->getId());
$qrCodeQuestionT = QrCode::create($url)
->setEncoding(new Encoding('UTF-8'))
->setErrorCorrectionLevel(new ErrorCorrectionLevelLow())
->setSize(300)
->setMargin(10)
->setRoundBlockSizeMode(new RoundBlockSizeModeMargin())
->setForegroundColor(new Color(0, 0, 0))
->setBackgroundColor(new Color(255, 255, 255));
$writer = new PngWriter();
// Create generic label
$label = Label::create('')
->setTextColor(new Color(255, 0, 0));
$resultquestion = $writer->write($qrCodeQuestionT);
$dataUri = $resultquestion->getDataUri();
$question = $_SERVER['HTTP_HOST'] . "/stream/". $shop->getShopUrl() ."/" . $p->getId();
array_push($arrrayPlaylist, ["url"=>$dataUri, "link"=>$question]);
}
$menuUrl = $_SERVER['HTTP_HOST'] . "/restaurant-und-cafe/menu/" . $shop->getShopUrl();
$shopUrl = $_SERVER['HTTP_HOST'] . "/restaurant-und-cafe/shop/" . $shop->getShopUrl();
$writer = new PngWriter();
$qrCode = QrCode::create($menuUrl)
->setEncoding(new Encoding('UTF-8'))
->setErrorCorrectionLevel(new ErrorCorrectionLevelLow())
->setSize(300)
->setMargin(10)
->setRoundBlockSizeMode(new RoundBlockSizeModeMargin())
->setForegroundColor(new Color(0, 0, 0))
->setBackgroundColor(new Color(255, 255, 255));
$qrCode2 = QrCode::create($shopUrl)
->setEncoding(new Encoding('UTF-8'))
->setErrorCorrectionLevel(new ErrorCorrectionLevelLow())
->setSize(300)
->setMargin(10)
->setRoundBlockSizeMode(new RoundBlockSizeModeMargin())
->setForegroundColor(new Color(0, 0, 0))
->setBackgroundColor(new Color(255, 255, 255));
// Create generic logo
// Create generic label
$label = Label::create('')
->setTextColor(new Color(255, 0, 0));
$resultmenu = $writer->write($qrCode);
$resultshop = $writer->write($qrCode2);
$dataUri = $resultmenu->getDataUri();
$dataUrishop = $resultshop->getDataUri();
return $this->render('security/qrcodeShop.html.twig', [
'name' => "Test",
'menuQR' => $dataUri,
'shopQR' => $dataUrishop,
'questionQR' => $arrrayQR,
'currentUser' => $currentUser,
'menu_link' => $menuUrl,
'shop_link' => $shopUrl,
'playlist' => $arrrayPlaylist,
'tische'=> $arrayTische
]);
}
#[Route('dashboard/shop/setting', name:'shopSetting')]
public function shopSetting(Request $request, EntityManagerInterface $entityManager): Response
{
$currentUser = $this->getUser();
$shop = $entityManager->getRepository(ShopData::class)->findOneBy(array("createdBy"=>$currentUser));
$form = $this->createForm(ShopDataFormType::class, $shop);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// encode the plain password
$shop->setUniqueShopID(Uuid::v4());
$entityManager->flush();
$sendRequest = new ShopRequest();
$sendRequest->setCreatedBy($this->getUser());
$entityManager->persist($sendRequest);
$entityManager->flush();
return $this->render('security/shopSetting.html.twig', [
'name' => "Test",
'form' => $form->createView(),
'currentUser' => $currentUser
]);
}
return $this->render('security/shopSetting.html.twig', [
'name' => "Test",
'form' => $form->createView(),
'currentUser' => $currentUser
]);
}
#[Route('dashboard/comming-soon', name:'commingsoon')]
public function commingsoon(Request $request, EntityManagerInterface $entityManager): Response
{
$currentUser = $this->getUser();
return $this->render('security/commingsoon.html.twig', [
'name' => "Test",
'currentUser' => $currentUser
]);
}
#[Route('licence/key/requests', name:'checkKeyLicence')]
public function CheckLicenceKeyBlitzkasseUpdate(Request $request, EntityManagerInterface $entityManager): Response
{
$key = $request->get("key");
$licence = $entityManager->getRepository(UpgradeLicenceBlitzkasse::class)->findOneBy(['keylicence'=>$key]);
return $this->json($licence);
}
#[Route('licence/key/update', name:'checkKeyLicenceupdate')]
public function CheckLicenceKeyBlitzkasseUpdateEdit(Request $request, EntityManagerInterface $entityManager): Response
{
$key = $request->get("key");
$licence = $entityManager->getRepository(UpgradeLicenceBlitzkasse::class)->findOneBy(['keylicence'=>$key]);
$licence->setStatus("1");
$entityManager->persist($licence);
$entityManager->flush();
return $this->json("true");
}
#[Route('dashboard/admin/requests/{id}', name:'showAllRequest')]
public function showAllRequest(Request $request, EntityManagerInterface $entityManager): Response
{
$currentUser = $this->getUser();
$shop = new ShopData();
$form = $this->createForm(ShopDataFormType::class, $shop);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// encode the plain password
$entityManager->flush();
$sendRequest = new ShopRequest();
$sendRequest->setCreatedBy($this->getUser());
return $this->render('security/shopSetting.html.twig', [
'name' => "Test",
'form' => $form->createView(),
'currentUser' => $currentUser
]);
}
return $this->render('security/shopSetting.html.twig', [
'name' => "Test",
'form' => $form->createView(),
'currentUser' => $currentUser
]);
}
}