From 3b4e2ed5d3815e2b2f55e0d84fd28bd81b65e99d Mon Sep 17 00:00:00 2001 From: Tadashi Jokagi Date: Thu, 15 Aug 2019 17:10:11 +0000 Subject: [PATCH] supported potential search feature. (#3) --- .../Admin/InternshipController.php | 4 +- .../Controllers/Admin/StudentController.php | 9 +++- app/Internship.php | 26 ++++++++++ app/Student.php | 32 ++++++++++++ .../views/admin/internships/show.blade.php | 3 ++ .../views/admin/students/_table.blade.php | 50 ++++++++++++++++++ .../views/admin/students/index.blade.php | 52 +------------------ resources/views/admin/students/show.blade.php | 3 ++ 8 files changed, 125 insertions(+), 54 deletions(-) create mode 100644 resources/views/admin/students/_table.blade.php diff --git a/app/Http/Controllers/Admin/InternshipController.php b/app/Http/Controllers/Admin/InternshipController.php index ad885bb..0589101 100644 --- a/app/Http/Controllers/Admin/InternshipController.php +++ b/app/Http/Controllers/Admin/InternshipController.php @@ -162,10 +162,10 @@ public function store(Request $request) */ public function show(Internship $internship) { - //$students = Student::findByInternshipPotentials($internship); + $students = \App\Student::getByInternship($internship); return view('admin.internships.show', [ - //'students' => $students, + 'students' => $students, 'internship' => $internship, ]); } diff --git a/app/Http/Controllers/Admin/StudentController.php b/app/Http/Controllers/Admin/StudentController.php index 8bbdd2c..1ee99ed 100644 --- a/app/Http/Controllers/Admin/StudentController.php +++ b/app/Http/Controllers/Admin/StudentController.php @@ -60,7 +60,6 @@ public function index(Request $request) */ public function create(Request $request) { - // $student = new Student; return view('admin.students.create', [ @@ -134,7 +133,13 @@ public function store(Request $request) */ public function show(Student $student) { - return view('admin.students.show', ['student' => $student]); + $internships = \App\Internship::getByStudent($student); + + return view('admin.students.show', [ + 'student' => $student, + 'files' => $student->files()->get(), + 'internships' => $internships, + ]); } /** diff --git a/app/Internship.php b/app/Internship.php index 836bb2c..55ca33d 100644 --- a/app/Internship.php +++ b/app/Internship.php @@ -54,4 +54,30 @@ public function supervisor() return $this->belongsTo('App\Supervisor'); } + public static function getByStudent(\App\Student $student) + { + return self::getQueryByStudent($student)->get(); + } + + public static function getQueryByStudent(\App\student $student) + { + $q = self::getQueryByPotentials($student->potentials); + + return $q; + } + + public static function getByPotentials(array $potentials) + { + return self::getQueryByPotentials($potentials)->get(); + } + + public static function getQueryByPotentials(array $potentials) + { + $q = self::query() + ->whereJsonContains('potentials->area_cores', $potentials['area_codes']) + ->whereJsonContains('potentials->specialisation_codes', $potentials['specialisation_codes'], 'OR') + ->whereJsonContains('potentials->transportation_codes', $potentials['transportation_codes'], 'OR') + ; + return $q; + } } diff --git a/app/Student.php b/app/Student.php index 4bc774c..9477013 100644 --- a/app/Student.php +++ b/app/Student.php @@ -40,4 +40,36 @@ public function getEnrollmentFinishAttribute() return $this->getCodeName('semesters', $this->enrollment_finish_code); } + public function files() + { + return $this->belongsToMany(\App\File::class, 'student_files'); + } + + public static function getByInternship(\App\Internship $internship) + { + return self::getQueryByInternship($internship)->get(); + } + + public static function getQueryByInternship(\App\Internship $internship) + { + $q = self::getQueryByPotentials($internship->potentials); + + return $q; + } + + public static function getByPotentials(array $potentials) + { + return self::getQueryByPotentials($potentials)->get(); + } + + public static function getQueryByPotentials(array $potentials) + { + $q = self::query() + ->whereJsonContains('potentials->area_cores', $potentials['area_codes']) + ->whereJsonContains('potentials->specialisation_codes', $potentials['specialisation_codes'], 'OR') + ->whereJsonContains('potentials->transportation_codes', $potentials['transportation_codes'], 'OR') + ; + return $q; + } + } diff --git a/resources/views/admin/internships/show.blade.php b/resources/views/admin/internships/show.blade.php index 2bfeff4..b667dc2 100644 --- a/resources/views/admin/internships/show.blade.php +++ b/resources/views/admin/internships/show.blade.php @@ -42,6 +42,9 @@
{{ implode(', ', $internship->potential_transportation_codes) }}
+

{{ __('Potential Students') }}

+ @include('admin.students._table') +
{{ __('Edit') }} diff --git a/resources/views/admin/students/_table.blade.php b/resources/views/admin/students/_table.blade.php new file mode 100644 index 0000000..d3128c9 --- /dev/null +++ b/resources/views/admin/students/_table.blade.php @@ -0,0 +1,50 @@ +
+ + + + + + + + + + + + + + @foreach ($students as $student) + + + + + + + + + + @endforeach + +
{{ __('ID') }}{{ __('Student ID') }}{{ __('Name') }} + {{ __('Email 1') }} + / + {{ __('Phone 1') }} + {{ __('Period') }} + {{ __('Programme') }} + / + {{ __('Specialisation') }} + {{ __('Action') }}
{{ $student->id }}{{ $student->code }}{{ $student->name }} + {{ $student->contact_email1 }}
+ {{ $student->contact_phone1 }} +
{{ $student->formatted_enrollment_period }} + {{ $student->programme->code }} + / + {{ $student->specialisation->code }} + + {{ __('Edit') }} +   + @component('components.button-delete') + @slot('route', 'admin.students.destroy') + @slot('id', $student->id) + @endcomponent +
+
diff --git a/resources/views/admin/students/index.blade.php b/resources/views/admin/students/index.blade.php index 2c3506f..ba7da85 100644 --- a/resources/views/admin/students/index.blade.php +++ b/resources/views/admin/students/index.blade.php @@ -55,55 +55,7 @@
{{ Form::close() }} -
- - - - - - - - - - - - - - @foreach ($students as $student) - - - - - - - - - - @endforeach - -
{{ __('ID') }}{{ __('Student ID') }}{{ __('Name') }} - {{ __('Email 1') }} - / - {{ __('Phone 1') }} - {{ __('Period') }} - {{ __('Programme') }} - / - {{ __('Specialisation') }} - {{ __('Action') }}
{{ $student->id }}{{ $student->code }}{{ $student->name }} - {{ $student->contact_email1 }}
- {{ $student->contact_phone1 }} -
{{ $student->formatted_enrollment_period }} - {{ $student->programme->code }} - / - {{ $student->specialisation->code }} - - {{ __('Edit') }} -   - @component('components.button-delete') - @slot('route', 'admin.students.destroy') - @slot('id', $student->id) - @endcomponent -
-
+ @include('admin.students._table') + @endsection diff --git a/resources/views/admin/students/show.blade.php b/resources/views/admin/students/show.blade.php index f45b366..a7df17a 100644 --- a/resources/views/admin/students/show.blade.php +++ b/resources/views/admin/students/show.blade.php @@ -48,6 +48,9 @@
{{ implode(', ', $student->potential_transportation_codes) }}
+

{{ __('Potential Internships') }}

+ @include('admin.internships._table') +
{{ __('Edit') }}