Sin descripción

Objective.php 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. use Illuminate\Database\Eloquent\SoftDeletingTrait;
  3. class Objective extends Eloquent
  4. {
  5. use SoftDeletingTrait;
  6. protected $fillable = array('text', 'outcome_id', 'active');
  7. protected $table = 'objectives';
  8. protected $appends = array("grouped_annual_course", 'programs');
  9. /**
  10. * Return the program that the objective belongs to
  11. *
  12. * @return Illuminate\Database\Eloquent\Model
  13. */
  14. public function getProgramsAttribute()
  15. {
  16. return Program::join('objective_program', 'programs.id', '=', 'objective_program.program_id')
  17. ->where('objective_program.objective_id', $this->id)
  18. ->get();
  19. }
  20. //paired_outcome
  21. public function getPairedOutcomeAttribute()
  22. {
  23. if (isset($this->typ_semester_objective_id))
  24. return Outcome::join('typ_semester_outcome', 'typ_semester_outcome.outcome_id', '=', 'outcomes.id')
  25. ->join('typ_semester_objectives', 'typ_semester_objectives.typ_semester_outcome_id', '=', 'typ_semester_outcome.id')
  26. ->where('typ_semester_objectives.id', $this->typ_semester_objective_id)
  27. ->select('typ_semester_outcome.id as typ_semester_outcome_id', 'outcomes.*')
  28. ->first();
  29. }
  30. //public function pairedCriteria(){
  31. // return Criterion::
  32. //}
  33. public function getGroupedAnnualCourseAttribute()
  34. {
  35. if (isset($this->typ_semester_objective_id)) {
  36. /*$course_codes = DB::table('typ_semester_courses')
  37. ->join('courses', 'courses.id', '=', 'typ_semester_courses.course_id')
  38. ->where('typ_semester_objective_id', $this->typ_semester_objective_id)
  39. ->where('courses.program_id', $this->program_id)
  40. ->select('courses.code', 'courses.number', 'courses.id as course_id', 'typ_semester_courses.id as typ_semester_course_id', DB::raw("'{$this->semester_id}' as semester_id"), "courses.program_id")
  41. ->get();*/
  42. return Course::join('typ_semester_courses', 'courses.id', '=', 'typ_semester_courses.course_id')
  43. ->where('typ_semester_objective_id', $this->typ_semester_objective_id)
  44. //->where('courses.program_id', $this->program_id)
  45. ->select('courses.*', 'typ_semester_courses.id as typ_semester_course_id', DB::raw("'{$this->semester_id}' as semester_id"), "courses.program_id")
  46. ->get();
  47. // $course_code_id = $course_codes->lists('course_id');
  48. //$course_code_typ = $course_codes->lists('typ_semester_course_id');
  49. /*
  50. $courses = []; //Course::whereIn("id", $course_code_id)->get();
  51. foreach ($course_codes as $i => $code) {
  52. $c = Course::where('id', $code->course_id)->first();
  53. $c->setAttribute('typ_semester_course_id', $code->typ_semester_course_id); //$course_code_typ[$i]);
  54. /*$c->setAttribute(
  55. 'transforming_actions',
  56. DB::table('annual_plan_transformative')
  57. ->join('transformative_actions', 'transformative_actions.id', '=', 'annual_plan_transformative.trans_id')
  58. ->where('typ_semester_course_id', $c->typ_semester_course_id)
  59. ->select('transformative_actions.*')
  60. ->get()
  61. );
  62. //$c->setAttribute("future_typ_course_id", $this->()); //Course::getFutureTypSemesterCourses($c->typ_semester_course_id, $c->program_id));
  63. $c->setAttribute("students", Course::getStudentReportForOutcome($c));
  64. //$c->setAttribute("criteria", Course::getCriteriaPlanReport($c));
  65. $courses[] = $c;
  66. }
  67. return $courses;
  68. */
  69. }
  70. return null;
  71. }
  72. /**
  73. * Return the outcomes that the objective belongs to
  74. *
  75. * @return Illuminate\Database\Eloquent\Model
  76. */
  77. //Must have typ_semester_objective_id, program_id,semester_id to work
  78. //funciona con Outcome::getObjectivesReport
  79. //Es como la imagen suelta por el app llamada, tabla_estudiantes.jpg
  80. //
  81. public static function getPlanReport($objective)
  82. {
  83. $course_codes = DB::table('typ_semester_courses')
  84. ->join('courses', 'courses.id', '=', 'typ_semester_courses.course_id')
  85. ->where('typ_semester_objective_id', $objective->typ_semester_objective_id)
  86. ->where('courses.program_id', $objective->program_id)
  87. ->select('courses.code', 'courses.number', 'courses.id as course_id', 'typ_semester_courses.id as typ_semester_course_id', DB::raw("{$objective->semester_id} as semester_id"), "courses.program_id")
  88. ->get();
  89. //Log::info($course_codes);
  90. Log::info("No es aqui");
  91. //$course_codes['studentPerOutcome'] = array();
  92. foreach ($course_codes as $course_code) {
  93. $course_code->transforming_actions = DB::table('annual_plan_transformative')
  94. ->join('transformative_actions', 'transformative_actions.id', '=', 'annual_plan_transformative.trans_id')
  95. ->where('typ_semester_course_id', $course_code->typ_semester_course_id)
  96. ->select('transformative_actions.*')
  97. ->get();
  98. $course_code->future_typ_course_id = Course::getFutureTypSemesterCourses($course_code->typ_semester_course_id, $course_code->program_id);
  99. $course_code->grouped = 1;
  100. $course_code->students = Course::getStudentReportForOutcome($course_code);
  101. //Log::info(array($course_code));
  102. Log::info("dimelo");
  103. $course_code->criteria = Course::getCriteriaPlanReport($course_code);
  104. }
  105. Log::info("???");
  106. return $course_codes;
  107. }
  108. public function outcomes()
  109. {
  110. return $this->belongsToMany('Outcome', 'objective_outcome', 'objective_id', 'outcome_id');
  111. }
  112. public function outcome()
  113. {
  114. return $this->belongsTo('Outcome');
  115. }
  116. /**
  117. * Return the program that the objective belongs to
  118. *
  119. * @return Illuminate\Database\Eloquent\Model
  120. */
  121. public function outcome_id()
  122. {
  123. return $this->hasMany('Objective_Outcome', 'objective_id');
  124. }
  125. }