Explorar el Código

ANtes de terminar assessment

Gabriel Santiago Plaza hace 3 años
padre
commit
6592b0a485

+ 9
- 2
app/controllers/ActivitiesController.php Ver fichero

@@ -171,6 +171,12 @@ class ActivitiesController extends \BaseController
171 171
             ->join("criterion_rubric", "criterion_rubric.criterion_id", "=", "criteria.id")
172 172
             ->where('criterion_rubric.rubric_id', '=', $rubric->id)->get();
173 173
         Log::info($criterion_rubric);
174
+        foreach ($criterion_rubric as $index => $singleCR) {
175
+            $singleCR->scales = json_encode(DB::table('scales')->join('rubric_criteria_scale', 'rubric_criteria_scale.scale_id', '=', 'scales.id')
176
+                ->where('rubric_criteria_scale.rubric_criterion_id', '=', $singleCR->id)
177
+                ->orderBy('position')
178
+                ->lists('description'));
179
+        }
174 180
         $criterion_rubric_ids = DB::table('criterion_rubric')->where('rubric_id', '=', $rubric->id)->lists('id');
175 181
         Log::info($rubric);
176 182
         Log::info($criterion_rubric);
@@ -190,7 +196,8 @@ class ActivitiesController extends \BaseController
190 196
         foreach ($assessments as $index => $assessment) {
191 197
             $scores_array[$assessment->id] = json_decode($assessment->scores, true);
192 198
         }
193
-        Log::info($rubric);
199
+        Log::info(sizeof($criterion_rubric));
200
+
194 201
 
195 202
         return View::make('local.professors.assessment', compact('activity', 'title', 'students', 'course', 'criterion_rubric', 'assessments', 'scores_array', 'rubric', 'scales'));
196 203
     }
@@ -684,7 +691,7 @@ class ActivitiesController extends \BaseController
684 691
         $rubric_contents = Rubric::select('contents')->where('id', '=', $activity->rubric_id)->get();
685 692
         $rubric_contents = json_decode($rubric_contents['0']->contents);
686 693
 
687
-        $rubric = Rubric::find($activity->rubric_id);
694
+        $rubric = Rubric::find($activity->rubric[0]->id);
688 695
 
689 696
         // Get results
690 697
         $assessments = DB::table('assessments')->where('activity_id', '=', $activity->id)->orderBy('id', 'asc')->get();

+ 152
- 64
app/controllers/RubricsController.php Ver fichero

@@ -33,6 +33,9 @@ class RubricsController extends \BaseController
33 33
         $outcomes = Outcome::orderBy('name', 'ASC')->get();
34 34
         $criteria = Criterion::orderBy('name', 'ASC')->get();
35 35
         $rubric = $activity->rubric;
36
+        Log::info($rubric);
37
+        Log::info($activity->rubric_id);
38
+        Log::info($activity->rubric[0]->id);
36 39
 
37 40
         return View::make('local.professors.rubrics', compact('title', 'templates', 'outcomes', 'criteria', 'rubrics', 'activity', 'rubric'));
38 41
     }
@@ -166,94 +169,160 @@ class RubricsController extends \BaseController
166 169
      */
167 170
     public function update()
