説明なし

AnnualPlan.php 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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 getSemestersAttribute()
  19. {
  20. $semester_ids = Semester::join('annual_cycle', function ($j) {
  21. $j->on('semesters.id', '=', 'annual_cycle.semester_start')
  22. ->orOn('semesters.id', '=', 'annual_cycle.semester_end');
  23. })
  24. ->where('annual_cycle.id', $this->annual_cycle_id)
  25. ->select('semesters.*')
  26. ->distinct()
  27. ->get();
  28. return $semester_ids;
  29. }
  30. public function getCoursesAttribute()
  31. {
  32. /*
  33. $sql = Course::join('typ_semester_courses', 'typ_semester_courses.course_id', '=', 'courses.id')
  34. ->join('typ_semester_objectives', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
  35. ->join("typ_semester_outcome", 'typ_semester_outcome.id', '=', 'typ_semester_objectives.typ_semester_outcome_id')
  36. ->join("annual_cycle", function ($join) {
  37. $join->on('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_start')
  38. ->orOn('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_end');
  39. })
  40. ->join('annual_plans', 'annual_plans.annual_cycle_id', '=', 'annual_cycle.id')
  41. ->join('typ_program', 'typ_program.program_id', '=', 'annual_plans.program_id')
  42. ->where('typ_program.id', '=', 'typ_semester_outcome.typ_program_id')
  43. ->where('annual_plans.program_id', $this->program_id)
  44. ->where('annual_plans.id', $this->id)
  45. ->select('courses.*', 'typ_semester_courses.id as typ_semester_course_id', 'annual_plans.program_id', 'typ_semester_outcome.semester_id as semester_id')
  46. ->toSql();
  47. Log::info($sql);
  48. Log::info("Aqui sql");
  49. */
  50. $courses = Course::join('typ_semester_courses', 'typ_semester_courses.course_id', '=', 'courses.id')
  51. ->join('typ_semester_objectives', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
  52. ->join("typ_semester_outcome", 'typ_semester_outcome.id', '=', 'typ_semester_objectives.typ_semester_outcome_id')
  53. ->join("annual_cycle", function ($join) {
  54. $join->on('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_start')
  55. ->orOn('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_end');
  56. })
  57. ->join('annual_plans', 'annual_plans.annual_cycle_id', '=', 'annual_cycle.id')
  58. ->join('typ_program', function ($join) {
  59. $join->on('typ_program.program_id', '=', 'annual_plans.program_id')
  60. ->on('typ_program.id', '=', 'typ_semester_outcome.typ_program_id');
  61. })
  62. ->where('annual_plans.program_id', $this->program_id)
  63. ->where('annual_plans.id', $this->id)
  64. ->select('courses.*', 'typ_semester_courses.id as typ_semester_course_id', 'annual_plans.program_id', 'typ_semester_outcome.semester_id as semester_id');
  65. //En templateController, for_template lo defino como el semestre que estoy buscando
  66. if (isset($this->for_template)) {
  67. $courses = $courses->where('typ_semester_outcome.semester_id', $this->for_template)
  68. ->groupBy("courses.id")
  69. ->orderBy("courses.number");
  70. }
  71. return $courses->get();
  72. }
  73. //Aprendi luego que se puede hacer esto smh
  74. public function getCoursesWithTransformativeActionsAttribute()
  75. {
  76. /*$courses = DB::table("annual_plans")
  77. ->join('annual_plan_transformative', 'annual_plans.id', '=', 'annual_plan_transformative.annual_plan_id')
  78. ->join('typ_semester_courses', 'annual_plan_transformative.typ_semester_course_id', '=', 'typ_semester_courses.id')
  79. ->where('annual_plan_id', $this->id)
  80. ->select('typ_semester_courses.id as typ_semester_course_id', 'typ_semester_courses.course_id as course_id')
  81. ->get();
  82. $course_list = [];
  83. foreach ($courses as $c) {
  84. $cour = Course::find($c->course_id);
  85. $cour->setAttribute('typ_semester_course_id', $c->typ_semester_course_id);
  86. $course_list[] = $cour;
  87. }
  88. return $course_list*/
  89. return Course::join('typ_semester_courses', 'typ_semester_courses.course_id', '=', 'courses.id')
  90. ->join('annual_plan_transformative', 'typ_semester_courses.id', '=', 'annual_plan_transformative.typ_semester_course_id')
  91. ->where('annual_plan_id', $this->id)
  92. ->select('courses.*', 'typ_semester_courses.id as typ_semester_course_id')
  93. ->groupBy("courses.id")
  94. //->with("proposed_transformative_actions")
  95. ->get();
  96. }
  97. public function getOutcomesAttribute()
  98. {
  99. return Outcome::join('typ_semester_outcome', 'typ_semester_outcome.outcome_id', '=', 'outcomes.id')
  100. ->join('annual_cycle', function ($j) {
  101. $j->on('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_start')
  102. ->orOn('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_end');
  103. })
  104. ->join('annual_plans', 'annual_cycle.id', '=', 'annual_plans.annual_cycle_id')
  105. ->join('typ_program', function ($j) {
  106. $j->on('typ_semester_outcome.typ_program_id', '=', 'typ_program.id')
  107. ->on('typ_program.program_id', '=', 'annual_plans.program_id');
  108. })
  109. ->join('typ_semester_objectives', 'typ_semester_objectives.typ_semester_outcome_id', '=', 'typ_semester_outcome.id')
  110. ->join('typ_semester_courses', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
  111. ->where('annual_plans.id', $this->id)
  112. ->groupBy('outcomes.id', 'semester_id')
  113. ->orderBy('typ_semester_outcome.semester_id')
  114. ->orderBy("outcomes.name", 'ASC')
  115. ->select(
  116. 'outcomes.*',
  117. 'outcomes.id as outcome_id',
  118. 'typ_semester_outcome.id as typ_semester_outcome_id',
  119. 'typ_semester_outcome.semester_id as semester_id',
  120. DB::raw("{$this->program_id} as program_id")
  121. )->get();
  122. /*$outcomes_query = DB::table('annual_plans')
  123. ->join('annual_cycle', 'annual_cycle.id', '=', 'annual_plans.annual_cycle_id')
  124. ->join('typ_semester_outcome', function ($q) {
  125. $q->on('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_start')
  126. ->orOn('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_end');
  127. })
  128. ->join('typ_program', function ($j) {
  129. $j->on('typ_semester_outcome.typ_program_id', '=', 'typ_program.id')
  130. ->on('typ_program.program_id', '=', 'annual_plans.program_id');
  131. })
  132. ->join('typ_semester_objectives', 'typ_semester_objectives.typ_semester_outcome_id', '=', 'typ_semester_outcome.id')
  133. ->join('typ_semester_courses', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
  134. ->join('outcomes', 'typ_semester_outcome.outcome_id', '=', 'outcomes.id')
  135. ->where('annual_plans.id', $this->id)
  136. ->groupBy('outcomes.id')
  137. ->orderBy('typ_semester_outcome.semester_id')
  138. ->select('outcomes.id as outcome_id', 'typ_semester_outcome.id as typ_semester_outcome_id', 'typ_semester_outcome.semester_id as semester_id');
  139. //Log::info($outcomes_query->toSql());
  140. //$outcomes = $outcomes_query->lists('outcome_id');
  141. //$outcomes_typ_semester_id = $outcomes_query->lists('typ_semester_outcome_id');
  142. //$outcomes_semester = $outcomes_query->lists('semester_id');
  143. //->lists(array('outcome_id', 'typ_semester_outcome_id', "typ_semester_outcome.semester_id"));
  144. $outcomes = $outcomes_query->get();
  145. //Log::info("an_id");
  146. //Log::info($an_id);
  147. $an_id = $this->id;
  148. //Log::info($an_id);
  149. //Log::info($outcomes);
  150. /*$outcomes_full = Outcome::whereIn("id", $outcomes)->get();
  151. Log::info($outcomes_full);
  152. foreach ($outcomes_full as $index => $outc) {
  153. $outc->setAttribute('typ_semester_outcome_id', $outcomes_typ_semester_id[$index]);
  154. $outc->setAttribute('semester_id', $outcomes_semester[$index]);
  155. $outc->setAttribute('program_id', $this->program_id);
  156. Log::info("Imagine");
  157. }
  158. //Log::info();*/
  159. /*
  160. $outcomes_full = [];
  161. //Log::info("Estamos aqui");
  162. //Log::info($outcomes);
  163. foreach ($outcomes as $index => $outc) {
  164. //Log::info("outcome_id");
  165. //Log::info($outc->outcome_id);
  166. $outcomes_full[$index] = Outcome::where('id', $outc->outcome_id)->first();
  167. //Log::info(array($outcome));
  168. $outcomes_full[$index]->setAttribute('typ_semester_outcome_id', $outc->typ_semester_outcome_id);
  169. $outcomes_full[$index]->setAttribute('semester_id', $outc->semester_id);
  170. $outcomes_full[$index]->setAttribute('program_id', $this->program_id);
  171. //$outcomes_full[] = $outcome;
  172. }
  173. return $outcomes_full;*/
  174. /*with([
  175. 'typ_semester_outcome_id' => function ($query) use (&$an_id) {
  176. Log::info($this->id);
  177. $query->join('typ_semester_outcome', 'typ_semester_outcome.outcome_id', '=', $this->id)
  178. ->join('annual_cycle', function ($q) {
  179. $q->on('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_start')
  180. ->orOn('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_end');
  181. })->join('typ_semester_objectives', 'typ_semester_objectives.typ_semester_outcome_id', '=', 'typ_semester_outcome.id')
  182. ->join('typ_semester_courses', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
  183. ->join('annual_cycle', 'annual_cycle.id', '=', 'annual_plans.annual_cycle_id')
  184. ->join('typ_semester_outcome', function ($q) {
  185. $q->on('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_start')
  186. ->orOn('typ_semester_outcome.semester_id', '=', 'annual_cycle.semester_end');
  187. })
  188. ->join('typ_program', function ($j) {
  189. $j->on('typ_semester_outcome.typ_program_id', '=', 'typ_program.id')
  190. ->on('typ_program.program_id', '=', 'annual_plans.program_id');
  191. })
  192. ->where('annual_plans.id', $an_id)
  193. ->select('typ_outcome_semester_id')
  194. ->first();
  195. //->first()->typ_outcome_semester_id;
  196. //->where('outcome_id',$this->id)
  197. }
  198. ]);*/
  199. /*
  200. select * from annual_plans
  201. select outcome_id, typ_semester_outcome_id, outcomes.* from annual_plans
  202. join annual_cycle on annual_cycle.id = annual_plans.annual_cycle_id
  203. join typ_semester_outcome on typ_semester_outcome.semester_id = annual_cycle.semester_start or typ_semester_outcome.semester_id = annual_cycle.semester_end
  204. join typ_program on typ_semester_outcome.typ_program_id = typ_program.id and typ_program.program_id = annual_plans.program_id
  205. join typ_semester_objectives on typ_semester_outcome.id = typ_semester_objectives.typ_semester_outcome_id
  206. join typ_semester_courses on typ_semester_objectives.id = typ_semester_courses.typ_semester_objective_id
  207. join outcomes on typ_semester_outcome.outcome_id = outcomes.id
  208. where annual_plans.id = 3
  209. GROUP by outcome_id
  210. */
  211. }
  212. }