Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/course-management-system' into 1…
Browse files Browse the repository at this point in the history
…48-ui-be-make-curriculums-depends-on-the-academic-program-in-frontend
  • Loading branch information
NuwanJ committed Oct 20, 2024
2 parents 8726631 + 94d5775 commit c336825
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 31 deletions.
5 changes: 5 additions & 0 deletions app/Http/Livewire/Backend/CreateCourses.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,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 @@ -53,6 +54,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 @@ -105,6 +107,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 @@ -269,6 +272,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 @@ -319,6 +323,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
23 changes: 18 additions & 5 deletions app/Http/Livewire/Backend/EditCourses.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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 @@ -47,7 +48,6 @@ class EditCourses extends Component

public function rules()
{

$validationRules = [
'academicProgram' => 'required|string',
'semester' => 'required|int',
Expand All @@ -56,6 +56,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 @@ -169,6 +170,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 @@ -186,6 +188,8 @@ public function mount(Course $course)
'time_allocation' => array_merge(Course::getTimeAllocation(), json_decode($module->time_allocation, true))
];
})->toArray();
$this->prerequisites = $course->prerequisites;

$this->prerequisites = $course->prerequisites->pluck('id')->toArray();

// Update semesters list based on academic program and version
Expand Down Expand Up @@ -228,9 +232,15 @@ public function previous()

public function update()
{
$this->validateCurrentStep();
$this->updateCourse();
return redirect()->route('dashboard.courses.index')->with('Success', 'Course updated successfully.');
try {
$this->validateCurrentStep();
$this->updateCourse();
return redirect()->route('dashboard.courses.index')->with('Success', 'Course updated successfully.');
} catch (\Exception $e) {
\Log::error("Error in update method: " . $e->getMessage());
session()->flash('error', 'There was an error updating the course: ' . $e->getMessage());
}
$this->resetForm();
}

public function updatedAcademicProgram()
Expand Down Expand Up @@ -290,6 +300,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 @@ -305,7 +316,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 @@ -315,6 +326,7 @@ protected function updateCourse()
]);
}
}

// Sync prerequisites
if (!empty($this->prerequisites)) {
$course->prerequisites()->sync(collect($this->prerequisites)->pluck('id')->toArray());
Expand All @@ -340,6 +352,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 Down
4 changes: 3 additions & 1 deletion database/factories/CourseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,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 @@ -48,4 +50,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');
});
}
}
61 changes: 48 additions & 13 deletions resources/views/livewire/backend/create-courses.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@
<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="dropAcademicProgram">
Academic Program
</label>
<label for="drop1">
Academic Program*
<label for="dropAcademicProgram">
Academic Program
</label>
</div>
<select id="dropAcademicProgram" name="dropAcademicProgram" class="form-select"
wire:model="academicProgram">
Expand All @@ -41,11 +45,14 @@
<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="dropCurriculum">Curriculum</label>
<label for="dropCurriculum">Curriculum*</label>
</div>
<select id="dropCurriculum" name="dropCurriculum" class="form-select" wire:model="version">
<select id="dropCurriculum" name="dropCurriculum" class="form-select"
wire:model="version">
<option style="display:none" selected></option>
@foreach ($curriculumList as $key => $value)
<option value="{{ $key }}">{{ $value }}</option>
Expand All @@ -55,9 +62,11 @@
<div class="text-danger">{{ $message }}</div>
@enderror
</div>

{{-- Semester --}}
<div class="col-12 py-2">
<div class="col ps-0">
<label for="dropSemester">Semester</label>
<label for="drop1">Semester*</label>
</div>
<select id="dropSemester" name="dropSemester" class="form-select"
wire:model="semester">
Expand All @@ -70,9 +79,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 @@ -81,9 +92,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 @@ -94,11 +107,12 @@
</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="dropType">Type*</label>
</div>
<select class="form-select" wire:model="type">
<select id="dropType" name="dropType" class="form-select" wire:model="type">
<option style="display:none" selected></option>
@foreach (App\Domains\AcademicProgram\Course\Models\Course::getTypes() as $key => $value)
<option value="{{ $key }}">{{ $value }}</option>
Expand All @@ -108,9 +122,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="number" class="form-control" wire:model.lazy ="credits">
Expand All @@ -119,6 +135,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 @@ -131,6 +163,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 @@ -187,7 +221,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 @@ -203,14 +237,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 c336825

Please sign in to comment.