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

[WIP] Add student survey #3

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/DTO/StudentData.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function __construct(
public Optional|string|null $emergency_home_phone,
public Optional|string|null $emergency_work_phone,
public Optional|string|null $emergency_mobile,
public Optional|array|null $survey,
) {
}

Expand Down
40 changes: 14 additions & 26 deletions app/Http/Controllers/Questionnaire/Student/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@

use App\DTO\StudentData;
use App\Http\Controllers\Controller;
use App\Models\Student;
use App\Questionnaire\StudentFacade;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Foundation\Application;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;

class DashboardController extends Controller
{
public function __construct(protected StudentFacade $studentFacade)
{

}

public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{
$data = [
Expand All @@ -22,33 +26,17 @@ public function index(): View|Application|Factory|\Illuminate\Contracts\Foundati
return view('questionnaire.student.index', $data);
}

public function updateProfile(Request $request): Application|View|Factory|RedirectResponse|\Illuminate\Contracts\Foundation\Application
public function updateProfile(Request $request)
{
$student = StudentData::authenticatedGuard()->user();
if ($request->method() === 'POST') {
try {
$studentData = StudentData::from($request->all());
Student::query()
->where('id', StudentData::authenticatedGuard()->id())
->update($studentData->toArray());

return redirect()->back()->with('success', 'Profile Updated.');
} catch (\Exception $exception) {
return back()->withErrors(['msg' => $exception->getMessage()])->withInput();
}
$studentData = StudentData::from($request->all());

return $this->studentFacade->postUpdateProfile($studentData, $student);
}
$data = [
'student' => StudentData::authenticatedGuard()->user(),
'titleOptions' => [
['value' => 'mr', 'label' => 'Mr'],
['value' => 'mrs', 'label' => 'Mrs'],
['value' => 'dr', 'label' => 'Dr'],
],
'genderOptions' => [
['value' => 'male', 'label' => 'Male'],
['value' => 'female', 'label' => 'Female'],
['value' => 'other', 'label' => 'Other'],
],
];
$data = $this->studentFacade->getStudentWithFormInputs($student);
$fetchSurveyData = $student->getAttribute('survey');
$data['survey'] = $this->studentFacade->getEnquiryData($fetchSurveyData);

return view('student.update-profile', $data);
}
Expand Down
6 changes: 2 additions & 4 deletions app/Http/Controllers/Questionnaire/Student/ExamController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@

class ExamController extends Controller
{
protected StudentFacade $studentFacade;

public function __construct()
public function __construct(protected StudentFacade $studentFacade)
{
$this->studentFacade = new StudentFacade();

}

public function listAssessments(Request $request, Course $course): Factory|Application|View|\Illuminate\Contracts\Foundation\Application
Expand Down
9 changes: 9 additions & 0 deletions app/Models/Student.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class Student extends \Illuminate\Foundation\Auth\User

protected $hidden = ['password'];

protected $casts = [
'survey' => 'array',
];

protected $appends = ['fullName'];

public function courses(): BelongsToMany
Expand All @@ -35,4 +39,9 @@ public function getFullNameAttribute(): string
{
return sprintf('%s %s', $this->first_name, $this->surname);
}

public function scopeByID($query, $id)
{
return $query->where('id', $id);
}
}
248 changes: 248 additions & 0 deletions app/Questionnaire/StudentFacade.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/View/Components/Form/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function __construct(
public string $label,
public string $name,
public string $id,
public string $cols,
public string $cols = '',
public string $type = 'text',
public string $placeholder = '',
public ?string $value = '',
Expand Down
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"spatie/laravel-honeypot": "^4.0",
"staudenmeir/eloquent-has-many-deep": "^1.7",
"symfony/http-client": "^6.3",
"symfony/mailer": "^6.3",
"ext-zend-opcache": "*"
"symfony/mailer": "^6.3"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.9",
Expand Down Expand Up @@ -57,7 +56,7 @@
},
"scripts": {
"format": [
"./vendor/bin/pint "
"./vendor/bin/pint"
],
"test": [
"./vendor/bin/pest --parallel --group=questionnaire-crud"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function up()
$table->integer('display_order')->default(0);
$table->tinyInteger('status')->default(1);
$table->json('extra')->nullable();
$table->json('survey')->nullable();
$table->timestamps();
});
}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/questionnaire/student/index.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@extends('student.layout.app')
@section('dashboard', 'active')
@section('content')
<div class="main-content pt-lg-4">
<div class="main-content pt-lg-4 ">
<h2 class="m-2 mb-0 d-flex justify-content-between">
<span>My Enrollments</span>
</h2>
Expand Down
101 changes: 94 additions & 7 deletions resources/views/student/update-profile.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
@section('title', 'Update Profile')
@section('update-profile', 'active')
@section('content')
<div class="main-content pt-lg-4">
<h2 class="m-2 mb-0 d-flex justify-content-between">
<div class="main-content pt-lg-4 bg-flat-color-1 ">
<h2 class="m-2 mb-0 d-flex justify-content-between text-white">
<span>Update profile</span>
</h2>
@if(session()->has('success'))
<div class="alert alert-success">
{{ session()->get('success') }}
</div>
@endif
<div class="w-100 h-100 bg-white mx-2 p-2">
<div class="w-100 h-100 bg-white mx-1 p-2">
<form action="{{ route('student.updateProfile') }}" method="POST">
@csrf
<div class="form-row mb-5">
Expand All @@ -38,7 +38,11 @@

</div>
<div class="form-row mb-5">
<h4 class="col-12 mb-2">Contact Information</h4>
<div class="col-12" id="heading">
<h4 class="mb-4 bg-flat-color-1 p-3 text-white">
Contact Information
</h4>
</div>
<x-form.input label="Home Phone" name="home_phone" id="home_phone" type="tel" required="true"
:value="$student['home_phone']"
pattern="[0-9]{10}" cols="col-md-8 col-3"/>
Expand All @@ -55,7 +59,11 @@
required="true" cols="col-md-8 col-3" :value="$student['email']" :readonly="true"/>
</div>
<div class="form-row mb-5">
<h4 class="col-12 mb-2">Address</h4>
<div class="col-12" id="heading">
<h4 class="mb-4 bg-flat-color-1 p-3 text-white">
Address
</h4>
</div>
<x-form.input label="Flat/Unit" name="flat_unit" id="flat_unit" type="text"
:value="$student['flat_unit']" required="true" cols="col-md-8 col-2"/>

Expand All @@ -74,7 +82,11 @@
:value="$student['post_code']"/>
</div>
<div class="form-row mb-5">
<h4 class="col-12 mb-2">Next of kin/emergency contact</h4>
<div class="col-12" id="heading">
<h4 class="mb-4 bg-flat-color-1 p-3 text-white">
Next of kin/emergency contact
</h4>
</div>

<x-form.input label="Name" name="emergency_name" id="emergency_name" type="text"
:value="$student['emergency_name']"
Expand All @@ -96,11 +108,86 @@
required="true" pattern="[0-9]{10}"
:value="$student['emergency_mobile']" cols="col-md-8 col-2"/>
</div>
@isset($survey)
@foreach($survey as $key => $value)
<div class="row">
<div class="col-12" id="heading"><h4
class="mb-4 bg-flat-color-1 p-3 text-white">{{$value['title']}}</h4></div>
@foreach($value['queries'] as $queryKey => $queryValue)
<div class="col-12"><p class="font-weight-bold">{{$queryValue['title']}}</p></div>
<div class="col-12 my-1"><p class="font-italic">{{$queryValue['subtitle']}}</p></div>

<div class="row col-12 m-1">
@if(count($queryValue['choices']) && array_is_list($queryValue['choices']))
@foreach($queryValue['choices'] as $choice)
<div class="form-group form-inline pr-4">
<label class="p-2" for="{{$choice['id']}}">{{$choice['label']}}</label>
<input
class="form-control"
name="{{$choice['name']}}"
id="{{$choice['id']}}"
value="{{$choice['value']}}"
type="{{$choice['type']}}"
@checked($choice['checked'] ?? false)
/>
</div>
@endforeach
@else
@foreach($queryValue['choices'] as $assocKey => $assocChoices)
<div class="col-12 col-md-4 mb-2">
<div
class="row">{{str($assocKey)->replace('__', '/')->replace('_', ' ')->title()->replace('i', 'I')}}</div>
<div class="row form-inline">
@if(count($assocChoices))
@foreach($assocChoices as $assocChoice)
<label class="p-2"
for="{{$assocChoice['id']}}">{{$assocChoice['label']}}</label>
<input
class="form-control mr-3"
name="{{$assocChoice['name']}}"
id="{{$assocChoice['id']}}"
value="{{$assocChoice['value']}}"
type="{{$assocChoice['type']}}"
/>
@endforeach
@endif
</div>
</div>
@endforeach
@endif
</div>
@endforeach
</div>
@endforeach
@endisset
<div>
<x-form.button>Update</x-form.button>
</div>
</form>
</div>
</div>

@endsection
@push('js')
<script>
const setDisplay = (element, value) => element.style.display = value

const countryBornAustraliaEl = document.getElementById('country-born-australia')
const countryBornOtherEl = document.getElementById('country-born-other')
const countryBornSpecifyParentEl = document.getElementById('country-born-specify').parentElement

const speakingLanguageEnglishEl = document.getElementById('speaking-language-english')
const speakingLanguageOtherEl = document.getElementById('speaking-language-other')
const speakingLanguageSpecifyParentEl = document.getElementById('speaking-language-specify').parentElement

setDisplay(countryBornSpecifyParentEl, 'none')
setDisplay(speakingLanguageSpecifyParentEl, 'none')

countryBornOtherEl.addEventListener('change', () => setDisplay(countryBornSpecifyParentEl, 'flex'))
countryBornAustraliaEl.addEventListener('change', () => setDisplay(countryBornSpecifyParentEl, 'none'))

speakingLanguageOtherEl.addEventListener('change', () => setDisplay(speakingLanguageSpecifyParentEl, 'flex'))
speakingLanguageEnglishEl.addEventListener('change', () => setDisplay(speakingLanguageSpecifyParentEl, 'none'))


</script>
@endpush
Loading