<commit_before><?php

namespace ITDoors\OperBundle\Services;

use Doctrine\ORM\EntityManager;
use Symfony\Component\DependencyInjection\Container;
use SD\UserBundle\Entity\User;
use \Doctrine\Common\Collections\ArrayCollection;
use Lists\CompanystructureBundle\Entity\Companystructure;
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
use SD\UserBundle\Entity\StuffDepartments;

/**
 * Class AccessService
 */
class AccessService
{

    /** @var Container $container */
    protected $container;

    /** @var  EntityManager $em */
    protected $em;

    /**
     * @param Container $container
     */
    public function __construct (Container $container)
    {
        $this->container = $container;
        $this->em = $this->container->get('doctrine.orm.entity_manager');
    }

    /**
     * @param null|User $user
     *
     * @return array|bool
     */
    public function getAllowedDepartmentsId ($user = null)
    {
        if (!$user) {
            $user = $this->container->get('security.context')->getToken()->getUser();
        }
        $idUser = $user->getId();
        //->getUser();
        $checkOper = $user->hasRole('ROLE_OPER');

        $checkSuperviser = $user->hasRole('ROLE_SUPERVISOR');

        if ($checkSuperviser) {

            return false;
        } elseif ($checkOper) {

            /** @var  $stuff \SD\UserBundle\Entity\Stuff */
            $stuff = $this->container->get('doctrine')
                ->getRepository('SDUserBundle:Stuff')
                ->findOneBy(array ('user' => $idUser));

            if (!$stuff) {
                return array ();
            }


            $stuffDepartments = $this->container->get('doctrine')
                ->getRepository('SDUserBundle:StuffDepartments')
                ->findBy(array ('stuff' => $stuff));

            if (count($stuffDepartments) == 0 || !$stuffDepartments) {
                return array ();
            }

            if (!is_array($stuffDepartments)) {
                $stuffDepartments = array ($stuffDepartments);
            }

            $idDepartmentsAllowed = array ();

            /** @var  $stuffDepartment \SD\UserBundle\Entity\StuffDepartments */
            foreach ($stuffDepartments as $stuffDepartment) {
                $departmentsAllowed = $stuffDepartment->getDepartments();

                if (count($departmentsAllowed) == 0) {
                    return array ();
                }
                if (!is_array($departmentsAllowed)) {
                    $departmentsAllowed = array ($departmentsAllowed);
                }

                foreach ($departmentsAllowed as $departmentAllowed) {
                    $idDepartmentsAllowed[] = $departmentAllowed->getId();
                }
            }
            $idDepartmentsAllowed = array_unique($idDepartmentsAllowed);

            return $idDepartmentsAllowed;
        } else {
            return array ();<commit_msg>new access to departments<commit_after><?php

namespace ITDoors\OperBundle\Services;

use Doctrine\ORM\EntityManager;
use Symfony\Component\DependencyInjection\Container;
use SD\UserBundle\Entity\User;
use \Doctrine\Common\Collections\ArrayCollection;
use Lists\CompanystructureBundle\Entity\Companystructure;
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
use SD\UserBundle\Entity\StuffDepartments;

/**
 * Class AccessService
 */
class AccessService
{

    /** @var Container $container */
    protected $container;

    /** @var  EntityManager $em */
    protected $em;

    /**
     * @param Container $container
     */
    public function __construct (Container $container)
    {
        $this->container = $container;
        $this->em = $this->container->get('doctrine.orm.entity_manager');
    }

    /**
     * @param null|User $user
     *
     * @return array|bool
     */
    public function getAllowedDepartmentsId ($user = null)
    {
        if (!$user) {
            $user = $this->container->get('security.context')->getToken()->getUser();
        }
        $idUser = $user->getId();
        //->getUser();
        $checkOper = $user->hasRole('ROLE_OPER');

        $checkSuperviser = $user->hasRole('ROLE_SUPERVISOR');

        if ($checkSuperviser) {

            return false;
        } elseif ($checkOper) {
            return $this->getAllowedDepartmentsForUser($user);

            /** @var  $stuff \SD\UserBundle\Entity\Stuff */
/*
            $stuff = $this->container->get('doctrine')
                ->getRepository('SDUserBundle:Stuff')
                ->findOneBy(array ('user' => $idUser));

            if (!$stuff) {
                return array ();
            }


            $stuffDepartments = $this->container->get('doctrine')
                ->getRepository('SDUserBundle:StuffDepartments')
                ->findBy(array ('stuff' => $stuff));

            if (count($stuffDepartments) == 0 || !$stuffDepartments) {
                return array ();
            }

            if (!is_array($stuffDepartments)) {
                $stuffDepartments = array ($stuffDepartments);
            }

            $idDepartmentsAllowed = array ();

            foreach ($stuffDepartments as $stuffDepartment) {
                $departmentsAllowed = $stuffDepartment->getDepartments();

                if (count($departmentsAllowed) == 0) {
                    return array ();
                }
                if (!is_array($departmentsAllowed)) {
                    $departmentsAllowed = array ($departmentsAllowed);
                }

                foreach ($departmentsAllowed as $departmentAllowed) {
                    $idDepartmentsAllowed[] = $departmentAllowed->getId();
                }
            }
            $idDepartmentsAllowed = array_unique($idDepartmentsAllowed);

            return $idDepartmentsAllowed;*/
        } else {
            return array ();
{'fraction_non_alphanumeric': 0.13004255319148936, 'fraction_numerical': 0.0006808510638297873, 'mean_word_length': 2.054054054054054, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 52, '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': '4663091', 'n_tokens_mistral': 1668, 'n_tokens_neox': 1538, 'n_words': 270}