123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- <?php
-
- class AnnualPlan extends \Eloquent
- {
- protected $fillable = [];
- protected $table = 'annual_plans';
- protected $appends = ["outcomes"];
-
- // return outcomes in annual plan to
- public function program()
- {
- return $this->belongsTo('Program');
- }
- public function annualCycle()
- {
-
- return $this->belongsTo('AnnualCycle');
- }
-
- //courses_with_transformative
-
- //
-
- public function getSemestersAttribute()
- {
- $semester_ids = Semester::join('annual_cycle', function ($j) {
- $j->on('semesters.id', '=', 'annual_cycle.semester_start')
- ->orOn('semesters.id', '=', 'annual_cycle.semester_end');
- })
- ->where('annual_cycle.id', $this->annual_cycle_id)
- ->select('semesters.*')
- ->distinct()
- ->get();
- return $semester_ids;
- }
-
- public function getCoursesAttribute()
- {
- /*
- $sql = Course::join('typ_semester_courses', 'typ_semester_courses.course_id', '=', 'courses.id')
- ->join('typ_semester_objectives', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
- ->join("typ_semester_outcome", 'typ_semester_outcome.id', '=', 'typ_semester_objectives.typ_semester_outcome_id')
- ->join("annual_cycle", function ($join) {
- $join->on('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_start')
- ->orOn('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_end');
- })
- ->join('annual_plans', 'annual_plans.annual_cycle_id', '=', 'annual_cycle.id')
- ->join('typ_program', 'typ_program.program_id', '=', 'annual_plans.program_id')
- ->where('typ_program.id', '=', 'typ_semester_outcome.typ_program_id')
- ->where('annual_plans.program_id', $this->program_id)
- ->where('annual_plans.id', $this->id)
- ->select('courses.*', 'typ_semester_courses.id as typ_semester_course_id', 'annual_plans.program_id', 'typ_semester_outcome.semester_id as semester_id')
- ->toSql();
- Log::info($sql);
- Log::info("Aqui sql");
-
- */
- $courses = Course::join('typ_semester_courses', 'typ_semester_courses.course_id', '=', 'courses.id')
- ->join('typ_semester_objectives', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
- ->join("typ_semester_outcome", 'typ_semester_outcome.id', '=', 'typ_semester_objectives.typ_semester_outcome_id')
-
- ->join("annual_cycle", function ($join) {
-
- $join->on('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_start')
- ->orOn('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_end');
- })
- ->join('annual_plans', 'annual_plans.annual_cycle_id', '=', 'annual_cycle.id')
- ->join('typ_program', function ($join) {
-
- $join->on('typ_program.program_id', '=', 'annual_plans.program_id')
- ->on('typ_program.id', '=', 'typ_semester_outcome.typ_program_id');
- })
- ->where('annual_plans.program_id', $this->program_id)
- ->where('annual_plans.id', $this->id)
- ->select('courses.*', 'typ_semester_courses.id as typ_semester_course_id', 'annual_plans.program_id', 'typ_semester_outcome.semester_id as semester_id');
-
- //En templateController, for_template lo defino como el semestre que estoy buscando
- if (isset($this->for_template)) {
- $courses = $courses->where('typ_semester_outcome.semester_id', $this->for_template)
- ->groupBy("courses.id")
- ->orderBy("courses.number");
- }
-
- return $courses->get();
- }
-
- //Aprendi luego que se puede hacer esto smh
-
- public function getCoursesWithTransformativeActionsAttribute()
- {
- /*$courses = DB::table("annual_plans")
-
- ->join('annual_plan_transformative', 'annual_plans.id', '=', 'annual_plan_transformative.annual_plan_id')
- ->join('typ_semester_courses', 'annual_plan_transformative.typ_semester_course_id', '=', 'typ_semester_courses.id')
- ->where('annual_plan_id', $this->id)
- ->select('typ_semester_courses.id as typ_semester_course_id', 'typ_semester_courses.course_id as course_id')
- ->get();
- $course_list = [];
- foreach ($courses as $c) {
- $cour = Course::find($c->course_id);
- $cour->setAttribute('typ_semester_course_id', $c->typ_semester_course_id);
- $course_list[] = $cour;
- }
- return $course_list*/
-
- return Course::join('typ_semester_courses', 'typ_semester_courses.course_id', '=', 'courses.id')
- ->join('annual_plan_transformative', 'typ_semester_courses.id', '=', 'annual_plan_transformative.typ_semester_course_id')
- ->where('annual_plan_id', $this->id)
- ->select('courses.*', 'typ_semester_courses.id as typ_semester_course_id')
- ->groupBy("courses.id")
- //->with("proposed_transformative_actions")
- ->get();
- }
-
-
-
-
-
- public function getOutcomesAttribute()
- {
-
-
- return Outcome::join('typ_semester_outcome', 'typ_semester_outcome.outcome_id', '=', 'outcomes.id')
- ->join('annual_cycle', function ($j) {
- $j->on('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_start')
- ->orOn('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_end');
- })
- ->join('annual_plans', 'annual_cycle.id', '=', 'annual_plans.annual_cycle_id')
- ->join('typ_program', function ($j) {
- $j->on('typ_semester_outcome.typ_program_id', '=', 'typ_program.id')
- ->on('typ_program.program_id', '=', 'annual_plans.program_id');
- })
- ->join('typ_semester_objectives', 'typ_semester_objectives.typ_semester_outcome_id', '=', 'typ_semester_outcome.id')
- ->join('typ_semester_courses', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
- ->where('annual_plans.id', $this->id)
- ->groupBy('outcomes.id', 'semester_id')
- ->orderBy('typ_semester_outcome.semester_id')
- ->orderBy("outcomes.name", 'ASC')
- ->select(
- 'outcomes.*',
- 'outcomes.id as outcome_id',
- 'typ_semester_outcome.id as typ_semester_outcome_id',
- 'typ_semester_outcome.semester_id as semester_id',
- DB::raw("{$this->program_id} as program_id")
- )->get();
-
-
-
- /*$outcomes_query = DB::table('annual_plans')
- ->join('annual_cycle', 'annual_cycle.id', '=', 'annual_plans.annual_cycle_id')
- ->join('typ_semester_outcome', function ($q) {
- $q->on('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_start')
- ->orOn('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_end');
- })
- ->join('typ_program', function ($j) {
- $j->on('typ_semester_outcome.typ_program_id', '=', 'typ_program.id')
- ->on('typ_program.program_id', '=', 'annual_plans.program_id');
- })
- ->join('typ_semester_objectives', 'typ_semester_objectives.typ_semester_outcome_id', '=', 'typ_semester_outcome.id')
- ->join('typ_semester_courses', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
- ->join('outcomes', 'typ_semester_outcome.outcome_id', '=', 'outcomes.id')
- ->where('annual_plans.id', $this->id)
- ->groupBy('outcomes.id')
- ->orderBy('typ_semester_outcome.semester_id')
- ->select('outcomes.id as outcome_id', 'typ_semester_outcome.id as typ_semester_outcome_id', 'typ_semester_outcome.semester_id as semester_id');
- //Log::info($outcomes_query->toSql());
-
-
- //$outcomes = $outcomes_query->lists('outcome_id');
- //$outcomes_typ_semester_id = $outcomes_query->lists('typ_semester_outcome_id');
- //$outcomes_semester = $outcomes_query->lists('semester_id');
-
- //->lists(array('outcome_id', 'typ_semester_outcome_id', "typ_semester_outcome.semester_id"));
- $outcomes = $outcomes_query->get();
- //Log::info("an_id");
- //Log::info($an_id);
- $an_id = $this->id;
- //Log::info($an_id);
- //Log::info($outcomes);
-
-
-
- /*$outcomes_full = Outcome::whereIn("id", $outcomes)->get();
-
- Log::info($outcomes_full);
-
- foreach ($outcomes_full as $index => $outc) {
- $outc->setAttribute('typ_semester_outcome_id', $outcomes_typ_semester_id[$index]);
- $outc->setAttribute('semester_id', $outcomes_semester[$index]);
- $outc->setAttribute('program_id', $this->program_id);
- Log::info("Imagine");
- }
- //Log::info();*/
- /*
- $outcomes_full = [];
- //Log::info("Estamos aqui");
- //Log::info($outcomes);
- foreach ($outcomes as $index => $outc) {
-
- //Log::info("outcome_id");
- //Log::info($outc->outcome_id);
- $outcomes_full[$index] = Outcome::where('id', $outc->outcome_id)->first();
- //Log::info(array($outcome));
- $outcomes_full[$index]->setAttribute('typ_semester_outcome_id', $outc->typ_semester_outcome_id);
- $outcomes_full[$index]->setAttribute('semester_id', $outc->semester_id);
- $outcomes_full[$index]->setAttribute('program_id', $this->program_id);
- //$outcomes_full[] = $outcome;
- }
-
-
- return $outcomes_full;*/
-
- /*with([
- 'typ_semester_outcome_id' => function ($query) use (&$an_id) {
- Log::info($this->id);
- $query->join('typ_semester_outcome', 'typ_semester_outcome.outcome_id', '=', $this->id)
- ->join('annual_cycle', function ($q) {
- $q->on('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_start')
- ->orOn('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_end');
- })->join('typ_semester_objectives', 'typ_semester_objectives.typ_semester_outcome_id', '=', 'typ_semester_outcome.id')
- ->join('typ_semester_courses', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
-
- ->join('annual_cycle', 'annual_cycle.id', '=', 'annual_plans.annual_cycle_id')
- ->join('typ_semester_outcome', function ($q) {
- $q->on('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_start')
- ->orOn('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_end');
- })
- ->join('typ_program', function ($j) {
- $j->on('typ_semester_outcome.typ_program_id', '=', 'typ_program.id')
- ->on('typ_program.program_id', '=', 'annual_plans.program_id');
- })
- ->where('annual_plans.id', $an_id)
- ->select('typ_outcome_semester_id')
- ->first();
- //->first()->typ_outcome_semester_id;
- //->where('outcome_id',$this->id)
-
- }
- ]);*/
-
-
- /*
- select * from annual_plans
-
- select outcome_id, typ_semester_outcome_id, outcomes.* from annual_plans
-
- join annual_cycle on annual_cycle.id = annual_plans.annual_cycle_id
- join typ_semester_outcome on typ_semester_outcome.semester_id = annual_cycle.semester_start or typ_semester_outcome.semester_id = annual_cycle.semester_end
- join typ_program on typ_semester_outcome.typ_program_id = typ_program.id and typ_program.program_id = annual_plans.program_id
- join typ_semester_objectives on typ_semester_outcome.id = typ_semester_objectives.typ_semester_outcome_id
- join typ_semester_courses on typ_semester_objectives.id = typ_semester_courses.typ_semester_objective_id
- join outcomes on typ_semester_outcome.outcome_id = outcomes.id
-
- where annual_plans.id = 3
- GROUP by outcome_id
- */
- }
- }
|