mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-10211 Added edit, show/hide and lock/unlock icons and links, with corresponding page-level actions to headers of grader report.
This commit is contained in:
parent
f9016aefca
commit
8178f34c56
@ -40,12 +40,19 @@ if (!empty($grades)) {
|
||||
}
|
||||
|
||||
// get the params
|
||||
$courseid = required_param('id', PARAM_INT);
|
||||
$context = get_context_instance(CONTEXT_COURSE, $courseid);
|
||||
$page = optional_param('page', 0, PARAM_INT);
|
||||
$sortitemid = optional_param('sortitemid', 0, PARAM_ALPHANUM); // sort by which grade item
|
||||
$report = optional_param('report', 0, PARAM_ALPHANUM);
|
||||
$perpage = optional_param('perpage', 3, PARAM_INT); // number of users on a page
|
||||
$courseid = required_param('id', PARAM_INT);
|
||||
$context = get_context_instance(CONTEXT_COURSE, $courseid);
|
||||
$page = optional_param('page', 0, PARAM_INT);
|
||||
$sortitemid = optional_param('sortitemid', 0, PARAM_ALPHANUM); // sort by which grade item
|
||||
$report = optional_param('report', 0, PARAM_ALPHANUM);
|
||||
$perpage = optional_param('perpage', 3, PARAM_INT); // number of users on a page
|
||||
$action = optional_param('action', 0, PARAM_ALPHA);
|
||||
$move = optional_param('move', 0, PARAM_INT);
|
||||
$type = optional_param('type', 0, PARAM_ALPHA);
|
||||
$target = optional_param('target', 0, PARAM_INT);
|
||||
|
||||
// Grab the grade_tree for this course
|
||||
$gtree = new grade_tree($courseid, false);
|
||||
|
||||
// setting the sort order, this depends on last state
|
||||
// all this should be in the new table class that we might need to use
|
||||
@ -87,6 +94,62 @@ if ($sortitemid) {
|
||||
|
||||
/// end of setting sort order code
|
||||
|
||||
// Perform actions on categories, items and grades
|
||||
if (!empty($target) && !empty($action) && confirm_sesskey()) {
|
||||
$element = $gtree->locate_element($target);
|
||||
switch ($action) {
|
||||
case 'edit':
|
||||
break;
|
||||
case 'delete':
|
||||
if ($confirm == 1) { // Perform the deletion
|
||||
$gtree->remove_element($target);
|
||||
$gtree->renumber();
|
||||
$gtree->update_db();
|
||||
// Print result message
|
||||
|
||||
} else { // Print confirmation dialog
|
||||
$strdeletecheckfull = get_string('deletecheck', '', $element->element['object']->get_name());
|
||||
$linkyes = "category.php?target=$target&action=delete&confirm=1$gtree->commonvars";
|
||||
$linkno = "category.php?$gtree->commonvars";
|
||||
notice_yesno($strdeletecheckfull, $linkyes, $linkno);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'hide':
|
||||
// TODO Implement calendar for selection of a date to hide element until
|
||||
if (!$element->element['object']->set_hidden(1)) {
|
||||
debugging("Could not update the element's hidden state!");
|
||||
} else {
|
||||
$gtree = new grade_tree($courseid);
|
||||
}
|
||||
break;
|
||||
case 'show':
|
||||
if (!$element->element['object']->set_hidden(0)) {
|
||||
debugging("Could not update the element's hidden state!");
|
||||
} else {
|
||||
$gtree = new grade_tree($courseid);
|
||||
}
|
||||
break;
|
||||
case 'lock':
|
||||
// TODO Implement calendar for selection of a date to lock element after
|
||||
if (!$element->element['object']->set_locked(1)) {
|
||||
debugging("Could not update the element's locked state!");
|
||||
} else {
|
||||
$gtree = new grade_tree($courseid);
|
||||
}
|
||||
break;
|
||||
case 'unlock':
|
||||
if (!$element->element['object']->set_locked(0)) {
|
||||
debugging("Could not update the element's locked state!");
|
||||
} else {
|
||||
$gtree = new grade_tree($courseid);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// first make sure we have all final grades
|
||||
// TODO: check that no grade_item has needsupdate set
|
||||
@ -169,174 +232,179 @@ $pbarurl = 'report.php?id='.$courseid.'&report=grader&';
|
||||
print_paging_bar($numusers, $page, $perpage, $pbarurl);
|
||||
|
||||
/// With the users in an sorted array and grades fetched, we can not print the main html table
|
||||
if ($gtree = new grade_tree($courseid, false)) {
|
||||
|
||||
// 1. Fetch all top-level categories for this course, with all children preloaded, sorted by sortorder
|
||||
$tree = $gtree->tree_filled;
|
||||
// 1. Fetch all top-level categories for this course, with all children preloaded, sorted by sortorder
|
||||
$tree = $gtree->tree_filled;
|
||||
|
||||
if (empty($gtree->tree_filled)) {
|
||||
debugging("The tree_filled array wasn't initialised, grade_tree could not display the grades correctly.");
|
||||
}
|
||||
|
||||
// Fetch array of students enroled in this course
|
||||
if (!$context = get_context_instance(CONTEXT_COURSE, $gtree->courseid)) {
|
||||
return false;
|
||||
}
|
||||
//$users = get_role_users(@implode(',', $CFG->gradebookroles), $context);
|
||||
if (empty($gtree->tree_filled)) {
|
||||
debugging("The tree_filled array wasn't initialised, grade_tree could not display the grades correctly.");
|
||||
}
|
||||
|
||||
// Fetch array of students enroled in this course
|
||||
if (!$context = get_context_instance(CONTEXT_COURSE, $gtree->courseid)) {
|
||||
return false;
|
||||
}
|
||||
//$users = get_role_users(@implode(',', $CFG->gradebookroles), $context);
|
||||
|
||||
$topcathtml = '<tr><td class="filler"> </td>';
|
||||
$cathtml = '<tr><td class="filler"> </td>';
|
||||
$topcathtml = '<tr><td class="filler"> </td>';
|
||||
$cathtml = '<tr><td class="filler"> </td>';
|
||||
|
||||
if ($sortitemid === 'lastname') {
|
||||
if ($sortorder == 'ASC') {
|
||||
$lastarrow = ' <img src="http://yu.moodle.com/dev/pix/t/up.gif"/> ';
|
||||
} else {
|
||||
$lastarrow = ' <img src="http://yu.moodle.com/dev/pix/t/down.gif"/> ';
|
||||
}
|
||||
if ($sortitemid === 'lastname') {
|
||||
if ($sortorder == 'ASC') {
|
||||
$lastarrow = ' <img src="http://yu.moodle.com/dev/pix/t/up.gif"/> ';
|
||||
} else {
|
||||
$lastarrow = '';
|
||||
$lastarrow = ' <img src="http://yu.moodle.com/dev/pix/t/down.gif"/> ';
|
||||
}
|
||||
|
||||
if ($sortitemid === 'firstname') {
|
||||
if ($sortorder == 'ASC') {
|
||||
$firstarrow = ' <img src="http://yu.moodle.com/dev/pix/t/up.gif"/> ';
|
||||
} else {
|
||||
$firstarrow = ' <img src="http://yu.moodle.com/dev/pix/t/down.gif"/> ';
|
||||
}
|
||||
} else {
|
||||
$firstarrow = '';
|
||||
}
|
||||
|
||||
// first name/last name column
|
||||
$itemhtml = '<tr><th class="filler"><a href="'.$baseurl.'&sortitemid=firstname">Firstname</a> '. $firstarrow. '/ <a href="'.$baseurl.'&sortitemid=lastname">Lastname </a>'. $lastarrow .'</th>';
|
||||
|
||||
$items = array();
|
||||
|
||||
foreach ($tree as $topcat) {
|
||||
$itemcount = 0;
|
||||
|
||||
foreach ($topcat['children'] as $catkey => $cat) {
|
||||
$catitemcount = 0;
|
||||
|
||||
foreach ($cat['children'] as $item) {
|
||||
$itemcount++;
|
||||
$catitemcount++;
|
||||
|
||||
if ($item['object']->id == $sortitemid) {
|
||||
if ($sortorder == 'ASC') {
|
||||
$arrow = ' <img src="http://yu.moodle.com/dev/pix/t/up.gif"/> ';
|
||||
} else {
|
||||
$arrow = ' <img src="http://yu.moodle.com/dev/pix/t/down.gif"/> ';
|
||||
}
|
||||
} else {
|
||||
$arrow = '';
|
||||
}
|
||||
$itemhtml .= '<th><a href="'.$baseurl.'&sortitemid='. $item['object']->id .'">'. $item['object']->itemname . '</a>' . $arrow. '</th>';
|
||||
$items[] = $item;
|
||||
}
|
||||
|
||||
if ($cat['object'] == 'filler') {
|
||||
$cathtml .= '<td class="subfiller"> </td>';
|
||||
} else {
|
||||
$cat['object']->load_grade_item();
|
||||
$cathtml .= '<td colspan="' . $catitemcount . '">' . $cat['object']->fullname . '</td>';
|
||||
}
|
||||
}
|
||||
|
||||
if ($topcat['object'] == 'filler') {
|
||||
$colspan = null;
|
||||
if (!empty($topcat['colspan'])) {
|
||||
$colspan = 'colspan="' . $topcat['colspan'] . '" ';
|
||||
}
|
||||
$topcathtml .= '<td ' . $colspan . 'class="topfiller"> </td>';
|
||||
} else {
|
||||
$topcathtml .= '<th colspan="' . $itemcount . '">' . $topcat['object']->fullname . '</th>';
|
||||
}
|
||||
}
|
||||
|
||||
$studentshtml = '';
|
||||
|
||||
foreach ($users as $userid => $user) {
|
||||
$studentshtml .= '<tr><th>' . $user->firstname . ' ' . $user->lastname . '</th>';
|
||||
foreach ($items as $item) {
|
||||
|
||||
|
||||
$studentshtml .= '<td>';
|
||||
|
||||
if (isset($finalgrades[$userid][$item['object']->id])) {
|
||||
$gradeval = $finalgrades[$userid][$item['object']->id];
|
||||
} else {
|
||||
$gradeval = '-';
|
||||
}
|
||||
|
||||
// if in editting mode, we need to print either a text box
|
||||
// or a drop down (for scales)
|
||||
if ($USER->gradeediting) {
|
||||
if ($item['object']->scaleid) {
|
||||
if ($scale = get_record('scale', 'id', $item['object']->scaleid)) {
|
||||
$scales = explode(",", $scale->scale);
|
||||
// reindex because scale is off 1
|
||||
$i = 0;
|
||||
foreach ($scales as $scaleoption) {
|
||||
$i++;
|
||||
$scaleopt[$i] = $scaleoption;
|
||||
}
|
||||
$studentshtml .= choose_from_menu ($scaleopt, 'grade_'.$userid.'_'.$item['object']->id, $gradeval, get_string('nograde'), '', -1, true);
|
||||
}
|
||||
} else {
|
||||
$studentshtml .= '<input type="text" name="grade_'.$userid.'_'.$item['object']->id.'" value="'.$gradeval.'"/>';
|
||||
}
|
||||
} else {
|
||||
// finalgrades[$userid][$itemid] could be null because of the outer join
|
||||
// in this case it's different than a 0
|
||||
if ($item['object']->scaleid) {
|
||||
if ($scale = get_record('scale', 'id', $item['object']->scaleid)) {
|
||||
$scales = explode(",", $scale->scale);
|
||||
|
||||
// invalid grade if gradeval < 1
|
||||
if ((int) $gradeval < 1) {
|
||||
$studentshtml .= '-';
|
||||
} else {
|
||||
$studentshtml .= $scales[$gradeval-1];
|
||||
}
|
||||
} else {
|
||||
// no such scale, throw error?
|
||||
}
|
||||
} else {
|
||||
$studentshtml .= $gradeval;
|
||||
}
|
||||
}
|
||||
|
||||
$studentshtml .= '</td>' . "\n";
|
||||
}
|
||||
$studentshtml .= '</tr>';
|
||||
}
|
||||
|
||||
$itemhtml .= '</tr>';
|
||||
$cathtml .= '</tr>';
|
||||
$topcathtml .= '</tr>';
|
||||
|
||||
$reporthtml = "<table style=\"text-align: center\" border=\"1\">$topcathtml$cathtml$itemhtml";
|
||||
$reporthtml .= $studentshtml;
|
||||
$reporthtml .= "</table>";
|
||||
|
||||
// print submit button
|
||||
if ($USER->gradeediting) {
|
||||
echo '<form action="report.php" method="POST">';
|
||||
echo '<div>';
|
||||
echo '<input type="hidden" value="'.$courseid.'" name="id" />';
|
||||
echo '<input type="hidden" value="'.sesskey().'" name="sesskey" />';
|
||||
echo '<input type="hidden" value="grader" name="report"/>';
|
||||
}
|
||||
|
||||
echo $reporthtml;
|
||||
|
||||
// print submit button
|
||||
if ($USER->gradeediting) {
|
||||
echo '<input type="submit" value="'.get_string('update').'" />';
|
||||
echo '</div></form>';
|
||||
}
|
||||
|
||||
} else {
|
||||
$lastarrow = '';
|
||||
}
|
||||
|
||||
if ($sortitemid === 'firstname') {
|
||||
if ($sortorder == 'ASC') {
|
||||
$firstarrow = ' <img src="http://yu.moodle.com/dev/pix/t/up.gif"/> ';
|
||||
} else {
|
||||
$firstarrow = ' <img src="http://yu.moodle.com/dev/pix/t/down.gif"/> ';
|
||||
}
|
||||
} else {
|
||||
$firstarrow = '';
|
||||
}
|
||||
|
||||
// first name/last name column
|
||||
$itemhtml = '<tr><th class="filler"><a href="'.$baseurl.'&sortitemid=firstname">Firstname</a> '. $firstarrow. '/ <a href="'.$baseurl.'&sortitemid=lastname">Lastname </a>'. $lastarrow .'</th>';
|
||||
|
||||
$items = array();
|
||||
|
||||
foreach ($tree as $topcat) {
|
||||
$itemcount = 0;
|
||||
|
||||
foreach ($topcat['children'] as $catkey => $cat) {
|
||||
$catitemcount = 0;
|
||||
|
||||
foreach ($cat['children'] as $item) {
|
||||
$itemcount++;
|
||||
$catitemcount++;
|
||||
|
||||
if ($item['object']->id == $sortitemid) {
|
||||
if ($sortorder == 'ASC') {
|
||||
$arrow = ' <img src="pix/t/up.gif"/> ';
|
||||
} else {
|
||||
$arrow = ' <img src="pix/t/down.gif"/> ';
|
||||
}
|
||||
} else {
|
||||
$arrow = '';
|
||||
}
|
||||
$itemhtml .= '<th><a href="'.$baseurl.'&sortitemid='
|
||||
. $item['object']->id .'">'. $item['object']->itemname
|
||||
. '</a>' . $arrow;
|
||||
|
||||
// Print icons
|
||||
$itemhtml .= grade_get_icons($item['object'], $gtree) . '</th>';
|
||||
$items[] = $item;
|
||||
}
|
||||
|
||||
if ($cat['object'] == 'filler') {
|
||||
$cathtml .= '<td class="subfiller"> </td>';
|
||||
} else {
|
||||
$cat['object']->load_grade_item();
|
||||
$cathtml .= '<td colspan="' . $catitemcount . '">' . $cat['object']->fullname;
|
||||
// Print icons
|
||||
$cathtml .= grade_get_icons($cat['object'], $gtree) . '</td>';
|
||||
}
|
||||
}
|
||||
|
||||
if ($topcat['object'] == 'filler') {
|
||||
$colspan = null;
|
||||
if (!empty($topcat['colspan'])) {
|
||||
$colspan = 'colspan="' . $topcat['colspan'] . '" ';
|
||||
}
|
||||
$topcathtml .= '<td ' . $colspan . 'class="topfiller"> </td>';
|
||||
} else {
|
||||
$topcathtml .= '<th colspan="' . $itemcount . '">' . $topcat['object']->fullname;
|
||||
// Print icons
|
||||
$topcathtml .= grade_get_icons($topcat['object'], $gtree) . '</th>';
|
||||
}
|
||||
}
|
||||
|
||||
$studentshtml = '';
|
||||
|
||||
foreach ($users as $userid => $user) {
|
||||
$studentshtml .= '<tr><th>' . $user->firstname . ' ' . $user->lastname . '</th>';
|
||||
foreach ($items as $item) {
|
||||
|
||||
|
||||
$studentshtml .= '<td>';
|
||||
|
||||
if (isset($finalgrades[$userid][$item['object']->id])) {
|
||||
$gradeval = $finalgrades[$userid][$item['object']->id];
|
||||
} else {
|
||||
$gradeval = '-';
|
||||
}
|
||||
|
||||
// if in editting mode, we need to print either a text box
|
||||
// or a drop down (for scales)
|
||||
if ($USER->gradeediting) {
|
||||
if ($item['object']->scaleid) {
|
||||
if ($scale = get_record('scale', 'id', $item['object']->scaleid)) {
|
||||
$scales = explode(",", $scale->scale);
|
||||
// reindex because scale is off 1
|
||||
$i = 0;
|
||||
foreach ($scales as $scaleoption) {
|
||||
$i++;
|
||||
$scaleopt[$i] = $scaleoption;
|
||||
}
|
||||
$studentshtml .= choose_from_menu ($scaleopt, 'grade_'.$userid.'_'.$item['object']->id, $gradeval, get_string('nograde'), '', -1, true);
|
||||
}
|
||||
} else {
|
||||
$studentshtml .= '<input type="text" name="grade_'.$userid.'_'.$item['object']->id.'" value="'.$gradeval.'"/>';
|
||||
}
|
||||
} else {
|
||||
// finalgrades[$userid][$itemid] could be null because of the outer join
|
||||
// in this case it's different than a 0
|
||||
if ($item['object']->scaleid) {
|
||||
if ($scale = get_record('scale', 'id', $item['object']->scaleid)) {
|
||||
$scales = explode(",", $scale->scale);
|
||||
|
||||
// invalid grade if gradeval < 1
|
||||
if ((int) $gradeval < 1) {
|
||||
$studentshtml .= '-';
|
||||
} else {
|
||||
$studentshtml .= $scales[$gradeval-1];
|
||||
}
|
||||
} else {
|
||||
// no such scale, throw error?
|
||||
}
|
||||
} else {
|
||||
$studentshtml .= $gradeval;
|
||||
}
|
||||
}
|
||||
|
||||
$studentshtml .= '</td>' . "\n";
|
||||
}
|
||||
$studentshtml .= '</tr>';
|
||||
}
|
||||
|
||||
$itemhtml .= '</tr>';
|
||||
$cathtml .= '</tr>';
|
||||
$topcathtml .= '</tr>';
|
||||
|
||||
$reporthtml = "<table style=\"text-align: center\" border=\"1\">$topcathtml$cathtml$itemhtml";
|
||||
$reporthtml .= $studentshtml;
|
||||
$reporthtml .= "</table>";
|
||||
|
||||
// print submit button
|
||||
if ($USER->gradeediting) {
|
||||
echo '<form action="report.php" method="POST">';
|
||||
echo '<div>';
|
||||
echo '<input type="hidden" value="'.$courseid.'" name="id" />';
|
||||
echo '<input type="hidden" value="'.sesskey().'" name="sesskey" />';
|
||||
echo '<input type="hidden" value="grader" name="report"/>';
|
||||
}
|
||||
|
||||
echo $reporthtml;
|
||||
|
||||
// print submit button
|
||||
if ($USER->gradeediting) {
|
||||
echo '<input type="submit" value="'.get_string('update').'" />';
|
||||
echo '</div></form>';
|
||||
}
|
||||
?>
|
||||
|
@ -677,4 +677,62 @@ function grade_oldgradebook_upgrade($courseid) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a grade_category, grade_item or grade_grade, this function
|
||||
* figures out the state of the object and builds then returns a div
|
||||
* with the icons needed for the grader report.
|
||||
*
|
||||
* @param object $object
|
||||
* @return string HTML
|
||||
*/
|
||||
function grade_get_icons($object, $tree) {
|
||||
global $CFG;
|
||||
|
||||
$stredit = get_string("edit");
|
||||
$strmove = get_string("move");
|
||||
$strmoveup = get_string("moveup");
|
||||
$strmovedown = get_string("movedown");
|
||||
$strmovehere = get_string("movehere");
|
||||
$strcancel = get_string("cancel");
|
||||
$stredit = get_string("edit");
|
||||
$strdelete = get_string("delete");
|
||||
$strhide = get_string("hide");
|
||||
$strshow = get_string("show");
|
||||
$strlock = get_string("lock", 'grades');
|
||||
$strunlock = get_string("unlock", 'grades');
|
||||
|
||||
$html = '<div class="grade_icons">img</div>';
|
||||
|
||||
// Edit icon
|
||||
$html .= '<a href="report/grader/category.php?target=' . $object->get_sortorder()
|
||||
. "&action=edit$tree->commonvars\">\n";
|
||||
$html .= '<img src="'.$CFG->pixpath.'/t/edit.gif" class="iconsmall" alt="'
|
||||
.$stredit.'" title="'.$stredit.'" /></a>'. "\n";
|
||||
|
||||
// Hide/Show icon
|
||||
$hide_show = 'hide';
|
||||
if ($object->is_hidden()) {
|
||||
$hide_show = 'show';
|
||||
}
|
||||
|
||||
$html .= '<a href="report.php?report=grader&target=' . $object->get_sortorder()
|
||||
. "&action=$hide_show$tree->commonvars\">\n";
|
||||
$html .= '<img src="'.$CFG->pixpath.'/t/'.$hide_show.'.gif" class="iconsmall" alt="'
|
||||
.${'str' . $hide_show}.'" title="'.${'str' . $hide_show}.'" /></a>'. "\n";
|
||||
|
||||
// Prepare lock/unlock string
|
||||
$lock_unlock = 'lock';
|
||||
if ($object->is_locked()) {
|
||||
$lock_unlock = 'unlock';
|
||||
}
|
||||
// Print lock/unlock icon
|
||||
$html .= '<a href="report.php?report=grader&target=' . $object->get_sortorder()
|
||||
. "&action=$lock_unlock$tree->commonvars\">\n";
|
||||
$html .= '<img src="'.$CFG->pixpath.'/t/'.$lock_unlock.'.gif" class="iconsmall" alt="'
|
||||
.${'str' . $lock_unlock}.'" title="'.${'str' . $lock_unlock}.'" /></a>'. "\n";
|
||||
|
||||
|
||||
// Lock/Unlock icon
|
||||
return $html;
|
||||
}
|
||||
?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user