Skip to content

Commit

Permalink
[CR] add a new field teaching methods into courses table #162 (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
NuwanJ authored Oct 20, 2024
1 parent bf8356a commit 94d5775
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 28 deletions.
4 changes: 3 additions & 1 deletion app/Domains/AcademicProgram/Course/Models/Course.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class Course extends AcademicProgram
'name',
'credits',
'type',
'teaching_methods',
'faq_page',
'content',
'objectives',
'time_allocation',
Expand Down Expand Up @@ -150,4 +152,4 @@ protected static function newFactory()
{
return CourseFactory::new();
}
}
}
5 changes: 5 additions & 0 deletions app/Http/Livewire/Backend/CreateCourses.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class CreateCourses extends Component
public $time_allocation;
public $module_time_allocation;
public $marks_allocation;
public $teaching_methods;

//2nd form step
public $objectives;
Expand All @@ -51,6 +52,7 @@ public function rules()
'code' => 'required|string|unique:courses,code',
'name' => 'required|string|max:255',
'credits' => 'required|integer|min:1|max:18',
'teaching_methods' => 'nullable|string',
'faq_page' => 'nullable|url',
'content' => 'nullable|string',
'time_allocation.lecture' => 'nullable|integer|min:0',
Expand Down Expand Up @@ -103,6 +105,7 @@ protected function validateCurrentStep()
'code' => 'required|string|unique:courses,code',
'name' => 'required|string|max:255',
'credits' => 'required|integer|min:1|max:18',
'teaching_methods' => 'nullable|string',
'faq_page' => 'nullable|url',
'content' => 'nullable|string',
];
Expand Down Expand Up @@ -246,6 +249,7 @@ protected function storeCourse()
'code' => $this->code,
'name' => $this->name,
'credits' => (int)$this->credits,
'teaching_methods' => $this->teaching_methods,
'faq_page' => $this->faq_page,
'content' => $this->content,
'time_allocation' => json_encode($this->time_allocation),
Expand Down Expand Up @@ -296,6 +300,7 @@ protected function resetForm()
$this->code = '';
$this->name = '';
$this->credits = 0;
$this->teaching_methods = '';
$this->faq_page = '';
$this->content = '';
$this->time_allocation = Course::getTimeAllocation();
Expand Down
15 changes: 10 additions & 5 deletions app/Http/Livewire/Backend/EditCourses.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class EditCourses extends Component
public $time_allocation;
public $module_time_allocation;
public $marks_allocation;
public $teaching_methods;

// 2nd form step
public $objectives;
Expand All @@ -46,7 +47,6 @@ class EditCourses extends Component

public function rules()
{

$validationRules = [
'academicProgram' => 'required|string',
'semester' => 'required|int',
Expand All @@ -55,6 +55,7 @@ public function rules()
'code' => 'required|string',
'name' => 'required|string|max:255',
'credits' => 'required|integer|min:1|max:18',
'teaching_methods' => 'nullable|string',
'faq_page' => 'nullable|url',
'content' => 'nullable|string',
'modules' => 'nullable|array',
Expand Down Expand Up @@ -163,6 +164,7 @@ public function mount(Course $course)
$this->code = $course->code;
$this->name = $course->name;
$this->credits = $course->credits;
$this->teaching_methods = $course->teaching_methods;
$this->faq_page = $course->faq_page;
$this->content = $course->content;
$this->time_allocation = array_merge(Course::getTimeAllocation(), json_decode($course->time_allocation, true));
Expand All @@ -180,7 +182,8 @@ public function mount(Course $course)
'time_allocation' => array_merge(Course::getTimeAllocation(), json_decode($module->time_allocation, true))
];
})->toArray();
$this->prerequisites = $course->prerequisites->pluck('id')->toArray();
$this->prerequisites = $course->prerequisites;

