<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use App\Repository\UserPlatformRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Doctrine\ORM\EntityManagerInterface;
use App\Acme\Bundle\Utility\ViewUtility\UtilityMenusBackend;
use App\Acme\Bundle\Utility\TemplatesUtility\MenusStandard;
use App\Form\SubscriptionForm\UserMultilType;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use App\Entity\UserPlatform;
use App\Entity\Product;
use App\Form\UserPlatformType;
use App\Repository\CategoriProductRepository;
use App\Repository\CommissionRepository;
use App\Repository\CoursDeChangeRepository;
use App\Repository\PriceProductRepository;
use App\Repository\ProductListRepository;
use App\Repository\ProductRepository;
use App\Repository\StockRepository;
use Exception;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
class HomeController extends AbstractController
{
/**
* @Route("/", name="app_home")
*/
public function index(EntityManagerInterface $entityManager, AuthorizationCheckerInterface $authorizationChecker, ProductRepository $productRepository, UserPlatformRepository $userPlatformRepository, PriceProductRepository $priceProductRepository, StockRepository $stockRepository, CategoriProductRepository $categoriProductRepository, ProductListRepository $productListRepository, CoursDeChangeRepository $coursDeChangeRepository, CommissionRepository $commissionRepository): Response
{
// return $this->redirectToRoute('app_product_index', [], Response::HTTP_SEE_OTHER);
// $templatesMenus = new UtilityMenusBackend(0);
// MenusStandard::setTitleTemplate($templatesMenus);
// MenusStandard::setTitleApplication($templatesMenus);
// MenusStandard::setMenusStandard($templatesMenus, $authorizationChecker);
$clainService = $userPlatformRepository->findBy(['email' => 'clainservice@gmail.com']);
$user = $this->getUser();
if ($clainService) {
$allProducts = $productRepository->getAllProductsByUser($clainService[0]->getId());
$allProductsDay = $productRepository->getAllProductsDayByUser($clainService[0]->getId());
$productsDayLeft = $productRepository->getAllProductsDayByUserForLeft($clainService[0]->getId());
$productsDayRight = $productRepository->getAllProductsDayByUserForRight($clainService[0]->getId());
// section mode produits
$priceMode = [];
$modeProducts = $productRepository->getCatModeAffiche($clainService[0]->getId());
foreach ($modeProducts as $key => $value) {
// dd($priceProductRepository->findBy(['product'=> $value->getId()]));
$priceMode[] = [
"idProduct" => $value->getId(),
"productTitle" => $value->getDesctription(),
"productImage" => $value->getPicture(),
"prix" => $priceProductRepository->findBy(['product' => $value->getId()])[0]->getPriceCustomer()
];
}
// dd($priceMode);
// tous les catégories
$catTable = [];
$categories = $categoriProductRepository->findAll();
foreach ($categories as $key => $value) {
$catTable[] = [
"id" => $value->getId(),
"title" => $value->getTitle(),
"image" => $value->getImageName()
];
}
// dd($catTable);
$productPriceAndStock = [];
$productDayPriceAndStock = [];
$productDayLeftPriceAndStock = [];
$productDayRightPriceAndStock = [];
foreach ($allProducts as $key => $value) {
$idValue = $value->getId();
$price = $priceProductRepository->getPriceProduct($idValue);
$stock = $stockRepository->getProduitStock($value);
$productPriceAndStock[] = [
"id" => $value->getId(),
"name" => $value->getTitle(),
"description" => $value->getDesctription(),
"imageName" => $value->getPicture(),
"devise" => $value->getFkdevise()->getId(),
"priceCust" => $price->getPriceCustomer(),
"priceDealer" => $price->getPriceDealer(),
"stockDispo" => $stock->getStockDispo(),
"stockReel" => $stock->getStockReel()
];
}
// tous les produits du jour
foreach ($allProductsDay as $key => $value) {
$idValue = $value->getId();
$price = $priceProductRepository->getPriceProduct($idValue);
// dd($price);
$stock = $stockRepository->getProduitStock($value);
$productDayPriceAndStock[] = [
"id" => $value->getId(),
"name" => $value->getTitle(),
"description" => $value->getDesctription(),
"imageName" => $value->getPicture(),
"devise" => $value->getFkdevise()->getId(),
"priceCust" => $price->getPriceCustomer(),
"priceDealer" => $price->getPriceDealer(),
"stockDispo" => $stock->getStockDispo(),
"stockReel" => $stock->getStockReel()
];
}
// offre du jour du gauche
foreach ($productsDayLeft as $key => $value) {
$idValue = $value->getId();
$price = $priceProductRepository->getPriceProduct($idValue);
$stock = $stockRepository->getProduitStock($value);
$productDayLeftPriceAndStock[] = [
"id" => $value->getId(),
"name" => $value->getTitle(),
"description" => $value->getDesctription(),
"imageName" => $value->getPicture(),
"devise" => $value->getFkdevise()->getId(),
"priceCust" => $price->getPriceCustomer(),
"priceDealer" => $price->getPriceDealer(),
"stockDispo" => $stock->getStockDispo(),
"stockReel" => $stock->getStockReel()
];
}
// offre du jour du droite
foreach ($productsDayRight as $key => $value) {
$idValue = $value->getId();
$price = $priceProductRepository->getPriceProduct($idValue);
$stock = $stockRepository->getProduitStock($value);
$productDayRightPriceAndStock[] = [
"id" => $value->getId(),
"name" => $value->getTitle(),
"description" => $value->getDesctription(),
"imageName" => $value->getPicture(),
"devise" => $value->getFkdevise()->getId(),
"priceCust" => $price->getPriceCustomer(),
"priceDealer" => $price->getPriceDealer(),
"stockDispo" => $stock->getStockDispo(),
"stockReel" => $stock->getStockReel(),
];
}
} else {
$productPriceAndStock = [];
$productDayPriceAndStock = [];
$productDayLeftPriceAndStock = [];
$productDayRightPriceAndStock = [];
}
shuffle($productPriceAndStock);
$chaussure = [];
$montre = [];
$femmes = [];
$timberland = [];
$air = [];
$gucci = [];
$alo = [];
$loui = [];
$dior = [];
$chaussures = $productListRepository->getProduitMarque("Chaussures", 1);
$montres = $productListRepository->getProduitMarque("Montre", 1);
$femme = $productListRepository->getProduitMarque("Pour femme", 1);
$timberlands = $productListRepository->getProduitMarque("Chaussure timberland", 1);
$airs = $productListRepository->getProduitMarque("Chaussure air jord", 1);
$guccis = $productListRepository->getProduitMarque("Gucci", 1);
$alos = $productListRepository->getProduitMarque("Alo yoga", 1);
$louis = $productListRepository->getProduitMarque("sac Louis Vuitton", 1);
$diors = $productListRepository->getProduitMarque("marque Christian Dior", 1);
$cours_change = $coursDeChangeRepository->findAll();
$commission = $commissionRepository->findAll();
// Traitement des produits récupérés
foreach ($chaussures as $key => $value) {
// dd($value->getProduct());
if (isset($cours_change[0])) {
$prix = ($cours_change[0]->getAriary() * $value->getProduct()[0]['price']);
if (isset($commission[0])) {
$commiss = ($commission[0]->getMontant() / 100) * $prix;
$prixFinal = $prix + $commiss;
} else {
$prixFinal = $prix;
}
} else {
$prixFinal = $value->getProduct()[0]['price'];
}
// Préparation des produits pour le retour
$chaussure[] = [
"title" => $value->getProduct()[0]['title'],
"price" => $prixFinal,
"pic_url" => $value->getProduct()[0]['img'],
"num_iid" => $value->getIdProduct(),
// "detail_url" => $value['product_url'],
];
}
// Traitement des produits récupérés
foreach ($montres as $key => $value) {
// dd($value->getProduct());
if (isset($cours_change[0])) {
$prix = ($cours_change[0]->getAriary() * $value->getProduct()[0]['price']);
if (isset($commission[0])) {
$commiss = ($commission[0]->getMontant() / 100) * $prix;
$prixFinal = $prix + $commiss;
} else {
$prixFinal = $prix;
}
} else {
$prixFinal = $value->getProduct()[0]['price'];
}
// Préparation des produits pour le retour
$montre[] = [
"title" => $value->getProduct()[0]['title'],
"price" => $prixFinal,
"pic_url" => $value->getProduct()[0]['img'],
"num_iid" => $value->getIdProduct(),
// "detail_url" => $value['product_url'],
];
}
// Traitement des produits récupérés
foreach ($femme as $key => $value) {
// dd($value->getProduct());
if (isset($cours_change[0])) {
$prix = ($cours_change[0]->getAriary() * $value->getProduct()[0]['price']);
if (isset($commission[0])) {
$commiss = ($commission[0]->getMontant() / 100) * $prix;
$prixFinal = $prix + $commiss;
} else {
$prixFinal = $prix;
}
} else {
$prixFinal = $value->getProduct()[0]['price'];
}
// Préparation des produits pour le retour
$femmes[] = [
"title" => $value->getProduct()[0]['title'],
"price" => $prixFinal,
"pic_url" => $value->getProduct()[0]['img'],
"num_iid" => $value->getIdProduct(),
// "detail_url" => $value['product_url'],
];
}
foreach ($timberlands as $key => $value) {
// dd($value->getProduct());
if (isset($cours_change[0])) {
$prix = ($cours_change[0]->getAriary() * $value->getProduct()[0]['price']);
if (isset($commission[0])) {
$commiss = ($commission[0]->getMontant() / 100) * $prix;
$prixFinal = $prix + $commiss;
} else {
$prixFinal = $prix;
}
} else {
$prixFinal = $value->getProduct()[0]['price'];
}
// Préparation des produits pour le retour
$timberland[] = [
"title" => $value->getProduct()[0]['title'],
"price" => $prixFinal,
"pic_url" => $value->getProduct()[0]['img'],
"num_iid" => $value->getIdProduct(),
// "detail_url" => $value['product_url'],
];
}
foreach ($airs as $key => $value) {
// dd($value->getProduct());
if (isset($cours_change[0])) {
$prix = ($cours_change[0]->getAriary() * $value->getProduct()[0]['price']);
if (isset($commission[0])) {
$commiss = ($commission[0]->getMontant() / 100) * $prix;
$prixFinal = $prix + $commiss;
} else {
$prixFinal = $prix;
}
} else {
$prixFinal = $value->getProduct()[0]['price'];
}
// Préparation des produits pour le retour
$air[] = [
"title" => $value->getProduct()[0]['title'],
"price" => $prixFinal,
"pic_url" => $value->getProduct()[0]['img'],
"num_iid" => $value->getIdProduct(),
// "detail_url" => $value['product_url'],
];
}
foreach ($guccis as $key => $value) {
// dd($value->getProduct());
if (isset($cours_change[0])) {
$prix = ($cours_change[0]->getAriary() * $value->getProduct()[0]['price']);
if (isset($commission[0])) {
$commiss = ($commission[0]->getMontant() / 100) * $prix;
$prixFinal = $prix + $commiss;
} else {
$prixFinal = $prix;
}
} else {
$prixFinal = $value->getProduct()[0]['price'];
}
// Préparation des produits pour le retour
$gucci[] = [
"title" => $value->getProduct()[0]['title'],
"price" => $prixFinal,
"pic_url" => $value->getProduct()[0]['img'],
"num_iid" => $value->getIdProduct(),
// "detail_url" => $value['product_url'],
];
}
foreach ($alos as $key => $value) {
// dd($value->getProduct());
if (isset($cours_change[0])) {
$prix = ($cours_change[0]->getAriary() * $value->getProduct()[0]['price']);
if (isset($commission[0])) {
$commiss = ($commission[0]->getMontant() / 100) * $prix;
$prixFinal = $prix + $commiss;
} else {
$prixFinal = $prix;
}
} else {
$prixFinal = $value->getProduct()[0]['price'];
}
// Préparation des produits pour le retour
$alo[] = [
"title" => $value->getProduct()[0]['title'],
"price" => $prixFinal,
"pic_url" => $value->getProduct()[0]['img'],
"num_iid" => $value->getIdProduct(),
// "detail_url" => $value['product_url'],
];
}
foreach ($louis as $key => $value) {
// dd($value->getProduct());
if (isset($cours_change[0])) {
$prix = ($cours_change[0]->getAriary() * $value->getProduct()[0]['price']);
if (isset($commission[0])) {
$commiss = ($commission[0]->getMontant() / 100) * $prix;
$prixFinal = $prix + $commiss;
} else {
$prixFinal = $prix;
}
} else {
$prixFinal = $value->getProduct()[0]['price'];
}
// Préparation des produits pour le retour
$loui[] = [
"title" => $value->getProduct()[0]['title'],
"price" => $prixFinal,
"pic_url" => $value->getProduct()[0]['img'],
"num_iid" => $value->getIdProduct(),
// "detail_url" => $value['product_url'],
];
}
foreach ($diors as $key => $value) {
// dd($value->getProduct());
if (isset($cours_change[0])) {
$prix = ($cours_change[0]->getAriary() * $value->getProduct()[0]['price']);
if (isset($commission[0])) {
$commiss = ($commission[0]->getMontant() / 100) * $prix;
$prixFinal = $prix + $commiss;
} else {
$prixFinal = $prix;
}
} else {
$prixFinal = $value->getProduct()[0]['price'];
}
// Préparation des produits pour le retour
$dior[] = [
"title" => $value->getProduct()[0]['title'],
"price" => $prixFinal,
"pic_url" => $value->getProduct()[0]['img'],
"num_iid" => $value->getIdProduct(),
// "detail_url" => $value['product_url'],
];
}
return $this->render('clainFront/accueil/index.html.twig', [
'user' => $user,
'products' => $productPriceAndStock,
'productsDay' => $allProductsDay,
'productsDayAll' => $productDayPriceAndStock,
'productsDayLeft' => $productDayLeftPriceAndStock,
'productsDayRight' => $productDayRightPriceAndStock,
'modeProducts' => $modeProducts,
'priceMode' => $priceMode,
'categories' => $categories,
'catTable' => $catTable,
'chaussures' => $chaussure,
'montres' => $montre,
'femmes' => $femmes,
'timberlands' => $timberland,
'airs' => $air,
'guccis' => $gucci,
'alos' => $alo,
'louis' => $loui,
'diors' => $dior
]);
}
/**
* @Route("/inscription-client", name="app_home_inscription", methods={"GET", "POST"})
*/
public function inscription(Request $request, UserPlatformRepository $userPlatformRepository, UserPasswordEncoderInterface $passwordEncoder): Response
{
$user = new UserPlatform();
$form = $this->createForm(UserMultilType::class, $user);
$form->handleRequest($request);
$arrayresult = array("error" => false, "msg" => "");
if ($form->isSubmitted() && $form->isValid()) {
try {
if ($user->getPassword() != $form->get('confirmpass')->getData()) {
$arrayresult['error'] = true;
$arrayresult['msg'] = "Mot de passe non confirmé.";
} else if (strpos($user->getMail(), " ")) {
$arrayresult['error'] = true;
$arrayresult['msg'] = "l'identifiant \"" . $user->getMail() . "\" ne doit pas contenir un espace.";
} else if (strlen($user->getMail()) < 5) {
$arrayresult['error'] = true;
$arrayresult['msg'] = "l'identifiant \"" . $user->getMail() . "\" doit contenir plus de 5 caracteres.";
} else {
$user->setEmail($user->getMail());
$user->setRoles(["ROLE_CUSTOMER"]);
$user->setPassword(
$passwordEncoder->encodePassword($user, $user->getPassword())
);
$userPlatformRepository->add($user, true);
// Stocker l'email dans la session
$request->getSession()->set(Security::LAST_USERNAME, $user->getEmail());
return $this->redirectToRoute('app_login', [], Response::HTTP_SEE_OTHER);
}
} catch (Exception $exc) {
// dd($exc->getMessage());
return $this->render('frontView/error.html.twig', [
'msg' => $exc->getMessage(),
]);
}
}
return $this->renderForm('frontView/inscription/inscription.html.twig', [
'form' => $form,
'arrayresult' => $arrayresult,
]);
}
/**
* @Route("/edit-profil/{id}", name="app_home_edit_profil", methods={"GET", "POST"})
*/
public function editProfil(Request $request, UserPlatform $userPlatform, UserPlatformRepository $userPlatformRepository, UserPasswordEncoderInterface $passwordEncoder): Response
{
$form = $this->createForm(UserMultilType::class, $userPlatform);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$userPlatformRepository->add($userPlatform, true);
}
return $this->renderForm('frontView/inscription/editprofil.html.twig', [
'admin' => $userPlatform,
'form' => $form
]);
}
/**
* @Route("/aroma-madagascar", name="app_aroma_madagascar", methods={"GET", "POST"})
*/
public function aromaMadagascar(EntityManagerInterface $entityManager): Response
{
$orderby = array('points' => 'DESC');
$criteria = array();
return $this->render('frontView/boutique/indexaroma.html.twig', [
'products' => $entityManager->getRepository(Product::class)->getProductShop(3)
]);
}
/**
* @Route("/kiki-creation-madagascar", name="app_kiki_madagascar", methods={"GET", "POST"})
*/
public function kikiMadagascar(EntityManagerInterface $entityManager): Response
{
$orderby = array('points' => 'DESC');
$criteria = array();
return $this->render('frontView/boutique/indexkiki.html.twig', [
'products' => $entityManager->getRepository(Product::class)->getProductShop(4)
]);
}
/**
* @Route("/infos", name="app_rapeto_infos", methods={"GET", "POST"})
*/
public function infosRapeto(): Response
{
return $this->render('frontView/boutique/infos.html.twig', []);
}
/**
* @Route("/access-denied", name="app_home_access_denied")
*/
public function accesDenied(EntityManagerInterface $entityManager): Response
{
return $this->render('security/error403.html.twig', []);
}
}