소스 검색

Cambioos a rubrics, y poco de assessment

부모
커밋
25016ca2d3

+ 12
- 4
app/controllers/ActivitiesController.php 파일 보기

@@ -170,21 +170,29 @@ class ActivitiesController extends \BaseController
170 170
         $criterion_rubric = DB::table('criteria')
171 171
             ->join("criterion_rubric", "criterion_rubric.criterion_id", "=", "criteria.id")
172 172
             ->where('criterion_rubric.rubric_id', '=', $rubric->id)->get();
173
+        Log::info($criterion_rubric);
174
+        $criterion_rubric_ids = DB::table('criterion_rubric')->where('rubric_id', '=', $rubric->id)->lists('id');
173 175
         Log::info($rubric);
174 176
         Log::info($criterion_rubric);
177
+        $scales = DB::table('scales')->join('rubric_criteria_scale', 'rubric_criteria_scale.scale_id', '=', 'scales.id')
178
+            ->whereIn('rubric_criteria_scale.rubric_criterion_id', $criterion_rubric_ids)->get();
179
+
180
+
175 181
 
176
-        $rubric_contents = json_decode($rubric->contents);
177 182
 
178 183
         // Get results
179
-        $assessments = DB::table('assessments')->join('students', 'assessments.student_id', '=', 'students.id')->where('activity_id', '=', $activity->id)->orderBy('assessments.id', 'asc')->get();
184
+        $activity_criterion_ids = DB::table('activity_criterion')->where("activity_id", '=', $activity->id)->lists('id');
185
+        Log::info($activity_criterion_ids);
186
+        $assessments = DB::table('assessments')->join('students', 'assessments.student_id', '=', 'students.id')->whereIn('activity_criterion_id', $activity_criterion_ids)->orderBy('assessments.id', 'asc')->get();
180 187
 
181 188
         // Decode the scores (blade workaround)
182 189
         $scores_array = array();
183 190
         foreach ($assessments as $index => $assessment) {
184 191
             $scores_array[$assessment->id] = json_decode($assessment->scores, true);
185 192
         }
193
+        Log::info($rubric);
186 194
 
187
-        return View::make('local.professors.assessment', compact('activity', 'title', 'students', 'course', 'rubric_contents', 'assessments', 'scores_array', 'rubric'));
195
+        return View::make('local.professors.assessment', compact('activity', 'title', 'students', 'course', 'criterion_rubric', 'assessments', 'scores_array', 'rubric', 'scales'));
188 196
     }
189 197
 
190 198
     public function saveAssessment()
@@ -215,9 +223,9 @@ class ActivitiesController extends \BaseController
215 223
                             }
216 224
 
217 225
                             // Add the assessment to the pivot table
226
+
218 227
                             $student->assessed_activities()->attach($activity->id, array(
219 228
                                 'scores' => json_encode($single_student_data->scores),
220
-                                'percentage' => $single_student_data->percentage,
221 229
                                 'comments' => $single_student_data->comments
222 230
                             ));
223 231
                         }

+ 5
- 1
app/controllers/CriteriaController.php 파일 보기