168 171
     {
172
+        Log::info('entré???');
169 173
         $rubric = Rubric::find(Input::get('id'));
174
+
175
+        $scales = Input::get('scales');
176
+        $criteria = Input::get('criteria');
177
+
178
+        // Process rubric
170 179
         $rubric->name = Input::get('name');
171 180
 
172 181
         $rubric->expected_percentage = Input::get('expected_percentage');
173 182
         $rubric->expected_points = Input::get('expected_points');
174 183
 
184
+        $rubric->num_scales = count($scales[0]);
185
+        $rubric->max_score = Input::get('max_score');
186
+        $division = $rubric->max_score / count($scales[0]);
187
+
175 188
         DB::beginTransaction();
176 189
 
177
-        try {
178
-            // Get associated activity
179
-            $activity = Activity::where('rubric_id', '=', $rubric->id)->first();
180 190
 
181
-            // If the associated activity has been assessed, delete the records
191
+        // Get associated activity
192
+        //$activity = Activity::where('rubric_id', '=', $rubric->id)->first();
193
+
194
+        $activity_id = DB::table('activities')
195
+            ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
196
+            ->where('rubric_id', '=', $rubric->id)
197
+            ->first();
198
+
199
+        $activity = Activity::where('id', '=', $activity_id->activity_id)->first();
200
+
201
+
202
+
203
+        // If the associated activity has been assessed, delete the records
204
+        if ($activity->outcomes_attempted != NULL) {
205
+            DB::table('assessments')->where('activity_id', '=', $activity->id)->delete();
206
+            $activity->criteria_achieved_percentage = NULL;
207
+            $activity->criteria_achieved = NULL;
208
+            $activity->outcomes_achieved = NULL;
209
+            $activity->outcomes_attempted = NULL;
210
+        }
211
+        Log::info('entré3???');
212
+
213
+        $rubric->save();
214
+        Log::info("????");
215
+        $activity->save();
216
+        Log::info("????22");
217
+        // Get all the course's activities
218
+        Log::info($activity->course);
219
+        $course = Course::find($activity->course->id);
220
+        $activities = $course->activities;
221
+
222
+        // Check if any assessed activities remain
223
+        $remainingAssessed = false;
224
+        foreach ($course->activities as $activity) {
182 225
             if ($activity->outcomes_attempted != NULL) {
183
-                DB::table('assessments')->where('activity_id', '=', $activity->id)->delete();
184
-                $activity->criteria_achieved_percentage = NULL;
185
-                $activity->criteria_achieved = NULL;
186
-                $activity->outcomes_achieved = NULL;
187
-                $activity->outcomes_attempted = NULL;
226
+                $remainingAssessed = true;
227
+                break;
188 228
             }
229
+        }
230
+        Log::info('entré4???');
189 231
 
190
-            $rubric->save();
191
-            $activity->save();
192
-
193
-            // Get all the course's activities
194
-            $course = Course::find($activity->course->id);
195
-            $activities = $course->activities;
232
+        //If there are still evaluated activities in the course, recalculate course outcomes
233
+        if (!$activities->isEmpty() && $remainingAssessed) {
234
+            // Variables to hold recalculated outcomes for the course
235
+            $course_outcomes_attempted = array_fill(1, Outcome::all()->count(), 0);
236
+            $course_outcomes_achieved = array_fill(1, Outcome::all()->count(), 0);
196 237
 
197
-            // Check if any assessed activities remain
198
-            $remainingAssessed = false;
199
-            foreach ($course->activities as $activity) {
238
+            // For each activity
239
+            foreach ($activities as $activity) {
240
+                // If activity has been assessed
200 241
                 if ($activity->outcomes_attempted != NULL) {
201
-                    $remainingAssessed = true;
202
-                    break;
242
+                    // Get the achieved criteria
243
+                    $criteria_achievement = json_decode($activity->criteria_achieved, true);
244
+                    foreach ($criteria_achievement as $criterion_id => $criterion_achieved) {
245
+                        // Find corresponding learning outcome;
246
+                        $criterion = Criterion::find($criterion_id);
247
+                        $outcome = Outcome::find($criterion->outcome_id);
248
+
249
+                        // If criterion is achieved (1), add 1 to both arrays
250
+                        if ($criterion_achieved === 1) {
251
+                            $course_outcomes_attempted[$outcome->id] += 1;
252
+                            $course_outcomes_achieved[$outcome->id] += 1;
253
+                        }
254
+                        // Else, only add to the attempted outcomes arrays
255
+                        elseif ($criterion_achieved === 0) {
256
+                            $course_outcomes_attempted[$outcome->id] += 1;
257
+                        }
258
+                    }
203 259
                 }
204 260
             }
261
+            Log::info('entré5???');
262
+            // Update course
263
+            $course->outcomes_achieved = json_encode($course_outcomes_achieved);
264
+            $course->outcomes_attempted = json_encode($course_outcomes_attempted);
265
+        } else {
266
+            // Update course
267
+            $course->outcomes_achieved = NULL;
268
+            $course->outcomes_attempted = NULL;
269
+        }
205 270
 
206
-            //If there are still evaluated activities in the course, recalculate course outcomes
207
-            if (!$activities->isEmpty() && $remainingAssessed) {
208
-                // Variables to hold recalculated outcomes for the course
209
-                $course_outcomes_attempted = array_fill(1, Outcome::all()->count(), 0);
210
-                $course_outcomes_achieved = array_fill(1, Outcome::all()->count(), 0);
211
-
212
-                // For each activity
213
-                foreach ($activities as $activity) {
214
-                    // If activity has been assessed
215
-                    if ($activity->outcomes_attempted != NULL) {
216
-                        // Get the achieved criteria
217
-                        $criteria_achievement = json_decode($activity->criteria_achieved, true);
218
-                        foreach ($criteria_achievement as $criterion_id => $criterion_achieved) {
219
-                            // Find corresponding learning outcome;
220
-                            $criterion = Criterion::find($criterion_id);
221
-                            $outcome = Outcome::find($criterion->outcome_id);
222
-
223
-                            // If criterion is achieved (1), add 1 to both arrays
224
-                            if ($criterion_achieved === 1) {
225
-                                $course_outcomes_attempted[$outcome->id] += 1;
226
-                                $course_outcomes_achieved[$outcome->id] += 1;
227
-                            }
228
-                            // Else, only add to the attempted outcomes arrays
229
-                            elseif ($criterion_achieved === 0) {
230
-                                $course_outcomes_attempted[$outcome->id] += 1;
231
-                            }
271
+        $course->save();
272
+        Log::info('entré6???');
273
+        DB::delete("delete from criterion_rubric where rubric_id ={$rubric->id}");
274
+        foreach ($criteria as $index => $criterion_id) {
275
+            if (
276
+
277
+                DB::insert("insert into criterion_rubric (`rubric_id`, `criterion_id`) values ({$rubric->id}, {$criterion_id}) ")
278
+            ) {
279
+                Log::info("AHH");
280
+                $rubric_criterion_id =  DB::table('criterion_rubric')
281
+                    ->where('rubric_id', '=', $rubric->id)
282
+                    ->where('criterion_id', '=', $criterion_id)
283
+                    ->first();
284
+
285
+                foreach ($scales[$index] as $in => $scale) {
286
+                    Log::info("AH2");
287
+                    $new_scale =  Scale::where('description', '=', $scale)
288
+                        ->where('max_score', '=', ($division * ($in + 1)))
289
+                        ->where("min_score", '=', (1 + ($division * $in)))->first();
290
+
291
+                    if ($new_scale) {
292
+                        DB::insert("insert into `rubric_criteria_scale` (`rubric_criterion_id`, `scale_id`, `position`) values ({$rubric_criterion_id->id},{$new_scale->id}, {$in})");
293
+                        DB::commit();
294
+                    } else {
295
+                        $new_scale = new Scale;
296
+                        $new_scale->description = $scales[$index][$in];
297
+                        $new_scale->min_score = 1 + ($division * $in);
298
+                        $new_scale->max_score = ($division * ($in + 1));
299
+                        if ($new_scale->save()) {
300
+                            DB::insert("insert into `rubric_criteria_scale` (`rubric_criterion_id`, `scale_id`, `position`) values ({$rubric_criterion_id->id},{$new_scale->id}, {$in})");
301
+                            DB::commit();
302
+                        } else {
303
+                            DB::rollBack();
304
+                            Session::flash('status', 'danger');
305
+                            Session::flash('message', 'Rubric could not be created.');
306
+                            return action('ActivitiesController@show', array($activity->id));
232 307
                         }
233 308
                     }
234 309
                 }
235
-
236
-                // Update course
237
-                $course->outcomes_achieved = json_encode($course_outcomes_achieved);
238
-                $course->outcomes_attempted = json_encode($course_outcomes_attempted);
239 310
             } else {
240
-                // Update course
241
-                $course->outcomes_achieved = NULL;
242
-                $course->outcomes_attempted = NULL;
311
+                DB::rollBack();
312
+                Session::flash('status', 'danger');
313
+                Session::flash('message', 'Rubric could not be created.');
314
+                return action('ActivitiesController@show', array($activity->id));
243 315
             }
316
+        }
317
+        Log::info('entré7???');
244 318
 
245
-            $course->save();
246
-            DB::commit();
319
+        DB::commit();
247 320
 
248
-            Session::flash('status', 'success');
249
-            Session::flash('message', 'Rubric updated.');
250 321
 
251
-            return action('ActivitiesController@show', array($activity->id));
252
-        } catch (Exception $e) {
253
-            DB::rollBack();
254
-            Session::flash('status', 'danger');
255
-            Session::flash('message', 'Error: The rubric could not be updated. Try again later.');
256
-        }
322
+        Session::flash('status', 'success');
323
+        Session::flash('message', 'Rubric updated.');
324
+
325
+        return action('ActivitiesController@show', array($activity->id));
257 326
     }
258 327
 
259 328
     /**
@@ -293,8 +362,27 @@ class RubricsController extends \BaseController
293 362
         Log::info($activity->rubric[0]->id);
294 363
 
295 364
         $rubric = Rubric::where('id', '=', $activity->rubric[0]->id)->firstOrFail();
365
+        $criterion_rubric = DB::table('criteria')
366
+            ->join('criterion_rubric', 'criterion_rubric.criterion_id', '=', 'criteria.id')
367
+            ->where('criterion_rubric.rubric_id', '=', $activity->rubric[0]->id)
368
+            ->get();
369
+
370
+        foreach ($criterion_rubric as $single_cr) {
371
+            $single_cr->scales = json_encode(DB::table('scales')
372
+                ->join('rubric_criteria_scale', 'rubric_criteria_scale.scale_id', '=', 'scales.id')
373
+                ->where('rubric_criteria_scale.rubric_criterion_id', '=', $single_cr->id)
374
+                ->orderBy('position')
375
+                ->lists('description'));
376
+            $single_cr->outcomes = json_encode(DB::table('outcomes')
377
+                ->join('criterion_objective_outcome', 'outcomes.id', '=', 'criterion_objective_outcome.outcome_id')
378
+                ->where('criterion_objective_outcome.criterion_id', '=', $single_cr->criterion_id)->lists('name'));
379
+        }
380
+
381
+
382
+        Log::info($criterion_rubric);
383
+
296 384
         $title = $activity->name . ': ' . $rubric->name;
297
-        return View::make('local.professors.viewrubric', compact('rubric', 'activity', 'title', 'course'));
385
+        return View::make('local.professors.viewrubric', compact('rubric', 'activity', 'criterion_rubric', 'title', 'course'));
298 386
     }
299 387
 
300 388
     /**

+ 28
- 40
app/views/local/professors/assessment.blade.php Ver fichero

@@ -24,10 +24,16 @@
24 24
             <div class="modal-body">
25 25
                 <table class="table table-bordered">
26 26
                     <thead id = "criteria-header">;
27
-                        
27
+                        @for($i=0; $i<$rubric->num_scales; $i++)
28
+                        <th>Scale {{$i+1}} ({{1+($i*($rubric->max_score/$rubric->num_scales))}} - {{(1+$i)*($rubric->max_score/$rubric->num_scales)}})</th>
29
+                        @endfor
30
+                        <th>Notes</th>
28 31
                     </thead>
29 32
                     <tbody>
30
-                        <tr></tr>
33
+                        <tr>
34
+                            
35
+                            
36
+                        </tr>
31 37
                     </tbody>
32 38
                 </table>
33 39
             </div>
@@ -94,6 +100,21 @@
94 100
 
95 101
         <table data-rubric-id="{{{ $rubric->id }}}" id="assessment-table" class="table table-striped table-condensed table-bordered">
96 102
             <thead>
103
+                <tr>
104
+                    <th>
105
+                    </th>
106
+                    @foreach ($criterion_rubric as $index => $criterion)
107
+                    <th  data-criterion-id="{{{ $criterion->criterion_id }}}" ><div class="th-box">
108
+                        <!--<div class="form-group row">
109
+                            <div class="col-xs-1">
110
+                                <label for="weight-{{$index}}">Weight</label>
111
+                            <input class="form-control" id="weight-{{$index}}" name='weight[]' type="text">
112
+                            </div>
113
+                        </div>-->
114
+                        Weight<input class="form-control" id="weight-{{$index}}" name='weight[]' type="text" style = "width: 50%">
115
+                        </div></th>
116
+                @endforeach
117
+                </tr>
97 118
                     <tr>
98 119
                         <th>
99 120
                             <div class="th-box">
@@ -101,9 +122,10 @@
101 122
                             </div>
102 123
                         </th>
103 124
                         @foreach ($criterion_rubric as $criterion)
104
-                            <th class="criterion-field" data-criterion-id="{{{ $criterion->id }}}" ><div class="th-box">{{ $criterion->name}}</div></th>
125
+                            <th class="criterion-field" data-criterion-id="{{{ $criterion->criterion_id }}}" ><div class="th-box">{{ $criterion->name}}</div></th>
105 126
                         @endforeach
106 127
                         <th>Student Percentage</th>
128
+                        <th>Student % per Weight</th>
107 129
                         <th>Comments</th>
108 130
                     </tr>
109 131
             </thead>
@@ -155,14 +177,15 @@
155 177
                         @for ($i = 0; $i<sizeof($criterion_rubric); $i++)
156 178
                             <td class="score-field">
157 179
                                 <select name="" id="" class="form-control" data-toggle="tooltip" data-placement="right" title="{{{ $student->name }}}">
158
-                                    @for($i=0; $i<$rubric->max_score; $i++)
159
-                                    <option value ='{{$i}}'>{{$i}}</option>
180
+                                    @for($j=0; $j<=$rubric->max_score; $j++)
181
+                                    <option value ='{{$j}}'>{{$j}}</option>
160 182
                                     @endfor
161 183
                                     <option selected="selected" value="N/A">N/A</option>
162 184
                                 </select>
163 185
                             </td>
164 186
                         @endfor
165 187
                         <td class="percentage"></td>
188
+                        <td class="percentage-per-w"></td>
166 189
                         <td class="comments"><textarea class="comments full-textarea" placeholder="Max. 255 characters" maxLength="255" ></textarea></td>
167 190
                      </tr>
168 191
                 @endforeach
@@ -189,43 +212,8 @@
189 212
         </div>
190 213
     </div>
191 214
 </div>
192
-<script>
193
-    function changeTable(){
194
-    
195
- 
196
-    amount_of_scales = parseInt($('#num_of_scales').val());
197
-    counter2 = 0;
198
-    maximum = parseInt($('#max').val());
199
-    
200
-   
201
-    newScaleHeaders = '';
202
-    counter = 0;
203
-    division = maximum/amount_of_scales;
204
-    if(amount_of_scales==1){
205
-        newScaleHeaders+= "<th>Score (1 - "+maximum+")</th>";
206
-    }
207
-    else if(maximum!= amount_of_scales){
208
-    while(counter <amount_of_scales){
209
-        
210
-        minimumScore = 1+(counter*division);
211
-        maximumScore = (1+counter)*division;
212
-        newScaleHeaders+= "<th>Scale "+ (counter +1) + " ("+minimumScore+" - "+maximumScore+")</th>";
213
-        counter++;
214
-    }
215
-    }else{
216
-        while(counter <amount_of_scales){
217
-        
218 215
 
219
-        newScaleHeaders+= "<th>Scale "+ (counter +1) + " </th>";
220
-        counter++;
221
-    }
222
-    }
223
-    newScaleHeaders += '<th>Notes</th>';
224
-    
225
-    $("#criterion-header").html(newScaleHeaders);
226 216
     
227
-}
228
-    </script>
229 217
 @stop
230 218
 
231 219
 @section('included-js')

+ 10
- 6
app/views/local/professors/rubrics.blade.php Ver fichero

@@ -42,8 +42,8 @@
42 42
 
43 43
 
44 44
     <div class="well">
45
-      @if($activity->rubric_id!=NULL)
46
-        <span id="assigned_rubric" class="hidden" data-assigned-rubric="{{{ $activity->rubric_id }}}"></span>
45
+      @if(count($activity->rubric)!=0)
46
+        <span id="assigned_rubric" class="hidden" data-assigned-rubric="{{{ $activity->rubric[0]->id }}}"></span>
47 47
       @endif
48 48
       <input id="activity_id" type="hidden" value="{{{ $activity->id}}}">
49 49
 
@@ -51,7 +51,7 @@
51 51
         <label>Select a Rubric:</label>
52 52
         <select id="select-template" class="form-control selectpicker">
53 53
           @foreach ($templates as $template)
54
-            @if($activity->rubric_id!=NULL && $template->name == Rubric::find($activity->rubric_id)->name)
54
+            @if(count($activity->rubric)!=0 && $template->name == Rubric::find($activity->rubric[0]->id)->name)
55 55
               <option data-template-id="{{ $template->id }}" class="template" selected="selected">{{ $template->name }}</option>
56 56
             @else
57 57
               <option data-template-id="{{ $template->id }}" class="template">{{ $template->name }}</option>
@@ -541,7 +541,7 @@ $('#button-save-rubric').on('click', function(e)
541 541
       {
542 542
         name: $('#select-template').find(':selected').text(),
543 543
         activity_id: parseInt($('#activity_id').val()),
544
-        contents: " ",
544
+        
545 545
         expected_percentage: $('#expected_percentage').text(),
546 546
         expected_points: $('#expected_points').text(),
547 547
         criteria: criteria,
@@ -566,9 +566,13 @@ $('#button-save-rubric').on('click', function(e)
566 566
       {
567 567
         id: $('#assigned_rubric').data('assigned-rubric'),
568 568
         name: $('#select-template').find(':selected').text(),
569
-        contents: JSON.stringify(criteriaArray),
569
+        activity_id: parseInt($('#activity_id').val()),
570
+        
570 571
         expected_percentage: $('#expected_percentage').text(),
571
-        expected_points: $('#expected_points').text()
572
+        expected_points: $('#expected_points').text(),
573
+        criteria: criteria,
574
+        scales: scales,
575
+        max_score:max_score
572 576
       },
573 577
       function(data)
574 578
       {

+ 16
- 11
app/views/local/professors/viewrubric.blade.php Ver fichero

@@ -32,15 +32,14 @@
32 32
           <tr>
33 33
             <th></th>
34 34
             <th>Criterion</th>
35
-            <th>Beginning (1-2)</th>
36
-            <th>In Progress (3-4)</th>
37
-            <th>Good (5-6)</th>
38
-            <th>Excellent (7-8)</th>
35
+            @for($i = 0; $i<$rubric->num_scales; $i++)
36
+            <th>Scale {{$i+1}} ({{1+($i*($rubric->max_score/$rubric->num_scales))}} - {{(1+$i)*($rubric->max_score/$rubric->num_scales)}})</th>
37
+            @endfor
39 38
             <th>Learning Outcome</th>
40 39
           </tr>
41 40
         </thead>
42 41
         <tbody>
43
-        @foreach(json_decode($rubric->contents) as $index => $criterion)
42
+        @foreach($criterion_rubric as $index => $criterion)
44 43
           <tr data-criterion-copyright="{{ $criterion->copyright }}" data-criterion-notes="{{ $criterion->notes }}">
45 44
             <td>{{ $index + 1 }}.</td>
46 45
             @if(isset($criterion->notes))
@@ -49,7 +48,7 @@
49 48
               <sup></sup>
50 49
               @if(property_exists($criterion, 'subcriteria'))
51 50
                 <ul class="list-unstyled">
52
-                  @foreach($criterion->subcriteria as $subcriterion)
51
+                  @foreach(json_decode($criterion->subcriteria) as $subcriterion)
53 52
                       <li>{{ $subcriterion }}</li>
54 53
                   @endforeach
55 54
                 </ul>
@@ -67,11 +66,17 @@
67 66
               @endif
68 67
             </td>
69 68
             @endif
70
-            <td>{{ nl2br($criterion->description12) }}</td>
71
-            <td>{{ nl2br($criterion->description34) }}</td>
72
-            <td>{{ nl2br($criterion->description56) }}</td>
73
-            <td>{{ nl2br($criterion->description78) }}</td>
74
-            <td>{{ Outcome::where('id', $criterion->outcome_id)->first()->name }}</td>
69
+            @foreach(json_decode($criterion->scales) as $scale)
70
+            <td>{{ nl2br($scale) }}</td>
71
+
72
+            @endforeach
73
+
74
+            <td>
75
+            
76
+            @foreach (json_decode($criterion->outcomes) as $index => $outcome)
77
+            {{$index+1}}. {{$outcome}}<br>                 
78
+            @endforeach  
79
+            </td>
75 80
           </tr>
76 81
         @endforeach
77 82
         </tbody>