Skip to content

Commit

Permalink
supported potential search feature. (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
elf committed Aug 15, 2019
1 parent 90013a8 commit 3b4e2ed
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 54 deletions.
4 changes: 2 additions & 2 deletions app/Http/Controllers/Admin/InternshipController.php
Expand Up @@ -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,
]);
}
Expand Down
9 changes: 7 additions & 2 deletions app/Http/Controllers/Admin/StudentController.php
Expand Up @@ -60,7 +60,6 @@ public function index(Request $request)
*/
public function create(Request $request)
{
//
$student = new Student;

return view('admin.students.create', [
Expand Down Expand Up @@ -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,
]);
}

/**
Expand Down
26 changes: 26 additions & 0 deletions app/Internship.php
Expand Up @@ -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;
}
}
32 changes: 32 additions & 0 deletions app/Student.php
Expand Up @@ -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;
}

}
3 changes: 3 additions & 0 deletions resources/views/admin/internships/show.blade.php
Expand Up @@ -42,6 +42,9 @@
<dd class="col-md-10">{{ implode(', ', $internship->potential_transportation_codes) }}</dd>
</dl>

<h4>{{ __('Potential Students') }}</h4>
@include('admin.students._table')

<div>
<a href="{{ route('admin.internships.edit', $internship->id) }}" class="btn btn-primary">
{{ __('Edit') }}
Expand Down
50 changes: 50 additions & 0 deletions resources/views/admin/students/_table.blade.php
@@ -0,0 +1,50 @@
<div class="table-responsive">
<table class="table table-sm table-striped">
<thead>
<tr>
<th>{{ __('ID') }}</th>
<th>{{ __('Student ID') }}</th>
<th>{{ __('Name') }}</th>
<th>
{{ __('Email 1') }}
/
{{ __('Phone 1') }}
</th>
<th>{{ __('Period') }}</th>
<th>
{{ __('Programme') }}
/
{{ __('Specialisation') }}
</th>
<th>{{ __('Action') }}</th>
</tr>
</thead>
<tbody>
@foreach ($students as $student)
<tr>
<td><a href="{{ route('admin.students.show', $student->id) }}">{{ $student->id }}</a></td>
<td>{{ $student->code }}</td>
<td>{{ $student->name }}</td>
<td>
<a href="mailto:{{ $student->contact_email1 }}">{{ $student->contact_email1 }}</a><br />
<a href="tel:{{ $student->contact_phone1 }}">{{ $student->contact_phone1 }}</a>
</td>
<td>{{ $student->formatted_enrollment_period }}</td>
<td>
<span title="{{ $student->programme->name }}">{{ $student->programme->code }}</span>
/
<span title="{{ $student->specialisation->name }}">{{ $student->specialisation->code }}</span>
</td>
<td>
<a href="{{ route('admin.students.edit', ['id' => $student->id]) }}" class="btn btn-primary">{{ __('Edit') }}</a>
&nbsp;
@component('components.button-delete')
@slot('route', 'admin.students.destroy')
@slot('id', $student->id)
@endcomponent
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
52 changes: 2 additions & 50 deletions resources/views/admin/students/index.blade.php
Expand Up @@ -55,55 +55,7 @@
</div>
{{ Form::close() }}

<div class="table-responsive">
<table class="table table-sm table-striped">
<thead>
<tr>
<th>{{ __('ID') }}</th>
<th>{{ __('Student ID') }}</th>
<th>{{ __('Name') }}</th>
<th>
{{ __('Email 1') }}
/
{{ __('Phone 1') }}
</th>
<th>{{ __('Period') }}</th>
<th>
{{ __('Programme') }}
/
{{ __('Specialisation') }}
</th>
<th>{{ __('Action') }}</th>
</tr>
</thead>
<tbody>
@foreach ($students as $student)
<tr>
<td><a href="{{ route('admin.students.show', $student->id) }}">{{ $student->id }}</a></td>
<td>{{ $student->code }}</td>
<td>{{ $student->name }}</td>
<td>
<a href="mailto:{{ $student->contact_email1 }}">{{ $student->contact_email1 }}</a><br />
<a href="tel:{{ $student->contact_phone1 }}">{{ $student->contact_phone1 }}</a>
</td>
<td>{{ $student->formatted_enrollment_period }}</td>
<td>
<span title="{{ $student->programme->name }}">{{ $student->programme->code }}</span>
/
<span title="{{ $student->specialisation->name }}">{{ $student->specialisation->code }}</span>
</td>
<td>
<a href="{{ route('admin.students.edit', ['id' => $student->id]) }}" class="btn btn-primary">{{ __('Edit') }}</a>
&nbsp;
@component('components.button-delete')
@slot('route', 'admin.students.destroy')
@slot('id', $student->id)
@endcomponent
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@include('admin.students._table')

</div>
@endsection
3 changes: 3 additions & 0 deletions resources/views/admin/students/show.blade.php
Expand Up @@ -48,6 +48,9 @@
<dd class="col-md-10">{{ implode(', ', $student->potential_transportation_codes) }}</dd>
</dl>

<h4>{{ __('Potential Internships') }}</h4>
@include('admin.internships._table')

<div>
<a href="{{ route('admin.students.edit', ['id' => $student->id]) }}" class="btn btn-primary">
{{ __('Edit') }}
Expand Down

0 comments on commit 3b4e2ed

Please sign in to comment.