diff --git a/grade/report/grader/index.php b/grade/report/grader/index.php index 85074109b92..e6cbbb3f807 100644 --- a/grade/report/grader/index.php +++ b/grade/report/grader/index.php @@ -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 = ' '; - $cathtml = ' '; +$topcathtml = ' '; +$cathtml = ' '; - if ($sortitemid === 'lastname') { - if ($sortorder == 'ASC') { - $lastarrow = ' '; - } else { - $lastarrow = ' '; - } +if ($sortitemid === 'lastname') { + if ($sortorder == 'ASC') { + $lastarrow = ' '; } else { - $lastarrow = ''; + $lastarrow = ' '; } - - if ($sortitemid === 'firstname') { - if ($sortorder == 'ASC') { - $firstarrow = ' '; - } else { - $firstarrow = ' '; - } - } else { - $firstarrow = ''; - } - - // first name/last name column - $itemhtml = 'Firstname '. $firstarrow. '/ Lastname '. $lastarrow .''; - - $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 = ' '; - } else { - $arrow = ' '; - } - } else { - $arrow = ''; - } - $itemhtml .= ''. $item['object']->itemname . '' . $arrow. ''; - $items[] = $item; - } - - if ($cat['object'] == 'filler') { - $cathtml .= ' '; - } else { - $cat['object']->load_grade_item(); - $cathtml .= '' . $cat['object']->fullname . ''; - } - } - - if ($topcat['object'] == 'filler') { - $colspan = null; - if (!empty($topcat['colspan'])) { - $colspan = 'colspan="' . $topcat['colspan'] . '" '; - } - $topcathtml .= ' '; - } else { - $topcathtml .= '' . $topcat['object']->fullname . ''; - } - } - - $studentshtml = ''; - - foreach ($users as $userid => $user) { - $studentshtml .= '' . $user->firstname . ' ' . $user->lastname . ''; - foreach ($items as $item) { - - - $studentshtml .= ''; - - 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 .= ''; - } - } 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 .= '' . "\n"; - } - $studentshtml .= ''; - } - - $itemhtml .= ''; - $cathtml .= ''; - $topcathtml .= ''; - - $reporthtml = "$topcathtml$cathtml$itemhtml"; - $reporthtml .= $studentshtml; - $reporthtml .= "
"; - - // print submit button - if ($USER->gradeediting) { - echo '
'; - echo '
'; - echo ''; - echo ''; - echo ''; - } - - echo $reporthtml; - - // print submit button - if ($USER->gradeediting) { - echo ''; - echo '
'; - } - +} else { + $lastarrow = ''; } +if ($sortitemid === 'firstname') { + if ($sortorder == 'ASC') { + $firstarrow = ' '; + } else { + $firstarrow = ' '; + } +} else { + $firstarrow = ''; +} + +// first name/last name column +$itemhtml = 'Firstname '. $firstarrow. '/ Lastname '. $lastarrow .''; + +$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 = ' '; + } else { + $arrow = ' '; + } + } else { + $arrow = ''; + } + $itemhtml .= ''. $item['object']->itemname + . '' . $arrow; + + // Print icons + $itemhtml .= grade_get_icons($item['object'], $gtree) . ''; + $items[] = $item; + } + + if ($cat['object'] == 'filler') { + $cathtml .= ' '; + } else { + $cat['object']->load_grade_item(); + $cathtml .= '' . $cat['object']->fullname; + // Print icons + $cathtml .= grade_get_icons($cat['object'], $gtree) . ''; + } + } + + if ($topcat['object'] == 'filler') { + $colspan = null; + if (!empty($topcat['colspan'])) { + $colspan = 'colspan="' . $topcat['colspan'] . '" '; + } + $topcathtml .= ' '; + } else { + $topcathtml .= '' . $topcat['object']->fullname; + // Print icons + $topcathtml .= grade_get_icons($topcat['object'], $gtree) . ''; + } +} + +$studentshtml = ''; + +foreach ($users as $userid => $user) { + $studentshtml .= '' . $user->firstname . ' ' . $user->lastname . ''; + foreach ($items as $item) { + + + $studentshtml .= ''; + + 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 .= ''; + } + } 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 .= '' . "\n"; + } + $studentshtml .= ''; +} + +$itemhtml .= ''; +$cathtml .= ''; +$topcathtml .= ''; + +$reporthtml = "$topcathtml$cathtml$itemhtml"; +$reporthtml .= $studentshtml; +$reporthtml .= "
"; + +// print submit button +if ($USER->gradeediting) { + echo '
'; + echo '
'; + echo ''; + echo ''; + echo ''; +} + +echo $reporthtml; + +// print submit button +if ($USER->gradeediting) { + echo ''; + echo '
'; +} ?> diff --git a/lib/gradelib.php b/lib/gradelib.php index 1854d0cda94..df816ed7a67 100644 --- a/lib/gradelib.php +++ b/lib/gradelib.php @@ -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 = '
img
'; + + // Edit icon + $html .= 'commonvars\">\n"; + $html .= ''
+          .$stredit.''. "\n"; + + // Hide/Show icon + $hide_show = 'hide'; + if ($object->is_hidden()) { + $hide_show = 'show'; + } + + $html .= 'commonvars\">\n"; + $html .= ''
+          .${'str' . $hide_show}.''. "\n"; + + // Prepare lock/unlock string + $lock_unlock = 'lock'; + if ($object->is_locked()) { + $lock_unlock = 'unlock'; + } + // Print lock/unlock icon + $html .= 'commonvars\">\n"; + $html .= ''
+          .${'str' . $lock_unlock}.''. "\n"; + + + // Lock/Unlock icon + return $html; +} ?>