tabbed Edit/Outcomes interface, link from course admin block, added manage outcomes capability, other cleanup

This commit is contained in:
skodak 2007-07-31 09:10:35 +00:00
parent b2af9c5895
commit 042596946b
13 changed files with 67 additions and 285 deletions

View File

@ -155,6 +155,12 @@ class block_admin extends block_list {
$this->content->icons[] = '<img src="'.$CFG->pixpath.'/i/payment.gif" class="icon" alt="" />';
}
/// Used outcomes
if (has_capability('moodle/course:update', $context) && ($course->id!==SITEID)) {
$this->content->items[]='<a href="'.$CFG->wwwroot.'/grade/edit/outcome/course.php?id='.$this->instance->pageid.'">'.get_string('outcomes', 'grades').'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/grades.gif" class="icon" alt="" />'; //TODO: add outcomes icon
}
/// View course grades (or just your own grades, same link)
if ((has_capability('moodle/grade:viewall', $context) or
(has_capability('moodle/grade:view', $context) && $course->showgrades)) && ($course->id!==SITEID)) {

View File

@ -17,7 +17,7 @@ require_capability('moodle/course:update', $context);
/// form processing
if ($data = data_submitted()) {
require_capability('gradereport/outcomes:manage', get_context_instance(CONTEXT_COURSE, $courseid));
require_capability('moodle/grade:manageoutcomes', get_context_instance(CONTEXT_COURSE, $courseid));
if (!empty($data->add) && !empty($data->addoutcomes)) {
/// add all selected to course list
foreach ($data->addoutcomes as $add) {
@ -34,10 +34,10 @@ if ($data = data_submitted()) {
}
/// return tracking object
$gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'favoutcomes', 'courseid'=>$courseid));
$gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'outcomes', 'courseid'=>$courseid));
$strgrades = get_string('grades');
$pagename = get_string('courseoutcomes', 'grades');
$pagename = get_string('outcomescourse', 'grades');
$navlinks = array(array('name'=>$strgrades, 'link'=>$CFG->wwwroot.'/grade/index.php?id='.$courseid, 'type'=>'misc'),
array('name'=>$pagename, 'link'=>'', 'type'=>'misc'));
@ -51,7 +51,7 @@ if ($coutcomes = get_records_sql('SELECT go.id, go.fullname
WHERE goc.courseid = '.$courseid.'
AND goc.outcomeid = go.id')) {
foreach ($coutcomes as $id=>$coutcome) {
$courseoutcomes[$id] = new grade_outcome(array('id'=>$id));
$courseoutcomes[$id] = new grade_outcome(array('id'=>$id));
}
}
@ -64,11 +64,13 @@ if (empty($courseoutcomes)) {
print_header_simple($strgrades.': '.$pagename, ': '.$strgrades, $navigation, '', '', true, '', navmenu($course));
/// Print the plugin selector at the top
print_grade_plugin_selector($courseid, 'edit', 'courseoutcomes');
print_heading(get_string('courseoutcomes', 'grades'));
print_grade_plugin_selector($courseid, 'edit', 'outcome');
$currenttab = 'courseoutcomes';
require('tabs.php');
check_theme_arrows();
include_once('form.html');
require('course_form.html');
print_footer($course);
?>

View File

@ -3,7 +3,7 @@
<table style="margin-left:auto;margin-right:auto">
<tr>
<td>
<label for="addoutcomes"><?php print_string('globaloutcomes', 'grades'); ?></label>
<label for="addoutcomes"><?php print_string('outcomesstandard', 'grades'); ?></label>
<br />
<select id="addoutcomes" size="20" name="addoutcomes[]" multiple="multiple">
@ -25,7 +25,7 @@
</p>
</td>
<td>
<label for="removeoutcomes"><?php print_string('courseoutcomes', 'grades'); ?></label>
<label for="removeoutcomes"><?php print_string('outcomescourse', 'grades'); ?></label>
<br />
<select id="removeoutcomes" size="20" name="removeoutcomes[]" multiple="multiple">
<?php

View File

@ -75,6 +75,9 @@ if ($courseid) {
/// Print the plugin selector at the top
print_grade_plugin_selector($courseid, 'edit', 'outcome');
$currenttab = 'outcomes';
require('tabs.php');
} else {
admin_externalpage_print_header();
}

View File

@ -0,0 +1,21 @@
<?php // $Id$
$row = $tabs = array();
$coursecontext = get_context_instance(CONTEXT_COURSE, $courseid);
if (has_capability('moodle/grade:manage', $context)) {
$row[] = new tabobject('outcomes',
$CFG->wwwroot.'/grade/edit/outcome/index.php?id='.$courseid,
get_string('outcomes', 'grades'));
}
$row[] = new tabobject('courseoutcomes',
$CFG->wwwroot.'/grade/edit/outcome/course.php?id='.$courseid,
get_string('outcomescourse', 'grades'));
$tabs[] = $row;
echo '<div class="outcomedisplay">';
print_tabs($tabs, $currenttab);
echo '</div>';
?>

View File

@ -94,7 +94,8 @@ function print_grade_plugin_selector($courseid, $active_type, $active_plugin, $r
/// editing scripts - not real plugins
if (has_capability('moodle/grade:manage', $context)
or has_capability('moodle/course:managescales', $context)) {
or has_capability('moodle/course:managescales', $context)
or has_capability('moodle/course:update', $context)) {
$menu['edit']='--'.get_string('edit');
if (has_capability('moodle/grade:manage', $context)) {
@ -113,21 +114,17 @@ function print_grade_plugin_selector($courseid, $active_type, $active_plugin, $r
$menu[$url] = get_string('scales');
}
if (has_capability('moodle/grade:manage', $context)) {
$url = 'edit/outcome/index.php?id='.$courseid;
if (has_capability('moodle/grade:manage', $context) or has_capability('course:update', $context)) {
if (has_capability('moodle/grade:manage', $context)) {
$url = 'edit/outcome/index.php?id='.$courseid;
} else {
$url = 'edit/outcome/course.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/courseoutcomes/index.php?id='.$courseid;
if ($active_type == 'edit' and $active_plugin == 'courseoutcomes' ) {
$active = $url;
}
$menu[$url] = get_string('courseoutcomes', 'grades');
}
}
/// finally print/return the popup form

View File

@ -748,7 +748,7 @@ class grade_report_grader extends grade_report {
} else {
$totalcount = $this->get_numusers();
}
if ($showaverages) {
/*
* this sql is broken in the event of multiple grade book roles assigned to one user
@ -765,7 +765,7 @@ class grade_report_grader extends grade_report {
AND ra.contextid ".get_related_contexts_string($this->context)."
GROUP BY g.itemid";
*/
// the first join on user is needed for groupsql
$SQL = "SELECT g.itemid, SUM(g.finalgrade) as sum, COUNT(DISTINCT(u.id)) as count
FROM {$CFG->prefix}grade_items gi LEFT JOIN
@ -774,15 +774,15 @@ class grade_report_grader extends grade_report {
$groupsql
WHERE gi.courseid = $this->courseid
$groupwheresql
AND g.userid IN (
SELECT DISTINCT(u.id)
AND g.userid IN (
SELECT DISTINCT(u.id)
FROM {$CFG->prefix}user u LEFT JOIN
{$CFG->prefix}role_assignments ra ON u.id = ra.userid
WHERE ra.roleid in ($this->gradebookroles)
AND ra.contextid ".get_related_contexts_string($this->context)."
)
GROUP BY g.itemid";
$sum_array = array();
$count_array = array();
$sums = get_records_sql($SQL);

View File

@ -1,98 +0,0 @@
<?php
include_once('../../../config.php');
require_once $CFG->libdir.'/formslib.php';
// courseid needs to be passed in to know whether this should be tied to a course
class edit_outcomes_form extends moodleform {
function definition() {
global $CFG, $COURSE;
$mform =& $this->_form;
$mform->addElement('header', 'general', get_string('outcomes'));
$mform->addElement('text', 'shortname', get_string('shortname'));
$mform->addRule('shortname', get_string('required'), 'required');
$mform->setType('shortname', PARAM_TEXT);
$mform->addElement('text', 'fullname', get_string('fullname'));
$mform->addRule('fullname', get_string('required'), 'required');
$mform->setType('fullname', PARAM_TEXT);
$scalearr = array();
if ($scales = get_records('scale')) {
foreach ($scales as $scale) {
$scalearr[$scale->id] = $scale->name;
}
}
$mform->addElement('select', 'scaleid', get_string('scale'), $scalearr);
$mform->addRule('scaleid', get_string('required'), 'required');
$mform->setType('scaleid', PARAM_INT);
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'courseid');
$mform->setType('courseid', PARAM_INT);
//-------------------------------------------------------------------------------
// buttons
$this->add_action_buttons();
}
}
$id = optional_param('id', 0, PARAM_INT); // id of the outcome
if ($courseid = optional_param('courseid', 0, PARAM_INT)) {
// optional course id, if set, editting from course
require_login($courseid);
require_capability('gradereport/outcomes:manage', get_context_instance(CONTEXT_COURSE, $courseid));
$returnurl = $CFG->wwwroot."/grade/report/outcomes/course.php?id=$courseid";
} else {
// admin editting site level outcomes
require_capability('gradereport/outcomes:manage', get_context_instance(CONTEXT_SYSTEM));
$returnurl = $CFG->wwwroot."/grade/report/outcomes/site.php";
}
// form processing
$mform = new edit_outcomes_form();
if ($id) {
// form set data
$mform->set_data(get_record('grade_outcomes', 'id', $id));
}
// if courseid is provided, set it in the form
if ($courseid) {
$data->courseid = $courseid;
$mform->set_data($data);
}
if ($mform->is_cancelled()) {
redirect($returnurl);
}
if ($data = $mform->get_data()) {
if ($data->courseid == 0) {
$data->courseid = NULL;
}
if ($data->id) {
update_record('grade_outcomes', $data);
} else {
insert_record('grade_outcomes', $data);
}
redirect($returnurl);
}
// 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);
// Add tabs
$currenttab = 'editoutcomes';
include('tabs.php');
$mform->display();
print_footer();
?>

View File

@ -1,127 +0,0 @@
<?php
/*********************************
* Global outcomes editting page *
*********************************/
include_once('../../../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/tablelib.php');
// setting up params
$courseid = optional_param('id', SITEID, PARAM_INT); // course id
require_capability('gradereport/outcomes:view', get_context_instance(CONTEXT_SYSTEM));
/// check capability
$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;
// form processing
if ($deleteid && confirm_sesskey()) {
require_capability('gradereport/outcomes:manage', get_context_instance(CONTEXT_SYSTEM));
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 {
$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);
// prints confirmation
$strdeleteoutcomecheck = get_string('deleteoutcomecheck', 'grades');
notice_yesno($strdeleteoutcomecheck,
'site.php?deleteid='.$deleteid.'&amp;confirm=1&amp;sesskey='.sesskey(),
'site.php');
print_footer();
exit;
}
}
/// display information
admin_externalpage_setup('gradereportoutcomes');
admin_externalpage_print_header();
// Add tabs
$currenttab = 'siteoutcomes';
include('tabs.php');
$totalcount = count_records('grade_outcomes');
$baseurl = "site.php";
print_paging_bar($totalcount, $page, $perpage, $baseurl);
if ($outcomes = get_recordset('grade_outcomes', '', '', '', '*', $page * $perpage, $perpage)) {
$tablecolumns = array('outcome', 'scale', 'course', 'edit', 'usedgradeitems', 'usedcourses');
$tableheaders = array(get_string('outcomes', 'grades'),
get_string('scale'),
get_string('course'),
'',
get_string('activities'),
get_string('courses'));
$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;
// get course
if ($outcome->courseid) {
$course = get_record('course', 'id', $outcome->courseid);
$data[] = $course->shortname;
} else {
$data[] = get_string('site');
}
// add operations
if (has_capability('gradereport/outcomes:manage', get_context_instance(CONTEXT_SYSTEM))) {
$data[] = '<a href="editoutcomes.php?id='.$outcome->id.'&amp;sesskey='.sesskey().'"><img alt="Update" class="iconsmall" src="'.$CFG->wwwroot.'/pix/t/edit.gif"/></a>
<a href="site.php?deleteid='.$outcome->id.'&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
$num = count_records('grade_outcomes_courses', 'outcomeid', $outcome->id);
$data[] = (int) $num;
$table->add_data($data);
}
$table->print_html();
}
if (has_capability('gradereport/outcomes:manage', get_context_instance(CONTEXT_SYSTEM))) {
echo '<a href="editoutcomes.php">'.get_string('addoutcome', 'gradereport_outcomes').'</a>';
}
// print the footer, end of page
admin_externalpage_print_footer();
?>

View File

@ -1,32 +0,0 @@
<?php // $Id$
$row = $tabs = array();
// Needs capability here
if ($courseid && ($courseid != SITEID)) {
$row[] = new tabobject('outcomereport',
$CFG->wwwroot.'/grade/report/outcomes/index.php?id='.$courseid,
get_string('outcomereport', 'grades'));
$coursecontext = get_context_instance(CONTEXT_COURSE, $courseid);
if (has_capability('gradereport/outcomes:manage', $coursecontext)) {
$row[] = new tabobject('courseoutcomes',
$CFG->wwwroot.'/grade/report/outcomes/course.php?id='.$courseid,
get_string('courseoutcomes', 'gradereport_outcomes'));
}
}
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
if (has_capability('gradereport/outcomes:manage', $sitecontext, NULL, false)) {
$row[] = new tabobject('siteoutcomes',
$CFG->wwwroot.'/grade/report/outcomes/site.php?id='.$courseid,
get_string('siteoutcomes', 'gradereport_outcomes'));
}
$tabs[] = $row;
echo '<div class="outcomedisplay">';
print_tabs($tabs, $currenttab);
echo '</div>';
?>

View File

@ -76,7 +76,6 @@ $string['configshowuserimage'] = 'Whether to show the user\'s profile image next
$string['configstudentsperpage'] = 'The number of students to display per page in the grader report.';
$string['configstudentsperpagedefault'] = 'The number of students to display per page in the grader report. Leave this field empty to use the site default (currently $a).';
$string['contract'] = 'Contract Category';
$string['courseoutcomes'] = 'Course outcomes';
$string['createcategory'] = 'Create Category';
$string['createcategoryerror'] = 'Could not create a new category';
$string['creatinggradebooksettings'] = 'Creating Gradebook settings';
@ -120,7 +119,6 @@ $string['finalgrade'] = 'Final grade';
$string['forelementtypes'] = ' for the selected $a';
$string['forstudents'] = 'For Students';
$string['full'] = 'Full';
$string['globaloutcomes'] = 'Global outcomes';
$string['grade'] = 'Grade';
$string['gradebook'] = 'Gradebook';
$string['gradebookhiddenerror'] = 'The gradebook is currently set to hide everything from students.';
@ -230,6 +228,7 @@ $string['outcomecreate'] = 'Add a new outcome';
$string['outcomeitemsedit'] = 'Edit outcome item';
$string['outcomes'] = 'Outcomes';
$string['outcomescustom'] = 'Custom outcomes';
$string['outcomescourse'] = 'Outcomes used in course';
$string['outcomename'] = 'Outcome name';
$string['outcomereport'] = 'Outcome report';
$string['outcomesstandard'] = 'Standard outcomes';

View File

@ -978,6 +978,17 @@ $moodle_capabilities = array(
'clonepermissionsfrom' => 'moodle/course:managegrades'
),
'moodle/grade:manageoutcomes' => array(
'riskbitmask' => RISK_PERSONAL,
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'editingteacher' => CAP_ALLOW,
'admin' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/course:managegrades'
),
'moodle/grade:hide' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,

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 = 2007073103; // YYYYMMDD = date
$version = 2007073104; // YYYYMMDD = date
// XY = increments within a single day
$release = '1.9 dev'; // Human-friendly version name