MDL-10490 Implemented grade letters in export. Needs testing.
This commit is contained in:
@@ -7,6 +7,12 @@ class grade_export_form extends moodleform {
|
||||
include_once($CFG->libdir.'/pear/HTML/QuickForm/advcheckbox.php');
|
||||
$mform =& $this->_form;
|
||||
$mform->addElement('header', 'general', get_string('gradeitemsinc', 'grades')); // TODO: localize
|
||||
|
||||
$mform->addElement('checkbox', 'export_letters', get_string('exportletters', 'grades'));
|
||||
$mform->setDefault('export_letters', 0);
|
||||
$mform->setHelpButton('export_letters', array(false, get_string('exportletters', 'grades'),
|
||||
false, true, false, get_string("exportlettershelp", 'grades')));
|
||||
|
||||
$id = $this->_customdata['id']; // course id
|
||||
$mform->addElement('hidden', 'id', $id);
|
||||
if ($grade_items = grade_item::fetch_all(array('courseid'=>$id))) {
|
||||
@@ -19,4 +25,4 @@ class grade_export_form extends moodleform {
|
||||
$this->add_action_buttons(false, get_string('submit'));
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
||||
+31
-9
@@ -25,6 +25,7 @@
|
||||
|
||||
require_once($CFG->dirroot.'/lib/gradelib.php');
|
||||
require_once($CFG->dirroot.'/grade/lib.php');
|
||||
|
||||
/**
|
||||
* Prints all grade items for selection
|
||||
* @input int id - course id
|
||||
@@ -62,10 +63,18 @@ class grade_export {
|
||||
|
||||
/**
|
||||
* Constructor should set up all the private variables ready to be pulled
|
||||
* @input int id - course id
|
||||
* @input string itemids - comma separated value of itemids to process for this export
|
||||
* @param int $id course id
|
||||
* @param string $itemids comma separated value of itemids to process for this export
|
||||
* @param boolean $export_letters Whether to export letter grade_items as literal letters, or as numerical values
|
||||
* @note Exporting as letters will lead to data loss if that exported set it re-imported.
|
||||
*/
|
||||
function grade_export($id, $itemids = '') {
|
||||
function grade_export($id, $itemids = '', $export_letters=false) {
|
||||
|
||||
if ($export_letters) {
|
||||
require_once($CFG->dirroot . '/grade/report/lib.php');
|
||||
$report = new grade_report();
|
||||
$letters = $report->get_grade_letters();
|
||||
}
|
||||
|
||||
$this->strgrades = get_string("grades");
|
||||
$this->strgrade = get_string("grade");
|
||||
@@ -127,14 +136,15 @@ class grade_export {
|
||||
}
|
||||
} else {
|
||||
// else we get all items for this course
|
||||
$gradeitems = grade_grade::fetch_all(array('courseid'=>$this->id));
|
||||
$gradeitems = grade_item::fetch_all(array('courseid'=>$this->id));
|
||||
}
|
||||
|
||||
if ($gradeitems) {
|
||||
foreach ($gradeitems as $gradeitem) {
|
||||
$grade_item_displaytype = $report->get_pref('gradedisplaytype', $gradeitem->id);
|
||||
|
||||
// load as an array of grade_final objects
|
||||
if ($itemgrades = $gradeitem -> get_final()) {
|
||||
if ($itemgrades = $gradeitem->get_final()) {
|
||||
|
||||
$this->columns[$gradeitem->id] = "$gradeitem->itemmodule: ".$gradeitem->get_name()." - $gradeitem->grademax";
|
||||
|
||||
@@ -149,12 +159,17 @@ class grade_export {
|
||||
if (!empty($this->students)) {
|
||||
foreach ($this->students as $student) {
|
||||
unset($studentgrade);
|
||||
// add support for comment here MDL-9634
|
||||
// TODO add support for comment here MDL-9634
|
||||
|
||||
if (!empty($itemgrades[$student->id])) {
|
||||
$studentgrade = $itemgrades[$student->id];
|
||||
}
|
||||
|
||||
// TODO Convert final grade to letter if export option is on, and grade_item is set to letter type MDL-10490
|
||||
if ($grade_item_displaytype == GRADE_REPORT_GRADE_DISPLAY_TYPE_LETTER && $export_letters) {
|
||||
$studentgrade->finalgrade = $studentgrade->get_letter($letters);
|
||||
}
|
||||
|
||||
if (!empty($studentgrade->finalgrade)) {
|
||||
$this->grades[$student->id][$gradeitem->id] = $currentstudentgrade = $studentgrade->finalgrade;
|
||||
} else {
|
||||
@@ -162,11 +177,16 @@ class grade_export {
|
||||
$this->gradeshtml[$student->id][$gradeitem->id] = "";
|
||||
}
|
||||
if (!empty($maxgrade)) {
|
||||
$this->totals[$student->id] = (float)($this->totals[$student->id]) + (float)($currentstudentgrade);
|
||||
$total = (float)($this->totals[$student->id]) + (float)($currentstudentgrade);
|
||||
} else {
|
||||
$this->totals[$student->id] = (float)($this->totals[$student->id]) + 0;
|
||||
$total = (float)($this->totals[$student->id]) + 0;
|
||||
}
|
||||
|
||||
if ($export_letters) {
|
||||
$total = grade_grade::get_letter($letters, $total, $gradeitem->grademin, $gradeitem->grademax);
|
||||
}
|
||||
$this->totals[$student->id] = $total;
|
||||
|
||||
if (!empty($comment)) {
|
||||
// load comments here
|
||||
if ($studentgrade) {
|
||||
@@ -186,12 +206,14 @@ class grade_export {
|
||||
}
|
||||
|
||||
/**
|
||||
* To be implemented by child classes
|
||||
* To be implemented by child classe
|
||||
* TODO finish PHPdocs
|
||||
*/
|
||||
function print_grades() { }
|
||||
|
||||
/**
|
||||
* Displays all the grades on screen as a feedback mechanism
|
||||
* TODO finish PHPdoc
|
||||
*/
|
||||
function display_grades($feedback=false) {
|
||||
echo '<table>';
|
||||
|
||||
@@ -58,7 +58,7 @@ if (($data = data_submitted()) && confirm_sesskey()) {
|
||||
|
||||
// print the grades on screen for feedbacks
|
||||
|
||||
$export = new grade_export($id, $data->itemids);
|
||||
$export = new grade_export($id, $data->itemids, $data->export_letters);
|
||||
$export->display_grades($feedback);
|
||||
|
||||
// this redirect should trigger a download prompt
|
||||
|
||||
@@ -57,7 +57,7 @@ if (($data = data_submitted()) && confirm_sesskey()) {
|
||||
$itemidsurl = implode(",",$data->itemids);
|
||||
}
|
||||
|
||||
$export = new grade_export($id, $data->itemids);
|
||||
$export = new grade_export($id, $data->itemids, $data->export_letters);
|
||||
$export->display_grades($feedback);
|
||||
|
||||
// this redirect should trigger a download prompt
|
||||
|
||||
@@ -58,7 +58,7 @@ if (($data = data_submitted()) && confirm_sesskey()) {
|
||||
|
||||
// print the grades on screen for feedbacks
|
||||
|
||||
$export = new grade_export($id, $data->itemids);
|
||||
$export = new grade_export($id, $data->itemids, $data->export_letters);
|
||||
$export->display_grades($feedback);
|
||||
|
||||
// this redirect should trigger a download prompt
|
||||
|
||||
@@ -58,7 +58,7 @@ if (($data = data_submitted()) && confirm_sesskey()) {
|
||||
|
||||
// print the grades on screen for feedbacks
|
||||
|
||||
$export = new grade_export($id, $data->itemids);
|
||||
$export = new grade_export($id, $data->itemids, $data->export_letters);
|
||||
$export->display_grades($feedback);
|
||||
|
||||
// this redirect should trigger a download prompt
|
||||
|
||||
@@ -30,7 +30,7 @@ function grade_import_commit($courseid, $importcode) {
|
||||
|
||||
if ($grades = get_records('grade_import_values', 'newgradeitem', $newitem->id)) {
|
||||
|
||||
// make the grardes array for update_grade
|
||||
// make the grades array for update_grade
|
||||
|
||||
// find the max instance number of 'manual' grade item
|
||||
// and increment that number by 1 by hand
|
||||
@@ -49,6 +49,8 @@ function grade_import_commit($courseid, $importcode) {
|
||||
}
|
||||
|
||||
$instances[] = $instance;
|
||||
|
||||
// TODO clean up following comment?
|
||||
// if fails, deletes all the created grade_items and grades
|
||||
|
||||
/// create a new grade item for this
|
||||
@@ -66,7 +68,7 @@ function grade_import_commit($courseid, $importcode) {
|
||||
if ($failed) {
|
||||
foreach ($instances as $instance) {
|
||||
$gradeitem = new grade_item(array('courseid'=>$courseid, 'itemtype'=>'manual', 'iteminstance'=>$instance));
|
||||
// this method does not seem to delete all the raw grades and the item itself
|
||||
// TODO this method does not seem to delete all the raw grades and the item itself
|
||||
// which I think should be deleted in this case, can I use sql directly here?
|
||||
$gradeitem->delete();
|
||||
}
|
||||
@@ -96,7 +98,7 @@ function grade_import_commit($courseid, $importcode) {
|
||||
// get all grades with this item
|
||||
if ($grades = get_records('grade_import_values', 'itemid', $itemid)) {
|
||||
|
||||
// make the grardes array for update_grade
|
||||
// make the grades array for update_grade
|
||||
foreach ($grades as $grade) {
|
||||
if (!$gradeitem->update_final_grade($grade->userid, $grade->finalgrade, NULL, NULL, $grade->feedback)) {
|
||||
$failed = 1;
|
||||
@@ -145,4 +147,4 @@ function my_file_get_contents($filename, $use_include_path = 0) {
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user