// Update semesters list based on academic program and version
$this->updateSemestersList();
}
Expand Down Expand Up @@ -219,7 +222,6 @@ public function previous()
public function update()
{
try {

$this->validateCurrentStep();
$this->updateCourse();
return redirect()->route('dashboard.courses.index')->with('Success', 'Course updated successfully.');
Expand Down Expand Up @@ -268,6 +270,7 @@ protected function updateCourse()
'code' => $this->code,
'name' => $this->name,
'credits' => (int)$this->credits,
'teaching_methods' => $this->teaching_methods,
'faq_page' => $this->faq_page,
'content' => $this->content,
'time_allocation' => json_encode($this->time_allocation),
Expand All @@ -283,7 +286,7 @@ protected function updateCourse()

if (!empty($this->modules)) {
foreach ($this->modules as $module) {
$createdModule = CourseModule::create([
CourseModule::create([
'course_id' => $course->id,
'topic' => $module['name'],
'description' => $module['description'],
Expand All @@ -293,6 +296,7 @@ protected function updateCourse()
]);
}
}

// Sync prerequisites
if (!empty($this->prerequisites)) {
$course->prerequisites()->sync(collect($this->prerequisites)->pluck('id')->toArray());
Expand All @@ -318,6 +322,7 @@ protected function resetForm()
$this->code = '';
$this->name = '';
$this->credits = null;
$this->teaching_methods = '';
$this->faq_page = '';
$this->content = '';
$this->time_allocation = Course::getTimeAllocation();
Expand All @@ -334,4 +339,4 @@ public function render()
{
return view('livewire.backend.edit-courses');
}
}
}
4 changes: 3 additions & 1 deletion database/factories/CourseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public function definition()
'name' => $this->faker->sentence(3),
'credits' => $this->faker->numberBetween(1, 6),
'type' => $this->faker->randomElement(array_keys(Course::getTypes())),
'teaching_methods' => $this->faker->sentence(3),
'faq_page' => $this->faker->url,
'content' => $this->faker->paragraph(),
'objectives' => json_encode([$this->faker->sentence(), $this->faker->sentence()]),
'time_allocation' => json_encode(['lectures' => $this->faker->numberBetween(10, 50), 'practicals' => $this->faker->numberBetween(5, 20)]),
Expand All @@ -45,4 +47,4 @@ public function definition()
'updated_at' => now(),
];
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddFieldTeachingMethods extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('courses', function (Blueprint $table) {
$table->text('teaching_methods')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('courses', function (Blueprint $table) {
$table->dropColumn('teaching_methods');
});
}
}
50 changes: 41 additions & 9 deletions resources/views/livewire/backend/create-courses.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
<h5 class="card-title">Basics</h5>
<div class="basics">
<div class="row" id="row1">

{{-- Academic Program --}}
<div class="col-12 col-sm-6 py-2">
<div class="col ps-0">
<label for="drop1">
Academic Program
Academic Program*
</label>
</div>
<select class="form-select" wire:model="academicProgram">
Expand All @@ -40,9 +42,11 @@
<div class="text-danger">{{ $message }}</div>
@enderror
</div>

{{-- Curriculum --}}
<div class="col-12 col-sm-6 py-2">
<div class="col ps-0">
<label for="drop1">Curriculum</label>
<label for="drop1">Curriculum*</label>
</div>
<select class="form-select" wire:model="version">
<option style="display:none" selected></option>
Expand All @@ -54,9 +58,11 @@
<div class="text-danger">{{ $message }}</div>
@enderror
</div>

{{-- Semester --}}
<div class="col-12 py-2">
<div class="col ps-0">
<label for="drop1">Semester</label>
<label for="drop1">Semester*</label>
</div>
<select class="form-select" wire:model="semester">
<option style="display:none" selected></option>
Expand All @@ -68,9 +74,11 @@
<div class="text-danger">{{ $message }}</div>
@enderror
</div>

{{-- Course Code --}}
<div class="col-12 col-sm-3 py-2">
<div class="col ps-0">
<label>Code</label>
<label>Code*</label>
</div>
<div class="input-group">
<input type="text" class="form-control" wire:model.lazy = "code">
Expand All @@ -79,9 +87,11 @@
<span class="text-danger">{{ $message }}</span>
@enderror
</div>

{{-- Course Name --}}
<div class="col-12 col-sm-9 py-2">
<div class="col ps-0">
<label>Name</label>
<label>Name*</label>
</div>
<div class="input-group">
<input type="text" class="form-control" wire:model.lazy = "name">
Expand All @@ -92,9 +102,10 @@
</div>
</div>
<div class="row" id="row2">
{{-- Course Type --}}
<div class="col-12 col-sm-6 py-2">
<div class="col ps-0">
<label for="drop1">Type</label>
<label for="drop1">Type*</label>
</div>
<select class="form-select" wire:model="type">
<option style="display:none" selected></option>
Expand All @@ -106,9 +117,11 @@
<div class="text-danger">{{ $message }}</div>
@enderror
</div>

{{-- Credits --}}
<div class="col-12 col-sm-6 py-2">
<div class="col ps-0">
<label>Credits</label>
<label>Credits*</label>
</div>
<div class="input-group">
<input type="text" class="form-control" wire:model.lazy ="credits">
Expand All @@ -117,6 +130,22 @@
<span class="text-danger">{{ $message }}</span>
@enderror
</div>

{{-- Teaching Methods --}}
<div class="col-12 py-2">
<div class="col ps-0">
<label>Teaching Methods</label>
</div>
<div class="input-group">
<input type="text" class="form-control"
wire:model.lazy = "teaching_methods">
</div>
@error('teaching_methods')
<div class="text-danger">{{ $message }}</div>
@enderror
</div>

{{-- FAQ Page --}}
<div class="col-12 py-2">
<div class="col ps-0">
<label>FAQ page</label>
Expand All @@ -129,6 +158,8 @@
<div class="text-danger">{{ $message }}</div>
@enderror
</div>

{{-- Content --}}
<div class="my-2" id="contentarea">
<label for="contentTextarea">Content</label>
<textarea class="form-control" id="contentTextarea" wire:model.lazy = "content" rows="3"></textarea>
Expand Down Expand Up @@ -185,7 +216,7 @@
<hr>
</div>

{{-- ILO --}}
{{-- ILOs --}}
@foreach ($ilos as $key => $value)
<div class="mt-5">
@livewire('backend.item-adder', ['type' => $key, 'items' => $ilos[$key]], key("ilos-$key-adder"))
Expand All @@ -201,14 +232,15 @@
<div class="card-body">
<h5 class="card-title">Modules & References</h5>

{{-- Modules --}}
<div class="pb-5">
<x-backend.course_module></x-backend.course_module>
</div>

{{-- References --}}
<div class="pb-5">
@livewire('backend.item-adder', ['type' => 'references', 'items' => $references], key('references-adder'))
</div>

</div>
</div>
</div>
Expand Down
Loading

0 comments on commit 94d5775

Please sign in to comment.