Sin descripción

AnnualPlan.php 9.7KB

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