Sin descripción

Objective.php 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. return Outcome::join('typ_semester_outcome', 'typ_semester_outcome.outcome_id', '=', 'outcomes.id')
  24. ->join('typ_semester_objectives', 'typ_semester_objectives.typ_semester_outcome_id', '=', 'typ_semester_outcome.id')
  25. ->where('typ_semester_objectives.id', $this->typ_semester_objective_id)
  26. ->select('typ_semester_outcome.id as typ_semester_outcome_id', 'outcomes.*')
  27. ->first();
  28. }
  29. public function getGroupedAnnualCourseAttribute()
  30. {
  31. if (isset($this->typ_semester_objective_id)) {
  32. /*$course_codes = DB::table('typ_semester_courses')
  33. ->join('courses', 'courses.id', '=', 'typ_semester_courses.course_id')
  34. ->where('typ_semester_objective_id', $this->typ_semester_objective_id)
  35. ->where('courses.program_id', $this->program_id)
  36. ->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")
  37. ->get();*/
  38. return Course::join('typ_semester_courses', 'courses.id', '=', 'typ_semester_courses.course_id')
  39. ->where('typ_semester_objective_id', $this->typ_semester_objective_id)
  40. ->where('courses.program_id', $this->program_id)
  41. ->select('courses.*', 'typ_semester_courses.id as typ_semester_course_id', DB::raw("'{$this->semester_id}' as semester_id"), "courses.program_id")
  42. ->get();
  43. // $course_code_id = $course_codes->lists('course_id');
  44. //$course_code_typ = $course_codes->lists('typ_semester_course_id');
  45. /*
  46. $courses = []; //Course::whereIn("id", $course_code_id)->get();
  47. foreach ($course_codes as $i => $code) {
  48. $c = Course::where('id', $code->course_id)->first();
  49. $c->setAttribute('typ_semester_course_id', $code->typ_semester_course_id); //$course_code_typ[$i]);
  50. /*$c->setAttribute(
  51. 'transforming_actions',
  52. DB::table('annual_plan_transformative')
  53. ->join('transformative_actions', 'transformative_actions.id', '=', 'annual_plan_transformative.trans_id')
  54. ->where('typ_semester_course_id', $c->typ_semester_course_id)
  55. ->select('transformative_actions.*')
  56. ->get()
  57. );
  58. //$c->setAttribute("future_typ_course_id", $this->()); //Course::getFutureTypSemesterCourses($c->typ_semester_course_id, $c->program_id));
  59. $c->setAttribute("students", Course::getStudentReportForOutcome($c));
  60. //$c->setAttribute("criteria", Course::getCriteriaPlanReport($c));
  61. $courses[] = $c;
  62. }
  63. return $courses;
  64. */
  65. }
  66. return null;
  67. }
  68. /**
  69. * Return the outcomes that the objective belongs to
  70. *
  71. * @return Illuminate\Database\Eloquent\Model
  72. */
  73. //Must have typ_semester_objective_id, program_id,semester_id to work
  74. //funciona con Outcome::getObjectivesReport
  75. //Es como la imagen suelta por el app llamada, tabla_estudiantes.jpg
  76. //
  77. public static function getPlanReport($objective)
  78. {
  79. $course_codes = DB::table('typ_semester_courses')
  80. ->join('courses', 'courses.id', '=', 'typ_semester_courses.course_id')
  81. ->where('typ_semester_objective_id', $objective->typ_semester_objective_id)
  82. ->where('courses.program_id', $objective->program_id)
  83. ->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")
  84. ->get();
  85. Log::info($course_codes);
  86. //$course_codes['studentPerOutcome'] = array();
  87. foreach ($course_codes as $course_code) {
  88. $course_code->transforming_actions = DB::table('annual_plan_transformative')
  89. ->join('transformative_actions', 'transformative_actions.id', '=', 'annual_plan_transformative.trans_id')
  90. ->where('typ_semester_course_id', $course_code->typ_semester_course_id)
  91. ->select('transformative_actions.*')
  92. ->get();
  93. $course_code->future_typ_course_id = Course::getFutureTypSemesterCourses($course_code->typ_semester_course_id, $course_code->program_id);
  94. $course_code->students = Course::getStudentReportForOutcome($course_code);
  95. //Log::info(array($course_code));
  96. $course_code->criteria = Course::getCriteriaPlanReport($course_code);
  97. }
  98. return $course_codes;
  99. }
  100. public function outcomes()
  101. {
  102. return $this->belongsToMany('Outcome', 'objective_outcome', 'objective_id', 'outcome_id');
  103. }
  104. public function outcome()
  105. {
  106. return $this->belongsTo('Outcome');
  107. }
  108. /**
  109. * Return the program that the objective belongs to
  110. *
  111. * @return Illuminate\Database\Eloquent\Model
  112. */
  113. public function outcome_id()
  114. {
  115. return $this->hasMany('Objective_Outcome', 'objective_id');
  116. }
  117. }