<commit_before><?php

namespace App\Http\Controllers\Maven;

use Illuminate\Http\Request;

use App\Http\Requests;
use Sukohi\Maven\Maven;
use Sukohi\Maven\MavenFaq;
use Sukohi\Maven\MavenLocale;
use Sukohi\Maven\MavenTag;
use Sukohi\Maven\MavenUniqueKey;

class MavenController extends \App\Http\Controllers\Controller
{
    public function index() {

        $message = '';
        $maven_items = MavenUniqueKey::with('faq.tags')
            ->neatness()
            ->smoothness()
            ->orderBy('sort')
            ->paginate(config('maven.per_page'));

        return view('maven.index', [
            'page_title' => trans('maven.list'),
            'maven_items' => $maven_items,
            'sort_values' => [],
            'tag_values' => [],
            'message' => $message,
            'current_locale' => Maven::getLocale()
        ]);

    }
    public function view() {

        $message = '';
        $maven_items = MavenUniqueKey::with('faq.tags')
            ->neatness()
            ->smoothness()
            ->orderBy('sort')
            ->paginate(config('maven.per_page'));

        return view('maven.view', [
            'page_title' => trans('maven.list'),
            'maven_items' => $maven_items,
            'sort_values' => [],
            'tag_values' => [],
            'message' => $message,
            'current_locale' => Maven::getLocale()
        ]);

    }
    public function create() {

        $maven_item = new MavenUniqueKey;

        return view('maven.input', [
            'page_title' => trans('maven.add'),
            'sort_options' => MavenUniqueKey::selectOptions(),
            'tag_values' => [],
            'locales' => MavenLocale::options(),
            'current_locale' => Maven::getLocale(),
            'maven_item' => $maven_item,
            'mode' => 'store'
        ]);

    }

    public function store(Requests\MavenRequest $request) {

        $unique_key = new MavenUniqueKey;
        $unique_key->unique_key = $this->getUniqueKey();
        $unique_key->sort = $request->sort;
        $unique_key->draft_flag = $request->has('draft_flag');
        $unique_key->save();
        $this->saveSubData($unique_key->id, $request);

        \Cahen::move($unique_key)->to('sort', $request->sort);
        return redirect()->route('maven.edit', $unique_key->id)->with('success', trans('maven.complete'));

    }

    public function edit($id) {

        $maven_item = MavenUniqueKey::with('faqs')->find($id);
        $faqs = $maven_item->faqs->keyBy('locale');

        return view('maven.input', [
            'page_title' => trans('maven.edit'),
            'sort_options' => MavenUniqueKey::selectOptions(),
            'tag_values' => [],
            'locales' => MavenLocale::options(),
            'current_locale' => Maven::getLocale(),
            'maven_item' => $maven_item,
            'faqs' => $faqs,
            'mode' => 'update'
        ]);

    }

    public function update(Request $request, $id) {

        $unique_key = MavenUniqueKey::find($id);
        $unique_key->unique_key = $this->getUniqueKey();
        $unique_key->sort = $request->sort;
        $unique_key->draft_flag = $request->has('draft_flag');
        $unique_key->save();
        $this->saveSubData($unique_key->id, $request);

        \Cahen::move($unique_key)->to('sort', $request->sort);
        return back()->with('success', trans('maven.complete'));

    }

    public function destroy($id) {

        $maven_item = MavenUniqueKey::find($id);
        $maven_item->delete();

        $maven_items = MavenUniqueKey::orderBy('sort')->get();
        \Cahen::align($maven_items, 'sort');

        return back()->with('success', trans('maven.complete'));

    }

