hasMany('Program')->orderBy('name', 'asc'); } public function coordinators() { return $this->hasMany('User'); } public function courses() { return $this->hasManyThrough('Course', 'Program')->orderBy('name', 'asc'); } public function templates() { return $this->hasMany('Template')->orderBy('name', 'asc'); } public function getUndergraduateProgramsAttribute() { return $this->hasMany("Program")->where('is_graduate', 0)->orderBy("name", 'asc'); } public function getGraduateProgramsAttribute() { return $this->hasMany("Program")->where('is_graduate', 1)->orderBy("name", 'asc'); } //Esto envia /* [ undergraduate_info:[ outcomes_attempted_uncombined:{ outcome_1: count(students), } outcomes_attempted_combined:{ } outcomes_achieved_uncombined:{ } outcomes_achieved_combined:{ } ], graduate_info:[ ] ] */ public function getSchoolStudentsPerOutcomeAttribute() { $semesters = Semester::whereIn('id', Session::get('semesters_ids'))->get(); $outcomes_grad = Outcome::active_by_semesters($semesters, 1); $outcomes_undergrad = Outcome::active_by_semesters($semesters, 0); $outcomes = Outcome::orderBy('name', 'asc')->get(); $array_to_send = []; $undergraduate_students = DB::table('assessments') ->join('activity_criterion', 'activity_criterion.id', '=', 'assessments.activity_criterion_id') ->join('activities', 'activities.id', '=', 'activity_criterion.activity_id') ->join('courses', 'courses.id', '=', 'activities.course_id') ->join('students', 'students.id', '=', 'assessments.student_id') ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id') ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id') ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id') ->join('semesters', 'semesters.id', '=', 'courses.semester_id') ->whereIn('students.program_id', $this->undergraduate_programs->lists('id')) ->whereIn('semester_id', Session::get('semesters_ids')) ->where('semesters.is_visible', '=', 1) ->select('student_id', 'students.program_id', 'semesters.code', 'outcome_id', 'criterion_objective_outcome.criterion_id', 'score', 'expected_points') ->addSelect(DB::raw("count(activity_criterion.criterion_id) as criteria_attempted")) ->addSelect(DB::raw("count(CASE WHEN score>= expected_points then 1 else null END) as criteria_achieved")) ->groupBy('students.id', 'outcome_id') ->get(); //$array_to_send["undergraduate_students"] = $undergraduate_students; $graduate_students = DB::table('assessments') ->join('activity_criterion', 'activity_criterion.id', '=', 'assessments.activity_criterion_id') ->join('activities', 'activities.id', '=', 'activity_criterion.activity_id') ->join('courses', 'courses.id', '=', 'activities.course_id') ->join('students', 'students.id', '=', 'assessments.student_id') ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id') ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id') ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id') ->join('semesters', 'semesters.id', '=', 'courses.semester_id') ->whereIn('students.program_id', $this->graduate_programs->lists('id')) ->whereIn('semester_id', Session::get('semesters_ids')) ->where('semesters.is_visible', '=', 1) ->select('student_id', 'students.program_id', 'semesters.code', 'outcome_id', 'criterion_objective_outcome.criterion_id', 'score', 'expected_points') ->addSelect(DB::raw("count(activity_criterion.criterion_id) as criteria_attempted")) ->addSelect(DB::raw("count(CASE WHEN score>= expected_points then 1 else null END) as criteria_achieved")) ->groupBy('students.id', 'outcome_id') ->get(); //$array_to_send["graduate_students"] = $graduate_students; //Log::info(count($graduate_students)); //Log::info(count($undergraduate_students)); $outcome_ids = DB::table("outcomes") ->whereNotNull('new_outcome_id') ->get(); $combined_outcomes = []; foreach ($outcome_ids as $outcome) { $combined_outcomes[$outcome->id] = $outcome->new_outcome_id; } //Necesito undergraduateCombined, undergraduateUncombined, //lo mismo pa graduate $array_to_send['undergraduate_info'] = []; $array_to_send['graduate_info'] = []; $array_to_send['undergraduate_info']['outcomes_attempted_uncombined'] = []; $array_to_send['undergraduate_info']['outcomes_achieved_uncombined'] = []; $array_to_send['graduate_info']['outcomes_attempted_uncombined'] = []; $array_to_send['graduate_info']['outcomes_achieved_uncombined'] = []; $under_out_att = []; $under_out_ach = []; foreach ($outcomes as $outcome) { $under_out_att[$outcome->id] = 0; $under_out_ach[$outcome->id] = 0; } //las filas son , estudiante, outcome que intentó, criterios_attempted, criterion_achieved, foreach ($undergraduate_students as $result) { $crit_att = $result->criteria_attempted; $crit_ach = $result->criteria_achieved; $under_out_att[$result->outcome_id] += 1; if ($crit_att != 0 && ($crit_ach / $crit_att) * 100 >= 66.67) { $under_out_ach[$result->outcome_id] += 1; } } $grad_out_att = []; $grad_out_ach = []; foreach ($outcomes as $outcome) { $grad_out_att[$outcome->id] = 0; $grad_out_ach[$outcome->id] = 0; } //las filas son , estudiante, outcome que intentó, criterios_attempted, criterion_achieved, foreach ($graduate_students as $result) { $crit_att = $result->criteria_attempted; $crit_ach = $result->criteria_achieved; $grad_out_att[$result->outcome_id] += 1; if ($crit_att != 0 && ($crit_ach / $crit_att) * 100 >= 66.67) { $grad_out_ach[$result->outcome_id] += 1; } } $array_to_send['undergraduate_info']['outcomes_attempted_uncombined'] = $under_out_att; $array_to_send['undergraduate_info']['outcomes_achieved_uncombined'] = $under_out_ach; $array_to_send['graduate_info']['outcomes_attempted_uncombined'] = $grad_out_att; $array_to_send['graduate_info']['outcomes_achieved_uncombined'] = $grad_out_ach; $array_to_send['undergraduate_info']['outcomes_attempted_combined'] = []; $array_to_send['undergraduate_info']['outcomes_achieved_combined'] = []; $array_to_send['graduate_info']['outcomes_attempted_combined'] = []; $array_to_send['graduate_info']['outcomes_achieved_combined'] = []; $under_out_att = []; $under_out_ach = []; foreach ($outcomes as $outcome) { $under_out_att[$outcome->id] = 0; $under_out_ach[$outcome->id] = 0; } //preprocess para combined_students $the_processed_table = []; foreach ($undergraduate_students as $result) { $student_id = $result->student_id; $outcome_id = $result->outcome_id; if (isset($combined_outcomes[$outcome_id])) $outcome_id = $combined_outcomes[$outcome_id]; if (!isset($the_processed_table[$student_id])) { $the_processed_table[$student_id] = []; } //si en esta tabla, el estudiante no está pareado con este dominio, entonces registra // los criterios, achieved y attempted if (!isset($the_processed_table[$student_id][$outcome_id])) { $the_processed_table[$student_id][$outcome_id] = array( "criteria_attempted" => $result->criteria_attempted, "criteria_achieved" => $result->criteria_achieved ); } //si este estudiante está pareado a este dominio, significa que ahora estoy en los //deprecated outcomes. else { $the_processed_table[$student_id][$outcome_id]['criteria_attempted'] += $result->criteria_attempted; $the_processed_table[$student_id][$outcome_id]['criteria_achieved'] += $result->criteria_achieved; } } foreach ($the_processed_table as $student_id => $outcome_ids) { foreach ($outcome_ids as $outcome_id => $crit_information) { $crit_att = $crit_information['criteria_attempted']; $crit_ach = $crit_information['criteria_achieved']; $under_out_att[$outcome_id] += 1; if ($crit_att != 0 && ($crit_ach / $crit_att) * 100 >= 66.67) { $under_out_ach[$outcome_id] += 1; } } } $array_to_send['undergraduate_info']['outcomes_attempted_combined'] = $under_out_att; $array_to_send['undergraduate_info']['outcomes_achieved_combined'] = $under_out_ach; $grad_out_att = []; $grad_out_ach = []; foreach ($outcomes as $outcome) { $grad_out_att[$outcome->id] = 0; $grad_out_ach[$outcome->id] = 0; } //preprocess para combined_students $the_processed_table = []; foreach ($graduate_students as $result) { $student_id = $result->student_id; $outcome_id = $result->outcome_id; if (isset($combined_outcomes[$outcome_id])) $outcome_id = $combined_outcomes[$outcome_id]; if (!isset($the_processed_table[$student_id])) { $the_processed_table[$student_id] = []; } //si en esta tabla, el estudiante no está pareado con este dominio, entonces registra // los criterios, achieved y attempted if (!isset($the_processed_table[$student_id][$outcome_id])) { $the_processed_table[$student_id][$outcome_id] = array( "criteria_attempted" => $result->criteria_attempted, "criteria_achieved" => $result->criteria_achieved ); } //si este estudiante está pareado a este dominio, significa que ahora estoy en los //deprecated outcomes. else { $the_processed_table[$student_id][$outcome_id]['criteria_attempted'] += $result->criteria_attempted; $the_processed_table[$student_id][$outcome_id]['criteria_achieved'] += $result->criteria_achieved; } } foreach ($the_processed_table as $student_id => $outcome_ids) { foreach ($outcome_ids as $out_id => $crit_information) { $crit_att = $crit_information['criteria_attempted']; $crit_ach = $crit_information['criteria_achieved']; $grad_out_att[$out_id] += 1; if ($crit_att != 0 && ($crit_ach / $crit_att) * 100 >= 66.67) { $grad_out_ach[$out_id] += 1; } } } $array_to_send['graduate_info']['outcomes_attempted_combined'] = $grad_out_att; $array_to_send['graduate_info']['outcomes_achieved_combined'] = $grad_out_ach; Log::info($array_to_send); return $array_to_send; } }