Pārlūkot izejas kodu

Antes de volver al merge

Gabriel Santiago Plaza 3 gadus atpakaļ
vecāks
revīzija
f75627ee58

+ 1
- 0
.gitignore Parādīt failu

@@ -12,3 +12,4 @@ app/config/app.php
12 12
 app/config/database.php
13 13
 node_modules/
14 14
 app/config/
15
+app/controllers/AuthController.php

+ 60
- 9
app/controllers/ActivitiesController.php Parādīt failu

@@ -169,19 +169,25 @@ class ActivitiesController extends \BaseController
169 169
         Log::info($activity);
170 170
         $criterion_rubric = DB::table('criteria')
171 171
             ->join("criterion_rubric", "criterion_rubric.criterion_id", "=", "criteria.id")
172
-            ->where('criterion_rubric.rubric_id', '=', $rubric->id)->get();
172
+            ->join("activity_criterion", "criteria.id", '=', 'activity_criterion.criterion_id')
173
+            ->where("activity_criterion.activity_id", '=', $activity->id)
174
+            ->where('criterion_rubric.rubric_id', '=', $rubric->id)
175
+            ->select('criteria.name', 'criteria.id as criterion_id', 'criteria.subcriteria')
176
+            ->addSelect('activity_criterion.activity_id', 'activity_criterion.weight', 'activity_criterion.id as activity_criterion_id')
177
+            ->addSelect('criterion_rubric.rubric_id', 'criterion_rubric.id as rubric_criterion_id')
178
+            ->addSelect('criterion_rubric.copyright', 'criterion_rubric.notes')
179
+            ->get();
173 180
         Log::info($criterion_rubric);
174 181
         foreach ($criterion_rubric as $index => $singleCR) {
175 182
             $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)
183
+                ->where('rubric_criteria_scale.rubric_criterion_id', '=', $singleCR->rubric_criterion_id)
177 184
                 ->orderBy('position')
178 185
                 ->lists('description'));
179 186
         }
180 187
         $criterion_rubric_ids = DB::table('criterion_rubric')->where('rubric_id', '=', $rubric->id)->lists('id');
181 188
         Log::info($rubric);
182 189
         Log::info($criterion_rubric);
183
-        $scales = DB::table('scales')->join('rubric_criteria_scale', 'rubric_criteria_scale.scale_id', '=', 'scales.id')
184
-            ->whereIn('rubric_criteria_scale.rubric_criterion_id', $criterion_rubric_ids)->get();
190
+
185 191
 
186 192
 
187 193
 
@@ -190,16 +196,21 @@ class ActivitiesController extends \BaseController
190 196
         $activity_criterion_ids = DB::table('activity_criterion')->where("activity_id", '=', $activity->id)->lists('id');
191 197
         Log::info($activity_criterion_ids);
192 198
         $assessments = DB::table('assessments')->join('students', 'assessments.student_id', '=', 'students.id')->whereIn('activity_criterion_id', $activity_criterion_ids)->orderBy('assessments.id', 'asc')->get();
193
-
199
+        Log::info($assessments);
194 200
         // Decode the scores (blade workaround)
195 201
         $scores_array = array();
202
+
196 203
         foreach ($assessments as $index => $assessment) {
197
-            $scores_array[$assessment->id] = json_decode($assessment->scores, true);
204
+            $scores_array[$assessment->student_id][$index] = $assessment->score;
205
+            $scores_array[$assessment->student_id]['comments'] = DB::table('activity_student')->where('student_id', '=', $assessment->student_id)
206
+                ->where("activity_id", '=', $activity->id)
207
+                ->select('comments')->first()->comments;
198 208
         }
199
-        Log::info(sizeof($criterion_rubric));
209
+
210
+        Log::info($scores_array);
200 211
 
201 212
 
202
-        return View::make('local.professors.assessment', compact('activity', 'title', 'students', 'course', 'criterion_rubric', 'assessments', 'scores_array', 'rubric', 'scales'));
213
+        return View::make('local.professors.assessment', compact('activity', 'title', 'students', 'course', 'criterion_rubric', 'assessments', 'scores_array', 'rubric'));
203 214
     }
204 215
 
205 216
     public function saveAssessment()
