<commit_before><?php

namespace App\Http\Controllers;

use App\Facades\UuidUtils;
use App\Http\Controllers\Controller;
use App\Notifications\RegisteredAccount;
use App\Notifications\UseOfReferralLink;
use App\User;
use App\UserSettingsManager;
use Illuminate\Database\QueryException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class Home extends Controller {

	private $POINTS_FOR_REFERRAL = 5;

	public function chooseAuthProvider(Request $request) {
		$referral = $request->input('referral');

		if ($referral) {
			session(['referral' => $referral]);
		}

		return view('choose-auth-provider');
	}

	public function about() {
		return view('about');
	}

	public function termsAndConditions() {
		return view('tos');
	}

	public function confirm($user_id, $confirm_token) {
		$user = DB::table('users')->where('id', $user_id)->first();

		if (!$user) {
			return view('home', ['error_message' => 'User not found']);
		}

		if ($user->is_confirmed) {
			return view('home', ['error_message' => 'User is already confirmed']);
		}

		if ($user->confirm_token != $confirm_token) {
			return view('home', ['error_message' => 'Confirmation token mismatch']);
		}

		DB::table('users')->where('id', $user_id)->update(['is_confirmed' => true]);

		return view('home', [
			'info_message' => 'User confirmed with success',
		]);
	}

	public function displayLatest(Request $request) {
		return view('home', [
			'reviews' => $this->fetchReviewsOrderBy('requests.created_at'),
		]);
	}

	public function displayTrending(Request $request) {
		return view('hot', [
			'reviews' => $this->fetchReviewsOrderBy('followers'),
		]);

	}

	public function displaySearch() {
		return view('search', [
			'languages' => DB::table('skills')->get(),
		]);
	}

	private function fetchReviewsOrderBy($column) {
		return DB::table('requests')
			->join('users', 'requests.author_id', '=', 'users.id')
			->join('skills', 'requests.skill_id', '=', 'skills.id')
			->select(
				'requests.*',
				DB::raw('(SELECT count(request_tracking.request_id ) FROM request_tracking WHERE request_tracking.request_id = requests.id AND request_tracking.is_active = TRUE) as followers'),
				'users.nickname as author',
				'skills.name as language'
			)
			->where('status', 'open')
			->orderBy($column, 'desc')
			->groupBy('skills.name', 'users.nickname', 'requests.id')
			->paginate(10);
	}

	public function search(Request $request) {
		$search_str     = $request->input('filters.query');
		$languages      = $request->input('filters.languages');
		$include_closed = $request->input('filters.include_closed');

		$reviews = DB::table('requests')
			->join('users', 'requests.author_id', '=', 'users.id')
			->join('skills', 'requests.skill_id', '=', 'skills.id')
			->select(
				'requests.id',
				'requests.name',
				'requests.repository',
				'users.nickname as author',
				'skills.name as language'
			)
			->orderBy('requests.created_at', 'desc')
			->groupBy('skills.name', 'users.nickname', 'requests.id')
			->when(count($languages) > 0, function ($query) use ($languages) {
				return $query->whereIn('skills.id', $languages);
			})
			->when($include_closed == 'false', function ($query) {<commit_msg>Added date and follower count on search<commit_after><?php

namespace App\Http\Controllers;

use App\Facades\UuidUtils;
use App\Http\Controllers\Controller;
use App\Notifications\RegisteredAccount;
use App\Notifications\UseOfReferralLink;
use App\User;
use App\UserSettingsManager;
use Illuminate\Database\QueryException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class Home extends Controller {

	private $POINTS_FOR_REFERRAL = 5;

	public function chooseAuthProvider(Request $request) {
		$referral = $request->input('referral');

		if ($referral) {
			session(['referral' => $referral]);
		}

		return view('choose-auth-provider');
	}

	public function about() {
		return view('about');
	}

	public function termsAndConditions() {
		return view('tos');
	}

	public function confirm($user_id, $confirm_token) {
		$user = DB::table('users')->where('id', $user_id)->first();

		if (!$user) {
			return view('home', ['error_message' => 'User not found']);
		}

		if ($user->is_confirmed) {
			return view('home', ['error_message' => 'User is already confirmed']);
		}

		if ($user->confirm_token != $confirm_token) {
			return view('home', ['error_message' => 'Confirmation token mismatch']);
		}

		DB::table('users')->where('id', $user_id)->update(['is_confirmed' => true]);

		return view('home', [
			'info_message' => 'User confirmed with success',
		]);
	}

	public function displayLatest(Request $request) {
		return view('home', [
			'reviews' => $this->fetchReviewsOrderBy('requests.created_at'),
		]);
	}

	public function displayTrending(Request $request) {
		return view('hot', [
			'reviews' => $this->fetchReviewsOrderBy('followers'),
		]);

	}

	public function displaySearch() {
		return view('search', [
			'languages' => DB::table('skills')->get(),
		]);
	}

	private function fetchReviewsOrderBy($column) {
		return DB::table('requests')
			->join('users', 'requests.author_id', '=', 'users.id')
			->join('skills', 'requests.skill_id', '=', 'skills.id')
			->select(
				'requests.*',
				DB::raw('(SELECT count(request_tracking.request_id ) FROM request_tracking WHERE request_tracking.request_id = requests.id AND request_tracking.is_active = TRUE) as followers'),
				'users.nickname as author',
				'skills.name as language'
			)
			->where('status', 'open')
			->orderBy($column, 'desc')
			->groupBy('skills.name', 'users.nickname', 'requests.id')
			->paginate(10);
	}

	public function search(Request $request) {
		$search_str     = $request->input('filters.query');
		$languages      = $request->input('filters.languages');
		$include_closed = $request->input('filters.include_closed');

		$reviews = DB::table('requests')
			->join('users', 'requests.author_id', '=', 'users.id')
			->join('skills', 'requests.skill_id', '=', 'skills.id')
			->select(
				'requests.id',
				'requests.name',
				'requests.repository',
				'requests.created_at as created_at',
				'users.nickname as author',
				'skills.name as language',
				DB::raw('(SELECT count(request_tracking.request_id ) FROM request_tracking WHERE request_tracking.request_id = requests.id AND request_tracking.is_active = TRUE) as followers')
			)
			->orderBy('requests.created_at', 'desc')
			->groupBy('skills.name', 'users.nickname', 'requests.id')
			->when(count($languages) > 0, function ($query) use ($languages) {
				return $query->whereIn('skills.id', $languages);
			})
			->when($include_closed == 'false', function ($query) {
{'fraction_non_alphanumeric': 0.1803181210049056, 'fraction_numerical': 0.0011892374015162776, 'mean_word_length': 4.711375212224109, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 79, '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': '639708', 'n_tokens_mistral': 2434, 'n_tokens_neox': 2182, 'n_words': 427}