<commit_before><?php
/**
 * This file is part of the demo_cms  package.
 *
 * (c) net working AG <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Networking\InitCmsBundle\Controller;

use Doctrine\ORM\Query;
use Networking\InitCmsBundle\Model\Tag;
use Sonata\AdminBundle\Exception\ModelManagerException;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Validator\Exception\ValidatorException;

class TagAdminController extends CRUDController
{
    /**
     * @return Response
     */
    public function createAction()
    {
        /** @var Response $response */
        $response = parent::createAction();

        if ($this->isXmlHttpRequest()) {
            $content = $response->getContent();
            $jsonArray = json_decode($content, true);

            if ($jsonArray['result'] == 'ok') {
                $jsonArray['html'] = $this->getTagTree($jsonArray['objectId']);
                $response = $this->renderJson($jsonArray, 200);
            }
        }

        return $response;
    }

    /**
     * @param $objectId
     *
     * @return string
     */
    public function getTagTree($objectId)
    {
        $tagRepo = $this->getDoctrine()->getRepository('NetworkingInitCmsBundle:Tag');
        $tags = $tagRepo->findBy(['level' => 1], ['path' => 'ASC']);

        return $this->renderView('@NetworkingInitCms/TagAdmin/tags.html.twig', [
            'noSort' => false,
            'tags' => $tags,
            'tagAdmin' => $this->admin,
            'lastItem' => $objectId, ]);
    }

    /**
     * @param int|null|string $id
     *<commit_msg>fix missing translation for tag creation<commit_after><?php
/**
 * This file is part of the demo_cms  package.
 *
 * (c) net working AG <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Networking\InitCmsBundle\Controller;

use Doctrine\ORM\Query;
use Networking\InitCmsBundle\Model\Tag;
use Sonata\AdminBundle\Exception\ModelManagerException;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Validator\Exception\ValidatorException;

class TagAdminController extends CRUDController
{
    /**
     * @return Response
     */
    public function createAction()
    {
        /** @var Response $response */
        $response = parent::createAction();

        if ($this->isXmlHttpRequest()) {
            $content = $response->getContent();
            $jsonArray = json_decode($content, true);


            if ($jsonArray['result'] == 'ok') {
                $object = $this->admin->getObject($jsonArray['objectId']);
                $jsonArray['status'] =  'success';
                $jsonArray['message'] =  $this->translate('flash_create_success', ['%name%' =>  $this->escapeHtml($this->admin->toString($object))], 'SonataAdminBundle');
                $jsonArray['html'] = $this->getTagTree($jsonArray['objectId']);
                $response = $this->renderJson($jsonArray, 200);
            }
        }

        return $response;
    }

    /**
     * @param $objectId
     *
     * @return string
     */
    public function getTagTree($objectId)
    {
        $tagRepo = $this->getDoctrine()->getRepository('NetworkingInitCmsBundle:Tag');
        $tags = $tagRepo->findBy(['level' => 1], ['path' => 'ASC']);

        return $this->renderView('@NetworkingInitCms/TagAdmin/tags.html.twig', [
            'noSort' => false,
            'tags' => $tags,
            'tagAdmin' => $this->admin,
            'lastItem' => $objectId, ]);
    }

    /**
     * @param int|null|string $id
     *
{'fraction_non_alphanumeric': 0.14087538866299928, 'fraction_numerical': 0.0019134178426213825, 'mean_word_length': 2.9047619047619047, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 44, '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': '351225', 'n_tokens_mistral': 1194, 'n_tokens_neox': 1169, 'n_words': 236}