123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- <?php
-
- class Activity extends Eloquent
- {
-
- public function section()
- {
- return $this->belongsTo('Section');
- }
-
- public function rubric()
- {
- // return $this->belongsTo('Rubric');
- return $this->belongsToMany('Rubric', 'rubric_activity');
- }
-
- public function course()
- {
- return $this->belongsTo('Course');
- }
-
- public function assessed_students()
- {
- return $this->belongsToMany('Student', 'assessments')->withPivot('scores', 'percentage')->withTimestamps();
- }
- public function amount_of_assessed_students()
- {
-
- $activity_criterion = DB::table('activity_criterion')->where('activity_id', '=', $this->id)->lists('id');
- $amount_of_students = DB::table('assessments')->whereIn('activity_criterion_id', $activity_criterion)->lists('student_id');
-
- return count($amount_of_students);
- }
-
- public function criteria_achieved()
- {
-
- $activity_criterion = DB::table('activity_criterion')
- ->where('activity_id', '=', $this->id)
- ->get();
-
- $criteria_achieved = [];
- foreach ($activity_criterion as $index => $single_ac) {
-
-
- $assessments_passed = count(DB::table('assessments')
- ->where('score', '>=', $this->rubric[0]->expected_points)
- ->where('activity_criterion_id', '=', $single_ac->id)
- ->lists('student_id'));
- $assessments_attempted = count(DB::table('assessments')
- ->where('activity_criterion_id', '=', $single_ac->id)
- ->lists('student_id'));
-
- if ($assessments_attempted != 0 && (($assessments_passed / $assessments_attempted) * 100) >= $this->rubric[0]->expected_percentage) {
- $criteria_achieved[$single_ac->criterion_id] = 1;
- } else {
- $criteria_achieved[$single_ac->criterion_id] = 0;
- }
- }
- return $criteria_achieved;
- }
-
-
-
- // cap_array
- public function getCapArrayAttribute()
- {
- $criteria_achieved_percentage = [];
-
-
- $criterias = DB::table('criteria')
- ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
- ->join('assessments', 'activity_criterion.id', '=', 'assessments.activity_criterion_id')
- ->where('activity_criterion.activity_id', '=', $this->id)
- ->select(
- array(
- 'activity_criterion.id as id',
- 'activity_criterion.criterion_id as criterion_id',
- 'activity_criterion.activity_id as activity_id'
- )
- )
- ->addSelect('criteria.name', 'criteria.subcriteria')
- ->get();
-
- foreach ($criterias as $index => $single_crit) {
-
-
- $single_crit->outcome_id = json_encode(DB::table('criterion_objective_outcome')
- ->where('criterion_id', '=', $single_crit->criterion_id)
- ->lists('outcome_id'));
- $amount_of_students = count(DB::table('assessments')
- ->where("activity_criterion_id", '=', $single_crit->id)
- ->lists('student_id'));
-
-
- $student_pass = DB::table('assessments')
- ->where("activity_criterion_id", '=', $single_crit->id)
- ->where('score', '>=', $this->rubric[0]->expected_points)
- ->lists('student_id');
- $amount_of_students_passed = count(DB::table('assessments')
- ->where("activity_criterion_id", '=', $single_crit->id)
- ->where('score', '>=', $this->rubric[0]->expected_points)
- ->lists('student_id'));
-
- $single_crit->score_percentage = ($amount_of_students_passed / $amount_of_students) * 100;
- $criteria_achieved_percentage[$single_crit->criterion_id] = $single_crit;
- }
- return $criteria_achieved_percentage;
- }
-
- // o_ach_array
- public function getOAchArrayAttribute($value)
- {
- /*
- $outcomes_achieved = [];
- $all_criterion = DB::table('activity_criterion')
- ->where('activity_criterion.activity_id', '=', $this->id)
- ->get();
-
- $attempted_criteria = 0;
- $passed_criteria = 0;
-
- $all_outcomes = DB::table('outcomes')->get();
-
-
- foreach ($all_criterion as $index => $activity_crit) {
-
- $amount_of_outcomes_attempted = DB::table('criterion_objective_outcome')
- ->join('outcomes', 'outcomes.id', '=', 'criterion_objective_outcome.outcome_id')
- ->where('criterion_id', '=', $activity_crit->criterion_id)
- ->select('criterion_objective_outcome.outcome_id')
- ->distinct()
- ->orderBy('criterion_objective_outcome.outcome_id')
- ->select('outcomes.id', 'outcomes.expected_outcome')
- ->get();
- $passed_criteria = count(DB::table('assessments')
- ->where('activity_criterion_id', '=', $activity_crit->id)
- ->where('score', '>=', $this->rubric[0]->expected_points)
- ->lists('student_id'));
- $attempted_criteria = count(DB::table('assessments')
- ->where('activity_criterion_id', '=', $activity_crit->id)
- ->lists('student_id'));
- Log::info("For activity_crit " . ($activity_crit->id));
- $percent_for_criteria = ($passed_criteria / $attempted_criteria) * 100;
- Log::info('Percent calculated' . $percent_for_criteria);
-
-
- $percent_for_criteria = ($passed_criteria / $attempted_criteria) * 100;
-
- foreach ($amount_of_outcomes_attempted as $index2 => $outcome) {
-
- if ($percent_for_criteria >= $this->rubric[0]->expected_percentage) {
- if (array_key_exists($outcome->id, $outcomes_achieved)) $outcomes_achieved[$outcome->id] += 1;
- else $outcomes_achieved[$outcome->id] = 1;
- }
- }
- }
-
- return $outcomes_achieved;*/
-
- $outcomes_achieved = [];
-
- $criteria_achieved = $this->criteria_achieved();
-
-
- $all_outcomes = DB::table('outcomes')->lists('id');
-
- foreach ($all_outcomes as $outcome_id) {
- $outcomes_achieved[$outcome_id] = 0;
- }
-
- foreach ($criteria_achieved as $criterion_id => $passed) {
-
- if ($passed == 1) {
- $outcomes_related = DB::table('criterion_objective_outcome')
- ->where("criterion_id", '=', $criterion_id)
- ->select('outcome_id')
- ->distinct()
- ->lists('outcome_id');
-
- foreach ($outcomes_related as $index => $outcome_id) {
-
- $outcomes_achieved[$outcome_id] += 1;
- }
- }
- }
- return $outcomes_achieved;
- }
-
-
- public function is_assessed()
- {
- $all_criterion = DB::table('activity_criterion')
- ->where('activity_criterion.activity_id', '=', $this->id)
- ->lists('id');
-
- $assessments = DB::table('assessments')
- ->whereIn('activity_criterion_id', $all_criterion)
- ->lists('id');
-
- // return boolval(count($assessments));
- return (bool)(count($assessments));
- }
-
- public function isStudentAssessed($student_id)
- {
- return DB::table('activities')
- ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
- ->join('assessments', 'assessments.activity_criterion_id', '=', 'ac.id')
- ->where('activity_id', $this->id)
- ->where('student_id', $student_id)
- ->count();
- }
- public function transforming_actions()
- {
- $transformative_action = DB::table('activities')
- ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
- ->join('transformative_activity_criterion as tac', 'tac.activity_criterion_id', '=', 'ac.id')
- ->join('transformative_actions as ta', 'ta.id', '=', 'tac.trans_action_id')
- ->where('activities.id', $this->id)
- ->select('ta.*')
- ->first();
- if ($transformative_action)
- return $transformative_action->description;
- else return '';
- }
-
- // o_att_array
-
- public function getOAttArrayAttribute()
- {
-
-
- $outcomes_attempted = [];
-
- $all_criterion = DB::table('activity_criterion')
- ->where('activity_criterion.activity_id', '=', $this->id)
- ->lists('criterion_id');
-
- foreach ($all_criterion as $index => $criterion_id) {
-
- $amount_of_outcomes = DB::table('criterion_objective_outcome')
- ->where('criterion_id', '=', $criterion_id)
- ->select('criterion_objective_outcome.outcome_id')
- ->distinct()
- ->orderBy('criterion_objective_outcome.outcome_id')
- ->lists('outcome_id');
-
- foreach ($amount_of_outcomes as $index2 => $outcome_id) {
- if (array_key_exists($outcome_id, $outcomes_attempted)) $outcomes_attempted[$outcome_id] += 1;
- else $outcomes_attempted[$outcome_id] = 1;
- }
- }
-
- //return json_decode($this->outcomes_attempted, true);
- return $outcomes_attempted;
- }
- }
|