Browse Source

Feature de objectives

parent
commit
0a44bf0ba1

+ 16
- 11
app/controllers/CriteriaController.php View File

@@ -257,7 +257,11 @@ class CriteriaController extends \BaseController
257 257
             ->where('criterion_id', $criteria_id)
258 258
             ->orderBy('position')
259 259
             ->get();
260
-        $criterion->program =  DB::table('program_criterion')->where('criterion_id', $criteria_id)->get();
260
+        $criterion->program =  DB::table('program_criterion_objective_outcome as poco')
261
+            ->join('criterion_objective_outcome as cobo', 'cobo.id', '=', 'poco.cri_obj_out_id')
262
+            ->where('criterion_id', $criteria_id)
263
+            ->select('poco.program_id')
264
+            ->distinct()->get();
261 265
         $criterion->activity_criterion = DB::table('assessments')
262 266
             ->join('activity_criterion', 'activity_criterion.id', '=', 'assessments.activity_criterion_id')
263 267
             ->where('activity_criterion.criterion_id', $criteria_id)
@@ -336,8 +340,9 @@ class CriteriaController extends \BaseController
336 340
 
337 341
 
338 342
         $saved_criterion = DB::table('criteria')
339
-            ->join('program_criterion', 'program_criterion.criterion_id', '=', 'criteria.id')
340 343
             ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
344
+            ->join('program_criterion_objective_outcome', 'program_criterion_objective_outcome.cri_obj_out_id', '=', 'criterion_objective_outcome.id')
345
+
341 346
             ->join('criterion_scale', 'criterion_scale.criterion_id', '=', 'criteria.id')
342 347
             ->whereIn('program_id', $input['program_id'])
343 348
             ->whereIn('objective_id', $objectives)
@@ -461,7 +466,7 @@ class CriteriaController extends \BaseController
461 466
      */
462 467
     public function create()
463 468
     {
464
-        $clean_input = $this->cleanInput();	
469
+        $clean_input = $this->cleanInput();
465 470
 
466 471
         Log::info(json_encode($clean_input));
467 472
 
@@ -489,7 +494,7 @@ class CriteriaController extends \BaseController
489 494
                     return Redirect::to('criteria')->withInput();
490 495
 
491 496
                 case 2:
492
-//                     Log::info(Input::all());
497
+                    //                     Log::info(Input::all());
493 498
                     return Redirect::to('school-criteria')->withInput();
494 499
 
495 500
                 case 3:
@@ -630,9 +635,9 @@ class CriteriaController extends \BaseController
630 635
                 }*/
631 636
 
632 637
 
633
-                foreach ($clean_input['program_id'] as $program_id) {
634
-                    DB::insert("insert into `program_criterion` (`criterion_id`, `program_id`) values({$criterionId},{$program_id})");
635
-                }
638
+                //foreach ($clean_input['program_id'] as $program_id) {
639
+                //    DB::insert("insert into `program_criterion` (`criterion_id`, `program_id`) values({$criterionId},{$program_id})");
640
+                //}
636 641
 
637 642
                 Session::flash('status', 'success');
638 643
                 Session::flash('message', 'Criterion created: "' . $criterion->name . '".');
@@ -873,7 +878,7 @@ class CriteriaController extends \BaseController
873 878
                 $criterionId = $criterion->id;
874 879
                 DB::table('criterion_objective_outcome as cobo')
875 880
                     ->join('program_criterion_objective_outcome as poco', 'poco.cri_obj_out_id', '=', 'cobo.id')
876
-                    ->where($criterionId)
881
+                    ->where('cobo.criterion_id', $criterionId)
877 882
                     ->delete();
878 883
                 // DB::delete("delete from `criterion_objective_outcome` where `criterion_id` ={$criterionId}");
879 884
                 DB::delete("delete from `program_criterion` where `criterion_id` ={$criterionId}");
@@ -964,9 +969,9 @@ class CriteriaController extends \BaseController
964 969
 
965 970
                         break;
966 971
                 }*/
967
-                foreach ($clean_input['program_id'] as $program_id) {
968
-                    DB::insert("insert into `program_criterion` (`criterion_id`, `program_id`) values({$criterionId},{$program_id})");
969
-                }
972
+                //foreach ($clean_input['program_id'] as $program_id) {
973
+                //    DB::insert("insert into `program_criterion` (`criterion_id`, `program_id`) values({$criterionId},{$program_id})");
974
+                //}
970 975
 
971 976
 
972 977
 

+ 2
- 2
app/controllers/Objective2Controller.php View File

@@ -660,9 +660,9 @@ class Objective2Controller extends \BaseController
660 660
 				if ($clean_input['agreement']) {
661 661
 					DB::table('criterion_objective_outcome')
662 662
 						//QUE PONEMOS CORRADA
663
-						//->join('program_criterion_objective_outcome', 'criterion_objective_outcome.id', "=", 'program_criterion_objective_outcome.cri_obj_out_id')
663
+						->join('program_criterion_objective_outcome', 'criterion_objective_outcome.id', "=", 'program_criterion_objective_outcome.cri_obj_out_id')
664 664
 
665
-						->join('program_criterion', 'criterion_objective_outcome.criterion_id', "=", 'program_criterion.criterion_id')
665
+						//->join('program_criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', "=", 'program_criterion_objective_outcome.criterion_id')
666 666
 						->whereIn('program_id', $clean_input['program_id'])
667 667
 						->whereIn('outcome_id', $clean_input['outcome_id'])
668 668
 						->where('objective_id', '=', 0)

+ 10
- 5
app/controllers/ObjectivesController.php View File

@@ -242,8 +242,8 @@ class ObjectivesController extends \BaseController
242 242
     }
