various grade outcomes and scales improvements, fixes, changes and refactoring

added new favoutcomes plugin settings page - to be used later, this replaces the grade_outcomes_grades table
admin settings - outcomes and scales both have settings page now
This commit is contained in:
skodak
2007-07-30 22:56:45 +00:00
parent d349d4f0e1
commit 173a9d21ea
23 changed files with 822 additions and 415 deletions
+10 -9
View File
@@ -10,6 +10,14 @@ $temp->add(new admin_setting_special_gradeexport());
$temp->add(new admin_setting_configcheckbox('enableoutcomes', get_string('enableoutcomes', 'grades'), get_string('configenableoutcomes', 'grades'), 0, PARAM_INT));
$ADMIN->add('grades', $temp);
/// Scales and outcomes
$scales = new admin_externalpage('scales', get_string('scales'), $CFG->wwwroot.'/grade/edit/scale/index.php', 'moodle/grade:manage');
$ADMIN->add('grades', $scales);
$outcomes = new admin_externalpage('outcomes', get_string('outcomes', 'grades'), $CFG->wwwroot.'/grade/edit/outcome/index.php', 'moodle/grade:manage');
$ADMIN->add('grades', $outcomes);
// The plugins must implement a settings.php file that adds their admin settings to the $settings object
// Reports
@@ -18,14 +26,11 @@ $first = true;
foreach (get_list_of_plugins('grade/report') as $plugin) {
// Include all the settings commands for this plugin if there are any
if ($first) {
$ADMIN->add('grades', new admin_category('gradereports', get_string('reports')));
$ADMIN->add('grades', new admin_category('gradereports', get_string('reportsettings', 'grades')));
$first = false;
}
if ($plugin == 'outcomes') {
$settings = new admin_externalpage('gradereport'.$plugin, get_string('modulename', 'gradereport_'.$plugin), $CFG->wwwroot.'/grade/report/outcomes/site.php');
$ADMIN->add('gradereports', $settings);
} else if (file_exists($CFG->dirroot.'/grade/report/'.$plugin.'/settings.php')) {
if (file_exists($CFG->dirroot.'/grade/report/'.$plugin.'/settings.php')) {
$settings = new admin_settingpage('gradereport'.$plugin, get_string('modulename', 'gradereport_'.$plugin));
include_once($CFG->dirroot.'/grade/report/'.$plugin.'/settings.php');
@@ -46,9 +51,7 @@ foreach (get_list_of_plugins('grade/import') as $plugin) {
}
$settings = new admin_settingpage('gradeimport'.$plugin, get_string('modulename', 'gradeimport_'.$plugin));
include_once($CFG->dirroot.'/grade/import/'.$plugin.'/settings.php');
$ADMIN->add('gradeimports', $settings);
}
}
@@ -66,9 +69,7 @@ foreach (get_list_of_plugins('grade/export') as $plugin) {
}
$settings = new admin_settingpage('gradeexport'.$plugin, get_string('modulename', 'gradeexport_'.$plugin));
include_once($CFG->dirroot.'/grade/export/'.$plugin.'/settings.php');
$ADMIN->add('gradeexports', $settings);
}
}
@@ -1,40 +1,33 @@
<form action="course.php" method="post">
<form action="index.php" method="post">
<div>
<table style="margin-left:auto;margin-right:auto">
<tr>
<td>
<label for="addoutcomes"><?php print_string('globaloutcomes', 'grades'); ?></label>
<br />
<select id="addoutcomes" size="20" name="addoutcomes[]" multiple="multiple">
<?php
foreach ($outcomes as $outcome) {
// do not include items already used in course
if (in_array($outcome->id, array_keys($courseoutcomes))) {
continue;
}
echo '<option value="'.$outcome->id.'">'.truncate($outcome->fullname, 150).'</option>';
echo '<option value="'.$outcome->id.'">'.$outcome->get_name().'</option>';
}
?>
</select>
</td>
<td>
<?php
// only show arrows if user has privilages to manage
if (has_capability('gradereport/outcomes:manage', get_context_instance(CONTEXT_COURSE, $courseid))) {
?>
<p class="arrow_button">
<input name="add" id="add" type="submit" value="<?php echo '&nbsp; '.$THEME->rarrow.' &nbsp; &nbsp; '.get_string('add'); ?>" title="<?php print_string('add'); ?>" />
<br />
<input name="remove" id="remove" type="submit" value="<?php echo '&nbsp;'.$THEME->larrow.' &nbsp; &nbsp; '.get_string('remove'); ?>" title="<?php print_string('remove'); ?>" />
</p>
<?php } ?>
</td>
<td>
<label for="removeoutcomes"><?php print_string('favoutcomes', 'grades'); ?></label>
<br />
<select id="removeoutcomes" size="20" name="removeoutcomes[]" multiple="multiple">
<?php
foreach ($courseoutcomes as $courseoutcome) {
echo '<option value="'.$courseoutcome->id.'">'.truncate($courseoutcome->fullname, 150).'</option>';
foreach ($favoutcomes as $outcome) {
echo '<option value="'.$outcome->id.'">'.$outcome->get_name().'</option>';
}
?>
</select>
+83
View File
@@ -0,0 +1,83 @@
<?php // $Id$
// Allows a creator to edit custom outcomes, and also display help about outcomes
require_once '../../../config.php';
require_once $CFG->dirroot.'/grade/lib.php';
require_once $CFG->libdir.'/gradelib.php';
$courseid = required_param('id', PARAM_INT);
/// Make sure they can even access this course
if (!$course = get_record('course', 'id', $courseid)) {
print_error('nocourseid');
}
require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
require_capability('moodle/course:update', $context);
/// return tracking object
$gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'favoutcomes', 'courseid'=>$courseid));
$strgrades = get_string('grades');
$pagename = get_string('favoutcomes', 'grades');
$navlinks = array(array('name'=>$strgrades, 'link'=>$CFG->wwwroot.'/grade/index.php?id='.$courseid, 'type'=>'misc'),
array('name'=>$pagename, 'link'=>'', 'type'=>'misc'));
$navigation = build_navigation($navlinks);
if ($fav_outcomes_ids = get_user_preferences('grade_favourite_outcomes', null)) {
$fav_outcomes_ids = unserialize($fav_outcomes_ids);
} else {
$fav_outcomes_ids = array();
}
$outcomes = grade_outcome::fetch_all_global();
$favoutcomes = array();
foreach($outcomes as $outcome) {
if (in_array($outcome->id, $fav_outcomes_ids)) {
unset($outcomes[$outcome->id]);
$favoutcomes[$outcome->id] = $outcome;
}
}
// store user preferences
if ($data = data_submitted()) {
if (!empty($data->add) && !empty($data->addoutcomes)) {
/// add all selected to favourite list
foreach ($data->addoutcomes as $add) {
if (isset($outcomes[$add])) {
$outcome = $outcomes[$add];
unset($outcomes[$outcome->id]);
$favoutcomes[$outcome->id] = $outcome;
}
}
} else if (!empty($data->remove) && !empty($data->removeoutcomes)) {
/// remove all selected from favourites
foreach ($data->removeoutcomes as $remove) {
if (isset($favoutcomes[$remove])) {
$outcome = $favoutcomes[$remove];
unset($favoutcomes[$outcome->id]);
$outcomes[$outcome->id] = $outcome;
}
}
}
$pref = array_keys($favoutcomes);
$pref = serialize($pref);
set_user_preference('grade_favourite_outcomes', $pref);
}
/// Print header
print_header_simple($strgrades.': '.$pagename, ': '.$strgrades, $navigation, '', '', true, '', navmenu($course));
/// Print the plugin selector at the top
print_grade_plugin_selector($courseid, 'edit', 'favoutcomes');
check_theme_arrows();
include_once('form.html');
print_footer($course);
?>
+123
View File
@@ -0,0 +1,123 @@
<?php //$Id$
require_once '../../../config.php';
require_once $CFG->dirroot.'/grade/lib.php';
require_once $CFG->dirroot.'/grade/report/lib.php';
require_once 'edit_form.php';
$courseid = optional_param('courseid', 0, PARAM_INT);
$id = optional_param('id', 0, PARAM_INT);
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
// a bit complex access control :-O
if ($id) {
/// editing existing outcome
if (!$outcome_rec = get_record('grade_outcomes', 'id', $id)) {
error('Incorrect outcome id');
}
if ($outcome_rec->courseid) {
$outcome_rec->standard = 0;
if (!$course = get_record('course', 'id', $outcome_rec->courseid)) {
error('Incorrect course id');
}
require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
require_capability('moodle/grade:manage', $context);
$courseid = $course->id;
} else {
if ($courseid) {
if (!$course = get_record('course', 'id', $courseid)) {
error('Incorrect course id');
}
}
$outcome_rec->standard = 1;
$outcome_rec->courseid = $courseid;
require_login();
require_capability('moodle/grade:manage', $systemcontext);
}
} else if ($courseid){
/// adding new outcome from course
if (!$course = get_record('course', 'id', $courseid)) {
print_error('nocourseid');
}
$outcome_rec = new object();
$outcome_rec->standard = 0;
$outcome_rec->courseid = $courseid;
require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
require_capability('moodle/grade:manage', $context);
} else {
/// adding new outcome from admin section
$outcome_rec = new object();
$outcome_rec->standard = 1;
$outcome_rec->courseid = 0;
require_login();
require_capability('moodle/grade:manage', $systemcontext);
}
// default return url
$gpr = new grade_plugin_return();
$returnurl = $gpr->get_return_url('index.php?id='.$courseid);
$mform = new edit_outcome_form(null, array('gpr'=>$gpr));
$mform->set_data($outcome_rec);
if ($mform->is_cancelled()) {
redirect($returnurl);
} else if ($data = $mform->get_data(false)) {
$outcome = new grade_outcome(array('id'=>$id));
$data->usermodified = $USER->id;
grade_outcome::set_properties($outcome, $data);
if (empty($outcome->id)) {
if (!has_capability('moodle/grade:manage', $systemcontext)) {
$data->standard = 0;
}
$outcome->courseid = !empty($data->standard) ? null : $courseid;
if (empty($outcome->courseid)) {
$outcome->courseid = null;
}
$outcome->insert();
} else {
if (isset($data->standard)) {
$outcome->courseid = !empty($data->standard) ? null : $courseid;
} else {
unset($outcome->couseid); // keep previous
}
$outcome->update();
}
redirect($returnurl, 'temp debug delay', 3);
}
$strgrades = get_string('grades');
$strgraderreport = get_string('graderreport', 'grades');
$stroutcomeedit = get_string('outcome', 'grades');
if ($courseid) {
$nav = array(array('name'=>$strgrades,'link'=>$CFG->wwwroot.'/grade/index.php?id='.$courseid, 'type'=>'misc'),
array('name'=>$stroutcomeedit, 'link'=>'', 'type'=>'misc'));
$navigation = build_navigation($nav);
print_header_simple($strgrades.': '.$strgraderreport, ': '.$stroutcomeedit, $navigation, '', '', true, '', navmenu($course));
} else {
require_once $CFG->libdir.'/adminlib.php';
admin_externalpage_setup('outcomes');
admin_externalpage_print_header();
}
$mform->display();
if ($courseid) {
print_footer($course);
} else {
admin_externalpage_print_footer();
}
?>
+132
View File
@@ -0,0 +1,132 @@
<?php //$Id$
require_once $CFG->libdir.'/formslib.php';
class edit_outcome_form extends moodleform {
function definition() {
global $CFG, $COURSE;
$mform =& $this->_form;
// visible elements
$mform->addElement('header', 'general', get_string('outcomes', 'grades'));
$mform->addElement('text', 'fullname', get_string('fullname'));
$mform->addRule('fullname', get_string('required'), 'required');
$mform->setType('fullname', PARAM_TEXT);
$mform->addElement('text', 'shortname', get_string('shortname'));
$mform->addRule('shortname', get_string('required'), 'required');
$mform->setType('shortname', PARAM_NOTAGS);
$mform->addElement('advcheckbox', 'standard', get_string('outcomestandard', 'grades'));
$options = array();
$mform->addElement('select', 'scaleid', get_string('scale'), $options);
$mform->addRule('scaleid', get_string('required'), 'required');
// hidden params
$mform->addElement('hidden', 'id', 0);
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'courseid', 0);
$mform->setType('courseid', PARAM_INT);
/// add return tracking info
$gpr = $this->_customdata['gpr'];
$gpr->add_mform_elements($mform);
//-------------------------------------------------------------------------------
// buttons
$this->add_action_buttons();
}
/// tweak the form - depending on existing data
function definition_after_data() {
global $CFG;
$mform =& $this->_form;
// first load proper scales
if ($courseid = $mform->getElementValue('courseid')) {
$options = array();
if ($scales = grade_scale::fetch_all_local($courseid)) {
$options[-1] = '--'.get_string('scalescustom');
foreach($scales as $scale) {
$options[$scale->id] = $scale->get_name();
}
}
if ($scales = grade_scale::fetch_all_global()) {
$options[-2] = '--'.get_string('scalesstandard');
foreach($scales as $scale) {
$options[$scale->id] = $scale->get_name();
}
}
$scale_el =& $mform->getElement('scaleid');
$scale_el->load($options);
} else {
$options = array();
if ($scales = grade_scale::fetch_all_global()) {
foreach($scales as $scale) {
$options[$scale->id] = $scale->get_name();
}
}
$scale_el =& $mform->getElement('scaleid');
$scale_el->load($options);
}
if ($id = $mform->getElementValue('id')) {
$outcome = grade_outcome::fetch(array('id'=>$id));
$count = $outcome->get_uses_count();
if ($count) {
$mform->hardFreeze('scaleid');
}
if (empty($courseid)) {
$mform->hardFreeze('standard');
} else if (empty($outcome->courseid) and !has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) {
$mform->hardFreeze('standard');
} else if ($count and !empty($outcome->courseid)) {
$mform->hardFreeze('standard');
}
} else {
if (empty($courseid) or !has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) {
$mform->hardFreeze('standard');
}
}
}
/// perform extra validation before submission
function validation($data){
$errors = array();
if ($data['scaleid'] < 1) {
$errors['scaleid'] = get_string('required');
}
if (!empty($data['standard']) and $scale = grade_scale::fetch(array('id'=>$data['scaleid']))) {
if (!empty($scale->courseid)) {
//TODO: localize
$errors['scaleid'] = 'Can not use custom scale in global outcome!';
}
}
if (0 == count($errors)){
return true;
} else {
return $errors;
}
}
}
?>
+163 -1
View File
@@ -1 +1,163 @@
TODO
<?php // $Id$
// Allows a creator to edit custom outcomes, and also display help about outcomes
require_once '../../../config.php';
require_once $CFG->dirroot.'/grade/lib.php';
require_once $CFG->libdir.'/gradelib.php';
$courseid = optional_param('id', 0, PARAM_INT);
$action = optional_param('action', '', PARAM_ALPHA);
/// Make sure they can even access this course
if ($courseid) {
if (!$course = get_record('course', 'id', $courseid)) {
print_error('nocourseid');
}
require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
require_capability('moodle/grade:manage', $context);
} else {
require_once $CFG->libdir.'/adminlib.php';
admin_externalpage_setup('outcomes');
}
/// return tracking object
$gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'outcome', 'courseid'=>$courseid));
$strgrades = get_string('grades');
$pagename = get_string('outcomes', 'grades');
$navlinks = array(array('name'=>$strgrades, 'link'=>$CFG->wwwroot.'/grade/index.php?id='.$courseid, 'type'=>'misc'),
array('name'=>$pagename, 'link'=>'', 'type'=>'misc'));
$navigation = build_navigation($navlinks);
$strshortname = get_string('shortname');
$strfullname = get_string('fullname');
$strscale = get_string('scale');
$strstandardoutcome = get_string('outcomesstandard', 'grades');
$strcustomoutcomes = get_string('outcomescustom', 'grades');
$strdelete = get_string('delete');
$stredit = get_string('edit');
$srtcreatenewoutcome = get_string('outcomecreate', 'grades');
$stractivities = get_string('activities');
$stredit = get_string('edit');
switch ($action) {
case 'delete':
if (!confirm_sesskey()) {
break;
}
$outcomeid = required_param('outcomeid', PARAM_INT);
if (!$outcome = grade_outcome::fetch(array('id'=>$outcomeid))) {
break;
}
if (empty($outcome->courseid)) {
require_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM));
} else if ($outcome->courseid != $courseid) {
error('Incorrect courseid!');
}
if (!$outcome->can_delete()) {
break;
}
//TODO: add confirmation
$outcome->delete();
break;
}
if ($courseid) {
/// Print header
print_header_simple($strgrades.': '.$pagename, ': '.$strgrades, $navigation, '', '', true, '', navmenu($course));
/// Print the plugin selector at the top
print_grade_plugin_selector($courseid, 'edit', 'outcome');
} else {
admin_externalpage_print_header();
}
if ($courseid and $outcomes = grade_outcome::fetch_all_local($courseid)) {
print_heading($strcustomoutcomes);
$data = array();
foreach($outcomes as $outcome) {
$line = array();
$line[] = $outcome->get_name();
$line[] = $outcome->get_shortname();
$scale = $outcome->load_scale();
$line[] = $scale->get_name();
$outcomes_uses = $outcome->get_uses_count();
$line[] = $outcomes_uses;
$buttons = "";
$buttons .= "<a title=\"$stredit\" href=\"edit.php?courseid=$courseid&amp;id=$outcome->id\"><img".
" src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
if (empty($outcomes_uses)) {
$buttons .= "<a title=\"$strdelete\" href=\"index.php?id=$courseid&amp;outcomeid=$outcome->id&amp;action=delete&amp;sesskey=$USER->sesskey\"><img".
" src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
}
$line[] = $buttons;
$data[] = $line;
}
$table = new object();
$table->head = array($strfullname, $strshortname, $strscale, $stractivities, $stredit);
$table->size = array('30%', '20%', '20%', '20%', '10%');
$table->align = array('left', 'left', 'left', 'center', 'center');
$table->width = '90%';
$table->data = $data;
print_table($table);
}
if ($outcomes = grade_outcome::fetch_all_global()) {
print_heading($strstandardoutcome);
$data = array();
foreach($outcomes as $outcome) {
$line = array();
$line[] = $outcome->get_name();
$line[] = $outcome->get_shortname();
$scale = $outcome->load_scale();
$line[] = $scale->get_name();
$outcomes_uses = $outcome->get_uses_count();
$line[] = $outcomes_uses;
$buttons = "";
if (has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) {
$buttons .= "<a title=\"$stredit\" href=\"edit.php?courseid=$courseid&amp;id=$outcome->id\"><img".
" src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
}
if (empty($outcomes_uses) and has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) {
$buttons .= "<a title=\"$strdelete\" href=\"index.php?id=$courseid&amp;outcomeid=$outcome->id&amp;action=delete&amp;sesskey=$USER->sesskey\"><img".
" src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
}
$line[] = $buttons;
$data[] = $line;
}
$table = new object();
$table->head = array($strfullname, $strshortname, $strscale, $stractivities, $stredit);
$table->size = array('30%', '20%', '20%', '20%', '10%');
$table->align = array('left', 'left', 'left', 'center', 'center');
$table->width = '90%';
$table->data = $data;
print_table($table);
}
echo '<div class="buttons">';
print_single_button('edit.php', array('courseid'=>$courseid), $srtcreatenewoutcome);
echo '</div>';
if ($courseid) {
print_footer($course);
} else {
admin_externalpage_print_footer();
}
?>
+74 -38
View File
@@ -5,39 +5,66 @@ require_once $CFG->dirroot.'/grade/lib.php';
require_once $CFG->dirroot.'/grade/report/lib.php';
require_once 'edit_form.php';
$courseid = required_param('courseid', PARAM_INT);
$courseid = optional_param('courseid', 0, PARAM_INT);
$id = optional_param('id', 0, PARAM_INT);
if (!$course = get_record('course', 'id', $courseid)) {
print_error('nocourseid');
}
require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
require_capability('moodle/course:managescales', $context);
// a bit complex access control :-O
if ($id) {
/// editing existing scale
if (!$scale_rec = get_record('scale', 'id', $id)) {
error('Incorrect scale id');
}
if ($scale_rec->courseid) {
$scale_rec->standard = 0;
if (!$course = get_record('course', 'id', $scale_rec->courseid)) {
error('Incorrect course id');
}
require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
require_capability('moodle/course:managescales', $context);
$courseid = $course->id;
} else {
if ($courseid) {
if (!$course = get_record('course', 'id', $courseid)) {
error('Incorrect course id');
}
}
$scale_rec->standard = 1;
$scale_rec->courseid = $courseid;
require_login();
require_capability('moodle/course:managescales', $systemcontext);
}
} else if ($courseid){
/// adding new scale from course
if (!$course = get_record('course', 'id', $courseid)) {
print_error('nocourseid');
}
$scale_rec = new object();
$scale_rec->standard = 0;
$scale_rec->courseid = $courseid;
require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
require_capability('moodle/course:managescales', $context);
} else {
/// adding new scale from admin section
$scale_rec = new object();
$scale_rec->standard = 1;
$scale_rec->courseid = 0;
require_login();
require_capability('moodle/course:managescales', $systemcontext);
}
// default return url
$gpr = new grade_plugin_return();
$returnurl = $gpr->get_return_url('index.php?id='.$course->id);
$returnurl = $gpr->get_return_url('index.php?id='.$courseid);
$mform = new edit_scale_form(null, array('gpr'=>$gpr));
if ($scale = get_record('scale', 'id', $id)) {
$scale->custom = (int)(!empty($scale->courseid));
if (!empty($scale->courseid)) {
require_capability('moodle/course:managescales', $systemcontext);
}
$scale->courseid = $courseid;
$options = new object();
$options->smiley = false;
$options->filter = false;
$options->noclean = false;
$scale->description = format_text($scale->description, FORMAT_MOODLE, $options);
$mform->set_data($scale);
} else {
$mform->set_data(array('courseid'=>$courseid, 'custom'=>1));
}
$mform->set_data($scale_rec);
if ($mform->is_cancelled()) {
redirect($returnurl);
@@ -48,17 +75,17 @@ if ($mform->is_cancelled()) {
grade_scale::set_properties($scale, $data);
if (empty($scale->id)) {
$scale->courseid = $courseid;
if (empty($data->custom) and has_capability('moodle/course:managescales', $systemcontext)) {
$scale->courseid = 0;
if (!has_capability('moodle/grade:manage', $systemcontext)) {
$data->standard = 0;
}
$scale->courseid = !empty($data->standard) ? 0 : $courseid;
$scale->insert();
} else {
if (isset($data->custom)) {
$scale->courseid = $data->custom ? $courseid : 0;
if (isset($data->standard)) {
$scale->courseid = !empty($data->standard) ? 0 : $courseid;
} else {
unset($scale->couseid);
unset($scale->couseid); // keep previous
}
$scale->update();
}
@@ -70,15 +97,24 @@ $strgrades = get_string('grades');
$strgraderreport = get_string('graderreport', 'grades');
$strscaleedit = get_string('scale');
$nav = array(array('name'=>$strgrades,'link'=>$CFG->wwwroot.'/grade/index.php?id='.$courseid, 'type'=>'misc'),
array('name'=>$strscaleedit, 'link'=>'', 'type'=>'misc'));
if ($courseid) {
$nav = array(array('name'=>$strgrades,'link'=>$CFG->wwwroot.'/grade/index.php?id='.$courseid, 'type'=>'misc'),
array('name'=>$strscaleedit, 'link'=>'', 'type'=>'misc'));
$navigation = build_navigation($nav);
print_header_simple($strgrades.': '.$strgraderreport, ': '.$strscaleedit, $navigation, '', '', true, '', navmenu($course));
$navigation = build_navigation($nav);
print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $strscaleedit, $navigation, '', '', true, '', navmenu($course));
} else {
require_once $CFG->libdir.'/adminlib.php';
admin_externalpage_setup('outcomes');
admin_externalpage_print_header();
}
$mform->display();
print_footer($course);
die;
if ($courseid) {
print_footer($course);
} else {
admin_externalpage_print_footer();
}
?>
+19 -7
View File
@@ -14,7 +14,7 @@ class edit_scale_form extends moodleform {
$mform->addRule('name', get_string('required'), 'required', null, 'client');
$mform->setType('name', PARAM_TEXT);
$mform->addElement('advcheckbox', 'custom', get_string('coursescale', 'grades'));
$mform->addElement('advcheckbox', 'standard', get_string('scalestandard'));
$mform->addElement('static', 'activities', get_string('activities'));
@@ -48,21 +48,33 @@ class edit_scale_form extends moodleform {
$mform =& $this->_form;
$courseid = $mform->getElementValue('courseid');
if ($id = $mform->getElementValue('id')) {
$scale = grade_scale::fetch(array('id'=>$id));
if ($count = $scale->get_uses_count()) {
if (empty($scale->courseid)) {
$mform->hardFreeze('custom');
}
$count = $scale->get_uses_count();
if ($count) {
$mform->hardFreeze('scale');
}
if (empty($courseid)) {
$mform->hardFreeze('standard');
} else if (empty($scale->courseid) and !has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) {
$mform->hardFreeze('standard');
} else if ($count and !empty($scale->courseid)) {
$mform->hardFreeze('standard');
}
$activities_el =& $mform->getElement('activities');
$activities_el->setValue(get_string('usedinnplaces', '', $count));
} else {
$mform->removeElement('activities');
if (!has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) {
$mform->hardFreeze('custom');
if (empty($courseid) or !has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) {
$mform->hardFreeze('standard');
}
}
}
+60 -47
View File
@@ -5,16 +5,21 @@ require_once '../../../config.php';
require_once $CFG->dirroot.'/grade/lib.php';
require_once $CFG->libdir.'/gradelib.php';
$courseid = required_param('id', PARAM_INT);
$courseid = optional_param('id', 0, PARAM_INT);
$action = optional_param('action', '', PARAM_ALPHA);
/// Make sure they can even access this course
if (!$course = get_record('course', 'id', $courseid)) {
print_error('nocourseid');
if ($courseid) {
if (!$course = get_record('course', 'id', $courseid)) {
print_error('nocourseid');
}
require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
require_capability('moodle/course:managescales', $context);
} else {
require_once $CFG->libdir.'/adminlib.php';
admin_externalpage_setup('scales');
}
require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
require_capability('moodle/course:managescales', $context);
/// return tracking object
$gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'scale', 'courseid'=>$courseid));
@@ -29,13 +34,13 @@ $navigation = build_navigation($navlinks);
$strscale = get_string('scale');
$strstandardscale = get_string('scalesstandard');
$strcustomscales = get_string('coursescales', 'grades');
$strcustomscales = get_string('scalescustom');
$strname = get_string('name');
$strdelete = get_string('delete');
$stredit = get_string('edit');
$srtcreatenewscale = get_string('scalescustomcreate');
$stractivities = get_string('activities');
$stroptions = get_string('action');
$stredit = get_string('edit');
switch ($action) {
case 'delete':
@@ -49,6 +54,8 @@ switch ($action) {
if (empty($scale->courseid)) {
require_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM));
} else if ($scale->courseid != $courseid) {
error('Incorrect courseid!');
}
if (!$scale->can_delete()) {
@@ -60,16 +67,46 @@ switch ($action) {
break;
}
/// Print header
print_header_simple($strgrades.': '.$pagename, ': '.$strgrades, $navigation,
'', '', true, '', navmenu($course));
if ($courseid) {
/// Print header
print_header_simple($strgrades.': '.$pagename, ': '.$strgrades, $navigation, '', '', true, '', navmenu($course));
/// Print the plugin selector at the top
print_grade_plugin_selector($courseid, 'edit', 'scale');
/// Print the plugin selector at the top
print_grade_plugin_selector($courseid, 'edit', 'scale');
} else {
admin_externalpage_print_header();
}
if ($courseid and $scales = grade_scale::fetch_all_local($courseid)) {
print_heading($strcustomscales);
$data = array();
foreach($scales as $scale) {
$line = array();
$line[] = format_string($scale->name).'<div class="scale_options">'.str_replace(",",", ",$scale->scale).'</div>';
print_heading($strstandardscale);
if ($scales = grade_scale::fetch_all(array('courseid'=>0))) {
$scales_uses = $scale->get_uses_count();
$line[] = $scales_uses;
$buttons = "";
$buttons .= "<a title=\"$stredit\" href=\"edit.php?courseid=$courseid&amp;id=$scale->id\"><img".
" src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
if (empty($scales_uses)) {
$buttons .= "<a title=\"$strdelete\" href=\"index.php?id=$courseid&amp;scaleid=$scale->id&amp;action=delete&amp;sesskey=$USER->sesskey\"><img".
" src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
}
$line[] = $buttons;
$data[] = $line;
}
$table->head = array($strscale, $stractivities, $stredit);
$table->size = array('70%', '20%', '10%');
$table->align = array('left', 'center', 'center');
$table->width = '90%';
$table->data = $data;
print_table($table);
}
if ($scales = grade_scale::fetch_all_global()) {
print_heading($strstandardscale);
$data = array();
foreach($scales as $scale) {
$line = array();
@@ -80,45 +117,17 @@ if ($scales = grade_scale::fetch_all(array('courseid'=>0))) {
$buttons = "";
if (has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) {
$buttons .= "<a title=\"$stredit\" href=\"edit.php?courseid=$course->id&amp;id=$scale->id\"><img".
$buttons .= "<a title=\"$stredit\" href=\"edit.php?courseid=$courseid&amp;id=$scale->id\"><img".
" src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
}
if (empty($scales_uses) and has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) {
$buttons .= "<a title=\"$strdelete\" href=\"index.php?id=$course->id&amp;scaleid=$scale->id&amp;action=delete&amp;sesskey=$USER->sesskey\"><img".
$buttons .= "<a title=\"$strdelete\" href=\"index.php?id=$courseid&amp;scaleid=$scale->id&amp;action=delete&amp;sesskey=$USER->sesskey\"><img".
" src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
}
$line[] = $buttons;
$data[] = $line;
}
$table->head = array($strscale, $stractivities, $stroptions);
$table->size = array('70%', '20%', '10%');
$table->align = array('left', 'center', 'center');
$table->width = '90%';
$table->data = $data;
print_table($table);
}
print_heading($strcustomscales);
if ($scales = grade_scale::fetch_all(array('courseid'=>$courseid))) {
$data = array();
foreach($scales as $scale) {
$line = array();
$line[] = format_string($scale->name).'<div class="scale_options">'.str_replace(",",", ",$scale->scale).'</div>';
$scales_uses = $scale->get_uses_count();
$line[] = $scales_uses;
$buttons = "";
$buttons .= "<a title=\"$stredit\" href=\"edit.php?courseid=$course->id&amp;id=$scale->id\"><img".
" src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
if (empty($scales_uses)) {
$buttons .= "<a title=\"$strdelete\" href=\"index.php?id=$course->id&amp;scaleid=$scale->id&amp;action=delete&amp;sesskey=$USER->sesskey\"><img".
" src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
}
$line[] = $buttons;
$data[] = $line;
}
$table->head = array($strscale, $stractivities, $stroptions);
$table->head = array($strscale, $stractivities, $stredit);
$table->size = array('70%', '20%', '10%');
$table->align = array('left', 'center', 'center');
$table->width = '90%';
@@ -130,7 +139,11 @@ echo '<div class="buttons">';
print_single_button('edit.php', array('courseid'=>$courseid), $srtcreatenewscale);
echo '</div>';
print_footer($course);
if ($courseid) {
print_footer($course);
} else {
admin_externalpage_print_footer();
}
?>
+9 -1
View File
@@ -113,13 +113,21 @@ function print_grade_plugin_selector($courseid, $active_type, $active_plugin, $r
$menu[$url] = get_string('scales');
}
if (has_capability('moodle/grade:manage', $context)) { // TODO: add outcome cap
if (has_capability('moodle/grade:manage', $context)) {
$url = 'edit/outcome/index.php?id='.$courseid;
if ($active_type == 'edit' and $active_plugin == 'outcome' ) {
$active = $url;
}
$menu[$url] = get_string('outcomes', 'grades');
}
if (has_capability('course:update', $context)) {
$url = 'edit/favoutcomes/index.php?id='.$courseid;
if ($active_type == 'edit' and $active_plugin == 'favoutcomes' ) {
$active = $url;
}
$menu[$url] = get_string('favouriteoutcomes', 'grades');
}
}
/// finally print/return the popup form
+2 -2
View File
@@ -743,7 +743,7 @@ class grade_report_grader extends grade_report {
$groupwheresql = null;
}
if ($meanselection == GRADE_AGGREGATE_MEAN_GRADED) {
if ($meanselection == GRADE_AGGREGATE_MEAN_GRADED) {
$totalcount = 0;
} else {
$totalcount = $this->get_numusers();
@@ -768,7 +768,7 @@ class grade_report_grader extends grade_report {
$sum_array[$itemid] = $csum->sum;
if ($totalcount) {
$count_array[$itemid] = $totalcount;
} else {
} else {
$count_array[$itemid] = $csum->count;
}
}
-178
View File
@@ -1,178 +0,0 @@
<?php
/*********************************
* Course outcomes editting page *
*********************************/
include_once('../../../config.php');
require_once($CFG->libdir.'/tablelib.php');
require_once $CFG->dirroot.'/grade/lib.php';
$page = optional_param('page', 0, PARAM_INT); // current page
$search = optional_param('search', 0, PARAM_TEXT);
$deleteid = optional_param('deleteid', 0, PARAM_INT); // which outcome to delete
$confirm = optional_param('confirm', 0, PARAM_INT);
$perpage = 30;
$courseid = required_param('id', PARAM_INT); // course id
if (!$course = get_record('course', 'id', $courseid)) {
print_error('nocourseid');
}
require_login($courseid);
require_capability('gradereport/outcomes:view', get_context_instance(CONTEXT_SYSTEM));
/// form processing
if ($deleteid && confirm_sesskey()) {
require_capability('gradereport/outcomes:manage', get_context_instance(CONTEXT_COURSE, $courseid));
if ($confirm) {
// delete all outcomes used in courses
// delete all outcomes used in grade items
delete_records('grade_outcomes_courses', 'outcomeid', $deleteid);
delete_records('grade_outcomes', 'id', $deleteid);
} else {
// prints confirmation
$strgrades = get_string('grades');
$stroutcomes = get_string('outcomes', 'grades');
$navlinks = array();
$navlinks[] = array('name' => $strgrades, 'link' => $CFG->wwwroot . '/grade/index.php?id='.$courseid, 'type' => 'misc');
$navlinks[] = array('name' => $stroutcomes, 'link' => '', 'type' => 'misc');
$navigation = build_navigation($navlinks);
/// Print header
print_header_simple($strgrades.':'.$stroutcomes, ':'.$strgrades, $navigation, '', '', true);
$strdeleteoutcomecheck = get_string('deleteoutcomecheck', 'grades');
notice_yesno($strdeleteoutcomecheck,
'course.php?id='.$courseid.'&amp;deleteid='.$deleteid.'&amp;confirm=1&amp;sesskey='.sesskey(),
'course.php?id='.$courseid.'&amp;');
print_footer();
exit;
}
}
if ($data = data_submitted()) {
require_capability('gradereport/outcomes:manage', get_context_instance(CONTEXT_COURSE, $courseid));
if (!empty($data->add) && !empty($data->addoutcomes)) {
/// add all selected to course list
foreach ($data->addoutcomes as $add) {
$goc -> courseid = $courseid;
$goc -> outcomeid = $add;
insert_record('grade_outcomes_courses', $goc);
}
} else if (!empty($data->remove) && !empty($data->removeoutcomes)) {
/// remove all selected from course outcomes list
foreach ($data->removeoutcomes as $remove) {
delete_records('grade_outcomes_courses', 'courseid', $courseid, 'outcomeid', $remove);
}
}
}
// Build navigation
$strgrades = get_string('grades');
$stroutcomes = get_string('outcomes', 'grades');
$navlinks = array();
$navlinks[] = array('name' => $strgrades, 'link' => $CFG->wwwroot . '/grade/index.php?id='.$courseid, 'type' => 'misc');
$navlinks[] = array('name' => $stroutcomes, 'link' => '', 'type' => 'misc');
$navigation = build_navigation($navlinks);
/// Print header
print_header_simple($strgrades.':'.$stroutcomes, ':'.$strgrades, $navigation, '', '', true);
print_grade_plugin_selector($courseid, 'report', 'outcomes');
// Add tabs
$currenttab = 'courseoutcomes';
include('tabs.php');
/// listing of all site outcomes + this course specific outcomes
$outcomes = get_records_sql('SELECT * FROM '.$CFG->prefix.'grade_outcomes
WHERE courseid IS NULL');
// outcomes used in this course
$courseoutcomes = get_records_sql('SELECT go.id, go.fullname
FROM '.$CFG->prefix.'grade_outcomes_courses goc,
'.$CFG->prefix.'grade_outcomes go
WHERE goc.courseid = '.$courseid.'
AND goc.outcomeid = go.id');
if (empty($courseoutcomes)) {
$courseoutcomes = get_records('grade_outcomes', 'courseid', $courseid);
} elseif ($mcourseoutcomes = get_records('grade_outcomes', 'courseid', $courseid)) {
$courseoutcomes += $mcourseoutcomes;
}
check_theme_arrows();
include_once('course.html');
/// interface to add/edit/delete course specific outcomes
echo '<p/>';
print_heading(get_string('coursespecoutcome', 'gradereport_outcomes')); // course sepcific outcomes
$totalcount = count_records('grade_outcomes_courses', 'courseid', $courseid);
$baseurl = "course.php";
print_paging_bar($totalcount, $page, $perpage, $baseurl);
if ($outcomes = get_recordset('grade_outcomes', 'courseid', $courseid, '', '*', $page * $perpage, $perpage)) {
$tablecolumns = array('outcome', 'scale', 'edit', 'usedgradeitems');
$tableheaders = array(get_string('outcomes', 'grades'),
get_string('scale'),
'',
get_string('activities'));
$table = new flexible_table('outcomes');
$table->define_columns($tablecolumns);
$table->define_headers($tableheaders);
$table->define_baseurl($baseurl);
$table->set_attribute('cellspacing', '0');
$table->set_attribute('id', 'user-grade');
$table->set_attribute('class', 'boxaligncenter generaltable');
$table->setup();
while ($outcome = rs_fetch_next_record($outcomes)) {
$data = array();
// full name of the outcome
$data[] = $outcome->fullname;
// full name of the scale used by this outcomes
$scale= get_record('scale', 'id', $outcome->scaleid);
$data[] = $scale->name;
if (has_capability('gradereport/outcomes:manage', get_context_instance(CONTEXT_COURSE, $courseid))) {
// add operations
$data[] = '<a href="editoutcomes.php?id='.$outcome->id.'&amp;courseid='.$courseid.'&amp;sesskey='.sesskey().'"><img alt="Update" class="iconsmall" src="'.$CFG->wwwroot.'/pix/t/edit.gif"/></a>
<a href="course.php?deleteid='.$outcome->id.'&amp;id='.$courseid.'&amp;sesskey='.sesskey().'"><img alt="Delete" class="iconsmall" src="'.$CFG->wwwroot.'/pix/t/delete.gif"/></a>'; // icons and links
} else {
$data[] = '';
}
// num of gradeitems using this
$num = count_records('grade_items', 'outcomeid' ,$outcome->id);
$data[] = (int) $num;
// num of courses using this outcome
$table->add_data($data);
}
$table->print_html();
}
if (has_capability('gradereport/outcomes:manage', get_context_instance(CONTEXT_COURSE, $courseid))) {
echo '<a href="editoutcomes.php?courseid='.$courseid.'">'.get_string('addoutcome', 'gradereport_outcomes').'</a>';
}
print_footer();
/**
* truncates a string to a length of num
* @param string string
* @param int num
* @return string
*/
function truncate($string, $num) {
if (strlen($string) > $num + 3) {
$text = substr($string, 0, $num);
$text = $text."...";
}
return $string;
}
?>
-10
View File
@@ -11,16 +11,6 @@ $gradereport_outcomes_capabilities = array(
'editingteacher' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
'gradereport/outcomes:manage' => array(
'riskbitmask' => RISK_CONFIG,
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'editingteacher' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
)
);
+19 -28
View File
@@ -4,16 +4,17 @@ include_once('../../../config.php');
require_once($CFG->libdir . '/gradelib.php');
require_once $CFG->dirroot.'/grade/lib.php';
$courseid = required_param('id'); // course id
$courseid = required_param('id', PARAM_INT); // course id
if (!$course = get_record('course', 'id', $courseid)) {
print_error('nocourseid');
}
require_login($course->id);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
require_capability('gradereport/outcomes:view', $context);
// Build navigation
$strgrades = get_string('grades');
$stroutcomes = get_string('outcomes', 'grades');
@@ -26,43 +27,27 @@ $navigation = build_navigation($navlinks);
/// Print header
print_header_simple($strgrades.':'.$stroutcomes, ':'.$strgrades, $navigation, '', '', true);
print_grade_plugin_selector($courseid, 'report', 'outcomes');
// Add tabs
$currenttab = 'outcomereport';
include('tabs.php');
// Grab all outcomes, distinguishing between site-level and course-level outcomes
$sql = "SELECT mdl_grade_outcomes.id,
mdl_grade_outcomes_courses.courseid,
mdl_grade_outcomes.shortname,
mdl_grade_outcomes.scaleid
FROM mdl_grade_outcomes
LEFT JOIN mdl_grade_outcomes_courses
ON (mdl_grade_outcomes.id = mdl_grade_outcomes_courses.outcomeid AND mdl_grade_outcomes_courses.courseid = $courseid)
ORDER BY mdl_grade_outcomes_courses.courseid DESC";
//first make sure we have proper final grades
grade_regrade_final_grades($courseid);
// Grab all outcomes used in course
$sql = "SELECT go.* FROM {$CFG->prefix}grade_outcomes go
WHERE go.id IN (SELECT gi.outcomeid FROM {$CFG->prefix}grade_items gi WHERE gi.courseid = $courseid)";
$report_info = array();
$outcomes = get_records_sql($sql);
// Get grade_items that use each outcome
foreach ($outcomes as $outcomeid => $outcome) {
$sql = "SELECT mdl_grade_items.id,
mdl_grade_items.itemname,
mdl_grade_items.itemmodule,
mdl_grade_items.iteminstance,
mdl_grade_items.itemtype,
mdl_grade_items.itemnumber,
mdl_grade_items.courseid,
mdl_grade_items.idnumber
FROM mdl_grade_items
WHERE mdl_grade_items.outcomeid = $outcomeid";
$report_info[$outcomeid]['items'] = get_records_sql($sql);
$report_info[$outcomeid]['items'] = get_records_select('grade_items', "outcomeid = $outcomeid AND courseid = $courseid");
$report_info[$outcomeid]['outcome'] = $outcome;
// Get average grades for each item
if (is_array($report_info[$outcomeid]['items'])) {
foreach ($report_info[$outcomeid]['items'] as $itemid => $item) {
$sql = "SELECT id, AVG(finalgrade) AS `avg`, COUNT(finalgrade) AS `count`
FROM mdl_grade_grades
FROM {$CFG->prefix}grade_grades
WHERE itemid = $itemid
GROUP BY itemid";
$info = get_records_sql($sql);
@@ -113,8 +98,14 @@ foreach ($report_info as $outcomeid => $outcomedata) {
$items_html .= "<tr>\n";
}
$cm = get_coursemodule_from_instance($item->itemmodule, $item->iteminstance, $item->courseid);
$itemname = '<a href="'.$CFG->wwwroot.'/mod/'.$item->itemmodule.'/view.php?id='.$cm->id.'">'.$item->itemname.'</a>';
$grade_item = new grade_item($item, false);
if ($item->itemtype == 'mod') {
$cm = get_coursemodule_from_instance($item->itemmodule, $item->iteminstance, $item->courseid);
$itemname = '<a href="'.$CFG->wwwroot.'/mod/'.$item->itemmodule.'/view.php?id='.$cm->id.'">'.$item->itemname.'</a>';
} else {
$itemname = $grade_item->get_name();
}
$outcomedata['outcome']->sum += $item->avg;
$gradehtml = $scale->get_nearest_item($item->avg);
+1 -1
View File
@@ -1,6 +1,6 @@
<?PHP // $Id$
$plugin->version = 2007072501;
$plugin->version = 2007073000;
$plugin->requires = 2007072402;
?>
+5
View File
@@ -221,9 +221,13 @@ $string['numberofgrades'] = 'Number of grades';
$string['onascaleof'] = ' on a scale of $a->grademin to $a->grademax';
$string['operations'] = 'Operations';
$string['outcome'] = 'Outcome';
$string['outcomecreate'] = 'Add a new outcome';
$string['outcomes'] = 'Outcomes';
$string['outcomescustom'] = 'Custom outcomes';
$string['outcomename'] = 'Outcome name';
$string['outcomereport'] = 'Outcome report';
$string['outcomesstandard'] = 'Standard outcomes';
$string['outcomestandard'] = 'Standard outcome';
$string['outcomes'] = 'Outcomes';
$string['overridden'] = 'Overridden';
$string['overallavg'] = 'Overall average';
@@ -251,6 +255,7 @@ $string['rank'] = 'Rank';
$string['real'] = 'Real';
$string['rawpct'] = 'Raw %%';
$string['reportplugins'] = 'Report plugins';
$string['reportsettings'] = 'Report settings';
$string['reprintheaders'] = 'Reprint Headers';
$string['right'] = 'Right';
$string['savechanges'] = 'Save Changes';
+1
View File
@@ -1222,6 +1222,7 @@ $string['scalescustom'] = 'Custom scales';
$string['scalescustomcreate'] = 'Add a new scale';
$string['scalescustomno'] = 'No custom scales have been created yet';
$string['scalesstandard'] = 'Standard scales';
$string['scalestandard'] = 'Standard scale';
$string['scalestip'] = 'To create custom scales, use the \'Scales...\' link in your course administration menu.';
$string['schedule'] = 'Schedule';
$string['scheduledbackupstatus'] = 'Scheduled backup status';
+3 -16
View File
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="20070725" COMMENT="XMLDB file for core Moodle tables"
<XMLDB PATH="lib/db" VERSION="20070730" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
@@ -1274,7 +1274,7 @@
<KEY NAME="handlerid" TYPE="foreign" FIELDS="handlerid" REFTABLE="events_handlers" REFFIELDS="id" PREVIOUS="queuedeventid"/>
</KEYS>
</TABLE>
<TABLE NAME="grade_outcomes" COMMENT="This table describes the outcomes used in the system. An outcome is a statement tied to a rubric scale from low to high, such as “Not met, Borderline, Met” (stored as 0,1 or 2)" PREVIOUS="events_queue_handlers" NEXT="grade_outcomes_courses">
<TABLE NAME="grade_outcomes" COMMENT="This table describes the outcomes used in the system. An outcome is a statement tied to a rubric scale from low to high, such as “Not met, Borderline, Met” (stored as 0,1 or 2)" PREVIOUS="events_queue_handlers" NEXT="grade_categories">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" COMMENT="id of the table, please edit me" NEXT="courseid"/>
<FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="Mostly these are defined site wide ie NULL" PREVIOUS="id" NEXT="shortname"/>
@@ -1292,20 +1292,7 @@
<KEY NAME="usermodified" TYPE="foreign" FIELDS="usermodified" REFTABLE="user" REFFIELDS="id" PREVIOUS="scaleid"/>
</KEYS>
</TABLE>
<TABLE NAME="grade_outcomes_courses" COMMENT="stores what outcomes are used in what courses." PREVIOUS="grade_outcomes" NEXT="grade_categories">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" SEQUENCE="true" ENUM="false" COMMENT="id of the table, please edit me" NEXT="courseid"/>
<FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="id of the course" PREVIOUS="id" NEXT="outcomeid"/>
<FIELD NAME="outcomeid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="id of the outcome" PREVIOUS="courseid"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="primary key of the table, please edit me" NEXT="courseid"/>
<KEY NAME="courseid" TYPE="foreign" FIELDS="courseid" REFTABLE="course" REFFIELDS="id" PREVIOUS="primary" NEXT="outcomeid"/>
<KEY NAME="outcomeid" TYPE="foreign" FIELDS="outcomeid" REFTABLE="grade_outcomes" REFFIELDS="id" PREVIOUS="courseid" NEXT="courseid-outcomeid"/>
<KEY NAME="courseid-outcomeid" TYPE="unique" FIELDS="courseid, outcomeid" PREVIOUS="outcomeid"/>
</KEYS>
</TABLE>
<TABLE NAME="grade_categories" COMMENT="This table keeps information about categories, used for grouping items." PREVIOUS="grade_outcomes_courses" NEXT="grade_items">
<TABLE NAME="grade_categories" COMMENT="This table keeps information about categories, used for grouping items." PREVIOUS="grade_outcomes" NEXT="grade_items">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" COMMENT="id of the table, please edit me" NEXT="courseid"/>
<FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="The course this grade category is part of" PREVIOUS="id" NEXT="parent"/>
+6 -25
View File
@@ -1059,23 +1059,6 @@ function xmldb_main_upgrade($oldversion=0) {
$result = $result && create_table($table);
/// Define table grade_outcomes_courses to be created
$table = new XMLDBTable('grade_outcomes_courses');
/// Adding fields to table grade_outcomes_courses
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('outcomeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
/// Adding keys to table grade_outcomes_courses
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
$table->addKeyInfo('outcomeid', XMLDB_KEY_FOREIGN, array('outcomeid'), 'grade_outcomes', array('id'));
/// Launch create table for grade_outcomes_courses
$result = $result && create_table($table);
/// Define table grade_categories to be created
$table = new XMLDBTable('grade_categories');
@@ -1451,16 +1434,14 @@ function xmldb_main_upgrade($oldversion=0) {
$result = $result && change_field_default($table, $field);
}
if ($result && $oldversion < 2007072500) {
/// Define key courseid-outcomeid (unique) to be added to grade_outcomes_courses
if ($result && $oldversion < 2007073000) {
// not used anymore
$table = new XMLDBTable('grade_outcomes_courses');
$key = new XMLDBKey('courseid-outcomeid');
$key->setAttributes(XMLDB_KEY_UNIQUE, array('courseid', 'outcomeid'));
/// Launch add key courseid-outcomeid
$result = $result && add_key($table, $key);
if (table_exists($table)) {
drop_table($table);
}
}
/*
/// drop old gradebook tables
if ($result && $oldversion < 2007072209) {
+65 -35
View File
@@ -86,16 +86,7 @@ class grade_outcome extends grade_object {
* @return object grade_outcome instance or false if none found.
*/
function fetch($params) {
if ($outcome = grade_object::fetch_helper('grade_outcomes', 'grade_outcome', $params)) {
if (!empty($outcome->scaleid)) {
$outcome->scale = new grade_scale(array('id'=>$outcome->scaleid));
$outcome->scale->load_items();
}
return $outcome;
} else {
return false;
}
return grade_object::fetch_helper('grade_outcomes', 'grade_outcome', $params);
}
/**
@@ -103,34 +94,38 @@ class grade_outcome extends grade_object {
* @static
*
* @param array $params associative arrays varname=>value
* @param bool $fetch_sitewide_outcomes Whether or not to also fetch all sitewide outcomes (with no courseid)
* @return array array of grade_outcome insatnces or false if none found.
*/
function fetch_all($params, $fetch_sitewide_outcomes=false) {
global $CFG;
function fetch_all($params) {
return grade_object::fetch_all_helper('grade_outcomes', 'grade_outcome', $params);
}
if ($outcomes = grade_object::fetch_all_helper('grade_outcomes', 'grade_outcome', $params)) {
// Fetch sitewide outcomes if requested
if ($fetch_sitewide_outcomes) {
$sitewide_outcomes = array();
$records = get_records_sql("SELECT * FROM {$CFG->prefix}grade_outcomes WHERE courseid IS NULL");
foreach ($records as $outcomeid => $outcome) {
$sitewide_outcomes[$outcomeid] = new grade_outcome($outcome, false);
}
$outcomes = array_merge($sitewide_outcomes, $outcomes);
}
foreach ($outcomes as $key=>$value) {
if (!empty($outcomes[$key]->scaleid)) {
$outcomes[$key]->scale = new grade_scale(array('id'=>$outcomes[$key]->scaleid));
$outcomes[$key]->scale->load_items();
}
}
return $outcomes;
} else {
return false;
/**
* Instantiates a grade_scale object whose data is retrieved from the
* @return object grade_scale
*/
function load_scale() {
if (empty($this->scale->id) or $this->scale->id != $this->scaleid) {
$this->scale = grade_scale::fetch(array('id'=>$this->scaleid));
$this->scale->load_items();
}
return $this->scale;
}
/**
* Static function returning all global outcomes
* @return object
*/
function fetch_all_global() {
return grade_outcome::fetch_all(array('courseid'=>null));
}
/**
* Static function returning all local course outcomes
* @return object
*/
function fetch_all_local($courseid) {
return grade_outcome::fetch_all(array('courseid'=>$courseid));
}
/**
@@ -139,7 +134,42 @@ class grade_outcome extends grade_object {
* @return string name
*/
function get_name() {
return $this->shortname;
return format_string($this->fullname);
}
/**
* Returns outcome short name.
* @return string name
*/
function get_shortname() {
return format_string($this->shortname);
}
/**
* Checks if outcome can be deleted.
* @return boolean
*/
function can_delete() {
$count = $this->get_uses_count();
return empty($count);
}
/**
* Returns the number of places where outcome is used.
* @return int
*/
function get_uses_count() {
global $CFG;
$count = 0;
// count grade items
$sql = "SELECT COUNT(id) FROM {$CFG->prefix}grade_items WHERE outcomeid = {$this->id}";
if ($scales_uses = count_records_sql($sql)) {
$count += $scales_uses;
}
return $count;
}
/**
+26 -1
View File
@@ -96,6 +96,15 @@ class grade_scale extends grade_object {
return grade_object::fetch_all_helper('scale', 'grade_scale', $params);
}
/**
* Returns the most descriptive field for this object. This is a standard method used
* when we do not know the exact type of an object.
* @return string name
*/
function get_name() {
return format_string($this->name);
}
/**
* Loads the scale's items into the $scale_items array.
* There are three ways to achieve this:
@@ -171,7 +180,23 @@ class grade_scale extends grade_object {
}
/**
* Determines if scale can be deleted.
* Static function returning all global scales
* @return object
*/
function fetch_all_global() {
return grade_scale::fetch_all(array('courseid'=>0));
}
/**
* Static function returning all local course scales
* @return object
*/
function fetch_all_local($courseid) {
return grade_scale::fetch_all(array('courseid'=>$courseid));
}
/**
* Checks if scale can be deleted.
* @return boolean
*/
function can_delete() {
+12
View File
@@ -2158,6 +2158,18 @@ body#doc-contents ul {
padding: 5px;
}
/* outcomes edit */
.grade-edit-outcome .buttons {
margin: 20px;
text-align:center;
}
.grade-edit-outcome .buttons .singlebutton {
display: inline;
padding: 5px;
}
/* gradebook edit tree */
.grade-edit-tree .gradetreebox {
+1 -1
View File
@@ -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 = 2007072500; // YYYYMMDD = date
$version = 2007073000; // YYYYMMDD = date
// XY = increments within a single day
$release = '1.9 dev'; // Human-friendly version name