Browse Source

Fixed migrations

jquino 4 years ago
parent
commit
c9ff702b51

+ 0
- 2
app/Course.php View File

24
     }
24
     }
25
 
25
 
26
     public function semesters() {
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
         return $this->belongsToMany(Semester::class, 'sections');
27
         return $this->belongsToMany(Semester::class, 'sections');
30
     }
28
     }
31
 
29
 

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

50
                 'code'          => str_pad($i, 3, '0', STR_PAD_LEFT)
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
     public function getAcademicLoad(Semester $semester) {
37
     public function getAcademicLoad(Semester $semester) {
38
         $prof_sections = $this->sections->where('semester_code', '=', $semester->code);
38
         $prof_sections = $this->sections->where('semester_code', '=', $semester->code);
39
         return $prof_sections->reduce(function ($carry, $section) {
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
         }, 0);
41
         }, 0);
42
     }
42
     }
43
 
43
 

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

20
 
20
 
21
         DB::table('departments')->insert(
21
         DB::table('departments')->insert(
22
             array(
22
             array(
23
-                array('id' => '0','name' => 'default'),
24
                 array('id' => '1','name' => 'BIOL'),
23
                 array('id' => '1','name' => 'BIOL'),
25
                 array('id' => '4','name' => 'CIAM'),
24
                 array('id' => '4','name' => 'CIAM'),
26
                 array('id' => '2','name' => 'FISI'),
25
                 array('id' => '2','name' => 'FISI'),
27
                 array('id' => '3','name' => 'MATE'),
26
                 array('id' => '3','name' => 'MATE'),
28
                 array('id' => '5','name' => 'PGCN'),
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
             $table->bigIncrements('id');
17
             $table->bigIncrements('id');
18
             $table->char('code', 8)->unique();
18
             $table->char('code', 8)->unique();
19
             $table->string('title');
19
             $table->string('title');
20
-            $table->unsignedBigInteger('dept_id');
20
+            $table->unsignedBigInteger('dept_id')->default(7);
21
             $table->string('syllabus')->nullable();
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
 
24
 
25
 
25
 
26
             $table->foreign('semester_code')->references('code')->on('semesters');
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
             $table->unique(['semester_code', 'course_id', 'code']);
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
     {
15
     {
16
         Schema::create('professors', function (Blueprint $table) {
16
         Schema::create('professors', function (Blueprint $table) {
17
             $table->bigIncrements('id');
17
             $table->bigIncrements('id');
18
-            $table->string('num_prof', 16);
18
+            $table->string('num_prof', 16)->unique()->nullable();
19
             $table->string('first_name');
19
             $table->string('first_name');
20
             $table->string('last_name');
20
             $table->string('last_name');
21
             $table->string('system_name')->nullable();
21
             $table->string('system_name')->nullable();
23
             $table->enum('type', ['plantilla', 'contrato', 'ta'])->nullable();
23
             $table->enum('type', ['plantilla', 'contrato', 'ta'])->nullable();
24
             $table->unsignedBigInteger('dept_id')->default(0);
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
             $table->decimal('admin_load')->nullable();
19
             $table->decimal('admin_load')->nullable();
20
             $table->decimal('investigative_load')->nullable();
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
             $table->foreign('semester_code')->references('code')->on('semesters');
23
             $table->foreign('semester_code')->references('code')->on('semesters');
24
 
24
 
25
             $table->unique(['professor_id', 'semester_code']);
25
             $table->unique(['professor_id', 'semester_code']);

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

20
             $table->string('schedule')->nullable();
20
             $table->string('schedule')->nullable();
21
             $table->float('eval')->nullable();
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
             $table->unique(['professor_id', 'section_id']);
26
             $table->unique(['professor_id', 'section_id']);
27
         });
27
         });

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

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

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

57
                                 </tr>
57
                                 </tr>
58
                             </thead>
58
                             </thead>
59
                             <tbody class="mdc-data-table__content">
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
                                     <tr class="mdc-data-table__row">
61
                                     <tr class="mdc-data-table__row">
62
                                         <td class="mdc-data-table__cell" @guest style="display:none;" @endguest>
62
                                         <td class="mdc-data-table__cell" @guest style="display:none;" @endguest>
63
                                             <button class="mdc-icon-button material-icons" data-toggle="modal" data-target="#modal-section-edit" data-section-id="{{ $section->id }}">edit</button>
63
                                             <button class="mdc-icon-button material-icons" data-toggle="modal" data-target="#modal-section-edit" data-section-id="{{ $section->id }}">edit</button>
73
                                         </td>
73
                                         </td>
74
                                         <td class="mdc-data-table__cell">
74
                                         <td class="mdc-data-table__cell">
75
                                             {{-- TODO: Add buton for uploading syllabus if admin --}}
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
                                         </td>
81
                                         </td>
78
                                         <td class="mdc-data-table__cell mdc-data-table__cell--numeric">
82
                                         <td class="mdc-data-table__cell mdc-data-table__cell--numeric">
79
                                             @if (!is_null($section->credits))
83
                                             @if (!is_null($section->credits))

+ 9
- 3
routes/web.php View File

15
     return view('welcome');
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
 // Auth::routes();
28
 // Auth::routes();
23
 
29
 

+ 0
- 1
webpack.mix.js View File

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