243 243
 
244 244
     $criteria_scales = DB::table('criteria')
245
-      ->join('criterion_objective_outcome as cobo', 'criterion_id', '=', 'criteria.id')
246
-      ->join('program_criterion', 'cobo.criterion_id', '=', 'program_criterion.criterion_id')
245
+      ->join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'criteria.id')
246
+      ->join('program_criterion_objective_outcome as poco', 'cobo.id', '=', 'poco.cri_obj_out_id')
247 247
       ->whereIn('program_id', $program_ids)
248 248
       ->where('objective_id', $objective->id)
249 249
       ->select('num_scales')
@@ -255,7 +255,7 @@ class ObjectivesController extends \BaseController
255 255
 
256 256
       $objective->criteria[$num_scales] = DB::table('criteria')
257 257
         ->join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'criteria.id')
258
-        ->join('program_criterion', 'program_criterion.criterion_id', '=', 'criteria.id')
258
+        ->join('program_criterion_objective_outcome as poco', 'cobo.id', '=', 'poco.cri_obj_out_id')
259 259
         ->whereIn('program_id', $program_ids)
260 260
         ->where('objective_id', $objective->id)
261 261
         ->where('num_scales', $num_scales)
@@ -265,8 +265,13 @@ class ObjectivesController extends \BaseController
265 265
 
266 266
       foreach ($objective->criteria[$num_scales] as $criteria) {
267 267
         $criteria->programs = DB::table('programs')
268
-          ->join('program_criterion', 'programs.id', '=', 'program_criterion.program_id')
268
+          ->join('program_criterion_objective_outcome as poco', 'poco.program_id', '=', 'programs.id')
269
+          ->join('criterion_objective_outcome as cobo', 'cobo.id', '=', 'poco.cri_obj_out_id')
270
+
271
+
269 272
           ->where('criterion_id', $criteria->criterion_id)
273
+          ->select("programs.*")
274
+          ->distinct()
270 275
           ->get();
271 276
 
272 277
         $criteria->outcomes = DB::table('outcomes')
@@ -289,4 +294,4 @@ class ObjectivesController extends \BaseController
289 294
       'objective' => $objective
290 295
     );
291 296
   }
292
-}
297
+}

+ 78
- 134
app/controllers/OutcomesController.php View File

@@ -14,7 +14,7 @@ class OutcomesController extends \BaseController
14 14
     {
15 15
         $title = "Learning Outcomes";
16 16
         $outcomes = Outcome::withTrashed()->orderBy('id', 'ASC')->get();
17
-//         $outcomes = Outcome::withTrashed()->orderBy('name', 'ASC')->get();
17
+        //         $outcomes = Outcome::withTrashed()->orderBy('name', 'ASC')->get();
18 18
         $schools = School::orderBy('name', 'ASC')->get();
19 19
         // $semesters_ids = Session::get('semesters_ids');
20 20
         // $semesters = Semester::whereIn('id',$semesters_ids)->get();
@@ -343,28 +343,26 @@ class OutcomesController extends \BaseController
343 343
     public function delete()
344 344
     {
345 345
         $outcomeArray = json_decode(Input::get('outcomeArray'), true);
346
-// 		Log::info("delete".json_encode($outcomeArray));
347
-		$outcome = Outcome::withTrashed()
348
-			->where('id', '=', $outcomeArray['id'])
349
-			->firstOrFail();
350
-// 		Log::info("delete2".json_encode($outcome));
351
-		$outcome->forceDelete();
352
-// 		Log::info("sal".json_encode($sal));
353
-// 		if($sal)
354
-		{
355
-			Session::flash('status', 'success');
356
-			Session::flash('message', 'Learning Outcome deleted.');
357
-			
358
-		}
359
-
360
-	}
361
-    
346
+        // 		Log::info("delete".json_encode($outcomeArray));
347
+        $outcome = Outcome::withTrashed()
348
+            ->where('id', '=', $outcomeArray['id'])
349
+            ->firstOrFail();
350
+        // 		Log::info("delete2".json_encode($outcome));
351
+        $outcome->forceDelete();
352
+        // 		Log::info("sal".json_encode($sal));
353
+        // 		if($sal)
354
+        {
355
+            Session::flash('status', 'success');
356
+            Session::flash('message', 'Learning Outcome deleted.');
357
+        }
358
+    }
359
+
362 360
     public function updateMore()
363 361
     {
364 362
         $outcomeArray = json_decode(Input::get('outcomeArray'), true);
365 363
         Session::flash('status', 'success');
366 364
         Session::flash('message', 'Learning Outcomes updated.');
367
-		Log::info("Ahora1".json_encode($outcomeArray));
365
+        Log::info("Ahora1" . json_encode($outcomeArray));
368 366
 
369 367
         foreach ($outcomeArray as $outcomeObject) {
370 368
 
@@ -375,9 +373,9 @@ class OutcomesController extends \BaseController
375 373
                     'definition' => $outcomeObject['definition'],
376 374
                     'expected_outcome' => $outcomeObject['expected_outcome'],
377 375
                     'activation_date' => $outcomeObject['activation_date'],
378
-//                     'deactivation_date' => (isset($outcomeObject['deactivation_date'])?$outcomeObject['deactivation_date']:NULL),
376
+                    //                     'deactivation_date' => (isset($outcomeObject['deactivation_date'])?$outcomeObject['deactivation_date']:NULL),
379 377
                     'level' => $outcomeObject['level'],
380
-//                     'new_outcome_id'=>$outcomeObject['new_outcome_id']
378
+                    //                     'new_outcome_id'=>$outcomeObject['new_outcome_id']
381 379
                     // TODO- validar los otros 3 valores
382 380
                 ),
383 381
                 array(
@@ -385,9 +383,9 @@ class OutcomesController extends \BaseController
385 383
                     'definition' => 'required',
386 384
                     'expected_outcome' => 'required|numeric',
387 385
                     'activation_date' => 'required|date',
388
-//                     'deactivation_date' => 'sometimes|required|date',
386
+                    //                     'deactivation_date' => 'sometimes|required|date',
389 387
                     'level' => 'required|numeric'
390
-//                     'new_outcome_id' => 'required|numeric'
388
+                    //                     'new_outcome_id' => 'required|numeric'
391 389
                     // TODO- los requisitos de los otros 3 valores
392 390
                 )
393 391
             );
