src/Event/MenuBuilderListener.php line 27

Open in your IDE?
  1. <?php
  2. // src/EventListener/MenuBuilderListener.php
  3. namespace App\Event;
  4. use Sonata\AdminBundle\Event\ConfigureMenuEvent;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\RequestStack;
  7. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  8. use App\Entity\Content;
  9. use App\Entity\Site;
  10. // Sonata Menu Builder is here: /vendor/sonata-project/admin-bundle/src/Menu/MenuBuilder.php
  11. class MenuBuilderListener
  12. {
  13.     protected $requestStack;
  14.     protected $user;
  15.     
  16.     public function __construct(RequestStack $requestStackTokenStorageInterface $tokenStore)
  17.     {
  18.         $this->requestStack $requestStack;
  19.         $this->user $tokenStore->getToken()->getUser();
  20.     }
  21.     
  22.     public function addMenuItems(ConfigureMenuEvent $event)
  23.     {
  24.         
  25.         $menu $event->getMenu();
  26.         
  27.         $request $this->requestStack->getCurrentRequest();
  28.         $admin_view $request->cookies->get("admin_view");
  29.         
  30.         //$session = $request->getSession();
  31.         //$admin_view = $session->get("admin_view");
  32.         
  33.         $menu->setChildren([]); //clear the menu items added through yaml
  34.         
  35.         
  36.         if($admin_view == Site::SITE_AAR) {
  37.             $ads $menu->addChild('ad', [
  38.                 'label' => 'Ads',
  39.                 'route' => 'ad_list',
  40.             ])->setExtras([
  41.                 'icon' => '<i class="fa fa-bar-chart"></i>',
  42.             ]);
  43.         }
  44.         else {
  45.             $ads $menu->addChild('ad', [
  46.                 'label' => 'Ads'
  47.             ])->setExtras([
  48.                 'icon' => '<i class="fa fa-bar-chart"></i>',
  49.             ]);
  50.                 $ads->addChild('general_ad', [
  51.                     'label' => 'Ads',
  52.                     'route' => 'ad_list',
  53.                 ]);
  54.                 $ads->addChild('curtain_ad', [
  55.                     'label' => 'Curtain Ads',
  56.                     'route' => 'curtainad_list',
  57.                 ]);
  58.                 $ads->addChild('header_ad', [
  59.                     'label' => 'Header Ads',
  60.                     'route' => 'headerad_list',
  61.                 ]);
  62.                 $ads->addChild('menu_ad', [
  63.                     'label' => 'Menu Ads',
  64.                     'route' => 'menuad_list',
  65.                 ]);
  66.                 $ads->addChild('popout_ad', [
  67.                     'label' => 'Pop-out Ads',
  68.                     'route' => 'popoutad_list',
  69.                 ]);
  70.                 $ads->addChild('video_ad', [
  71.                     'label' => 'Video Ads',
  72.                     'route' => 'videoad_list',
  73.                 ]);
  74.         }
  75.         
  76.         //if(!$admin_view || $admin_view == Site::SITE_RCS) {
  77.             $admin_dashboard $menu->addChild('admin_dashboard', [
  78.                 'label' => 'Advertiser Report',
  79.                 //'uri' => '/admin-dashboard',
  80.                 'uri' => 'https://rooferscoffeeshop.com/admin-dashboard',
  81.             ])->setExtras([
  82.                 'icon' => '<i class="fa fa-map"></i>',
  83.             ]);
  84.         //}
  85.         
  86.             
  87.         if($admin_view != Site::SITE_AAR) {
  88.             
  89.             $categories $menu->addChild('category', [
  90.                 'label' => 'Categories'
  91.             ])->setExtras([
  92.                 'icon' => '<i class="fa fa-tag"></i>',
  93.             ]);
  94.                 $categories->addChild('award_category', [
  95.                     'label' => 'Award Categories',
  96.                     'route' => 'awardcategory_list',
  97.                 ]);
  98.                 $categories->addChild('classified_category', [
  99.                     'label' => 'Classified Categories',
  100.                     'route' => 'classifiedcategory_list',
  101.                 ]);
  102.                 $categories->addChild('classified_region', [
  103.                     'label' => 'Classified Regions',
  104.                     'route' => 'classifiedregion_list',
  105.                 ]);
  106.                 $categories->addChild('contest_category', [
  107.                     'label' => 'Contest Categories',
  108.                     'route' => 'contestcategory_list',
  109.                 ]);
  110.                 $categories->addChild('directory_category', [
  111.                     'label' => 'Directory Categories',
  112.                     'route' => 'directorycategory_list',
  113.                 ]);
  114.                 $categories->addChild('directory_type', [
  115.                     'label' => 'Directory Types',
  116.                     'route' => 'directorytype_list',
  117.                 ]);
  118.                 $categories->addChild('ebook_category', [
  119.                     'label' => 'eBook Categories',
  120.                     'route' => 'ebookcategory_list',
  121.                 ]);
  122.                 $categories->addChild('general_category', [
  123.                     'label' => 'General Categories',
  124.                     'route' => 'generalcategory_list',
  125.                 ]);
  126.                 $categories->addChild('interest_tag', [
  127.                     'label' => 'Interest Tags',
  128.                     'route' => 'interesttagcategory_list',
  129.                 ]);
  130.                 $categories->addChild('partner_level', [
  131.                     'label' => 'Partner Levels',
  132.                     'route' => 'partnerlevel_list',
  133.                 ]);
  134.                 $categories->addChild('partner_webinar_type', [
  135.                     'label' => 'Partner Webinar Types',
  136.                     'route' => 'partnerwebinartype_list',
  137.                 ]);
  138.                 $categories->addChild('post_category', [
  139.                     'label' => 'Post Categories',
  140.                     'route' => 'postcategory_list',
  141.                 ]);
  142.                 $categories->addChild('promo_category', [
  143.                     'label' => 'Promo Categories',
  144.                     'route' => 'promocategory_list',
  145.                 ]);
  146.                 $categories->addChild('rclubperk_category', [
  147.                     'label' => 'R-Club Perk Categories',
  148.                     'route' => 'rclubperkcategory_list',
  149.                 ]);
  150.                 $categories->addChild('rcs_podcast_type', [
  151.                     'label' => 'RCS Podcast Types',
  152.                     'route' => 'rcspodcasttype_list',
  153.                 ]);
  154.                 $categories->addChild('access_level', [
  155.                     'label' => 'RLW Access Levels',
  156.                     'route' => 'accesslevel_list',
  157.                 ]);
  158.                 $categories->addChild('rlw_category', [
  159.                     'label' => 'RLW Categories',
  160.                     'route' => 'rlwcategory_list',
  161.                 ]);
  162.                 $categories->addChild('industry_category', [
  163.                     'label' => 'RLW Industries',
  164.                     'route' => 'industry_list',
  165.                 ]);
  166.                 $categories->addChild('resource_type', [
  167.                     'label' => 'RLW Resource Types',
  168.                     'route' => 'resourcetype_list',
  169.                 ]);
  170.                 $categories->addChild('scholarship_category', [
  171.                     'label' => 'Scholarship Categories',
  172.                     'route' => 'scholarshipcategory_list',
  173.                 ]);
  174.                 $categories->addChild('video_category', [
  175.                     'label' => 'Video Categories',
  176.                     'route' => 'videocategory_list',
  177.                 ]);
  178.                 $categories->addChild('webinar_type', [
  179.                     'label' => 'Webinar Types',
  180.                     'route' => 'webinartype_list',
  181.                 ]);
  182.                 
  183.         }
  184.         elseif($admin_view == Site::SITE_AAR) {
  185.             $categories $menu->addChild('category', [
  186.                 'label' => 'Categories'
  187.             ])->setExtras([
  188.                 'icon' => '<i class="fa fa-tag"></i>',
  189.             ]);
  190.                 $categories->addChild('aar_post_category', [
  191.                     'label' => 'Post Categories',
  192.                     'route' => 'aarpostcategory_list',
  193.                 ]);
  194.                 $categories->addChild('aar_ebook_category', [
  195.                     'label' => 'eBook Categories',
  196.                     'route' => 'aarebookcategory_list',
  197.                 ]);
  198.                 $categories->addChild('aar_tag', [
  199.                     'label' => 'Tags',
  200.                     'route' => 'aartag_list',
  201.                 ]);
  202.         }
  203.         
  204.         $comments $menu->addChild('comment', [
  205.             'label' => 'Comments',
  206.             'route' => 'admin_app_comment_list',
  207.         ])->setExtras([
  208.             'icon' => '<i class="fa fa-comment"></i>',
  209.         ]);
  210.         
  211.         $customers $menu->addChild('customers', [
  212.             'label' => 'Directory',
  213.             'route' => 'admin_app_customer_list',
  214.         ])->setExtras([
  215.             'icon' => '<i class="fa fa-address-book"></i>',
  216.         ]);
  217.         
  218.         $blacklist $menu->addChild('blacklist', [
  219.             'label' => 'Domain Blacklist',
  220.             'route' => 'admin_app_domainblacklist_list',
  221.         ])->setExtras([
  222.             'icon' => '<i class="fa fa-ban"></i>',
  223.         ]);
  224.         
  225.         if($admin_view != Site::SITE_AAR) {
  226.             $forms $menu->addChild('form', [
  227.                 'label' => 'Forms',
  228.                 'route' => 'admin_app_form_list',
  229.             ])->setExtras([
  230.                 'icon' => '<i class="fa fa-list-ol"></i>',
  231.             ]);
  232.             $quizzes $menu->addChild('quiz', [
  233.                 'label' => 'Quizzes',
  234.                 'route' => 'admin_app_quiz_list',
  235.             ])->setExtras([
  236.                 'icon' => '<i class="fa fa-question-circle"></i>',
  237.             ]);
  238.         }
  239.         
  240.         $media $menu->addChild('media', [
  241.             'label' => 'Media',
  242.             'route' => 'admin_app_media_list',
  243.         ])->setExtras([
  244.             'icon' => '<i class="fa fa-image"></i>',
  245.         ]);
  246.         
  247.         if($this->user && $this->user->isSuperAdmin()) {
  248.             $mega_menu_builder $menu->addChild('mega_menu_builder', [
  249.                 'label' => 'Mega Menu Builder',
  250.                 'uri' => '/admin/mega-menu-builder',
  251.             ])->setExtras([
  252.                 'icon' => '<i class="fa fa-wrench"></i>',
  253.             ]);
  254.         }
  255.         
  256.         if($admin_view != Site::SITE_AAR) {
  257.             $polls $menu->addChild('poll', [
  258.                 'label' => 'Polls',
  259.                 'route' => 'poll_list',
  260.             ])->setExtras([
  261.                 'icon' => '<i class="fa fa-check-square"></i>',
  262.             ]);
  263.         }
  264.         if(!$admin_view || $admin_view == Site::SITE_RCS) {
  265.             $sales $menu->addChild('sale', [
  266.                 'label' => 'Sales'
  267.             ])->setExtras([
  268.                 'icon' => '<i class="fa fa-dollar"></i>',
  269.             ]);
  270.                 $sales->addChild('coupon', [
  271.                     'label' => 'Coupons',
  272.                     'route' => 'admin_app_coupon_list',
  273.                 ]);
  274.                 $sales->addChild('product_category', [
  275.                     'label' => 'Product Categories',
  276.                     'route' => 'productcategory_list',
  277.                 ]);
  278.                 $sales->addChild('product', [
  279.                     'label' => 'Products',
  280.                     'route' => 'admin_app_product_list',
  281.                 ]);
  282.                 $sales->addChild('purchase', [
  283.                     'label' => 'Purchases',
  284.                     'route' => 'admin_app_purchase_list',
  285.                 ]);
  286.                 $sales->addChild('tax_report', [
  287.                     'label' => 'Tax Report',
  288.                     'uri' => '/tax-report',
  289.                 ]);
  290.         }
  291.         
  292.         /* Start Content */
  293.         $content $menu->addChild('content', [
  294.             'label' => 'Site Content'
  295.         ])->setExtras([
  296.             'icon' => '<i class="fa fa-file"></i>',
  297.         ]);
  298.             
  299.             $content->addChild('content_content', [
  300.                 'label' => 'All Content',
  301.                 'route' => 'content_list',
  302.             ]);
  303.             
  304.             if(!$admin_view || in_array($admin_viewContent::getSitesForContentType(Content::AWARD))) {
  305.                 $content->addChild('content_award', [
  306.                     'label' => 'Awards',
  307.                     'route' => 'award_list',
  308.                 ]);
  309.             }
  310.             if(!$admin_view || in_array($admin_viewContent::getSitesForContentType(Content::CLASSIFIED))) {
  311.                 $content->addChild('content_classified', [
  312.                     'label' => 'Classifieds',
  313.                     'route' => 'classified_list',
  314.                 ]);
  315.             }
  316.             if(!$admin_view || in_array($admin_viewContent::getSitesForContentType(Content::CONTEST_GAMES))) {
  317.                 $content->addChild('content_contest', [
  318.                     'label' => 'Contests and Games',
  319.                     'route' => 'contestsgames_list',
  320.                 ]);
  321.             }
  322.             if(!$admin_view || in_array($admin_viewContent::getSitesForContentType(Content::EBOOK))) {
  323.                 $content->addChild('content_ebook', [
  324.                     'label' => 'eBooks',
  325.                     'route' => 'ebook_list',
  326.                 ]);
  327.             }
  328.             if(!$admin_view || in_array($admin_viewContent::getSitesForContentType(Content::EVENT))) {
  329.                 $content->addChild('content_event', [
  330.                     'label' => 'Events',
  331.                     'route' => 'event_list',
  332.                 ]);
  333.             }
  334.             if(!$admin_view || in_array($admin_viewContent::getSitesForContentType(Content::FORUM))) {
  335.                 $content->addChild('content_forum', [
  336.                     'label' => 'Forums',
  337.                     'route' => 'forum_list',
  338.                 ]);
  339.             }
  340.             if(!$admin_view || in_array($admin_viewContent::getSitesForContentType(Content::LANDING_PAGE))) {
  341.                 $content->addChild('content_landing_page', [
  342.                     'label' => 'Landing Pages',
  343.                     'route' => 'landingpage_list',
  344.                 ]);
  345.             }
  346.             if(!$admin_view || in_array($admin_viewContent::getSitesForContentType(Content::PAGE))) {
  347.                 $content->addChild('content_page', [
  348.                     'label' => 'Pages',
  349.                     'route' => 'page_list',
  350.                 ]);
  351.             }
  352.             if(!$admin_view || $admin_view == Site::SITE_RCS) { //TODO: handle diff kinds of same type
  353.                 $content->addChild('content_partner_gallery', [
  354.                     'label' => 'Partner Galleries',
  355.                     'route' => 'partnergallery_list',
  356.                 ]);
  357.             }
  358.             if(!$admin_view || $admin_view == Site::SITE_RCS) {
  359.                 $content->addChild('content_partner_podcast', [
  360.                     'label' => 'Partner Podcasts',
  361.                     'route' => 'partnerpodcast_list',
  362.                 ]);
  363.             }
  364.             if(!$admin_view || $admin_view == Site::SITE_RCS) {
  365.                 $content->addChild('content_partner_webinar', [
  366.                     'label' => 'Partner Webinars',
  367.                     'route' => 'partnerwebinar_list',
  368.                 ]);
  369.             }
  370.             if(!$admin_view || in_array($admin_viewContent::getSitesForContentType(Content::PODCAST))) {
  371.                 $content->addChild('content_podcast', [
  372.                     'label' => 'Podcasts',
  373.                     'route' => 'podcast_list',
  374.                 ]);
  375.             }
  376.             if(!$admin_view || in_array($admin_viewContent::getSitesForContentType(Content::POST))) {
  377.                 $content->addChild('content_post', [
  378.                     'label' => 'Posts',
  379.                     'route' => 'post_list',
  380.                 ]);
  381.             }
  382.             
  383.             if(!$admin_view || in_array($admin_viewContent::getSitesForContentType(Content::PROMOS_REBATES))) {
  384.                 $content->addChild('content_promos_and_rebates', [
  385.                     'label' => 'Promos and Rebates',
  386.                     'route' => 'promosrebates_list',
  387.                 ]);
  388.             }
  389.             if(!$admin_view || in_array($admin_viewContent::getSitesForContentType(Content::R_CLUB_PERK))) {
  390.                 $content->addChild('content_club_perk', [
  391.                     'label' => 'R-Club Perks',
  392.                     'route' => 'rclubperk_list',
  393.                 ]);
  394.             }
  395.             if(!$admin_view || in_array($admin_viewContent::getSitesForContentType(Content::THE_HUB))) { 
  396.                 $content->addChild('content_rlw', [
  397.                     'label' => 'RLW',
  398.                     'route' => 'thehub_list',
  399.                 ]);
  400.             }
  401.             if(!$admin_view || in_array($admin_viewContent::getSitesForContentType(Content::GALLERY))) { 
  402.                 $content->addChild('content_roofing_gallery', [
  403.                     'label' => 'Roofing Galleries',
  404.                     'route' => 'gallery_list',
  405.                 ]);
  406.             }
  407.             if(!$admin_view || in_array($admin_viewContent::getSitesForContentType(Content::SCHOLARSHIP))) {
  408.                 $content->addChild('content_scholarship', [
  409.                     'label' => 'Scholarships',
  410.                     'route' => 'scholarship_list',
  411.                 ]);
  412.             }
  413.             if($this->user && $this->user->isSuperAdmin()) {
  414.                 $content->addChild('content_staticpage', [
  415.                     'label' => 'Static Pages',
  416.                     'route' => 'staticpage_list',
  417.                 ]);
  418.             }
  419.             if(!$admin_view || in_array($admin_viewContent::getSitesForContentType(Content::VIDEO))) {
  420.                 $content->addChild('content_video', [
  421.                     'label' => 'Videos',
  422.                     'route' => 'video_list',
  423.                 ]);
  424.             }
  425.             if(!$admin_view || in_array($admin_viewContent::getSitesForContentType(Content::WEBINAR))) {
  426.                 $content->addChild('content_webinar', [
  427.                     'label' => 'Webinars',
  428.                     'route' => 'webinar_list',
  429.                 ]);
  430.             }
  431.         /* End Content */
  432.         
  433.         if($admin_view != Site::SITE_AAR) {
  434.             $user_dashboard $menu->addChild('user_dashboard', [
  435.                 'label' => 'User Dashboard',
  436.                 //'uri' => '/user-dashboard',
  437.                 'uri' => 'https://rooferscoffeeshop.com/user-dashboard',
  438.             ])->setExtras([
  439.                 'icon' => '<i class="fa fa-users"></i>',
  440.             ]);
  441.         }
  442.         
  443.         $users $menu->addChild('user', [
  444.                 'label' => 'Users',
  445.                 'route' => 'admin_app_user_list',
  446.             ])->setExtras([
  447.                 'icon' => '<i class="fa fa-user"></i>',
  448.             ]);
  449.         
  450.         if($admin_view != Site::SITE_AAR) {
  451.             $user_dashboard $menu->addChild('rclubquick', [
  452.                 'label' => 'RClub Quick Sign Up',
  453.                 'uri' => 'https://rooferscoffeeshop.com/rcs-club-quick-sign-up',
  454.             ])/*->setExtras([
  455.                 'icon' => '<i class="fa fa-users"></i>',
  456.             ])*/;
  457.         }
  458.         
  459.     }
  460. }