Geen omschrijving

AnnualPlan.php 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <?php
  2. class AnnualPlan extends \Eloquent
  3. {
  4. protected $fillable = [];
  5. protected $table = 'annual_plans';
  6. protected $appends = ["outcomes"];
  7. // return outcomes in annual plan to
  8. public function program()
  9. {
  10. return $this->belongsTo('Program');
  11. }
  12. public function annualCycle()
  13. {
  14. return $this->belongsTo('AnnualCycle');
  15. }
  16. //courses_with_transformative
  17. //
  18. public function getCoursesAttribute()
  19. {
  20. $sql = Course::join('typ_semester_courses', 'typ_semester_courses.course_id', '=', 'courses.id')
  21. ->join('typ_semester_objectives', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
  22. ->join("typ_semester_outcome", 'typ_semester_outcome.id', '=', 'typ_semester_objectives.typ_semester_outcome_id')
  23. ->join("annual_cycle", function ($join) {
  24. $join->on('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_start')
  25. ->orOn('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_end');
  26. })
  27. ->join('annual_plans', 'annual_plans.annual_cycle_id', '=', 'annual_cycle.id')
  28. ->where('annual_plans.program_id', $this->program_id)
  29. ->where('annual_plans.id', $this->id)
  30. ->select('courses.*', 'typ_semester_courses.id as typ_semester_course_id', 'annual_plans.program_id', 'typ_semester_outcome.semester_id as semester_id')
  31. ->toSql();
  32. Log::info($sql);
  33. Log::info("Aqui sql");
  34. return Course::join('typ_semester_courses', 'typ_semester_courses.course_id', '=', 'courses.id')
  35. ->join('typ_semester_objectives', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
  36. ->join("typ_semester_outcome", 'typ_semester_outcome.id', '=', 'typ_semester_objectives.typ_semester_outcome_id')
  37. ->join("annual_cycle", function ($join) {
  38. $join->on('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_start')
  39. ->orOn('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_end');
  40. })
  41. ->join('annual_plans', 'annual_plans.annual_cycle_id', '=', 'annual_cycle.id')
  42. ->where('annual_plans.program_id', $this->program_id)
  43. ->where('annual_plans.id', $this->id)
  44. ->select('courses.*', 'typ_semester_courses.id as typ_semester_course_id', 'annual_plans.program_id', 'typ_semester_outcome.semester_id as semester_id')
  45. ->get();
  46. }
  47. //Aprendi luego que se puede hacer esto smh
  48. public function getCoursesWithTransformativeActionsAttribute()
  49. {
  50. /*$courses = DB::table("annual_plans")
  51. ->join('annual_plan_transformative', 'annual_plans.id', '=', 'annual_plan_transformative.annual_plan_id')
  52. ->join('typ_semester_courses', 'annual_plan_transformative.typ_semester_course_id', '=', 'typ_semester_courses.id')
  53. ->where('annual_plan_id', $this->id)
  54. ->select('typ_semester_courses.id as typ_semester_course_id', 'typ_semester_courses.course_id as course_id')
  55. ->get();
  56. $course_list = [];
  57. foreach ($courses as $c) {
  58. $cour = Course::find($c->course_id);
  59. $cour->setAttribute('typ_semester_course_id', $c->typ_semester_course_id);
  60. $course_list[] = $cour;
  61. }
  62. return $course_list*/
  63. return Course::join('typ_semester_courses', 'typ_semester_courses.course_id', '=', 'courses.id')
  64. ->join('annual_plan_transformative', 'typ_semester_courses.id', '=', 'annual_plan_transformative.typ_semester_course_id')
  65. ->where('annual_plan_id', $this->id)
  66. ->select('courses.*', 'typ_semester_courses.id as typ_semester_course_id')
  67. ->groupBy("courses.id")
  68. //->with("proposed_transformative_actions")
  69. ->get();
  70. }
  71. public function getOutcomesAttribute()
  72. {
  73. return Outcome::join('typ_semester_outcome', 'typ_semester_outcome.outcome_id', '=', 'outcomes.id')
  74. ->join('annual_cycle', function ($j) {
  75. $j->on('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_start')
  76. ->orOn('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_end');
  77. })
  78. ->join('annual_plans', 'annual_cycle.id', '=', 'annual_plans.annual_cycle_id')
  79. ->join('typ_program', function ($j) {
  80. $j->on('typ_semester_outcome.typ_program_id', '=', 'typ_program.id')
  81. ->on('typ_program.program_id', '=', 'annual_plans.program_id');
  82. })
  83. ->join('typ_semester_objectives', 'typ_semester_objectives.typ_semester_outcome_id', '=', 'typ_semester_outcome.id')
  84. ->join('typ_semester_courses', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
  85. ->where('annual_plans.id', $this->id)
  86. ->groupBy('outcomes.id')
  87. ->orderBy('typ_semester_outcome.semester_id')
  88. ->select(
  89. 'outcomes.*',
  90. 'outcomes.id as outcome_id',
  91. 'typ_semester_outcome.id as typ_semester_outcome_id',
  92. 'typ_semester_outcome.semester_id as semester_id',
  93. DB::raw("{$this->program_id} as program_id")
  94. )->get();
  95. /*$outcomes_query = DB::table('annual_plans')
  96. ->join('annual_cycle', 'annual_cycle.id', '=', 'annual_plans.annual_cycle_id')
  97. ->join('typ_semester_outcome', function ($q) {
  98. $q->on('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_start')
  99. ->orOn('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_end');
  100. })
  101. ->join('typ_program', function ($j) {
  102. $j->on('typ_semester_outcome.typ_program_id', '=', 'typ_program.id')
  103. ->on('typ_program.program_id', '=', 'annual_plans.program_id');
  104. })
  105. ->join('typ_semester_objectives', 'typ_semester_objectives.typ_semester_outcome_id', '=', 'typ_semester_outcome.id')
  106. ->join('typ_semester_courses', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
  107. ->join('outcomes', 'typ_semester_outcome.outcome_id', '=', 'outcomes.id')
  108. ->where('annual_plans.id', $this->id)
  109. ->groupBy('outcomes.id')
  110. ->orderBy('typ_semester_outcome.semester_id')
  111. ->select('outcomes.id as outcome_id', 'typ_semester_outcome.id as typ_semester_outcome_id', 'typ_semester_outcome.semester_id as semester_id');
  112. //Log::info($outcomes_query->toSql());
  113. //$outcomes = $outcomes_query->lists('outcome_id');
  114. //$outcomes_typ_semester_id = $outcomes_query->lists('typ_semester_outcome_id');
  115. //$outcomes_semester = $outcomes_query->lists('semester_id');
  116. //->lists(array('outcome_id', 'typ_semester_outcome_id', "typ_semester_outcome.semester_id"));
  117. $outcomes = $outcomes_query->get();
  118. //Log::info("an_id");
  119. //Log::info($an_id);
  120. $an_id = $this->id;
  121. //Log::info($an_id);
  122. //Log::info($outcomes);
  123. /*$outcomes_full = Outcome::whereIn("id", $outcomes)->get();
  124. Log::info($outcomes_full);
  125. foreach ($outcomes_full as $index => $outc) {
  126. $outc->setAttribute('typ_semester_outcome_id', $outcomes_typ_semester_id[$index]);
  127. $outc->setAttribute('semester_id', $outcomes_semester[$index]);
  128. $outc->setAttribute('program_id', $this->program_id);
  129. Log::info("Imagine");
  130. }
  131. //Log::info();*/
  132. /*
  133. $outcomes_full = [];
  134. //Log::info("Estamos aqui");
  135. //Log::info($outcomes);
  136. foreach ($outcomes as $index => $outc) {
  137. //Log::info("outcome_id");
  138. //Log::info($outc->outcome_id);
  139. $outcomes_full[$index] = Outcome::where('id', $outc->outcome_id)->first();
  140. //Log::info(array($outcome));
  141. $outcomes_full[$index]->setAttribute('typ_semester_outcome_id', $outc->typ_semester_outcome_id);
  142. $outcomes_full[$index]->setAttribute('semester_id', $outc->semester_id);
  143. $outcomes_full[$index]->setAttribute('program_id', $this->program_id);
  144. //$outcomes_full[] = $outcome;
  145. }
  146. return $outcomes_full;*/
  147. /*with([
  148. 'typ_semester_outcome_id' => function ($query) use (&$an_id) {
  149. Log::info($this->id);
  150. $query->join('typ_semester_outcome', 'typ_semester_outcome.outcome_id', '=', $this->id)
  151. ->join('annual_cycle', function ($q) {
  152. $q->on('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_start')
  153. ->orOn('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_end');
  154. })->join('typ_semester_objectives', 'typ_semester_objectives.typ_semester_outcome_id', '=', 'typ_semester_outcome.id')
  155. ->join('typ_semester_courses', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
  156. ->join('annual_cycle', 'annual_cycle.id', '=', 'annual_plans.annual_cycle_id')
  157. ->join('typ_semester_outcome', function ($q) {
  158. $q->on('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_start')
  159. ->orOn('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_end');
  160. })
  161. ->join('typ_program', function ($j) {
  162. $j->on('typ_semester_outcome.typ_program_id', '=', 'typ_program.id')
  163. ->on('typ_program.program_id', '=', 'annual_plans.program_id');
  164. })
  165. ->where('annual_plans.id', $an_id)
  166. ->select('typ_outcome_semester_id')
  167. ->first();
  168. //->first()->typ_outcome_semester_id;
  169. //->where('outcome_id',$this->id)
  170. }
  171. ]);*/
  172. /*
  173. select * from annual_plans
  174. select outcome_id, typ_semester_outcome_id, outcomes.* from annual_plans
  175. join annual_cycle on annual_cycle.id = annual_plans.annual_cycle_id
  176. join typ_semester_outcome on typ_semester_outcome.semester_id = annual_cycle.semester_start or typ_semester_outcome.semester_id = annual_cycle.semester_end
  177. join typ_program on typ_semester_outcome.typ_program_id = typ_program.id and typ_program.program_id = annual_plans.program_id
  178. join typ_semester_objectives on typ_semester_outcome.id = typ_semester_objectives.typ_semester_outcome_id
  179. join typ_semester_courses on typ_semester_objectives.id = typ_semester_courses.typ_semester_objective_id
  180. join outcomes on typ_semester_outcome.outcome_id = outcomes.id
  181. where annual_plans.id = 3
  182. GROUP by outcome_id
  183. */
  184. }
  185. }