|
@@ -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)
|
|
@@ -654,7 +731,7 @@ class ThreeYearPlanController extends \BaseController
|
654
|
731
|
}
|
655
|
732
|
}
|
656
|
733
|
}
|
657
|
|
- Log::info($typ_semester_outcome);
|
|
734
|
+ //Log::info($typ_semester_outcome);
|
658
|
735
|
|
659
|
736
|
|
660
|
737
|
return View::make('global.print_three_year_plan', compact('typ_semesters', 'program', 'three_year_plan', 'typ_semesters', 'typ_semester_outcome', 'view'));
|
|
@@ -706,4 +783,106 @@ class ThreeYearPlanController extends \BaseController
|
706
|
783
|
|
707
|
784
|
return View::make('global.print_three_year_plan', compact('typ_semesters', 'program', 'three_year_plan', 'typ_semesters', 'typ_semester_outcome', 'view'));
|
708
|
785
|
}
|
709
|
|
-}
|
|
786
|
+
|
|
787
|
+ public function showPDFs($program_id)
|
|
788
|
+ {
|
|
789
|
+
|
|
790
|
+ $role = Auth::user()->role;
|
|
791
|
+ switch ($role) {
|
|
792
|
+ case 1:
|
|
793
|
+ case 2:
|
|
794
|
+ case 3:
|
|
795
|
+ $last = [1, 0];
|
|
796
|
+ break;
|
|
797
|
+
|
|
798
|
+ case 4:
|
|
799
|
+ $last = [1];
|
|
800
|
+
|
|
801
|
+ break;
|
|
802
|
+ default:
|
|
803
|
+ App::abort('404');
|
|
804
|
+ }
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+ $title = "Three Year Plans for " . Program::findOrFail($program_id)->name;
|
|
808
|
+ $paths_with_users = DB::table('paths_for_three_year_plans')
|
|
809
|
+ ->join('typ_program', 'typ_program.id', '=', 'paths_for_three_year_plans.typ_program_id')
|
|
810
|
+ ->join('three_year_plan', 'typ_program.three_year_plan_id', '=', 'three_year_plan.id')
|
|
811
|
+ ->join('users', 'users.id', '=', 'paths_for_three_year_plans.user_id')
|
|
812
|
+
|
|
813
|
+ ->whereIn('last', $last)
|
|
814
|
+ ->where('typ_program.program_id', $program_id)
|
|
815
|
+ ->orderBy('date_posted', 'desc')
|
|
816
|
+ ->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')
|
|
817
|
+ ->get();
|
|
818
|
+
|
|
819
|
+ return View::make('local.managers.shared.new_view_three_year_plans', compact('paths_with_users', 'title', 'last', 'program_id'));
|
|
820
|
+ }
|
|
821
|
+
|
|
822
|
+ public function downloadPDF($download, $path_id)
|
|
823
|
+ {
|
|
824
|
+ $pdf = new PDF(app('config'), app("Filesystem"), app('view'), '/storage/three_year_plan_pdfs');
|
|
825
|
+
|
|
826
|
+ $queryToPath = DB::table('paths_for_three_year_plans')
|
|
827
|
+ ->join('typ_program', 'typ_program.id', '=', 'paths_for_three_year_plans.typ_program_id')
|
|
828
|
+ ->where('paths_for_three_year_plans.id', $path_id)
|
|
829
|
+ ->first();
|
|
830
|
+
|
|
831
|
+ //Log::info("ERES TU? creo que no");
|
|
832
|
+
|
|
833
|
+ // $annualPlan = AnnualPlan::findOrFail($queryToPath->annual_plan_id);
|
|
834
|
+
|
|
835
|
+
|
|
836
|
+ $program = Program::findOrFail($queryToPath->program_id);
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+ $typ_program_id = $queryToPath->typ_program_id;
|
|
840
|
+
|
|
841
|
+ $three_year_plan = DB::table('three_year_plan')
|
|
842
|
+ ->where('id', $queryToPath->three_year_plan_id)
|
|
843
|
+ ->first();
|
|
844
|
+
|
|
845
|
+ $typ_semesters = DB::table('semesters')
|
|
846
|
+ ->join('typ_semesters', 'semesters.id', '=', 'typ_semesters.semester_id')
|
|
847
|
+ ->where('typ_id', $queryToPath->three_year_plan_id)
|
|
848
|
+ ->orderBy('semester_id')
|
|
849
|
+ ->get();
|
|
850
|
+
|
|
851
|
+
|
|
852
|
+ foreach ($typ_semesters as $semester) {
|
|
853
|
+ $typ_semester_outcome[$semester->semester_id] = DB::table('typ_semester_outcome')
|
|
854
|
+ ->join('outcomes', 'outcomes.id', '=', 'typ_semester_outcome.outcome_id')
|
|
855
|
+ ->where('typ_program_id', $typ_program_id)
|
|
856
|
+ ->where('semester_id', $semester->semester_id)
|
|
857
|
+ ->select('typ_semester_outcome.id as typ_id')
|
|
858
|
+ ->addSelect('outcomes.id as outcome_id', 'outcomes.name')
|
|
859
|
+ ->get();
|
|
860
|
+
|
|
861
|
+ foreach ($typ_semester_outcome[$semester->semester_id] as $outcome) {
|
|
862
|
+ $outcome->objectives = DB::table('typ_semester_objectives')
|
|
863
|
+ ->join('objectives', 'objectives.id', '=', 'typ_semester_objectives.objective_id')
|
|
864
|
+ ->where('typ_semester_outcome_id', $outcome->typ_id)
|
|
865
|
+ ->select('typ_semester_objectives.id as typ_obj_id')
|
|
866
|
+ ->addSelect('objectives.text', 'objectives.id as objective_id')
|
|
867
|
+ ->get();
|
|
868
|
+ foreach ($outcome->objectives as $objective) {
|
|
869
|
+ $objective->courses = DB::table('typ_semester_courses')
|
|
870
|
+ ->join('courses', 'courses.id', '=', 'typ_semester_courses.course_id')
|
|
871
|
+ ->where('typ_semester_objective_id', $objective->typ_obj_id)
|
|
872
|
+ ->get();
|
|
873
|
+ }
|
|
874
|
+ }
|
|
875
|
+ }
|
|
876
|
+ //Log::info("ERES TU?");
|
|
877
|
+
|
|
878
|
+ $pdf = $pdf->loadView('global.print_three_year_plan', compact('typ_semesters', 'program', 'three_year_plan', 'typ_semesters', 'typ_semester_outcome'))
|
|
879
|
+ ->setOrientation("landscape")
|
|
880
|
+
|
|
881
|
+ ->setPaper('legal', 'landscape');
|
|
882
|
+ if ($download == "download")
|
|
883
|
+ return $pdf->download(basename($queryToPath->path_to_pdf));
|
|
884
|
+
|
|
885
|
+ else
|
|
886
|
+ return $pdf->stream(basename($queryToPath->path_to_pdf));
|
|
887
|
+ }
|
|
888
|
+}
|