    public function locale($locale) {

        Maven::setLocale($locale);
        return redirect()->route('maven.index');
<commit_msg>add middleware<commit_after><?php

namespace App\Http\Controllers\Maven;

use Illuminate\Http\Request;

use App\Http\Requests;
use Sukohi\Maven\Maven;
use Sukohi\Maven\MavenFaq;
use Sukohi\Maven\MavenLocale;
use Sukohi\Maven\MavenTag;
use Sukohi\Maven\MavenUniqueKey;
use DB;

class MavenController extends \App\Http\Controllers\Controller
{
    public function __construct()
    {
        $this->middleware('role:admin|superadmin',['except' => 'view']);
    }

    public function index() {
        $message = '';
        $maven_items = MavenUniqueKey::with('faq.tags')
            ->neatness()
            ->smoothness()
            ->orderBy('sort')
            ->paginate(config('maven.per_page'));

        return view('maven.index', [
            'page_title' => trans('maven.list'),
            'maven_items' => $maven_items,
            'sort_values' => [],
            'tag_values' => [],
            'message' => $message,
            'current_locale' => Maven::getLocale()
        ]);

    }
    public function view() {

        $message = '';

        $maven_items= DB::table('maven_faqs')
            ->join('maven_tags','maven_faqs.id','=','maven_tags.faq_id')
            ->select(DB::raw('maven_faqs.question as question,maven_faqs.answer as answer, maven_tags.tag as tag'))
            ->get();

/*        $maven_items = MavenUniqueKey::with('faq.tags')
            ->neatness()
            ->smoothness()
            ->orderBy('sort')
            ->paginate(config('maven.per_page'));*/

/*        return view('maven.view', [
            'page_title' => trans('maven.list'),
            'maven_items' => $maven_items,
            'sort_values' => [],
            'tag_values' => [],
            'message' => $message,
            'current_locale' => Maven::getLocale()
        ]);*/
        return view('maven.view',compact('maven_items'));

    }
    public function create() {
        $maven_item = new MavenUniqueKey;

        return view('maven.input', [
            'page_title' => trans('maven.add'),
            'sort_options' => MavenUniqueKey::selectOptions(),
            'tag_values' => [],
            'locales' => MavenLocale::options(),
            'current_locale' => Maven::getLocale(),
            'maven_item' => $maven_item,
            'mode' => 'store'
        ]);

    }

    public function store(Requests\MavenRequest $request) {
        $unique_key = new MavenUniqueKey;
        $unique_key->unique_key = $this->getUniqueKey();
        $unique_key->sort = $request->sort;
        $unique_key->draft_flag = $request->has('draft_flag');
        $unique_key->save();
        $this->saveSubData($unique_key->id, $request);

        \Cahen::move($unique_key)->to('sort', $request->sort);
        return redirect()->route('maven.edit', $unique_key->id)->with('success', trans('maven.complete'));

    }

    public function edit($id) {
        $maven_item = MavenUniqueKey::with('faqs')->find($id);
        $faqs = $maven_item->faqs->keyBy('locale');

        return view('maven.input', [
            'page_title' => trans('maven.edit'),
            'sort_options' => MavenUniqueKey::selectOptions(),
            'tag_values' => [],
            'locales' => MavenLocale::options(),
            'current_locale' => Maven::getLocale(),
            'maven_item' => $maven_item,
            'faqs' => $faqs,
            'mode' => 'update'
        ]);

    }

    public function update(Request $request, $id) {
        $unique_key = MavenUniqueKey::find($id);
        $unique_key->unique_key = $this->getUniqueKey();
        $unique_key->sort = $request->sort;
        $unique_key->draft_flag = $request->has('draft_flag');
        $unique_key->save();
        $this->saveSubData($unique_key->id, $request);

        \Cahen::move($unique_key)->to('sort', $request->sort);
        return back()->with('success', trans('maven.complete'));

    }

    public function destroy($id) {
        $maven_item = MavenUniqueKey::find($id);
        $maven_item->delete();

        $maven_items = MavenUniqueKey::orderBy('sort')->get();
        \Cahen::align($maven_items, 'sort');

        return back()->with('success', trans('maven.complete'));

    }

    public function locale($locale) {

        Maven::setLocale($locale);
        return redirect()->route('maven.index');

{'fraction_non_alphanumeric': 0.17502759720348338, 'fraction_numerical': 0.0, 'mean_word_length': 2.393258426966292, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 144, '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': '5316675', 'n_tokens_mistral': 2570, 'n_tokens_neox': 2446, 'n_words': 366}