load(); if ($course && $course->getType() == 'course' && $course->canEdit()) { $grades_table_data = $course->getGradesTableFull(); $header = array(_('Title')); $assignments_points = array(_("Ceiling")); $assignments_type = array(_("Type")); if (sizeof($grades_table_data['assignments']) > 0) { foreach ($grades_table_data['assignments'] as $assignment) { $header []= $assignment->title; $assignments_points []= $assignment->maxpoints; $assignments_type []= $assignment->getSubtypeString(); } } $header = array_merge($header, array(_("Total points"), _("Grade"), _("Feedback"))); $assignments_points = array_merge($assignments_points, array($grades_table_data['total_max_points'], '', '')); $assignments_type = array_merge($assignments_type, array('', '', '')); $csv_gen = new CSVGenerator(); $csv_gen->addHeader($header); $csv_gen->addDataRow($assignments_points); $csv_gen->addDataRow($assignments_type); if (sizeof($grades_table_data['learners']) > 0) { foreach ($grades_table_data['learners'] as $learner) { $learner_data_row = array($learner->getFullname()); if (sizeof($grades_table_data['assignments'] > 0)) { foreach ($grades_table_data['assignments'] as $assignment) { if (isset($grades_table_data['answers'][$learner->user_id]['answers'][$assignment->id])) { $learner_data_row []= $grades_table_data['answers'][$learner->user_id]['answers'][$assignment->id]->grade; } else { $learner_data_row []= ''; } } } if (isset($grades_table_data['answers'][$learner->user_id]['answers']['total_points'])) { $learner_data_row []= $grades_table_data['answers'][$learner->user_id]['answers']['total_points']; } else { $learner_data_row []= ''; } if (isset($grades_table_data['grades'][$learner->id])) { $learner_data_row []= $grades_table_data['grades'][$learner->id]->getGrade(); $learner_data_row []= $grades_table_data['grades'][$learner->id]->getFeedback(); } else { $learner_data_row = array_merge($learner_data_row, array('', '')); } $csv_gen->addDataRow($learner_data_row); } } header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="course_' . $course->id . '_grades_' . time() . '.csv"'); echo $csv_gen->getData(); unset($csv_gen); exit; }