parent
commit
eff7fc67a6
4 changed files with 364 additions and 82 deletions
  1. 1
    0
      .gitignore
  2. 154
    57
      app/controllers/CoursesController.php
  3. 3
    0
      app/routes.php
  4. 206
    25
      app/views/local/managers/shared/course_edit.blade.php

+ 1
- 0
.gitignore View File

@@ -23,3 +23,4 @@ vendor/*
23 23
 app/controllers/AuthController.php
24 24
 app/controllers/AuthController.php
25 25
 bootstrap/start.php
26
+testdisk.log

+ 154
- 57
app/controllers/CoursesController.php View File

@@ -1,6 +1,7 @@
1 1
 <?php
2 2
 
3 3
 use Illuminate\Support\Facades\Log;
4
+use Illuminate\Support\Facades\Redirect;
4 5
 
5 6
 class
6 7
 CoursesController extends \BaseController
@@ -83,6 +84,13 @@ CoursesController extends \BaseController
83 84
         return View::make('local.managers.shared.course_edit', compact('title', 'programs', 'professors', 'modalities', 'semesters'));
84 85
     }
85 86
 
87
+    public function fetchCourses()
88
+    {
89
+        return Course::where('program_id', Input::get('program_id'))
90
+            ->where('semester_id', Input::get('semester_id'))
91
+            ->get();
92
+    }
93
+
86 94
     public function create()
87 95
     {
88 96
 
@@ -120,18 +128,32 @@ CoursesController extends \BaseController
120 128
         if ($course->save()) {
121 129
 
122 130
             //$students->move('./course_student', 'test.txt');
123
-            $student_nums = file(Input::file('students'));
131
+
132
+            if (Input::file('students') != '') {
133
+                $student_nums = file(Input::file('students'));
134
+            } else {
135
+                $student_nums = false;
136
+            }
137
+
138
+
139
+
140
+
141
+            //para la validación. Si se encuentra un numero de estudiante incorrecto, 
142
+            //set stu_not_found = true, 
143
+
144
+            $stu_not_found = false;
145
+            $stu_nf_list =  [];
124 146
 
125 147
             if ($student_nums) {
126 148
                 foreach ($student_nums as $stu_num) {
127
-                    Log::info($stu_num);
128
-                    Log::info("Stunum");
149
+                    //Log::info($stu_num);
150
+                    //Log::info("Stunum");
129 151
                     $student_id = DB::select("select id from students where number = " . $stu_num);
130 152
                     /*DB::table("students")
131 153
                         ->where('number', '=', $stu_num)
132 154
                         ->first();
133 155
                     */
134
-                    if ($student_id) {
156
+                    if (count($student_id)) {
135 157
                         $student_id = $student_id[0]->id;
136 158
                         DB::table("course_student")
137 159
                             ->insert(array(
@@ -140,85 +162,160 @@ CoursesController extends \BaseController
140 162
                                 'semester_id' => $course->semester_id
141 163
                             ));
142 164
                     } else {
143
-                        $course->forceDelete();
144
-                        Session::flash('status', 'danger');
145
-                        Session::flash('message', '<p>Error Enrolling students. Please try again later.</p>');
146
-                        return Redirect::to('editCourses')->withInput();
165
+
166
+                        $stu_not_found = true;
167
+                        $stu_nf_list[] = $stu_num;
168
+
169
+
170
+
171
+                        //$course->forceDelete();
172
+                        //Session::flash('status', 'danger');
173
+                        //Session::flash('message', '<p>Error Enrolling students. Please try again later.</p>');
174
+                        //return Redirect::to('editCourses')->withInput();
147 175
                     }
148 176
                 }
149
-
150 177
                 Session::flash('status', 'success');
151 178
                 Session::flash('message', 'Course created: "' . $course->name . '".');
152
-                return Redirect::to('editCourses');
179
+                if ($stu_not_found) {
180
+
181
+                    $error_msg = "<ul>";
182
+
183
+                    foreach ($stu_nf_list as $stu_num) {
184
+                        $error_msg .= "<li>" . $stu_num . "</li>";
185
+                    }
186
+                    $error_msg .= "</ul>";
187
+
188
+                    Session::flash('status', 'warning');
189
+                    Session::flash('message', '<p>Error Enrolling students these students</p>' . $error_msg .
190
+                        '<p>But course ' . $course->name . ' was created</p>');
191
+                    //return Redirect::to('editCourses')->withInput();
192
+                }
193
+
194
+
195
+                return Redirect::to('editCourses')->withInput();
153 196
 
