diff --git a/app/Domains/AcademicProgram/Course/Models/Course.php b/app/Domains/AcademicProgram/Course/Models/Course.php index 1ec81d7..bd723e5 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 f544b1f..7e09398 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 0409f61..71244de 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 1d223f8..ababdbd 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 0000000..b8b7e56 --- /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 56c8bbe..bd89fa4 100644 --- a/resources/views/livewire/backend/create-courses.blade.php +++ b/resources/views/livewire/backend/create-courses.blade.php @@ -23,10 +23,12 @@