<commit_before><?php

namespace PHPOrchestra\BackofficeBundle\Controller;

use PHPOrchestra\BackofficeBundle\Form\Type\BlockType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration as Config;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use PHPOrchestra\ModelBundle\Model\NodeInterface;
use PHPOrchestra\ModelBundle\Model\BlockInterface;

/**
 * Class BlockController
 */
class BlockController extends AbstractAdminController
{
    /**
     * @param Request $request
     * @param string  $nodeId
     * @param int     $blockNumber
     *
     * @Config\Route("/block/form/{nodeId}/{blockNumber}", name="php_orchestra_backoffice_block_form", requirements={"blockNumber" = "\d+"}, defaults={"blockNumber" = 0})
     * @Config\Method({"GET", "POST"})
     *
     * @return Response
     */
    public function formAction(Request $request, $nodeId, $blockNumber = 0)
    {
        $node = $this->get('php_orchestra_model.repository.node')->find($nodeId);
        $block = $node->getBlocks()->get($blockNumber);

        $form = $this->createForm(
            'block',
            $block,
            array(
                'action' => $this->generateUrl('php_orchestra_backoffice_block_form', array(
                    'nodeId' => $nodeId,
                    'blockNumber' => $blockNumber
                )),
                'blockPosition' => $blockNumber
            )
        );

        $form->handleRequest($request);

        $this->handleForm($form, $this->get('translator')
            ->trans('php_orchestra_backoffice.form.block.success'), $node);

        return $this->renderAdminForm($form, array('blockType' => $block->getComponent()));
    }

    /**
     * List all possible blocks
     *
     * @return Response
     */
    public function listPossibleBlocksAction()
    {
        $blocks = $this->container->getParameter('php_orchestra.blocks');

        return $this->render('PHPOrchestraBackofficeBundle:Block:possibleBlocksList.html.twig', array(
            'blocks' => $blocks
        ));
    }

    /**
     * List all existing blocks
     *
     * @return Response
     */
    public function listExistingBlocksAction()
    {
        $node = $this->get('php_orchestra_model.repository.node')
            ->findOneByNodeIdAndSiteIdAndLastVersion(NodeInterface::ROOT_NODE_ID);
        if ($node) {
            $transformer = $this->get('php_orchestra_api.transformer_manager')->get('block');
            $blocks = $node->getBlocks();
            foreach ($blocks as $key => $block) {<commit_msg>add the block research in the transverse node<commit_after><?php

namespace PHPOrchestra\BackofficeBundle\Controller;

use PHPOrchestra\BackofficeBundle\Form\Type\BlockType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration as Config;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use PHPOrchestra\ModelBundle\Model\NodeInterface;
use PHPOrchestra\ModelBundle\Model\BlockInterface;

/**
 * Class BlockController
 */
class BlockController extends AbstractAdminController
{
    /**
     * @param Request $request
     * @param string  $nodeId
     * @param int     $blockNumber
     *
     * @Config\Route("/block/form/{nodeId}/{blockNumber}", name="php_orchestra_backoffice_block_form", requirements={"blockNumber" = "\d+"}, defaults={"blockNumber" = 0})
     * @Config\Method({"GET", "POST"})
     *
     * @return Response
     */
    public function formAction(Request $request, $nodeId, $blockNumber = 0)
    {
        $node = $this->get('php_orchestra_model.repository.node')->find($nodeId);
        $block = $node->getBlocks()->get($blockNumber);

        $form = $this->createForm(
            'block',
            $block,
            array(
                'action' => $this->generateUrl('php_orchestra_backoffice_block_form', array(
                    'nodeId' => $nodeId,
                    'blockNumber' => $blockNumber
                )),
                'blockPosition' => $blockNumber
            )
        );

        $form->handleRequest($request);

        $this->handleForm($form, $this->get('translator')
            ->trans('php_orchestra_backoffice.form.block.success'), $node);

        return $this->renderAdminForm($form, array('blockType' => $block->getComponent()));
    }

    /**
     * List all possible blocks
     *
     * @return Response
     */
    public function listPossibleBlocksAction()
    {
        $blocks = $this->container->getParameter('php_orchestra.blocks');

        return $this->render('PHPOrchestraBackofficeBundle:Block:possibleBlocksList.html.twig', array(
            'blocks' => $blocks
        ));
    }

    /**
     * List all existing blocks
     *
     * @return Response
     */
    public function listExistingBlocksAction()
    {
        $node = $this->get('php_orchestra_model.repository.node')
            ->findOneByNodeIdAndSiteIdAndLastVersion(NodeInterface::TRANSVERSE_NODE_ID);
        if ($node) {
            $transformer = $this->get('php_orchestra_api.transformer_manager')->get('block');
            $blocks = $node->getBlocks();
            foreach ($blocks as $key => $block) {
{'fraction_non_alphanumeric': 0.13843774168600154, 'fraction_numerical': 0.0007733952049497294, 'mean_word_length': 2.7649199417758368, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 57, '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': '7383431', 'n_tokens_mistral': 1477, 'n_tokens_neox': 1456, 'n_words': 237}