123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388 |
- <?php
-
- use Illuminate\Database\Eloquent\SoftDeletingTrait;
-
- class Outcome extends Eloquent
- {
- use SoftDeletingTrait;
- protected $dates = ['deleted_at'];
-
- protected $fillable = array('name', 'definition');
-
- public function criteria()
- {
- return $this->hasManyThrough('Criterion', 'Objective')->orderBy('name');
- }
-
- /**
- * Return the objectives that the outcome belongs to
- *
- * @return Illuminate\Database\Eloquent\Model
- */
- public function objectives()
- {
- return $this->hasMany('Objective');
- // return $this->belongsToMany('Objective', 'objective_outcome');
- }
- // public function attempted($semester, $is_grad)
- // {
- // return DB::table('new_criteria')
- // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
- // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
- // ->join('courses', 'activities.course_id', '=', 'courses.id')
- // ->join('programs', 'programs.id', '=', 'courses.program_id')
- // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
- // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
- // ->where('programs.is_graduate','=',$is_grad)
- // ->where('courses.semester_id','=',$semester)
- // ->count(DB::raw('DISTINCT new_criteria.id,activity_criterion.activity_id'))
- // ;
- //
- // }
- // public function attempted($semester, $is_grad)
- // {
- // $criteria=DB::table('new_criteria')
- // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
- // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
- // ->join('courses', 'activities.course_id', '=', 'courses.id')
- // ->join('programs', 'programs.id', '=', 'courses.program_id')
- // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
- // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
- // ->where('programs.is_graduate','=',$is_grad)
- // ->where('courses.semester_id','=',$semester)
- // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
- // ->distinct()
- // ->get()
- // ;
- // $conteo=0;
- // foreach($criteria as $criterion)
- // {
- // $students_attempted=Criterion::students_attempted($criterion->id, $criterion->activity_id);
- // if($students_attempted)
- // {
- // $conteo++;
- // }
- // }
- // return $conteo;
- // }
- public static function active_by_semesters($selected_semesters, $level)
- {
- $min_start = "9000-01-01 00:00:00";
- $max_end = "1000-01-01 00:00:00";
- foreach ($selected_semesters as $semester) {
- if ($min_start > $semester->start) {
- $min_start = $semester->start;
- }
- if ($max_end < $semester->end) {
- $max_end = $semester->end;
- }
- }
- $outcomes = Outcome::where(function ($query) use ($min_start) {
- $query->where('deactivation_date', '>=', $min_start)
- ->orWhere('deactivation_date', null);
- })
- ->where('activation_date', '<=', $max_end)
- ->where(function ($query2) use ($level) {
- $query2->where("level", $level + 1)
- ->orWhere("level", 3);
- })
- ->orderBy('name', 'ASC')
- ->get();
-
- // return array('outcomes'=>$outcomes,'outcomes_attempted'=>$outcomes_attempted, 'outcomes_achieved'=>$outcomes_achieved, 'attemptedProgramsPerOutcome'=>$attemptedProgramsPerOutcome, 'achievedProgramsPerOutcome'=>$achievedProgramsPerOutcome,'participating_programs'=>$participating_programs);
- return $outcomes;
- }
-
- public function programs_attempted($semesters)
- {
- $semesters_array = [];
- foreach ($semesters as $semester) {
- $semesters_array[] = $semester->id;
- }
- // $programs=DB::table('programs')
- // ->join('courses', 'programs.id', '=', 'courses.program_id')
- // ->join('activities', 'activities.course_id', '=', 'courses.id')
- // ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
- // ->join('new_criteria', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
- // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
- // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
- // ->whereIn('courses.semester_id',$semesters_array)
- // ->distinct()
- // ->select('programs.id')
- // ->get()
- // ;
- $programs = DB::table('programs')
- ->join('courses', 'programs.id', '=', 'courses.program_id')
- ->join('activities', 'activities.course_id', '=', 'courses.id')
- ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
- ->join('criteria', 'activity_criterion.criterion_id', '=', 'criteria.id')
- ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
- ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
- ->whereIn('courses.semester_id', $semesters_array)
- ->distinct()
- ->select('programs.id')
- ->get();
-
- return $programs;
- }
-
- public function attempted($semesters, $is_grad)
- {
- $semesters_array = [];
- foreach ($semesters as $semester) {
- $semesters_array[] = $semester->id;
- }
- // $criteria=DB::table('new_criteria')
- // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
- // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
- // ->join('courses', 'activities.course_id', '=', 'courses.id')
- // ->join('programs', 'programs.id', '=', 'courses.program_id')
- // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
- // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
- // ->where('programs.is_graduate','=',$is_grad)
- // ->whereIn('courses.semester_id',$semesters_array)
- // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
- // ->distinct()
- // ->get()
- // ;
- $criteria = DB::table('criteria')
- ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
- ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
- ->join('courses', 'activities.course_id', '=', 'courses.id')
- ->join('programs', 'programs.id', '=', 'courses.program_id')
- ->join('rubric_activity', 'activities.id', '=', 'rubric_activity.activity_id')
- ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
- ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
- ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
- ->where('programs.is_graduate', '=', $is_grad)
- ->whereIn('courses.semester_id', $semesters_array)
- ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
- ->distinct()
- ->get();
- $conteo = 0;
- foreach ($criteria as $criterion) {
- $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
- if ($students_attempted) {
- $conteo++;
- }
- }
- // var_dump($conteo);
- // exit();
- return $conteo;
- }
-
- public function courses_attempted($courses)
- {
- $courses_array = [];
- foreach ($courses as $course) {
- // var_dump($course);
- // exit();
- $courses_array[] = $course->id;
- }
- // $criteria=DB::table('new_criteria')
- // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
- // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
- // ->join('courses', 'activities.course_id', '=', 'courses.id')
- // ->join('programs', 'programs.id', '=', 'courses.program_id')
- // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
- // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
- // ->whereIn('courses.id',$courses_array)
- // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
- // ->distinct()
- // ->get()
- // ;
- $criteria = DB::table('criteria')
- ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
- ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
- ->join('courses', 'activities.course_id', '=', 'courses.id')
- ->join('programs', 'programs.id', '=', 'courses.program_id')
- ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
- ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
- ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
- ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
- ->whereIn('courses.id', $courses_array)
- ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
- ->distinct()
- ->get();
- $conteo = 0;
- foreach ($criteria as $criterion) {
- $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
- if ($students_attempted) {
- $conteo++;
- }
- }
- // var_dump($conteo);
- // exit();
- return $conteo;
- }
-
- public function courses_achieved($courses)
- {
- $courses_array = [];
- foreach ($courses as $course) {
- $courses_array[] = $course->id;
- }
-
- // $criteria=DB::table('new_criteria')
- // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
- // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
- // ->join('courses', 'activities.course_id', '=', 'courses.id')
- // ->join('programs', 'programs.id', '=', 'courses.program_id')
- // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
- // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
- // ->whereIn('courses.id',$courses_array)
- // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
- // ->distinct()
- // ->get()
- // ;
- $criteria = DB::table('criteria')
- ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
- ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
- ->join('courses', 'activities.course_id', '=', 'courses.id')
- ->join('programs', 'programs.id', '=', 'courses.program_id')
- ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
- ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
- ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
- ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
- ->whereIn('courses.id', $courses_array)
- ->select('criteria.id', 'expected_percentage as expected_percentage_students_achieving', 'activity_criterion.activity_id')
- ->distinct()
- ->get();
-
- $conteo = 0;
- foreach ($criteria as $criterion) {
- $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
- $students_achieved = Criterion::students_achieved($criterion->id, $criterion->activity_id);
-
- if ($students_attempted) {
- $percentage_students_who_achieved = 100.0 * $students_achieved / $students_attempted;
- } else {
- $percentage_students_who_achieved = 0;
- }
- if ($percentage_students_who_achieved >= $criterion->expected_percentage_students_achieving) {
- $conteo++;
- }
- }
- return $conteo;
- }
-
- public function achieved($semesters, $is_grad)
- {
- $semesters_array = [];
- foreach ($semesters as $semester) {
- $semesters_array[] = $semester->id;
- }
-
- // DB::enableQueryLog();
- // $criteria=DB::table('new_criteria')
- // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
- // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
- // ->join('courses', 'activities.course_id', '=', 'courses.id')
- // ->join('programs', 'programs.id', '=', 'courses.program_id')
- // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
- // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
- // ->where('programs.is_graduate','=',$is_grad)
- // ->whereIn('courses.semester_id',$semesters_array)
- // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
- // ->distinct()
- // ->get()
- // ;
- $criteria = DB::table('criteria')
- ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
- ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
- ->join('courses', 'activities.course_id', '=', 'courses.id')
- ->join('programs', 'programs.id', '=', 'courses.program_id')
- ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
- ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
- ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
- ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
- ->where('programs.is_graduate', '=', $is_grad)
- ->whereIn('courses.semester_id', $semesters_array)
- ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
- ->distinct()
- ->get();
- // dd(DB::getQueryLog());
-
- $conteo = 0;
- foreach ($criteria as $criterion) {
- $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
- $students_achieved = Criterion::students_achieved($criterion->id, $criterion->activity_id);
-
- if ($students_attempted) {
- $percentage_students_who_achieved = 100.0 * $students_achieved / $students_attempted;
- } else {
- $percentage_students_who_achieved = 0;
- }
- if ($percentage_students_who_achieved >= $criterion->expected_percentage) {
- $conteo++;
- }
- }
- return $conteo;
- }
-
-
- // public function achieved($semester, $is_grad)
- // {
- //
- // // DB::enableQueryLog();
- // $criteria=DB::table('criteria')
- // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
- // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
- // ->join('courses', 'activities.course_id', '=', 'courses.id')
- // ->join('programs', 'programs.id', '=', 'courses.program_id')
- // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
- // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
- // ->where('programs.is_graduate','=',$is_grad)
- // ->where('courses.semester_id','=',$semester)
- // ->select('criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
- // ->distinct()
- // ->get()
- // ;
- // // dd(DB::getQueryLog());
- //
- // $conteo=0;
- // foreach($criteria as $criterion)
- // {
- // $outcome_performance=DB::table('outcome_performance')
- // ->where('outcome_performance.outcome_id','=',$this->id)
- // ->where('outcome_performance.criterion_id','=',$criterion->id)
- // ->where('outcome_performance.semester_id','=',$semester)
- // ->where('outcome_performance.level','=',$is_grad)
- // ->select('students_attempted','students_achieved')
- // ->first();
- // if(!empty($outcome_performance) and $outcome_performance->students_attempted)
- // {
- // $percentage_students_who_achieved=100.0*$outcome_performance->students_achieved/$outcome_performance->students_attempted;
- // }
- // else
- // {
- // $students_attempted=Criterion::students_attempted($criterion->id, $criterion->activity_id);
- // $students_achieved=Criterion::students_achieved($criterion->id, $criterion->activity_id);
- //
- // if($students_attempted)
- // {
- // $percentage_students_who_achieved=100.0*$students_achieved/$students_attempted;
- // DB::table('outcome_performance')->insert(array('criterion_id'=>$criterion->id,'outcome_id'=>$this->id,'semester_id'=>$semester,
- // 'students_attempted' => $students_attempted,'students_achieved' => $students_achieved,'level'=>$is_grad));
- // }
- // else
- // {
- // $percentage_students_who_achieved=0;
- // }
- // }
- // if($percentage_students_who_achieved>=$criterion->expected_percentage_students_achieving)
- // {
- // $conteo++;
- // }
- // }
- // return $conteo;
- // }
- //
-
- public static function active()
- {
- //TODO: Check when semester doesnt exist or session is empty
- $selected_semester = Semester::find(Session::get('semesters_ids')[0]);
- return Outcome::withTrashed()->where('deactivation_date', '>=', $selected_semester->start)->orWhere('deactivation_date', null)->orderBy('name', 'ASC')->get();
- }
- }
|