mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
fix for MDL-9137, adding support for gradebook plugins for db, cron, events, permission structures etc
This commit is contained in:
parent
a15428a2f6
commit
ce34ed3a76
@ -386,6 +386,46 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// run gradebook import/export/report cron
|
||||
if ($gradeimports = get_list_of_plugins('grade/import')) {
|
||||
foreach ($gradeimports as $gradeimport) {
|
||||
if (file_exists($CFG->dirroot.'/grade/import/lib.php')) {
|
||||
require_once($CFG->dirroot.'/grade/import/lib.php');
|
||||
$cron_function = 'gradeimport_'.$gradeimport.'_cron';
|
||||
if (function_exists($cron_function)) {
|
||||
mtrace("Processing gradebook import function $cron_function ...", '');
|
||||
$cron_function;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($gradeexports = get_list_of_plugins('grade/export')) {
|
||||
foreach ($gradeexports as $gradeexport) {
|
||||
if (file_exists($CFG->dirroot.'/grade/export/lib.php')) {
|
||||
require_once($CFG->dirroot.'/grade/export/lib.php');
|
||||
$cron_function = 'gradeexport_'.$gradeexport.'_cron';
|
||||
if (function_exists($cron_function)) {
|
||||
mtrace("Processing gradebook export function $cron_function ...", '');
|
||||
$cron_function;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($gradereports = get_list_of_plugins('grade/report')) {
|
||||
foreach ($gradereports as $gradereport) {
|
||||
if (file_exists($CFG->dirroot.'/grade/report/lib.php')) {
|
||||
require_once($CFG->dirroot.'/grade/report/lib.php');
|
||||
$cron_function = 'gradereport_'.$gradereport.'_cron';
|
||||
if (function_exists($cron_function)) {
|
||||
mtrace("Processing gradebook report function $cron_function ...", '');
|
||||
$cron_function;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Unset session variables and destroy it
|
||||
@session_unset();
|
||||
|
@ -424,6 +424,10 @@
|
||||
require_once($CFG->dirroot.'/admin/mnet/adminlib.php');
|
||||
upgrade_RPC_functions("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
|
||||
|
||||
/// Upgrade all plugins for gradebook
|
||||
upgrade_plugins('gradeexport', 'grade/export', "$CFG->wwwroot/$CFG->admin/index.php");
|
||||
upgrade_plugins('gradeimport', 'grade/import', "$CFG->wwwroot/$CFG->admin/index.php");
|
||||
upgrade_plugins('gradereport', 'grade/report', "$CFG->wwwroot/$CFG->admin/index.php");
|
||||
|
||||
/// just make sure upgrade logging is properly terminated
|
||||
upgrade_log_finish();
|
||||
|
@ -22,7 +22,7 @@
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
include_once('../../../config.php');
|
||||
|
||||
include_once($CFG->dirroot.'/lib/gradelib.php');
|
||||
include_once($CFG->dirroot.'/grade/lib.php');
|
||||
/**
|
||||
@ -30,10 +30,15 @@ include_once($CFG->dirroot.'/grade/lib.php');
|
||||
* @input int id - course id
|
||||
*/
|
||||
function print_gradeitem_selections($id, $params = NULL) {
|
||||
|
||||
global $CFG;
|
||||
// print all items for selections
|
||||
// make this a standard function in lib maybe
|
||||
if ($grade_items = grade_get_items($id)) {
|
||||
//if ($grade_items = grade_get_items($id)) {
|
||||
include_once('grade_export_form.php');
|
||||
$mform = new grade_export_form(qualified_me(), array('id'=>$id));
|
||||
$mform->display();
|
||||
/*
|
||||
|
||||
echo '<form action="index.php" method="post">';
|
||||
echo '<div>';
|
||||
foreach ($grade_items as $grade_item) {
|
||||
@ -52,7 +57,8 @@ function print_gradeitem_selections($id, $params = NULL) {
|
||||
echo '<input type="submit" value="'.get_string('submit').'" />';
|
||||
echo '</div>';
|
||||
echo '</form>';
|
||||
}
|
||||
*/
|
||||
//}
|
||||
}
|
||||
/**
|
||||
* Base export class
|
||||
@ -155,16 +161,19 @@ class grade_export {
|
||||
$maxgrade = "$strmax: $gradeitem->grademax";
|
||||
} else {
|
||||
$maxgrade = "";
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($this->students)) {
|
||||
foreach ($this->students as $student) {
|
||||
|
||||
unset($studentgrade);
|
||||
// add support for comment here MDL-9634
|
||||
$studentgrade = $itemgrades[$student->id];
|
||||
|
||||
if (!empty($itemgrades[$student->id])) {
|
||||
$studentgrade = $itemgrades[$student->id];
|
||||
}
|
||||
|
||||
if (!empty($studentgrade->gradevalue)) {
|
||||
$this->grades[$student->id][$gradeitem->id] = $currentstudentgrade = $studentgrade->gradevalue;
|
||||
$this->grades[$student->id][$gradeitem->id] = $currentstudentgrade = $studentgrade->gradevalue;
|
||||
} else {
|
||||
$this->grades[$student->id][$gradeitem->id] = $currentstudentgrade = "";
|
||||
$this->gradeshtml[$student->id][$gradeitem->id] = "";
|
||||
@ -175,13 +184,14 @@ class grade_export {
|
||||
$this->totals[$student->id] = (float)($this->totals[$student->id]) + 0;
|
||||
}
|
||||
|
||||
// load comments here
|
||||
$studentgrade->load_text();
|
||||
// get the actual comment
|
||||
$comment = $studentgrade->grade_grades_text->feedback;
|
||||
|
||||
if (!empty($comment)) {
|
||||
$this->comments[$student->id][$gradeitem->id] = $comment;
|
||||
if (!empty($comment)) {
|
||||
// load comments here
|
||||
if ($studentgrade) {
|
||||
$studentgrade->load_text();
|
||||
// get the actual comment
|
||||
$comment = $studentgrade->grade_grades_text->feedback;
|
||||
$this->comments[$student->id][$gradeitem->id] = $comment;
|
||||
}
|
||||
} else {
|
||||
$this->comments[$student->id][$gradeitem->id] = '';
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ if (($data = data_submitted()) && confirm_sesskey()) {
|
||||
|
||||
// print the grades on screen for feedbacks
|
||||
$course = get_record('course', 'id', $id);
|
||||
$action = 'exporttxt';
|
||||
$action = 'exportxml';
|
||||
print_header($course->shortname.': '.get_string('grades'), $course->fullname, grade_nav($course, $action));
|
||||
|
||||
$export = new grade_export($id, $data->itemids);
|
||||
@ -47,7 +47,7 @@ if (($data = data_submitted()) && confirm_sesskey()) {
|
||||
|
||||
// this redirect should trigger a download prompt
|
||||
redirect('export.php?id='.$id.'&itemids='.$itemidsurl);
|
||||
exit;
|
||||
exit;
|
||||
}
|
||||
$course = get_record('course', 'id', $id);
|
||||
$action = 'exportxml';
|
||||
|
86
grade/import/xml/index.php
Executable file
86
grade/import/xml/index.php
Executable file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
This is development code, and it is not finished
|
||||
|
||||
$form = new custom_form_subclass(qualified_me(), array('somefield' => 'somevalue', 'someotherfield' => 'someothervalue') );
|
||||
and then in your subclass, in definition, you can access
|
||||
$this->_customdata['somefield']
|
||||
*/
|
||||
|
||||
require_once('../../../config.php');
|
||||
|
||||
// capability check
|
||||
$id = required_param('id', PARAM_INT); // course id
|
||||
// require_capability('moodle/site:uploadusers', get_context_instance(CONTEXT_SYSTEM));
|
||||
|
||||
require_once('../grade_import_form.php');
|
||||
|
||||
|
||||
require_once($CFG->dirroot.'/grade/lib.php');
|
||||
$course = get_record('course', 'id', $id);
|
||||
$action = 'importxml';
|
||||
print_header($course->shortname.': '.get_string('grades'), $course->fullname, grade_nav($course, $action));
|
||||
|
||||
$mform = new grade_import_form();
|
||||
|
||||
//$mform2 = new grade_import_mapping_form();
|
||||
|
||||
//if ($formdata = $mform2->get_data() ) {
|
||||
|
||||
if ( $formdata = $mform->get_data() ) {
|
||||
|
||||
$filename = $mform->get_userfile_name();
|
||||
|
||||
// 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
|
||||
// to free up memory.
|
||||
@set_time_limit(0);
|
||||
@raise_memory_limit("192M");
|
||||
if (function_exists('apache_child_terminate')) {
|
||||
@apache_child_terminate();
|
||||
}
|
||||
|
||||
$text = my_file_get_contents($filename);
|
||||
// trim utf-8 bom
|
||||
$textlib = new textlib();
|
||||
$text = $textlib->trim_utf8_bom($text);
|
||||
// Fix mac/dos newlines
|
||||
$text = preg_replace('!\r\n?!',"\n",$text);
|
||||
|
||||
// text is the text, we should xmlize it
|
||||
include_once($CFG->dirroot.'/lib/xmlize.php');
|
||||
$content = xmlize($text);
|
||||
|
||||
if ($results = $content['results']['#']['result']) {
|
||||
foreach ($results as $result) {
|
||||
unset ($eventdata);
|
||||
|
||||
$eventdata->idnumber = $result['#']['assignment'][0]['#'];
|
||||
$eventdata->userid = $result['#']['student'][0]['#'];
|
||||
$eventdata->gradevalue = $result['#']['score'][0]['#'];
|
||||
|
||||
trigger_event('grade_added', $eventdata);
|
||||
echo "<br/>triggering event for $eventdata->idnumber... student id is $eventdata->userid and grade is $eventdata->gradevalue";
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
$mform->display();
|
||||
}
|
||||
print_footer();
|
||||
|
||||
function my_file_get_contents($filename, $use_include_path = 0) {
|
||||
/// Returns the file as one big long string
|
||||
|
||||
$data = "";
|
||||
$file = @fopen($filename, "rb", $use_include_path);
|
||||
if ($file) {
|
||||
while (!feof($file)) {
|
||||
$data .= fread($file, 1024);
|
||||
}
|
||||
fclose($file);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
?>
|
@ -2406,10 +2406,19 @@ function load_capability_def($component) {
|
||||
's/'.$compparts[1].'/db/access.php';
|
||||
$varprefix = $compparts[0].'_'.$compparts[1];
|
||||
} else if ($compparts[0] == 'format') {
|
||||
// Similar to the above, course formats are 'format' while they
|
||||
// Similar to the above, course formats are 'format' while they
|
||||
// are stored in 'course/format'.
|
||||
$defpath = $CFG->dirroot.'/course/'.$component.'/db/access.php';
|
||||
$varprefix = $compparts[0].'_'.$compparts[1];
|
||||
} else if ($compparts[0] == 'gradeimport') {
|
||||
$defpath = $CFG->dirroot.'/grade/import/'.$component.'/db/access.php';
|
||||
$varprefix = $component;
|
||||
} else if ($compparts[0] == 'gradeexport') {
|
||||
$defpath = $CFG->dirroot.'/grade/export/'.$component.'/db/access.php';
|
||||
$varprefix = $component;
|
||||
} else if ($compparts[0] == 'gradereport') {
|
||||
$defpath = $CFG->dirroot.'/grade/report/'.$component.'/db/access.php';
|
||||
$varprefix = $component;
|
||||
} else {
|
||||
$defpath = $CFG->dirroot.'/'.$component.'/db/access.php';
|
||||
$varprefix = str_replace('/', '_', $component);
|
||||
|
@ -39,6 +39,15 @@ function events_load_def($component) {
|
||||
// are stored in 'course/format'.
|
||||
$defpath = $CFG->dirroot.'/course/format/'.$compparts[1].'/db/events.php';
|
||||
|
||||
} else if ($compparts[0] == 'gradeimport') {
|
||||
$defpath = $CFG->dirroot.'/grade/import/'.$compparts[1].'/db/events.php';
|
||||
|
||||
} else if ($compparts[0] == 'gradeexport') {
|
||||
$defpath = $CFG->dirroot.'/grade/export/'.$compparts[1].'/db/events.php';
|
||||
|
||||
} else if ($compparts[0] == 'gradereport') {
|
||||
$defpath = $CFG->dirroot.'/grade/report/'.$compparts[1].'/db/events.php';
|
||||
|
||||
} else {
|
||||
$defpath = $CFG->dirroot.'/'.$component.'/db/events.php';
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user