123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <?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)->whereIn('semester_id', Session::get('semesters_ids'));
- }
-
- public function assessesOutcome($outcome_id)
- {
-
- foreach ($this->publishedActivities as $activity)
- {
- $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 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;
- }
-
- }
|