@@ -208,9 +219,49 @@ class ActivitiesController extends \BaseController
208 219
             $exception = DB::transaction(function () {
209 220
                 DB::transaction(function () {
210 221
                     // Student assessment data
211
-                    $student_data = json_decode(Input::get('student_scores'));
212 222
 
223
+                    $activity_id = Input::get('activity_id');
224
+                    $student_data = json_decode(Input::get('student_info'));
225
+                    $weights = json_decode(Input::get('weights'));
226
+                    Log::info(json_encode($weights));
227
+                    Log::info(json_encode($student_data));
228
+
229
+                    foreach ($student_data as $index => $student_dict) {
230
+                        $student_id = $student_dict->studentId;
231
+                        foreach ($student_dict->activity_crit_id as $act_crit_id => $score) {
232
+                            if (DB::table('assessments')->where('student_id', '=', $student_id)
233
+                                ->where('activity_criterion_id', '=', $act_crit_id)
234
+                                ->first()
235
+                            ) {
236
+                                DB::table('assessments')->where('student_id', '=', $student_id)
237
+                                    ->where('activity_criterion_id', '=', $act_crit_id)
238
+                                    ->update(array('score' => $score));
239
+                            } else {
240
+                                DB::insert("insert into assessments (`activity_criterion_id`, `student_id`, `score`) values ({$act_crit_id}, {$student_id}, {$score})");
241
+                            }
242
+                        }
243
+                        if (DB::table('activity_student')
244
+                            ->where('student_id', '=', $student_id)->where('activity_id', '=', $activity_id)
245
+                            ->first()
246
+                        ) {
247
+                            DB::table('activity_student')
248
+                                ->where('student_id', '=', $student_id)->where('activity_id', '=', $activity_id)
249
+                                ->update(array('comments' => $student_dict->comments));
250
+                        } else {
251
+                            DB::insert("insert into activity_student (`activity_id`, `student_id`, `comments`) values ({$activity_id}, {$student_id}, '{$student_dict->comments}')");
252
+                        }
253
+                    }
254
+                    $activity_draft = Input::get('draft');
255
+
256
+                    foreach ($weights as $act_crit => $weigh) {
257
+                        DB::update("update activity_criterion set weight = {$weigh} where id = {$act_crit}");
258
+                    }
259
+                    DB::update("update activities set draft = {$activity_draft} where id = {$activity_id}");
213 260
                     // Outcome count
261
+                    Session::flash('status', 'success');
262
+                    Session::flash('message', 'Assessment Saved. To add transforming actions click "Transforming Actions".');
263
+                    return action('ActivitiesController@show', array(Input::get('activity_id')));
264
+
214 265
                     $outcomeCount = Outcome::all()->count();
215 266
 
216 267
 

+ 29
- 22
app/controllers/RubricsController.php Parādīt failu

@@ -94,7 +94,8 @@ class RubricsController extends \BaseController
94 94
         $rubric->user_id = Auth::id();
95 95
         $rubric->num_scales = count($scales[0]);
96 96
         $rubric->max_score = Input::get('max_score');
97
-        $division = $rubric->max_score / count($scales[0]);
97
+        $defaultWeight = round(100 / $rubric->num_scales, 2);
98
+
98 99
         if ($rubric->save()) {
99 100
 
100 101
             // Process activity
@@ -115,9 +116,7 @@ class RubricsController extends \BaseController
115 116
 
116 117
 
117 118
                 for ($i = 0; $i < count($scales[$index]); $i++) {
118
-                    $scale =  Scale::where('description', '=', $scales[$index][$i])
119
-                        ->where('max_score', '=', ($division * ($i + 1)))
120
-                        ->where("min_score", '=', (1 + ($division * $i)))->first();
119
+                    $scale =  Scale::where('description', '=', $scales[$index][$i])->first();
121 120
                     Log::info($scale);
122 121
                     if ($scale) {
123 122
                         DB::insert("insert into `rubric_criteria_scale` (`rubric_criterion_id`, `scale_id`, `position`) values ({$rubric_criterion_id->id},{$scale->id}, {$i})");
@@ -125,8 +124,7 @@ class RubricsController extends \BaseController
125 124
                     } else {
126 125
                         $scale = new Scale;
127 126
                         $scale->description = $scales[$index][$i];
128
-                        $scale->min_score = 1 + ($division * $i);
129
-                        $scale->max_score = ($division * ($i + 1));
127
+
130 128
                         if ($scale->save()) {
131 129
                             DB::insert("insert into `rubric_criteria_scale` (`rubric_criterion_id`, `scale_id`, `position`) values ({$rubric_criterion_id->id},{$scale->id}, {$i})");
132 130
                             DB::commit();
@@ -136,8 +134,9 @@ class RubricsController extends \BaseController
136 134
                         }
137 135
                     }
138 136
                 }
137
+
139 138
                 $activity_id = Input::get("activity_id");
140
-                DB::insert("insert into `activity_criterion` (`activity_id`,`criterion_id`) values ({$activity_id}, {$criterion_id})");
139
+                DB::insert("insert into `activity_criterion` (`activity_id`,`criterion_id`, `weight`) values ({$activity_id}, {$criterion_id}, {$defaultWeight})");
141 140
                 DB::commit();
142 141
             }
143 142
             Session::flash('status', 'success');
@@ -183,7 +182,8 @@ class RubricsController extends \BaseController
183 182
 
184 183
         $rubric->num_scales = count($scales[0]);
185 184
         $rubric->max_score = Input::get('max_score');
186
-        $division = $rubric->max_score / count($scales[0]);
185
+        $defaultWeight = round(100 / $rubric->num_scales, 2);
186
+
187 187
 
188 188
         DB::beginTransaction();
189 189
 
@@ -271,12 +271,14 @@ class RubricsController extends \BaseController
271 271
         $course->save();
272 272
         Log::info('entré6???');
273 273
         DB::delete("delete from criterion_rubric where rubric_id ={$rubric->id}");
274
+        DB::delete("delete from activity_criterion where activity_id = {$activity->id}");
274 275
         foreach ($criteria as $index => $criterion_id) {
275 276
             if (
276 277
 
277 278
                 DB::insert("insert into criterion_rubric (`rubric_id`, `criterion_id`) values ({$rubric->id}, {$criterion_id}) ")
279
+                &&  DB::insert("insert into `activity_criterion` (`activity_id`,`criterion_id`, `weight`) values ({$activity->id}, {$criterion_id}, {$defaultWeight})")
278 280
             ) {
279
-                Log::info("AHH");
281
+
280 282
                 $rubric_criterion_id =  DB::table('criterion_rubric')
281 283
                     ->where('rubric_id', '=', $rubric->id)
282 284
                     ->where('criterion_id', '=', $criterion_id)
@@ -284,9 +286,7 @@ class RubricsController extends \BaseController
284 286
 
285 287
                 foreach ($scales[$index] as $in => $scale) {
286 288
                     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();
289
+                    $new_scale =  Scale::where('description', '=', $scale)->first();
290 290
 
291 291
                     if ($new_scale) {
292 292
                         DB::insert("insert into `rubric_criteria_scale` (`rubric_criterion_id`, `scale_id`, `position`) values ({$rubric_criterion_id->id},{$new_scale->id}, {$in})");
@@ -294,8 +294,6 @@ class RubricsController extends \BaseController
294 294
                     } else {
295 295
                         $new_scale = new Scale;
296 296
                         $new_scale->description = $scales[$index][$in];
297
-                        $new_scale->min_score = 1 + ($division * $in);
298
-                        $new_scale->max_score = ($division * ($in + 1));
299 297
                         if ($new_scale->save()) {
300 298
                             DB::insert("insert into `rubric_criteria_scale` (`rubric_criterion_id`, `scale_id`, `position`) values ({$rubric_criterion_id->id},{$new_scale->id}, {$in})");
301 299
                             DB::commit();
@@ -366,6 +364,7 @@ class RubricsController extends \BaseController
366 364
             ->join('criterion_rubric', 'criterion_rubric.criterion_id', '=', 'criteria.id')
367 365
             ->where('criterion_rubric.rubric_id', '=', $activity->rubric[0]->id)
368 366
             ->get();
367
+        Log::info($criterion_rubric);
369 368
 
370 369
         foreach ($criterion_rubric as $single_cr) {
371 370
             $single_cr->scales = json_encode(DB::table('scales')
@@ -434,15 +433,23 @@ class RubricsController extends \BaseController
434 433
 
435 434
     public function fetchRubricCriterion()
436 435
     {
437
-        $rubric = Rubric::findOrFail(Input::get('rubric_id'));
438
-        $criterion_id = Input::get('criterion_id');
436
+        $rubric = DB::table("rubric_criteria_scale")
437
+            ->join('scales', 'scales.id', '=', 'rubric_criteria_scale.scale_id')
438
+            ->where("rubric_criterion_id", '=', Input::get('rubric_criterion_id'))->get();
439
+        Log::info($rubric);
439 440
 
440
-        $rubric_contents = json_decode($rubric->contents);
441
+        $rubric["criteria"] = DB::table("criteria")
442
+            ->join("criterion_rubric", 'criterion_rubric.criterion_id', '=', 'criteria.id')
443
+            ->where("criterion_rubric.id", '=', Input::get('rubric_criterion_id'))
444
+            ->select('name', 'criterion_rubric.notes')
445
+            ->first();
446
+        return json_encode($rubric);
441 447
 
442
-        foreach ($rubric_contents as $key => $criterion) {
443
-            if ($criterion->id == $criterion_id) {
444
-                return json_encode($criterion);
445
-            }
446
-        }
448
+        //$rubric_contents = json_decode($rubric->contents);
449
+
450
+        //foreach ($rubric_contents as $key => $criterion) {
451
+        //    if ($criterion->id == $criterion_id) {
452
+        //        return json_encode($criterion);
453
+        //    }
447 454
     }
448 455
 }

+ 9
- 11
app/controllers/TemplatesController.php Parādīt failu

@@ -145,7 +145,7 @@ class TemplatesController extends \BaseController
145 145
 
146 146
 		$template->num_scales = count($scales[0]);
147 147
 		$template->max_score = $max_score;
148
-		$division = $max_score / count($scales[0]);
148
+
149 149
 		if ($template->save()) {
150 150
 			$templateId = $template->id;
151 151
 			foreach ($criteria as $index => $criterion_id) {
@@ -154,9 +154,7 @@ 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 =  Scale::where('description', '=', $scales[$index][$i])
158
-						->where('max_score', '=', ($division * ($i + 1)))
159
-						->where("min_score", '=', (1 + ($division * $i)))->first();
157
+					$scale =  Scale::where('description', '=', $scales[$index][$i])->first();
160 158
 					Log::info($scale);
161 159
 					if ($scale) {
162 160
 						DB::insert("insert into `template_criterion_scale` (`template_criterion_id`, `scale_id`, `position`) values ({$template_criterion_id->id},{$scale->id}, {$i})");
@@ -164,8 +162,7 @@ class TemplatesController extends \BaseController
164 162
 					} else {
165 163
 						$scale = new Scale;
166 164
 						$scale->description = $scales[$index][$i];
167
-						$scale->min_score = 1 + ($division * $i);
168
-						$scale->max_score = ($division * ($i + 1));
165
+
169 166
 						if ($scale->save()) {
170 167
 							DB::insert("insert into `template_criterion_scale` (`template_criterion_id`, `scale_id`, `position`) values ({$template_criterion_id->id},{$scale->id}, {$i})");
171 168
 							DB::commit();
@@ -261,7 +258,7 @@ class TemplatesController extends \BaseController
261 258
 		Log::info(Input::all());
262 259
 		$template->num_scales = count($scales[0]);
263 260
 		$template->max_score = $max_score;
264
-		$division = $max_score / count($scales[0]);
261
+		//$division = $max_score / count($scales[0]);
265 262
 
266 263
 		if ($template->save()) {
267 264
 			$templateId = $template->id;
@@ -274,8 +271,9 @@ class TemplatesController extends \BaseController
274 271
 				DB::delete("delete from template_criterion_scale where template_criterion_id ={$template_criterion_id->id}");
275 272
 				for ($i = 0; $i < count($scales[$index]); $i++) {
276 273
 					$scale =  Scale::where('description', '=', $scales[$index][$i])
277
-						->where('max_score', '=', ($division * ($i + 1)))
278
-						->where("min_score", '=', (1 + ($division * $i)))->first();
274
+						//->where('max_score', '=', ($division * ($i + 1)))
275
+						//->where("min_score", '=', (1 + ($division * $i)))
276
+						->first();
279 277
 					Log::info($scale);
280 278
 					if ($scale) {
281 279
 						DB::insert("insert into `template_criterion_scale` (`template_criterion_id`, `scale_id`, `position`) values ({$template_criterion_id->id},{$scale->id}, {$i})");
@@ -283,8 +281,8 @@ class TemplatesController extends \BaseController
283 281
 					} else {
284 282
 						$scale = new Scale;
285 283
 						$scale->description = $scales[$index][$i];
286
-						$scale->min_score = 1 + ($division * $i);
287
-						$scale->max_score = ($division * ($i + 1));
284
+						//$scale->min_score = 1 + ($division * $i);
285
+						//$scale->max_score = ($division * ($i + 1));
288 286
 						if ($scale->save()) {
289 287
 							DB::insert("insert into `template_criterion_scale` (`template_criterion_id`, `scale_id`, `position`) values ({$template_criterion_id->id},{$scale->id}, {$i})");
290 288
 							DB::commit();

+ 181
- 157
app/views/local/professors/assessment.blade.php Parādīt failu

@@ -61,7 +61,7 @@
61 61
                     <li>If a particular criterion was assessed but the student did not complete the necessary work, you must select "0". This <strong>will</strong> affect the student's score.</li>
62 62
                     <li>If a student did not complete any work for this activity, select "0" for all columns in that student's row.</li>
63 63
                     <li>If a student dropped the class, select "N/A" (Not Applicable) for all columns in that student's row.</li>
64
-                    <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>
64
+                    <li>Cells with "N/A" <strong>will not</strong> be used to determine whether a criterion is achieved. Only scores from 0 to {{$rubric->max_score}} will be considered for this purpose.</li>
65 65
                     <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>
66 66
 
67 67
                 </ul>
@@ -82,7 +82,7 @@
82 82
                     <li>Si un criterio particular fue evaluado, pero el estudiante no completó el trabajo necesario, debe seleccionar "0". Esto <strong>sí</strong> afectará la puntuación final del estudiante.</li>
83 83
                     <li>Si un estudiante no completó el trabajo para esta actividad, seleccione "0" en todas las columnas de la fila de ese estudiante.</li>
84 84
                     <li>Si un estudiante se dio de baja, seleccione "N/A" (No Aplica) en todas las columnas de la fila de ese estudiante.</li>
85
-                    <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>
85
+                    <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 {{$rubric->max_score}} serán consideradas.</li>
86 86
                     <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>
87 87
 
88 88
 
@@ -105,13 +105,8 @@
105 105
                     </th>
106 106
                     @foreach ($criterion_rubric as $index => $criterion)
107 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%">
108
+                        
109
+                        Weight<input class="form-control" id="weight-{{$index}}" name='weight[]' type="text"  value="{{$criterion->weight}}" data-activity-criterion-id="{{$criterion->activity_criterion_id}}">
115 110
                         </div></th>
116 111
                 @endforeach
117 112
                 </tr>
@@ -122,7 +117,7 @@
122 117
                             </div>
123 118
                         </th>
124 119
                         @foreach ($criterion_rubric as $criterion)
125
-                            <th class="criterion-field" data-criterion-id="{{{ $criterion->criterion_id }}}" ><div class="th-box">{{ $criterion->name}}</div></th>
120
+                            <th class="criterion-field" data-activity-criterion-id = "{{$criterion->activity_criterion_id}}"data-rubric-criterion-id = "{{$criterion->rubric_criterion_id}}" data-criterion-id="{{{ $criterion->criterion_id }}}" ><div class="th-box">{{ $criterion->name}}</div></th>
126 121
                         @endforeach
127 122
                         <th>Student Percentage</th>
128 123
                         <th>Student % per Weight</th>
@@ -134,21 +129,21 @@
134 129
             <!-- If the activity was assessed, load the assessment. Otherwise load empty sheet -->
135 130
             @if(sizeof($assessments)!=0)
136 131
                 <!-- For each assessment -->
137
-                @foreach ($assessments as $assessment)
132
+                @foreach ($students as $student)
138 133
                     <tr class="student-row">
139 134
                         <!-- Fetch student name -->
140
-                        <td class="student-field" data-student-id="{{ $assessment->student_id }}">
141
-                            {{{ $assessment->name }}}
135
+                        <td class="student-field" data-student-id="{{ $student->id }}">
136
+                            {{{ $student->name }}}
142 137
                         </td>
143 138
 
144 139
                         <!-- For each criterion in the rubric, there's a score field -->
145 140
                         @for ($i = 0; $i<sizeof($criterion_rubric); $i++)
146 141
                             <td class="score-field">
147
-                                <select name="" id="" class="form-control" data-toggle="tooltip" data-placement="right" title="{{{ $assessment->name }}}">
142
+                                <select name="" id="" class="form-control" data-toggle="tooltip" data-placement="right" title="{{{ $student->name }}}">
148 143
                                 <!-- Option from 0-8 -->
149
-                                @for ($j=0; $j<=8; $j++)
144
+                                @for ($j=0; $j<=$rubric->max_score; $j++)
150 145
                                     <!-- If the decoded scores with index as the assessment id and second index as criterion id equals the loop index, mark it as selected -->
151
-                                    @if( $j ==  $scores_array[$assessment->id][$criterion_rubric[$i]->criterion_id])
146
+                                    @if( $j ==  $scores_array[$student->id][$i])
152 147
                                         <option value="{{$j}}" selected="selected">{{ $j }}</option>
153 148
                                     @else
154 149
                                         <option value="{{$j}}">{{ $j }}</option>
@@ -156,7 +151,7 @@
156 151
                                 @endfor
157 152
 
158 153
                                 <!-- N/A option -->
159
-                                @if( $scores_array[$assessment->id][$criterion_rubric[$i]->criterion_id]=="N/A")
154
+                                @if( $scores_array[$student->id][$i]=="N/A")
160 155
                                     <option value="N/A" selected="selected">N/A</option>
161 156
                                 @else
162 157
                                     <option value="N/A">N/A</option>
@@ -164,9 +159,10 @@
164 159
                                 </select>
165 160
                             </td>
166 161
                         @endfor
167
-                        <td class="percentage">{{{ $assessment->percentage }}}</td>
162
+                        <td class="percentage"></td>
163
+                        <td class="percentage-per-weight"></td>
168 164
                         <td class="">
169
-                            <textarea class="comments full-textarea" placeholder="Max. 255 characters" maxLength="255" >{{ $assessment->comments }}</textarea>
165
+                            <textarea class="comments full-textarea" placeholder="Max. 255 characters" maxLength="255" >{{ $scores_array[$student->id]["comments"] }}</textarea>
170 166
                         </td>
171 167
                      </tr>
172 168
                 @endforeach
@@ -175,7 +171,7 @@
175 171
                     <tr class="student-row">
176 172
                         <td class="student-field" data-student-id={{ $student->id }}>{{{ $student->name }}}</td>
177 173
                         @for ($i = 0; $i<sizeof($criterion_rubric); $i++)
178
-                            <td class="score-field">
174
+                            <td class="score-field" data-weight = '1'>
179 175
                                 <select name="" id="" class="form-control" data-toggle="tooltip" data-placement="right" title="{{{ $student->name }}}">
180 176
                                     @for($j=0; $j<=$rubric->max_score; $j++)
181 177
                                     <option value ='{{$j}}'>{{$j}}</option>
@@ -185,7 +181,7 @@
185 181
                             </td>
186 182
                         @endfor
187 183
                         <td class="percentage"></td>
188
-                        <td class="percentage-per-w"></td>
184
+                        <td class="percentage-per-weight"></td>
189 185
                         <td class="comments"><textarea class="comments full-textarea" placeholder="Max. 255 characters" maxLength="255" ></textarea></td>
190 186
                      </tr>
191 187
                 @endforeach
@@ -212,8 +208,147 @@
212 208
         </div>
213 209
     </div>
214 210
 </div>
211
+<script>
212
+$('#button-submit-assessment, #button-draft-assessment').on('click', function(e)
213
+{
214
+
215
+    var draft = 0;
216
+
217
+    if($(this).hasClass('draft'))
218
+        draft = 1;
219
+
220
+    var expected_points = parseInt($('#expected_points').text());
221
+    var expected_percentage = parseInt($('#expected_percentage').text());
222
+
223
+    //Prevent page refresh
224
+    e.preventDefault();
225
+
226
+    // Row in the database
227
+    var activity_id   =  $('#activity').data('activity-id');
228
+
229
+    var student_info = new Object();
230
+
231
+    // Object to hold the score sum of each criterion
232
+    var criteriaSumObject = new Object();
233
+
234
+    // Object to hold % of students that passed each criterion
235
+    var CriteriaAchievedPercentage = new Object();
236
+
237
+    // Object to hold all student evaluations
238
+    var studentAssessments = new Array();
239
+
240
+    var weights = new Object();
241
+
242
+    $('input[name="weight[]"]').each(function (index){
243
+        activity_criterion_id = $(this).data('activity-criterion-id');
244
+        weights[activity_criterion_id] = $(this).val();
245
+    });
246
+
247
+    // Iterate through all students
248
+    $('#assessment-table tbody tr').each(function( index )
249
+    {   
250
+
251
+        student_info[index] = new Object()
252
+        student_info[index].studentId = $(this).find('.student-field').data('student-id');
253
+        student_info[index].activity_crit_id = new Object();
254
+
255
+       /* var ScoresObject     = new Object();        // Scores column in database
256
+        var CriterionObject = new Object();     // Objects inside ScoresObject
257
+        var SingleStudentAssessment = new Object();
258
+        SingleStudentAssessment.student_id = $(this).find('.student-field').data('student-id');
259
+        */
260
+        // For each criterion, store the score in array
261
+        $(this).children('td.score-field').each(function(index2)
262
+        {
263
+            // Table cell with a score
264
+            var scoreField = $(this);
265
+
266
+            // Criterion being evaluated in current iteration
267
+            activity_criterion_id = $('.criterion-field').eq(index2).data('activity-criterion-id');
268
+            student_info[index].activity_crit_id[activity_criterion_id] = scoreField.children('select').find(':selected').val();
269
+
270
+            // Score in the cell
271
+            //var score = scoreField.children('select').find(':selected').val();
272
+
273
+            // Store the score in the scores Object
274
+            //ScoresObject[criterion_id]=score;
275
+
276
+            // Initialize the index for the sum object, if it's undefined
277
+            //if(typeof(criteriaSumObject[criterion_id]) == 'undefined')
278
+            //{
279
+            //    criteriaSumObject[criterion_id]=0;
280
+            //}
281
+
282
+            // Add to this criterion's total
283
+            //criteriaSumObject[criterion_id]+=parseInt(score);
284
+        });
285
+        student_info[index].comments = $.trim($(this).find('.comments').val());
286
+
287
+        //SingleStudentAssessment.scores = ScoresObject;
288
+        //SingleStudentAssessment.percentage = $(this).find('.percentage').text();
289
+        //SingleStudentAssessment.comments = $.trim($(this).find('.comments').val());
290
+        // console.log('comment '+index+': '+SingleStudentAssessment.comments);
291
+        // console.log('student object: '+JSON.stringify(SingleStudentAssessment));
292
+
293
+        //var clone = jQuery.extend({}, SingleStudentAssessment);
294
+        //studentAssessments.push(clone);
295
+
296
+
297
+    });
298
+
299
+    // console.log('students: '+JSON.stringify(studentAssessments));
300
+    // console.log('total points per criteria: '+JSON.stringify(criteriaSumObject));
301
+
302
+    // Iterate through all evaluated criteria, determining which were achieved
303
+    // by comparing the completion percentage to the expected percentage
304
+    /*var CriteriaAchievedResults = new Object();
305
+
306
+
307
+    $('.total').each(function(index)
308
+    {
309
+        var id = $('.criterion-field').eq(index).data('criterion-id');
310
+
311
+        CriteriaAchievedPercentage[id] = parseFloat($(this).find('span').text());
312
+
313
+        //Set whether criterion was achieved (1) or not (0)
314
+        if(CriteriaAchievedPercentage[id] >= expected_percentage)
315
+        {
316
+            CriteriaAchievedResults[id]=1;
317
+        }
318
+        else if (CriteriaAchievedPercentage[id] < expected_percentage)
319
+        {
320
+            CriteriaAchievedResults[id]=0;
321
+        }
322
+        else
323
+        {
324
+            CriteriaAchievedResults[id]=null;
325
+        }
326
+
327
+    });
328
+*/
329
+    // console.log('criteria percentages: '+JSON.stringify(CriteriaAchievedPercentage));
330
+    // console.log('criteria achieved results: '+JSON.stringify(CriteriaAchievedResults));
331
+
332
+
333
+    // Save activity to the database
334
+    $.post
335
+    (
336
+        "{{ URL::action('ActivitiesController@saveAssessment') }}",
337
+        {
338
+            activity_id: activity_id,
339
+            draft: draft,
340
+            weights: JSON.stringify(weights),
341
+        
342
+            student_info: JSON.stringify(student_info)
343
+        },
344
+        function(data)
345
+        {
346
+            location.replace(data);
347
+        }
348
+    );
215 349
 
216
-    
350
+});
351
+    </script>
217 352
 @stop
218 353
 
219 354
 @section('included-js')
@@ -230,7 +365,7 @@
230 365
 // Page load
231 366
 // --------------------------------------------------------------------------
232 367
 
233
-changeTable();
368
+
234 369
 // Enable fixed headers
235 370
 $('#assessment-table').stickyTableHeaders();
236 371
 
@@ -322,6 +457,8 @@ function percentagePerStudent(row)
322 457
     var total = 0;
323 458
     var percentage = 0;
324 459
     var max_score = parseInt($('#max').val());
460
+    sum_of_weight = 0;
461
+    per_of_weight =0;
325 462
 
326 463
     row.find('td.score-field').each(function(index)
327 464
     {
@@ -330,9 +467,12 @@ function percentagePerStudent(row)
330 467
         {
331 468
             sum += val;
332 469
             total+=1;
470
+            per_of_weight += val * parseInt($('#weight-'+index).val()); 
471
+            sum_of_weight += parseInt($('#weight-'+index).val());
333 472
         }
334
-    });
335 473
 
474
+    });
475
+    percentage_per_weight = (100 *(per_of_weight/(max_score*sum_of_weight))).toFixed(2);
336 476
     percentage =((sum/(total*max_score))*100).toFixed(2);
337 477
 
338 478
     //If percentage is not a number, set it to 0.
@@ -345,6 +485,13 @@ function percentagePerStudent(row)
345 485
     {
346 486
         row.find('.percentage').html('<strong>'+percentage+'%</strong>');
347 487
     }
488
+    if(isNaN(percentage_per_weight)){
489
+        percentage_per_weight="N/A";
490
+        row.find('.percentage-per-weight').html('<strong>'+percentage_per_weight+'</strong>');
491
+    }
492
+    else{
493
+        row.find('.percentage-per-weight').html('<strong>'+percentage_per_weight+'%</strong>');
494
+    }
348 495
 
349 496
 
350 497
 }
@@ -398,131 +545,9 @@ $('select').on('change', function(e)
398 545
     percentagePerStudent($(this).closest('tr'));
399 546
     toggleSaveButton();
400 547
 });
401
-
548
+//LA LINEA DONDE VA, 410
402 549
 // Submit button is clicked
403
-$('#button-submit-assessment, #button-draft-assessment').on('click', function(e)
404
-{
405
-
406
-    var draft = 0;
407
-
408
-    if($(this).hasClass('draft'))
409
-        draft = 1;
410
-
411
-    var expected_points = parseInt($('#expected_points').text());
412
-    var expected_percentage = parseInt($('#expected_percentage').text());
413
-
414
-    //Prevent page refresh
415
-    e.preventDefault();
416
-
417
-    // Row in the database
418
-    var activity_id   =  $('#activity').data('activity-id');
419
-
420
-    // Object to hold the score sum of each criterion
421
-    var criteriaSumObject = new Object();
422
-
423
-    // Object to hold % of students that passed each criterion
424
-    var CriteriaAchievedPercentage = new Object();
425
-
426
-    // Object to hold all student evaluations
427
-    var studentAssessments = new Array();
428
-
429
-    // Iterate through all students
430
-    $('#assessment-table tbody tr').each(function( index )
431
-    {
432
-        var ScoresObject     = new Object();        // Scores column in database
433
-        var CriterionObject = new Object();     // Objects inside ScoresObject
434
-        var SingleStudentAssessment = new Object();
435
-        SingleStudentAssessment.student_id = $(this).find('.student-field').data('student-id');
436
-
437
-        // For each criterion, store the score in array
438
-        $(this).children('td.score-field').each(function(index)
439
-        {
440
-            // Table cell with a score
441
-            var scoreField = $(this);
442
-
443
-            // Criterion being evaluated in current iteration
444
-            var criterion_id = $('.criterion-field').eq(index).data('criterion-id');
445
-
446
-            // Score in the cell
447
-            var score = scoreField.children('select').find(':selected').val();
448
-
449
-            // Store the score in the scores Object
450
-            ScoresObject[criterion_id]=score;
451
-
452
-            // Initialize the index for the sum object, if it's undefined
453
-            if(typeof(criteriaSumObject[criterion_id]) == 'undefined')
454
-            {
455
-                criteriaSumObject[criterion_id]=0;
456
-            }
457
-
458
-            // Add to this criterion's total
459
-            criteriaSumObject[criterion_id]+=parseInt(score);
460
-        });
461
-
462
-        SingleStudentAssessment.scores = ScoresObject;
463
-        SingleStudentAssessment.percentage = $(this).find('.percentage').text();
464
-        SingleStudentAssessment.comments = $.trim($(this).find('.comments').val());
465
-        // console.log('comment '+index+': '+SingleStudentAssessment.comments);
466
-        // console.log('student object: '+JSON.stringify(SingleStudentAssessment));
467
-
468
-        var clone = jQuery.extend({}, SingleStudentAssessment);
469
-        studentAssessments.push(clone);
470
-
471
-
472
-    });
473
-
474
-    // console.log('students: '+JSON.stringify(studentAssessments));
475
-    // console.log('total points per criteria: '+JSON.stringify(criteriaSumObject));
476
-
477
-    // Iterate through all evaluated criteria, determining which were achieved
478
-    // by comparing the completion percentage to the expected percentage
479
-    var CriteriaAchievedResults = new Object();
480
-
481
-
482
-    $('.total').each(function(index)
483
-    {
484
-        var id = $('.criterion-field').eq(index).data('criterion-id');
485
-
486
-        CriteriaAchievedPercentage[id] = parseFloat($(this).find('span').text());
487
-
488
-        //Set whether criterion was achieved (1) or not (0)
489
-        if(CriteriaAchievedPercentage[id] >= expected_percentage)
490
-        {
491
-            CriteriaAchievedResults[id]=1;
492
-        }
493
-        else if (CriteriaAchievedPercentage[id] < expected_percentage)
494
-        {
495
-            CriteriaAchievedResults[id]=0;
496
-        }
497
-        else
498
-        {
499
-            CriteriaAchievedResults[id]=null;
500
-        }
501
-
502
-    });
503
-
504
-    // console.log('criteria percentages: '+JSON.stringify(CriteriaAchievedPercentage));
505
-    // console.log('criteria achieved results: '+JSON.stringify(CriteriaAchievedResults));
506
-
507
-
508
-    // Save activity to the database
509
-    $.post
510
-    (
511
-        "{{ URL::action('ActivitiesController@saveAssessment') }}",
512
-        {
513
-            activity_id: activity_id,
514
-            draft: draft,
515
-            criteria_achieved_percentage: JSON.stringify(CriteriaAchievedPercentage),
516
-            criteria_achievement: JSON.stringify(CriteriaAchievedResults),
517
-            student_scores: JSON.stringify(studentAssessments),
518
-        },
519
-        function(data)
520
-        {
521
-            location.replace(data);
522
-        }
523
-    );
524 550
 
525
-});
526 551
 
527 552
 // Language button is clicked
528 553
 $('#button-language').on('click', function(e)
@@ -539,25 +564,24 @@ $('.criterion-field').on('click', function()
539 564
         type: 'POST',
540 565
         url: "{{ URL::action('RubricsController@fetchRubricCriterion') }}",
541 566
         data: {
542
-            rubric_id: $(this).closest('table').data('rubric-id'),
543
-            criterion_id: $(this).data('criterion-id'),
567
+            rubric_criterion_id: $(this).data('rubric-criterion-id')
544 568
         },
545 569
         success: function(data)
546 570
         {
547 571
             data = JSON.parse(data);
548
-            $('.modal-title').html(data.name);
549
-
572
+            $('.modal-title').html(data.criteria.name);
573
+            descriptions = '';
550 574
             $('.modal-body tbody tr').empty();
575
+            for(i =0; i<{{$rubric->num_scales}}; i++){
576
+                descriptions += '<td>'+data[i].description+'</td>'
577
+            }
551 578
             $('.modal-body tbody tr').append
552 579
             (
553
-                '<td>'+data.description12+'</td>'
554
-                +'<td>'+data.description34+'</td>'
555
-                +'<td>'+data.description56+'</td>'
556
-                +'<td>'+data.description78+'</td>'
580
+                descriptions
557 581
             );
558 582
 
559
-            if(data.notes!=null)
560
-                $('.modal-body tbody tr').append('<td>'+data.notes+'</td>');
583
+            if(data.criteria.notes!=null)
584
+                $('.modal-body tbody tr').append('<td>'+data.criteria.notes+'</td>');
561 585
             else
562 586
                 $('.modal-body tbody tr').append('<td></td>');
563 587
 

+ 1
- 1
app/views/local/professors/viewrubric.blade.php Parādīt failu

@@ -59,7 +59,7 @@
59 59
               <span>{{{ $criterion->name }}}</span><sup></sup>
60 60
               @if(property_exists($criterion, 'subcriteria'))
61 61
                 <ul class="list-unstyled">
62
-                  @foreach($criterion->subcriteria as $subcriterion)
62
+                  @foreach(json_decode($criterion->subcriteria) as $subcriterion)
63 63
                       <li>{{ $subcriterion }}</li>
64 64
                   @endforeach
65 65
                 </ul>