/** * Manage course pages * * @return void */ public function displayTask() { // Incoming $this->view->filters = array('tmpl' => Request::getState($this->_option . '.' . $this->_controller . '.tmpl', 'tmpl', ''), 'asset_scope' => Request::getState($this->_option . '.' . $this->_controller . '.scope', 'scope', 'asset_group'), 'asset_scope_id' => Request::getState($this->_option . '.' . $this->_controller . '.scope_id', 'scope_id', 0, 'int'), 'course_id' => Request::getState($this->_option . '.' . $this->_controller . '.course_id', 'course_id', 0, 'int'), 'limit' => Request::getState($this->_option . '.' . $this->_controller . '.limit', 'limit', Config::get('list_limit'), 'int'), 'start' => Request::getState($this->_option . '.' . $this->_controller . '.limitstart', 'limitstart', 0, 'int')); $tbl = new Tables\Asset($this->database); $rows = $tbl->find(array('w' => $this->view->filters)); $r = array(); if ($rows) { foreach ($rows as $row) { $r[$row->id] = $row; } } $this->view->rows = $r; $assets = $tbl->find(array('w' => array('course_id' => $this->view->filters['course_id']))); $a = array(); if ($assets) { foreach ($assets as $row) { $a[$row->id] = $row; } } $this->view->assets = $a; $this->view->total = count($this->view->rows); // Set any errors foreach ($this->getErrors() as $error) { $this->view->setError($error); } // Output the HTML $this->view->display(); }
/** * Check whether or not the student is passing the course and has completed all items * * @param int $member_id * @return bool **/ public function isEligibleForRecognition($member_id = null) { static $assets = null; static $grades = null; // Get a grade policy object $gradePolicy = new GradePolicies($this->course->offering()->section()->get('grade_policy_id'), $this->course->offering()->section()->get('id')); if (!isset($assets)) { // Get the graded assets $asset = new Tables\Asset(\App::get('db')); $assets = $asset->find(array('w' => array('course_id' => $this->course->get('id'), 'section_id' => $this->course->offering()->section()->get('id'), 'offering_id' => $this->course->offering()->get('id'), 'graded' => true, 'state' => 1, 'asset_scope' => 'asset_group'), 'order_by' => 'title', 'order_dir' => 'ASC')); // Get gradebook auxiliary assets $auxiliary = $asset->findByScope('offering', $this->course->offering()->get('id'), array('asset_type' => 'gradebook', 'asset_subtype' => 'auxiliary', 'graded' => true, 'state' => 1)); $assets = array_merge($assets, $auxiliary); } // Get totals by type $totals = array('exam' => 0, 'quiz' => 0, 'homework' => 0); $counts = array(); if ($assets && count($assets) > 0) { foreach ($assets as $asset) { ++$totals[$asset->grade_weight]; } } if (!isset($grades)) { // Get count of graded items taken $filters = array('member_id' => $member_id, 'scope' => 'asset', 'graded' => true); $grades = $this->_grades($filters); } // Restructure data foreach ($grades as $g) { if (!is_null($g->score) || !is_null($g->override)) { if (isset($counts[$g->member_id][$g->grade_weight])) { ++$counts[$g->member_id][$g->grade_weight]; } else { $counts[$g->member_id][$g->grade_weight] = 1; } } } // Get weights to determine what counts toward the final grade $exam_weight = $gradePolicy->get('exam_weight'); $quiz_weight = $gradePolicy->get('quiz_weight'); $homework_weight = $gradePolicy->get('homework_weight'); $return = false; if (isset($counts)) { if (!is_null($member_id) && !is_array($member_id)) { $member_id = (array) $member_id; } else { $member_id = array(); foreach ($this->course->offering()->section()->members() as $m) { $member_id[] = $m->get('id'); } } // Loop though the users foreach ($member_id as $m) { $passing = $this->passing(true, $m); // Now make sure they've taken all required exams/quizzes/homeworks, and that they passed if (($exam_weight == 0 || $exam_weight > 0 && isset($counts[$m]['exam']) && $totals['exam'] == $counts[$m]['exam']) && ($quiz_weight == 0 || $quiz_weight > 0 && isset($counts[$m]['quiz']) && $totals['quiz'] == $counts[$m]['quiz']) && ($homework_weight == 0 || $homework_weight > 0 && isset($counts[$m]['homework']) && $totals['homework'] == $counts[$m]['homework']) && $passing[$m]) { $return[] = $m; } } } return $return; }
/** * Get a list of assets for a unit * Accepts an array of filters to apply to the list of assets * * @param array $filters Filters to apply * @return object \Components\Courses\Models\Iterator */ public function assets($filters = array()) { if (!isset($this->_assets) || !$this->_assets instanceof Iterator) { if (!isset($filters['asset_scope_id'])) { $filters['asset_scope_id'] = (int) $this->get('id'); } if (!isset($filters['asset_scope'])) { $filters['asset_scope'] = 'unit'; } if (!isset($filters['section_id'])) { $filters['section_id'] = (int) $this->get('section_id'); } $tbl = new Tables\Asset($this->_db); if ($results = $tbl->find(array('w' => $filters))) { foreach ($results as $key => $result) { $results[$key] = new Asset($result); } } else { $results = array(); } $this->_assets = new Iterator($results); } return $this->_assets; }