mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 12:32:08 +02:00
MDL-11082 big refactoring in grade export - export tracking and grade formatting still not finished
This commit is contained in:
parent
76ca1ff134
commit
caffc55a84
@ -9,7 +9,7 @@ $temp->add(new admin_setting_special_gradeexport());
|
||||
// enable outcomes checkbox
|
||||
$temp->add(new admin_setting_configcheckbox('enableoutcomes', get_string('enableoutcomes', 'grades'), get_string('configenableoutcomes', 'grades'), 0, PARAM_INT));
|
||||
// enable publishing in exports/imports
|
||||
$temp->add(new admin_setting_configcheckbox('enablepublishing', get_string('enablepublishing', 'userkey'), get_string('configenablepublishing', 'userkey'), 0, PARAM_INT));
|
||||
$temp->add(new admin_setting_configcheckbox('gradepublishing', get_string('gradepublishing', 'grades'), get_string('configgradepublishing', 'grades'), 0, PARAM_INT));
|
||||
$ADMIN->add('grades', $temp);
|
||||
|
||||
/// Scales and outcomes
|
||||
|
@ -19,6 +19,9 @@ class grade_export_form extends moodleform {
|
||||
$mform->setHelpButton('export_letters', array(false, get_string('exportletters', 'grades'),
|
||||
false, true, false, get_string("exportlettershelp", 'grades')));
|
||||
|
||||
$mform->addElement('advcheckbox', 'export_feedback', get_string('exportfeedback', 'grades'));
|
||||
$mform->setDefault('export_feedback', 0);
|
||||
|
||||
$options = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000);
|
||||
$mform->addElement('select', 'previewrows', 'Preview rows', $options); // TODO: localize
|
||||
|
||||
@ -30,7 +33,7 @@ class grade_export_form extends moodleform {
|
||||
$mform->setDefault('separator', 'comma');
|
||||
}
|
||||
|
||||
if (!empty($features['publishing'])) {
|
||||
if (!empty($CFG->gradepublishing) and !empty($features['publishing'])) {
|
||||
$mform->addElement('header', 'publishing', get_string('publishing', 'grades'));
|
||||
$options = array(get_string('nopublish', 'grades'), get_string('createnewkey', 'userkey'));
|
||||
if ($keys = get_records_select('user_private_key', "script='grade/export' AND instance={$COURSE->id} AND userid={$USER->id}")) {
|
||||
@ -43,11 +46,11 @@ class grade_export_form extends moodleform {
|
||||
false, true, false, get_string("userkeyhelp", 'grades')));
|
||||
$mform->addElement('static', 'keymanagerlink', get_string('keymanager', 'userkey'),
|
||||
'<a href="'.$CFG->wwwroot.'/grade/export/keymanager.php?id='.$COURSE->id.'">'.get_string('keymanager', 'userkey').'</a>');
|
||||
|
||||
|
||||
$mform->addElement('text', 'iprestriction', get_string('keyiprestriction', 'userkey'), array('size'=>80));
|
||||
$mform->setHelpButton('iprestriction', array(false, get_string('keyiprestriction', 'userkey'),
|
||||
false, true, false, get_string("keyiprestrictionhelp", 'userkey')));
|
||||
|
||||
|
||||
$mform->addElement('date_time_selector', 'validuntil', get_string('keyvaliduntil', 'userkey'), array('optional'=>true));
|
||||
$mform->setHelpButton('validuntil', array(false, get_string('keyvaliduntil', 'userkey'),
|
||||
false, true, false, get_string("keyvaliduntilhelp", 'userkey')));
|
||||
@ -55,14 +58,14 @@ class grade_export_form extends moodleform {
|
||||
$mform->disabledIf('validuntil', 'key', get_string('createnewkey', 'userkey'));
|
||||
}
|
||||
|
||||
$mform->addElement('header', 'gradeitems', get_string('gradeitemsinc', 'grades')); // TODO: localize
|
||||
$mform->addElement('header', 'gradeitems', get_string('gradeitemsinc', 'grades'));
|
||||
|
||||
if ($grade_items = grade_item::fetch_all(array('courseid'=>$COURSE->id))) {
|
||||
foreach ($grade_items as $grade_item) {
|
||||
if (!empty($features['idnumberrequired']) and empty($grade_item->idnumber)) {
|
||||
$mform->addElement('advcheckbox', 'itemids['.$grade_item->id.']', $grade_item->get_name(), get_string('noidnumber'));
|
||||
$mform->hardFreeze('itemids['.$grade_item->id.']');
|
||||
|
||||
|
||||
} else {
|
||||
$mform->addElement('advcheckbox', 'itemids['.$grade_item->id.']', $grade_item->get_name());
|
||||
$mform->setDefault('itemids['.$grade_item->id.']', 1);
|
||||
|
@ -32,187 +32,194 @@ require_once($CFG->dirroot.'/grade/export/grade_export_form.php');
|
||||
*/
|
||||
class grade_export {
|
||||
|
||||
var $id; // course id
|
||||
var $grade_items; // array of grade_items
|
||||
var $groupid;
|
||||
var $grades = array(); // Collect all grades in this array
|
||||
var $comments = array(); // Collect all comments for each grade
|
||||
var $columns = array(); // Accumulate column names in this array.
|
||||
var $columnidnumbers = array(); // Collect all gradeitem id numbers
|
||||
var $students = array();
|
||||
var $course; // course
|
||||
var $userkey; // Optional MD5 string used to publish this export data via a URL
|
||||
var $export_letters;
|
||||
var $itemidsurl; // A string of itemids to add to the URL for the export
|
||||
var $plugin; // plgin name - must be filled in subclasses!
|
||||
|
||||
// common strings
|
||||
var $strgrades;
|
||||
var $strgrade;
|
||||
var $grade_items; // list of all course grade items
|
||||
var $groupid; // groupid, 0 means all groups
|
||||
var $course; // course object
|
||||
var $columns; // array of grade_items selected for export
|
||||
|
||||
var $previewrows; // number of rows in preview
|
||||
var $export_letters; // export letters - TODO: finish implementation
|
||||
var $export_feedback; // export feedback
|
||||
var $userkey; // export using private user key
|
||||
|
||||
var $letters; // internal
|
||||
var $report; // internal
|
||||
|
||||
/**
|
||||
* Constructor should set up all the private variables ready to be pulled
|
||||
* @param int $courseid course id
|
||||
* @param array $itemids array of grade item ids, empty means all
|
||||
* @param stdClass $formdata Optional object of formdata.
|
||||
* @param object $course
|
||||
* @param int $groupid id of selected group, 0 means all
|
||||
* @param string $itemlist comma separated list of item ids, empty means all
|
||||
* @param boolean $export_feedback
|
||||
* @param boolean $export_letters
|
||||
* @note Exporting as letters will lead to data loss if that exported set it re-imported.
|
||||
*/
|
||||
function grade_export($courseid, $itemids=null, $formdata=null) {
|
||||
global $CFG, $USER, $COURSE;
|
||||
function grade_export($course, $groupid=0, $itemlist='', $export_feedback=false, $export_letters=false) {
|
||||
$this->course = $course;
|
||||
$this->groupid = $groupid;
|
||||
$this->grade_items = grade_item::fetch_all(array('courseid'=>$this->course->id));
|
||||
|
||||
$this->export_letters = false;
|
||||
if (isset($formdata->export_letters)) {
|
||||
$this->export_letters = $formdata->export_letters;
|
||||
$this->columns = array();
|
||||
if (!empty($itemlist)) {
|
||||
$itemids = explode(',', $itemlist);
|
||||
// remove items that are not requested
|
||||
foreach ($itemids as $itemid) {
|
||||
if (array_key_exists($itemid, $this->grade_items)) {
|
||||
$this->columns[$itemid] =& $this->grade_items[$itemid];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($this->grade_items as $itemid=>$unused) {
|
||||
$this->columns[$itemid] =& $this->grade_items[$itemid];
|
||||
}
|
||||
}
|
||||
|
||||
$this->export_letters = $export_letters;
|
||||
$this->export_feedback = $export_feedback;
|
||||
$this->userkey = '';
|
||||
$this->previewrows = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init object based using data from form
|
||||
* @param object $formdata
|
||||
*/
|
||||
function process_form($formdata) {
|
||||
global $USER;
|
||||
|
||||
$this->columns = array();
|
||||
if (!empty($formdata->itemids)) {
|
||||
foreach ($formdata->itemids as $itemid=>$selected) {
|
||||
if ($selected and array_key_exists($itemid, $this->grade_items)) {
|
||||
$this->columns[$itemid] =& $this->grade_items[$itemid];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($this->grade_items as $itemid=>$unused) {
|
||||
$this->columns[$itemid] =& $this->grade_items[$itemid];
|
||||
}
|
||||
}
|
||||
|
||||
$this->userkey = false;
|
||||
if (isset($formdata->key)) {
|
||||
if ($formdata->key == 1 && isset($formdata->iprestriction) && isset($formdata->validuntil)) { // Create a new key
|
||||
$formdata->key = create_user_key('grade/export', $USER->id, $COURSE->id, $formdata->iprestriction, $formdata->validuntil);
|
||||
if ($formdata->key == 1 && isset($formdata->iprestriction) && isset($formdata->validuntil)) {
|
||||
// Create a new key
|
||||
$formdata->key = create_user_key('grade/export', $USER->id, $this->course->id, $formdata->iprestriction, $formdata->validuntil);
|
||||
}
|
||||
$this->userkey = $formdata->key;
|
||||
}
|
||||
|
||||
$this->strgrades = get_string("grades");
|
||||
$this->strgrade = get_string("grade");
|
||||
|
||||
if (!$course = get_record("course", "id", $courseid)) {
|
||||
error("Course ID was incorrect");
|
||||
}
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
require_capability('moodle/grade:export', $context);
|
||||
|
||||
$this->id = $course->id;
|
||||
$this->course = $course;
|
||||
|
||||
// fetch all grade items
|
||||
if (empty($itemids)) {
|
||||
$this->grade_items = grade_item::fetch_all(array('courseid'=>$this->id));
|
||||
} else {
|
||||
$this->grade_items = array();
|
||||
foreach ($itemids as $iid) {
|
||||
if ($grade_item = grade_item::fetch(array('id'=>(int)$iid, 'courseid'=>$this->id))) {
|
||||
$this->grade_items[$grade_item->id] = $grade_item;
|
||||
}
|
||||
}
|
||||
if (isset($formdata->export_letters)) {
|
||||
$this->export_letters = $formdata->export_letters;
|
||||
}
|
||||
|
||||
// init colums
|
||||
foreach ($this->grade_items as $grade_item) {
|
||||
if ($grade_item->itemtype == 'mod') {
|
||||
$this->columns[$grade_item->id] = get_string('modulename', $grade_item->itemmodule).': '.$grade_item->get_name();
|
||||
if (isset($formdata->export_feedback)) {
|
||||
$this->export_feedback = $formdata->export_feedback;
|
||||
}
|
||||
|
||||
if (isset($formdata->previewrows)) {
|
||||
$this->previewrows = $formdata->previewrows;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Update exported field in grade_grades table
|
||||
* @return boolean
|
||||
*/
|
||||
function track_exports() {
|
||||
global $CFG;
|
||||
|
||||
/// Whether this plugin is entitled to update export time
|
||||
if ($expplugins = explode(",", $CFG->gradeexport)) {
|
||||
if (in_array($this->plugin, $expplugins)) {
|
||||
return true;
|
||||
} else {
|
||||
$this->columns[$grade_item->id] = $grade_item->get_name();
|
||||
}
|
||||
$this->columnidnumbers[$grade_item->id] = $grade_item->idnumber; // this might be needed for some export plugins
|
||||
}
|
||||
|
||||
/// Check to see if groups are being used in this course
|
||||
if ($groupmode = groupmode($course)) { // Groups are being used
|
||||
|
||||
if (isset($_GET['group'])) {
|
||||
$changegroup = $_GET['group']; /// 0 or higher
|
||||
} else {
|
||||
$changegroup = -1; /// This means no group change was specified
|
||||
}
|
||||
|
||||
$currentgroup = get_and_set_current_group($course, $groupmode, $changegroup);
|
||||
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$currentgroup = false;
|
||||
}
|
||||
|
||||
$this->groupid = $currentgroup;
|
||||
|
||||
if ($currentgroup) {
|
||||
$this->students = get_group_students($currentgroup, "u.lastname ASC");
|
||||
} else {
|
||||
$this->students = get_role_users(@implode(',', $CFG->gradebookroles), $context);
|
||||
}
|
||||
|
||||
if (!empty($this->students)) {
|
||||
foreach ($this->students as $student) {
|
||||
$this->grades[$student->id] = array(); // Collect all grades in this array
|
||||
$this->comments[$student->id] = array(); // Collect all comments in tihs array
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($formdata->itemids)) {
|
||||
// Build itemidsurl for links
|
||||
$itemids = array();
|
||||
if ($formdata->itemids) {
|
||||
foreach ($formdata->itemids as $itemid=>$selected) {
|
||||
if ($selected) {
|
||||
$itemids[] = $itemid;
|
||||
}
|
||||
}
|
||||
$this->itemidsurl = implode(",", $itemids);
|
||||
} else {
|
||||
//error?
|
||||
$this->itemidsurl = '';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function load_grades() {
|
||||
/**
|
||||
* internal
|
||||
*/
|
||||
function _init_letters() {
|
||||
global $CFG;
|
||||
|
||||
// first make sure we have all final grades
|
||||
// TODO: check that no grade_item has needsupdate set
|
||||
grade_regrade_final_grades($this->id);
|
||||
|
||||
if ($this->export_letters) {
|
||||
require_once($CFG->dirroot . '/grade/report/lib.php');
|
||||
$report = new grade_report($this->id, null, null);
|
||||
$letters = $report->get_grade_letters();
|
||||
} else {
|
||||
$letters = null;
|
||||
}
|
||||
|
||||
if ($this->grade_items) {
|
||||
foreach ($this->grade_items as $gradeitem) {
|
||||
// load as an array of grade_final objects
|
||||
if ($itemgrades = $gradeitem->get_final() and !empty($this->students)) {
|
||||
foreach ($this->students as $student) {
|
||||
$finalgrade = null;
|
||||
$feedback = '';
|
||||
if (array_key_exists($student->id, $itemgrades)) {
|
||||
$finalgrade = $itemgrades[$student->id]->finalgrade;
|
||||
$grade = new grade_grade($itemgrades[$student->id], false);
|
||||
if ($grade_text = $grade->load_text()) {
|
||||
$feedback = format_text($grade_text->feedback, $grade_text->feedbackformat);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->export_letters) {
|
||||
$grade_item_displaytype = $report->get_pref('gradedisplaytype', $gradeitem->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) {
|
||||
$finalgrade = grade_grade::get_letter($letters, $finalgrade, $gradeitem->grademin, $gradeitem->grademax);
|
||||
}
|
||||
}
|
||||
|
||||
$this->grades[$student->id][$gradeitem->id] = $finalgrade;
|
||||
$this->comments[$student->id][$gradeitem->id] = $feedback;
|
||||
}
|
||||
}
|
||||
if (!isset($this->letters)) {
|
||||
if ($this->export_letters) {
|
||||
require_once($CFG->dirroot . '/grade/report/lib.php');
|
||||
$this->report = new grade_report($this->course->id, null, null);
|
||||
$this->letters = $this->report->get_grade_letters();
|
||||
} else {
|
||||
$this->letters = false; // false prevents another fetching of grade letters
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* To be implemented by child class
|
||||
* TODO finish PHPdocs
|
||||
* Returns string representation of final grade
|
||||
* @param $object $grade instance of grade_grade class
|
||||
* @return string
|
||||
*/
|
||||
function format_grade($grade) {
|
||||
$this->_init_letters();
|
||||
|
||||
//TODO: rewrite the letters handling code - this is slow
|
||||
if ($this->letters) {
|
||||
$grade_item = $this->grade_items[$grade->itemid];
|
||||
$grade_item_displaytype = $this->report->get_pref('gradedisplaytype', $grade_item->id);
|
||||
|
||||
if ($grade_item_displaytype == GRADE_REPORT_GRADE_DISPLAY_TYPE_LETTER) {
|
||||
return grade_grade::get_letter($this->letters, $grade->finalgrade, $grade_item->grademin, $grade_item->grademax);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: format it somehow - scale/letter/number/etc.
|
||||
return $grade->finalgrade;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of column in export
|
||||
* @param object $grade_item
|
||||
* @param boolena $feedback feedback colum
|
||||
* &return string
|
||||
*/
|
||||
function format_column_name($grade_item, $feedback=false) {
|
||||
if ($grade_item->itemtype == 'mod') {
|
||||
$name = get_string('modulename', $grade_item->itemmodule).': '.$grade_item->get_name();
|
||||
} else {
|
||||
$name = $grade_item->get_name();
|
||||
}
|
||||
|
||||
if ($feedback) {
|
||||
$name .= ' ('.get_string('feedback').')';
|
||||
}
|
||||
|
||||
return strip_tags($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns formatted grade feedback
|
||||
* @param object $feedback object with properties feedback and feedbackformat
|
||||
* @return string
|
||||
*/
|
||||
function format_feedback($feedback) {
|
||||
return strip_tags(format_text($feedback->feedback, $feedback->feedbackformat));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implemented by child class
|
||||
*/
|
||||
function print_grades() { }
|
||||
|
||||
/**
|
||||
* Displays all the grades on screen as a feedback mechanism
|
||||
* TODO finish PHPdoc
|
||||
* Prints preview of exported grades on screen as a feedback mechanism
|
||||
*/
|
||||
function display_grades($feedback=false, $rows=10) {
|
||||
|
||||
$this->load_grades();
|
||||
|
||||
function display_preview() {
|
||||
echo '<table>';
|
||||
echo '<tr>';
|
||||
echo '<th>'.get_string("firstname")."</th>".
|
||||
@ -221,58 +228,83 @@ class grade_export {
|
||||
'<th>'.get_string("institution")."</th>".
|
||||
'<th>'.get_string("department")."</th>".
|
||||
'<th>'.get_string("email")."</th>";
|
||||
foreach ($this->columns as $column) {
|
||||
$column = strip_tags($column);
|
||||
echo "<th>$column</th>";
|
||||
foreach ($this->columns as $grade_item) {
|
||||
echo '<th>'.$this->format_column_name($grade_item).'</th>';
|
||||
|
||||
/// add a column_feedback column
|
||||
if ($feedback) {
|
||||
echo "<th>{$column}_feedback</th>";
|
||||
if ($this->export_feedback) {
|
||||
echo '<th>'.$this->format_column_name($grade_item, true).'</th>';
|
||||
}
|
||||
}
|
||||
echo '</tr>';
|
||||
/// Print all the lines of data.
|
||||
|
||||
$i = 0;
|
||||
foreach ($this->grades as $studentid => $studentgrades) {
|
||||
|
||||
$gui = new graded_users_iterator($this->course, $this->columns, $this->groupid);
|
||||
$gui->init();
|
||||
while ($userdata = $gui->next_user()) {
|
||||
// number of preview rows
|
||||
if ($i++ == $rows) {
|
||||
if ($this->previewrows and $this->previewrows < ++$i) {
|
||||
break;
|
||||
}
|
||||
$user = $userdata->user;
|
||||
|
||||
echo '<tr>';
|
||||
$student = $this->students[$studentid];
|
||||
echo "<td>$user->firstname</td><td>$user->lastname</td><td>$user->idnumber</td><td>$user->institution</td><td>$user->department</td><td>$user->email</td>";
|
||||
foreach ($this->columns as $itemid=>$unused) {
|
||||
$gradetxt = $this->format_grade($userdata->grades[$itemid]);
|
||||
echo "<td>$gradetxt</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 $itemid=>$grade) {
|
||||
$grade = strip_tags($grade);
|
||||
echo "<td>$grade</td>";
|
||||
|
||||
if ($feedback) {
|
||||
echo '<td>'.$this->comments[$studentid][$itemid].'</td>';
|
||||
if ($this->export_feedback) {
|
||||
echo '<td>'.$this->format_feedback($userdata->feedbacks[$itemid]).'</td>';
|
||||
}
|
||||
}
|
||||
echo "</tr>";
|
||||
}
|
||||
echo '</table>';
|
||||
$gui->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Either prints a "continue" box, which will redirect the user to the download page, or prints the URL for the published data.
|
||||
* Returns array of parameters used by dump.php and export.php.
|
||||
* @return array
|
||||
*/
|
||||
function get_export_params() {
|
||||
$itemids = array_keys($this->columns);
|
||||
|
||||
$params = array('id' =>$this->course->id,
|
||||
'groupid' =>$this->groupid,
|
||||
'itemids' =>implode(',', $itemids),
|
||||
'export_letters' =>$this->export_letters,
|
||||
'export_feedback'=>$this->export_feedback);
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Either prints a "Export" box, which will redirect the user to the download page,
|
||||
* or prints the URL for the published data.
|
||||
* @note exit() at the end of the method
|
||||
* @param string $plugin Required: name of the plugin calling this method. Used for building the URL.
|
||||
* @return void
|
||||
*/
|
||||
function print_continue($plugin) {
|
||||
function print_continue() {
|
||||
global $CFG;
|
||||
|
||||
// this redirect should trigger a download prompt
|
||||
$params = $this->get_export_params();
|
||||
|
||||
// this button should trigger a download prompt
|
||||
if (!$this->userkey) {
|
||||
print_continue('export.php?id='.$this->id.'&itemids='.$this->itemidsurl.'&export_letters='.$this->export_letters);
|
||||
print_single_button($CFG->wwwroot.'/grade/export/'.$this->plugin.'/export.php', $params, get_string('export', 'grades'));
|
||||
|
||||
} else {
|
||||
$link = $CFG->wwwroot.'/grade/export/'.$plugin.'/dump.php?id='.$this->id.'&itemids='
|
||||
. $this->itemidsurl.'&export_letters='.$this->export_letters.'&key='.$this->userkey;
|
||||
$paramstr = '';
|
||||
$sep = '?';
|
||||
foreach($params as $name=>$value) {
|
||||
$paramstr .= $sep.$name.'='.$value;
|
||||
$sep = '&';
|
||||
}
|
||||
|
||||
$link = $CFG->wwwroot.'/grade/export/'.$this->plugin.'/dump.php'.$paramstr.'&key='.$this->userkey;
|
||||
|
||||
echo '<p>';
|
||||
echo '<a href="'.$link.'">'.$link.'</a>';
|
||||
|
@ -7,6 +7,10 @@ $id = required_param('id', PARAM_INT); // course id
|
||||
|
||||
require_user_key_login('grade/export', $id); // we want different keys for each course
|
||||
|
||||
if (empty($CFG->gradepublishing)) {
|
||||
error('Grade publishing disabled');
|
||||
}
|
||||
|
||||
// use the same page parameters as export.php and append &key=sdhakjsahdksahdkjsahksadjksahdkjsadhksa
|
||||
require 'export.php';
|
||||
|
||||
|
@ -27,10 +27,11 @@ require_once '../../../config.php';
|
||||
require_once $CFG->dirroot.'/grade/export/lib.php';
|
||||
require_once 'grade_export_ods.php';
|
||||
|
||||
$id = required_param('id', PARAM_INT); // course id
|
||||
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
||||
$export_letters = optional_param('export_letters', '', PARAM_INT);
|
||||
$itemids = explode(",", required_param('itemids', PARAM_RAW));
|
||||
$id = required_param('id', PARAM_INT); // course id
|
||||
$groupid = optional_param('groupid', 0, PARAM_INT);
|
||||
$itemids = required_param('itemids', PARAM_RAW);
|
||||
$export_feedback = optional_param('export_feedback', 0, PARAM_BOOL);
|
||||
$export_letters = optional_param('export_letters', 0, PARAM_BOOL);
|
||||
|
||||
if (!$course = get_record('course', 'id', $id)) {
|
||||
print_error('nocourseid');
|
||||
@ -44,7 +45,7 @@ require_capability('gradeexport/ods:view', $context);
|
||||
|
||||
|
||||
// print all the exported data here
|
||||
$export = new grade_export_ods($id, $itemids, $export_letters);
|
||||
$export->print_grades($feedback);
|
||||
$export = new grade_export_ods($course, $groupid, $itemids, $export_feedback, $export_letters);
|
||||
$export->print_grades();
|
||||
|
||||
?>
|
||||
|
@ -26,35 +26,27 @@ require_once($CFG->dirroot.'/grade/export/lib.php');
|
||||
|
||||
class grade_export_ods extends grade_export {
|
||||
|
||||
var $plugin = 'ods';
|
||||
|
||||
/**
|
||||
* To be implemented by child classes
|
||||
*/
|
||||
function print_grades($feedback = false) {
|
||||
function print_grades() {
|
||||
global $CFG;
|
||||
|
||||
$this->load_grades();
|
||||
|
||||
require_once($CFG->dirroot.'/lib/odslib.class.php');
|
||||
|
||||
/// Whether this plugin is entitled to update export time
|
||||
if ($expplugins = explode(",", $CFG->gradeexport)) {
|
||||
if (in_array('ods', $expplugins)) {
|
||||
$export = true;
|
||||
} else {
|
||||
$export = false;
|
||||
}
|
||||
} else {
|
||||
$export = false;
|
||||
}
|
||||
$export_tracking = $this->track_exports();
|
||||
|
||||
$strgrades = get_string('grades', 'grade');
|
||||
|
||||
/// Calculate file name
|
||||
$downloadfilename = clean_filename("{$this->course->shortname} $this->strgrades.ods");
|
||||
$downloadfilename = clean_filename("{$this->course->shortname} $strgrades.ods");
|
||||
/// Creating a workbook
|
||||
$workbook = new MoodleODSWorkbook("-");
|
||||
/// Sending HTTP headers
|
||||
$workbook->send($downloadfilename);
|
||||
/// Adding the worksheet
|
||||
$myxls =& $workbook->add_worksheet($this->strgrades);
|
||||
$myxls =& $workbook->add_worksheet($strgrades);
|
||||
|
||||
/// Print names of all the fields
|
||||
$myxls->write_string(0,0,get_string("firstname"));
|
||||
@ -64,61 +56,48 @@ class grade_export_ods extends grade_export {
|
||||
$myxls->write_string(0,4,get_string("department"));
|
||||
$myxls->write_string(0,5,get_string("email"));
|
||||
$pos=6;
|
||||
foreach ($this->columns as $column) {
|
||||
$myxls->write_string(0,$pos++,strip_tags($column));
|
||||
foreach ($this->columns as $grade_item) {
|
||||
$myxls->write_string(0, $pos++, $this->format_column_name($grade_item));
|
||||
|
||||
/// add a column_feedback column
|
||||
if ($feedback) {
|
||||
$myxls->write_string(0,$pos++,strip_tags($column."_feedback"));
|
||||
if ($this->export_feedback) {
|
||||
$myxls->write_string(0, $pos++, $this->format_column_name($grade_item, true));
|
||||
}
|
||||
}
|
||||
|
||||
/// Print all the lines of data.
|
||||
$i = 0;
|
||||
if (!empty($this->grades)) {
|
||||
foreach ($this->grades as $studentid => $studentgrades) {
|
||||
$i++;
|
||||
$student = $this->students[$studentid];
|
||||
if (empty($this->totals[$student->id])) {
|
||||
$this->totals[$student->id] = '';
|
||||
$gui = new graded_users_iterator($this->course, $this->columns, $this->groupid);
|
||||
$gui->init();
|
||||
while ($userdata = $gui->next_user()) {
|
||||
$i++;
|
||||
$user = $userdata->user;
|
||||
|
||||
$myxls->write_string($i,0,$user->firstname);
|
||||
$myxls->write_string($i,1,$user->lastname);
|
||||
$myxls->write_string($i,2,$user->idnumber);
|
||||
$myxls->write_string($i,3,$user->institution);
|
||||
$myxls->write_string($i,4,$user->department);
|
||||
$myxls->write_string($i,5,$user->email);
|
||||
$j=6;
|
||||
foreach ($userdata->grades as $itemid => $grade) {
|
||||
$gradestr = $this->format_grade($grade);
|
||||
if (is_numeric($gradestr)) {
|
||||
$myxls->write_number($i,$j++,$gradestr);
|
||||
}
|
||||
else {
|
||||
$myxls->write_string($i,$j++,$gradestr);
|
||||
}
|
||||
|
||||
$myxls->write_string($i,0,$student->firstname);
|
||||
$myxls->write_string($i,1,$student->lastname);
|
||||
$myxls->write_string($i,2,$student->idnumber);
|
||||
$myxls->write_string($i,3,$student->institution);
|
||||
$myxls->write_string($i,4,$student->department);
|
||||
$myxls->write_string($i,5,$student->email);
|
||||
$j=6;
|
||||
foreach ($studentgrades as $gradeitemid => $grade) {
|
||||
if (is_numeric($grade)) {
|
||||
$myxls->write_number($i,$j++,$grade);
|
||||
}
|
||||
else {
|
||||
$myxls->write_string($i,$j++,strip_tags($grade));
|
||||
}
|
||||
|
||||
// writing comment if requested
|
||||
if ($feedback) {
|
||||
$myxls->write_string($i,$j++,$this->comments[$student->id][$gradeitemid]);
|
||||
}
|
||||
|
||||
/// if export flag needs to be set
|
||||
/// construct the grade_grade object and update timestamp if CFG flag is set
|
||||
|
||||
if ($export) {
|
||||
$params= new object();
|
||||
$params->itemid = $gradeitemid;
|
||||
$params->userid = $studentid;
|
||||
|
||||
$grade_grade = new grade_grade($params);
|
||||
$grade_grade->exported = time();
|
||||
// update the time stamp;
|
||||
$grade_grade->update();
|
||||
}
|
||||
// writing feedback if requested
|
||||
if ($this->export_feedback) {
|
||||
$myxls->write_string($i, $j++, $this->format_feedback($userdata->feedbacks[$itemid]));
|
||||
}
|
||||
|
||||
//TODO: reimplement export handling flag
|
||||
}
|
||||
}
|
||||
$gui->close();
|
||||
|
||||
/// Close the workbook
|
||||
$workbook->close();
|
||||
|
@ -27,8 +27,7 @@ require_once '../../../config.php';
|
||||
require_once $CFG->dirroot.'/grade/export/lib.php';
|
||||
require_once 'grade_export_ods.php';
|
||||
|
||||
$id = required_param('id', PARAM_INT); // course id
|
||||
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
||||
$id = required_param('id', PARAM_INT); // course id
|
||||
|
||||
if (!$course = get_record('course', 'id', $id)) {
|
||||
print_error('nocourseid');
|
||||
@ -48,16 +47,21 @@ $navigation = grade_build_nav(__FILE__, $actionstr, array('courseid' => $course-
|
||||
print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation);
|
||||
print_grade_plugin_selector($id, 'export', 'ods');
|
||||
|
||||
$mform = new grade_export_form(null, array('publishing' => $CFG->enablepublishing));
|
||||
$mform = new grade_export_form(null, array('publishing' => true));
|
||||
|
||||
// process post information
|
||||
if ($data = $mform->get_data()) {
|
||||
$export = new grade_export_ods($course, get_current_group($course->id));
|
||||
|
||||
// print the grades on screen for feedbacks
|
||||
$export = new grade_export($id, $itemids, $data);
|
||||
$export->display_grades($feedback, $data->previewrows);
|
||||
$export->print_continue('ods');
|
||||
$export->process_form($data);
|
||||
$export->display_preview();
|
||||
$export->print_continue();
|
||||
die;
|
||||
}
|
||||
|
||||
//TODO: add course group selector here
|
||||
|
||||
$mform->display();
|
||||
|
||||
print_footer();
|
||||
|
@ -7,6 +7,10 @@ $id = required_param('id', PARAM_INT); // course id
|
||||
|
||||
require_user_key_login('grade/export', $id); // we want different keys for each course
|
||||
|
||||
if (empty($CFG->gradepublishing)) {
|
||||
error('Grade publishing disabled');
|
||||
}
|
||||
|
||||
// use the same page parameters as export.php and append &key=sdhakjsahdksahdkjsahksadjksahdkjsadhksa
|
||||
require 'export.php';
|
||||
|
||||
|
@ -27,10 +27,12 @@ require_once '../../../config.php';
|
||||
require_once $CFG->dirroot.'/grade/export/lib.php';
|
||||
require_once 'grade_export_txt.php';
|
||||
|
||||
$id = required_param('id', PARAM_INT); // course id
|
||||
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
||||
$export_letters = optional_param('export_letters', '', PARAM_INT);
|
||||
$itemids = explode(",", required_param('itemids', PARAM_RAW));
|
||||
$id = required_param('id', PARAM_INT); // course id
|
||||
$groupid = optional_param('groupid', 0, PARAM_INT);
|
||||
$itemids = required_param('itemids', PARAM_RAW);
|
||||
$export_feedback = optional_param('export_feedback', 0, PARAM_BOOL);
|
||||
$export_letters = optional_param('export_letters', 0, PARAM_BOOL);
|
||||
$separator = optional_param('separator', 'comma', PARAM_ALPHA);
|
||||
|
||||
if (!$course = get_record('course', 'id', $id)) {
|
||||
print_error('nocourseid');
|
||||
@ -42,9 +44,9 @@ $context = get_context_instance(CONTEXT_COURSE, $id);
|
||||
require_capability('moodle/grade:export', $context);
|
||||
require_capability('gradeexport/txt:view', $context);
|
||||
|
||||
|
||||
// print all the exported data here
|
||||
$export = new grade_export_txt($id, $itemids, $export_letters);
|
||||
$export->set_separator(optional_param('separator'));
|
||||
$export->print_grades($feedback);
|
||||
$export = new grade_export_txt($course, $groupid, $itemids, $export_feedback, $export_letters, $separator);
|
||||
$export->print_grades();
|
||||
|
||||
?>
|
||||
|
@ -26,94 +26,91 @@ require_once($CFG->dirroot.'/grade/export/lib.php');
|
||||
|
||||
class grade_export_txt extends grade_export {
|
||||
|
||||
var $separator = "\t"; // default separator
|
||||
var $plugin = 'txt';
|
||||
|
||||
function set_separator($separator) {
|
||||
if ($separator == 'comma') {
|
||||
$this->separator = ",";
|
||||
} else if ($separator == 'tab') {
|
||||
$this->separator = "\t";
|
||||
var $separator; // default separator
|
||||
|
||||
function grade_export_txt($course, $groupid=0, $itemlist='', $export_feedback=false, $export_letters=false, $separator='comma') {
|
||||
$this->grade_export($course, $groupid, $itemlist, $export_feedback, $export_letters);
|
||||
$this->separator = $separator;
|
||||
}
|
||||
|
||||
function process_form($formdata) {
|
||||
parent::process_form($formdata);
|
||||
if (isset($formdata->separator)) {
|
||||
$this->separator = $formdata->separator;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* To be implemented by child classes
|
||||
*/
|
||||
function print_grades($feedback = false) {
|
||||
function get_export_params() {
|
||||
$params = parent::get_export_params();
|
||||
$params['separator'] = $this->separator;
|
||||
return $params;
|
||||
}
|
||||
|
||||
function print_grades() {
|
||||
global $CFG;
|
||||
|
||||
$this->load_grades();
|
||||
$export_tracking = $this->track_exports();
|
||||
|
||||
$retval = '';
|
||||
$strgrades = get_string('grades', 'grade');
|
||||
|
||||
/// Whether this plugin is entitled to update export time
|
||||
if ($expplugins = explode(",", $CFG->gradeexport)) {
|
||||
if (in_array('txt', $expplugins)) {
|
||||
$export = true;
|
||||
} else {
|
||||
$export = false;
|
||||
}
|
||||
} else {
|
||||
$export = false;
|
||||
switch ($this->separator) {
|
||||
case 'comma':
|
||||
$separator = ",";
|
||||
break;
|
||||
case 'tab':
|
||||
default:
|
||||
$separator = "\t";
|
||||
}
|
||||
|
||||
/// Print header to force download
|
||||
@header('Cache-Control: private, must-revalidate, pre-check=0, post-check=0, max-age=0');
|
||||
@header('Expires: '. gmdate('D, d M Y H:i:s', 0) .' GMT');
|
||||
@header('Pragma: no-cache');
|
||||
header("Content-Type: application/download\n");
|
||||
$downloadfilename = clean_filename("{$this->course->shortname} $this->strgrades");
|
||||
$downloadfilename = clean_filename("{$this->course->shortname} $strgrades");
|
||||
header("Content-Disposition: attachment; filename=\"$downloadfilename.txt\"");
|
||||
|
||||
/// Print names of all the fields
|
||||
|
||||
$retval .= get_string("firstname")."$this->separator".
|
||||
get_string("lastname")."{$this->separator}".
|
||||
get_string("idnumber")."{$this->separator}".
|
||||
get_string("institution")."{$this->separator}".
|
||||
get_string("department")."{$this->separator}".
|
||||
echo get_string("firstname").$separator.
|
||||
get_string("lastname").$separator.
|
||||
get_string("idnumber").$separator.
|
||||
get_string("institution").$separator.
|
||||
get_string("department").$separator.
|
||||
get_string("email");
|
||||
foreach ($this->columns as $column) {
|
||||
$column = strip_tags($column);
|
||||
$retval .= "{$this->separator}$column";
|
||||
|
||||
/// add a column_feedback column
|
||||
if ($feedback) {
|
||||
$retval .= "{$this->separator}{$column}_feedback";
|
||||
foreach ($this->columns as $grade_item) {
|
||||
echo $separator.$this->format_column_name($grade_item);
|
||||
|
||||
/// add a feedback column
|
||||
if ($this->export_feedback) {
|
||||
echo $separator.$this->format_column_name($grade_item, true);
|
||||
}
|
||||
}
|
||||
echo "\n";
|
||||
|
||||
/// Print all the lines of data.
|
||||
foreach ($this->grades as $studentid => $studentgrades) {
|
||||
$gui = new graded_users_iterator($this->course, $this->columns, $this->groupid);
|
||||
$gui->init();
|
||||
while ($userdata = $gui->next_user()) {
|
||||
|
||||
$student = $this->students[$studentid];
|
||||
$user = $userdata->user;
|
||||
|
||||
$retval .= "$student->firstname{$this->separator}$student->lastname{$this->separator}$student->idnumber{$this->separator}$student->institution{$this->separator}$student->department{$this->separator}$student->email";
|
||||
echo $user->firstname.$separator.$user->lastname.$separator.$user->idnumber.$separator.$user->institution.$separator.$user->department.$separator.$user->email;
|
||||
|
||||
foreach ($studentgrades as $gradeitemid => $grade) {
|
||||
$grade = strip_tags($grade);
|
||||
$retval .= "{$this->separator}$grade";
|
||||
foreach ($userdata->grades as $itemid => $grade) {
|
||||
echo $separator.$this->format_grade($grade);
|
||||
|
||||
if ($feedback) {
|
||||
$retval .= "{$this->separator}".$this->comments[$student->id][$gradeitemid];
|
||||
if ($this->export_feedback) {
|
||||
echo $separator.$this->format_feedback($userdata->feedbacks[$itemid]);
|
||||
}
|
||||
|
||||
/// if export flag needs to be set
|
||||
/// construct the grade_grade object and update timestamp if CFG flag is set
|
||||
|
||||
if ($export) {
|
||||
//this should be improved with sql
|
||||
$params = new object();
|
||||
$params->itemid = $gradeitemid;
|
||||
$params->userid = $studentid;
|
||||
|
||||
$grade_grade = new grade_grade($params);
|
||||
$grade_grade->exported = time();
|
||||
// update the time stamp;
|
||||
$grade_grade->update();
|
||||
}
|
||||
//TODO: reimplement export handling flag
|
||||
}
|
||||
$retval .= "\n";
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
echo $retval;
|
||||
$gui->close();
|
||||
|
||||
exit;
|
||||
}
|
||||
|
@ -27,8 +27,7 @@ require_once '../../../config.php';
|
||||
require_once $CFG->dirroot.'/grade/export/lib.php';
|
||||
require_once 'grade_export_txt.php';
|
||||
|
||||
$id = required_param('id', PARAM_INT); // course id
|
||||
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
||||
$id = required_param('id', PARAM_INT); // course id
|
||||
|
||||
if (!$course = get_record('course', 'id', $id)) {
|
||||
print_error('nocourseid');
|
||||
@ -48,17 +47,21 @@ $navigation = grade_build_nav(__FILE__, $actionstr, array('courseid' => $course-
|
||||
print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation);
|
||||
print_grade_plugin_selector($id, 'export', 'txt');
|
||||
|
||||
$mform = new grade_export_form(null, array('includeseparator'=>true, 'publishing' => $CFG->enablepublishing));
|
||||
$mform = new grade_export_form(null, array('includeseparator'=>true, 'publishing' => true));
|
||||
|
||||
// process post information
|
||||
if ($data = $mform->get_data()) {
|
||||
$export = new grade_export_txt($course, get_current_group($course->id));
|
||||
|
||||
// print the grades on screen for feedbacks
|
||||
$export = new grade_export($id, $itemids, $data);
|
||||
$export->display_grades($feedback, $data->previewrows);
|
||||
$export->print_continue('txt');
|
||||
$export->process_form($data);
|
||||
$export->display_preview();
|
||||
$export->print_continue();
|
||||
die;
|
||||
}
|
||||
|
||||
// print the form to choose what grade_items to export
|
||||
//TODO: add course group selector here
|
||||
|
||||
$mform->display();
|
||||
|
||||
print_footer();
|
||||
|
@ -7,6 +7,10 @@ $id = required_param('id', PARAM_INT); // course id
|
||||
|
||||
require_user_key_login('grade/export', $id); // we want different keys for each course
|
||||
|
||||
if (empty($CFG->gradepublishing)) {
|
||||
error('Grade publishing disabled');
|
||||
}
|
||||
|
||||
// use the same page parameters as export.php and append &key=sdhakjsahdksahdkjsahksadjksahdkjsadhksa
|
||||
require 'export.php';
|
||||
|
||||
|
@ -27,10 +27,11 @@ require_once '../../../config.php';
|
||||
require_once $CFG->dirroot.'/grade/export/lib.php';
|
||||
require_once 'grade_export_xls.php';
|
||||
|
||||
$id = required_param('id', PARAM_INT); // course id
|
||||
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
||||
$export_letters = optional_param('export_letters', '', PARAM_INT);
|
||||
$itemids = explode(",", required_param('itemids', PARAM_RAW));
|
||||
$id = required_param('id', PARAM_INT); // course id
|
||||
$groupid = optional_param('groupid', 0, PARAM_INT);
|
||||
$itemids = required_param('itemids', PARAM_RAW);
|
||||
$export_feedback = optional_param('export_feedback', 0, PARAM_BOOL);
|
||||
$export_letters = optional_param('export_letters', 0, PARAM_BOOL);
|
||||
|
||||
if (!$course = get_record('course', 'id', $id)) {
|
||||
print_error('nocourseid');
|
||||
@ -42,8 +43,9 @@ $context = get_context_instance(CONTEXT_COURSE, $id);
|
||||
require_capability('moodle/grade:export', $context);
|
||||
require_capability('gradeexport/xls:view', $context);
|
||||
|
||||
|
||||
// print all the exported data here
|
||||
$export = new grade_export_xls($id, $itemids, $export_letters);
|
||||
$export->print_grades($feedback);
|
||||
$export = new grade_export_xls($course, $groupid, $itemids, $export_feedback, $export_letters);
|
||||
$export->print_grades();
|
||||
|
||||
?>
|
||||
|
@ -26,35 +26,27 @@ require_once($CFG->dirroot.'/grade/export/lib.php');
|
||||
|
||||
class grade_export_xls extends grade_export {
|
||||
|
||||
var $plugin = 'xls';
|
||||
|
||||
/**
|
||||
* To be implemented by child classes
|
||||
*/
|
||||
function print_grades($feedback = false) {
|
||||
function print_grades() {
|
||||
global $CFG;
|
||||
|
||||
$this->load_grades();
|
||||
|
||||
/// Whether this plugin is entitled to update export time
|
||||
if ($expplugins = explode(",", $CFG->gradeexport)) {
|
||||
if (in_array('xls', $expplugins)) {
|
||||
$export = true;
|
||||
} else {
|
||||
$export = false;
|
||||
}
|
||||
} else {
|
||||
$export = false;
|
||||
}
|
||||
|
||||
require_once($CFG->dirroot.'/lib/excellib.class.php');
|
||||
|
||||
$export_tracking = $this->track_exports();
|
||||
|
||||
$strgrades = get_string('grades', 'grade');
|
||||
|
||||
/// Calculate file name
|
||||
$downloadfilename = clean_filename("{$this->course->shortname} $this->strgrades.xls");
|
||||
$downloadfilename = clean_filename("{$this->course->shortname} $strgrades.xls");
|
||||
/// Creating a workbook
|
||||
$workbook = new MoodleExcelWorkbook("-");
|
||||
/// Sending HTTP headers
|
||||
$workbook->send($downloadfilename);
|
||||
/// Adding the worksheet
|
||||
$myxls =& $workbook->add_worksheet($this->strgrades);
|
||||
$myxls =& $workbook->add_worksheet($strgrades);
|
||||
|
||||
/// Print names of all the fields
|
||||
$myxls->write_string(0,0,get_string("firstname"));
|
||||
@ -64,63 +56,52 @@ class grade_export_xls extends grade_export {
|
||||
$myxls->write_string(0,4,get_string("department"));
|
||||
$myxls->write_string(0,5,get_string("email"));
|
||||
$pos=6;
|
||||
foreach ($this->columns as $column) {
|
||||
$myxls->write_string(0,$pos++,strip_tags($column));
|
||||
foreach ($this->columns as $grade_item) {
|
||||
$myxls->write_string(0, $pos++, $this->format_column_name($grade_item));
|
||||
|
||||
/// add a column_feedback column
|
||||
if ($feedback) {
|
||||
$myxls->write_string(0,$pos++,strip_tags($column."_feedback"));
|
||||
if ($this->export_feedback) {
|
||||
$myxls->write_string(0, $pos++, $this->format_column_name($grade_item, true));
|
||||
}
|
||||
}
|
||||
|
||||
/// Print all the lines of data.
|
||||
$i = 0;
|
||||
if (!empty($this->grades)) {
|
||||
foreach ($this->grades as $studentid => $studentgrades) {
|
||||
$i++;
|
||||
$student = $this->students[$studentid];
|
||||
if (empty($this->totals[$student->id])) {
|
||||
$this->totals[$student->id] = '';
|
||||
$gui = new graded_users_iterator($this->course, $this->columns, $this->groupid);
|
||||
$gui->init();
|
||||
while ($userdata = $gui->next_user()) {
|
||||
$i++;
|
||||
$user = $userdata->user;
|
||||
|
||||
$myxls->write_string($i,0,$user->firstname);
|
||||
$myxls->write_string($i,1,$user->lastname);
|
||||
$myxls->write_string($i,2,$user->idnumber);
|
||||
$myxls->write_string($i,3,$user->institution);
|
||||
$myxls->write_string($i,4,$user->department);
|
||||
$myxls->write_string($i,5,$user->email);
|
||||
$j=6;
|
||||
foreach ($userdata->grades as $itemid => $grade) {
|
||||
$gradestr = $this->format_grade($grade);
|
||||
if (is_numeric($gradestr)) {
|
||||
$myxls->write_number($i,$j++,$gradestr);
|
||||
}
|
||||
else {
|
||||
$myxls->write_string($i,$j++,$gradestr);
|
||||
}
|
||||
|
||||
$myxls->write_string($i,0,$student->firstname);
|
||||
$myxls->write_string($i,1,$student->lastname);
|
||||
$myxls->write_string($i,2,$student->idnumber);
|
||||
$myxls->write_string($i,3,$student->institution);
|
||||
$myxls->write_string($i,4,$student->department);
|
||||
$myxls->write_string($i,5,$student->email);
|
||||
$j=6;
|
||||
foreach ($studentgrades as $gradeitemid => $grade) {
|
||||
if (is_numeric($grade)) {
|
||||
$myxls->write_number($i,$j++,$grade);
|
||||
}
|
||||
else {
|
||||
$myxls->write_string($i,$j++,strip_tags($grade));
|
||||
}
|
||||
|
||||
// writing comment if requested
|
||||
if ($feedback) {
|
||||
$myxls->write_string($i,$j++,$this->comments[$student->id][$gradeitemid]);
|
||||
}
|
||||
|
||||
/// if export flag needs to be set
|
||||
/// construct the grade_grade object and update timestamp if CFG flag is set
|
||||
|
||||
if ($export) {
|
||||
$params = new object();
|
||||
$params->itemid = $gradeitemid;
|
||||
$params->userid = $studentid;
|
||||
|
||||
$grade_grade = new grade_grade($params);
|
||||
$grade_grade->exported = time();
|
||||
// update the time stamp;
|
||||
$grade_grade->update();
|
||||
}
|
||||
// writing feedback if requested
|
||||
if ($this->export_feedback) {
|
||||
$myxls->write_string($i, $j++, $this->format_feedback($userdata->feedbacks[$itemid]));
|
||||
}
|
||||
|
||||
//TODO: reimplement export handling flag
|
||||
}
|
||||
}
|
||||
$gui->close();
|
||||
|
||||
/// Close the workbook
|
||||
$workbook->close();
|
||||
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
@ -27,8 +27,7 @@ require_once '../../../config.php';
|
||||
require_once $CFG->dirroot.'/grade/export/lib.php';
|
||||
require_once 'grade_export_xls.php';
|
||||
|
||||
$id = required_param('id', PARAM_INT); // course id
|
||||
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
||||
$id = required_param('id', PARAM_INT); // course id
|
||||
|
||||
if (!$course = get_record('course', 'id', $id)) {
|
||||
print_error('nocourseid');
|
||||
@ -48,16 +47,21 @@ $navigation = grade_build_nav(__FILE__, $actionstr, array('courseid' => $course-
|
||||
print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation);
|
||||
print_grade_plugin_selector($id, 'export', 'xls');
|
||||
|
||||
$mform = new grade_export_form(null, array('publishing' => $CFG->enablepublishing));
|
||||
$mform = new grade_export_form(null, array('publishing' => true));
|
||||
|
||||
// process post information
|
||||
if ($data = $mform->get_data()) {
|
||||
$export = new grade_export_xls($course, get_current_group($course->id));
|
||||
|
||||
// print the grades on screen for feedbacks
|
||||
$export = new grade_export($id, $itemids, $data);
|
||||
$export->display_grades($feedback, $data->previewrows);
|
||||
$export->print_continue('xls');
|
||||
$export->process_form($data);
|
||||
$export->display_preview();
|
||||
$export->print_continue();
|
||||
die;
|
||||
}
|
||||
|
||||
//TODO: add course group selector here
|
||||
|
||||
$mform->display();
|
||||
|
||||
print_footer();
|
||||
|
@ -7,6 +7,10 @@ $id = required_param('id', PARAM_INT); // course id
|
||||
|
||||
require_user_key_login('grade/export', $id); // we want different keys for each course
|
||||
|
||||
if (empty($CFG->gradepublishing)) {
|
||||
error('Grade publishing disabled');
|
||||
}
|
||||
|
||||
// use the same page parameters as export.php and append &key=sdhakjsahdksahdkjsahksadjksahdkjsadhksa
|
||||
require 'export.php';
|
||||
|
||||
|
@ -27,10 +27,11 @@ require_once '../../../config.php';
|
||||
require_once $CFG->dirroot.'/grade/export/lib.php';
|
||||
require_once 'grade_export_xml.php';
|
||||
|
||||
$id = required_param('id', PARAM_INT); // course id
|
||||
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
||||
$export_letters = optional_param('export_letters', '', PARAM_INT);
|
||||
$itemids = explode(",", required_param('itemids', PARAM_RAW));
|
||||
$id = required_param('id', PARAM_INT); // course id
|
||||
$groupid = optional_param('groupid', 0, PARAM_INT);
|
||||
$itemids = required_param('itemids', PARAM_RAW);
|
||||
$export_feedback = optional_param('export_feedback', 0, PARAM_BOOL);
|
||||
$export_letters = optional_param('export_letters', 0, PARAM_BOOL);
|
||||
|
||||
if (!$course = get_record('course', 'id', $id)) {
|
||||
print_error('nocourseid');
|
||||
@ -42,8 +43,9 @@ $context = get_context_instance(CONTEXT_COURSE, $id);
|
||||
require_capability('moodle/grade:export', $context);
|
||||
require_capability('gradeexport/xml:view', $context);
|
||||
|
||||
|
||||
// print all the exported data here
|
||||
$export = new grade_export_xml($id, $itemids, $export_letters);
|
||||
$export->print_grades($feedback);
|
||||
$export = new grade_export_xml($course, $groupid, $itemids, $export_feedback, $export_letters);
|
||||
$export->print_grades();
|
||||
|
||||
?>
|
||||
|
@ -26,6 +26,8 @@ require_once($CFG->dirroot.'/grade/export/lib.php');
|
||||
|
||||
class grade_export_xml extends grade_export {
|
||||
|
||||
var $plugin = 'xml';
|
||||
|
||||
/**
|
||||
* To be implemented by child classes
|
||||
* @param boolean $feedback
|
||||
@ -34,26 +36,17 @@ class grade_export_xml extends grade_export {
|
||||
*/
|
||||
function print_grades($feedback = false) {
|
||||
global $CFG;
|
||||
require_once($CFG->libdir.'/filelib.php');
|
||||
|
||||
$this->load_grades();
|
||||
$export_tracking = $this->track_exports();
|
||||
|
||||
$retval = '';
|
||||
|
||||
/// Whether this plugin is entitled to update export time
|
||||
if ($expplugins = explode(",", $CFG->gradeexport)) {
|
||||
if (in_array('xml', $expplugins)) {
|
||||
$export = true;
|
||||
} else {
|
||||
$export = false;
|
||||
}
|
||||
} else {
|
||||
$export = false;
|
||||
}
|
||||
$strgrades = get_string('grades', 'grade');
|
||||
|
||||
/// Calculate file name
|
||||
$downloadfilename = clean_filename("{$this->course->shortname} $this->strgrades.xml");
|
||||
$downloadfilename = clean_filename("{$this->course->shortname} $strgrades.xml");
|
||||
|
||||
$tempfilename = $CFG->dataroot . MD5(microtime()) . $downloadfilename;
|
||||
make_upload_directory('temp/gradeexport', false);
|
||||
$tempfilename = $CFG->dataroot .'/temp/gradeexport/'. md5(sesskey().microtime().$downloadfilename);
|
||||
if (!$handle = fopen($tempfilename, 'w+b')) {
|
||||
error("Could not create a temporary file into which to dump the XML data.");
|
||||
return false;
|
||||
@ -62,74 +55,65 @@ class grade_export_xml extends grade_export {
|
||||
/// time stamp to ensure uniqueness of batch export
|
||||
fwrite($handle, '<results batch="xml_export_'.time().'">'."\n");
|
||||
|
||||
foreach ($this->columnidnumbers as $index => $idnumber) {
|
||||
$gui = new graded_users_iterator($this->course, $this->columns, $this->groupid);
|
||||
$gui->init();
|
||||
while ($userdata = $gui->next_user()) {
|
||||
$user = $userdata->user;
|
||||
|
||||
// studentgrades[] index should match with corresponding $index
|
||||
foreach ($this->grades as $studentid => $studentgrades) {
|
||||
foreach ($userdata->grades as $itemid => $grade) {
|
||||
$grade_item = $this->grade_items[$itemid];
|
||||
$grade->grade_item =& $grade_item;
|
||||
$gradestr = $this->format_grade($grade);
|
||||
|
||||
fwrite($handle, "\t<result>\n");
|
||||
|
||||
// state can be new, or regrade
|
||||
// require comparing of timestamps in db
|
||||
|
||||
$params = new object();
|
||||
$params->idnumber = $idnumber;
|
||||
// get the grade item
|
||||
$gradeitem = new grade_item($params);
|
||||
|
||||
// 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
|
||||
|
||||
// get the grade_grade for this user
|
||||
$params = new object();
|
||||
$params->itemid = $gradeitem->id;
|
||||
$params->userid = $studentid;
|
||||
|
||||
$grade_grade = new grade_grade($params);
|
||||
|
||||
// if exported, check grade_history, if modified after export, set state to regrade
|
||||
$status = 'new';
|
||||
if (!empty($grade_grade->exported)) {
|
||||
/* if (!empty($grade_grade->exported)) {
|
||||
//TODO: use timemodified or something else instead
|
||||
/* if (record_exists_select('grade_history', 'itemid = '.$gradeitem->id.' AND userid = '.$studentid.' AND timemodified > '.$grade_grade->exported)) {
|
||||
if (record_exists_select('grade_history', 'itemid = '.$gradeitem->id.' AND userid = '.$userid.' AND timemodified > '.$grade_grade->exported)) {
|
||||
$status = 'regrade';
|
||||
} else {
|
||||
$status = 'new';
|
||||
}*/
|
||||
}
|
||||
} else {
|
||||
// never exported
|
||||
$status = 'new';
|
||||
}
|
||||
|
||||
*/
|
||||
fwrite($handle, "\t\t<state>$status</state>\n");
|
||||
// only need id number
|
||||
fwrite($handle, "\t\t<assignment>$idnumber</assignment>\n");
|
||||
fwrite($handle, "\t\t<assignment>{$grade_item->idnumber}</assignment>\n");
|
||||
// this column should be customizable to use either student id, idnumber, uesrname or email.
|
||||
fwrite($handle, "\t\t<student>$studentid</student>\n");
|
||||
fwrite($handle, "\t\t<score>{$studentgrades[$index]}</score>\n");
|
||||
if ($feedback) {
|
||||
fwrite($handle, "\t\t<feedback>{$this->comments[$studentid][$index]}</feedback>\n");
|
||||
fwrite($handle, "\t\t<student>{$user->id}</student>\n");
|
||||
fwrite($handle, "\t\t<score>$gradestr</score>\n");
|
||||
if ($this->export_feedback) {
|
||||
$feedbackstr = $this->format_feedback($userdata->feedbacks[$itemid]);
|
||||
fwrite($handle, "\t\t<feedback>$feedbackstr</feedback>\n");
|
||||
}
|
||||
fwrite($handle, "\t</result>\n");
|
||||
|
||||
// timestamp this if needed
|
||||
if ($export) {
|
||||
/* if ($export) {
|
||||
$grade_grade->exported = time();
|
||||
// update the time stamp;
|
||||
$grade_grade->update();
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
fwrite($handle, "</results>");
|
||||
fclose($handle);
|
||||
|
||||
require_once($CFG->libdir . '/filelib.php');
|
||||
|
||||
@header('Cache-Control: private, must-revalidate, pre-check=0, post-check=0, max-age=0');
|
||||
@header('Expires: '. gmdate('D, d M Y H:i:s', 0) .' GMT');
|
||||
@header('Pragma: no-cache');
|
||||
header("Content-type: text/xml; charset=UTF-8");
|
||||
header("Content-Disposition: attachment; filename=\"$downloadfilename\"");
|
||||
|
||||
readfile_chunked($tempfilename);
|
||||
|
||||
unlink($tempfilename);
|
||||
@unlink($tempfilename);
|
||||
|
||||
exit();
|
||||
}
|
||||
|
@ -27,8 +27,7 @@ require_once '../../../config.php';
|
||||
require_once $CFG->dirroot.'/grade/export/lib.php';
|
||||
require_once 'grade_export_xml.php';
|
||||
|
||||
$id = required_param('id', PARAM_INT); // course id
|
||||
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
||||
$id = required_param('id', PARAM_INT); // course id
|
||||
|
||||
if (!$course = get_record('course', 'id', $id)) {
|
||||
print_error('nocourseid');
|
||||
@ -48,16 +47,21 @@ $navigation = grade_build_nav(__FILE__, $actionstr, array('courseid' => $course-
|
||||
print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation);
|
||||
print_grade_plugin_selector($id, 'export', 'xml');
|
||||
|
||||
$mform = new grade_export_form(null, array('idnumberrequired'=>true, 'publishing'=>$CFG->enablepublishing));
|
||||
$mform = new grade_export_form(null, array('idnumberrequired'=>true, 'publishing' => true));
|
||||
|
||||
// process post information
|
||||
if ($data = $mform->get_data()) {
|
||||
$export = new grade_export_xml($course, get_current_group($course->id));
|
||||
|
||||
// print the grades on screen for feedbacks
|
||||
$export = new grade_export($id, $itemids, $data);
|
||||
$export->display_grades($feedback, $data->previewrows);
|
||||
$export->print_continue('xml');
|
||||
$export->process_form($data);
|
||||
$export->display_preview();
|
||||
$export->print_continue();
|
||||
die;
|
||||
}
|
||||
|
||||
//TODO: add course group selector here
|
||||
|
||||
$mform->display();
|
||||
|
||||
print_footer();
|
||||
|
@ -69,7 +69,7 @@ class graded_users_iterator {
|
||||
AND ra.contextid $relatedcontexts
|
||||
$groupwheresql
|
||||
ORDER BY u.id ASC";
|
||||
$this->rs_users = get_recordset_sql($users_sql);
|
||||
$this->users_rs = get_recordset_sql($users_sql);
|
||||
|
||||
if (!empty($this->grade_items)) {
|
||||
$itemids = array_keys($this->grade_items);
|
||||
@ -86,7 +86,7 @@ class graded_users_iterator {
|
||||
AND g.itemid IN ($itemids)
|
||||
$groupwheresql
|
||||
ORDER BY g.userid ASC, g.itemid ASC";
|
||||
$this->rs_grades = get_recordset_sql($grades_sql);
|
||||
$this->grades_rs = get_recordset_sql($grades_sql);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -97,11 +97,11 @@ class graded_users_iterator {
|
||||
* @return mixed array of user info, all grades and feedback or null when no more users found
|
||||
*/
|
||||
function next_user() {
|
||||
if (!$this->rs_users or !$this->rs_users->RecordCount()) {
|
||||
if (!$this->users_rs or !$this->users_rs->RecordCount()) {
|
||||
return false; // no users present
|
||||
}
|
||||
|
||||
if (!$user = rs_fetch_next_record($this->rs_users)) {
|
||||
if (!$user = rs_fetch_next_record($this->users_rs)) {
|
||||
return false; // no more users
|
||||
}
|
||||
|
||||
@ -155,13 +155,13 @@ class graded_users_iterator {
|
||||
* @return void
|
||||
*/
|
||||
function close() {
|
||||
if ($this->rs_users) {
|
||||
rs_close($this->rs_users);
|
||||
$this->rs_users = null;
|
||||
if ($this->users_rs) {
|
||||
rs_close($this->users_rs);
|
||||
$this->users_rs = null;
|
||||
}
|
||||
if ($this->rs_grades) {
|
||||
rs_close($this->rs_grades);
|
||||
$this->rs_grades = null;
|
||||
if ($this->grades_rs) {
|
||||
rs_close($this->grades_rs);
|
||||
$this->grades_rs = null;
|
||||
}
|
||||
$this->gradestack = array();
|
||||
}
|
||||
@ -178,11 +178,11 @@ class graded_users_iterator {
|
||||
*/
|
||||
function _pop() {
|
||||
if (empty($this->gradestack)) {
|
||||
if (!$this->rs_grades or !$this->rs_grades->RecordCount()) {
|
||||
if (!$this->grades_rs or !$this->grades_rs->RecordCount()) {
|
||||
return NULL; // no grades present
|
||||
}
|
||||
|
||||
if (!$grade = rs_fetch_next_record($this->rs_grades)) {
|
||||
if (!$grade = rs_fetch_next_record($this->grades_rs)) {
|
||||
return NULL; // no more grades
|
||||
}
|
||||
|
||||
|
@ -72,6 +72,7 @@ $string['configgradeboundary'] = 'A percentage boundary over which grades will b
|
||||
$string['configgradedisplaytype'] = 'Grades can be shown as real grades, as percentages (in reference to the minimum and maximum grades) or as letters (A, B, C etc..)';
|
||||
$string['configgradeletter'] = 'A letter or other symbol used to represent a range of grades.';
|
||||
$string['configgradeletterdefault'] = 'A letter or other symbol used to represent a range of grades. Leave this field empty to use the site default (currently $a).';
|
||||
$string['configgradepublishing'] = 'Enable publishing in exports and imports: Exported grades can be accessed by accessing a URL, without having to log on to a Moodle site. Grades can be imported by accessing such a URL (which means that a moodle site can import grades published by another site).';
|
||||
$string['configmeanselection'] = 'Select which types of grades will be included in the column averages. Cells with no grade can be ignored, or counted as 0 (default setting).';
|
||||
$string['configquickfeedback'] = 'Quick Feedback adds a text input element in each grade cell on the grader report, allowing you to edit many grades at once. You can then click the Update button to perform all these changes at once, instead of one at a time.';
|
||||
$string['configquickgrading'] = 'Quick Grading adds a text input element in each grade cell on the grader report, allowing you to edit the feedback for many grades at once. You can then click the Update button to perform all these changes at once, instead of one at a time.';
|
||||
@ -176,6 +177,7 @@ $string['grademinhelp'] = 'The minimum allowable grade for this grade item.';
|
||||
$string['gradeoutcomeitem'] = 'Grade outcome item';
|
||||
$string['gradepass'] = 'Grade to pass';
|
||||
$string['gradepasshelp'] = 'What grade is needed to pass?';
|
||||
$string['gradepublishing'] = 'Enable publishing';
|
||||
$string['graderreport'] = 'Grader report';
|
||||
$string['gradessettings'] = 'Grade settings';
|
||||
$string['gradepreferences'] = 'Grade Preferences';
|
||||
|
@ -1,9 +1,7 @@
|
||||
<?php // $Id$
|
||||
$string['configenablepublishing'] = 'Enable publishing in exports and imports: Exported grades can be accessed by accessing a URL, without having to log on to a Moodle site. Grades can be imported by accessing such a URL (which means that a moodle site can import grades published by another site).';
|
||||
$string['createnewkey'] = 'Create a new user key';
|
||||
$string['createuserkey'] = 'Create user key';
|
||||
$string['deletekeyconfirm'] = 'Do you really want to delete this user key?';
|
||||
$string['enablepublishing'] = 'Enable publishing';
|
||||
$string['edituserkey'] = 'Edit user key';
|
||||
$string['keyiprestriction'] = 'Key IP restriction';
|
||||
$string['keyiprestrictionhelp'] = 'Enter a specific IP address, or a range of IP addresses that will be the only IP addresses allowed to access this data. Enter nothing to disable IP restriction (not recommended).';
|
||||
|
@ -6,7 +6,7 @@
|
||||
// This is compared against the values stored in the database to determine
|
||||
// whether upgrades should be performed (see lib/db/*.php)
|
||||
|
||||
$version = 2007083100; // YYYYMMDD = date
|
||||
$version = 2007083101; // YYYYMMDD = date
|
||||
// XY = increments within a single day
|
||||
|
||||
$release = '1.9 Beta +'; // Human-friendly version name
|
||||
|
Loading…
x
Reference in New Issue
Block a user