<commit_before><?php

namespace App\Http\Controllers;

use App\Activity;
use App\AppointeddUser;
use App\Category;
use App\CategoryForbiddenName;
use App\Comment;
use App\Message;
use App\Notifications\BecameModerator;
use App\Report;
use App\Submission;
use App\Traits\CachableCategory;
use App\Traits\EchoServer;
use App\User;
use App\UserForbiddenName;
use Auth;
use Carbon\Carbon;
use DB;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;

class BackendController extends Controller
{
    use EchoServer, CachableCategory;

    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * shows the forbidden names and usernames page.
     *
     * @return view
     */
    public function forbiddenNames()
    {
        abort_unless($this->mustBeVotenAdministrator(), 403);

        $forbiddenUsernames = UserForbiddenName::paginate(30);

        $forbiddenCategoryNames = CategoryForbiddenName::paginate(30);

        $blockedDomains = \App\BlockedDomain::where('category', 'all')->paginate(30);

        return view('backend.forbidden-names', compact('forbiddenUsernames', 'forbiddenCategoryNames', 'blockedDomains'));
    }

    /**
     * Shows categories.
     *
     * @param Request $request
     *
     * @return \Illuminate\View\View
     */
    public function showCategories(Request $request)
    {
        abort_unless($this->mustBeVotenAdministrator(), 403);

        if ($request->has('filter')) {
            $categories = Category::search($request->filter)->take(20)->get();
        } else {
            $categories = (new Category())->newQuery();

            if ($request->has('sort_by')) {
                if ($request->sort_by == 'subscribers') {
                    $categories->orderBy('subscribers', 'desc');
                } elseif ($request->sort_by == 'submissions_count') {
                    $categories->withCount('submissions')->orderBy('submissions_count', 'desc');
                } elseif ($request->sort_by == 'comments_count') {
                    $categories->withCount('comments')->orderBy('comments_count', 'desc');
                } else {
                    $categories->orderBy('id', 'desc');
                }
            }

            $categories = $categories->paginate(30);
        }

        return view('backend.categories', compact('categories'));
    }

    /**
     * Shows the category page.
     *
     * @return \Illuminate\View\View
     */
    public function showCategory($category)
    {
        abort_unless($this->mustBeVotenAdministrator(), 403);

        $category = Category::where('name', $category)->firstOrFail();<commit_msg>desc sorting for default categories listing<commit_after><?php

namespace App\Http\Controllers;

use App\Activity;
use App\AppointeddUser;
use App\Category;
use App\CategoryForbiddenName;
use App\Comment;
use App\Message;
use App\Notifications\BecameModerator;
use App\Report;
use App\Submission;
use App\Traits\CachableCategory;
use App\Traits\EchoServer;
use App\User;
use App\UserForbiddenName;
use Auth;
use Carbon\Carbon;
use DB;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;

class BackendController extends Controller
{
    use EchoServer, CachableCategory;

    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * shows the forbidden names and usernames page.
     *
     * @return view
     */
    public function forbiddenNames()
    {
        abort_unless($this->mustBeVotenAdministrator(), 403);

        $forbiddenUsernames = UserForbiddenName::paginate(30);

        $forbiddenCategoryNames = CategoryForbiddenName::paginate(30);

        $blockedDomains = \App\BlockedDomain::where('category', 'all')->paginate(30);

        return view('backend.forbidden-names', compact('forbiddenUsernames', 'forbiddenCategoryNames', 'blockedDomains'));
    }

    /**
     * Shows categories.
     *
     * @param Request $request
     *
     * @return \Illuminate\View\View
     */
    public function showCategories(Request $request)
    {
        abort_unless($this->mustBeVotenAdministrator(), 403);

        if ($request->has('filter')) {
            $categories = Category::search($request->filter)->take(20)->get();
        } else {
            $categories = (new Category())->newQuery();

            if ($request->has('sort_by')) {
                if ($request->sort_by == 'subscribers') {
                    $categories->orderBy('subscribers', 'desc');
                } elseif ($request->sort_by == 'submissions_count') {
                    $categories->withCount('submissions')->orderBy('submissions_count', 'desc');
                } elseif ($request->sort_by == 'comments_count') {
                    $categories->withCount('comments')->orderBy('comments_count', 'desc');
                }
            } else {
                $categories->orderBy('id', 'desc');
            }

            $categories = $categories->paginate(30);
        }

        return view('backend.categories', compact('categories'));
    }

    /**
     * Shows the category page.
     *
     * @return \Illuminate\View\View
     */
    public function showCategory($category)
    {
        abort_unless($this->mustBeVotenAdministrator(), 403);

        $category = Category::where('name', $category)->firstOrFail();
{'fraction_non_alphanumeric': 0.1394736842105263, 'fraction_numerical': 0.007142857142857143, 'mean_word_length': 2.700278164116829, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, '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': '2354964', 'n_tokens_mistral': 1566, 'n_tokens_neox': 1519, 'n_words': 276}