123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402 |
- <?php
-
- class Program extends Eloquent
- {
- public function school()
- {
- return $this->belongsTo('School');
- }
-
- public function courses()
- {
- return $this->hasMany('Course')->with('semester')->whereIn('semester_id', Session::get('semesters_ids'))->orderBy('code')->orderBy('number')->orderBy('section');
- }
-
- public function coordinators()
- {
- return $this->hasMany('User');
- }
-
- public function professors()
- {
- return $this->hasMany('Professor');
- }
-
- public function students()
- {
- return $this->hasMany('Student');
- }
-
- public function templates()
- {
- return $this->hasMany('Template');
- }
-
- public function activities()
- {
- return $this->hasManyThrough('Activity', 'Course')->whereNotNull('activities.outcomes_attempted')->whereIn('semester_id', Session::get('semesters_ids'));
- }
-
- public function publishedActivities()
- {
-
- return $this->hasManyThrough('Activity', 'Course')
- //->whereNotNull('activities.outcomes_attempted')
- ->where('activities.draft', 0)
- ->where('activities.diagnostic', 0)->whereIn('semester_id', Session::get('semesters_ids'));
- }
-
- public function assessesOutcome($outcome_id)
- {
-
- foreach ($this->publishedActivities as $activity) {
- $assessed = DB::table('activity_criterion')
- ->join('assessments', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
- ->where('activity_id', $activity->id)
- ->first();
- if (!$assessed) continue;
- $outcomes_attempted = (array)$activity->o_att_array;
- if (array_key_exists($outcome_id, $outcomes_attempted) && $outcomes_attempted[$outcome_id] != 0) {
- return true;
- }
- }
- return false;
- }
-
- // return the users that are pcoords for a program
- public function users()
- {
- return $this->belongsToMany('User');
- }
-
- public function objectives()
- {
-
- return $this->hasMany('Objective');
- }
-
- // Return learning objectives ordered by outcome
- public function objectivesByOutcome()
- {
- // Objective::
- $objectives = DB::table('outcomes')
- ->select('outcomes.id as outcome_id', 'outcomes.name as outcome_name', 'objectives.id as objective_id', 'objectives.text', 'objectives.active')
- ->leftJoin('objectives', function ($join) {
- $join
- ->on('outcomes.id', '=', 'objectives.outcome_id')
- ->where('objectives.program_id', '=', $this->id);
- })
- ->orderBy('outcome_name', 'ASC')
- ->orderBy('objectives.text', 'ASC')
- ->get();
-
- return $objectives;
- }
-
- public function hasObjectivesInOutcome($outcome_id)
- {
- return Objective::where('program_id', $this->id)
- ->where('outcome_id', $outcome_id)->count();
- }
-
- /**
- * Return all the criteria in/for the program, if any
- *
- * @return Illuminate\Database\Eloquent\Collection
- */
- public function criteria()
- {
- return $this->hasMany('Criterion');
- }
-
- // public function attempted_outcome($outcome_id, $semester)
- // {
- // $conteo= DB::table('activity_criterion')
- // ->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', '=', 'activity_criterion.criterion_id')
- // ->where('criterion_objective_outcome.outcome_id','=',$outcome_id)
- // ->where('programs.id','=',$this->id)
- // ->where('courses.semester_id','=',$semester)
- // ->count(DB::raw('DISTINCT criterion_objective_outcome.outcome_id'))
- // ;
- // return $conteo;
- // }
-
- public function attempted_criteria_by_outcome($outcome_id, $semesters)
- {
- $semesters_array = [];
- foreach ($semesters as $semester) {
- $semesters_array[] = $semester->id;
- }
-
- $conteo = DB::table('activity_criterion')
- ->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', '=', 'activity_criterion.criterion_id')
- ->where('criterion_objective_outcome.outcome_id', '=', $outcome_id)
- ->where('programs.id', '=', $this->id)
- ->whereIn('courses.semester_id', $semesters_array)
- ->count(DB::raw('DISTINCT criterion_objective_outcome.criterion_id'));
- return $conteo;
- }
-
- public function attempted_outcome($outcome_id, $semesters)
- {
- $semesters_array = [];
- foreach ($semesters as $semester) {
- $semesters_array[] = $semester->id;
- }
-
- $conteo = DB::table('activity_criterion')
- ->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', '=', 'activity_criterion.criterion_id')
- ->where('criterion_objective_outcome.outcome_id', '=', $outcome_id)
- ->where('programs.id', '=', $this->id)
- ->whereIn('courses.semester_id', $semesters_array)
- ->count(DB::raw('DISTINCT criterion_objective_outcome.outcome_id'));
-
-
- Log::info(DB::table('activity_criterion')
- ->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', '=', 'activity_criterion.criterion_id')
- ->where('criterion_objective_outcome.outcome_id', '=', $outcome_id)
- ->where('programs.id', '=', $this->id)
- ->whereIn('courses.semester_id', $semesters_array)
- ->toSql());
- return $conteo;
- }
-
- public function achieved_criteria_by_outcome($outcome_id, $semesters)
- {
- $semesters_array = [];
- foreach ($semesters as $semester) {
- $semesters_array[] = $semester->id;
- }
-
- // DB::enableQueryLog();
- // dd(DB::getQueryLog());
- // $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','=',$outcome_id)
- // ->where('programs.id','=',$this->id)
- // ->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', '=', $outcome_id)
- ->where('programs.id', '=', $this->id)
- ->whereIn('courses.semester_id', $semesters_array)
- ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
- ->distinct()
- ->get();
-
- // dd(DB::getQueryLog());
-
- $conteo = 0;
- $attempted_criteria_per_program_array = [];
- // $students_attempted=0;
- // $students_achieved=0;
- foreach ($criteria as $criterion) {
- if (!isset($students_attempted[$criterion->id])) $students_attempted[$criterion->id] = 0;
- if (!isset($students_achieved[$criterion->id])) $students_achieved[$criterion->id] = 0;
- $attempted_criteria_per_program_array[$criterion->id] = 1;
- $students_attempted[$criterion->id] += Criterion::students_attempted($criterion->id, $criterion->activity_id);
- $students_achieved[$criterion->id] += Criterion::students_achieved($criterion->id, $criterion->activity_id);
- }
- // var_dump($outcome_id);
- // var_dump($this->id);
- // if(isset($students_attempted))var_dump($students_attempted);
- // else{print "aqui hay algo";}
- // print "<br>";
- // if(isset($students_achieved))var_dump($students_achieved);
- // print "<br>";
- // print "<br>";
- // exit();
- if (isset($students_attempted)) {
- foreach ($students_attempted as $criteria_id => $students_attempted_n) {
- if ($students_attempted_n) {
- $percentage_students_who_achieved = 100.0 * $students_achieved[$criteria_id] / $students_attempted[$criteria_id];
- } else {
- $percentage_students_who_achieved = 0;
- }
- if ($percentage_students_who_achieved >= $criterion->expected_percentage) {
- $conteo++;
- }
- }
- }
- $attempted_criteria_per_program = count($attempted_criteria_per_program_array);
- $achievedProgramOutcome = 0;
- $outcome = Outcome::where('id', $outcome_id)->select('expected_outcome')->first();
- // var_dump($outcome->expected_outcome);
- // exit();
- if ($attempted_criteria_per_program != 0 && 100.0 * $conteo / $attempted_criteria_per_program >= $outcome->expected_outcome) {
- $achievedProgramOutcome = 1;
- // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
- }
- return $conteo;
- }
-
- public function achieved_outcome($outcome_id, $semesters)
- {
- $semesters_array = [];
- foreach ($semesters as $semester) {
- $semesters_array[] = $semester->id;
- }
-
- // DB::enableQueryLog();
- // dd(DB::getQueryLog());
- // $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','=',$outcome_id)
- // ->where('programs.id','=',$this->id)
- // ->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', '=', $outcome_id)
- ->where('programs.id', '=', $this->id)
- ->whereIn('courses.semester_id', $semesters_array)
- ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
- ->distinct()
- ->get();
-
- // dd(DB::getQueryLog());
-
- $conteo = 0;
- $attempted_criteria_per_program_array = [];
- // $students_attempted=0;
- // $students_achieved=0;
- foreach ($criteria as $criterion) {
- if (!isset($students_attempted[$criterion->id])) $students_attempted[$criterion->id] = 0;
- if (!isset($students_achieved[$criterion->id])) $students_achieved[$criterion->id] = 0;
- $attempted_criteria_per_program_array[$criterion->id] = 1;
- $students_attempted[$criterion->id] += Criterion::students_attempted($criterion->id, $criterion->activity_id);
- $students_achieved[$criterion->id] += Criterion::students_achieved($criterion->id, $criterion->activity_id);
- }
- // var_dump($this->id);
- // if(isset($students_attempted))var_dump($students_attempted);
- // else{print "aqui hay algo";}
- // print "<br>";
- // if(isset($students_achieved))var_dump($students_achieved);
- // print "<br>";
- // print "<br>";
- // exit();
- if (isset($students_attempted)) {
- foreach ($students_attempted as $criteria_id => $students_attempted_n) {
- if ($students_attempted_n) {
- $percentage_students_who_achieved = 100.0 * $students_achieved[$criteria_id] / $students_attempted[$criteria_id];
- } else {
- $percentage_students_who_achieved = 0;
- }
- if ($percentage_students_who_achieved >= $criterion->expected_percentage) {
- $conteo++;
- }
- }
- }
- $attempted_criteria_per_program = count($attempted_criteria_per_program_array);
- $achievedProgramOutcome = 0;
- $outcome = Outcome::where('id', $outcome_id)->select('expected_outcome')->first();
- // var_dump($outcome->expected_outcome);
- // exit();
- if ($attempted_criteria_per_program != 0 && 100.0 * $conteo / $attempted_criteria_per_program >= $outcome->expected_outcome) {
- $achievedProgramOutcome = 1;
- // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
- }
- return $achievedProgramOutcome;
- }
-
- public static function generalComponentPrograms()
- {
- return self::whereIn('id', array(123, 124, 125, 126, 127, 128, 129))->get();
- }
-
- public function assessmentOverview()
- {
-
- $assessment_overview = array();
-
- $assessment_overview['program_courses'] = $this->courses;
- $outcomeCount = Outcome::all()->count();
-
-
- $assessment_overview['outcomes_achieved'] = array_fill(1, $outcomeCount, 0);
- $assessment_overview['outcomes_attempted'] = array_fill(1, $outcomeCount, 0);
-
- $assessment_overview['assessed_courses_count'] = 0;
- foreach ($assessment_overview['program_courses'] as $course) {
- if ($course->outcomes_achieved != NULL) {
- $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
- $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
- for ($i = 1; $i <= count($assessment_overview['outcomes_attempted']); $i++) {
- $assessment_overview['outcomes_achieved'][$i] += $course_outcomes_achieved[$i];
- $assessment_overview['outcomes_attempted'][$i] += $course_outcomes_attempted[$i];
- }
- $assessment_overview['assessed_courses_count'] += 1;
- }
- }
-
- /**
- * List of grouped courses (grouped sections)
- */
-
- $assessment_overview['grouped_courses'] = Course::select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
- ->with('semester')
- ->with('program')
- ->where('program_id', $this->id)
- ->whereIn('semester_id', Session::get('semesters_ids'))
- ->groupBy(array('code', 'number', 'semester_id'))
- ->orderBy('code')
- ->orderBy('number')
- ->orderBy('semester_id')
- ->get();
-
- Log::info(Course::select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
- ->with('semester')
- ->with('program')
- ->where('program_id', $this->id)
- ->whereIn('semester_id', Session::get('semesters_ids'))
- ->groupBy(array('code', 'number', 'semester_id'))
- ->orderBy('code')
- ->orderBy('number')
- ->orderBy('semester_id')
- ->toSql());
-
-
- return $assessment_overview;
- }
- }
|