src/Controller/DefaultController.php line 52

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Controller\DefaultValuesController;
  4. use App\Document\DataFeed;
  5. use App\Document\Product;
  6. use App\Document\SchedulerJob;
  7. use App\Entity\AllegroCategory;
  8. use App\Entity\Model;
  9. use App\Entity\ProcessQueue;
  10. use App\Entity\StanMag;
  11. use Doctrine\Persistence\ManagerRegistry;
  12. use Doctrine\ORM\EntityManager;
  13. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. use Symfony\Contracts\Translation\TranslatorInterface;
  18. /**
  19.  * @Route("/")
  20.  */
  21. class DefaultController extends AbstractController
  22. {
  23.     private TranslatorInterface $translator;
  24.     public function __construct(TranslatorInterface $translator)
  25.     {
  26.         $this->translator $translator;
  27.     }
  28.     public static function getName($translator)
  29.     {
  30.         return $translator->trans("Home");
  31.     }
  32.     public static function getAdminName()
  33.     {
  34.         return "default";
  35.     }
  36.     /**
  37.      * @Route("/", name="admin_default", methods={"GET"})
  38.      * @param ManagerRegistry $managerRegistry
  39.      * @return Response
  40.      */
  41.     public function adminDefault(ManagerRegistry $managerRegistry): Response
  42.     {
  43.         /** @var EntityManager $dm */
  44.         $dm =  $managerRegistry->getManager();
  45.         $data = [
  46.             'stanmag' => [
  47. //                'bySource' => DefaultValuesController::getGenericStats(
  48. //                    $dm->getRepository(AllegroCategory::class)->getStatsCategoryBySQL("select  case when kod_lokalizacji = '12' then 'WAW' when kod_lokalizacji = '6' then 'GRU' else 'OTHER' end  as label, count(*) as total from stanmag group by 1"), 'label', 'total'
  49. //                ),
  50.                 'bySource' => DefaultValuesController::getGenericStats(
  51.                     $dm->getRepository(AllegroCategory::class)->getStatsCategoryBySQL("select  case when kod_lokalizacji = '12' then 'WAW' when kod_lokalizacji = '6' then 'GRU' else 'OTHER' end  as label, count(*) as total from stanmag group by 1"), 'label''total'
  52.                 ),
  53.                 'byMake' => DefaultValuesController::getGenericStats(
  54.                     $dm->getRepository(AllegroCategory::class)->getStatsCategoryBySQL("select m.name as label, count(*) as total from stanmag s, ak_make m where s.id_marki_fk = m.id group by 1 order by 2 desc "), 'label''total'
  55.                 ),
  56.                 'byNrOem' => DefaultValuesController::getGenericStats(
  57.                     $dm->getRepository(AllegroCategory::class)->getStatsCategoryBySQL("select  case when TRIM(nr_oem) = '' then 'NO' when nr_oem is null then 'NULL' else 'YES' end as label, count(*) as total from stanmag group by 1"), 'label''total'
  58.                 ),
  59. //                'bySoldStatus' => DefaultValuesController::getGenericStats(
  60. //                    $dm->getRepository(AllegroCategory::class)->getStatsCategoryBySQL("select  case when data_sprzedazy_allegro is not null then 'ALLEGRO' when data_sprzedazy_allegro is not null then 'ACTIVE' else 'OTHER' end  as label, count(distinct nr_etykiety) as total from stanmag group by 1"), 'label', 'total'
  61. //                ),
  62.                 'bySoldStatus' => DefaultValuesController::getGenericStats(
  63.                     $dm->getRepository(AllegroCategory::class)->getStatsCategoryBySQL("select case when ilosc = '1' then 'ACTIVE' when ilosc = '0' then 'SOLD' else 'OTHER' end  as label, count(distinct nr_etykiety) as total from stanmag group by 1"), 'label''total'
  64.                 ),
  65.                 'byAllegroStatus' => DefaultValuesController::getGenericStats(
  66.                     $dm->getRepository(AllegroCategory::class)->getStatsCategoryBySQL("select  case when a.status is null then 'NOT ON ALLEGRO' else a.status end  as label , count(distinct s.nr_etykiety) as total from stanmag s left join allegro_offer a on s.nr_etykiety = a.external  group by 1;"), 'label''total'
  67.                 ),
  68.                 'noCatalog' => $dm->getRepository(StanMag::class)->getStanMagNoCatalog(),
  69.                 'noCatalogAll' => $dm->getRepository(StanMag::class)->getStanMagNoCatalog(true),
  70.                 'noModel' => $dm->getRepository(StanMag::class)->getStanMagNoModel(),
  71.             ],
  72.             'model' => [
  73.                 'noMake' => $dm->getRepository(Model::class)->getModelNoMake(),
  74.                 'noMakeAll' => $dm->getRepository(Model::class)->getModelNoMake(true),
  75.             ],
  76.             'allegroCategories' => [
  77.                 'byLeaf' => DefaultValuesController::getGenericStats(
  78.                     $dm->getRepository(AllegroCategory::class)->getStatsCategoryBySQL("select case when is_leaf = false then 'NO' when is_leaf = true then 'YES' end  as label, count(*) as total from allegro_category group by 1"), 'label''total'
  79.                 ),
  80.                 'byStatus' => DefaultValuesController::getGenericStats(
  81.                     $dm->getRepository(AllegroCategory::class)->getStatsCategoryBySQL("select case when is_active = false then 'NO' when is_active = true then 'YES' end  as label, count(*) as total from allegro_category group by 1"), 'label''total'
  82.                 ),
  83.                 'byProduct' => DefaultValuesController::getGenericStats(
  84.                     $dm->getRepository(AllegroCategory::class)->getStatsCategoryBySQL("select case when is_products_enabled = false then 'NO' when is_products_enabled = true then 'YES' end  as label, count(*) as total from allegro_category group by 1"), 'label''total'
  85.                 ),
  86.                 'byMapping' => DefaultValuesController::getGenericStats(
  87.                     $dm->getRepository(AllegroCategory::class)->getStatsCategoryBySQL("select case when cm.allegro_category_id is null then 'NO' else 'YES' end as label, count(*) as total from allegro_category c left join ak_catalog_mapping cm on c.id=cm.allegro_category_id group by 1"), 'label''total'
  88.                 ),
  89.             ],
  90.             'opencartCategories' => [
  91.                 'byMapping' => DefaultValuesController::getGenericStats(
  92.                     $dm->getRepository(AllegroCategory::class)->getStatsCategoryBySQL("select case when cm.opencart_category_id is null then 'NO' else 'YES' end as label, count(*) as total from opencart_category c left join ak_catalog_mapping cm on c.id=cm.opencart_category_id group by 1"), 'label''total'
  93.                 ),
  94.             ],
  95.             'catalog' => [
  96.                 'byMappingOpencart' => DefaultValuesController::getGenericStats(
  97.                     $dm->getRepository(AllegroCategory::class)->getStatsCategoryBySQL("select case when cm.opencart_category_id is null then 'NO' else 'YES' end as label, count(*) as total from ak_catalog_mapping cm left join opencart_category c on c.id=cm.category_id group by 1"), 'label''total'
  98.                 ),
  99.                 'byMappingAllegro' => DefaultValuesController::getGenericStats(
  100.                     $dm->getRepository(AllegroCategory::class)->getStatsCategoryBySQL("select case when cm.allegro_category_id is null then 'NO' else 'YES' end as label, count(*) as total from ak_catalog_mapping cm left join allegro_category c on c.id=cm.allegro_category_id group by 1"), 'label''total'
  101.                 ),
  102.             ],
  103.             'processQueue' => [
  104.                 //'byActionStatus' => $dm->getRepository(ProcessQueue::class)->getStatsByActionStatus(),
  105.                 'byActionStatus' => DefaultValuesController::getGenericStats(
  106.                     $dm->getRepository(ProcessQueue::class)->getStatsBySQL("select action as label, count(*) as total from process_queue where status not in ('COMPLETED','FAILED') group by 1"), 'label''total'
  107.                 ),
  108.                 'byTriggerStatus' => DefaultValuesController::getGenericStats(
  109.                     $dm->getRepository(ProcessQueue::class)->getStatsBySQL("select trigger_item as label, count(*) as total from process_queue where status not in ('COMPLETED','FAILED') group by 1"), 'label''total'
  110.                 ),
  111.                 'byStatus' => DefaultValuesController::getGenericStats(
  112.                     $dm->getRepository(ProcessQueue::class)->getStatsBySQL("select status as label, count(*) as total from process_queue where 1=1 group by 1"), 'label''total'
  113.                 ),
  114. //                'completedByStatus' => DefaultValuesController::getGenericStats(
  115. //                    $dm->getRepository(ProcessQueue::class)->getStatsBySQL("select action as label, count(*) as total from process_queue where 1=1 and status in ('COMPLETED') group by 1"), 'label', 'total'
  116. //                ),
  117.                 'noMakeAll' => $dm->getRepository(Model::class)->getModelNoMake(true),
  118.             ],
  119.         ];
  120. //        {#                last Varlink product pull (date, status, link)#}
  121. //        {#                last Website product sync (date, status, link)#}
  122. //        {#                last Website update (date, status, link)#}
  123. //        {#                number of products in Prod and Stage (group by in Valink Feed or not)#}
  124. //        {#                number of products in Varlink Feed#}
  125.         return $this->render('app/dashboard/index.html.twig', [
  126.             'jobs' => [],
  127.             'buckets' => [],
  128.             'data' => $data,
  129.             'debug_str' => print_r($data,1),
  130.             'breadcrumbTitle' => DefaultValuesController::getBreadcrumbTitle(),
  131.             'categoryTitle' => self::getName($this->translator),
  132.             'adminMenu' => self::getAdminName(),
  133. //            'appName' => DefaultValuesController::getAppName($dm),
  134.         ]);
  135.     }
  136. }