mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
regular whitespace cleanup in grade code
This commit is contained in:
parent
e1d2692a73
commit
ba74762bda
21 changed files with 297 additions and 297 deletions
|
@ -16,7 +16,7 @@ class grade_export_form extends moodleform {
|
||||||
$mform->addElement($element);
|
$mform->addElement($element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->add_action_buttons(false, get_string('submit'));
|
$this->add_action_buttons(false, get_string('submit'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
|
@ -42,7 +42,7 @@ function print_gradeitem_selections($id, $params = NULL) {
|
||||||
* Base export class
|
* Base export class
|
||||||
*/
|
*/
|
||||||
class grade_export {
|
class grade_export {
|
||||||
|
|
||||||
var $format = ''; // export format
|
var $format = ''; // export format
|
||||||
var $id; // course id
|
var $id; // course id
|
||||||
var $itemids; // comma separated grade_item ids;
|
var $itemids; // comma separated grade_item ids;
|
||||||
|
@ -51,34 +51,34 @@ class grade_export {
|
||||||
var $comments = array(); // Collect all comments for each grade
|
var $comments = array(); // Collect all comments for each grade
|
||||||
var $totals = array(); // Collect all totals in this array
|
var $totals = array(); // Collect all totals in this array
|
||||||
var $columns = array(); // Accumulate column names in this array.
|
var $columns = array(); // Accumulate column names in this array.
|
||||||
var $columnhtml = array(); // Accumulate column html in this array.
|
var $columnhtml = array(); // Accumulate column html in this array.
|
||||||
var $columnidnumbers = array(); // Collect all gradeitem id numbers
|
var $columnidnumbers = array(); // Collect all gradeitem id numbers
|
||||||
var $students = array();
|
var $students = array();
|
||||||
var $course; // course
|
var $course; // course
|
||||||
|
|
||||||
// common strings
|
// common strings
|
||||||
var $strgrades;
|
var $strgrades;
|
||||||
var $strgrade;
|
var $strgrade;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor should set up all the private variables ready to be pulled
|
* Constructor should set up all the private variables ready to be pulled
|
||||||
* @input int id - course id
|
* @input int id - course id
|
||||||
* @input string itemids - comma separated value of itemids to process for this export
|
* @input string itemids - comma separated value of itemids to process for this export
|
||||||
*/
|
*/
|
||||||
function grade_export($id, $itemids = '') {
|
function grade_export($id, $itemids = '') {
|
||||||
|
|
||||||
$this->strgrades = get_string("grades");
|
$this->strgrades = get_string("grades");
|
||||||
$this->strgrade = get_string("grade");
|
$this->strgrade = get_string("grade");
|
||||||
$this->itemids = $itemids;
|
$this->itemids = $itemids;
|
||||||
|
|
||||||
$strmax = get_string("maximumshort");
|
$strmax = get_string("maximumshort");
|
||||||
|
|
||||||
if (! $course = get_record("course", "id", $id)) {
|
if (! $course = get_record("course", "id", $id)) {
|
||||||
error("Course ID was incorrect");
|
error("Course ID was incorrect");
|
||||||
}
|
}
|
||||||
$context = get_context_instance(CONTEXT_COURSE, $id);
|
$context = get_context_instance(CONTEXT_COURSE, $id);
|
||||||
require_capability('moodle/course:viewcoursegrades', $context);
|
require_capability('moodle/course:viewcoursegrades', $context);
|
||||||
|
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
$this->course = $course;
|
$this->course = $course;
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ class grade_export {
|
||||||
|
|
||||||
/// Check to see if groups are being used in this course
|
/// Check to see if groups are being used in this course
|
||||||
if ($groupmode = groupmode($course)) { // Groups are being used
|
if ($groupmode = groupmode($course)) { // Groups are being used
|
||||||
|
|
||||||
if (isset($_GET['group'])) {
|
if (isset($_GET['group'])) {
|
||||||
$changegroup = $_GET['group']; /// 0 or higher
|
$changegroup = $_GET['group']; /// 0 or higher
|
||||||
} else {
|
} else {
|
||||||
|
@ -96,7 +96,7 @@ class grade_export {
|
||||||
}
|
}
|
||||||
|
|
||||||
$currentgroup = get_and_set_current_group($course, $groupmode, $changegroup);
|
$currentgroup = get_and_set_current_group($course, $groupmode, $changegroup);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$currentgroup = false;
|
$currentgroup = false;
|
||||||
}
|
}
|
||||||
|
@ -119,44 +119,44 @@ class grade_export {
|
||||||
// if grade_item ids are specified
|
// if grade_item ids are specified
|
||||||
if ($itemids) {
|
if ($itemids) {
|
||||||
foreach ($itemids as $iid) {
|
foreach ($itemids as $iid) {
|
||||||
|
|
||||||
if ($iid) {
|
if ($iid) {
|
||||||
$params->id = clean_param($iid, PARAM_INT);
|
$params->id = clean_param($iid, PARAM_INT);
|
||||||
$gradeitems[] = new grade_item($params);
|
$gradeitems[] = new grade_item($params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// else we get all items for this course
|
// else we get all items for this course
|
||||||
$gradeitems = grade_grades::fetch_all(array('courseid'=>$this->id));
|
$gradeitems = grade_grades::fetch_all(array('courseid'=>$this->id));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($gradeitems) {
|
if ($gradeitems) {
|
||||||
foreach ($gradeitems as $gradeitem) {
|
foreach ($gradeitems as $gradeitem) {
|
||||||
|
|
||||||
// load as an array of grade_final objects
|
// load as an array of grade_final objects
|
||||||
if ($itemgrades = $gradeitem -> get_final()) {
|
if ($itemgrades = $gradeitem -> get_final()) {
|
||||||
|
|
||||||
$this->columns[$gradeitem->id] = "$gradeitem->itemmodule: ".format_string($gradeitem->itemname,true)." - $gradeitem->grademax";
|
$this->columns[$gradeitem->id] = "$gradeitem->itemmodule: ".format_string($gradeitem->itemname,true)." - $gradeitem->grademax";
|
||||||
|
|
||||||
$this->columnidnumbers[$gradeitem->id] = $gradeitem->idnumber; // this might be needed for some export plugins
|
$this->columnidnumbers[$gradeitem->id] = $gradeitem->idnumber; // this might be needed for some export plugins
|
||||||
|
|
||||||
if (!empty($gradeitem->grademax)) {
|
if (!empty($gradeitem->grademax)) {
|
||||||
$maxgrade = "$strmax: $gradeitem->grademax";
|
$maxgrade = "$strmax: $gradeitem->grademax";
|
||||||
} else {
|
} else {
|
||||||
$maxgrade = "";
|
$maxgrade = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($this->students)) {
|
if (!empty($this->students)) {
|
||||||
foreach ($this->students as $student) {
|
foreach ($this->students as $student) {
|
||||||
unset($studentgrade);
|
unset($studentgrade);
|
||||||
// add support for comment here MDL-9634
|
// add support for comment here MDL-9634
|
||||||
|
|
||||||
if (!empty($itemgrades[$student->id])) {
|
if (!empty($itemgrades[$student->id])) {
|
||||||
$studentgrade = $itemgrades[$student->id];
|
$studentgrade = $itemgrades[$student->id];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($studentgrade->finalgrade)) {
|
if (!empty($studentgrade->finalgrade)) {
|
||||||
$this->grades[$student->id][$gradeitem->id] = $currentstudentgrade = $studentgrade->finalgrade;
|
$this->grades[$student->id][$gradeitem->id] = $currentstudentgrade = $studentgrade->finalgrade;
|
||||||
} else {
|
} else {
|
||||||
$this->grades[$student->id][$gradeitem->id] = $currentstudentgrade = "";
|
$this->grades[$student->id][$gradeitem->id] = $currentstudentgrade = "";
|
||||||
$this->gradeshtml[$student->id][$gradeitem->id] = "";
|
$this->gradeshtml[$student->id][$gradeitem->id] = "";
|
||||||
|
@ -166,8 +166,8 @@ class grade_export {
|
||||||
} else {
|
} else {
|
||||||
$this->totals[$student->id] = (float)($this->totals[$student->id]) + 0;
|
$this->totals[$student->id] = (float)($this->totals[$student->id]) + 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($comment)) {
|
if (!empty($comment)) {
|
||||||
// load comments here
|
// load comments here
|
||||||
if ($studentgrade) {
|
if ($studentgrade) {
|
||||||
$studentgrade->load_text();
|
$studentgrade->load_text();
|
||||||
|
@ -176,20 +176,20 @@ class grade_export {
|
||||||
$this->comments[$student->id][$gradeitem->id] = $comment;
|
$this->comments[$student->id][$gradeitem->id] = $comment;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->comments[$student->id][$gradeitem->id] = '';
|
$this->comments[$student->id][$gradeitem->id] = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To be implemented by child classes
|
* To be implemented by child classes
|
||||||
*/
|
*/
|
||||||
function print_grades() { }
|
function print_grades() { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays all the grades on screen as a feedback mechanism
|
* Displays all the grades on screen as a feedback mechanism
|
||||||
*/
|
*/
|
||||||
|
@ -205,34 +205,34 @@ class grade_export {
|
||||||
foreach ($this->columns as $column) {
|
foreach ($this->columns as $column) {
|
||||||
$column = strip_tags($column);
|
$column = strip_tags($column);
|
||||||
echo "<th>$column</th>";
|
echo "<th>$column</th>";
|
||||||
|
|
||||||
/// add a column_feedback column
|
/// add a column_feedback column
|
||||||
if ($feedback) {
|
if ($feedback) {
|
||||||
echo "<th>{$column}_feedback</th>";
|
echo "<th>{$column}_feedback</th>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo '<th>'.get_string("total")."</th>";
|
echo '<th>'.get_string("total")."</th>";
|
||||||
echo '</tr>';
|
echo '</tr>';
|
||||||
/// Print all the lines of data.
|
/// Print all the lines of data.
|
||||||
|
|
||||||
|
|
||||||
foreach ($this->grades as $studentid => $studentgrades) {
|
foreach ($this->grades as $studentid => $studentgrades) {
|
||||||
|
|
||||||
echo '<tr>';
|
echo '<tr>';
|
||||||
$student = $this->students[$studentid];
|
$student = $this->students[$studentid];
|
||||||
if (empty($this->totals[$student->id])) {
|
if (empty($this->totals[$student->id])) {
|
||||||
$this->totals[$student->id] = '';
|
$this->totals[$student->id] = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
echo "<td>$student->firstname</td><td>$student->lastname</td><td>$student->idnumber</td><td>$student->institution</td><td>$student->department</td><td>$student->email</td>";
|
echo "<td>$student->firstname</td><td>$student->lastname</td><td>$student->idnumber</td><td>$student->institution</td><td>$student->department</td><td>$student->email</td>";
|
||||||
foreach ($studentgrades as $grade) {
|
foreach ($studentgrades as $grade) {
|
||||||
$grade = strip_tags($grade);
|
$grade = strip_tags($grade);
|
||||||
echo "<td>$grade</td>";
|
echo "<td>$grade</td>";
|
||||||
|
|
||||||
if ($feedback) {
|
if ($feedback) {
|
||||||
echo '<td>'.array_shift($this->comments[$student->id]).'</td>';
|
echo '<td>'.array_shift($this->comments[$student->id]).'</td>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo '<td>'.$this->totals[$student->id].'</td>';
|
echo '<td>'.$this->totals[$student->id].'</td>';
|
||||||
echo "</tr>";
|
echo "</tr>";
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
require_once("../../../config.php");
|
require_once("../../../config.php");
|
||||||
require_once($CFG->dirroot.'/grade/export/lib.php');
|
require_once($CFG->dirroot.'/grade/export/lib.php');
|
||||||
require_once('grade_export_ods.php');
|
require_once('grade_export_ods.php');
|
||||||
|
|
||||||
$id = required_param('id', PARAM_INT); // course id
|
$id = required_param('id', PARAM_INT); // course id
|
||||||
$itemids = explode(",", required_param('itemids', PARAM_RAW));
|
$itemids = explode(",", required_param('itemids', PARAM_RAW));
|
||||||
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
||||||
|
|
||||||
// print all the exported data here
|
// print all the exported data here
|
||||||
$export = new grade_export_ods($id, $itemids);
|
$export = new grade_export_ods($id, $itemids);
|
||||||
$export->print_grades($feedback);
|
$export->print_grades($feedback);
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -25,29 +25,29 @@
|
||||||
require_once($CFG->dirroot.'/grade/export/lib.php');
|
require_once($CFG->dirroot.'/grade/export/lib.php');
|
||||||
|
|
||||||
class grade_export_ods extends grade_export {
|
class grade_export_ods extends grade_export {
|
||||||
|
|
||||||
var $format = 'ods'; // export format
|
var $format = 'ods'; // export format
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To be implemented by child classes
|
* To be implemented by child classes
|
||||||
*/
|
*/
|
||||||
function print_grades($feedback = false) {
|
function print_grades($feedback = false) {
|
||||||
|
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
|
||||||
require_once($CFG->dirroot.'/lib/odslib.class.php');
|
require_once($CFG->dirroot.'/lib/odslib.class.php');
|
||||||
|
|
||||||
/// Whether this plugin is entitled to update export time
|
/// Whether this plugin is entitled to update export time
|
||||||
if ($expplugins = explode(",", $CFG->gradeexport)) {
|
if ($expplugins = explode(",", $CFG->gradeexport)) {
|
||||||
if (in_array($this->format, $expplugins)) {
|
if (in_array($this->format, $expplugins)) {
|
||||||
$export = true;
|
$export = true;
|
||||||
} else {
|
} else {
|
||||||
$export = false;
|
$export = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$export = false;
|
$export = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calculate file name
|
/// Calculate file name
|
||||||
$downloadfilename = clean_filename("{$this->course->shortname} $this->strgrades.ods");
|
$downloadfilename = clean_filename("{$this->course->shortname} $this->strgrades.ods");
|
||||||
/// Creating a workbook
|
/// Creating a workbook
|
||||||
|
@ -56,7 +56,7 @@ class grade_export_ods extends grade_export {
|
||||||
$workbook->send($downloadfilename);
|
$workbook->send($downloadfilename);
|
||||||
/// Adding the worksheet
|
/// Adding the worksheet
|
||||||
$myxls =& $workbook->add_worksheet($this->strgrades);
|
$myxls =& $workbook->add_worksheet($this->strgrades);
|
||||||
|
|
||||||
/// Print names of all the fields
|
/// Print names of all the fields
|
||||||
$myxls->write_string(0,0,get_string("firstname"));
|
$myxls->write_string(0,0,get_string("firstname"));
|
||||||
$myxls->write_string(0,1,get_string("lastname"));
|
$myxls->write_string(0,1,get_string("lastname"));
|
||||||
|
@ -67,14 +67,14 @@ class grade_export_ods extends grade_export {
|
||||||
$pos=6;
|
$pos=6;
|
||||||
foreach ($this->columns as $column) {
|
foreach ($this->columns as $column) {
|
||||||
$myxls->write_string(0,$pos++,strip_tags($column));
|
$myxls->write_string(0,$pos++,strip_tags($column));
|
||||||
|
|
||||||
/// add a column_feedback column
|
/// add a column_feedback column
|
||||||
if ($feedback) {
|
if ($feedback) {
|
||||||
$myxls->write_string(0,$pos++,strip_tags($column."_feedback"));
|
$myxls->write_string(0,$pos++,strip_tags($column."_feedback"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$myxls->write_string(0,$pos,get_string("total"));
|
$myxls->write_string(0,$pos,get_string("total"));
|
||||||
|
|
||||||
/// Print all the lines of data.
|
/// Print all the lines of data.
|
||||||
$i = 0;
|
$i = 0;
|
||||||
if (!empty($this->grades)) {
|
if (!empty($this->grades)) {
|
||||||
|
@ -84,7 +84,7 @@ class grade_export_ods extends grade_export {
|
||||||
if (empty($this->totals[$student->id])) {
|
if (empty($this->totals[$student->id])) {
|
||||||
$this->totals[$student->id] = '';
|
$this->totals[$student->id] = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$myxls->write_string($i,0,$student->firstname);
|
$myxls->write_string($i,0,$student->firstname);
|
||||||
$myxls->write_string($i,1,$student->lastname);
|
$myxls->write_string($i,1,$student->lastname);
|
||||||
$myxls->write_string($i,2,$student->idnumber);
|
$myxls->write_string($i,2,$student->idnumber);
|
||||||
|
@ -99,20 +99,20 @@ class grade_export_ods extends grade_export {
|
||||||
else {
|
else {
|
||||||
$myxls->write_string($i,$j++,strip_tags($grade));
|
$myxls->write_string($i,$j++,strip_tags($grade));
|
||||||
}
|
}
|
||||||
|
|
||||||
// writing comment if requested
|
// writing comment if requested
|
||||||
if ($feedback) {
|
if ($feedback) {
|
||||||
$myxls->write_string($i,$j++,array_shift($this->comments[$student->id]));
|
$myxls->write_string($i,$j++,array_shift($this->comments[$student->id]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// if export flag needs to be set
|
/// if export flag needs to be set
|
||||||
/// construct the grade_grades object and update timestamp if CFG flag is set
|
/// construct the grade_grades object and update timestamp if CFG flag is set
|
||||||
|
|
||||||
if ($export) {
|
if ($export) {
|
||||||
$params= new object();
|
$params= new object();
|
||||||
$params->itemid = $gradeitemid;
|
$params->itemid = $gradeitemid;
|
||||||
$params->userid = $studentid;
|
$params->userid = $studentid;
|
||||||
|
|
||||||
$grade_grades = new grade_grades($params);
|
$grade_grades = new grade_grades($params);
|
||||||
$grade_grades->exported = time();
|
$grade_grades->exported = time();
|
||||||
// update the time stamp;
|
// update the time stamp;
|
||||||
|
@ -125,7 +125,7 @@ class grade_export_ods extends grade_export {
|
||||||
|
|
||||||
/// Close the workbook
|
/// Close the workbook
|
||||||
$workbook->close();
|
$workbook->close();
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,13 +25,13 @@ require_once("../../../config.php");
|
||||||
require_once($CFG->dirroot.'/grade/export/lib.php');
|
require_once($CFG->dirroot.'/grade/export/lib.php');
|
||||||
require_once('grade_export_ods.php');
|
require_once('grade_export_ods.php');
|
||||||
|
|
||||||
$id = required_param('id', PARAM_INT); // course id
|
$id = required_param('id', PARAM_INT); // course id
|
||||||
|
|
||||||
require_login($id);
|
require_login($id);
|
||||||
require_capability('moodle/course:downloadallgrades', get_context_instance(CONTEXT_COURSE, $id));
|
require_capability('moodle/course:downloadallgrades', get_context_instance(CONTEXT_COURSE, $id));
|
||||||
|
|
||||||
$course = get_record('course', 'id', $id);
|
$course = get_record('course', 'id', $id);
|
||||||
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
||||||
$strgrades = get_string('grades', 'grades');
|
$strgrades = get_string('grades', 'grades');
|
||||||
$actionstr = get_string('exportods', 'grades');
|
$actionstr = get_string('exportods', 'grades');
|
||||||
$gradenav = "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>";
|
$gradenav = "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>";
|
||||||
|
@ -46,15 +46,15 @@ if (($data = data_submitted()) && confirm_sesskey()) {
|
||||||
} else {
|
} else {
|
||||||
$itemidsurl = implode(",",$data->itemids);
|
$itemidsurl = implode(",",$data->itemids);
|
||||||
}
|
}
|
||||||
|
|
||||||
// print the grades on screen for feedbacks
|
// print the grades on screen for feedbacks
|
||||||
|
|
||||||
$export = new grade_export($id, $data->itemids);
|
$export = new grade_export($id, $data->itemids);
|
||||||
$export->display_grades($feedback);
|
$export->display_grades($feedback);
|
||||||
|
|
||||||
// this redirect should trigger a download prompt
|
// this redirect should trigger a download prompt
|
||||||
redirect('export.php?id='.$id.'&itemids='.$itemidsurl);
|
redirect('export.php?id='.$id.'&itemids='.$itemidsurl);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
print_gradeitem_selections($id);
|
print_gradeitem_selections($id);
|
||||||
|
|
|
@ -3,14 +3,14 @@
|
||||||
require_once("../../../config.php");
|
require_once("../../../config.php");
|
||||||
require_once($CFG->dirroot.'/grade/export/lib.php');
|
require_once($CFG->dirroot.'/grade/export/lib.php');
|
||||||
require_once('grade_export_txt.php');
|
require_once('grade_export_txt.php');
|
||||||
|
|
||||||
$id = required_param('id', PARAM_INT); // course id
|
$id = required_param('id', PARAM_INT); // course id
|
||||||
$itemids = explode(",", required_param('itemids', PARAM_RAW));
|
$itemids = explode(",", required_param('itemids', PARAM_RAW));
|
||||||
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
||||||
|
|
||||||
// print all the exported data here
|
// print all the exported data here
|
||||||
$export = new grade_export_txt($id, $itemids);
|
$export = new grade_export_txt($id, $itemids);
|
||||||
$export->set_separator(optional_param('separator'));
|
$export->set_separator(optional_param('separator'));
|
||||||
$export->print_grades($feedback);
|
$export->print_grades($feedback);
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -25,22 +25,22 @@
|
||||||
require_once($CFG->dirroot.'/grade/export/lib.php');
|
require_once($CFG->dirroot.'/grade/export/lib.php');
|
||||||
|
|
||||||
class grade_export_txt extends grade_export {
|
class grade_export_txt extends grade_export {
|
||||||
|
|
||||||
var $format = 'txt'; // export format
|
var $format = 'txt'; // export format
|
||||||
var $separator = "\t"; // default separator
|
var $separator = "\t"; // default separator
|
||||||
|
|
||||||
function set_separator($separator) {
|
function set_separator($separator) {
|
||||||
if ($separator == 'comma') {
|
if ($separator == 'comma') {
|
||||||
$this->separator = ",";
|
$this->separator = ",";
|
||||||
} else if ($separator == 'tab') {
|
} else if ($separator == 'tab') {
|
||||||
$this->separator = "\t";
|
$this->separator = "\t";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To be implemented by child classes
|
* To be implemented by child classes
|
||||||
*/
|
*/
|
||||||
function print_grades($feedback = false) {
|
function print_grades($feedback = false) {
|
||||||
|
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
|
||||||
|
@ -49,14 +49,14 @@ class grade_export_txt extends grade_export {
|
||||||
if (in_array($this->format, $expplugins)) {
|
if (in_array($this->format, $expplugins)) {
|
||||||
$export = true;
|
$export = true;
|
||||||
} else {
|
} else {
|
||||||
$export = false;
|
$export = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$export = false;
|
$export = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Print header to force download
|
/// Print header to force download
|
||||||
header("Content-Type: application/download\n");
|
header("Content-Type: application/download\n");
|
||||||
$downloadfilename = clean_filename("{$this->course->shortname} $this->strgrades");
|
$downloadfilename = clean_filename("{$this->course->shortname} $this->strgrades");
|
||||||
header("Content-Disposition: attachment; filename=\"$downloadfilename.txt\"");
|
header("Content-Disposition: attachment; filename=\"$downloadfilename.txt\"");
|
||||||
|
|
||||||
|
@ -71,17 +71,17 @@ class grade_export_txt extends grade_export {
|
||||||
foreach ($this->columns as $column) {
|
foreach ($this->columns as $column) {
|
||||||
$column = strip_tags($column);
|
$column = strip_tags($column);
|
||||||
echo "{$this->separator}$column";
|
echo "{$this->separator}$column";
|
||||||
|
|
||||||
/// add a column_feedback column
|
/// add a column_feedback column
|
||||||
if ($feedback) {
|
if ($feedback) {
|
||||||
echo "{$this->separator}{$column}_feedback";
|
echo "{$this->separator}{$column}_feedback";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo "{$this->separator}".get_string("total")."\n";
|
echo "{$this->separator}".get_string("total")."\n";
|
||||||
|
|
||||||
/// Print all the lines of data.
|
/// Print all the lines of data.
|
||||||
foreach ($this->grades as $studentid => $studentgrades) {
|
foreach ($this->grades as $studentid => $studentgrades) {
|
||||||
|
|
||||||
$student = $this->students[$studentid];
|
$student = $this->students[$studentid];
|
||||||
if (empty($this->totals[$student->id])) {
|
if (empty($this->totals[$student->id])) {
|
||||||
$this->totals[$student->id] = '';
|
$this->totals[$student->id] = '';
|
||||||
|
@ -90,12 +90,12 @@ class grade_export_txt extends grade_export {
|
||||||
|
|
||||||
foreach ($studentgrades as $gradeitemid => $grade) {
|
foreach ($studentgrades as $gradeitemid => $grade) {
|
||||||
$grade = strip_tags($grade);
|
$grade = strip_tags($grade);
|
||||||
echo "{$this->separator}$grade";
|
echo "{$this->separator}$grade";
|
||||||
|
|
||||||
if ($feedback) {
|
if ($feedback) {
|
||||||
echo "{$this->separator}".array_shift($this->comments[$student->id]);
|
echo "{$this->separator}".array_shift($this->comments[$student->id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// if export flag needs to be set
|
/// if export flag needs to be set
|
||||||
/// construct the grade_grades object and update timestamp if CFG flag is set
|
/// construct the grade_grades object and update timestamp if CFG flag is set
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ class grade_export_txt extends grade_export {
|
||||||
$params = new object();
|
$params = new object();
|
||||||
$params->itemid = $gradeitemid;
|
$params->itemid = $gradeitemid;
|
||||||
$params->userid = $studentid;
|
$params->userid = $studentid;
|
||||||
|
|
||||||
$grade_grades = new grade_grades($params);
|
$grade_grades = new grade_grades($params);
|
||||||
$grade_grades->exported = time();
|
$grade_grades->exported = time();
|
||||||
// update the time stamp;
|
// update the time stamp;
|
||||||
|
@ -113,7 +113,7 @@ class grade_export_txt extends grade_export {
|
||||||
echo "{$this->separator}".$this->totals[$student->id];
|
echo "{$this->separator}".$this->totals[$student->id];
|
||||||
echo "\n";
|
echo "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,15 +16,15 @@ class grade_export_txt_form extends moodleform {
|
||||||
$mform->addElement($element);
|
$mform->addElement($element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
include_once($CFG->libdir.'/pear/HTML/QuickForm/radio.php');
|
include_once($CFG->libdir.'/pear/HTML/QuickForm/radio.php');
|
||||||
$radio = array();
|
$radio = array();
|
||||||
$radio[] = &MoodleQuickForm::createElement('radio', 'separator', null, get_string('septab', 'grades'), 'tab');
|
$radio[] = &MoodleQuickForm::createElement('radio', 'separator', null, get_string('septab', 'grades'), 'tab');
|
||||||
$radio[] = &MoodleQuickForm::createElement('radio', 'separator', null, get_string('sepcomma', 'grades'), 'comma');
|
$radio[] = &MoodleQuickForm::createElement('radio', 'separator', null, get_string('sepcomma', 'grades'), 'comma');
|
||||||
$mform->addGroup($radio, 'separator', get_string('separator', 'grades'), ' ', false);
|
$mform->addGroup($radio, 'separator', get_string('separator', 'grades'), ' ', false);
|
||||||
$mform->setDefault('separator', 'comma');
|
$mform->setDefault('separator', 'comma');
|
||||||
|
|
||||||
$this->add_action_buttons(false, get_string('submit'));
|
$this->add_action_buttons(false, get_string('submit'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
|
@ -48,13 +48,13 @@ if (($data = data_submitted()) && confirm_sesskey()) {
|
||||||
} else {
|
} else {
|
||||||
$itemidsurl = implode(",",$data->itemids);
|
$itemidsurl = implode(",",$data->itemids);
|
||||||
}
|
}
|
||||||
|
|
||||||
$export = new grade_export($id, $data->itemids);
|
$export = new grade_export($id, $data->itemids);
|
||||||
$export->display_grades($feedback);
|
$export->display_grades($feedback);
|
||||||
|
|
||||||
// this redirect should trigger a download prompt
|
// this redirect should trigger a download prompt
|
||||||
redirect('export.php?id='.$id.'&itemids='.$itemidsurl.'&separator='.$data->separator);
|
redirect('export.php?id='.$id.'&itemids='.$itemidsurl.'&separator='.$data->separator);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// print the form to choose what grade_items to export
|
// print the form to choose what grade_items to export
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
require_once("../../../config.php");
|
require_once("../../../config.php");
|
||||||
require_once($CFG->dirroot.'/grade/export/lib.php');
|
require_once($CFG->dirroot.'/grade/export/lib.php');
|
||||||
require_once('grade_export_xls.php');
|
require_once('grade_export_xls.php');
|
||||||
|
|
||||||
$id = required_param('id', PARAM_INT); // course id
|
$id = required_param('id', PARAM_INT); // course id
|
||||||
$itemids = explode(",", required_param('itemids', PARAM_RAW));
|
$itemids = explode(",", required_param('itemids', PARAM_RAW));
|
||||||
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
||||||
|
|
||||||
// print all the exported data here
|
// print all the exported data here
|
||||||
$export = new grade_export_xls($id, $itemids);
|
$export = new grade_export_xls($id, $itemids);
|
||||||
$export->print_grades($feedback);
|
$export->print_grades($feedback);
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -25,27 +25,27 @@
|
||||||
require_once($CFG->dirroot.'/grade/export/lib.php');
|
require_once($CFG->dirroot.'/grade/export/lib.php');
|
||||||
|
|
||||||
class grade_export_xls extends grade_export {
|
class grade_export_xls extends grade_export {
|
||||||
|
|
||||||
var $format = 'xls'; // export format
|
var $format = 'xls'; // export format
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To be implemented by child classes
|
* To be implemented by child classes
|
||||||
*/
|
*/
|
||||||
function print_grades($feedback = false) {
|
function print_grades($feedback = false) {
|
||||||
|
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
|
||||||
/// Whether this plugin is entitled to update export time
|
/// Whether this plugin is entitled to update export time
|
||||||
if ($expplugins = explode(",", $CFG->gradeexport)) {
|
if ($expplugins = explode(",", $CFG->gradeexport)) {
|
||||||
if (in_array($this->format, $expplugins)) {
|
if (in_array($this->format, $expplugins)) {
|
||||||
$export = true;
|
$export = true;
|
||||||
} else {
|
} else {
|
||||||
$export = false;
|
$export = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$export = false;
|
$export = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once($CFG->dirroot.'/lib/excellib.class.php');
|
require_once($CFG->dirroot.'/lib/excellib.class.php');
|
||||||
|
|
||||||
/// Calculate file name
|
/// Calculate file name
|
||||||
|
@ -56,7 +56,7 @@ class grade_export_xls extends grade_export {
|
||||||
$workbook->send($downloadfilename);
|
$workbook->send($downloadfilename);
|
||||||
/// Adding the worksheet
|
/// Adding the worksheet
|
||||||
$myxls =& $workbook->add_worksheet($this->strgrades);
|
$myxls =& $workbook->add_worksheet($this->strgrades);
|
||||||
|
|
||||||
/// Print names of all the fields
|
/// Print names of all the fields
|
||||||
$myxls->write_string(0,0,get_string("firstname"));
|
$myxls->write_string(0,0,get_string("firstname"));
|
||||||
$myxls->write_string(0,1,get_string("lastname"));
|
$myxls->write_string(0,1,get_string("lastname"));
|
||||||
|
@ -67,13 +67,13 @@ class grade_export_xls extends grade_export {
|
||||||
$pos=6;
|
$pos=6;
|
||||||
foreach ($this->columns as $column) {
|
foreach ($this->columns as $column) {
|
||||||
$myxls->write_string(0,$pos++,strip_tags($column));
|
$myxls->write_string(0,$pos++,strip_tags($column));
|
||||||
/// add a column_feedback column
|
/// add a column_feedback column
|
||||||
if ($feedback) {
|
if ($feedback) {
|
||||||
$myxls->write_string(0,$pos++,strip_tags($column."_feedback"));
|
$myxls->write_string(0,$pos++,strip_tags($column."_feedback"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$myxls->write_string(0,$pos,get_string("total"));
|
$myxls->write_string(0,$pos,get_string("total"));
|
||||||
|
|
||||||
/// Print all the lines of data.
|
/// Print all the lines of data.
|
||||||
$i = 0;
|
$i = 0;
|
||||||
if (!empty($this->grades)) {
|
if (!empty($this->grades)) {
|
||||||
|
@ -83,7 +83,7 @@ class grade_export_xls extends grade_export {
|
||||||
if (empty($this->totals[$student->id])) {
|
if (empty($this->totals[$student->id])) {
|
||||||
$this->totals[$student->id] = '';
|
$this->totals[$student->id] = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$myxls->write_string($i,0,$student->firstname);
|
$myxls->write_string($i,0,$student->firstname);
|
||||||
$myxls->write_string($i,1,$student->lastname);
|
$myxls->write_string($i,1,$student->lastname);
|
||||||
$myxls->write_string($i,2,$student->idnumber);
|
$myxls->write_string($i,2,$student->idnumber);
|
||||||
|
@ -97,8 +97,8 @@ class grade_export_xls extends grade_export {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$myxls->write_string($i,$j++,strip_tags($grade));
|
$myxls->write_string($i,$j++,strip_tags($grade));
|
||||||
}
|
}
|
||||||
|
|
||||||
// writing comment if requested
|
// writing comment if requested
|
||||||
if ($feedback) {
|
if ($feedback) {
|
||||||
$myxls->write_string($i,$j++,array_shift($this->comments[$student->id]));
|
$myxls->write_string($i,$j++,array_shift($this->comments[$student->id]));
|
||||||
|
@ -106,12 +106,12 @@ class grade_export_xls extends grade_export {
|
||||||
|
|
||||||
/// if export flag needs to be set
|
/// if export flag needs to be set
|
||||||
/// construct the grade_grades object and update timestamp if CFG flag is set
|
/// construct the grade_grades object and update timestamp if CFG flag is set
|
||||||
|
|
||||||
if ($export) {
|
if ($export) {
|
||||||
$params = new object();
|
$params = new object();
|
||||||
$params->itemid = $gradeitemid;
|
$params->itemid = $gradeitemid;
|
||||||
$params->userid = $studentid;
|
$params->userid = $studentid;
|
||||||
|
|
||||||
$grade_grades = new grade_grades($params);
|
$grade_grades = new grade_grades($params);
|
||||||
$grade_grades->exported = time();
|
$grade_grades->exported = time();
|
||||||
// update the time stamp;
|
// update the time stamp;
|
||||||
|
@ -124,7 +124,7 @@ class grade_export_xls extends grade_export {
|
||||||
|
|
||||||
/// Close the workbook
|
/// Close the workbook
|
||||||
$workbook->close();
|
$workbook->close();
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,15 +48,15 @@ if (($data = data_submitted()) && confirm_sesskey()) {
|
||||||
} else {
|
} else {
|
||||||
$itemidsurl = implode(",",$data->itemids);
|
$itemidsurl = implode(",",$data->itemids);
|
||||||
}
|
}
|
||||||
|
|
||||||
// print the grades on screen for feedbacks
|
// print the grades on screen for feedbacks
|
||||||
|
|
||||||
$export = new grade_export($id, $data->itemids);
|
$export = new grade_export($id, $data->itemids);
|
||||||
$export->display_grades($feedback);
|
$export->display_grades($feedback);
|
||||||
|
|
||||||
// this redirect should trigger a download prompt
|
// this redirect should trigger a download prompt
|
||||||
redirect('export.php?id='.$id.'&itemids='.$itemidsurl);
|
redirect('export.php?id='.$id.'&itemids='.$itemidsurl);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
print_gradeitem_selections($id);
|
print_gradeitem_selections($id);
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
require_once("../../../config.php");
|
require_once("../../../config.php");
|
||||||
require_once($CFG->dirroot.'/grade/export/lib.php');
|
require_once($CFG->dirroot.'/grade/export/lib.php');
|
||||||
require_once('grade_export_xml.php');
|
require_once('grade_export_xml.php');
|
||||||
|
|
||||||
$id = required_param('id', PARAM_INT); // course id
|
$id = required_param('id', PARAM_INT); // course id
|
||||||
$itemids = explode(",", required_param('itemids', PARAM_RAW));
|
$itemids = explode(",", required_param('itemids', PARAM_RAW));
|
||||||
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
||||||
|
|
||||||
// print all the exported data here
|
// print all the exported data here
|
||||||
$export = new grade_export_xml($id, $itemids);
|
$export = new grade_export_xml($id, $itemids);
|
||||||
$export->print_grades($feedback);
|
$export->print_grades($feedback);
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -25,14 +25,14 @@
|
||||||
require_once($CFG->dirroot.'/grade/export/lib.php');
|
require_once($CFG->dirroot.'/grade/export/lib.php');
|
||||||
|
|
||||||
class grade_export_xml extends grade_export {
|
class grade_export_xml extends grade_export {
|
||||||
|
|
||||||
var $format = 'xml'; // export format
|
var $format = 'xml'; // export format
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To be implemented by child classes
|
* To be implemented by child classes
|
||||||
*/
|
*/
|
||||||
function print_grades($feedback = false) {
|
function print_grades($feedback = false) {
|
||||||
|
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
|
||||||
/// Whether this plugin is entitled to update export time
|
/// Whether this plugin is entitled to update export time
|
||||||
|
@ -40,60 +40,60 @@ class grade_export_xml extends grade_export {
|
||||||
if (in_array($this->format, $expplugins)) {
|
if (in_array($this->format, $expplugins)) {
|
||||||
$export = true;
|
$export = true;
|
||||||
} else {
|
} else {
|
||||||
$export = false;
|
$export = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$export = false;
|
$export = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once($CFG->dirroot.'/lib/excellib.class.php');
|
require_once($CFG->dirroot.'/lib/excellib.class.php');
|
||||||
|
|
||||||
/// Calculate file name
|
/// Calculate file name
|
||||||
$downloadfilename = clean_filename("{$this->course->shortname} $this->strgrades.xml");
|
$downloadfilename = clean_filename("{$this->course->shortname} $this->strgrades.xml");
|
||||||
|
|
||||||
header("Content-type: text/xml; charset=UTF-8");
|
header("Content-type: text/xml; charset=UTF-8");
|
||||||
header("Content-Disposition: attachment; filename=\"$downloadfilename\"");
|
header("Content-Disposition: attachment; filename=\"$downloadfilename\"");
|
||||||
|
|
||||||
/// time stamp to ensure uniqueness of batch export
|
/// time stamp to ensure uniqueness of batch export
|
||||||
echo '<results batch="xml_export_'.time().'">';
|
echo '<results batch="xml_export_'.time().'">';
|
||||||
|
|
||||||
foreach ($this->columnidnumbers as $index => $idnumber) {
|
foreach ($this->columnidnumbers as $index => $idnumber) {
|
||||||
|
|
||||||
// studentgrades[] index should match with corresponding $index
|
// studentgrades[] index should match with corresponding $index
|
||||||
foreach ($this->grades as $studentid => $studentgrades) {
|
foreach ($this->grades as $studentid => $studentgrades) {
|
||||||
echo '<result>';
|
echo '<result>';
|
||||||
|
|
||||||
// state can be new, or regrade
|
// state can be new, or regrade
|
||||||
// require comparing of timestamps in db
|
// require comparing of timestamps in db
|
||||||
|
|
||||||
$params = new object();
|
$params = new object();
|
||||||
$params->idnumber = $idnumber;
|
$params->idnumber = $idnumber;
|
||||||
// get the grade item
|
// get the grade item
|
||||||
$gradeitem = new grade_item($params);
|
$gradeitem = new grade_item($params);
|
||||||
|
|
||||||
// we are trying to figure out if this is a new grade, or a regraded grade
|
// we are trying to figure out if this is a new grade, or a regraded grade
|
||||||
// only relevant if this grade for this user is already exported
|
// only relevant if this grade for this user is already exported
|
||||||
|
|
||||||
// get the grade_grades for this user
|
// get the grade_grades for this user
|
||||||
$params = new object();
|
$params = new object();
|
||||||
$params->itemid = $gradeitem->id;
|
$params->itemid = $gradeitem->id;
|
||||||
$params->userid = $studentid;
|
$params->userid = $studentid;
|
||||||
|
|
||||||
$grade_grades = new grade_grades($params);
|
$grade_grades = new grade_grades($params);
|
||||||
|
|
||||||
// if exported, check grade_history, if modified after export, set state to regrade
|
// if exported, check grade_history, if modified after export, set state to regrade
|
||||||
if (!empty($grade_grades->exported)) {
|
if (!empty($grade_grades->exported)) {
|
||||||
//TODO: use timemodified or something else instead
|
//TODO: use timemodified or something else instead
|
||||||
/* if (record_exists_select('grade_history', 'itemid = '.$gradeitem->id.' AND userid = '.$studentid.' AND timemodified > '.$grade_grades->exported)) {
|
/* if (record_exists_select('grade_history', 'itemid = '.$gradeitem->id.' AND userid = '.$studentid.' AND timemodified > '.$grade_grades->exported)) {
|
||||||
$status = 'regrade';
|
$status = 'regrade';
|
||||||
} else {
|
} else {
|
||||||
$status = 'new';
|
$status = 'new';
|
||||||
}*/
|
}*/
|
||||||
} else {
|
} else {
|
||||||
// never exported
|
// never exported
|
||||||
$status = 'new';
|
$status = 'new';
|
||||||
}
|
}
|
||||||
|
|
||||||
echo '<state>'.$status.'</state>';
|
echo '<state>'.$status.'</state>';
|
||||||
// only need id number
|
// only need id number
|
||||||
echo '<assignment>'.$idnumber.'</assignment>';
|
echo '<assignment>'.$idnumber.'</assignment>';
|
||||||
|
@ -101,7 +101,7 @@ class grade_export_xml extends grade_export {
|
||||||
echo '<student>'.$studentid.'</student>';
|
echo '<student>'.$studentid.'</student>';
|
||||||
echo '<score>'.$studentgrades[$index].'</score>';
|
echo '<score>'.$studentgrades[$index].'</score>';
|
||||||
if ($feedback) {
|
if ($feedback) {
|
||||||
echo '<feedback>'.$this->comments[$studentid][$index].'</feedback>';
|
echo '<feedback>'.$this->comments[$studentid][$index].'</feedback>';
|
||||||
}
|
}
|
||||||
echo '</result>';
|
echo '</result>';
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ class grade_export_xml extends grade_export {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo '</results>';
|
echo '</results>';
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ require_capability('moodle/course:downloadallgrades', get_context_instance(CONTE
|
||||||
|
|
||||||
$course = get_record('course', 'id', $id);
|
$course = get_record('course', 'id', $id);
|
||||||
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
||||||
|
|
||||||
$strgrades = get_string('grades', 'grades');
|
$strgrades = get_string('grades', 'grades');
|
||||||
$actionstr = get_string('exportxml', 'grades');
|
$actionstr = get_string('exportxml', 'grades');
|
||||||
$gradenav = "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>";
|
$gradenav = "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>";
|
||||||
|
@ -48,12 +48,12 @@ if (($data = data_submitted()) && confirm_sesskey()) {
|
||||||
} else {
|
} else {
|
||||||
$itemidsurl = implode(",",$data->itemids);
|
$itemidsurl = implode(",",$data->itemids);
|
||||||
}
|
}
|
||||||
|
|
||||||
// print the grades on screen for feedbacks
|
// print the grades on screen for feedbacks
|
||||||
|
|
||||||
$export = new grade_export($id, $data->itemids);
|
$export = new grade_export($id, $data->itemids);
|
||||||
$export->display_grades($feedback);
|
$export->display_grades($feedback);
|
||||||
|
|
||||||
// this redirect should trigger a download prompt
|
// this redirect should trigger a download prompt
|
||||||
redirect('export.php?id='.$id.'&itemids='.$itemidsurl);
|
redirect('export.php?id='.$id.'&itemids='.$itemidsurl);
|
||||||
exit;
|
exit;
|
||||||
|
|
|
@ -40,25 +40,25 @@ $mform = new grade_import_form();
|
||||||
// i am not able to get the mapping[] and map[] array using the following line
|
// i am not able to get the mapping[] and map[] array using the following line
|
||||||
// they are somehow not returned with get_data()
|
// they are somehow not returned with get_data()
|
||||||
if (($formdata = data_submitted()) && !empty($formdata->map)) {
|
if (($formdata = data_submitted()) && !empty($formdata->map)) {
|
||||||
|
|
||||||
// temporary file name supplied by form
|
// temporary file name supplied by form
|
||||||
$filename = $CFG->dataroot.'/temp/'.clean_param($formdata->filename, PARAM_FILE);
|
$filename = $CFG->dataroot.'/temp/'.clean_param($formdata->filename, PARAM_FILE);
|
||||||
|
|
||||||
if ($fp = fopen($filename, "r")) {
|
if ($fp = fopen($filename, "r")) {
|
||||||
// --- get header (field names) ---
|
// --- get header (field names) ---
|
||||||
$header = split($csv_delimiter, clean_param(fgets($fp,1024), PARAM_RAW));
|
$header = split($csv_delimiter, clean_param(fgets($fp,1024), PARAM_RAW));
|
||||||
|
|
||||||
foreach ($header as $i => $h) {
|
foreach ($header as $i => $h) {
|
||||||
$h = trim($h); $header[$i] = $h; // remove whitespace
|
$h = trim($h); $header[$i] = $h; // remove whitespace
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
error ('could not open file '.$filename);
|
error ('could not open file '.$filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
$map = array();
|
$map = array();
|
||||||
// loops mapping_0, mapping_1 .. mapping_n and construct $map array
|
// loops mapping_0, mapping_1 .. mapping_n and construct $map array
|
||||||
foreach ($header as $i => $head) {
|
foreach ($header as $i => $head) {
|
||||||
$map[$i] = $formdata->{'mapping_'.$i};
|
$map[$i] = $formdata->{'mapping_'.$i};
|
||||||
}
|
}
|
||||||
|
|
||||||
// if mapping informatioin is supplied
|
// if mapping informatioin is supplied
|
||||||
|
@ -69,12 +69,12 @@ if (($formdata = data_submitted()) && !empty($formdata->map)) {
|
||||||
foreach ($map as $i=>$j) {
|
foreach ($map as $i=>$j) {
|
||||||
if ($j == 0) {
|
if ($j == 0) {
|
||||||
// you can have multiple ignores
|
// you can have multiple ignores
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
if (!isset($maperrors[$j])) {
|
if (!isset($maperrors[$j])) {
|
||||||
$maperrors[$j] = true;
|
$maperrors[$j] = true;
|
||||||
} else {
|
} else {
|
||||||
// collision
|
// collision
|
||||||
unlink($filename); // needs to be uploaded again, sorry
|
unlink($filename); // needs to be uploaded again, sorry
|
||||||
error('mapping collision detected, 2 fields maps to the same grdae item '.$j);
|
error('mapping collision detected, 2 fields maps to the same grdae item '.$j);
|
||||||
}
|
}
|
||||||
|
@ -89,32 +89,32 @@ if (($formdata = data_submitted()) && !empty($formdata->map)) {
|
||||||
if (function_exists('apache_child_terminate')) {
|
if (function_exists('apache_child_terminate')) {
|
||||||
@apache_child_terminate();
|
@apache_child_terminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// we only operate if file is readable
|
// we only operate if file is readable
|
||||||
if ($fp = fopen($filename, "r")) {
|
if ($fp = fopen($filename, "r")) {
|
||||||
|
|
||||||
// read the first line makes sure this doesn't get read again
|
// read the first line makes sure this doesn't get read again
|
||||||
$header = split($csv_delimiter, clean_param(fgets($fp,1024), PARAM_RAW));
|
$header = split($csv_delimiter, clean_param(fgets($fp,1024), PARAM_RAW));
|
||||||
|
|
||||||
// use current (non-conflicting) time stamp
|
// use current (non-conflicting) time stamp
|
||||||
$importcode = time();
|
$importcode = time();
|
||||||
while (get_record('grade_import_values', 'import_code', $importcode)) {
|
while (get_record('grade_import_values', 'import_code', $importcode)) {
|
||||||
$importcode = time();
|
$importcode = time();
|
||||||
}
|
}
|
||||||
|
|
||||||
$newgradeitems = array(); // temporary array to keep track of what new headers are processed
|
$newgradeitems = array(); // temporary array to keep track of what new headers are processed
|
||||||
$status = true;
|
$status = true;
|
||||||
|
|
||||||
while (!feof ($fp)) {
|
while (!feof ($fp)) {
|
||||||
// add something
|
// add something
|
||||||
$line = split($csv_delimiter, fgets($fp,1024));
|
$line = split($csv_delimiter, fgets($fp,1024));
|
||||||
|
|
||||||
// array to hold all grades to be inserted
|
// array to hold all grades to be inserted
|
||||||
$newgrades = array();
|
$newgrades = array();
|
||||||
// array to hold all feedback
|
// array to hold all feedback
|
||||||
$newfeedbacks = array();
|
$newfeedbacks = array();
|
||||||
// each line is a student record
|
// each line is a student record
|
||||||
foreach ($line as $key => $value) {
|
foreach ($line as $key => $value) {
|
||||||
//decode encoded commas
|
//decode encoded commas
|
||||||
$value = clean_param($value, PARAM_RAW);
|
$value = clean_param($value, PARAM_RAW);
|
||||||
$value = preg_replace($csv_encode,$csv_delimiter2,trim($value));
|
$value = preg_replace($csv_encode,$csv_delimiter2,trim($value));
|
||||||
|
@ -132,9 +132,9 @@ if (($formdata = data_submitted()) && !empty($formdata->map)) {
|
||||||
if (isset($t[1])) {
|
if (isset($t[1])) {
|
||||||
$t1 = $t[1];
|
$t1 = $t[1];
|
||||||
} else {
|
} else {
|
||||||
$t1 = '';
|
$t1 = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($t0) {
|
switch ($t0) {
|
||||||
case 'userid': //
|
case 'userid': //
|
||||||
if (!$user = get_record('user','id', $value)) {
|
if (!$user = get_record('user','id', $value)) {
|
||||||
|
@ -142,7 +142,7 @@ if (($formdata = data_submitted()) && !empty($formdata->map)) {
|
||||||
import_cleanup($importcode);
|
import_cleanup($importcode);
|
||||||
notify("user mapping error, could not find user with id \"$value\"");
|
notify("user mapping error, could not find user with id \"$value\"");
|
||||||
$status = false;
|
$status = false;
|
||||||
break 3;
|
break 3;
|
||||||
}
|
}
|
||||||
$studentid = $value;
|
$studentid = $value;
|
||||||
break;
|
break;
|
||||||
|
@ -152,7 +152,7 @@ if (($formdata = data_submitted()) && !empty($formdata->map)) {
|
||||||
import_cleanup($importcode);
|
import_cleanup($importcode);
|
||||||
notify("user mapping error, could not find user with idnumber \"$value\"");
|
notify("user mapping error, could not find user with idnumber \"$value\"");
|
||||||
$status = false;
|
$status = false;
|
||||||
break 3;
|
break 3;
|
||||||
}
|
}
|
||||||
$studentid = $user->id;
|
$studentid = $user->id;
|
||||||
break;
|
break;
|
||||||
|
@ -161,43 +161,43 @@ if (($formdata = data_submitted()) && !empty($formdata->map)) {
|
||||||
import_cleanup($importcode);
|
import_cleanup($importcode);
|
||||||
notify("user mapping error, could not find user with email address \"$value\"");
|
notify("user mapping error, could not find user with email address \"$value\"");
|
||||||
$status = false;
|
$status = false;
|
||||||
break 3;
|
break 3;
|
||||||
}
|
}
|
||||||
$studentid = $user->id;
|
$studentid = $user->id;
|
||||||
break;
|
break;
|
||||||
case 'username':
|
case 'username':
|
||||||
if (!$user = get_record('user', 'username', $value)) {
|
if (!$user = get_record('user', 'username', $value)) {
|
||||||
import_cleanup($importcode);
|
import_cleanup($importcode);
|
||||||
notify("user mapping error, could not find user with username \"$value\"");
|
notify("user mapping error, could not find user with username \"$value\"");
|
||||||
$status = false;
|
$status = false;
|
||||||
break 3;
|
break 3;
|
||||||
}
|
}
|
||||||
$studentid = $user->id;
|
$studentid = $user->id;
|
||||||
break;
|
break;
|
||||||
case 'new':
|
case 'new':
|
||||||
// first check if header is already in temp database
|
// first check if header is already in temp database
|
||||||
|
|
||||||
if (empty($newgradeitems[$key])) {
|
if (empty($newgradeitems[$key])) {
|
||||||
|
|
||||||
$newgradeitem->itemname = $header[$key];
|
$newgradeitem->itemname = $header[$key];
|
||||||
$newgradeitem->import_code = $importcode;
|
$newgradeitem->import_code = $importcode;
|
||||||
|
|
||||||
// failed to insert into new grade item buffer
|
// failed to insert into new grade item buffer
|
||||||
if (!$newgradeitems[$key] = insert_record('grade_import_newitem', $newgradeitem)) {
|
if (!$newgradeitems[$key] = insert_record('grade_import_newitem', $newgradeitem)) {
|
||||||
$status = false;
|
$status = false;
|
||||||
import_cleanup($importcode);
|
import_cleanup($importcode);
|
||||||
notify(get_string('importfailed', 'grades'));
|
notify(get_string('importfailed', 'grades'));
|
||||||
break 3;
|
break 3;
|
||||||
}
|
}
|
||||||
// add this to grade_import_newitem table
|
// add this to grade_import_newitem table
|
||||||
// add the new id to $newgradeitem[$key]
|
// add the new id to $newgradeitem[$key]
|
||||||
}
|
}
|
||||||
unset($newgrade);
|
unset($newgrade);
|
||||||
$newgrade -> newgradeitem = $newgradeitems[$key];
|
$newgrade -> newgradeitem = $newgradeitems[$key];
|
||||||
$newgrade -> finalgrade = $value;
|
$newgrade -> finalgrade = $value;
|
||||||
$newgrades[] = $newgrade;
|
$newgrades[] = $newgrade;
|
||||||
|
|
||||||
// if not, put it in
|
// if not, put it in
|
||||||
// else, insert grade into the table
|
// else, insert grade into the table
|
||||||
break;
|
break;
|
||||||
case 'feedback':
|
case 'feedback':
|
||||||
|
@ -207,22 +207,22 @@ if (($formdata = data_submitted()) && !empty($formdata->map)) {
|
||||||
$feedback -> feedback = $value;
|
$feedback -> feedback = $value;
|
||||||
$newfeedbacks[] = $feedback;
|
$newfeedbacks[] = $feedback;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// existing grade items
|
// existing grade items
|
||||||
if (!empty($map[$key]) && $value!=="") {
|
if (!empty($map[$key]) && $value!=="") {
|
||||||
|
|
||||||
// non numeric grade value supplied, possibly mapped wrong column
|
// non numeric grade value supplied, possibly mapped wrong column
|
||||||
if (!is_numeric($value)) {
|
if (!is_numeric($value)) {
|
||||||
echo "<br/>t0 is $t0";
|
echo "<br/>t0 is $t0";
|
||||||
echo "<br/>grade is $value";
|
echo "<br/>grade is $value";
|
||||||
$status = false;
|
$status = false;
|
||||||
import_cleanup($importcode);
|
import_cleanup($importcode);
|
||||||
notify(get_string('badgrade', 'grades'));
|
notify(get_string('badgrade', 'grades'));
|
||||||
break 3;
|
break 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
// case of an id, only maps id of a grade_item
|
// case of an id, only maps id of a grade_item
|
||||||
// this was idnumber
|
// this was idnumber
|
||||||
include_once($CFG->libdir.'/grade/grade_item.php');
|
include_once($CFG->libdir.'/grade/grade_item.php');
|
||||||
if (!$gradeitem = new grade_item(array('id'=>$map[$key]))) {
|
if (!$gradeitem = new grade_item(array('id'=>$map[$key]))) {
|
||||||
|
@ -233,20 +233,20 @@ if (($formdata = data_submitted()) && !empty($formdata->map)) {
|
||||||
notify(get_string('importfailed', 'grades'));
|
notify(get_string('importfailed', 'grades'));
|
||||||
break 3;
|
break 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if grade item is locked if so, abort
|
// check if grade item is locked if so, abort
|
||||||
if ($gradeitem->locked) {
|
if ($gradeitem->locked) {
|
||||||
$status = false;
|
$status = false;
|
||||||
import_cleanup($importcode);
|
import_cleanup($importcode);
|
||||||
notify(get_string('gradeitemlocked', 'grades'));
|
notify(get_string('gradeitemlocked', 'grades'));
|
||||||
break 3;
|
break 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($newgrade);
|
unset($newgrade);
|
||||||
$newgrade -> itemid = $gradeitem->id;
|
$newgrade -> itemid = $gradeitem->id;
|
||||||
$newgrade -> finalgrade = $value;
|
$newgrade -> finalgrade = $value;
|
||||||
$newgrades[] = $newgrade;
|
$newgrades[] = $newgrade;
|
||||||
} // otherwise, we ignore this column altogether
|
} // otherwise, we ignore this column altogether
|
||||||
// because user has chosen to ignore them (e.g. institution, address etc)
|
// because user has chosen to ignore them (e.g. institution, address etc)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -263,9 +263,9 @@ if (($formdata = data_submitted()) && !empty($formdata->map)) {
|
||||||
|
|
||||||
// insert results of this students into buffer
|
// insert results of this students into buffer
|
||||||
if (!empty($newgrades)) {
|
if (!empty($newgrades)) {
|
||||||
|
|
||||||
foreach ($newgrades as $newgrade) {
|
foreach ($newgrades as $newgrade) {
|
||||||
|
|
||||||
// check if grade_grades is locked and if so, abort
|
// check if grade_grades is locked and if so, abort
|
||||||
if ($grade_grades = new grade_grades(array('itemid'=>$newgrade->itemid, 'userid'=>$studentid))) {
|
if ($grade_grades = new grade_grades(array('itemid'=>$newgrade->itemid, 'userid'=>$studentid))) {
|
||||||
if ($grade_grades->locked) {
|
if ($grade_grades->locked) {
|
||||||
|
@ -305,21 +305,21 @@ if (($formdata = data_submitted()) && !empty($formdata->map)) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// at this stage if things are all ok, we commit the changes from temp table
|
/// at this stage if things are all ok, we commit the changes from temp table
|
||||||
if ($status) {
|
if ($status) {
|
||||||
grade_import_commit($course->id, $importcode);
|
grade_import_commit($course->id, $importcode);
|
||||||
}
|
}
|
||||||
// temporary file can go now
|
// temporary file can go now
|
||||||
unlink($filename);
|
unlink($filename);
|
||||||
} else {
|
} else {
|
||||||
error ('import file '.$filename.' not readable');
|
error ('import file '.$filename.' not readable');
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if ($formdata = $mform->get_data()) {
|
} else if ($formdata = $mform->get_data()) {
|
||||||
// else if file is just uploaded
|
// else if file is just uploaded
|
||||||
|
|
||||||
$filename = $mform->get_userfile_name();
|
$filename = $mform->get_userfile_name();
|
||||||
|
|
||||||
// Large files are likely to take their time and memory. Let PHP know
|
// Large files are likely to take their time and memory. Let PHP know
|
||||||
// that we'll take longer, and that the process should be recycled soon
|
// that we'll take longer, and that the process should be recycled soon
|
||||||
// to free up memory.
|
// to free up memory.
|
||||||
|
@ -331,9 +331,9 @@ if (($formdata = data_submitted()) && !empty($formdata->map)) {
|
||||||
|
|
||||||
$text = my_file_get_contents($filename);
|
$text = my_file_get_contents($filename);
|
||||||
// trim utf-8 bom
|
// trim utf-8 bom
|
||||||
$textlib = new textlib();
|
$textlib = new textlib();
|
||||||
/// normalize line endings and do the encoding conversion
|
/// normalize line endings and do the encoding conversion
|
||||||
$text = $textlib->convert($text, $formdata->encoding);
|
$text = $textlib->convert($text, $formdata->encoding);
|
||||||
$text = $textlib->trim_utf8_bom($text);
|
$text = $textlib->trim_utf8_bom($text);
|
||||||
// Fix mac/dos newlines
|
// Fix mac/dos newlines
|
||||||
$text = preg_replace('!\r\n?!',"\n",$text);
|
$text = preg_replace('!\r\n?!',"\n",$text);
|
||||||
|
@ -341,11 +341,11 @@ if (($formdata = data_submitted()) && !empty($formdata->map)) {
|
||||||
fwrite($fp,$text);
|
fwrite($fp,$text);
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
|
|
||||||
$fp = fopen($filename, "r");
|
$fp = fopen($filename, "r");
|
||||||
|
|
||||||
// --- get header (field names) ---
|
// --- get header (field names) ---
|
||||||
$header = split($csv_delimiter, clean_param(fgets($fp,1024), PARAM_RAW));
|
$header = split($csv_delimiter, clean_param(fgets($fp,1024), PARAM_RAW));
|
||||||
|
|
||||||
// print some preview
|
// print some preview
|
||||||
$numlines = 0; // 0 preview lines displayed
|
$numlines = 0; // 0 preview lines displayed
|
||||||
|
|
||||||
|
@ -354,11 +354,11 @@ if (($formdata = data_submitted()) && !empty($formdata->map)) {
|
||||||
echo '<tr>';
|
echo '<tr>';
|
||||||
foreach ($header as $h) {
|
foreach ($header as $h) {
|
||||||
$h = clean_param($h, PARAM_RAW);
|
$h = clean_param($h, PARAM_RAW);
|
||||||
echo '<th>'.$h.'</th>';
|
echo '<th>'.$h.'</th>';
|
||||||
}
|
}
|
||||||
echo '</tr>';
|
echo '</tr>';
|
||||||
while (!feof ($fp) && $numlines <= $formdata->previewrows) {
|
while (!feof ($fp) && $numlines <= $formdata->previewrows) {
|
||||||
$lines = split($csv_delimiter, fgets($fp,1024));
|
$lines = split($csv_delimiter, fgets($fp,1024));
|
||||||
echo '<tr>';
|
echo '<tr>';
|
||||||
foreach ($lines as $line) {
|
foreach ($lines as $line) {
|
||||||
echo '<td>'.$line.'</td>';;
|
echo '<td>'.$line.'</td>';;
|
||||||
|
@ -367,7 +367,7 @@ if (($formdata = data_submitted()) && !empty($formdata->map)) {
|
||||||
echo '</tr>';
|
echo '</tr>';
|
||||||
}
|
}
|
||||||
echo '</table>';
|
echo '</table>';
|
||||||
|
|
||||||
/// feeding gradeitems into the grade_import_mapping_form
|
/// feeding gradeitems into the grade_import_mapping_form
|
||||||
include_once($CFG->libdir.'/grade/grade_item.php');
|
include_once($CFG->libdir.'/grade/grade_item.php');
|
||||||
$gradeitems = array();
|
$gradeitems = array();
|
||||||
|
@ -376,11 +376,11 @@ if (($formdata = data_submitted()) && !empty($formdata->map)) {
|
||||||
foreach ($grade_items as $grade_item) {
|
foreach ($grade_items as $grade_item) {
|
||||||
// skip course type and category type
|
// skip course type and category type
|
||||||
if ($grade_item->itemtype == 'course' || $grade_item->itemtype == 'category') {
|
if ($grade_item->itemtype == 'course' || $grade_item->itemtype == 'category') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// this was idnumber
|
// this was idnumber
|
||||||
$gradeitems[$grade_item->id] = $grade_item->itemname;
|
$gradeitems[$grade_item->id] = $grade_item->itemname;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ class grade_import_form extends moodleform {
|
||||||
$encodings = $textlib->get_encodings();
|
$encodings = $textlib->get_encodings();
|
||||||
$mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings);
|
$mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings);
|
||||||
|
|
||||||
$options = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000);
|
$options = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000);
|
||||||
$mform->addElement('select', 'previewrows', 'Preview rows', $options); // TODO: localize
|
$mform->addElement('select', 'previewrows', 'Preview rows', $options); // TODO: localize
|
||||||
$mform->setType('previewrows', PARAM_INT);
|
$mform->setType('previewrows', PARAM_INT);
|
||||||
$this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
|
$this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
|
||||||
|
@ -34,7 +34,7 @@ class grade_import_form extends moodleform {
|
||||||
}
|
}
|
||||||
|
|
||||||
class grade_import_mapping_form extends moodleform {
|
class grade_import_mapping_form extends moodleform {
|
||||||
|
|
||||||
function definition () {
|
function definition () {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
$mform =& $this->_form;
|
$mform =& $this->_form;
|
||||||
|
@ -54,35 +54,35 @@ class grade_import_mapping_form extends moodleform {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$mform->addElement('select', 'mapfrom', get_string('mapfrom', 'grades'), $mapfromoptions);
|
$mform->addElement('select', 'mapfrom', get_string('mapfrom', 'grades'), $mapfromoptions);
|
||||||
//choose_from_menu($mapfromoptions, 'mapfrom');
|
//choose_from_menu($mapfromoptions, 'mapfrom');
|
||||||
|
|
||||||
$maptooptions = array('userid'=>'userid', 'username'=>'username', 'useridnumber'=>'useridnumber', 'useremail'=>'useremail', '0'=>'ignore');
|
$maptooptions = array('userid'=>'userid', 'username'=>'username', 'useridnumber'=>'useridnumber', 'useremail'=>'useremail', '0'=>'ignore');
|
||||||
//choose_from_menu($maptooptions, 'mapto');
|
//choose_from_menu($maptooptions, 'mapto');
|
||||||
$mform->addElement('select', 'mapto', get_string('mapto', 'grades'), $maptooptions);
|
$mform->addElement('select', 'mapto', get_string('mapto', 'grades'), $maptooptions);
|
||||||
|
|
||||||
$mform->addElement('header', 'general', get_string('mappings', 'grades'));
|
$mform->addElement('header', 'general', get_string('mappings', 'grades'));
|
||||||
|
|
||||||
// add a comment option
|
// add a comment option
|
||||||
|
|
||||||
if ($gradeitems = $this->_customdata['gradeitems']) {
|
if ($gradeitems = $this->_customdata['gradeitems']) {
|
||||||
$comments = array();
|
$comments = array();
|
||||||
foreach ($gradeitems as $itemid => $itemname) {
|
foreach ($gradeitems as $itemid => $itemname) {
|
||||||
$comments['feedback_'.$itemid] = 'comments for '.$itemname;
|
$comments['feedback_'.$itemid] = 'comments for '.$itemname;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
include_once($CFG->libdir.'/gradelib.php');
|
include_once($CFG->libdir.'/gradelib.php');
|
||||||
|
|
||||||
if ($header) {
|
if ($header) {
|
||||||
$i = 0; // index
|
$i = 0; // index
|
||||||
foreach ($header as $h) {
|
foreach ($header as $h) {
|
||||||
|
|
||||||
$h = trim($h);
|
$h = trim($h);
|
||||||
// this is what each header maps to
|
// this is what each header maps to
|
||||||
$mform->addElement('selectgroups',
|
$mform->addElement('selectgroups',
|
||||||
'mapping_'.$i, s($h),
|
'mapping_'.$i, s($h),
|
||||||
array('others'=>array('0'=>'ignore', 'new'=>'new gradeitem'),
|
array('others'=>array('0'=>'ignore', 'new'=>'new gradeitem'),
|
||||||
'gradeitems'=>$gradeitems,
|
'gradeitems'=>$gradeitems,
|
||||||
'comments'=>$comments));
|
'comments'=>$comments));
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ class grade_import_mapping_form extends moodleform {
|
||||||
//echo '<input name="filename" value='.$newfilename.' type="hidden" />';
|
//echo '<input name="filename" value='.$newfilename.' type="hidden" />';
|
||||||
$mform->addElement('hidden', 'filename', $newfilename);
|
$mform->addElement('hidden', 'filename', $newfilename);
|
||||||
$mform->setType('filename', PARAM_FILE);
|
$mform->setType('filename', PARAM_FILE);
|
||||||
$this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
|
$this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,53 +1,53 @@
|
||||||
<?php // $Id$
|
<?php // $Id$
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* given an import code, commits all entries in buffer tables
|
* given an import code, commits all entries in buffer tables
|
||||||
* (grade_import_value and grade_import_newitem)
|
* (grade_import_value and grade_import_newitem)
|
||||||
* If this function is called, we assume that all data collected
|
* If this function is called, we assume that all data collected
|
||||||
* up to this point is fine and we can go ahead and commit
|
* up to this point is fine and we can go ahead and commit
|
||||||
* @param int courseid - id of the course
|
* @param int courseid - id of the course
|
||||||
* @param string importcode - import batch identifier
|
* @param string importcode - import batch identifier
|
||||||
*/
|
*/
|
||||||
function grade_import_commit($courseid, $importcode) {
|
function grade_import_commit($courseid, $importcode) {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
|
||||||
include_once($CFG->libdir.'/gradelib.php');
|
include_once($CFG->libdir.'/gradelib.php');
|
||||||
include_once($CFG->libdir.'/grade/grade_item.php');
|
include_once($CFG->libdir.'/grade/grade_item.php');
|
||||||
$commitstart = time(); // start time in case we need to roll back
|
$commitstart = time(); // start time in case we need to roll back
|
||||||
$newitemids = array(); // array to hold new grade_item ids from grade_import_newitem table, mapping array
|
$newitemids = array(); // array to hold new grade_item ids from grade_import_newitem table, mapping array
|
||||||
|
|
||||||
/// first select distinct new grade_items with this batch
|
/// first select distinct new grade_items with this batch
|
||||||
|
|
||||||
if ($newitems = get_records_sql("SELECT *
|
if ($newitems = get_records_sql("SELECT *
|
||||||
FROM {$CFG->prefix}grade_import_newitem
|
FROM {$CFG->prefix}grade_import_newitem
|
||||||
WHERE import_code = $importcode")) {
|
WHERE import_code = $importcode")) {
|
||||||
|
|
||||||
// instances of the new grade_items created, cached
|
// instances of the new grade_items created, cached
|
||||||
// in case grade_update fails, so that we can remove them
|
// in case grade_update fails, so that we can remove them
|
||||||
$instances = array();
|
$instances = array();
|
||||||
foreach ($newitems as $newitem) {
|
foreach ($newitems as $newitem) {
|
||||||
// get all grades with this item
|
// get all grades with this item
|
||||||
|
|
||||||
if ($grades = get_records('grade_import_values', 'newgradeitem', $newitem->id)) {
|
if ($grades = get_records('grade_import_values', 'newgradeitem', $newitem->id)) {
|
||||||
|
|
||||||
// make the grardes array for update_grade
|
// make the grardes array for update_grade
|
||||||
|
|
||||||
// find the max instance number of 'manual' grade item
|
// find the max instance number of 'manual' grade item
|
||||||
// and increment that number by 1 by hand
|
// and increment that number by 1 by hand
|
||||||
// I can not find other ways to make 'manual' type work,
|
// I can not find other ways to make 'manual' type work,
|
||||||
// unless we have a 'new' flag for grade_update to let it
|
// unless we have a 'new' flag for grade_update to let it
|
||||||
// know that this is a new grade_item, and let grade_item
|
// know that this is a new grade_item, and let grade_item
|
||||||
// handle the instance id in the case of a 'manual' import?
|
// handle the instance id in the case of a 'manual' import?
|
||||||
if ($lastimport = get_record_sql("SELECT *
|
if ($lastimport = get_record_sql("SELECT *
|
||||||
FROM {$CFG->prefix}grade_items
|
FROM {$CFG->prefix}grade_items
|
||||||
WHERE courseid = $courseid
|
WHERE courseid = $courseid
|
||||||
AND itemtype = 'manual'
|
AND itemtype = 'manual'
|
||||||
ORDER BY iteminstance DESC", true)) {
|
ORDER BY iteminstance DESC", true)) {
|
||||||
$instance = $lastimport->iteminstance + 1;
|
$instance = $lastimport->iteminstance + 1;
|
||||||
} else {
|
} else {
|
||||||
$instance = 1;
|
$instance = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$instances[] = $instance;
|
$instances[] = $instance;
|
||||||
// if fails, deletes all the created grade_items and grades
|
// if fails, deletes all the created grade_items and grades
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ function grade_import_commit($courseid, $importcode) {
|
||||||
|
|
||||||
// insert each individual grade to this new grade item
|
// insert each individual grade to this new grade item
|
||||||
$failed = 0;
|
$failed = 0;
|
||||||
foreach ($grades as $grade) {
|
foreach ($grades as $grade) {
|
||||||
if (!$gradeitem->update_final_grade($grade->userid, $grade->finalgrade, NULL, NULL, $grade->feedback)) {
|
if (!$gradeitem->update_final_grade($grade->userid, $grade->finalgrade, NULL, NULL, $grade->feedback)) {
|
||||||
$failed = 1;
|
$failed = 1;
|
||||||
break;
|
break;
|
||||||
|
@ -65,7 +65,7 @@ function grade_import_commit($courseid, $importcode) {
|
||||||
}
|
}
|
||||||
if ($failed) {
|
if ($failed) {
|
||||||
foreach ($instances as $instance) {
|
foreach ($instances as $instance) {
|
||||||
$gradeitem = new grade_item(array('courseid'=>$courseid, 'itemtype'=>'manual', 'iteminstance'=>$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
|
// 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?
|
// which I think should be deleted in this case, can I use sql directly here?
|
||||||
$gradeitem->delete();
|
$gradeitem->delete();
|
||||||
|
@ -79,15 +79,15 @@ function grade_import_commit($courseid, $importcode) {
|
||||||
|
|
||||||
/// then find all existing items
|
/// then find all existing items
|
||||||
|
|
||||||
if ($gradeitems = get_records_sql("SELECT DISTINCT (itemid)
|
if ($gradeitems = get_records_sql("SELECT DISTINCT (itemid)
|
||||||
FROM {$CFG->prefix}grade_import_values
|
FROM {$CFG->prefix}grade_import_values
|
||||||
WHERE import_code = $importcode
|
WHERE import_code = $importcode
|
||||||
AND itemid > 0")) {
|
AND itemid > 0")) {
|
||||||
|
|
||||||
$modifieditems = array();
|
$modifieditems = array();
|
||||||
|
|
||||||
foreach ($gradeitems as $itemid=>$iteminfo) {
|
foreach ($gradeitems as $itemid=>$iteminfo) {
|
||||||
|
|
||||||
if (!$gradeitem = new grade_item(array('id'=>$itemid))) {
|
if (!$gradeitem = new grade_item(array('id'=>$itemid))) {
|
||||||
// not supposed to happen, but just in case
|
// not supposed to happen, but just in case
|
||||||
import_cleanup($importcode);
|
import_cleanup($importcode);
|
||||||
|
@ -107,7 +107,7 @@ function grade_import_commit($courseid, $importcode) {
|
||||||
$modifieditems[] = $itemid;
|
$modifieditems[] = $itemid;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($failed)) {
|
if (!empty($failed)) {
|
||||||
import_cleanup($importcode);
|
import_cleanup($importcode);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -47,7 +47,7 @@ if ( $formdata = $mform->get_data()) {
|
||||||
// trim utf-8 bom
|
// trim utf-8 bom
|
||||||
$textlib = new textlib();
|
$textlib = new textlib();
|
||||||
// converts to propert unicode
|
// converts to propert unicode
|
||||||
$text = $textlib->convert($text, $formdata->encoding);
|
$text = $textlib->convert($text, $formdata->encoding);
|
||||||
$text = $textlib->trim_utf8_bom($text);
|
$text = $textlib->trim_utf8_bom($text);
|
||||||
// Fix mac/dos newlines
|
// Fix mac/dos newlines
|
||||||
$text = preg_replace('!\r\n?!',"\n",$text);
|
$text = preg_replace('!\r\n?!',"\n",$text);
|
||||||
|
@ -55,19 +55,19 @@ if ( $formdata = $mform->get_data()) {
|
||||||
// text is the text, we should xmlize it
|
// text is the text, we should xmlize it
|
||||||
include_once($CFG->dirroot.'/lib/xmlize.php');
|
include_once($CFG->dirroot.'/lib/xmlize.php');
|
||||||
$content = xmlize($text);
|
$content = xmlize($text);
|
||||||
|
|
||||||
if ($results = $content['results']['#']['result']) {
|
if ($results = $content['results']['#']['result']) {
|
||||||
|
|
||||||
// import batch identifier timestamp
|
// import batch identifier timestamp
|
||||||
$importcode = time();
|
$importcode = time();
|
||||||
$status = true;
|
$status = true;
|
||||||
|
|
||||||
$numlines = 0;
|
$numlines = 0;
|
||||||
|
|
||||||
// print some previews
|
// print some previews
|
||||||
print_heading(get_string('importpreview', 'grades'));
|
print_heading(get_string('importpreview', 'grades'));
|
||||||
|
|
||||||
echo '<table cellpadding="5">';
|
echo '<table cellpadding="5">';
|
||||||
foreach ($results as $i => $result) {
|
foreach ($results as $i => $result) {
|
||||||
if ($numlines < $formdata->previewrows && isset($results[$i+1])) {
|
if ($numlines < $formdata->previewrows && isset($results[$i+1])) {
|
||||||
echo '<tr>';
|
echo '<tr>';
|
||||||
|
@ -88,14 +88,14 @@ if ( $formdata = $mform->get_data()) {
|
||||||
$status = false;
|
$status = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// grade item locked, abort
|
// grade item locked, abort
|
||||||
if ($gradeitem->locked) {
|
if ($gradeitem->locked) {
|
||||||
$status = false;
|
$status = false;
|
||||||
notify(get_string('gradeitemlocked', 'grades'));
|
notify(get_string('gradeitemlocked', 'grades'));
|
||||||
break 3;
|
break 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if grade_grades is locked and if so, abort
|
// check if grade_grades is locked and if so, abort
|
||||||
if ($grade_grades = new grade_grades(array('itemid'=>$gradeitem->id, 'userid'=>$result['#']['student'][0]['#']))) {
|
if ($grade_grades = new grade_grades(array('itemid'=>$gradeitem->id, 'userid'=>$result['#']['student'][0]['#']))) {
|
||||||
if ($grade_grades->locked) {
|
if ($grade_grades->locked) {
|
||||||
|
@ -114,11 +114,11 @@ if ( $formdata = $mform->get_data()) {
|
||||||
$newgrades[] = $newgrade;
|
$newgrades[] = $newgrade;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// loop through info collected so far
|
// loop through info collected so far
|
||||||
if ($status && !empty($newgrades)) {
|
if ($status && !empty($newgrades)) {
|
||||||
foreach ($newgrades as $newgrade) {
|
foreach ($newgrades as $newgrade) {
|
||||||
|
|
||||||
// check if user exist
|
// check if user exist
|
||||||
if (!$user = get_record('user', 'id', $newgrade->userid)) {
|
if (!$user = get_record('user', 'id', $newgrade->userid)) {
|
||||||
// no user found, abort
|
// no user found, abort
|
||||||
|
@ -127,8 +127,8 @@ if ( $formdata = $mform->get_data()) {
|
||||||
notify(get_string('baduserid', 'grades'));
|
notify(get_string('baduserid', 'grades'));
|
||||||
notify(get_string('importfailed', 'grades'));
|
notify(get_string('importfailed', 'grades'));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check grade value is a numeric grade
|
// check grade value is a numeric grade
|
||||||
if (!is_numeric($newgrade->rawgrade)) {
|
if (!is_numeric($newgrade->rawgrade)) {
|
||||||
$status = false;
|
$status = false;
|
||||||
|
@ -153,11 +153,11 @@ if ( $formdata = $mform->get_data()) {
|
||||||
if ($status) {
|
if ($status) {
|
||||||
/// comit the code if we are up this far
|
/// comit the code if we are up this far
|
||||||
grade_import_commit($id, $importcode);
|
grade_import_commit($id, $importcode);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// no results section found in xml,
|
// no results section found in xml,
|
||||||
// assuming bad format, abort import
|
// assuming bad format, abort import
|
||||||
notify('badxmlformat', 'grade');
|
notify('badxmlformat', 'grade');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// display the standard upload file form
|
// display the standard upload file form
|
||||||
|
|
|
@ -482,7 +482,7 @@ class grade_category extends grade_object {
|
||||||
$weightsum = 0;
|
$weightsum = 0;
|
||||||
$sum = 0;
|
$sum = 0;
|
||||||
foreach($items as $key=>$value) {
|
foreach($items as $key=>$value) {
|
||||||
$grade_value = isset($grade_values[$key]) ? $grade_values[$key] : 0;
|
$grade_value = isset($grade_values[$key]) ? $grade_values[$key] : 0;
|
||||||
if ($items[$key]->aggregationcoef <= 0) {
|
if ($items[$key]->aggregationcoef <= 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -513,11 +513,11 @@ class grade_category extends grade_object {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GRADE_AGGREGATE_EXTRACREDIT_MEAN_ALL: // special average
|
case GRADE_AGGREGATE_EXTRACREDIT_MEAN_ALL: // special average
|
||||||
$num = 0;
|
$num = 0;
|
||||||
$sum = 0;
|
$sum = 0;
|
||||||
foreach($items as $key=>$value) {
|
foreach($items as $key=>$value) {
|
||||||
$grade_value = isset($grade_values[$key]) ? $grade_values[$key] : 0;
|
$grade_value = isset($grade_values[$key]) ? $grade_values[$key] : 0;
|
||||||
if ($items[$key]->aggregationcoef == 0) {
|
if ($items[$key]->aggregationcoef == 0) {
|
||||||
$num += 1;
|
$num += 1;
|
||||||
$sum += $grade_value;
|
$sum += $grade_value;
|
||||||
|
@ -532,7 +532,7 @@ class grade_category extends grade_object {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GRADE_AGGREGATE_EXTRACREDIT_MEAN_GRADED: // special average
|
case GRADE_AGGREGATE_EXTRACREDIT_MEAN_GRADED: // special average
|
||||||
$num = 0;
|
$num = 0;
|
||||||
$sum = 0;
|
$sum = 0;
|
||||||
foreach($grade_values as $key=>$grade_value) {
|
foreach($grade_values as $key=>$grade_value) {
|
||||||
|
@ -617,7 +617,7 @@ class grade_category extends grade_object {
|
||||||
or $this->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN_GRADED
|
or $this->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN_GRADED
|
||||||
or $this->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN_ALL
|
or $this->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN_ALL
|
||||||
or $this->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN_GRADED);
|
or $this->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN_GRADED);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -427,7 +427,7 @@ class grade_grades extends grade_object {
|
||||||
*/
|
*/
|
||||||
function standardise_score($rawgrade, $source_min, $source_max, $target_min, $target_max) {
|
function standardise_score($rawgrade, $source_min, $source_max, $target_min, $target_max) {
|
||||||
if (is_null($rawgrade)) {
|
if (is_null($rawgrade)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$factor = ($rawgrade - $source_min) / ($source_max - $source_min);
|
$factor = ($rawgrade - $source_min) / ($source_max - $source_min);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue