Aucune description

AnnualPlan.php 9.6KB

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