src/Controller/MarketPlace/CategorieErpCategorieMarketPlaceController.php line 109

Open in your IDE?
  1. <?php
  2. namespace App\Controller\MarketPlace;
  3. use App\Entity\Articles\Article;
  4. use App\Entity\Articles\ArticleCategorie;
  5. use App\Entity\Articles\Categorie;
  6. use App\Entity\MarketPlace\ArticleMarketPlace;
  7. use App\Entity\MarketPlace\CategorieErpCategorieMarketPlace;
  8. use App\Entity\MarketPlace\CompteMarketPlace;
  9. use App\Entity\MarketPlace\MarketPlace;
  10. use App\Form\MarketPlace\AssocierCategorieErpCategorieMarketPlaceType;
  11. use Doctrine\ORM\EntityManagerInterface;
  12. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  13. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  14. use Symfony\Component\HttpFoundation\JsonResponse;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use Symfony\Component\Routing\Annotation\Route;
  18. use Symfony\Component\Validator\Validator\ValidatorInterface;
  19. use Symfony\Contracts\Translation\TranslatorInterface;
  20. class CategorieErpCategorieMarketPlaceController extends AbstractController
  21. {
  22.     /**
  23.      * @Route("/associer-categorie-marketplace/{categorie}/{comptemarketplace}", name="dtc_associer_categorie_market_place")
  24.      */
  25.     public function associerAction(Request            $requestCategorie $categorieCompteMarketPlace $comptemarketplaceEntityManagerInterface $emTranslatorInterface $translator,
  26.                                    ValidatorInterface $validator
  27.     ) {
  28.         $user                                  $this->getUser();
  29.         $errors                                = [];
  30.         $repo_CategorieErpCategorieMarketPlace $em->getRepository(CategorieErpCategorieMarketPlace::class);
  31.         $repo_categorie                        $em->getRepository(Categorie::class);
  32.         $categorieErpCategorieMarketPlace_obj $repo_CategorieErpCategorieMarketPlace->findOneBy(["categorieErp" => $categorie"compteMarketPlace" => $comptemarketplace]);
  33.         if ( ! is_object($categorieErpCategorieMarketPlace_obj)) {
  34.             $categorieErpCategorieMarketPlace_obj = new CategorieErpCategorieMarketPlace;
  35.             $categorieErpCategorieMarketPlace_obj->setCategorieErp($categorie);
  36.             $categorieErpCategorieMarketPlace_obj->setCompteMarketPlace($comptemarketplace);
  37.         }
  38.         $form $this->createForm(AssocierCategorieErpCategorieMarketPlaceType::class, $categorieErpCategorieMarketPlace_obj);
  39.         $get  $request->query->all();
  40.         $titre_modal $translator->trans("Associer catégorie");
  41.         $errors "";
  42.         $form->handleRequest($request);
  43.         if ($form->isSubmitted()) {
  44.             $type_json "";
  45.             if ($form->isValid()) {
  46.                 $post   $request->request->all();
  47.                 $valeur "";
  48.                 if (array_key_exists('categories'$post) && count($post["categories"]) > 0) {
  49.                     $cat_obj $repo_categorie->find($post["categories"][0]);
  50.                     if (is_object($cat_obj)) {
  51.                         $categorieErpCategorieMarketPlace_obj->setCategorieMarketPlace($cat_obj);
  52.                         $em->persist($categorieErpCategorieMarketPlace_obj);
  53.                         $em->flush();
  54.                         $valeur $cat_obj->getLibelle();
  55.                     }
  56.                 } else {
  57.                     $em->remove($categorieErpCategorieMarketPlace_obj);
  58.                     $em->flush();
  59.                 }
  60.                 return new JsonResponse(
  61.                     [
  62.                         'rendu'             => '',
  63.                         'valide'            => '1',
  64.                         'url'               => '',
  65.                         'valeur'            => $valeur,
  66.                         'type'              => 'associerCategorieMarketPlace',
  67.                         'categorie'         => $categorie->getId(),
  68.                         'comptemarketplace' => $comptemarketplace->getId(),
  69.                     ]
  70.                 );
  71.             } else {
  72.                 $errors $validator->validate($categorieErpCategorieMarketPlace_obj);
  73.                 $rendu  $this->renderView(
  74.                     'MarketPlace/CategorieErpCategorieMarketPlace/associer.html.twig',
  75.                     ['form' => $form->createView(), 'errors' => $errors'comptemarketplace' => $comptemarketplace]
  76.                 );
  77.                 return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  78.             }
  79.         }
  80.         $rendu $this->renderView(
  81.             'MarketPlace/CategorieErpCategorieMarketPlace/associer.html.twig',
  82.             ['form' => $form->createView(), 'type' => '''errors' => $errors'comptemarketplace' => $comptemarketplace]
  83.         );
  84.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  85.     }
  86.     /**
  87.      * @Route("", name="")
  88.      */
  89.     public function listerCategorieErpAjaxAction(Request $request$article null$mode ""$mpId ''$compteMarketPlace ''$amp ''EntityManagerInterface $em)
  90.     {
  91.         $get  $request->query->all();
  92.         $type "";
  93.         $s    "";
  94.         if (is_array($get) && array_key_exists('mpid'$get)) {
  95.             $mpId    $get["mpid"];
  96.             $s       $get["sc"];
  97.             $article $get["article"];
  98.             $cmp_id  $get["cmp"];
  99.             $amp     $get["amp"];
  100.             $mode    $get["mode"];
  101.             $repo_article_market_place $em->getRepository(ArticleMarketPlace::class);
  102.             //$articleMarketPlace = $repo_article_market_place->find($amp_id);
  103.             $repo_compte_market_place $em->getRepository(CompteMarketPlace::class);
  104.             $compteMarketPlace        $repo_compte_market_place->find($cmp_id);
  105.             $type                     "recherche";
  106.         }
  107.         //echo "test".$mode;
  108.         $repo_article_market_place $em->getRepository(ArticleMarketPlace::class);
  109.         $repo_market_place         $em->getRepository(MarketPlace::class);
  110.         $marketPlace               $repo_market_place->find($mpId);
  111.         //echo $marketPlace->getLibelle();
  112.         $repo_article $em->getRepository(Article::class);
  113.         $article      $repo_article->find($article);
  114.         $repo_categorie         $em->getRepository(Categorie::class);
  115.         $repo_article_categorie $em->getRepository(ArticleCategorie::class);
  116.         $nbCategoriesEnfant = [];
  117.         $articleCategories  = [];
  118.         if (is_object($compteMarketPlace)) {
  119.             $repo_article_market_place $em->getRepository(ArticleMarketPlace::class);
  120.             //$article = $repo_article_market_place->findOneBy(array("article"=>$article,"compteMarketPlace"=>$compteMarketPlace));
  121.             $article $repo_article_market_place->find($amp);
  122.         }
  123.         $articleMarketPlace $repo_article_market_place->find($amp);
  124.         if (is_object($articleMarketPlace)) {
  125.             //echo "AAAAAAAAAAAAA";
  126.             //$categoriesArticle = $repo_article_categorie->findByArticle($articleId);
  127.             if (count($articleMarketPlace->getArticleCategorie()) > 0) {
  128.                 foreach ($articleMarketPlace->getArticleCategorie() as $categorieArticle) {
  129.                     //echo "<div>C ".$categorieArticle->getCategorie()->getLibelle()."</div>";
  130.                     $boucler             true;
  131.                     $articleCategories[] = $categorieArticle->getCategorie()->getId();
  132.                     if (is_object($categorieArticle->getCategorie()->getCategorieParent()) and $categorieArticle->getCategorie()->getCategorieParent()->getId() > 1) {
  133.                         $parent $categorieArticle->getCategorie()->getCategorieParent();
  134.                         while ($boucler) {
  135.                             if ( ! array_key_exists($parent->getId(), $nbCategoriesEnfant)) {
  136.                                 $nbCategoriesEnfant[$parent->getId()] = 1;
  137.                             } else {
  138.                                 $nbCategoriesEnfant[$parent->getId()]++;
  139.                             }
  140.                             if (is_object($parent->getCategorieParent()) and $parent->getCategorieParent()->getId() > 1) {
  141.                                 $parent $parent->getCategorieParent();
  142.                             } else {
  143.                                 $boucler false;
  144.                             }
  145.                         }
  146.                     }
  147.                 }
  148.             }
  149.         } elseif (is_object($article)) {
  150.             //$categoriesArticle = $repo_article_categorie->findByArticle($articleId);
  151.             if (count($article->getArticleCategorie()) > 0) {
  152.                 foreach ($article->getArticleCategorie() as $categorieArticle) {
  153.                     //echo "<div>C ".$categorieArticle->getCategorie()->getLibelle()."</div>";
  154.                     $boucler             true;
  155.                     $articleCategories[] = $categorieArticle->getCategorie()->getId();
  156.                     if (is_object($categorieArticle->getCategorie()->getCategorieParent()) and $categorieArticle->getCategorie()->getCategorieParent()->getId() > 1) {
  157.                         $parent $categorieArticle->getCategorie()->getCategorieParent();
  158.                         while ($boucler) {
  159.                             if ( ! array_key_exists($parent->getId(), $nbCategoriesEnfant)) {
  160.                                 $nbCategoriesEnfant[$parent->getId()] = 1;
  161.                             } else {
  162.                                 $nbCategoriesEnfant[$parent->getId()]++;
  163.                             }
  164.                             if (is_object($parent->getCategorieParent()) and $parent->getCategorieParent()->getId() > 1) {
  165.                                 $parent $parent->getCategorieParent();
  166.                             } else {
  167.                                 $boucler false;
  168.                             }
  169.                         }
  170.                     }
  171.                 }
  172.             }
  173.         }
  174.         $categories $repo_categorie->getCategorieMarketPlace($marketPlace);
  175.         //return $this->render('Articles/Categorie/lister-dossier-ajax.html.twig', array(
  176.         return $this->render('MarketPlace/CategorieErpCategorieMarketPlace/lister-dossier-categorie-marketplace-ajax.html.twig', [
  177.             'nbCategoriesEnfant' => $nbCategoriesEnfant,
  178.             'categories'         => $categories,
  179.             'article'            => $article,
  180.             'categoriesArticle'  => $articleCategories,
  181.             'marketPlace'        => $marketPlace,
  182.             'compteMarketPlace'  => $compteMarketPlace,
  183.             'articleMarketPlace' => $articleMarketPlace,
  184.             'type'               => $type,
  185.             'mode'               => $mode,
  186.         ]);
  187.     }
  188.     /**
  189.      * @Route("/associer-categorie-marketplace/enfants/{id}", name="dtc_associer_categorie_market_placelister_enfants")
  190.      */
  191.     public function listerCategorieDossierEnfantsAjaxAction(Request $requestCategorie $categorieEntityManagerInterface $em)
  192.     {
  193.         //echo $categorie->getId();
  194.         $articleMarketPlaceId      "";
  195.         $repo_categorie            $em->getRepository(Categorie::class);
  196.         $repo_article              $em->getRepository(Article::class);
  197.         $repo_article_categorie    $em->getRepository(ArticleCategorie::class);
  198.         $repo_article_market_place $em->getRepository(ArticleMarketPlace::class);
  199.         $repo_article_market_place $em->getRepository(ArticleMarketPlace::class);
  200.         $repo_market_place         $em->getRepository(MarketPlace::class);
  201.         $categories $repo_categorie->findBy(["categorieParent" => $categorie]);
  202.         $type          $request->query->get('type');
  203.         $mode          $request->query->get('mode');
  204.         $niveau        intval($request->query->get('niveau')) + 1;
  205.         $articleId     intval($request->query->get('article'));
  206.         $marketPlaceId intval($request->query->get('marketPlaceId'));
  207.         $typecategorie $request->query->get('typecategorie');
  208.         $article "";
  209.         //echo $mode." aid:".$articleId;
  210.         if ($typecategorie != "erp" && $mode != "catArtMp") {
  211.             $article $repo_article_market_place->find($articleId);
  212.         } else {
  213.             $article $repo_article->find($articleId);
  214.         }
  215.         //echo $article->getId();
  216.         $repo_article_market_place $em->getRepository(ArticleMarketPlace::class);
  217.         $repo_market_place         $em->getRepository(MarketPlace::class);
  218.         $articleMarketPlace "";
  219.         if ($marketPlaceId != "" && $articleId != "" && $mode != "catArtMp") {
  220.             $repo_article_market_place $em->getRepository(ArticleMarketPlace::class);
  221.             //$article = $repo_article_market_place->findOneBy(array("article"=>$article,"compteMarketPlace"=>$compteMarketPlace));
  222.             $article $repo_article_market_place->find($articleId);
  223.             $articleMarketPlace   $repo_article_market_place->find($articleId);
  224.             $articleMarketPlaceId $articleMarketPlace->getId();
  225.         }
  226.         $articleCategories  = [];
  227.         $nbCategoriesEnfant = [];
  228.         if (is_object($article)) {
  229.             //$categoriesArticle = $repo_article_categorie->findByArticle($articleId);
  230.             foreach ($article->getArticleCategorie() as $categorieArticle) {
  231.                 $boucler             true;
  232.                 $articleCategories[] = $categorieArticle->getCategorie()->getId();
  233.                 //echo "<div>ART ".$article->getId()." CAT ".$categorieArticle->getCategorie()->getId()."</div>";
  234.                 if (is_object($categorieArticle->getCategorie()->getCategorieParent()) and $categorieArticle->getCategorie()->getCategorieParent()->getId() > 1) {
  235.                     $parent $categorieArticle->getCategorie()->getCategorieParent();
  236.                     while ($boucler) {
  237.                         if ( ! array_key_exists($parent->getId(), $nbCategoriesEnfant)) {
  238.                             $nbCategoriesEnfant[$parent->getId()] = 1;
  239.                         } else {
  240.                             $nbCategoriesEnfant[$parent->getId()]++;
  241.                         }
  242.                         if (is_object($parent->getCategorieParent()) and $parent->getCategorieParent()->getId() > 1) {
  243.                             $parent $parent->getCategorieParent();
  244.                         } else {
  245.                             $boucler false;
  246.                         }
  247.                     }
  248.                 }
  249.             }
  250.         }
  251.         //print_r($articleCategories);
  252.         //exit;
  253.         /*
  254.         'nbCategoriesEnfant'=>$nbCategoriesEnfant,
  255.         'categories' =>$categories,
  256.         'article'=>$article,
  257.         'categoriesArticle' => $articleCategories,
  258.         'mode' => $mode,
  259.         'marketPlace' => $marketPlace,
  260.         'compteMarketPlace' => $compteMarketPlace,
  261.         'articleMarketPlace' => $articleMarketPlace,
  262.         */
  263.         //echo count($categories);
  264.         //$rendu = $this->render('Articles/Categorie/lister-dossier-ajax.html.twig', array('nbCategoriesEnfant'=>array(),'categories' =>$categories,'article'=>"", 'categoriesArticle' => "","marketPlace"=>""));
  265.         //$rendu = $this->renderView('Articles/Categorie/lister-dossier-ligne-ajax_1.html.twig',
  266.         $rendu $this->renderView(
  267.             'MarketPlace/CategorieErpCategorieMarketPlace/lister-dossier-ligne-ajax_1.html.twig',
  268.             [
  269.                 'nbCategoriesEnfant'   => $nbCategoriesEnfant,
  270.                 'niveau'               => $niveau,
  271.                 'categories'           => $categories,
  272.                 'ajax'                 => '1',
  273.                 'mode'                 => $mode,
  274.                 'parents'              => '',
  275.                 'parent'               => $categorie->getId(),
  276.                 'categorie'            => $categorie,
  277.                 'article'              => $article,
  278.                 'categoriesArticle'    => $articleCategories,
  279.                 "marketPlace"          => "",
  280.                 "marketPlaceId"        => $marketPlaceId,
  281.                 "articleMarketPlace"   => $articleMarketPlace,
  282.                 "articleMarketPlaceId" => $articleMarketPlaceId,
  283.                 "type"                 => $type,
  284.                 "typecategorie"        => $typecategorie,
  285.             ]
  286.         );
  287.         return new JsonResponse(['rendu' => $rendu]);
  288.     }
  289. }