123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444 |
- <?php
-
- class Course extends Eloquent
- {
-
- protected $fillable = array('name', 'code', 'number', 'section', 'program_id', 'user_id', 'semester_id');
-
- public function program()
- {
- return $this->belongsTo('Program');
- }
-
- public function students()
- {
- return $this->belongsToMany('Student')->orderBy('name', 'asc')->withTimestamps();
- }
-
- public function user()
- {
- return $this->belongsTo('User')->orderBy('surnames', 'asc')->orderBy('first_name', 'asc');
- }
-
-
-
- // TODO: Remove
- public function activities()
- {
- return $this->hasMany('Activity')->orderBy('date', 'asc');
- }
-
- public function activity()
- {
- return $this->belongsTo('Activity');
- }
-
- public function assessedActivities()
- {
- // return $this->hasMany('Activity')->whereNotNull('activities.outcomes_attempted')->orderBy('date', 'asc');
- $activitiesAssessed = DB::table('activities')
- ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
- ->join('assessments', 'assessments.activity_criterion_id', '=', 'ac.id')
- ->where('activities.course_id', $this->id)
- ->select('activities.id')
- ->distinct()
- ->lists('activities.id');
- Log::info($activitiesAssessed);
-
- return $this->hasMany('Activity')->whereIn('activities.id', $activitiesAssessed)->orderBy('date', 'asc');
-
- // return $this->hasMany('Activity')->where('activities.draft', 0)->orderBy('date', 'asc');
- }
-
- public function publishedActivities()
- {
- $activitiesAssessed = DB::table('activities')
- ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
- ->join('assessments', 'assessments.activity_criterion_id', '=', 'ac.id')
- ->where('activities.course_id', $this->id)
- ->where('activities.draft', 0)
- ->where('activities.diagnostic', 0)
- ->select('activities.id')
- ->distinct()
- ->lists('activities.id');
- //$this->hasMany('Activity')->whereNotNull('activities.outcomes_attempted')->where('activities.draft', 0)->orderBy('date', 'asc');
- return $this->hasMany('Activity')->whereIn('activities.id', $activitiesAssessed)->orderBy('date', 'asc');
- }
- public function diagnosticActivities()
- {
- $activitiesAssessed = DB::table('activities')
- ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
- ->join('assessments', 'assessments.activity_criterion_id', '=', 'ac.id')
- ->where('activities.course_id', $this->id)
- ->where('activities.draft', 0)
- ->where('activities.diagnostic', 1)
- ->select('activities.id')
- ->distinct()
- ->lists('activities.id');
- //$this->hasMany('Activity')
- return $this->hasMany('Activity')->whereIn('activities.id', $activitiesAssessed)->orderBy('date', 'asc');
- }
-
- public function outcomes_attempted()
- {
- return DB::table('courses')
- ->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('courses.id', '=', $this->id)
- ->select('criterion_objective_outcome.outcome_id')
- ->distinct()
- ->orderBy('criterion_objective_outcome.outcome_id')
- ->get();
-
- // SELECT distinct cr.outcome_id FROM courses c, activities a, activity_criterion ac, criteria cr WHERE c.id=a.course_id and a.id=ac.activity_id and ac.criterion_id=cr.id and c.id=1
- // return $this->id;
- }
-
-
- public function outcomes_att()
- {
- $criteria_attempted = DB::table('courses')
- ->join('activities', 'activities.course_id', '=', 'courses.id')
- ->join('activity_criterion', 'activities.id', '=', 'activity_criterion.activity_id')
- ->select('criterion_id', 'activity_criterion.id as activity_criterion_id')
- ->where('courses.id', $this->id)
- ->where('draft', 0)
- ->where('activities.diagnostic', 0)
- ->get();
-
- // Old data was formed like { "outcome1": cuantity_of_criteria_associated, "outcome2":cuantity_of_criteria}
- $outcomes_attempted = [];
-
-
-
- foreach ($criteria_attempted as $criterion) {
- $outcomes = DB::table('criterion_objective_outcome')
- ->where('criterion_id', $criterion->criterion_id)
- ->select('outcome_id')
- ->distinct()
- ->lists('outcome_id');
-
- foreach ($outcomes as $outcome_id) {
- if (array_key_exists($outcome_id, $outcomes_attempted)) $outcomes_attempted[$outcome_id] += 1;
- else $outcomes_attempted[$outcome_id] = 1;
- }
- }
- Log::info("outcomes_attempted");
- Log::info($outcomes_attempted);
-
- return $outcomes_attempted;
- }
- public static function getCriteriaPlanReport($course_code = null)
- {
- if ($course_code) {
- $criteria_id = DB::table('annual_plan_objective')
- ->where('typ_semester_course_id', $course_code->typ_semester_course_id)
- ->lists('criteria_id');
- Log::info($course_code->typ_semester_course_id);
- Log::info("dame ese id");
- $program = Program::where('id', $course_code->program_id)->first();
- // Log::info($program->code);
- if ($program->code == "") {
- $program_ids = DB::table('programs')
- ->where('school_id', $program->school->id)
- ->lists('programs.id');
- //Log::info("estamos");
- } else $program_ids = array($program->id);
-
- /*tabla es asi por curso codigo
- *
- *criterioDelPlan EstudiantesDelProgramaQuePasaron EstudiantesqueIntentaron
- *
- * criterio1 3 5
- * criterio2 2 2
- *
- *
- */
- $table_per_criterion = DB::table('program_student_semester')
- ->join('course_student', 'program_student_semester.student_id', '=', 'course_student.student_id')
- ->join('courses', 'courses.id', '=', 'course_student.course_id')
- ->join('activities', 'activities.course_id', '=', 'courses.id')
- ->join('activity_criterion', 'activities.id', '=', 'activity_criterion.activity_id')
- ->join('criteria', 'criteria.id', '=', 'activity_criterion.criterion_id')
- ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
- ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
-
- ->join('assessments', function ($join) {
- $join->on("assessments.student_id", '=', 'program_student_semester.student_id')
- ->on('assessments.activity_criterion_id', '=', 'activity_criterion.id');
- })
- ->where('courses.semester_id', $course_code->semester_id)
- ->whereIn('courses.program_id', $program_ids)
- ->where('courses.code', $course_code->code)
- ->where('courses.number', $course_code->number)
- ->whereIn('program_student_semester.program_id', $program_ids)
- ->whereIn('activity_criterion.criterion_id', $criteria_id)
- ->whereIn('criteria.id', $criteria_id)
- ->where('program_student_semester.semester_id', $course_code->semester_id)
- ->select('criteria.*')
- ->addSelect(DB::raw('count(case when assessments.score>= rubrics.expected_points then 1 else null end) as criteria_achieved'))
- ->addSelect(DB::raw('count(assessments.activity_criterion_id) as criteria_attempted'))
- ->groupBy('criteria.id');
-
- /* Log::info($table_per_criterion->toSql());
- Log::info(array($course_code));
- Log::info($program_ids);
- Log::info($criteria_id);*/
- Log::info('mera 1');
- Log::info(array($course_code));
- Log::info($table_per_criterion->get());
- return $table_per_criterion->get();
- }
- }
- public static function getStudentReportForOutcome($course_code = null)
- {
- if ($course_code) {
- //Log::info('entré');
- $criteria_id = DB::table('annual_plan_objective')
- ->where('typ_semester_course_id', $course_code->typ_semester_course_id)
- ->lists('criteria_id');
- Log::info($criteria_id);
- $program = Program::where('id', $course_code->program_id)->first();
- // // Log::info($program->code);
- if ($program->code == "") {
- $program_ids = DB::table('programs')
- ->where('school_id', $program->school->id)
- ->lists('programs.id');
- // Log::info("estamos");
- } else $program_ids = array($program->id);
-
- // Log::info(array($course_code));
-
- //Table
- /* Student criterion_attempted criterion passed
- * 1 2 1
- * 2 7 4
- *
- *
- */
- $table_per_student = DB::table('program_student_semester')
- ->join('course_student', 'program_student_semester.student_id', '=', 'course_student.student_id')
- ->join('courses', 'courses.id', '=', 'course_student.course_id')
- ->join('activities', 'activities.course_id', '=', 'courses.id')
- ->join('activity_criterion', 'activities.id', '=', 'activity_criterion.activity_id')
- ->join('criteria', 'criteria.id', '=', 'activity_criterion.criterion_id')
- ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
- ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
-
- ->join('assessments', function ($join) {
- $join->on("assessments.student_id", '=', 'program_student_semester.student_id')
- ->on('assessments.activity_criterion_id', '=', 'activity_criterion.id');
- })
- ->where('courses.semester_id', $course_code->semester_id)
- ->whereIn('courses.program_id', $program_ids)
- ->where('courses.code', $course_code->code)
- ->where('courses.number', $course_code->number)
- ->whereIn('program_student_semester.program_id', $program_ids)
- ->whereIn('activity_criterion.criterion_id', $criteria_id)
- ->where('program_student_semester.semester_id', $course_code->semester_id)
- ->select('course_student.student_id')
- ->addSelect(DB::raw('count(assessments.activity_criterion_id) as criteria_attempted'))
- ->addSelect(DB::raw('count(case when assessments.score>=rubrics.expected_points then 1 else NULL end) as criteria_achieved'))
- ->groupBy('course_student.student_id');
-
-
-
-
-
- //Log::info($criteria_id);
- Log::info('los courseCode');
- Log::info(array($course_code));
- Log::info('los programas');
- Log::info($program_ids);
-
- Log::info($table_per_student->toSql());
- $students = $table_per_student->get();
-
-
- return $students;
- }
- }
- public function getReportObject()
- {
- $reportObject = new stdClass();
-
- $reportObject->criteriaReport = DB::table('courses')
- ->join('activities', 'activities.course_id', '=', 'courses.id')
- ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
- ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
- ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
- ->join('criteria', 'criteria.id', '=', 'activity_criterion.criterion_id')
- ->join('assessments', 'activity_criterion.id', '=', 'assessments.activity_criterion_id')
- ->select(DB::raw(
- "count(assessments.score) as assessed,
- count(case when assessments.score >= rubrics.expected_points then 1 else NULL end) as achieved,
- criteria.*"
- ))
- ->where('courses.id', $this->id)
- ->groupBy('criteria.id')
- ->get();
- //Log::info($this->id);
- $reportObject->outcomesReport = DB::table('courses')
- ->join('activities', 'activities.course_id', '=', 'courses.id')
- ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
- ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
- ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
- ->join('assessments', 'activity_criterion.id', '=', 'assessments.activity_criterion_id')
- ->join('criterion_objective_outcome', 'activity_criterion.criterion_id', '=', 'criterion_objective_outcome.criterion_id')
- ->join('outcomes', 'criterion_objective_outcome.outcome_id', '=', 'outcomes.id')
- ->select(
- DB::raw(
- "student_id, outcomes.name, outcomes.id,
- count(activity_criterion.criterion_id) as attempted,
- count(case when assessments.score >= rubrics.expected_points then 1 else null end) as achieved"
- )
- )
- ->where('courses.id', $this->id)
- ->groupBy(array('outcome_id', 'student_id'))
- ->get();
-
- return $reportObject;
- }
-
- public function outcomes_ach()
- {
- $criteria = DB::table('criteria')
- ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
- ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
- ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
- ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
- ->join('courses', 'activities.course_id', '=', 'courses.id')
- ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
- ->where('courses.id', '=', $this->id)
- ->where('activities.draft', 0)
- ->where('activities.diagnostic', 0)
- ->select(
- 'criteria.id',
- 'rubrics.expected_percentage as expected_percentage_students_achieving'/*'expected_percentage_students_achieving',*/,
- 'activity_criterion.activity_id'
- )
- ->distinct()
- ->get();
- // Old data was formed like { "outcome1": cuantity_of_criteria_associated_passed, "outcome2":cuantity_of_criteria}
-
- $outcomes_achieved = [];
-
- foreach ($criteria as $criterion) {
- $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
- $students_achieved = Criterion::students_achieved($criterion->id, $criterion->activity_id);
-
- Log::info('estamos aqui');
- Log::info($students_attempted);
-
- 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) {
- $outcomes = DB::table('criterion_objective_outcome')
- ->where('criterion_id', $criterion->id)
- ->select('outcome_id')
- ->distinct()
- ->lists('outcome_id');
-
- foreach ($outcomes as $outcome_id) {
- if (array_key_exists($outcome_id, $outcomes_achieved)) $outcomes_achieved[$outcome_id] += 1;
- else $outcomes_achieved[$outcome_id] = 1;
- }
- }
- }
- Log::info(
- "OUTCOMES_ACHIEVED: "
- );
- Log::info(
- $outcomes_achieved
- );
- return $outcomes_achieved;
- }
-
- public function someSectionAssessed()
- {
- $all_sections = DB::table('courses')
- ->join('activities', 'activities.course_id', '=', 'courses.id')
- ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
- ->join('assessments', 'assessments.activity_criterion_id', '=', 'ac.id')
- ->where('courses.name', $this->name)
- ->where('code', $this->code)
- ->where('number', $this->number)
- ->where('semester_id', $this->semester_id)
- ->where(
- 'program_id',
- $this->program_id
- )
- ->where('activities.draft', 0)
- ->where('activities.diagnostic', 0)
- ->groupBy('courses.id')
- ->count();
-
- return $all_sections;
- }
-
- public function isAssessed()
- {
- $assessed = DB::table('assessments')
- ->join('activity_criterion', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
- ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
- ->where('activities.course_id', $this->id)
- ->count();
- // Log::info("aqui".$assessed);
-
- if ($assessed) return true;
- else return false;
- }
-
-
- public function outcomes_achieved()
- {
- $criteria = DB::table('criteria')
- ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
- ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
- ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
- ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
- ->join('courses', 'activities.course_id', '=', 'courses.id')
- ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
- ->where('courses.id', '=', $this->id)
- ->select(
- 'criteria.id',
- 'rubrics.expected_percentage as expected_percentage_students_achieving'/*'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 semester()
- {
- return $this->belongsTo('Semester');
- }
-
- public function sectionsWithOutcome($outcome_id)
- {
- return Course::has('activities')->with(array('activities' => function ($query) use (&$outcome_id) {
- $query->where('outcomes_attempted', 'not like', '\'%"' . $outcome_id . '":0%\'');
- }))->where('code', $this->code)->where('number', $this->number)->get();
- }
- }
|