From 94d5775169b74ce0698ecc9a3289d25e68834865 Mon Sep 17 00:00:00 2001 From: Nuwan Jaliyagoda Date: Sun, 20 Oct 2024 22:43:05 +0530 Subject: [PATCH] [CR] add a new field teaching methods into courses table #162 (#190) --- .../AcademicProgram/Course/Models/Course.php | 4 +- app/Http/Livewire/Backend/CreateCourses.php | 5 ++ app/Http/Livewire/Backend/EditCourses.php | 15 +++-- database/factories/CourseFactory.php | 4 +- ...0_10_103420_add-field-teaching-methods.php | 32 ++++++++++ .../livewire/backend/create-courses.blade.php | 50 +++++++++++++--- .../livewire/backend/edit-courses.blade.php | 60 +++++++++++++++---- 7 files changed, 142 insertions(+), 28 deletions(-) create mode 100644 database/migrations/2024_10_10_103420_add-field-teaching-methods.php diff --git a/app/Domains/AcademicProgram/Course/Models/Course.php b/app/Domains/AcademicProgram/Course/Models/Course.php index 1ec81d71..bd723e51 100644 --- a/app/Domains/AcademicProgram/Course/Models/Course.php +++ b/app/Domains/AcademicProgram/Course/Models/Course.php @@ -36,6 +36,8 @@ class Course extends AcademicProgram 'name', 'credits', 'type', + 'teaching_methods', + 'faq_page', 'content', 'objectives', 'time_allocation', @@ -150,4 +152,4 @@ protected static function newFactory() { return CourseFactory::new(); } -} \ No newline at end of file +} diff --git a/app/Http/Livewire/Backend/CreateCourses.php b/app/Http/Livewire/Backend/CreateCourses.php index f544b1fa..7e093989 100644 --- a/app/Http/Livewire/Backend/CreateCourses.php +++ b/app/Http/Livewire/Backend/CreateCourses.php @@ -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; @@ -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', @@ -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', ]; @@ -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), @@ -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(); diff --git a/app/Http/Livewire/Backend/EditCourses.php b/app/Http/Livewire/Backend/EditCourses.php index 0409f61c..71244dea 100644 --- a/app/Http/Livewire/Backend/EditCourses.php +++ b/app/Http/Livewire/Backend/EditCourses.php @@ -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; @@ -46,7 +47,6 @@ class EditCourses extends Component public function rules() { - $validationRules = [ 'academicProgram' => 'required|string', 'semester' => 'required|int', @@ -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', @@ -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)); @@ -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(); } @@ -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.'); @@ -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), @@ -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'], @@ -293,6 +296,7 @@ protected function updateCourse() ]); } } + // Sync prerequisites if (!empty($this->prerequisites)) { $course->prerequisites()->sync(collect($this->prerequisites)->pluck('id')->toArray()); @@ -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(); @@ -334,4 +339,4 @@ public function render() { return view('livewire.backend.edit-courses'); } -} \ No newline at end of file +} diff --git a/database/factories/CourseFactory.php b/database/factories/CourseFactory.php index 1d223f87..ababdbd1 100644 --- a/database/factories/CourseFactory.php +++ b/database/factories/CourseFactory.php @@ -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)]), @@ -45,4 +47,4 @@ public function definition() 'updated_at' => now(), ]; } -} +} \ No newline at end of file diff --git a/database/migrations/2024_10_10_103420_add-field-teaching-methods.php b/database/migrations/2024_10_10_103420_add-field-teaching-methods.php new file mode 100644 index 00000000..b8b7e56e --- /dev/null +++ b/database/migrations/2024_10_10_103420_add-field-teaching-methods.php @@ -0,0 +1,32 @@ +text('teaching_methods')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('courses', function (Blueprint $table) { + $table->dropColumn('teaching_methods'); + }); + } +} diff --git a/resources/views/livewire/backend/create-courses.blade.php b/resources/views/livewire/backend/create-courses.blade.php index 56c8bbe7..bd89fa43 100644 --- a/resources/views/livewire/backend/create-courses.blade.php +++ b/resources/views/livewire/backend/create-courses.blade.php @@ -23,10 +23,12 @@
Basics
+ + {{-- Academic Program --}}
@@ -54,9 +58,11 @@
{{ $message }}
@enderror
+ + {{-- Semester --}}
- +
@@ -79,9 +87,11 @@ {{ $message }} @enderror
+ + {{-- Course Name --}}
- +
@@ -92,9 +102,10 @@
+ {{-- Course Type --}}
- +
@@ -117,6 +130,22 @@ {{ $message }} @enderror
+ + {{-- Teaching Methods --}} +
+
+ +
+
+ +
+ @error('teaching_methods') +
{{ $message }}
+ @enderror +
+ + {{-- FAQ Page --}}
@@ -129,6 +158,8 @@
{{ $message }}
@enderror
+ + {{-- Content --}}
@@ -185,7 +216,7 @@
- {{-- ILO --}} + {{-- ILOs --}} @foreach ($ilos as $key => $value)
@livewire('backend.item-adder', ['type' => $key, 'items' => $ilos[$key]], key("ilos-$key-adder")) @@ -201,14 +232,15 @@
Modules & References
+ {{-- Modules --}}
+ {{-- References --}}
@livewire('backend.item-adder', ['type' => 'references', 'items' => $references], key('references-adder'))
-
diff --git a/resources/views/livewire/backend/edit-courses.blade.php b/resources/views/livewire/backend/edit-courses.blade.php index 44c2db67..49514bea 100644 --- a/resources/views/livewire/backend/edit-courses.blade.php +++ b/resources/views/livewire/backend/edit-courses.blade.php @@ -23,10 +23,12 @@
Basics
+ + {{-- Academic Program --}}
@@ -54,9 +58,11 @@
{{ $message }}
@enderror
+ + {{-- Semester --}}
- +
@@ -79,9 +87,11 @@ {{ $message }} @enderror
+ + {{-- Course Name --}}
- +
@@ -93,9 +103,10 @@
+ {{-- Course Type --}}
- +
@@ -118,6 +131,22 @@ {{ $message }} @enderror
+ + {{-- Teaching Methods --}} +
+
+ +
+
+ +
+ @error('teaching_methods') +
{{ $message }}
+ @enderror +
+ + {{-- FAQ Page --}}
@@ -130,6 +159,8 @@
{{ $message }}
@enderror
+ + {{-- Content --}}
@@ -159,7 +190,6 @@
- {{-- objectives --}}
{!! Form::textarea('objectives', '', [ @@ -189,7 +219,7 @@
- {{-- ILO --}} + {{-- ILOs --}} @foreach ($ilos as $key => $value)
@livewire('backend.item-adder', ['type' => $key, 'items' => $ilos[$key]], key("ilos-$key-adder")) @@ -205,9 +235,15 @@
Modules & References
- -
- @livewire('backend.item-adder', ['type' => 'references', 'items' => $references], key('references-adder')) + {{-- Modules --}} +
+ +
+ + {{-- References --}} +
+ @livewire('backend.item-adder', ['type' => 'references', 'items' => $references], key('references-adder')) +