|
@@ -1,6 +1,7 @@
|
1
|
1
|
<?php
|
2
|
2
|
|
3
|
3
|
use Illuminate\Database\Eloquent\Collection;
|
|
4
|
+use Barryvdh\DomPDF\PDF as PDF;
|
4
|
5
|
|
5
|
6
|
class ThreeYearPlanController extends \BaseController
|
6
|
7
|
{
|
|
@@ -55,7 +56,7 @@ class ThreeYearPlanController extends \BaseController
|
55
|
56
|
}
|
56
|
57
|
|
57
|
58
|
$program = Program::find($program_id);
|
58
|
|
- Log::info($program);
|
|
59
|
+ Log::info($program);
|
59
|
60
|
|
60
|
61
|
// el ID de los semestres que el usuario tiene seleccionado.
|
61
|
62
|
$semesters_ids = Session::get('semesters_ids');
|
|
@@ -72,13 +73,10 @@ class ThreeYearPlanController extends \BaseController
|
72
|
73
|
->select('program_id')
|
73
|
74
|
->get();
|
74
|
75
|
$program_id = $program_id[0]->program_id;*/
|
75
|
|
- if($program->is_graduate==0)
|
76
|
|
- {
|
77
|
|
- $outcomes = DB::table('outcomes')->where('deactivation_date', '=', null)->orderBy('name', 'ASC')->get();
|
78
|
|
- }
|
79
|
|
- else
|
80
|
|
- {
|
81
|
|
- $outcomes = DB::table('outcomes')->where('deactivation_date', '=', null)->where('level', '=', 3)->orderBy('name', 'ASC')->get();
|
|
76
|
+ if ($program->is_graduate == 0) {
|
|
77
|
+ $outcomes = DB::table('outcomes')->where('deactivation_date', '=', null)->orderBy('name', 'ASC')->get();
|
|
78
|
+ } else {
|
|
79
|
+ $outcomes = DB::table('outcomes')->where('deactivation_date', '=', null)->where('level', '=', 3)->orderBy('name', 'ASC')->get();
|
82
|
80
|
}
|
83
|
81
|
|
84
|
82
|
// se annadio la nueva variable
|
|
@@ -610,6 +608,85 @@ class ThreeYearPlanController extends \BaseController
|
610
|
608
|
$yearStart++;
|
611
|
609
|
$yearStartPlusOne++;
|
612
|
610
|
}
|
|
611
|
+ $this->createThreeYearPlanPdf($program_id, $input_id);
|
|
612
|
+ }
|
|
613
|
+
|
|
614
|
+ public function createThreeYearPlanPdf($program_id, $typ)
|
|
615
|
+ {
|
|
616
|
+ $program = DB::table('programs')->where('id', $program_id)->first();
|
|
617
|
+ $three_year_plan = DB::table('three_year_plan')->where('id', $typ)->first();
|
|
618
|
+
|
|
619
|
+ $typ_program_id = DB::table('typ_program')->where('three_year_plan_id', $three_year_plan->id)
|
|
620
|
+ ->where('program_id', $program->id)
|
|
621
|
+ ->first()->id;
|
|
622
|
+
|
|
623
|
+ $typ_semesters = DB::table('semesters')
|
|
624
|
+ ->join('typ_semesters', 'semesters.id', '=', 'typ_semesters.semester_id')
|
|
625
|
+ ->where('typ_id', $three_year_plan->id)
|
|
626
|
+ ->orderBy('semester_id')
|
|
627
|
+ ->get();
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+ foreach ($typ_semesters as $semester) {
|
|
631
|
+ $typ_semester_outcome[$semester->semester_id] = DB::table('typ_semester_outcome')
|
|
632
|
+ ->join('outcomes', 'outcomes.id', '=', 'typ_semester_outcome.outcome_id')
|
|
633
|
+ ->where('typ_program_id', $typ_program_id)
|
|
634
|
+ ->where('semester_id', $semester->semester_id)
|
|
635
|
+ ->select('typ_semester_outcome.id as typ_id')
|
|
636
|
+ ->addSelect('outcomes.id as outcome_id', 'outcomes.name')
|
|
637
|
+ ->get();
|
|
638
|
+
|
|
639
|
+ foreach ($typ_semester_outcome[$semester->semester_id] as $outcome) {
|
|
640
|
+ $outcome->objectives = DB::table('typ_semester_objectives')
|
|
641
|
+ ->join('objectives', 'objectives.id', '=', 'typ_semester_objectives.objective_id')
|
|
642
|
+ ->where('typ_semester_outcome_id', $outcome->typ_id)
|
|
643
|
+ ->select('typ_semester_objectives.id as typ_obj_id')
|
|
644
|
+ ->addSelect('objectives.text', 'objectives.id as objective_id')
|
|
645
|
+ ->get();
|
|
646
|
+ foreach ($outcome->objectives as $objective) {
|
|
647
|
+ $objective->courses = DB::table('typ_semester_courses')
|
|
648
|
+ ->join('courses', 'courses.id', '=', 'typ_semester_courses.course_id')
|
|
649
|
+ ->where('typ_semester_objective_id', $objective->typ_obj_id)
|
|
650
|
+ ->get();
|
|
651
|
+ }
|
|
652
|
+ }
|
|
653
|
+ }
|
|
654
|
+
|
|
655
|
+ $pdf = new PDF(app('config'), app("Filesystem"), app('view'), '/storage/three_year_plan_pdfs');
|
|
656
|
+ $pdf = $pdf->loadView('global.print_three_year_plan', compact('typ_semesters', 'program', 'three_year_plan', 'typ_semesters', 'typ_semester_outcome'))
|
|
657
|
+ ->setOrientation("landscape")
|
|
658
|
+
|
|
659
|
+ ->setPaper('legal', 'landscape');
|
|
660
|
+ $path = app_path() . '/storage/three_year_plan_pdfs/' . date('d-m-Y') . '-for-' . $program->id . '-by-' . Auth::user()->id . '.pdf';
|
|
661
|
+ $pdf->save($path);
|
|
662
|
+ $name = date('d-m-Y') . '-for-' . $program->id . '.pdf';
|
|
663
|
+ $pdf->download($name);
|
|
664
|
+
|
|
665
|
+ //is a path already there
|
|
666
|
+
|
|
667
|
+ $it_exists = DB::table("paths_for_three_year_plans")
|
|
668
|
+ ->where('path_to_pdf', $path)
|
|
669
|
+ ->first();
|
|
670
|
+
|
|
671
|
+ if (isset($it_exists)) {
|
|
672
|
+ return '200';
|
|
673
|
+ }
|
|
674
|
+ //$user_id = Auth::user()->id;
|
|
675
|
+ DB::table("paths_for_three_year_plans")
|
|
676
|
+ ->where('typ_program_id', $typ_program_id)
|
|
677
|
+ ->where('user_id', Auth::user()->id)
|
|
678
|
+
|
|
679
|
+ ->update(array(
|
|
680
|
+ 'last' => 0
|
|
681
|
+ ));
|
|
682
|
+
|
|
683
|
+ DB::table('paths_for_three_year_plans')->insert(array(
|
|
684
|
+ "path_to_pdf" => $path,
|
|
685
|
+ 'typ_program_id' => $typ_program_id,
|
|
686
|
+ 'last' => 1,
|
|
687
|
+ 'user_id' => Auth::user()->id,
|
|
688
|
+ 'date_posted' => date('Y-m-d')
|
|
689
|
+ ));
|
613
|
690
|
}
|
614
|
691
|
|
615
|
692
|
public function printPlan($program_id, $typ)
|
|
@@ -653,9 +730,111 @@ class ThreeYearPlanController extends \BaseController
|
653
|
730
|
}
|
654
|
731
|
}
|
655
|
732
|
}
|
656
|
|
- Log::info($typ_semester_outcome);
|
|
733
|
+ //Log::info($typ_semester_outcome);
|
657
|
734
|
|
658
|
735
|
|
659
|
736
|
return View::make('global.print_three_year_plan', compact('typ_semesters', 'program', 'three_year_plan', 'typ_semesters', 'typ_semester_outcome'));
|
660
|
737
|
}
|
661
|
|
-}
|
|
738
|
+
|
|
739
|
+ public function showPDFs($program_id)
|
|
740
|
+ {
|
|
741
|
+
|
|
742
|
+ $role = Auth::user()->role;
|
|
743
|
+ switch ($role) {
|
|
744
|
+ case 1:
|
|
745
|
+ case 2:
|
|
746
|
+ case 3:
|
|
747
|
+ $last = [1, 0];
|
|
748
|
+ break;
|
|
749
|
+
|
|
750
|
+ case 4:
|
|
751
|
+ $last = [1];
|
|
752
|
+
|
|
753
|
+ break;
|
|
754
|
+ default:
|
|
755
|
+ App::abort('404');
|
|
756
|
+ }
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+ $title = "Three Year Plans for " . Program::findOrFail($program_id)->name;
|
|
760
|
+ $paths_with_users = DB::table('paths_for_three_year_plans')
|
|
761
|
+ ->join('typ_program', 'typ_program.id', '=', 'paths_for_three_year_plans.typ_program_id')
|
|
762
|
+ ->join('three_year_plan', 'typ_program.three_year_plan_id', '=', 'three_year_plan.id')
|
|
763
|
+ ->join('users', 'users.id', '=', 'paths_for_three_year_plans.user_id')
|
|
764
|
+
|
|
765
|
+ ->whereIn('last', $last)
|
|
766
|
+ ->where('typ_program.program_id', $program_id)
|
|
767
|
+ ->orderBy('date_posted', 'desc')
|
|
768
|
+ ->select('paths_for_three_year_plans.path_to_pdf', 'users.*', 'date_posted', 'three_year_plan.*', 'paths_for_three_year_plans.last', 'paths_for_three_year_plans.id as path_id')
|
|
769
|
+ ->get();
|
|
770
|
+
|
|
771
|
+ return View::make('local.managers.shared.new_view_three_year_plans', compact('paths_with_users', 'title', 'last', 'program_id'));
|
|
772
|
+ }
|
|
773
|
+
|
|
774
|
+ public function downloadPDF($download, $path_id)
|
|
775
|
+ {
|
|
776
|
+ $pdf = new PDF(app('config'), app("Filesystem"), app('view'), '/storage/three_year_plan_pdfs');
|
|
777
|
+
|
|
778
|
+ $queryToPath = DB::table('paths_for_three_year_plans')
|
|
779
|
+ ->join('typ_program', 'typ_program.id', '=', 'paths_for_three_year_plans.typ_program_id')
|
|
780
|
+ ->where('paths_for_three_year_plans.id', $path_id)
|
|
781
|
+ ->first();
|
|
782
|
+
|
|
783
|
+ //Log::info("ERES TU? creo que no");
|
|
784
|
+
|
|
785
|
+ // $annualPlan = AnnualPlan::findOrFail($queryToPath->annual_plan_id);
|
|
786
|
+
|
|
787
|
+
|
|
788
|
+ $program = Program::findOrFail($queryToPath->program_id);
|
|
789
|
+
|
|
790
|
+
|
|
791
|
+ $typ_program_id = $queryToPath->typ_program_id;
|
|
792
|
+
|
|
793
|
+ $three_year_plan = DB::table('three_year_plan')
|
|
794
|
+ ->where('id', $queryToPath->three_year_plan_id)
|
|
795
|
+ ->first();
|
|
796
|
+
|
|
797
|
+ $typ_semesters = DB::table('semesters')
|
|
798
|
+ ->join('typ_semesters', 'semesters.id', '=', 'typ_semesters.semester_id')
|
|
799
|
+ ->where('typ_id', $queryToPath->three_year_plan_id)
|
|
800
|
+ ->orderBy('semester_id')
|
|
801
|
+ ->get();
|
|
802
|
+
|
|
803
|
+
|
|
804
|
+ foreach ($typ_semesters as $semester) {
|
|
805
|
+ $typ_semester_outcome[$semester->semester_id] = DB::table('typ_semester_outcome')
|
|
806
|
+ ->join('outcomes', 'outcomes.id', '=', 'typ_semester_outcome.outcome_id')
|
|
807
|
+ ->where('typ_program_id', $typ_program_id)
|
|
808
|
+ ->where('semester_id', $semester->semester_id)
|
|
809
|
+ ->select('typ_semester_outcome.id as typ_id')
|
|
810
|
+ ->addSelect('outcomes.id as outcome_id', 'outcomes.name')
|
|
811
|
+ ->get();
|
|
812
|
+
|
|
813
|
+ foreach ($typ_semester_outcome[$semester->semester_id] as $outcome) {
|
|
814
|
+ $outcome->objectives = DB::table('typ_semester_objectives')
|
|
815
|
+ ->join('objectives', 'objectives.id', '=', 'typ_semester_objectives.objective_id')
|
|
816
|
+ ->where('typ_semester_outcome_id', $outcome->typ_id)
|
|
817
|
+ ->select('typ_semester_objectives.id as typ_obj_id')
|
|
818
|
+ ->addSelect('objectives.text', 'objectives.id as objective_id')
|
|
819
|
+ ->get();
|
|
820
|
+ foreach ($outcome->objectives as $objective) {
|
|
821
|
+ $objective->courses = DB::table('typ_semester_courses')
|
|
822
|
+ ->join('courses', 'courses.id', '=', 'typ_semester_courses.course_id')
|
|
823
|
+ ->where('typ_semester_objective_id', $objective->typ_obj_id)
|
|
824
|
+ ->get();
|
|
825
|
+ }
|
|
826
|
+ }
|
|
827
|
+ }
|
|
828
|
+ //Log::info("ERES TU?");
|
|
829
|
+
|
|
830
|
+ $pdf = $pdf->loadView('global.print_three_year_plan', compact('typ_semesters', 'program', 'three_year_plan', 'typ_semesters', 'typ_semester_outcome'))
|
|
831
|
+ ->setOrientation("landscape")
|
|
832
|
+
|
|
833
|
+ ->setPaper('legal', 'landscape');
|
|
834
|
+ if ($download == "download")
|
|
835
|
+ return $pdf->download(basename($queryToPath->path_to_pdf));
|
|
836
|
+
|
|
837
|
+ else
|
|
838
|
+ return $pdf->stream(basename($queryToPath->path_to_pdf));
|
|
839
|
+ }
|
|
840
|
+}
|