<commit_before><?php

namespace Oro\Bundle\ReportBundle\EventListener;

use Doctrine\ORM\EntityManager;

use Knp\Menu\ItemInterface;

use Oro\Bundle\SecurityBundle\SecurityFacade;
use Oro\Bundle\EntityConfigBundle\Provider\ConfigProvider;
use Oro\Bundle\NavigationBundle\Event\ConfigureMenuEvent;

class NavigationListener
{
    /**
     * @var EntityManager
     */
    protected $em;

    /**
     * @var ConfigProvider
     */
    protected $entityConfigProvider = null;

    /**
     * @var SecurityFacade
     */
    protected $securityFacade;

    /**
     * @param EntityManager  $entityManager
     * @param ConfigProvider $entityConfigProvider
     * @param SecurityFacade $securityFacade
     */
    public function __construct(
        EntityManager $entityManager,
        ConfigProvider $entityConfigProvider,
        SecurityFacade $securityFacade
    ) {
        $this->em                   = $entityManager;
        $this->entityConfigProvider = $entityConfigProvider;
        $this->securityFacade       = $securityFacade;
    }

    /**
     * @param ConfigureMenuEvent $event
     */
    public function onNavigationConfigure(ConfigureMenuEvent $event)
    {
        /** @var ItemInterface $reportsMenuItem */
        $reportsMenuItem = $event->getMenu()->getChild('reports_tab');
        if ($reportsMenuItem && $this->securityFacade->hasLoggedUser()) {
            $reports = $this->em->getRepository('OroReportBundle:Report')
                ->findBy([], ['name' => 'ASC']);

            if (!empty($reports)) {
                foreach ($reports as $key => $report) {
                    if (!$this->securityFacade->isGranted('VIEW', sprintf('entity:%s', $report->getEntity()))) {
                        unset($reports[$key]);
                    }
                }
            }

            if (!empty($reports)) {
                $this->addDivider($reportsMenuItem);
                $reportMenuData = [];
                foreach ($reports as $report) {
                    $config      = $this->entityConfigProvider->getConfig($report->getEntity());
                    $entityLabel = $config->get('plural_label');
                    if (!isset ($reportMenuData[$entityLabel])) {
                        $reportMenuData[$entityLabel] = [];
                    }
                    $reportMenuData[$entityLabel][$report->getId()] = $report->getName();<commit_msg>BAP-3397: Segments VIEW - navigation event listener, tests    - remove extra check<commit_after><?php

namespace Oro\Bundle\ReportBundle\EventListener;

use Doctrine\ORM\EntityManager;

use Knp\Menu\ItemInterface;

use Oro\Bundle\SecurityBundle\SecurityFacade;
use Oro\Bundle\EntityConfigBundle\Provider\ConfigProvider;
use Oro\Bundle\NavigationBundle\Event\ConfigureMenuEvent;

class NavigationListener
{
    /**
     * @var EntityManager
     */
    protected $em;

    /**
     * @var ConfigProvider
     */
    protected $entityConfigProvider = null;

    /**
     * @var SecurityFacade
     */
    protected $securityFacade;

    /**
     * @param EntityManager  $entityManager
     * @param ConfigProvider $entityConfigProvider
     * @param SecurityFacade $securityFacade
     */
    public function __construct(
        EntityManager $entityManager,
        ConfigProvider $entityConfigProvider,
        SecurityFacade $securityFacade
    ) {
        $this->em                   = $entityManager;
        $this->entityConfigProvider = $entityConfigProvider;
        $this->securityFacade       = $securityFacade;
    }

    /**
     * @param ConfigureMenuEvent $event
     */
    public function onNavigationConfigure(ConfigureMenuEvent $event)
    {
        /** @var ItemInterface $reportsMenuItem */
        $reportsMenuItem = $event->getMenu()->getChild('reports_tab');
        if ($reportsMenuItem && $this->securityFacade->hasLoggedUser()) {
            $reports = $this->em->getRepository('OroReportBundle:Report')
                ->findBy([], ['name' => 'ASC']);

            foreach ($reports as $key => $report) {
                if (!$this->securityFacade->isGranted('VIEW', sprintf('entity:%s', $report->getEntity()))) {
                    unset($reports[$key]);
                }
            }

            if (!empty($reports)) {
                $this->addDivider($reportsMenuItem);
                $reportMenuData = [];
                foreach ($reports as $report) {
                    $config      = $this->entityConfigProvider->getConfig($report->getEntity());
                    $entityLabel = $config->get('plural_label');
                    if (!isset ($reportMenuData[$entityLabel])) {
                        $reportMenuData[$entityLabel] = [];
                    }
                    $reportMenuData[$entityLabel][$report->getId()] = $report->getName();
{'fraction_non_alphanumeric': 0.12905249947709685, 'fraction_numerical': 0.0008366450533361222, 'mean_word_length': 2.213709677419355, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '678005', 'n_tokens_mistral': 1276, 'n_tokens_neox': 1218, 'n_words': 210}