$this->course->offering()->gradebook()->hasEarnedBadge($this->member->get('id')); $student = $this->member; $gradePolicy = new \Components\Courses\Models\GradePolicies($this->course->offering()->section()->get('grade_policy_id'), $this->course->offering()->section()->get('id')); $details = array(); $details['quizzes_total'] = 0; $details['homeworks_total'] = 0; $details['exams_total'] = 0; $details['quizzes_taken'] = 0; $details['homeworks_submitted'] = 0; $details['exams_taken'] = 0; $details['forms'] = array(); // Get the assets $asset = new \Components\Courses\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'))); // 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); foreach ($assets as $asset) { $increment_count_taken = false; $crumb = false; $isValidForm = true; // Check for result for given student on form $crumb = $asset->url; $title = $asset->title; $url = Route::url($this->base . '&asset=' . $asset->id); $unit = isset($asset->unit_id) ? $this->course->offering()->unit($asset->unit_id) : null; if (!$crumb || strlen($crumb) != 20) { $score = isset($grades[$this->member->get('id')]['assets'][$asset->id]['score']) ? $grades[$this->member->get('id')]['assets'][$asset->id]['score'] : '--'; if (is_numeric($score)) { $increment_count_taken = true; } else {
/** * Export gradebook to csv * * @return void **/ private function exportcsv() { // Only allow for instructors if (!$this->course->offering()->section()->access('manage')) { echo json_encode(array('success' => false)); exit; } // Get all section members $members = $this->course->offering()->section()->members(array('student' => 1)); // Refresh the grades // @FIXME: This seems to cause memory problems...neeed trigger based solution, rather than one-time computation //$this->course->offering()->gradebook()->refresh(); // Get the grades $grades = $this->course->offering()->gradebook()->grades(); // Get the assets $asset = new \Components\Courses\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); usort($assets, function ($a, $b) { return strcasecmp($a->title, $b->title); }); $section = $this->course->offering()->section()->get('alias'); $filename = $this->course->get('alias') . '.' . $section . '.gradebook.csv'; // Set content type headers header("Content-type: application/csv"); header("Content-Disposition: attachment; filename={$filename}"); header("Pragma: no-cache"); header("Expires: 0"); $row = array(); $row[] = 'Student Name'; $row[] = 'Student Email'; foreach ($assets as $a) { $row[] = $a->title; } echo implode(',', $row) . "\n"; foreach ($members as $m) { $row = array(); $row[] = User::getInstance($m->get('user_id'))->get('name'); $row[] = User::getInstance($m->get('user_id'))->get('email'); foreach ($assets as $a) { $row[] = isset($grades[$m->get('id')]['assets'][$a->id]['score']) ? $grades[$m->get('id')]['assets'][$a->id]['score'] : '-'; } echo implode(',', $row) . "\n"; } // That's all exit; }