<commit_before><?php

namespace Alpaca\Block\Controllers;

use Alpaca\Block\Models\Block;
use Alpaca\Crud\Controllers\ControllerTrait;
use Alpaca\Crud\Controllers\CrudContract;
use Alpaca\Crud\Controllers\DependencyTrait;
use Alpaca\Crud\Controllers\ModelTrait;
use Alpaca\Crud\Controllers\TextTrait;
use Alpaca\Crud\Controllers\ViewTrait;
use Alpaca\Crud\Permission\Permission;
use Alpaca\Menu\Models\Menu;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Routing\Controller;

class BlockBackend extends Controller implements CrudContract
{
    use ControllerTrait, ViewTrait, ModelTrait, TextTrait, DependencyTrait;

    /**
     * Modelname as singular.
     *
     * @return string
     */
    public function getSingularModelName()
    {
        return trans('block::block.block');
    }

    /**
     * Modelname as plural.
     *
     * @return string
     */
    public function getPluralModelName()
    {
        return trans('block::block.blocks');
    }

    /**
     *  Columns for the index page.
     *
     * @return array
     */
    public function getIndexColumns()
    {
        return [
            [
                'label' => trans('crud::crud.name'),
                'css' => 'col-md-3',
                'modelValue' => 'name',
            ],
            [
                'label' => trans('block::block.area'),
                'css' => 'col-md-3',
                'modelValue' => 'area',
            ],
            [
                'label' => trans('menu::menu.menu'),
                'css' => 'col-md-3',
                'modelValue' => 'getMenu',
            ],
            [
                'label' => trans('block::block.range'),
                'css' => 'col-md-3',
                'modelValue' => 'range',
            ],
        ];
    }

    /**
     * Formbuilder.
     *
     * @param null $form
     * @param \Illuminate\Database\Eloquent\Model|null $entry
     *
     * @return mixed
     */
    public function getForm($form = null, Model $entry = null)
    {
        $selectedArea = null;
        $selectedRange = null;
        $selectedMenu = null;

        if (! is_null($entry)) {
            // only for edit
            $selectedArea = $entry->area;
            $selectedRange = $entry->range;

            if (! empty($entry->menu->id)) {
                $selectedMenu = $entry->menu->id;
            }
        }

        $menus = Menu::orderBy('title', 'asc')->lists('title', 'id');
        $menus->prepend(trans('menu::menu.no_menu'), '');

        $formFields = [
            'id' => $form->hidden('id'),

            'name' => $form->text(trans('crud::crud.name'), 'name'),
            'title' => $form->text(trans('crud::crud.title'), 'title'),
            'active' => $form->checkbox(trans('page::page.active'), 'active')->defaultToChecked(),
            'mobile_view' => $form->checkbox(trans('block::block.mobile_view'), 'mobile_view')->defaultToChecked(),
            'desktop_view' => $form->checkbox(trans('block::block.mobile_view'), 'desktop_view')->defaultToChecked(),
            'desktop_view_force' => $form->checkbox(trans('block::block.mobile_view'), 'desktop_view_force'),
            'area' => $form->select(trans('block::block.area'), 'area')
                ->options($this->getAreaChoice())
                ->select($selectedArea),
            'range' => $form->select(trans('block::block.range'), 'range')
                ->options(Block::RANGES)
                ->select($selectedRange),
            'menu_id' => $form->select(trans('menu::menu.menu'), 'menu_id')
                ->options($menus)
                ->select($selectedMenu),
            'html' => $form->textarea(trans('crud::crud.body'), 'html')->addClass('is-summernote'),
            'exception' => $form->textarea(trans('block::block.exception'), 'exception'),
            'submit' => $form->submit(trans('crud::crud.save')),
        ];

        return $formFields;
    }

    /**
     * Return a model classname.
     *
     * @return \Illuminate\Database\Eloquent\Model
     */
    public function getModelClass()
    {
        return Block::class;
    }

