mirror of
https://github.com/moodle/moodle.git
synced 2025-05-05 07:48:21 +02: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
@ -387,6 +387,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
|
//Unset session variables and destroy it
|
||||||
@session_unset();
|
@session_unset();
|
||||||
@session_destroy();
|
@session_destroy();
|
||||||
|
@ -424,6 +424,10 @@
|
|||||||
require_once($CFG->dirroot.'/admin/mnet/adminlib.php');
|
require_once($CFG->dirroot.'/admin/mnet/adminlib.php');
|
||||||
upgrade_RPC_functions("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
|
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
|
/// just make sure upgrade logging is properly terminated
|
||||||
upgrade_log_finish();
|
upgrade_log_finish();
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
// http://www.gnu.org/copyleft/gpl.html //
|
// http://www.gnu.org/copyleft/gpl.html //
|
||||||
// //
|
// //
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
include_once('../../../config.php');
|
|
||||||
include_once($CFG->dirroot.'/lib/gradelib.php');
|
include_once($CFG->dirroot.'/lib/gradelib.php');
|
||||||
include_once($CFG->dirroot.'/grade/lib.php');
|
include_once($CFG->dirroot.'/grade/lib.php');
|
||||||
/**
|
/**
|
||||||
@ -30,10 +30,15 @@ include_once($CFG->dirroot.'/grade/lib.php');
|
|||||||
* @input int id - course id
|
* @input int id - course id
|
||||||
*/
|
*/
|
||||||
function print_gradeitem_selections($id, $params = NULL) {
|
function print_gradeitem_selections($id, $params = NULL) {
|
||||||
|
global $CFG;
|
||||||
// print all items for selections
|
// print all items for selections
|
||||||
// make this a standard function in lib maybe
|
// 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 '<form action="index.php" method="post">';
|
||||||
echo '<div>';
|
echo '<div>';
|
||||||
foreach ($grade_items as $grade_item) {
|
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 '<input type="submit" value="'.get_string('submit').'" />';
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
echo '</form>';
|
echo '</form>';
|
||||||
}
|
*/
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Base export class
|
* Base export class
|
||||||
@ -159,9 +165,12 @@ class grade_export {
|
|||||||
|
|
||||||
if (!empty($this->students)) {
|
if (!empty($this->students)) {
|
||||||
foreach ($this->students as $student) {
|
foreach ($this->students as $student) {
|
||||||
|
unset($studentgrade);
|
||||||
// add support for comment here MDL-9634
|
// add support for comment here MDL-9634
|
||||||
$studentgrade = $itemgrades[$student->id];
|
|
||||||
|
if (!empty($itemgrades[$student->id])) {
|
||||||
|
$studentgrade = $itemgrades[$student->id];
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($studentgrade->gradevalue)) {
|
if (!empty($studentgrade->gradevalue)) {
|
||||||
$this->grades[$student->id][$gradeitem->id] = $currentstudentgrade = $studentgrade->gradevalue;
|
$this->grades[$student->id][$gradeitem->id] = $currentstudentgrade = $studentgrade->gradevalue;
|
||||||
@ -175,13 +184,14 @@ class grade_export {
|
|||||||
$this->totals[$student->id] = (float)($this->totals[$student->id]) + 0;
|
$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)) {
|
if (!empty($comment)) {
|
||||||
$this->comments[$student->id][$gradeitem->id] = $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 {
|
} else {
|
||||||
$this->comments[$student->id][$gradeitem->id] = '';
|
$this->comments[$student->id][$gradeitem->id] = '';
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ if (($data = data_submitted()) && confirm_sesskey()) {
|
|||||||
|
|
||||||
// print the grades on screen for feedbacks
|
// print the grades on screen for feedbacks
|
||||||
$course = get_record('course', 'id', $id);
|
$course = get_record('course', 'id', $id);
|
||||||
$action = 'exporttxt';
|
$action = 'exportxml';
|
||||||
print_header($course->shortname.': '.get_string('grades'), $course->fullname, grade_nav($course, $action));
|
print_header($course->shortname.': '.get_string('grades'), $course->fullname, grade_nav($course, $action));
|
||||||
|
|
||||||
$export = new grade_export($id, $data->itemids);
|
$export = new grade_export($id, $data->itemids);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
?>
|
@ -2410,6 +2410,15 @@ function load_capability_def($component) {
|
|||||||
// are stored in 'course/format'.
|
// are stored in 'course/format'.
|
||||||
$defpath = $CFG->dirroot.'/course/'.$component.'/db/access.php';
|
$defpath = $CFG->dirroot.'/course/'.$component.'/db/access.php';
|
||||||
$varprefix = $compparts[0].'_'.$compparts[1];
|
$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 {
|
} else {
|
||||||
$defpath = $CFG->dirroot.'/'.$component.'/db/access.php';
|
$defpath = $CFG->dirroot.'/'.$component.'/db/access.php';
|
||||||
$varprefix = str_replace('/', '_', $component);
|
$varprefix = str_replace('/', '_', $component);
|
||||||
|
@ -39,6 +39,15 @@ function events_load_def($component) {
|
|||||||
// are stored in 'course/format'.
|
// are stored in 'course/format'.
|
||||||
$defpath = $CFG->dirroot.'/course/format/'.$compparts[1].'/db/events.php';
|
$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 {
|
} else {
|
||||||
$defpath = $CFG->dirroot.'/'.$component.'/db/events.php';
|
$defpath = $CFG->dirroot.'/'.$component.'/db/events.php';
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user