<commit_before><?php

/*
 * This file is part of the Orchestra project.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace RomaricDrigon\OrchestraBundle\Controller;

use RomaricDrigon\OrchestraBundle\Core\Entity\EntityReflectionInterface;
use RomaricDrigon\OrchestraBundle\Domain\Command\CommandInterface;
use RomaricDrigon\OrchestraBundle\Domain\Repository\RepositoryInterface;
use RomaricDrigon\OrchestraBundle\Exception\Domain\EntityNotListableException;
use RomaricDrigon\OrchestraBundle\Form\Type\CommandType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

/**
 * Class GenericController
 * @author <NAME> <<EMAIL>>
 *
 * "Base" controller our Request goes to
 */
class GenericController extends Controller
{
    /**
     * Action for the dashboard page
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function dashboardAction()
    {
        return $this->render('RomaricDrigonOrchestraBundle:Generic:dashboard.html.twig', []);
    }

    /**
     * Action used when a repository "listing" is called
     *
     * @param RepositoryInterface $repository
     * @param EntityReflectionInterface $entity
     * @throws EntityNotListableException
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function listAction(RepositoryInterface $repository, EntityReflectionInterface $entity)
    {
        $name = $this->get('orchestra.resolver.repository_name')->getName($repository);

        if (false === $entity->isListable()) {
            throw new EntityNotListableException($entity->getName());
        }

        // Get objects to show
        $objects = $repository->listing();

        // Do not use empty, Doctrine Collection does not support it, only count
        $noData = (0 === count($objects));

        // We will also need titles for our table header
        $headers = [];
        if (false === $noData) {
            $headers = $this->get('orchestra.resolver.listing_header')->getHeaders($objects[0], 'viewListing');
        }

        // Finally, we need the routes for each entity
        // TODO

        return $this->render('RomaricDrigonOrchestraBundle:Generic:list.html.twig', [
            'headers'   => $headers,
            'no_data'   => $noData,
            'objects'   => $objects,
            'title'     => $name
        ]);
    }

    /**
     * Action used when a method on en Entity is called
     *
     * @param EntityReflectionInterface $entity
     * @param string $entity_slug
     * @param string $entity_method name
     * @param string $method_slug
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function entityMethodAction(EntityReflectionInterface $entity, $entity_slug, $entity_method, $method_slug)
    {
        return $this->render('RomaricDrigonOrchestraBundle:Generic:dashboard.html.twig', []);
    }

    /**
     * Action used when a method on en Repository is called
     *
     * @param \RomaricDrigon\OrchestraBundle\Domain\Repository\RepositoryInterface $repository
     * @param EntityReflectionInterface $entity
     * @param string $repository_method
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function repositoryMethodAction(RepositoryInterface $repository, EntityReflectionInterface $entity, $repository_method)
    {
        return $this->render('RomaricDrigonOrchestraBundle:Generic:dashboard.html.twig', []);
    }

    /**
     * Action used when a method accepting a Command, on en Repository is called
     *
     * @param Request $request
     * @param RepositoryInterface $repository
     * @param string $repository_method
     * @param CommandInterface $command
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function repositoryCommandAction(Request $request, RepositoryInterface $repository, $repository_method, CommandInterface $command)
    {
        $form = $this->createForm(new CommandType($command), $command);

        $repoName = $this->get('orchestra.resolver.repository_name')->getName($repository);

        if ($request->isMethod('POST')) {
            if ($form->handleRequest($request) && $form->isValid()) {
                // Pass the command to the repository, and we're done!
                call_user_func([$repository, $repository_method]);

                $this->get('session')->getFlashBag()->add(
                    'notice',
                    'Command run with success!'
                );

                // TODO: redirect to Repository listing
                //return $this->redirect($this->generateUrl('agency_list'));
            } else {
                $this->get('session')->getFlashBag()->add(
                    'error',
                    'An error happened!'
                );
            }
        }

        return $this->render('RomaricDrigonOrchestraBundle:Generic:repositoryCommand.html.twig', [
            'form'  => $form->createView(),
            'title' => $repoName
        ]);
    }
}<commit_msg>After a repository Command, user is redirected to listing<commit_after><?php

/*
 * This file is part of the Orchestra project.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace RomaricDrigon\OrchestraBundle\Controller;

use RomaricDrigon\OrchestraBundle\Core\Entity\EntityReflectionInterface;
use RomaricDrigon\OrchestraBundle\Domain\Command\CommandInterface;
use RomaricDrigon\OrchestraBundle\Domain\Repository\RepositoryInterface;
use RomaricDrigon\OrchestraBundle\Exception\Domain\EntityNotListableException;
use RomaricDrigon\OrchestraBundle\Form\Type\CommandType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

/**
 * Class GenericController
 * @author <NAME> <<EMAIL>>
 *
 * "Base" controller our Request goes to
 */
class GenericController extends Controller
{
    /**
     * Action for the dashboard page
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function dashboardAction()
    {
        return $this->render('RomaricDrigonOrchestraBundle:Generic:dashboard.html.twig', []);
    }

    /**
     * Action used when a repository "listing" is called
     *
     * @param RepositoryInterface $repository
     * @param EntityReflectionInterface $entity
     * @throws EntityNotListableException
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function listAction(RepositoryInterface $repository, EntityReflectionInterface $entity)
    {
        $name = $this->get('orchestra.resolver.repository_name')->getName($repository);

        if (false === $entity->isListable()) {
            throw new EntityNotListableException($entity->getName());
        }

        // Get objects to show
        $objects = $repository->listing();

        // Do not use empty, Doctrine Collection does not support it, only count
        $noData = (0 === count($objects));

        // We will also need titles for our table header
        $headers = [];
        if (false === $noData) {
            $headers = $this->get('orchestra.resolver.listing_header')->getHeaders($objects[0], 'viewListing');
        }

        // Finally, we need the routes for each entity
        // TODO

        return $this->render('RomaricDrigonOrchestraBundle:Generic:list.html.twig', [
            'headers'   => $headers,
            'no_data'   => $noData,
            'objects'   => $objects,
            'title'     => $name
        ]);
    }

    /**
     * Action used when a method on en Entity is called
     *
     * @param EntityReflectionInterface $entity
     * @param string $entity_slug
     * @param string $entity_method name
     * @param string $method_slug
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function entityMethodAction(EntityReflectionInterface $entity, $entity_slug, $entity_method, $method_slug)
    {
        return $this->render('RomaricDrigonOrchestraBundle:Generic:dashboard.html.twig', []);
    }

    /**
     * Action used when a method on en Repository is called
     *
     * @param \RomaricDrigon\OrchestraBundle\Domain\Repository\RepositoryInterface $repository
     * @param EntityReflectionInterface $entity
     * @param string $repository_method
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function repositoryMethodAction(RepositoryInterface $repository, EntityReflectionInterface $entity, $repository_method)
    {
        return $this->render('RomaricDrigonOrchestraBundle:Generic:dashboard.html.twig', []);
    }

    /**
     * Action used when a method accepting a Command, on en Repository is called
     *
     * @param Request $request
     * @param RepositoryInterface $repository
     * @param string $repository_method
     * @param CommandInterface $command
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function repositoryCommandAction(Request $request, RepositoryInterface $repository, $repository_method, CommandInterface $command)
    {
        $form = $this->createForm(new CommandType($command), $command);

        $repoName = $this->get('orchestra.resolver.repository_name')->getName($repository);

        if ($request->isMethod('POST')) {
            if ($form->handleRequest($request) && $form->isValid()) {
                // Pass the command to the repository, and we're done!
                call_user_func([$repository, $repository_method]);

                $this->get('session')->getFlashBag()->add(
                    'notice',
                    'Command run with success!'
                );

                // We redirect to "listing" page/action
                $listRoute = $this->get('orchestra.resolver.repository_route_name')->getRouteName($repository, 'listing');

                return $this->redirect($this->generateUrl($listRoute));
            } else {
                $this->get('session')->getFlashBag()->add(
                    'error',
                    'An error happened!'
                );
            }
        }

        return $this->render('RomaricDrigonOrchestraBundle:Generic:repositoryCommand.html.twig', [
            'form'  => $form->createView(),
            'title' => $repoName
        ]);
    }
}
{'fraction_non_alphanumeric': 0.1132509341764875, 'fraction_numerical': 0.00038325189230621826, 'mean_word_length': 2.7832548024646613, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 77, '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': '3690804', 'n_tokens_mistral': 2758, 'n_tokens_neox': 2706, 'n_words': 623}