<commit_before><?php namespace Anomaly\VariablesModule\Http\Controller\Admin;

use Anomaly\Streams\Platform\Assignment\Form\AssignmentFormBuilder;
use Anomaly\Streams\Platform\Assignment\Table\AssignmentTableBuilder;
use Anomaly\Streams\Platform\Field\Contract\FieldInterface;
use Anomaly\Streams\Platform\Field\Contract\FieldRepositoryInterface;
use Anomaly\Streams\Platform\Http\Controller\AdminController;
use Anomaly\Streams\Platform\Stream\Contract\StreamInterface;
use Anomaly\Streams\Platform\Stream\Contract\StreamRepositoryInterface;
use Anomaly\Streams\Platform\Ui\Breadcrumb\BreadcrumbCollection;
use Anomaly\VariablesModule\Group\Form\GroupFormBuilder;
use Anomaly\VariablesModule\Group\Table\GroupTableBuilder;

/**
 * Class GroupsController
 *
 * @link          http://pyrocms.com/
 * @author        PyroCMS, Inc. <<EMAIL>>
 * @author        <NAME> <<EMAIL>>
 * @package       Anomaly\VariablesModule\Http\Controller\Admin
 */
class GroupsController extends AdminController
{

    /**
     * Return an index of existing entries.
     *
     * @param GroupTableBuilder $table
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function index(GroupTableBuilder $table)
    {
        return $table->render();
    }

    /**
     * Return a form for a new page type.
     *
     * @param GroupFormBuilder $form
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function create(GroupFormBuilder $form)
    {
        return $form->render();
    }

    /**
     * Return a form for editing an existing page type.
     *
     * @param GroupFormBuilder    $form
     * @param                     $id
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function edit(GroupFormBuilder $form, $id)
    {
        return $form->render($id);
    }

    /**
     * Return a table of existing page type assignments.
     *
     * @param AssignmentTableBuilder      $table
     * @param StreamRepositoryInterface   $groups
     * @param BreadcrumbCollection        $breadcrumbs
     * @param                             $id
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function fields(
        AssignmentTableBuilder $table,
        StreamRepositoryInterface $streams,
        BreadcrumbCollection $breadcrumbs,
        $id
    ) {
        /* @var StreamInterface $group */
        $group = $streams->find($id);

        $breadcrumbs->put($group->getName(), 'admin/variables/groups/edit/' . $group->getId());
        $breadcrumbs->put('streams::breadcrumb.assignments', 'admin/variables/groups/assignments/' . $group->getId());

        return $table
            ->setButtons(
                [
                    'edit' => [
                        'href' => '{request.path}/assignment/{entry.id}'
                    ]
                ]
            )
            ->setStream($group)
            ->render();
    }

    /**
     * Return the modal for choosing a field to assign.
     *
     * @param FieldRepositoryInterface $fields
     * @return \Illuminate\View\View
     */
    public function choose(FieldRepositoryInterface $fields, StreamRepositoryInterface $groups, $id)
    {
        /* @var StreamInterface $group */
        $group = $groups->find($id);

        return view(
            'module::ajax/choose_field',
            [
                'fields' => $fields->findAllByNamespace('variables')->notAssignedTo($group)->unlocked(),
                'id'     => $id
            ]
        );
    }

    /**
     * Return the assignment form for a variable.
     *
     * @param AssignmentFormBuilder     $form
     * @param StreamRepositoryInterface $streams
     * @param FieldRepositoryInterface  $fields
     * @param                           $id
     * @param                           $field
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function assign(
        AssignmentFormBuilder $form,
        StreamRepositoryInterface $streams,
        FieldRepositoryInterface $fields,
        $id,
        $field
    ) {
        /* @var StreamInterface $group */
        /* @var FieldInterface $field */
        $group = $streams->find($id);
        $field = $fields->find($field);

        return $form
            ->setActions(
                [
                    'save' => [
                        'redirect' => 'admin/variables/groups/assignments/' . $id
                    ]
                ]
            )
            ->setStream($group)
            ->setField($field)
            ->render();
    }

    /**<commit_msg>Let the defaults do their thing<commit_after><?php namespace Anomaly\VariablesModule\Http\Controller\Admin;

use Anomaly\Streams\Platform\Assignment\Form\AssignmentFormBuilder;
use Anomaly\Streams\Platform\Assignment\Table\AssignmentTableBuilder;
use Anomaly\Streams\Platform\Field\Contract\FieldInterface;
use Anomaly\Streams\Platform\Field\Contract\FieldRepositoryInterface;
use Anomaly\Streams\Platform\Http\Controller\AdminController;
use Anomaly\Streams\Platform\Stream\Contract\StreamInterface;
use Anomaly\Streams\Platform\Stream\Contract\StreamRepositoryInterface;
use Anomaly\Streams\Platform\Ui\Breadcrumb\BreadcrumbCollection;
use Anomaly\VariablesModule\Group\Form\GroupFormBuilder;
use Anomaly\VariablesModule\Group\Table\GroupTableBuilder;

/**
 * Class GroupsController
 *
 * @link          http://pyrocms.com/
 * @author        PyroCMS, Inc. <<EMAIL>>
 * @author        <NAME> <<EMAIL>>
 * @package       Anomaly\VariablesModule\Http\Controller\Admin
 */
