<commit_before><?php

namespace Bundle\MainBundle\Repository;

use Doctrine\ORM\NoResultException;

class OrganChartRepository extends BaseRepository
{

    public function getOrganChartByName($name)
    {
        $q = $this
            ->createQueryBuilder('o')
            ->where('o.name = :name')
            ->setParameter('name', $name)
            ->getQuery();

        try {
            $organChart = $q->getSingleResult();
        } catch (NoResultException $e) {
            $message = sprintf(
                'Unable to find OrganChart object identified by name "%s".',
                $name
            );
            throw new \Exception($message, 0, $e);
        }

        return $organChart;
    }

    public function getOrganChartIdByName($name)
    {
        $sql = "SELECT id FROM OrganChart WHERE name = '".trim($name)."'";
        $result = $this->sqlQuery($sql, true);

        return array_shift($result);
    }

    /**
     * Поиск подразделения по строке
     * @param $q
     * @return array
     */
    public function findByString($q)
    {
        $result = array();
        $qb = $this->createQueryBuilder('o');

        if (!empty($q)) {
            $q = trim($q);
            $condition = "o.name like '%$q%'";
            $qb->where($condition);
        }

        $qb->select(array('o'))
            ->orderBy('o.name', 'ASC');

        $organCharts = $qb->getQuery()->getResult();
        if ($organCharts) {
            foreach ($organCharts as $o) {
                $result[] = array(
                    "id" => $o->getId(),
                    "value" => $o->getName(),
                    "code" => $o->getCode()
                );
            }
        }

        return $result;
    }

    /**
     * Список кодов департаментов
     * @return array|mixed
     */
    public function getCodeList() {
        $sql = "SELECT id, code FROM OrganChart WHERE 1 ORDER BY code ASC";<commit_msg>Сообщение автокомплита при пустом результате<commit_after><?php

namespace Bundle\MainBundle\Repository;

use Doctrine\ORM\NoResultException;

class OrganChartRepository extends BaseRepository
{

    public function getOrganChartByName($name)
    {
        $q = $this
            ->createQueryBuilder('o')
            ->where('o.name = :name')
            ->setParameter('name', $name)
            ->getQuery();

        try {
            $organChart = $q->getSingleResult();
        } catch (NoResultException $e) {
            $message = sprintf(
                'Unable to find OrganChart object identified by name "%s".',
                $name
            );
            throw new \Exception($message, 0, $e);
        }

        return $organChart;
    }

    public function getOrganChartIdByName($name)
    {
        $sql = "SELECT id FROM OrganChart WHERE name = '".trim($name)."'";
        $result = $this->sqlQuery($sql, true);

        return array_shift($result);
    }

    /**
     * Поиск подразделения по строке
     * @param $q
     * @return array
     */
    public function findByString($q)
    {
        $result = array();
        $qb = $this->createQueryBuilder('o');

        if (!empty($q)) {
            $q = trim($q);
            $condition = "o.name like '%$q%'";
            $qb->where($condition);
        }

        $qb->select(array('o'))
            ->orderBy('o.name', 'ASC');

        $organCharts = $qb->getQuery()->getResult();
        if ($organCharts) {
            foreach ($organCharts as $o) {
                $result[] = array(
                    "id" => $o->getId(),
                    "value" => $o->getName(),
                    "code" => $o->getCode()
                );
            }
        } else {
            $result[] = array(
                "id" => "",
                "value" => $this->getTranslator()->trans('errors.noResult'),
                "position" => "",
                "category" => ""
            );
        }

        return $result;
    }

    /**
     * Список кодов департаментов
     * @return array|mixed
     */
    public function getCodeList() {
        $sql = "SELECT id, code FROM OrganChart WHERE 1 ORDER BY code ASC";
{'fraction_non_alphanumeric': 0.14769975786924938, 'fraction_numerical': 0.0009685230024213075, 'mean_word_length': 1.596480201131364, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 45, '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': '3519359', 'n_tokens_mistral': 1220, 'n_tokens_neox': 1195, 'n_words': 263}