@@ -54,6 +54,10 @@ class CriteriaController extends \BaseController
54 54
     {
55 55
         $json_to_send = array();
56 56
         $json_to_send['criterion'] = DB::table('criteria')->where('id', '=', Input::get('id'))->first();
57
+        $num_scales = Input::get('numberOfScale');
58
+        $criterionID = Input::get('id');
59
+        $json_to_send['scales'] = DB::select("select * from scales, template_criterion_scale where template_criterion_scale.template_criterion_id in (select id from template_criterion where template_criterion.template_id in (SELECT id FROM templates where num_scales = {$num_scales}) and template_criterion.criterion_id = {$criterionID}) and scales.id = template_criterion_scale.scale_id GROUP BY position order by position");
60
+        Log::info("select * from scales, template_criterion_scale where template_criterion_scale.template_criterion_id in (select id from template_criterion where template_criterion.template_id in (SELECT id FROM templates where num_scales = {$num_scales}) and template_criterion.criterion_id = {$criterionID}) and scales.id = template_criterion_scale.scale_id GROUP BY position order by position");
57 61
 
58 62
 
59 63
 
@@ -63,8 +67,8 @@ class CriteriaController extends \BaseController
63 67
     public function fetchCriterion()
64 68
     {
65 69
         $json_to_send = array();
66
-        $json_to_send['criterion'] = DB::table('criteria')->where('id', '=', Input::get('id'))->first();
67 70
 
71
+        $json_to_send['criterion'] = DB::table('criteria')->where('id', '=', Input::get('id'))->first();
68 72
 
69 73
 
70 74
 

+ 23
- 7
app/controllers/RubricsController.php 파일 보기

@@ -105,21 +105,37 @@ class RubricsController extends \BaseController
105 105
             $rubricId = $rubric->id;
106 106
             foreach ($criteria as $index => $criterion_id) {
107 107
                 DB::insert("insert into criterion_rubric (`rubric_id`,`criterion_id`) values ({$rubricId},{$criterion_id})");
108
+                DB::commit();
108 109
                 $rubric_criterion_id = DB::table('criterion_rubric')->where('rubric_id', '=', $rubricId)
109 110
                     ->where('criterion_id', '=', $criterion_id)->first();
110 111
 
112
+
113
+
111 114
                 for ($i = 0; $i < count($scales[$index]); $i++) {
112
-                    $scale = new Scale;
113
-                    $scale->description = $scales[$index][$i];
114
-                    $scale->min_score = 1 + ($division * $i);
115
-                    $scale->max_score = ($division * ($i + 1));
116
-                    if ($scale->save()) {
115
+                    $scale =  Scale::where('description', '=', $scales[$index][$i])
116
+                        ->where('max_score', '=', ($division * ($i + 1)))
117
+                        ->where("min_score", '=', (1 + ($division * $i)))->first();
118
+                    Log::info($scale);
119
+                    if ($scale) {
117 120
                         DB::insert("insert into `rubric_criteria_scale` (`rubric_criterion_id`, `scale_id`, `position`) values ({$rubric_criterion_id->id},{$scale->id}, {$i})");
121
+                        DB::commit();
118 122
                     } else {
119
-                        Session::flash('status', 'danger');
120
-                        Session::flash('message', 'Rubric could not be created.');
123
+                        $scale = new Scale;
124
+                        $scale->description = $scales[$index][$i];
125
+                        $scale->min_score = 1 + ($division * $i);
126
+                        $scale->max_score = ($division * ($i + 1));
127
+                        if ($scale->save()) {
128
+                            DB::insert("insert into `rubric_criteria_scale` (`rubric_criterion_id`, `scale_id`, `position`) values ({$rubric_criterion_id->id},{$scale->id}, {$i})");
129
+                            DB::commit();
130
+                        } else {
131
+                            Session::flash('status', 'danger');
132
+                            Session::flash('message', 'Rubric could not be created.');
133
+                        }
121 134
                     }
122 135
                 }
136
+                $activity_id = Input::get("activity_id");
137
+                DB::insert("insert into `activity_criterion` (`activity_id`,`criterion_id`) values ({$activity_id}, {$criterion_id})");
138
+                DB::commit();
123 139
             }
124 140
             Session::flash('status', 'success');
125 141
             Session::flash('message', 'Rubric assigned.');

+ 34
- 14
app/controllers/TemplatesController.php 파일 보기

@@ -154,15 +154,25 @@ class TemplatesController extends \BaseController
154 154
 					->where('criterion_id', '=', $criterion_id)->first();
155 155
 
156 156
 				for ($i = 0; $i < count($scales[$index]); $i++) {
157
-					$scale = new Scale;
158
-					$scale->description = $scales[$index][$i];
159
-					$scale->min_score = 1 + ($division * $i);
160
-					$scale->max_score = ($division * ($i + 1));
161
-					if ($scale->save()) {
157
+					$scale =  Scale::where('description', '=', $scales[$index][$i])
158
+						->where('max_score', '=', ($division * ($i + 1)))
159
+						->where("min_score", '=', (1 + ($division * $i)))->first();
160
+					Log::info($scale);
161
+					if ($scale) {
162 162
 						DB::insert("insert into `template_criterion_scale` (`template_criterion_id`, `scale_id`, `position`) values ({$template_criterion_id->id},{$scale->id}, {$i})");
163
+						DB::commit();
163 164
 					} else {
164
-						Session::flash('status', 'danger');
165
-						Session::flash('message', 'Rubric could not be created.');
165
+						$scale = new Scale;
166
+						$scale->description = $scales[$index][$i];
167
+						$scale->min_score = 1 + ($division * $i);
168
+						$scale->max_score = ($division * ($i + 1));
169
+						if ($scale->save()) {
170
+							DB::insert("insert into `template_criterion_scale` (`template_criterion_id`, `scale_id`, `position`) values ({$template_criterion_id->id},{$scale->id}, {$i})");
171
+							DB::commit();
172
+						} else {
173
+							Session::flash('status', 'danger');
174
+							Session::flash('message', 'Rubric could not be created.');
175
+						}
166 176
 					}
167 177
 				}
168 178
 			}
@@ -263,15 +273,25 @@ class TemplatesController extends \BaseController
263 273
 					->where('criterion_id', '=', $criterion_id)->first();
264 274
 				DB::delete("delete from template_criterion_scale where template_criterion_id ={$template_criterion_id->id}");
265 275
 				for ($i = 0; $i < count($scales[$index]); $i++) {
266
-					$scale = new Scale;
267
-					$scale->description = $scales[$index][$i];
268
-					$scale->min_score = 1 + ($division * $i);
269
-					$scale->max_score = ($division * ($i + 1));
270
-					if ($scale->save()) {
276
+					$scale =  Scale::where('description', '=', $scales[$index][$i])
277
+						->where('max_score', '=', ($division * ($i + 1)))
278
+						->where("min_score", '=', (1 + ($division * $i)))->first();
279
+					Log::info($scale);
280
+					if ($scale) {
271 281
 						DB::insert("insert into `template_criterion_scale` (`template_criterion_id`, `scale_id`, `position`) values ({$template_criterion_id->id},{$scale->id}, {$i})");
282
+						DB::commit();
272 283
 					} else {
273
-						Session::flash('status', 'danger');
274
-						Session::flash('message', 'Rubric could not be created.');
284
+						$scale = new Scale;
285
+						$scale->description = $scales[$index][$i];
286
+						$scale->min_score = 1 + ($division * $i);
287
+						$scale->max_score = ($division * ($i + 1));
288
+						if ($scale->save()) {
289
+							DB::insert("insert into `template_criterion_scale` (`template_criterion_id`, `scale_id`, `position`) values ({$template_criterion_id->id},{$scale->id}, {$i})");
290
+							DB::commit();
291
+						} else {
292
+							Session::flash('status', 'danger');
293
+							Session::flash('message', 'Rubric could not be created.');
294
+						}
275 295
 					}
276 296
 				}
277 297
 			}

+ 0
- 3
app/models/Scale.php 파일 보기

@@ -4,9 +4,6 @@ use Illuminate\Database\Eloquent\SoftDeletingTrait;
4 4
 
5 5
 class Scale extends Eloquent
6 6
 {
7
-    use SoftDeletingTrait;
8
-    protected $dates = ['deleted_at'];
9
-
10 7
     protected $table = 'scales';
11 8
 
12 9
     public function outcomes()

+ 2
- 1
app/models/Student.php 파일 보기

@@ -16,6 +16,7 @@ class Student extends Eloquent
16 16
 
17 17
   public function assessed_activities()
18 18
   {
19
-  	return $this->belongsToMany('Activity', 'assessments')->withPivot('scores', 'percentage')->withTimestamps();
19
+    //return $this->belongsToMany('Activity', 'assessments')->withPivot('scores', 'percentage')->withTimestamps();
20
+    return $this->belongsToMany('Activity', 'assessments')->withPivot('scores')->withTimestamps();
20 21
   }
21 22
 }

+ 11
- 2
app/views/local/managers/shared/rubrics.blade.php 파일 보기

@@ -371,6 +371,7 @@ function addCriterion()
371 371
 
372 372
     // Check for duplicates
373 373
     var duplicates=false;
374
+    numberOfScale = $('#number_of_scales').find(':selected').val();
374 375
     $('tbody tr').each(function()
375 376
     {
376 377
         if ($(this).data('criterion-id') == id)
@@ -398,7 +399,8 @@ function addCriterion()
398 399
     $.post
399 400
     (
400 401
         "{{ URL::route('fetchCriterionWithTemplate') }}",
401
-        { id: id},
402
+        { id: id,
403
+        numberOfScale: numberOfScale },
402 404
         function(data)
403 405
         {
404 406
             // Append the fetched data
@@ -425,10 +427,17 @@ function addCriterion()
425 427
                 str+='<span>'+data.criterion.name+'</span><sup></sup>'+subcriteria+'</td>';
426 428
             }
427 429
             numberOfScale = $('#number_of_scales').find(':selected').val();
430
+            if(data.scales.length)
428 431
             for(i=0; i<numberOfScale; i++){
429
-                str+='<td class="editable" data-type="textarea"></td>';
432
+                str+='<td class="editable" data-type="textarea">'+data.scales[i].description+'</td>';
433
+                
430 434
           
431 435
             }
436
+            else{
437
+                for(i=0; i<numberOfScale; i++){
438
+                str+='<td class="editable" data-type="textarea"></td>';
439
+            }
440
+        }
432 441
 
433 442
             str +='<th><span class="glyphicon glyphicon-remove icon-btn" aria-hidden="true"></span></th></tr>';
434 443
 

+ 55
- 27
app/views/local/professors/assessment.blade.php 파일 보기

@@ -23,12 +23,8 @@
23 23
             </div>
24 24
             <div class="modal-body">
25 25
                 <table class="table table-bordered">
26
-                    <thead>
27
-                        <th>Beginning (1-2)</th>
28
-                        <th>In Progress (3-4)</th>
29
-                        <th>Good (5-6)</th>
30
-                        <th>Excellent (7-8)</th>
31
-                        <th>Notes</th>
26
+                    <thead id = "criteria-header">;
27
+                        
32 28
                     </thead>
33 29
                     <tbody>
34 30
                         <tr></tr>
@@ -60,7 +56,7 @@
60 56
                     <li>If a student did not complete any work for this activity, select "0" for all columns in that student's row.</li>
61 57
                     <li>If a student dropped the class, select "N/A" (Not Applicable) for all columns in that student's row.</li>
62 58
                     <li>Cells with "N/A" <strong>will not</strong> be used to determine whether a criterion is achieved. Only scores from 0 to 8 will be considered for this purpose.</li>
63
-                    <li><strong>At least one score must be from 1-8.</strong> Otherwise, the 'Publish Assessment' and 'Save as Draft' buttons will be <strong>disabled</strong>. If you want to delete previously saved scores, go back to the activity and click the "Delete Assessment" button.</li>
59
+                    <li>For this activity, <strong>at least one score must be from 1-{{$rubric->max_score}}.</strong> Otherwise, the 'Publish Assessment' and 'Save as Draft' buttons will be <strong>disabled</strong>. If you want to delete previously saved scores, go back to the activity and click the "Delete Assessment" button.</li>
64 60
 
65 61
                 </ul>
66 62
             </div>
@@ -81,14 +77,15 @@
81 77
                     <li>Si un estudiante no completó el trabajo para esta actividad, seleccione "0" en todas las columnas de la fila de ese estudiante.</li>
82 78
                     <li>Si un estudiante se dio de baja, seleccione "N/A" (No Aplica) en todas las columnas de la fila de ese estudiante.</li>
83 79
                     <li>Las celdas con "N/A" <strong>no</strong> serán utilizadas para determinar si un criterio se alcanzó o no. Solamente las puntuaciones del 0 al 8 serán consideradas.</li>
84
-                    <li><strong>Al menos una puntuación deber ser del 1 al 8.</strong> De otra manera, el botón para guardar <strong>se desactivará</strong>. Si quiere borrar los resultados del avalúo, vuelva a la actividad y oprima el botón que dice "Delete Assessment".</li>
80
+                    <li>Para esta actividad, <strong>al menos una puntuación deber ser del 1 al {{$rubric->max_score}}.</strong> De otra manera, el botón para guardar <strong>se desactivará</strong>. Si quiere borrar los resultados del avalúo, vuelva a la actividad y oprima el botón que dice "Delete Assessment".</li>
85 81
 
86 82
 
87 83
                 </ul>
88 84
             </div>
89 85
 
90 86
         </div>
91
-
87
+        <input type='hidden' id='max' name= 'max' value='{{$rubric->max_score}}'>
88
+        <input type ='hidden' id='num_of_scales' name ='num_of_scales' value ='{{$rubric->num_scales}}'>
92 89
         <p id="course">Course: {{{ $course->code }}} {{{ $course->number }}}</p>
93 90
         <p id="section">Section: {{{ $course->section }}}</p>
94 91
         {{ HTML::linkAction('ActivitiesController@show', 'Back to Activity', array($activity->id), array('class'=>'btn btn-default btn-sm pull-right')) }}
@@ -103,8 +100,8 @@
103 100
                                 Student
104 101
                             </div>
105 102
                         </th>
106
-                        @foreach ($rubric_contents as $criterion)
107
-                            <th class="criterion-field" data-criterion-id="{{{ $criterion->id }}}"><div class="th-box">{{ $criterion->name}}</div></th>
103
+                        @foreach ($criterion_rubric as $criterion)
104
+                            <th class="criterion-field" data-criterion-id="{{{ $criterion->id }}}" ><div class="th-box">{{ $criterion->name}}</div></th>
108 105
                         @endforeach
109 106
                         <th>Student Percentage</th>
110 107
                         <th>Comments</th>
@@ -123,13 +120,13 @@
123 120
                         </td>
124 121
 
125 122
                         <!-- For each criterion in the rubric, there's a score field -->
126
-                        @for ($i = 0; $i<sizeof($rubric_contents); $i++)
123
+                        @for ($i = 0; $i<sizeof($criterion_rubric); $i++)
127 124
                             <td class="score-field">
128 125
                                 <select name="" id="" class="form-control" data-toggle="tooltip" data-placement="right" title="{{{ $assessment->name }}}">
129 126
                                 <!-- Option from 0-8 -->
130 127
                                 @for ($j=0; $j<=8; $j++)
131 128
                                     <!-- If the decoded scores with index as the assessment id and second index as criterion id equals the loop index, mark it as selected -->
132
-                                    @if( $j ==  $scores_array[$assessment->id][$rubric_contents[$i]->id])
129
+                                    @if( $j ==  $scores_array[$assessment->id][$criterion_rubric[$i]->criterion_id])
133 130
                                         <option value="{{$j}}" selected="selected">{{ $j }}</option>
134 131
                                     @else
135 132
                                         <option value="{{$j}}">{{ $j }}</option>
@@ -137,7 +134,7 @@
137 134
                                 @endfor
138 135
 
139 136
                                 <!-- N/A option -->
140
-                                @if( $scores_array[$assessment->id][$rubric_contents[$i]->id]=="N/A")
137
+                                @if( $scores_array[$assessment->id][$criterion_rubric[$i]->criterion_id]=="N/A")
141 138
                                     <option value="N/A" selected="selected">N/A</option>
142 139
                                 @else
143 140
                                     <option value="N/A">N/A</option>
@@ -155,18 +152,12 @@
155 152
                 @foreach ($students as $student)
156 153
                     <tr class="student-row">
157 154
                         <td class="student-field" data-student-id={{ $student->id }}>{{{ $student->name }}}</td>
158
-                        @for ($i = 0; $i<sizeof($rubric_contents); $i++)
155
+                        @for ($i = 0; $i<sizeof($criterion_rubric); $i++)
159 156
                             <td class="score-field">
160 157
                                 <select name="" id="" class="form-control" data-toggle="tooltip" data-placement="right" title="{{{ $student->name }}}">
161
-                                    <option value="0">0</option>
162
-                                    <option value="1">1</option>
163
-                                    <option value="2">2</option>
164
-                                    <option value="3">3</option>
165
-                                    <option value="4">4</option>
166
-                                    <option value="5">5</option>
167
-                                    <option value="6">6</option>
168
-                                    <option value="7">7</option>
169
-                                    <option value="8">8</option>
158
+                                    @for($i=0; $i<$rubric->max_score; $i++)
159
+                                    <option value ='{{$i}}'>{{$i}}</option>
160
+                                    @endfor
170 161
                                     <option selected="selected" value="N/A">N/A</option>
171 162
                                 </select>
172 163
                             </td>
@@ -182,7 +173,7 @@
182 173
                     <td>
183 174
                         <strong>Passed Criteria Percentage </strong>
184 175
                     </td>
185
-                    @for ($i = 0; $i<sizeof($rubric_contents); $i++)
176
+                    @for ($i = 0; $i<sizeof($criterion_rubric); $i++)
186 177
                         <td class="total"><strong><span class="total-value"></span><span class="percent-sign">%</span></strong>
187 178
                         </td>
188 179
                     @endfor
@@ -198,7 +189,43 @@
198 189
         </div>
199 190
     </div>
200 191
 </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
+        
201 218
 
219
+        newScaleHeaders+= "<th>Scale "+ (counter +1) + " </th>";
220
+        counter++;
221
+    }
222
+    }
223
+    newScaleHeaders += '<th>Notes</th>';
224
+    
225
+    $("#criterion-header").html(newScaleHeaders);
226
+    
227
+}
228
+    </script>
202 229
 @stop
203 230
 
204 231
 @section('included-js')
@@ -215,7 +242,7 @@
215 242
 // Page load
216 243
 // --------------------------------------------------------------------------
217 244
 
218
-
245
+changeTable();
219 246
 // Enable fixed headers
220 247
 $('#assessment-table').stickyTableHeaders();
221 248
 
@@ -306,6 +333,7 @@ function percentagePerStudent(row)
306 333
     var sum = 0 ;
307 334
     var total = 0;
308 335
     var percentage = 0;
336
+    var max_score = parseInt($('#max').val());
309 337
 
310 338
     row.find('td.score-field').each(function(index)
311 339
     {
@@ -317,7 +345,7 @@ function percentagePerStudent(row)
317 345
         }
318 346
     });
319 347
 
320
-    percentage =((sum/(total*8))*100).toFixed(2);
348
+    percentage =((sum/(total*max_score))*100).toFixed(2);
321 349
 
322 350
     //If percentage is not a number, set it to 0.
323 351
     if(isNaN(percentage))