class GroupsController extends AdminController
{

    /**
     * Return an index of existing entries.
     *
     * @param GroupTableBuilder $table
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function index(GroupTableBuilder $table)
    {
        return $table->render();
    }

    /**
     * Return a form for a new page type.
     *
     * @param GroupFormBuilder $form
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function create(GroupFormBuilder $form)
    {
        return $form->render();
    }

    /**
     * Return a form for editing an existing page type.
     *
     * @param GroupFormBuilder    $form
     * @param                     $id
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function edit(GroupFormBuilder $form, $id)
    {
        return $form->render($id);
    }

    /**
     * Return a table of existing page type assignments.
     *
     * @param AssignmentTableBuilder      $table
     * @param StreamRepositoryInterface   $groups
     * @param BreadcrumbCollection        $breadcrumbs
     * @param                             $id
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function fields(
        AssignmentTableBuilder $table,
        StreamRepositoryInterface $streams,
        BreadcrumbCollection $breadcrumbs,
        $id
    ) {
        /* @var StreamInterface $group */
        $group = $streams->find($id);

        $breadcrumbs->put($group->getName(), 'admin/variables/groups/edit/' . $group->getId());
        $breadcrumbs->put('streams::breadcrumb.assignments', 'admin/variables/groups/assignments/' . $group->getId());

        return $table
            ->setButtons(
                [
                    'edit' => [
                        'href' => '{request.path}/assignment/{entry.id}'
                    ]
                ]
            )
            ->setStream($group)
            ->render();
    }

    /**
     * Return the modal for choosing a field to assign.
     *
     * @param FieldRepositoryInterface $fields
     * @return \Illuminate\View\View
     */
    public function choose(FieldRepositoryInterface $fields, StreamRepositoryInterface $groups, $id)
    {
        /* @var StreamInterface $group */
        $group = $groups->find($id);

        return view(
            'module::ajax/choose_field',
            [
                'fields' => $fields->findAllByNamespace('variables')->notAssignedTo($group)->unlocked(),
                'id'     => $id
            ]
        );
    }

    /**
     * Return the assignment form for a variable.
     *
     * @param AssignmentFormBuilder     $form
     * @param StreamRepositoryInterface $streams
     * @param FieldRepositoryInterface  $fields
     * @param                           $id
     * @param                           $field
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function assign(
        AssignmentFormBuilder $form,
        StreamRepositoryInterface $streams,
        FieldRepositoryInterface $fields,
        $id,
        $field
    ) {
        /* @var StreamInterface $group */
        /* @var FieldInterface $field */
        $group = $streams->find($id);
        $field = $fields->find($field);

        return $form
            ->setStream($group)
            ->setField($field)
            ->render();
    }

    /**
{'fraction_non_alphanumeric': 0.11426020977460388, 'fraction_numerical': 0.0, 'mean_word_length': 2.055915444936925, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 66, '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': '406133', 'n_tokens_mistral': 2415, 'n_tokens_neox': 2367, 'n_words': 470}