|
@@ -156,14 +156,20 @@ class CriteriaController extends \BaseController
|
156
|
156
|
else
|
157
|
157
|
$program_id = NULL;
|
158
|
158
|
|
159
|
|
- $saved_criterion = Criterion::withTrashed()
|
|
159
|
+ $saved_criterion = DB::table('criteria')
|
|
160
|
+ ->join('program_criterion', 'program_criterion.criterion_id', '=', 'criteria.id')
|
|
161
|
+ ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
|
|
162
|
+ ->whereIn('program_id', $input['program_id'])
|
|
163
|
+ ->whereIn('objective_id', $input['objective_id'])
|
|
164
|
+ ->whereIn('outcome_id', $input['outcome_id'])
|
160
|
165
|
->where('name', '=', $input['name'])
|
161
|
|
- ->where('outcome_id', '=', $input['outcome_id'])
|
162
|
|
- ->where('program_id', '=', $program_id)
|
|
166
|
+ ->where('subcriteria', '=', $input['subcriteria'])
|
163
|
167
|
->first();
|
164
|
168
|
|
165
|
169
|
|
166
|
170
|
|
|
171
|
+
|
|
172
|
+
|
167
|
173
|
if ($saved_criterion)
|
168
|
174
|
return false;
|
169
|
175
|
else
|
|
@@ -227,16 +233,19 @@ class CriteriaController extends \BaseController
|
227
|
233
|
'outcome_id' => $clean_input['outcome_id'],
|
228
|
234
|
'notes' => $clean_input['notes'],
|
229
|
235
|
'copyright' => $clean_input['copyright'],
|
230
|
|
- 'maximum_score' => $clean_input['maximum_score']
|
|
236
|
+ 'maximum_score' => $clean_input['maximum_score'],
|
|
237
|
+ 'scales' => $clean_input['scale_description'],
|
|
238
|
+ 'objective_id' => $clean_input['objective_id']
|
231
|
239
|
),
|
232
|
240
|
array(
|
233
|
241
|
'name' => 'required|string',
|
234
|
242
|
'subcriteria' => 'string',
|
235
|
243
|
'outcome_id' => 'required|array',
|
236
|
|
-
|
|
244
|
+ 'scales' => 'required|array',
|
237
|
245
|
'notes' => 'string',
|
238
|
246
|
'copyright' => 'string',
|
239
|
|
- 'maximum_score' => 'required|integer'
|
|
247
|
+ 'maximum_score' => 'required|integer',
|
|
248
|
+ 'objective_id' => 'required|array'
|
240
|
249
|
)
|
241
|
250
|
|
242
|
251
|
);
|
|
@@ -281,12 +290,23 @@ class CriteriaController extends \BaseController
|
281
|
290
|
}
|
282
|
291
|
} else {
|
283
|
292
|
// Check criterion uniqueness
|
284
|
|
- /*if (!$this->isCriterionUnique($clean_input)) {
|
285
|
|
- /** Send error message and old data
|
|
293
|
+ if (!$this->isCriterionUnique($clean_input)) {
|
|
294
|
+ /** Send error message and old data*/
|
286
|
295
|
Session::flash('status', 'danger');
|
287
|
296
|
Session::flash('message', 'This criterion is a duplicate of an already saved criterion because its name and associated program are the same.');
|
288
|
|
- return Redirect::to('criteria')->withInput();
|
289
|
|
- }*/
|
|
297
|
+
|
|
298
|
+ $role = Auth::user()['role'];
|
|
299
|
+ switch ($role) {
|
|
300
|
+ case 1:
|
|
301
|
+ return Redirect::to('criteria')->withInput();
|
|
302
|
+
|
|
303
|
+ case 2:
|
|
304
|
+ return Redirect::to('school-criteria')->withInput();
|
|
305
|
+
|
|
306
|
+ case 3:
|
|
307
|
+ return Redirect::to('program-criteria')->withInput();
|
|
308
|
+ }
|
|
309
|
+ }
|
290
|
310
|
|
291
|
311
|
/** Instantiate new criterion */
|
292
|
312
|
$criterion = new Criterion;
|
|
@@ -296,8 +316,8 @@ class CriteriaController extends \BaseController
|
296
|
316
|
|
297
|
317
|
//gabriel añadió aqui
|
298
|
318
|
|
299
|
|
- //$criterion->number_of_scales = $clean_input['number_of_scales'];
|
300
|
|
- //$criterion->maximum_score = $clean_input['maximum_score'];
|
|
319
|
+ $criterion->num_scales = $clean_input['number_of_scales'];
|
|
320
|
+ $criterion->max_score = $clean_input['maximum_score'];
|
301
|
321
|
|
302
|
322
|
if (Input::get('copyright'))
|
303
|
323
|
$criterion->copyright = $clean_input['copyright'];
|
|
@@ -319,27 +339,34 @@ class CriteriaController extends \BaseController
|
319
|
339
|
}
|
320
|
340
|
|
321
|
341
|
for ($i = 0; $i < sizeof($clean_input['scale_description']); $i++) {
|
322
|
|
- $scale = new Scale;
|
323
|
342
|
|
324
|
|
- $position = $i;
|
325
|
|
- $scale->description = $clean_input['scale_description'][$i];
|
|
343
|
+ $existing_scale = DB::table('scales')->where('description', $clean_input['scale_description'][$i])
|
|
344
|
+ ->first();
|
|
345
|
+ if ($existing_scale) {
|
|
346
|
+ DB::insert("insert_into `criterion_scale` (`criterion_id`, `scale_id`, `position`) values({$criterionId},{$existing_scale->id},{$i})");
|
|
347
|
+ } else {
|
|
348
|
+ $scale = new Scale;
|
326
|
349
|
|
|
350
|
+ $position = $i;
|
|
351
|
+ $scale->description = $clean_input['scale_description'][$i];
|
327
|
352
|
|
328
|
|
- if ($scale->save()) {
|
329
|
|
- DB::insert("insert into `criterion_scale` (`criterion_id`, `scale_id`, `position`) values({$criterionId},{$scale->id}, {$position})");
|
330
|
|
- } else {
|
331
|
|
- Session::flash('status', 'danger');
|
332
|
|
- Session::flash('message', '<p>Error creating the Scales</p>');
|
333
|
|
- $role = Auth::user()['role'];
|
334
|
|
- switch ($role) {
|
335
|
|
- case 1:
|
336
|
|
- return Redirect::to('criteria')->withInput();
|
337
|
|
-
|
338
|
|
- case 2:
|
339
|
|
- return Redirect::to('school-criteria')->withInput();
|
340
|
|
-
|
341
|
|
- case 3:
|
342
|
|
- return Redirect::to('program-criteria')->withInput();
|
|
353
|
+
|
|
354
|
+ if ($scale->save()) {
|
|
355
|
+ DB::insert("insert into `criterion_scale` (`criterion_id`, `scale_id`, `position`) values({$criterionId},{$scale->id}, {$position})");
|
|
356
|
+ } else {
|
|
357
|
+ Session::flash('status', 'danger');
|
|
358
|
+ Session::flash('message', '<p>Error creating the Scales</p>');
|
|
359
|
+ $role = Auth::user()['role'];
|
|
360
|
+ switch ($role) {
|
|
361
|
+ case 1:
|
|
362
|
+ return Redirect::to('criteria')->withInput();
|
|
363
|
+
|
|
364
|
+ case 2:
|
|
365
|
+ return Redirect::to('school-criteria')->withInput();
|
|
366
|
+
|
|
367
|
+ case 3:
|
|
368
|
+ return Redirect::to('program-criteria')->withInput();
|
|
369
|
+ }
|
343
|
370
|
}
|
344
|
371
|
}
|
345
|
372
|
}
|
|
@@ -436,10 +463,10 @@ class CriteriaController extends \BaseController
|
436
|
463
|
|
437
|
464
|
$clean_input['copyright'] = trim(preg_replace('/\t+/', '', Input::get('copyright')));
|
438
|
465
|
$clean_input['notes'] = trim(preg_replace('/\t+/', '', Input::get('notes')));
|
439
|
|
- /* $clean_input['maximum_score'] = (int) Input::get('assoc_maximum_score');
|
440
|
|
- $clean_input['scale_title'] = Input::get('assoc_title');
|
|
466
|
+ $clean_input['maximum_score'] = (int) Input::get('assoc_maximum_score');
|
|
467
|
+ //$clean_input['scale_title'] = Input::get('assoc_title');
|
441
|
468
|
$clean_input['scale_description'] = Input::get('assoc_scales');
|
442
|
|
- $clean_input['number_of_scales'] = sizeof($clean_input['scale_title']);*/
|
|
469
|
+ $clean_input['number_of_scales'] = sizeof($clean_input['scale_description']);
|
443
|
470
|
|
444
|
471
|
|
445
|
472
|
return $clean_input;
|
|
@@ -482,19 +509,29 @@ class CriteriaController extends \BaseController
|
482
|
509
|
} else {
|
483
|
510
|
|
484
|
511
|
// // Check criterion uniqueness
|
485
|
|
- // if(!$this->isCriterionUnique($clean_input, $criterion))
|
486
|
|
- // {
|
487
|
|
- // /** Send error message and old data */
|
488
|
|
- // Session::flash('status', 'danger');
|
489
|
|
- // Session::flash('message', 'This criterion is a duplicate of an already saved criterion because its name, assoaciated school or program, and progress indicators are the same.');
|
490
|
|
- // return Redirect::to('criteria')->withInput();
|
491
|
|
- // }
|
|
512
|
+ if (!$this->isCriterionUnique($clean_input, $criterion)) {
|
|
513
|
+ /** Send error message and old data */
|
|
514
|
+ Session::flash('status', 'danger');
|
|
515
|
+ Session::flash('message', 'This criterion is a duplicate of an already saved criterion because its name, assoaciated school or program, and progress indicators are the same.');
|
|
516
|
+ $role = Auth::user()['role'];
|
|
517
|
+ switch ($role) {
|
|
518
|
+ case 1:
|
|
519
|
+ return Redirect::to('objective')->withInput();
|
|
520
|
+
|
|
521
|
+ case 2:
|
|
522
|
+ return Redirect::to('school-objective')->withInput();
|
|
523
|
+
|
|
524
|
+ case 3:
|
|
525
|
+ return Redirect::to('program-objective')->withInput();
|
|
526
|
+ }
|
|
527
|
+ }
|
492
|
528
|
|
493
|
529
|
/** Set info */
|
494
|
530
|
$criterion->name = $clean_input['name'];
|
495
|
531
|
$criterion->subcriteria = $clean_input['subcriteria'];
|
496
|
532
|
|
497
|
|
-
|
|
533
|
+ $criterion->num_scales = $clean_input['number_of_scales'];
|
|
534
|
+ $criterion->max_score = $clean_input['maximum_score'];
|
498
|
535
|
|
499
|
536
|
|
500
|
537
|
|
|
@@ -535,31 +572,42 @@ class CriteriaController extends \BaseController
|
535
|
572
|
DB::insert("insert into `criterion_objective_outcome` (`objective_id`, `outcome_id`, `criterion_id`) values ({$objective_id},{$outcome_id}, {$criterionId})");
|
536
|
573
|
}
|
537
|
574
|
}
|
|
575
|
+
|
538
|
576
|
/*DB::delete("delete from `scales` where id in (select scale_id id from criterion_scale where criterion_id = {$criterionId})");
|
|
577
|
+*/
|
|
578
|
+ DB::delete("delete from criterion_scale where criterion_id = {$criterionId}");
|
|
579
|
+ for ($i = 0; $i < sizeof($clean_input['scale_description']); $i++) {
|
539
|
580
|
|
540
|
|
- for ($i = 0; $i < sizeof($clean_input['scale_title']); $i++) {
|
541
|
|
- $scale = new Scale;
|
542
|
|
- $scale->title = $clean_input['scale_title'][$i];
|
543
|
|
- $scale->position = $i + 1;
|
544
|
|
- $scale->description = $clean_input['scale_description'][$i];
|
545
|
|
- if ($scale->save()) {
|
546
|
|
- DB::insert("insert into `criterion_scale` (`criterion_id`, `scale_id`) values({$criterionId},{$scale->id})");
|
|
581
|
+ $existing_scale = DB::table('scales')->where('description', $clean_input['scale_description'][$i])
|
|
582
|
+ ->first();
|
|
583
|
+ if ($existing_scale) {
|
|
584
|
+ DB::insert("insert_into `criterion_scale` (`criterion_id`, `scale_id`, `position`) values({$criterionId},{$existing_scale->id},{$i})");
|
547
|
585
|
} else {
|
548
|
|
- Session::flash('status', 'danger');
|
549
|
|
- Session::flash('message', '<p>Error creating the Scales</p>');
|
550
|
|
- $role = Auth::user()['role'];
|
551
|
|
- switch ($role) {
|
552
|
|
- case 1:
|
553
|
|
- return Redirect::to('objective')->withInput();
|
554
|
|
-
|
555
|
|
- case 2:
|
556
|
|
- return Redirect::to('school-objective')->withInput();
|
557
|
|
-
|
558
|
|
- case 3:
|
559
|
|
- return Redirect::to('program-objective')->withInput();
|
|
586
|
+ $scale = new Scale;
|
|
587
|
+
|
|
588
|
+ $position = $i;
|
|
589
|
+ $scale->description = $clean_input['scale_description'][$i];
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+ if ($scale->save()) {
|
|
593
|
+ DB::insert("insert into `criterion_scale` (`criterion_id`, `scale_id`, `position`) values({$criterionId},{$scale->id}, {$position})");
|
|
594
|
+ } else {
|
|
595
|
+ Session::flash('status', 'danger');
|
|
596
|
+ Session::flash('message', '<p>Error creating the Scales</p>');
|
|
597
|
+ $role = Auth::user()['role'];
|
|
598
|
+ switch ($role) {
|
|
599
|
+ case 1:
|
|
600
|
+ return Redirect::to('criteria')->withInput();
|
|
601
|
+
|
|
602
|
+ case 2:
|
|
603
|
+ return Redirect::to('school-criteria')->withInput();
|
|
604
|
+
|
|
605
|
+ case 3:
|
|
606
|
+ return Redirect::to('program-criteria')->withInput();
|
|
607
|
+ }
|
560
|
608
|
}
|
561
|
609
|
}
|
562
|
|
- }*/
|
|
610
|
+ }
|
563
|
611
|
foreach ($clean_input['program_id'] as $program_id) {
|
564
|
612
|
DB::insert("insert into `program_criterion` (`criterion_id`, `program_id`) values({$criterionId},{$program_id})");
|
565
|
613
|
}
|