Browse Source

Fixed migrations

jquino 4 years ago
parent
commit
c9ff702b51

+ 0
- 2
app/Course.php View File

@@ -24,8 +24,6 @@ class Course extends Model
24 24
     }
25 25
 
26 26
     public function semesters() {
27
-        // dd($this->hasManyThrough(Semester::class, Section::class, 'course_id', 'code'));
28
-        // dd($this->hasManyThrough(Semester::class, Section::class, 'course_id', 'code')->get());
29 27
         return $this->belongsToMany(Semester::class, 'sections');
30 28
     }
31 29
 

+ 1
- 1
app/Http/Controllers/SectionController.php View File

@@ -50,7 +50,7 @@ class SectionController extends Controller
50 50
                 'code'          => str_pad($i, 3, '0', STR_PAD_LEFT)
51 51
             ]);
52 52
         }
53
-        return redirect('/course');
53
+        return redirect()->back();
54 54
     }
55 55
 
56 56
     /**

+ 1
- 1
app/Professor.php View File

@@ -37,7 +37,7 @@ class Professor extends Model
37 37
     public function getAcademicLoad(Semester $semester) {
38 38
         $prof_sections = $this->sections->where('semester_code', '=', $semester->code);
39 39
         return $prof_sections->reduce(function ($carry, $section) {
40
-            return $carry + ($section->pivot->percent ?? 1.0) * (($section->credits ?? 0.0) + $section->extra_credits);
40
+            return $carry + (($section->pivot->percent ?? 100.0) / 100.0) * (($section->credits ?? 0.0) + $section->extra_credits);
41 41
         }, 0);
42 42
     }
43 43
 

+ 2
- 2
database/migrations/2019_07_07_183013_create_departments_table.php View File

@@ -20,13 +20,13 @@ class CreateDepartmentsTable extends Migration
20 20
 
21 21
         DB::table('departments')->insert(
22 22
             array(
23
-                array('id' => '0','name' => 'default'),
24 23
                 array('id' => '1','name' => 'BIOL'),
25 24
                 array('id' => '4','name' => 'CIAM'),
26 25
                 array('id' => '2','name' => 'FISI'),
27 26
                 array('id' => '3','name' => 'MATE'),
28 27
                 array('id' => '5','name' => 'PGCN'),
29
-                array('id' => '6','name' => 'QUIM')
28
+                array('id' => '6','name' => 'QUIM'),
29
+                array('id' => '7','name' => 'default'),
30 30
             ));
31 31
     }
32 32
 

+ 2
- 2
database/migrations/2019_07_07_190000_create_courses_table.php View File

@@ -17,10 +17,10 @@ class CreateCoursesTable extends Migration
17 17
             $table->bigIncrements('id');
18 18
             $table->char('code', 8)->unique();
19 19
             $table->string('title');
20
-            $table->unsignedBigInteger('dept_id');
20
+            $table->unsignedBigInteger('dept_id')->default(7);
21 21
             $table->string('syllabus')->nullable();
22 22
 
23
-            $table->foreign('dept_id')->references('id')->on('departments');
23
+            $table->foreign('dept_id')->references('id')->on('departments')->onUpdate('cascade');
24 24
         });
25 25
     }
26 26
 

+ 1
- 1
database/migrations/2019_07_07_191614_create_sections_table.php View File

@@ -24,7 +24,7 @@ class CreateSectionsTable extends Migration
24 24
 
25 25
 
26 26
             $table->foreign('semester_code')->references('code')->on('semesters');
27
-            $table->foreign('course_id')->references('id')->on('courses');
27
+            $table->foreign('course_id')->references('id')->on('courses')->onUpdate('cascade');
28 28
 
29 29
             $table->unique(['semester_code', 'course_id', 'code']);
30 30
         });

+ 2
- 2
database/migrations/2019_07_07_230040_create_professors_table.php View File

@@ -15,7 +15,7 @@ class CreateProfessorsTable extends Migration
15 15
     {
16 16
         Schema::create('professors', function (Blueprint $table) {
17 17
             $table->bigIncrements('id');
18
-            $table->string('num_prof', 16);
18
+            $table->string('num_prof', 16)->unique()->nullable();
19 19
             $table->string('first_name');
20 20
             $table->string('last_name');
21 21
             $table->string('system_name')->nullable();
@@ -23,7 +23,7 @@ class CreateProfessorsTable extends Migration
23 23
             $table->enum('type', ['plantilla', 'contrato', 'ta'])->nullable();
24 24
             $table->unsignedBigInteger('dept_id')->default(0);
25 25
 
26
-            $table->foreign('dept_id')->references('id')->on('departments');
26
+            $table->foreign('dept_id')->references('id')->on('departments')->onUpdate('cascade');
27 27
         });
28 28
     }
29 29
 

+ 1
- 1
database/migrations/2019_07_07_231850_create_professor_semester_table.php View File

@@ -19,7 +19,7 @@ class CreateProfessorSemesterTable extends Migration
19 19
             $table->decimal('admin_load')->nullable();
20 20
             $table->decimal('investigative_load')->nullable();
21 21
 
22
-            $table->foreign('professor_id')->references('id')->on('professors');
22
+            $table->foreign('professor_id')->references('id')->on('professors')->onUpdate('cascade');
23 23
             $table->foreign('semester_code')->references('code')->on('semesters');
24 24
 
25 25
             $table->unique(['professor_id', 'semester_code']);

+ 2
- 2
database/migrations/2019_07_07_231913_create_professor_section_table.php View File

@@ -20,8 +20,8 @@ class CreateProfessorSectionTable extends Migration
20 20
             $table->string('schedule')->nullable();
21 21
             $table->float('eval')->nullable();
22 22
 
23
-            $table->foreign('professor_id')->references('id')->on('professors');
24
-            $table->foreign('section_id')->references('id')->on('sections');
23
+            $table->foreign('professor_id')->references('id')->on('professors')->onUpdate('cascade');
24
+            $table->foreign('section_id')->references('id')->on('sections')->onDelete('cascade')->onUpdate('cascade');
25 25
 
26 26
             $table->unique(['professor_id', 'section_id']);
27 27
         });

+ 0
- 1
public/mix-manifest.json View File

@@ -2,7 +2,6 @@
2 2
     "/js/app.js": "/js/app.js",
3 3
     "/css/app.css": "/css/app.css",
4 4
     "/js/course.js": "/js/course.js",
5
-    "/js/createPDF.js": "/js/createPDF.js",
6 5
     "/js/dashboard.js": "/js/dashboard.js",
7 6
     "/js/prof.js": "/js/prof.js"
8 7
 }

+ 6
- 2
resources/views/courses/show.blade.php View File

@@ -57,7 +57,7 @@
57 57
                                 </tr>
58 58
                             </thead>
59 59
                             <tbody class="mdc-data-table__content">
60
-                                @foreach ($semester->sections->where('course_id', '=', $course->id) as $section)
60
+                                @foreach ($semester->sections->where('course_id', '=', $course->id)->sortBy('code') as $section)
61 61
                                     <tr class="mdc-data-table__row">
62 62
                                         <td class="mdc-data-table__cell" @guest style="display:none;" @endguest>
63 63
                                             <button class="mdc-icon-button material-icons" data-toggle="modal" data-target="#modal-section-edit" data-section-id="{{ $section->id }}">edit</button>
@@ -73,7 +73,11 @@
73 73
                                         </td>
74 74
                                         <td class="mdc-data-table__cell">
75 75
                                             {{-- TODO: Add buton for uploading syllabus if admin --}}
76
-                                            <a href="{{ $section->syllabus }}">PDF</a>
76
+                                            @if (!is_null($section->syllabus))
77
+                                                <a href="{{ $section->syllabus }}">PDF</a>
78
+                                            @else
79
+                                                n/a
80
+                                            @endif
77 81
                                         </td>
78 82
                                         <td class="mdc-data-table__cell mdc-data-table__cell--numeric">
79 83
                                             @if (!is_null($section->credits))

+ 9
- 3
routes/web.php View File

@@ -15,9 +15,15 @@ Route::get('/', function () {
15 15
     return view('welcome');
16 16
 });
17 17
 
18
-Route::resource('course', 'CourseController');
19
-Route::resource('professor', 'ProfessorController');
20
-Route::resource('section', 'SectionController');
18
+Route::resource('course', 'CourseController')->except([
19
+    'create', 'edit'
20
+]);
21
+Route::resource('professor', 'ProfessorController')->except([
22
+    'create', 'edit'
23
+]);
24
+Route::resource('section', 'SectionController')->only([
25
+    'store', 'update', 'destroy'
26
+]);
21 27
 
22 28
 // Auth::routes();
23 29
 

+ 0
- 1
webpack.mix.js View File

@@ -16,7 +16,6 @@ mix.js('resources/js/app.js', 'public/js')
16 16
     .js('resources/js/prof.js', 'public/js')
17 17
     .js('resources/js/course.js', 'public/js')
18 18
     .js('resources/js/dashboard.js', 'public/js')
19
-    .js('resources/js/createPDF.js', 'public/js')
20 19
     .sass('resources/sass/app.scss', 'public/css', {
21 20
         includePaths: [path.resolve(__dirname, 'node_modules')]
22 21
     });