    /**
     * Return a permession class.
     *
     * @return \Alpaca\Crud\Permission\Permission<commit_msg>* block view typo<commit_after><?php

namespace Alpaca\Block\Controllers;

use Alpaca\Block\Models\Block;
use Alpaca\Crud\Controllers\ControllerTrait;
use Alpaca\Crud\Controllers\CrudContract;
use Alpaca\Crud\Controllers\DependencyTrait;
use Alpaca\Crud\Controllers\ModelTrait;
use Alpaca\Crud\Controllers\TextTrait;
use Alpaca\Crud\Controllers\ViewTrait;
use Alpaca\Crud\Permission\Permission;
use Alpaca\Menu\Models\Menu;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Routing\Controller;

class BlockBackend extends Controller implements CrudContract
{
    use ControllerTrait, ViewTrait, ModelTrait, TextTrait, DependencyTrait;

    /**
     * Modelname as singular.
     *
     * @return string
     */
    public function getSingularModelName()
    {
        return trans('block::block.block');
    }

    /**
     * Modelname as plural.
     *
     * @return string
     */
    public function getPluralModelName()
    {
        return trans('block::block.blocks');
    }

    /**
     *  Columns for the index page.
     *
     * @return array
     */
    public function getIndexColumns()
    {
        return [
            [
                'label' => trans('crud::crud.name'),
                'css' => 'col-md-3',
                'modelValue' => 'name',
            ],
            [
                'label' => trans('block::block.area'),
                'css' => 'col-md-3',
                'modelValue' => 'area',
            ],
            [
                'label' => trans('menu::menu.menu'),
                'css' => 'col-md-3',
                'modelValue' => 'getMenu',
            ],
            [
                'label' => trans('block::block.range'),
                'css' => 'col-md-3',
                'modelValue' => 'range',
            ],
        ];
    }

    /**
     * Formbuilder.
     *
     * @param null $form
     * @param \Illuminate\Database\Eloquent\Model|null $entry
     *
     * @return mixed
     */
    public function getForm($form = null, Model $entry = null)
    {
        $selectedArea = null;
        $selectedRange = null;
        $selectedMenu = null;

        if (! is_null($entry)) {
            // only for edit
            $selectedArea = $entry->area;
            $selectedRange = $entry->range;

            if (! empty($entry->menu->id)) {
                $selectedMenu = $entry->menu->id;
            }
        }

        $menus = Menu::orderBy('title', 'asc')->lists('title', 'id');
        $menus->prepend(trans('menu::menu.no_menu'), '');

        $formFields = [
            'id' => $form->hidden('id'),

            'name' => $form->text(trans('crud::crud.name'), 'name'),
            'title' => $form->text(trans('crud::crud.title'), 'title'),
            'active' => $form->checkbox(trans('page::page.active'), 'active')->defaultToChecked(),
            'mobile_view' => $form->checkbox(trans('block::block.mobile_view'), 'mobile_view')->defaultToChecked(),
            'desktop_view' => $form->checkbox(trans('block::block.desktop_view'), 'desktop_view')->defaultToChecked(),
            'desktop_view_force' => $form->checkbox(trans('block::block.desktop_view_force'), 'desktop_view_force'),
            'area' => $form->select(trans('block::block.area'), 'area')
                ->options($this->getAreaChoice())
                ->select($selectedArea),
            'range' => $form->select(trans('block::block.range'), 'range')
                ->options(Block::RANGES)
                ->select($selectedRange),
            'menu_id' => $form->select(trans('menu::menu.menu'), 'menu_id')
                ->options($menus)
                ->select($selectedMenu),
            'html' => $form->textarea(trans('crud::crud.body'), 'html')->addClass('is-summernote'),
            'exception' => $form->textarea(trans('block::block.exception'), 'exception'),
            'submit' => $form->submit(trans('crud::crud.save')),
        ];

        return $formFields;
    }

    /**
     * Return a model classname.
     *
     * @return \Illuminate\Database\Eloquent\Model
     */
    public function getModelClass()
    {
        return Block::class;
    }

    /**
     * Return a permession class.
     *
     * @return \Alpaca\Crud\Permission\Permission
{'fraction_non_alphanumeric': 0.16702228544333808, 'fraction_numerical': 0.000948316737790422, 'mean_word_length': 2.037077033837293, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 117, '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': '3417880', 'n_tokens_mistral': 2555, 'n_tokens_neox': 2514, 'n_words': 392}