Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: clean unused imports in controllers and extend from control… #376

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 0 additions & 5 deletions app/Http/Controllers/AcademicSettingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How the Controller class will be extended if it is not imported?

use Illuminate\Http\Request;
use App\Traits\SchoolSession;
use App\Interfaces\UserInterface;
use App\Interfaces\CourseInterface;
use App\Interfaces\SectionInterface;
use App\Interfaces\SemesterInterface;
use App\Interfaces\SchoolClassInterface;
use App\Interfaces\SchoolSessionInterface;
use App\Interfaces\AcademicSettingInterface;
use App\Http\Requests\AttendanceTypeUpdateRequest;

class AcademicSettingController extends Controller
{
use SchoolSession;
protected $academicSettingRepository;
protected $schoolSessionRepository;
protected $schoolClassRepository;
protected $schoolSectionRepository;
protected $userRepository;
Expand All @@ -27,7 +24,6 @@ class AcademicSettingController extends Controller

public function __construct(
AcademicSettingInterface $academicSettingRepository,
SchoolSessionInterface $schoolSessionRepository,
SchoolClassInterface $schoolClassRepository,
SectionInterface $schoolSectionRepository,
UserInterface $userRepository,
Expand All @@ -37,7 +33,6 @@ public function __construct(
$this->middleware(['can:view academic settings']);

$this->academicSettingRepository = $academicSettingRepository;
$this->schoolSessionRepository = $schoolSessionRepository;
$this->schoolClassRepository = $schoolClassRepository;
$this->schoolSectionRepository = $schoolSectionRepository;
$this->userRepository = $userRepository;
Expand Down
50 changes: 23 additions & 27 deletions app/Http/Controllers/AssignedTeacherController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;
use App\Traits\SchoolSession;
use App\Interfaces\SemesterInterface;
Expand All @@ -13,18 +15,16 @@
class AssignedTeacherController extends Controller
{
use SchoolSession;
protected $schoolSessionRepository;

protected $semesterRepository;

/**
* Create a new Controller instance
*
*
* @param SchoolSessionInterface $schoolSessionRepository
* @return void
*/
public function __construct(SchoolSessionInterface $schoolSessionRepository,
SemesterInterface $semesterRepository) {
$this->schoolSessionRepository = $schoolSessionRepository;
public function __construct(SemesterInterface $semesterRepository) {
$this->semesterRepository = $semesterRepository;
}
/**
Expand All @@ -38,39 +38,35 @@ public function index()
}

/**
* Display a listing of the resource.
*
* @param CourseStoreRequest $request
* @return \Illuminate\Http\Response
* @param Request $request
* @return Application|Factory|View
*/
public function getTeacherCourses(Request $request)
{
$teacher_id = $request->query('teacher_id');
$semester_id = $request->query('semester_id');
$courses = [];
$teacherId = $request->query('teacher_id');
$semesterId = $request->query('semester_id');

if($teacher_id == null) {
if (is_null($teacherId)) {
abort(404);
}

$current_school_session_id = $this->getSchoolCurrentSession();

$semesters = $this->semesterRepository->getAll($current_school_session_id);
$currentSchoolSessionId = $this->getSchoolCurrentSession();

$semesters = $this->semesterRepository->getAll($currentSchoolSessionId);

$assignedTeacherRepository = new AssignedTeacherRepository();

if($semester_id == null) {
$courses = [];
} else {
$courses = $assignedTeacherRepository->getTeacherCourses($current_school_session_id, $teacher_id, $semester_id);
if (!is_null($semesterId)) {
$courses = $assignedTeacherRepository->getTeacherCourses($currentSchoolSessionId, $teacherId, $semesterId);
}

$data = [
'courses' => $courses,
'semesters' => $semesters,
'selected_semester_id' => $semester_id,
];

return view('courses.teacher', $data);
return view('courses.teacher')
->with([
'courses' => $courses,
'semesters' => $semesters,
'selected_semester_id' => $semesterId
]);
}

/**
Expand Down
25 changes: 7 additions & 18 deletions app/Http/Controllers/AssignmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,44 @@

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Models\Assignment;
use Illuminate\Http\Request;
use App\Traits\SchoolSession;
use App\Http\Requests\StoreFileRequest;
use App\Interfaces\SchoolSessionInterface;
use App\Repositories\AssignmentRepository;

class AssignmentController extends Controller
{
use SchoolSession;
protected $schoolSessionRepository;

/**
* Create a new Controller instance
*
* @param CourseInterface $schoolCourseRepository
* @return void
*/
public function __construct(SchoolSessionInterface $schoolSessionRepository) {
$this->schoolSessionRepository = $schoolSessionRepository;
}

/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function getCourseAssignments(Request $request)
{
$course_id = $request->query('course_id', 0);
$current_school_session_id = $this->getSchoolCurrentSession();
$courseId = $request->query('course_id', 0);
$currentSchoolSessionId = $this->getSchoolCurrentSession();
$assignmentRepository = new AssignmentRepository();
$assignments = $assignmentRepository->getAssignments($current_school_session_id, $course_id);
$assignments = $assignmentRepository->getAssignments($currentSchoolSessionId, $courseId);
$data = [
'assignments' => $assignments,
];
return view('assignments.index', $data);
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create(Request $request)
{
$current_school_session_id = $this->getSchoolCurrentSession();
$currentSchoolSessionId = $this->getSchoolCurrentSession();
$data = [
'current_school_session_id' => $current_school_session_id,
'current_school_session_id' => $currentSchoolSessionId,
'class_id' => $request->query('class_id', 0),
'section_id' => $request->query('section_id', 0),
'course_id' => $request->query('course_id', 0),
Expand Down
8 changes: 3 additions & 5 deletions app/Http/Controllers/AttendanceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Models\Attendance;
use Illuminate\Http\Request;
use App\Interfaces\UserInterface;
use App\Interfaces\SchoolClassInterface;
Expand All @@ -12,12 +10,12 @@
use App\Http\Requests\AttendanceStoreRequest;
use App\Interfaces\SectionInterface;
use App\Repositories\AttendanceRepository;
use App\Repositories\CourseRepository;
use App\Traits\SchoolSession;

class AttendanceController extends Controller
{
use SchoolSession;

protected $academicSettingRepository;
protected $schoolSessionRepository;
protected $schoolClassRepository;
Expand Down Expand Up @@ -66,7 +64,7 @@ public function index()

/**
* Show the form for creating a new resource.
*
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
Expand Down Expand Up @@ -157,7 +155,7 @@ public function show(Request $request)
$attendances = $attendanceRepository->getCourseAttendance($class_id, $course_id, $current_school_session_id);
}
$data = ['attendances' => $attendances];

return view('attendances.view', $data);
} catch (\Exception $e) {
return back()->withError($e->getMessage());
Expand Down
7 changes: 7 additions & 0 deletions app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers;

use App\Interfaces\SchoolSessionInterface;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
Expand All @@ -10,4 +11,10 @@
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

protected $schoolSession;

protected function __construct(SchoolSessionInterface $schoolSession) {
$this->schoolSession = $schoolSession;
}
}
9 changes: 3 additions & 6 deletions app/Http/Controllers/CourseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,26 @@

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Models\Course;
use Illuminate\Http\Request;
use App\Traits\SchoolSession;
use App\Interfaces\CourseInterface;
use App\Http\Requests\CourseStoreRequest;
use App\Interfaces\SchoolSessionInterface;
use App\Repositories\PromotionRepository;

class CourseController extends Controller
{
use SchoolSession;

protected $schoolCourseRepository;
protected $schoolSessionRepository;


/**
* Create a new Controller instance
*
* @param CourseInterface $schoolCourseRepository
* @return void
*/
public function __construct(SchoolSessionInterface $schoolSessionRepository, CourseInterface $schoolCourseRepository) {
$this->schoolSessionRepository = $schoolSessionRepository;
public function __construct(CourseInterface $schoolCourseRepository) {
$this->schoolCourseRepository = $schoolCourseRepository;
}

Expand Down
20 changes: 7 additions & 13 deletions app/Http/Controllers/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Models\Event;
use Illuminate\Http\Request;
use App\Traits\SchoolSession;
use App\Interfaces\SchoolSessionInterface;

class EventController extends Controller
{
use SchoolSession;
protected $schoolSessionRepository;

public function __construct(SchoolSessionInterface $schoolSessionRepository) {
$this->schoolSessionRepository = $schoolSessionRepository;
}
/**
* Display a listing of the resource.
*
Expand All @@ -24,11 +18,11 @@ public function __construct(SchoolSessionInterface $schoolSessionRepository) {
public function index(Request $request)
{
if($request->ajax()) {
$current_school_session_id = $this->getSchoolCurrentSession();
$currentSchoolSessionId = $this->getSchoolCurrentSession();

$data = Event::whereDate('start', '>=', $request->start)
->whereDate('end', '<=', $request->end)
->where('session_id', $current_school_session_id)
->where('session_id', $currentSchoolSessionId)
->get(['id', 'title', 'start', 'end']);
return response()->json($data);
}
Expand All @@ -37,30 +31,30 @@ public function index(Request $request)

public function calendarEvents(Request $request)
{
$current_school_session_id = $this->getSchoolCurrentSession();
$currentSchoolSessionId = $this->getSchoolCurrentSession();
$event = null;
switch ($request->type) {
case 'create':
$event = Event::create([
'title' => $request->title,
'start' => $request->start,
'end' => $request->end,
'session_id' => $current_school_session_id
'session_id' => $currentSchoolSessionId
]);
break;

case 'edit':
$event = Event::find($request->id)->update([
'title' => $request->title,
'start' => $request->start,
'end' => $request->end,
]);
break;

case 'delete':
$event = Event::find($request->id)->delete();
break;

default:
break;
}
Expand Down