@@ -401,18 +399,15 @@ class OutcomesController extends \BaseController
401 399
                     $outcome->definition = $outcomeObject['definition'];
402 400
                     $outcome->expected_outcome = $outcomeObject['expected_outcome'];
403 401
                     $outcome->activation_date = $outcomeObject['activation_date'];
404
-                    if($outcomeObject['deactivation_date']!="")
405
-                    {
406
-                    	$outcome->deactivation_date = $outcomeObject['deactivation_date'];
407
-	                    if(isset($outcomeObject['new_outcome_id']))$outcome->new_outcome_id = $outcomeObject['new_outcome_id'];
408
-                    }
409
-                    else 
410
-                    {
411
-                    	$outcome->deactivation_date = NULL;
412
-                    	$outcome->new_outcome_id=NULL;
402
+                    if ($outcomeObject['deactivation_date'] != "") {
403
+                        $outcome->deactivation_date = $outcomeObject['deactivation_date'];
404
+                        if (isset($outcomeObject['new_outcome_id'])) $outcome->new_outcome_id = $outcomeObject['new_outcome_id'];
405
+                    } else {
406
+                        $outcome->deactivation_date = NULL;
407
+                        $outcome->new_outcome_id = NULL;
413 408
                     }
414 409
                     $outcome->level = $outcomeObject['level'];
415
-		Log::info("Ahora2".json_encode($outcome));
410
+                    Log::info("Ahora2" . json_encode($outcome));
416 411
 
417 412
                     $outcome->save();
418 413
 
@@ -448,22 +443,24 @@ class OutcomesController extends \BaseController
448 443
 
449 444
     public function fetchCriteria()
450 445
     {
451
-        // 		var_dump((Input::get('filter')));
452
-        // 		exit();
446
+        $criteria_not_available = DB::table('criterion_objective_outcome')
447
+            ->where('objective_id', '=', 0)
448
+            ->lists('criterion_id');
449
+        $criteria = DB::table('criteria')
450
+            ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id');
453 451
         if (Input::get('filter')) {
454 452
             switch (Input::get('filter')) {
455 453
                 case 'all':
456
-                    $criteria = DB::table('criteria')
454
+                    /*$criteria = DB::table('criteria')
457 455
                         ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
458 456
                         ->where('criterion_objective_outcome.outcome_id', '=', Input::get('outcome_id'))
459 457
                         ->where('criterion_objective_outcome.objective_id', '=', Input::get('objective_id'))
460 458
                         ->where('criteria.num_scales', '=', Input::get('num_scales'))
461
-                        ->where('criteria.max_score', '=', Input::get('maximum'))
462
-                        ->select('criterion_id as id', 'name')
463
-                        ->orderBy('name', 'ASC')
464
-                        ->get();
459
+                        ->where('criteria.max_score', '=', Input::get('maximum'))*/
460
+
465 461
 
466
-                    foreach ($criteria as $criterion) {
462
+
463
+                    /*foreach ($criteria as $criterion) {
467 464
                         $criterion->program_ids = json_encode(DB::table('program_criterion')
468 465
                             ->where('criterion_id', $criterion->id)
469 466
                             ->lists('program_id'));
@@ -475,6 +472,7 @@ class OutcomesController extends \BaseController
475 472
                             ->lists('text');
476 473
                     }
477 474
                     return $criteria;
475
+                    break;*/
478 476
                     break;
479 477
 
480 478
                 case 'school':
@@ -483,17 +481,15 @@ class OutcomesController extends \BaseController
483 481
 
484 482
                         // Fetch all the programs whose school is the user's
485 483
                         $program_ids = DB::table('programs')->where('school_id', Auth::user()->school_id)->lists('id');
486
-                        $criteria = DB::table('criteria')
487
-                            ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
488
-                            ->join('program_criterion', 'program_criterion.criterion_id', '=', 'criteria.id')
489
-                            ->where('criterion_objective_outcome.outcome_id', '=', Input::get('outcome_id'))
490
-                            ->where('criterion_objective_outcome.objective_id', '=', Input::get('objective_id'))
491
-                            ->where('criteria.num_scales', '=', Input::get('num_scales'))
492
-                            ->where('criteria.max_score', '=', Input::get('maximum'))
493
-                            ->whereIn('program_criterion.program_id', $program_ids)
494
-                            ->select('criterion_id as id', 'name')
495
-                            ->orderBy('name', 'ASC')
496
-                            ->get();
484
+                    } else {
485
+                        $program_ids = DB::table('programs')->where('school_id', Auth::user()->programs[0]->school->id)->lists('id');
486
+                    }
487
+                    $criteria = $criteria
488
+                        ->join('program_criterion_objective_outcome as poco', 'poco.cri_obj_out_id', '=', 'criterion_objective_outcome.id')
489
+
490
+                        ->whereIn('poco.program_id', $program_ids);
491
+
492
+                    /*
497 493
                         foreach ($criteria as $criterion) {
498 494
                             $criterion->program_ids = json_encode(DB::table('program_criterion')
499 495
                                 ->where('criterion_id', $criterion->id)
@@ -506,57 +502,21 @@ class OutcomesController extends \BaseController
506 502
                                 ->lists('text'));
507 503
                         }
508 504
                         // Return all criteria belonging to any of those programs
509
-                        return $criteria;
510
-                    }
505
+                        return $criteria;*/
511 506
 
512
-                    // If pcoord
513
-                    else {
514 507
 
515
-                        // Fetch all the programs from the user's school;
516
-                        // Fetch all the programs from the user's school;
517
-                        $program_ids = DB::table('programs')->where('school_id', Auth::user()->programs[0]->school->id)->lists('id');
518 508
 
519
-                        $criteria = DB::table('criteria')
520
-                            ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
521
-                            ->join('program_criterion', 'program_criterion.criterion_id', '=', 'criteria.id')
522
-                            ->where('criterion_objective_outcome.outcome_id', '=', Input::get('outcome_id'))
523
-                            ->where('criterion_objective_outcome.objective_id', '=', Input::get('objective_id'))
524
-                            ->where('criteria.num_scales', '=', Input::get('num_scales'))
525
-                            ->where('criteria.max_score', '=', Input::get('maximum'))
526
-                            ->whereIn('program_criterion.program_id', $program_ids)
527
-                            ->select('criterion_id as id', 'name')
528
-                            ->orderBy('name', 'ASC')
529
-                            ->get();
530 509
 
531
-                        foreach ($criteria as $criterion) {
532
-                            $criterion->program_ids = json_encode(DB::table('program_criterion')
533
-                                ->where('criterion_id', $criterion->id)
534
-                                ->lists('program_id'));
535
-                            $criterion->objectives = json_encode(DB::table('criterion_objective_outcome')
536
-                                ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
537
-                                ->where('criterion_id', $criterion->id)
538
-                                ->select('objectives.*')
539
-                                ->distinct()
540
-                                ->lists('text'));
541
-                        }
542
-                        return $criteria;
543
-                    }
544 510
 
545 511
                     break;
546 512
 
547 513
                 case 'program':
548
-                    $criteria = DB::table('criteria')
549
-                        ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
550
-                        ->join('program_criterion', 'program_criterion.criterion_id', '=', 'criteria.id')
551
-                        ->where('criterion_objective_outcome.outcome_id', '=', Input::get('outcome_id'))
552
-                        ->where('criterion_objective_outcome.objective_id', '=', Input::get('objective_id'))
553
-                        ->where('criteria.num_scales', '=', Input::get('num_scales'))
554
-                        ->where('criteria.max_score', '=', Input::get('maximum'))
555
-                        ->whereIn('program_criterion.program_id', Auth::user()->programs->lists('id'))
556
-                        ->select('criterion_id as id', 'name')
557
-                        ->orderBy('name', 'ASC')
558
-                        ->get();
559
-                    foreach ($criteria as $criterion) {
514
+
515
+                    $criteria = $criteria
516
+                        ->join('program_criterion_objective_outcome as poco', 'poco.cri_obj_out_id', '=', 'criterion_objective_outcome.id')
517
+
518
+                        ->whereIn('poco.program_id', Auth::user()->programs->lists('id'));
519
+                    /*foreach ($criteria as $criterion) {
560 520
                         $criterion->program_ids = json_encode(DB::table('program_criterion')
561 521
                             ->where('criterion_id', $criterion->id)
562 522
                             ->lists('program_id'));
@@ -567,21 +527,13 @@ class OutcomesController extends \BaseController
567 527
                             ->distinct()
568 528
                             ->lists('text'));
569 529
                     }
570
-                    return $criteria;
530
+                    return $criteria;*/
571 531
                     break;
572 532
 
573 533
                 default:
574
-                    $criteria = DB::table('criteria')
575
-                        ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
576
-                        ->where('criterion_objective_outcome.outcome_id', '=', Input::get('outcome_id'))
577
-                        ->where('criterion_objective_outcome.objective_id', '=', Input::get('objective_id'))
578
-                        ->where('criteria.num_scales', '=', Input::get('num_scales'))
579
-                        ->where('criteria.max_score', '=', Input::get('maximum'))
580
-                        ->select('criterion_id as id', 'name')
581
-                        ->orderBy('name', 'ASC')
582
-                        ->get();
583 534
 
584
-                    foreach ($criteria as $criterion) {
535
+
536
+                    /*foreach ($criteria as $criterion) {
585 537
                         $criterion->program_ids = json_encode(DB::table('program_criterion')
586 538
                             ->where('criterion_id', $criterion->id)
587 539
                             ->lists('program_id'));
@@ -592,33 +544,21 @@ class OutcomesController extends \BaseController
592 544
                             ->distinct()
593 545
                             ->lists('text'));
594 546
                     }
595
-                    return $criteria;
547
+                    return $criteria;*/
596 548
                     break;
597 549
             }
598
-        } else {
599
-            $criteria = DB::table('criteria')
600
-                ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
601
-                ->where('criterion_objective_outcome.outcome_id', '=', Input::get('outcome_id'))
602
-                ->where('criterion_objective_outcome.objective_id', '=', Input::get('objective_id'))
603
-                ->where('criteria.num_scales', '=', Input::get('num_scales'))
604
-                ->where('criteria.max_score', '=', Input::get('maximum'))
605
-                ->select('criterion_id as id', 'name')
606
-                ->orderBy('name', 'ASC')
607
-                ->get();
608
-
609
-            foreach ($criteria as $criterion) {
610
-                $criterion->program_ids = json_encode(DB::table('program_criterion')
611
-                    ->where('criterion_id', $criterion->id)
612
-                    ->lists('program_id'));
613
-                $criterion->objectives = json_encode(DB::table('criterion_objective_outcome')
614
-                    ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
615
-                    ->where('criterion_id', $criterion->id)
616
-                    ->select('objectives.*')
617
-                    ->distinct()
618
-                    ->lists('text'));
619
-            }
620
-            return $criteria;
621 550
         }
551
+
552
+        $criteria = $criteria
553
+            ->where('criterion_objective_outcome.outcome_id', '=', Input::get('outcome_id'))
554
+            ->where('criterion_objective_outcome.objective_id', '=', Input::get('objective_id'))
555
+            ->where('criteria.num_scales', '=', Input::get('num_scales'))
556
+            ->where('criteria.max_score', '=', Input::get('maximum'))
557
+            ->whereNotIn('criteria.id', $criteria_not_available)
558
+            ->select('criterion_id as id', 'name')
559
+            ->orderBy('name', 'ASC')
560
+            ->get();
561
+        return $criteria;
622 562
     }
623 563
 
624 564
     /**
@@ -715,7 +655,7 @@ class OutcomesController extends \BaseController
715 655
         $diferent_levels = DB::table('criterion_objective_outcome')
716 656
             ->join('criteria', 'criteria.id', '=', 'criterion_objective_outcome.criterion_id')
717 657
             // GASP, añadí programa, para que solo muestre niveles de criterios del programa
718
-            ->join('program_criterion', 'criteria.id', '=', 'program_criterion.criterion_id')
658
+            ->join('program_criterion_objective_outcome', 'criterion_objective_outcome.id', '=', 'program_criterion_objective_outcome.cri_obj_out_id')
719 659
             ->whereIn('program_id', $program_ids)
720 660
             ->where('criterion_objective_outcome.outcome_id', $id)
721 661
             ->distinct('criteria.num_scales')
@@ -739,8 +679,8 @@ class OutcomesController extends \BaseController
739 679
             //                 ->get();
740 680
             $outcome_criterias = DB::table('criterion_objective_outcome')
741 681
                 ->join('criteria', 'criteria.id', '=', 'criterion_objective_outcome.criterion_id')
742
-                ->join('program_criterion', 'program_criterion.criterion_id', '=', 'criteria.id')
743
-                ->whereIn('program_criterion.program_id', $program_ids)
682
+                ->join('program_criterion_objective_outcome', 'criterion_objective_outcome.id', '=', 'program_criterion_objective_outcome.cri_obj_out_id')
683
+                ->whereIn('program_criterion_objective_outcome.program_id', $program_ids)
744 684
                 ->where('criterion_objective_outcome.outcome_id', $id)
745 685
                 ->where('criteria.num_scales', $level)
746 686
                 ->select('criteria.id', 'criteria.name', 'criteria.deleted_at')
@@ -753,10 +693,14 @@ class OutcomesController extends \BaseController
753 693
                 $scales = DB::select("select * FROM scales INNER join `criterion_scale` on `criterion_scale`.`scale_id` = `scales`.`id` where criterion_scale.criterion_id ={$criteria_id->id} ORDER BY position");
754 694
 
755 695
                 $programs = DB::table('programs')
756
-                    ->join('program_criterion', 'program_criterion.program_id', '=', 'programs.id')
696
+                    ->join('program_criterion_objective_outcome', 'programs.id', '=', 'program_criterion_objective_outcome.program_id')
697
+                    ->join('criterion_objective_outcome as cobo', 'cobo.id', '=', 'program_criterion_objective_outcome.cri_obj_out_id')
698
+                    //->join('program_criterion', 'program_criterion.program_id', '=', 'programs.id')
757 699
                     ->where('criterion_id', $criteria_id->id)
700
+                    ->select('programs.*')
701
+                    ->distinct()
758 702
                     ->lists('programs.name');
759
-                Log::info($scales);
703
+                // Log::info($scales);
760 704
 
761 705
                 /* $scales =
762 706
                     DB::select(

+ 9
- 9
app/controllers/ProgramsController.php View File

@@ -282,9 +282,9 @@ class ProgramsController extends \BaseController
282 282
       $domains = DB::table('outcomes')
283 283
         ->join('criterion_objective_outcome as cobo', 'cobo.outcome_id', '=', 'outcomes.id')
284 284
         ->join('criteria', 'criteria.id', '=', 'cobo.criterion_id')
285
-        ->join('program_criterion', 'criteria.id', '=', 'program_criterion.criterion_id')
286
-        ->join('courses', 'courses.program_id', '=', 'program_criterion.program_id')
287
-        ->where('program_criterion.program_id', $program->id)
285
+        ->join('program_criterion_objective_outcome', 'cobo.id', '=', 'program_criterion_objective_outcome.cri_obj_out_id')
286
+        ->join('courses', 'courses.program_id', '=', 'program_criterion_objective_outcome.program_id')
287
+        ->where('program_criterion_objective_outcome.program_id', $program->id)
288 288
         ->select('outcomes.name', 'outcomes.activation_date')
289 289
         ->distinct()
290 290
         ->orderBy('outcomes.name', 'asc')
@@ -306,9 +306,9 @@ class ProgramsController extends \BaseController
306 306
       $courses_used =  DB::table('outcomes')
307 307
         ->join('criterion_objective_outcome as cobo', 'cobo.outcome_id', '=', 'outcomes.id')
308 308
         ->join('criteria', 'criteria.id', '=', 'cobo.criterion_id')
309
-        ->join('program_criterion', 'criteria.id', '=', 'program_criterion.criterion_id')
310
-        ->join('courses', 'courses.program_id', '=', 'program_criterion.program_id')
311
-        ->where('program_criterion.program_id', $program->id)
309
+        ->join('program_criterion_objective_outcome', 'cobo.id', '=', 'program_criterion_objective_outcome.cri_obj_out_id')
310
+        ->join('courses', 'courses.program_id', '=', 'program_criterion_objective_outcome.program_id')
311
+        ->where('program_criterion_objective_outcome.program_id', $program->id)
312 312
         ->select('courses.number', 'outcomes.name as domain_name', 'courses.code')
313 313
         ->distinct()
314 314
         ->orderBy('courses.name', 'asc')
@@ -328,14 +328,14 @@ class ProgramsController extends \BaseController
328 328
       $transformative_actions = DB::table('outcomes')
329 329
         ->join('criterion_objective_outcome as cobo', 'cobo.outcome_id', '=', 'outcomes.id')
330 330
         ->join('criteria', 'criteria.id', '=', 'cobo.criterion_id')
331
-        ->join('program_criterion', 'criteria.id', '=', 'program_criterion.criterion_id')
332
-        ->join('courses', 'courses.program_id', '=', 'program_criterion.program_id')
331
+        ->join('program_criterion_objective_outcome', 'cobo.id', '=', 'program_criterion_objective_outcome.cri_obj_out_id')
332
+        ->join('courses', 'courses.program_id', '=', 'program_criterion_objective_outcome.program_id')
333 333
 
334 334
         ->join('activities', 'activities.course_id', '=', 'courses.id')
335 335
         ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
336 336
         ->join('transformative_activity_criterion as taa', 'taa.activity_criterion_id', '=', 'activity_criterion.id')
337 337
         ->join('transformative_actions', 'transformative_actions.id', '=', 'taa.trans_action_id')
338
-        ->where('program_criterion.program_id', $program->id)
338
+        ->where('program_criterion_objective_outcome.program_id', $program->id)
339 339
         ->select('transformative_actions.description', 'outcomes.name as domain_name')
340 340
         ->distinct()
341 341
         ->orderBy('transformative_actions.description', 'asc')

+ 25
- 4
app/controllers/TemplatesController.php View File

@@ -252,6 +252,8 @@ class TemplatesController extends \BaseController
252 252
 		// 			Log::info("aqui".(count($criteria)));
253 253
 		// 			Log::info(json_encode(count($criteria)));
254 254
 
255
+
256
+
255 257
 		$templates = Template::where('school_id', '=', $school_id_user)->orWhere('school_id', '=', NULL)
256 258
 			->orderBy('name', 'ASC')->get();
257 259
 		$criteria_ids = array();
@@ -274,6 +276,22 @@ class TemplatesController extends \BaseController
274 276
 		$templates_dentro = Template::whereNotIn('id', $templates_fuera_ids)
275 277
 			->orderBy('name', 'ASC')->get();
276 278
 
279
+		/*$templates_dentro = Template::join('template_criterion', 'template_criterion.template_id', '=', 'templates.id')
280
+			->join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'template_criterion.criterion_id')
281
+			->where('objective_id', '<>', '0')
282
+
283
+			->where(function ($query) use ($school_id_user) {
284
+				$query->where('school_id', $school_id_user)
285
+					->orWhere('school_id', '=', NULL);
286
+			})
287
+
288
+			//			->orWhere('school_id', '=', NULL)
289
+
290
+			->orderBy('name', 'ASC')
291
+			->groupBy('templates.id')
292
+			->select("templates.*")
293
+			->get();*/
294
+
277 295
 		// 			if(!isset($templates_dentro))$templates_dentro=
278 296
 
279 297
 		// 			var_dump(json_encode($templates_dentro));
@@ -296,7 +314,7 @@ class TemplatesController extends \BaseController
296 314
 				return "NO pa";
297 315
 			}
298 316
 
299
-			$crit->all_objectives = Objective::join("criterion_objective_outcome", 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
317
+			$crit->all_objectives = DB::table("objectives")->join("criterion_objective_outcome", 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
300 318
 				->where('criterion_id', $crit->id)
301 319
 				->select('objectives.*')
302 320
 				->groupBy('objectives.id')
@@ -452,9 +470,12 @@ class TemplatesController extends \BaseController
452 470
 				->orderBy('position', 'ASC')
453 471
 				->get();
454 472
 
455
-			$temp_crit->program_ids = json_encode(DB::table('program_criterion')
456
-				->where('criterion_id', $temp_crit->id)
457
-				->lists('program_id'));
473
+			$temp_crit->program_ids = json_encode(DB::table('program_criterion_objective_outcome')
474
+				->join('criterion_objective_outcome', 'criterion_objective_outcome.id', '=', 'program_criterion_objective_outcome.cri_obj_out_id')
475
+				->where('criterion_objective_outcome.criterion_id', $temp_crit->id)
476
+				->select('program_criterion_objective_outcome.program_id')
477
+				->distinct()
478
+				->lists('program_criterion_objective_outcome.program_id'));
458 479
 
459 480
 			Log::info("ee" . json_encode($temp_crit->program_ids));
460 481
 

+ 31
- 2
app/controllers/ThreeYearPlanController.php View File

@@ -321,8 +321,8 @@ class ThreeYearPlanController extends \BaseController
321 321
     $program_id = Input::get('program_id');
322 322
 
323 323
     // get program_id
324
-    $user_id = auth::user()->id;
325
-    Log::info(Input::all());
324
+    //$user_id = auth::user()->id;
325
+    //Log::info(Input::all());
326 326
 
327 327
     // get typ_program_id
328 328
     $result = DB::table('typ_program')
@@ -1070,4 +1070,33 @@ class ThreeYearPlanController extends \BaseController
1070 1070
       return $pdf->stream(basename($queryToPath->path_to_pdf));
1071 1071
   }
1072 1072
   */
1073
+
1074
+  ///////////////////
1075
+  //
1076
+  //Pair everything
1077
+  //
1078
+  ////////////////////
1079
+
1080
+  public function pairEveryObjective()
1081
+  {
1082
+    Log::info(Input::all());
1083
+    $selected_objectives = Input::get('selected_objectives');
1084
+    $typ_id = Input::get('typ_id');
1085
+    $program_id = Input::get('program_id');
1086
+    for ($i = 0; $i < count($selected_objectives); $i += 3) {
1087
+      Input::replace([
1088
+        'program_id' => $program_id,
1089
+        'new_objective_id' => $selected_objectives[$i + 2],
1090
+        'outcome_id' => $selected_objectives[$i],
1091
+        'semester_id' => $selected_objectives[$i + 1],
1092
+        'typ_id' => $typ_id,
1093
+        'previous_objective_id' => 'nothing_selected'
1094
+
1095
+
1096
+      ]);
1097
+      if ($this->section2_on_change() != 'update was succes')
1098
+        return 0;
1099
+    }
1100
+    return 200;
1101
+  }
1073 1102
 }

+ 2
- 2
app/models/Criterion.php View File

@@ -39,13 +39,13 @@ class Criterion extends Eloquent
39 39
 	}
40 40
 
41 41
 
42
-	public function scopeFromProgram($query, $programs)
42
+	/*public function scopeFromProgram($query, $programs)
43 43
 	{
44 44
 
45 45
 		return $query->join('program_criterion', 'program_criterion.criterion_id', '=', 'criteria.id')
46 46
 			->whereIn("program_id", "programs")
47 47
 			->select('criteria.*');
48
-	}
48
+	}*/
49 49
 
50 50
 	/**
51 51
 	 * Return the program that the criterion belongs to

+ 8
- 0
app/routes.php View File

@@ -246,6 +246,14 @@ Route::group(array('before' => 'auth|has_access'), function () {
246 246
     Route::get("downloadThreeYearPlanPDF/{path_id}", "ThreeYearPlanController@showHTML");
247 247
     Route::get("findHTMLlinksTYP/{path_id}", 'ThreeYearPlanController@findHTML');
248 248
 
249
+    /////////////////////////////////////////
250
+    // 
251
+    //  pairing everything in three year
252
+    //
253
+    /////////////////////////////////////////
254
+
255
+
256
+    Route::post('pairEveryObjective', "ThreeYearPlanController@pairEveryObjective");
249 257
     //View annual plans and report
250 258
 
251 259
     Route::get('{annual_report_or_plan}/show/{program_id}', "AnnualPlansController@annualPlansShow");

+ 103
- 1
app/views/global/view-three-year-plan.blade.php View File

@@ -252,16 +252,19 @@
252 252
                                 <div class="select-course-selection-0" style="margin-left:30px;">
253 253
                                     <div class="objective-selector-0">
254 254
                                         <label for="">OBJECTIVE TEMP</label>
255
-                                        <select class="select-0" name="" style="width:100%;max-width:55%;">
255
+                                        <select class="select-0"  name="" style="width:100%;max-width:55%;">
256 256
                                             <option class="default-option" value="nothing_selected">Select a course</option>
257 257
                                         </select>
258 258
                                         <button class="btn btn-md btn-primary delete-selection-0"
259 259
                                             style="margin:5px; "><span></span> X</button>
260 260
                                     </div>
261 261
                                     <div class="clone-objective-course-select-0">
262
+                                        <div class = 'btn-group'>
262 263
                                         <button class="btn btn-md btn-secondary add-objective-course"
263 264
                                             style="margin:5px;"><span class="glyphicon glyphicon-plus"></span> Choose more
264 265
                                             Courses</button>
266
+                                        <button class = 'btn btn-md btn-secondary copy-objective-button'  onclick="showParingObjectiveModal(this)" style="margin:5px;">Copy Courses to each Objective</button>
267
+                                        </div>
265 268
                                     </div>
266 269
                                 </div>
267 270
                             </div>
@@ -326,9 +329,101 @@
326 329
                 </div>
327 330
             </div>
328 331
         </div>
332
+        <div id="pairingModal" class="modal fade" tabindex="-1" data-criterion-id="0">
333
+            <div class="modal-dialog">
334
+                <div class="modal-content">
335
+                    <div class="modal-header" >
336
+                        <h5 class="modal-title" id = "pairingModalTitle">Would you like to pair this </h5>
337
+                        <button type="button" class="close" data-dismiss="modal">&times;</button>
338
+                    </div>
339
+                    <div class="modal-body"  id = 'pairingModalBody'>
340
+                    
341
+
342
+                    </div>
343
+                    <div class="modal-footer">
344
+                       
345
+                        <button type="button" class="btn btn-secondary" data-dismiss="modal" >cancel</button>
346
+                        <button type="button" id='pairingModalSubmitButton' class="btn btn-primary" data-dismiss="modal" onclick = 'pairEverything()' >Ok</button>
347
+                        
348
+                    </div>
349
+                </div>
350
+            </div>
351
+        </div>
329 352
 
330 353
     </div>
354
+
331 355
     <script>
356
+
357
+        function showParingObjectiveModal(button){
358
+            modal = "#pairingModal"
359
+
360
+            
361
+
362
+            select_course_selector = $(button).parent().parent().parent();
363
+            objective_selectors= select_course_selector.find("div:not([style*='display: none'])");
364
+            selects = objective_selectors.find('select');
365
+            
366
+
367
+            array_to_send = [];
368
+
369
+            var semester_id;
370
+            var outcome_id;
371
+            var objectives_ids = [];
372
+            $.each(selects, function(ind, select){
373
+                splited = $(select).val().split('-');
374
+                semester_id = splited[1];
375
+                outcome_id = splited[0];
376
+                objectives_ids.push(splited[2]);
377
+                array_to_send.push(splited);
378
+            })
379
+
380
+            whole_outcome_div = select_course_selector.parent().parent();
381
+            whole_outcome_div.children('div.semester-course-selection').each(function(ind, div){
382
+                if($(div).data('semester-id')== semester_id){
383
+                    return;
384
+                }
385
+                div_semester = $(div).data('semester-id');
386
+                $.each(objectives_ids, function(ind, obj){
387
+                    array_to_send.push([outcome_id, div_semester, obj]);
388
+                })
389
+            })
390
+
391
+            if($(button).html()=="Copy Courses to each Objective"){
392
+                $(modal+'Title').html("Would you like to pair these Courses to each Objective in this Outcome");
393
+                $(modal+'Body').html("This action will pair each Course in each Objective and each Semester of this Outcome.<br> This action is reversable")
394
+                $(modal+"SubmitButton").attr('onclick', 'pairEveryCourse(['+array_to_send.toString()+'])')
395
+            }
396
+            else{
397
+                $(modal+'Title').html("Would you like to pair these Objective to each Semester in this Outcome");
398
+                $(modal+'Body').html("This action will pair each Objective on each Semester of this Outcome.<br> This action is reversable")
399
+                $(modal+"SubmitButton").attr('onclick', 'pairEveryObjective(['+array_to_send.toString()+'])')
400
+            }
401
+
402
+            
403
+
404
+
405
+            $(modal).modal('show');
406
+
407
+        }
408
+        function pairEveryObjective(selected_objectives){
409
+
410
+            var typ_id = $('#table-cycles').data('typ-id');
411
+            $.post(
412
+                "{{URL::action('ThreeYearPlanController@pairEveryObjective')}}",
413
+                {
414
+                    selected_objectives:selected_objectives,
415
+                    typ_id: typ_id,
416
+                    program_id:{{$program_id}}
417
+                },
418
+                function(data){
419
+                    if(data ==200){
420
+                        $(".go-to-2").trigger('click');
421
+                    }
422
+                   
423
+
424
+                }
425
+            )
426
+        }
332 427
         $(document).ready(function() {
333 428
             // --------------------------------------------------------------------------
334 429
             // Page load
@@ -656,6 +751,7 @@
656 751
             window.scrollTo(0, 0);
657 752
             $(".panel-body").hide();
658 753
             $("#section2").show();
754
+            
659 755
         });
660 756
 
661 757
 
@@ -716,6 +812,7 @@
716 812
 
717 813
                             var select_area = $('.semester-course-selection-0').clone(true);
718 814
                             select_area.attr('class', 'semester-course-selection');
815
+                            select_area.attr('data-semester-id', semester_id);
719 816
                             select_area.attr('style', ' ');
720 817
                             select_area.find('.semester-label-course-selection-0').html(
721 818
                                 semester_name + "'s Objectives");
@@ -725,6 +822,8 @@
725 822
                             select_area.find('.add-objective-course').html(
726 823
                                 '<span class="glyphicon glyphicon-plus"></span> Choose more Objectives'
727 824
                             );
825
+                            select_area.find('.copy-objective-button').html('Copy Objectives to each Semester in Outcome');
826
+
728 827
 
729 828
                             if (semester.available_objectives.length != 0) {
730 829
                                 select_area.find('.objective-selector-0 label').hide();
@@ -811,6 +910,7 @@
811 910
             new_select.attr('class', 'objective-selector');
812 911
             new_select.show();
813 912
             $(this).parent().before(new_select);
913
+            //$('.selectpicker').selectpicker('refresh')
814 914
         });
815 915
 
816 916
 
@@ -853,6 +953,7 @@
853 953
 
854 954
                             var select_area = $('.semester-course-selection-0').clone(true);
855 955
                             select_area.attr('class', 'semester-course-selection');
956
+                            select_area.attr('data-semester-id', semester_id);
856 957
                             select_area.attr('style', ' ');
857 958
                             select_area.find('.semester-label-course-selection-0').html(
858 959
                                 semester_name);
@@ -945,6 +1046,7 @@
945 1046
                         $('.courses-section').append(area);
946 1047
 
947 1048
                     });
1049
+                    //$('.selectpicker').selectpicker('refresh');
948 1050
                     //$('.objective-selector').children('.delete-selection-0').css("margin:5px; display:block;");
949 1051
                 }
950 1052
             );