154 197
 
155 198
 
156 199
                 //fclose($student_nums);
157 200
             } else {
158
-                $course->forceDelete();
159
-                Session::flash('status', 'danger');
160
-                Session::flash('message', '<p>Error creating course. Please try again later.</p>');
201
+
202
+                Session::flash('status', 'Warning');
203
+                Session::flash('message', '<p>Course ' . $course->name . ' created  but no student enrolled.</p>');
161 204
                 return Redirect::to('editCourses')->withInput();
162 205
             }
163
-            /*$objectiveId = $objective->id;
206
+        }
164 207
 
165
-            Log::info($clean_input['outcome_id']);
208
+        /** If saving fails, send error message and old data */
209
+        else {
210
+            Session::flash('status', 'danger');
211
+            Session::flash('message', '<p>Error creating course. Please try again later.</p>');
212
+            return Redirect::to('editCourses')->withInput();
213
+        }
214
+    }
166 215
 
216
+    public function updateCourseInfo()
217
+    {
167 218
 
219
+        $all_info = Input::all();
220
+        $course = Course::findOrFail($all_info['select-course']);
221
+        $course->name = $all_info['name'];
222
+        $course->code = $all_info['code'];
223
+        $course->section = $all_info['section'];
224
+        $course->number = $all_info['number'];
225
+        $course->program_id = $all_info['program'];
226
+        $course->user_id = $all_info['professor_id'];
227
+        $course->semester_id = $all_info['semester_id'];
228
+        $course->modality = $all_info['modality'];
168 229
 
230
+        if ($course->save()) {
169 231
 
170
-            foreach ($clean_input['program_id'] as $program_id) {
171
-                DB::insert("insert into objective_program (objective_id, program_id) values({$objectiveId},{$program_id})");
232
+            if (Input::file('students') != '') {
233
+                $student_nums = file(Input::file('students'));
234
+            } else {
235
+                $student_nums = false;
172 236
             }
173
-            foreach ($clean_input['outcome_id'] as $outcome_id) {
174
-                DB::insert("insert into `objective_outcome` (objective_id, outcome_id) values ({$objectiveId}, {$outcome_id})");
175
-                //DB::raw("insert ignore into `objective_outcome` (objective_id, outcome_id) values ({$objectiveId}, {$outcome_id})");
176
-                /*if (!($objectiveOutcome->save())) {
177
-                    Session::flash('status', 'danger');
178
-                    Session::flash('message', '<p>Error creating objective. Please try again later.</p>');
179
-                    return Redirect::to('objective')->withInput();
237
+            //para la validación. Si se encuentra un numero de estudiante incorrecto, 
238
+            //set stu_not_found = true, 
239
+
240
+            $stu_not_found = false;
241
+            $stu_nf_list =  [];
242
+
243
+            if ($student_nums) {
244
+                foreach ($student_nums as $stu_num) {
245
+
246
+                    $if_stu_matriculado = DB::table('course_student')
247
+                        ->where('student_id', $stu_num)
248
+                        ->where('course_id', $course->id)
249
+                        ->first();
250
+
251
+                    //si está matriculado, pichea.
252
+                    if ($if_stu_matriculado) {
253
+                        continue;
254
+                    }
255
+                    $student_id = DB::select("select id from students where number = " . $stu_num);
256
+
257
+                    if (count($student_id)) {
258
+                        $student_id = $student_id[0]->id;
259
+                        DB::table("course_student")
260
+                            ->insert(array(
261
+                                'course_id' => $course->id,
262
+                                'student_id' => $student_id,
263
+                                'semester_id' => $course->semester_id
264
+                            ));
265
+                    } else {
266
+
267
+                        $stu_not_found = true;
268
+                        $stu_nf_list[] = $stu_num;
269
+
270
+
271
+
272
+                        //$course->forceDelete();
273
+                        //Session::flash('status', 'danger');
274
+                        //Session::flash('message', '<p>Error Enrolling students. Please try again later.</p>');
275
+                        //return Redirect::to('editCourses')->withInput();
276
+                    }
180 277
                 }
278
+                Session::flash('status', 'success');
279
+                Session::flash('message', 'Course edited: "' . $course->name . '".');
280
+                if ($stu_not_found) {
281
+
282
+                    $error_msg = "<ul>";
283
+
284
+                    foreach ($stu_nf_list as $stu_num) {
285
+                        $error_msg .= "<li>" . $stu_num . "</li>";
286
+                    }
287
+                    $error_msg .= "</ul>";
288
+
289
+                    Session::flash('status', 'warning');
290
+                    Session::flash('message', '<p>Error Enrolling students these students</p>' . $error_msg .
291
+                        '<p>But course ' . $course->name . ' was edited</p>');
292
+                    //return Redirect::to('editCourses')->withInput();
293
+                }
294
+
295
+
296
+                return Redirect::to('editCourses')->withInput();
297
+
298
+
299
+
300
+                //fclose($student_nums);
301
+            } else {
302
+
303
+                Session::flash('status', 'warning');
304
+                Session::flash('message', '<p>Course ' . $course->name . ' edited  but no student enrolled.</p>');
305
+                return Redirect::to('editCourses')->withInput();
181 306
             }
182
-            DB::table('criterion_objective_outcome')
183
-                ->join('program_criterion', 'criterion_objective_outcome.criterion_id', "=", 'program_criterion.criterion_id')
184
-                ->whereIn('program_id', $clean_input['program_id'])
185
-                ->whereIn('outcome_id', $clean_input['outcome_id'])
186
-                ->where('objective_id', '=', 0)
187
-                ->update(array('objective_id' => $objectiveId));
188
-            // 				update("update criterion_objective_outcome coo join program_criterion pc on coo.criterion_id=pc.criterion_id set 
189
-            // 				objective_id= {$objectiveId} where program_id in (".$clean_input['program_id'].") and objective_id=0 and outcome_id in (".$clean_input['outcome_id'].")");
190
-            */
191
-
192
-            /*$role = Auth::user()['role'];
193
-            switch ($role) {
194
-                case 1:
195
-                    return Redirect::to('objective')->withInput(Input::only('outcome_id'));
196
-
197
-                case 2:
198
-                    return Redirect::to('school-objective')->withInput(Input::only('outcome_id'));
199
-
200
-                case 3:
201
-                    return Redirect::to('program-objective')->withInput(Input::only('outcome_id'));
202
-            }*/
203 307
         }
204 308
 
205 309
         /** If saving fails, send error message and old data */
206 310
         else {
207 311
             Session::flash('status', 'danger');
208 312
             Session::flash('message', '<p>Error creating course. Please try again later.</p>');
209
-            return Redirect::to('editCourse')->withInput();
210
-            /*$role = Auth::user()['role'];
211
-            switch ($role) {
212
-                case 1:
213
-                    return Redirect::to('objective')->withInput();
214
-
215
-                case 2:
216
-                    return Redirect::to('school-objective')->withInput();
217
-
218
-                case 3:
219
-                    return Redirect::to('program-objective')->withInput();
220
-            }*/
313
+            return Redirect::to('editCourses')->withInput();
221 314
         }
315
+
316
+
317
+
318
+        return Redirect::to('editCourses')->withInput();
222 319
     }
223 320
 
224 321
 

+ 3
- 0
app/routes.php View File

@@ -219,6 +219,9 @@ Route::group(array('before' => 'auth|has_access'), function () {
219 219
     // van a poder crear luego)
220 220
     Route::get('editCourses', 'CoursesController@editView');
221 221
     Route::post("createCourse", 'CoursesController@create');
222
+    Route::post("updateCourseInfo", 'CoursesController@updateCourseInfo');
223
+    Route::post("fetch_assoc_courses", 'CoursesController@fetchCourses');
224
+
222 225
 
223 226
 
224 227
     //shared viewTransformativeActions

+ 206
- 25
app/views/local/managers/shared/course_edit.blade.php View File

@@ -73,7 +73,7 @@
73 73
 
74 74
                         <select id ="semester_id" name="semester_id" class="form-control selectpicker">
75 75
                             @foreach ($semesters as $semester)
76
-                                @if (Input::old('semester_prof') != $semester->id)
76
+                                @if (Input::old('semester_id') != $semester->id)
77 77
                                     <option value="{{ $semester->id }}">{{ $semester->name }}</option>
78 78
                                 @else
79 79
                                     <option selected value="{{ $semester->id }}">{{ $semester->name }}</option>
@@ -82,6 +82,22 @@
82 82
                         </select>
83 83
                     </div>
84 84
 
85
+                    
86
+                    <div class = "form-group">
87
+                        {{Form::label('modality','Course Modality')}}
88
+
89
+                        <select id="modality" name = "modality" class= "form-control selectpicker">
90
+                            @foreach($modalities as $modality)
91
+                                @if (Input::old('modality') != $modality)
92
+                                    <option value="{{ $modality }}">{{ $modality }}</option>
93
+                                @else
94
+                                    <option selected value="{{ $modality }}">{{ $modality }}</option>
95
+                                @endif
96
+                                
97
+                            @endforeach
98
+                        </select>
99
+                    </div>
100
+
85 101
                     <div class ="form-group">
86 102
                         <label for="file">Choose student text file</label>
87 103
                         <input type="file"
@@ -118,52 +134,118 @@
118 134
         <div class="col-md-6">
119 135
             <div class="panel panel-default panel-button">
120 136
                 <div class="panel-heading">
121
-                    Reassign Sections' Professors
137
+                    Edit Course
122 138
                 </div>
123 139
                 <div class="panel-body">
124 140
 
125
-                    <p>Use this to reassign a section to a specific professor. Write down the code, number and section of
126
-                        the course. Then, choose a professor from the list. <strong>All fields are required.</strong></p>
127 141
 
128
-                    {{ Form::open(['action' => 'CoursesController@update']) }}
129 142
 
143
+                    <p>You can enroll students in this setting, by choosing the course and uploading a .txt file with the students numbers</p>
144
+
145
+                    {{ Form::open(['action' => 'CoursesController@updateCourseInfo', 'enctype'=>"multipart/form-data"]) }}
146
+                    <button class="btn btn-md btn-secondary filterButton">
147
+                        <span class="glyphicon glyphicon-minus">
148
+                        </span>
149
+                        Filters
150
+                    </button>
151
+                    <div class="filterSection">
152
+                        <br>
153
+                        <div class="form-group">
154
+                            {{ Form::label('program_id2', 'Associated Program') }}
155
+                            <select id='select-program' class="form-control selectpicker"
156
+                            onchange='fetchCourses("#select-program", "#select-semester")'>
157
+
158
+                                @foreach ($programs as $program)
159
+                                    <option value='{{ $program->id }}' data-subtext="{{ $program->code }}">
160
+                                        {{ $program->name }}</option>
161
+                                @endforeach
162
+
163
+                            </select>
164
+                        </div>
165
+                        
166
+                        <div class="form-group">
167
+                            {{ Form::label('semester_assoc', 'Course Semester') }}
168
+                            <select id='select-semester' class="form-control selectpicker"
169
+                                onchange='fetchCourses("#select-program", "#select-semester")'>
170
+
171
+                                @foreach ($semesters as $semester)
172
+                                    <option value='{{ $semester->id }}' data-subtext="{{ $semester->code }}">
173
+                                        {{ $semester->name }}</option>
174
+                                @endforeach
175
+
176
+                            </select>
177
+                        </div>
178
+                        
179
+                    </div>
180
+                    <hr>
181
+                    <div class = "form-group">
182
+                        {{Form::label('select_course', "Course")}}
183
+                        <select id = "select-course" name = "select-course" class ='form-control selectpicker'
184
+                        onchange = "fetchCourseInfo('#select-course')">
185
+                            
186
+
187
+                        </select>
188
+                    </div>
189
+
190
+
191
+                    <div class="form-group">
192
+                        {{ Form::label("name",'Name')}}
193
+                        {{ Form::text('name', Input::old('name'), ['class'=>'form-control', 'placeholder' => "Introducción a la ...", 'id'=> 'edit_name'])}}
194
+                    </div>
130 195
                     <div class="form-group">
131
-                        {{ Form::label('code_prof', 'Code') }}
132
-                        {{ Form::text('code_prof', Input::old('code_prof'), ['class' => 'form-control', 'placeholder' => 'TEST', 'maxLength' => 4]) }}
196
+                        {{ Form::label('code', 'Code') }}
197
+                        {{ Form::text('code', Input::old('code'), ['class' => 'form-control', 'placeholder' => 'TEST', 'maxLength' => 4, 'id'=> 'edit_code']) }}
133 198
                     </div>
134 199
 
135 200
                     <div class="form-group">
136
-                        {{ Form::label('number_prof', 'Number') }}
137
-                        {{ Form::text('number_prof', Input::old('number_prof'), ['class' => 'form-control', 'placeholder' => '3001', 'maxLength' => 4]) }}
201
+                        {{ Form::label('number', 'Number') }}
202
+                        {{ Form::text('number', Input::old('number'), ['class' => 'form-control', 'placeholder' => '3001', 'maxLength' => 4, 'id'=> 'edit_number']) }}
138 203
                     </div>
139 204
 
140 205
                     <div class="form-group">
141
-                        {{ Form::label('section_prof', 'Section') }}
142
-                        {{ Form::text('section_prof', Input::old('section_prof'), ['class' => 'form-control', 'placeholder' => '001', 'maxLength' => 3]) }}
206
+                        {{ Form::label('section', 'Section') }}
207
+                        {{ Form::text('section', Input::old('section'), ['class' => 'form-control', 'placeholder' => '001', 'maxLength' => 3, 'id'=> 'edit_section']) }}
143 208
                     </div>
144 209
 
145 210
                     <!-- Program -->
146
-                    {{--
147 211
                     <div class="form-group">
148
-                        {{ Form::label('user_prof', 'User') }}
149
-                        <select id="user_prof" name="user_prof" class="form-control">
150
-                            @foreach ($users as $user)
151
-                                @if (Input::old('user_prof') != $user->id)
152
-                                    <option value="{{ $user->id }}">{{ $user->surnames }},
153
-                                        {{ $user->first_name }}</option>
212
+                        {{ Form::label('program', 'Program') }}
213
+                        <select id="edit_program" name="program" class="form-control selectpicker">
214
+                            
215
+                            @foreach ($programs as $program)
216
+                                @if (Input::old('program') != $program->id)
217
+                                    <option value="{{ $program->id }}">{{ $program->name }}
218
+                                        ({{ $program->school->name }})</option>
154 219
                                 @else
155
-                                    <option selected value="{{ $user->id }}">{{ $user->surnames }},
156
-                                        {{ $user->first_name }}</option>
220
+                                    <option selected value="{{ $program->id }}">{{ $program->name }}
221
+                                        ({{ $program->school->name }})</option>
157 222
                                 @endif
158 223
                             @endforeach
159 224
                         </select>
160 225
                     </div>
161
-                    --}}
162 226
 
163
-                    <!-- Semester -->
164 227
                     <div class="form-group">
165
-                        {{ Form::label('semester_prof', 'Semester') }}
166
-                        <select id="semester_prof" name="semester_prof" class="form-control selectpicker">
228
+                        {{ Form::label('user_id', 'Professor') }}
229
+                        <select id="edit_professor_id" name="professor_id" class="form-control selectpicker">
230
+                             @foreach ($professors as $professor)
231
+                                 @if (Input::old('professor_id') != $professor->id )
232
+                                    <option value="{{$professor->id}}">{{ $professor->surnames }}, {{$professor->first_name}}
233
+                                        {{-- $professor->program->name --}}</option>
234
+                                @else
235
+                                    <option selected value="{{ $professor->id }}">{{ $professor->name }}
236
+                                        {{-- $professor->program->name --}}</option>
237
+                               
238
+
239
+                                    
240
+                                @endif
241
+                            @endforeach
242
+                        </select>
243
+                    </div>
244
+
245
+                    <div class ="form-group">
246
+                        {{ Form::label("semester_id",'Semester')}}
247
+
248
+                        <select id ="edit_semester_id" name="semester_id" class="form-control selectpicker">
167 249
                             @foreach ($semesters as $semester)
168 250
                                 @if (Input::old('semester_prof') != $semester->id)
169 251
                                     <option value="{{ $semester->id }}">{{ $semester->name }}</option>
@@ -174,15 +256,114 @@
174 256
                         </select>
175 257
                     </div>
176 258
 
259
+                    <div class = "form-group">
260
+                        {{Form::label('modality','Course Modality')}}
261
+
262
+                        <select id="edit_modality" name = "modality" class= "form-control selectpicker">
263
+                            @foreach($modalities as $modality)
264
+                                @if (Input::old('modality') != $modality)
265
+                                    <option value="{{ $modality }}">{{ $modality }}</option>
266
+                                @else
267
+                                    <option selected value="{{ $modality }}">{{ $modality }}</option>
268
+                                @endif
269
+                                
270
+                            @endforeach
271
+                        </select>
272
+                    </div>
273
+
274
+
275
+                    <div class ="form-group">
276
+                        <label for="file">Choose student text file</label>
277
+                        <input type="file"
278
+                        id="edit_students" class="form-control" name="students"
279
+                        accept=".txt">
280
+                    </div>
281
+
177 282
                     <br>
178 283
 
179
-                    {{ Form::submit('Create Course', ['class' => 'btn btn-primary btn-block', 'name' => 'create_professor']) }}
284
+                    {{ Form::submit('Edit Course', ['class' => 'btn btn-primary btn-block', 'name' => 'edit_course_info']) }}
180 285
                     {{ Form::close() }}
181 286
 
182 287
                 </div>
183 288
             </div>
184 289
         </div>
185 290
     </div>
291
+
292
+    <script>
293
+        $('.filterSection').show();
294
+        $('.filterButton').on('click', function() {
295
+            var span = $(this).find('span');
296
+            if (span.attr('class') == 'glyphicon glyphicon-plus') {
297
+                span.attr('class', 'glyphicon glyphicon-minus');
298
+            } else {
299
+                span.attr('class', 'glyphicon glyphicon-plus');
300
+            }
301
+            $('.filterSection').toggle(533);
302
+        });
303
+        $('.filterButton').on('click', function(e) {
304
+        // Prevent the default action of the clicked item. In this case that is submit
305
+            e.preventDefault();
306
+
307
+
308
+        return false;
309
+        });
310
+
311
+        function fetchCourses(select, semester){
312
+
313
+            
314
+
315
+            program_id = $(select).val();
316
+            semester_id = $(semester).val();
317
+            $.post(
318
+                "{{URL::action('CoursesController@fetchCourses')}}",
319
+                {
320
+                    program_id:program_id,
321
+                    semester_id:semester_id
322
+                },
323
+                function(courses){
324
+                    $('#select-course').html(
325
+                        " "
326
+                    )
327
+                    $.each(courses, function(ind, course){
328
+
329
+                        
330
+                        option =  "<option value= '"+course.id+"' data-subtext ='"+course.code+course.number+"'"+
331
+                        "data-code='"+course.code+"' data-number='"+course.number+"' data-program-id='"+course.program_id+"'"+
332
+                        "data-section='"+course.section+"' data-user-id='"+course.user_id+"' data-semester-id = '"+course.semester_id+"'"+
333
+                        "data-modality='"+course.modality+"' "+
334
+                        ">"+course.name+"</option>";
335
+                        $("#select-course").append(option);
336
+                    });
337
+                    $("#select-course").trigger('change');
338
+                    $("#select-course").selectpicker('refresh');
339
+                }
340
+            )
341
+        }
342
+
343
+        function fetchCourseInfo(course_select){
344
+
345
+            course_option = $(course_select).find(':selected');
346
+
347
+            $('#edit_name').val($(course_option).html())
348
+            $('#edit_code').val($(course_option).data('code'))
349
+            $('#edit_number').val($(course_option).data('number'))
350
+            $('#edit_section').val($(course_option).data('section'))
351
+            $('#edit_program').val($(course_option).data('program-id'))
352
+            $("#edit_program").selectpicker('refresh');
353
+            $('#edit_professor_id').val($(course_option).data('user-id'))
354
+            $("#edit_professor_id").selectpicker('refresh');
355
+            
356
+            $('#edit_semester_id').val($(course_option).data('semester-id'))
357
+            $("#edit_semester_id").selectpicker('refresh');
358
+
359
+            $('#edit_modality').val($(course_option).data('modality'))
360
+            $("#edit_modality").selectpicker('refresh');
361
+            $(course_select).selectpicker('refresh');
362
+
363
+        }
364
+
365
+
366
+    </script>
186 367
 @stop
187 368
 
188 369
 @section('javascript')