//TODO: implement deleting in grade items and categories
break;
+ case 'autosort':
+ //TODO: implement autosorting based on order of mods on course page, categories first, manual items last
+ break;
+
+ case 'synclegacy':
+ grade_grab_legacy_grades($course->id);
+ redirect($returnurl);
+
case 'move':
if ($eid and confirm_sesskey()) {
$moveafter = required_param('moveafter', PARAM_ALPHANUM);
print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $strcategoriesedit, $navigation, '', '', true, '', navmenu($course));
-echo '<ul class="grade_tree">';
+print_box_start('gradetreebox generalbox');
+echo '<ul id="grade_tree">';
print_grade_tree($gtree->top_element, $moving);
echo '</ul>';
+print_box_end();
+echo '<div class="buttons">';
if ($moving) {
print_single_button('category.php', array('id'=>$course->id), get_string('cancel'), 'get');
} else {
print_single_button('edit_category.php', array('courseid'=>$course->id), get_string('addcategory', 'grades'), 'get');
- print_single_button('edit_item.php', array('courseid'=>$course->id), get_string('additem', 'grades'), 'get');
+ print_single_button('edit_item.php', array('courseid'=>$course->id), get_string('additem', 'grades'), 'get'); // TODO: localize
+ print_single_button('category.php', array('id'=>$course->id, 'action'=>'autosort'), get_string('autosort', 'grades'), 'get'); //TODO: localize
+ print_single_button('category.php', array('id'=>$course->id, 'action'=>'synclegacy'), get_string('synclegacygrades', 'grades'), 'get'); //TODO: localize
}
-
+echo '</div>';
print_footer($course);
die;
/// print the list items now
if ($moving == $eid) {
// do not diplay children
- echo '<li class="'.$element['type'].'">'.$icon.$name.'('.get_string('move').')</li>';
+ echo '<li class="'.$element['type'].' moving">'.$icon.$name.'('.get_string('move').')</li>';
} else if ($element['type'] != 'category') {
echo '<li class="'.$element['type'].'">'.$icon.$name.$actions.'</li>'.$moveto;
require_once '../../../config.php';
require_once $CFG->libdir.'/gradelib.php';
-require_once 'edit_category_form.php';
+require_once $CFG->libdir.'/formslib.php';
$courseid = required_param('courseid', PARAM_INT);
$id = optional_param('id', 0, PARAM_INT);
$mform->display();
print_footer($course);
-die;
\ No newline at end of file
+die;
+
+
+class edit_category_form extends moodleform {
+ function definition() {
+ $mform =& $this->_form;
+
+ // visible elements
+ $mform->addElement('text', 'fullname', get_string('categoryname', 'grades'));
+
+ //TODO: add other elements
+
+ // hidden params
+ $mform->addElement('hidden', 'id', 0);
+ $mform->setType('id', PARAM_INT);
+
+ $mform->addElement('hidden', 'courseid', 0);
+ $mform->setType('courseid', PARAM_INT);
+
+//-------------------------------------------------------------------------------
+ // buttons
+ $this->add_action_buttons();
+ }
+}
+++ /dev/null
-<?php //$Id$
-
-require_once $CFG->libdir.'/formslib.php';
-
-class edit_category_form extends moodleform {
- function definition() {
- $mform =& $this->_form;
-
- // visible elements
- $mform->addElement('text', 'fullname', get_string('categoryname', 'grades'));
-
- //TODO: add other elements
-
- // hidden params
- $mform->addElement('hidden', 'id', 0);
- $mform->setType('id', PARAM_INT);
-
- $mform->addElement('hidden', 'courseid', 0);
- $mform->setType('courseid', PARAM_INT);
-
-//-------------------------------------------------------------------------------
- // buttons
- $this->add_action_buttons();
- }
-}
-?>
\ No newline at end of file
--- /dev/null
+<?php //$id:$
+
+//TODO: implement
+?>
require_once '../../../config.php';
require_once $CFG->libdir.'/gradelib.php';
-require_once 'edit_item_form.php';
+require_once $CFG->libdir.'/formslib.php';
$courseid = required_param('courseid', PARAM_INT);
$id = optional_param('id', 0, PARAM_INT);
$mform->display();
print_footer($course);
-die;
\ No newline at end of file
+die;
+
+
+class edit_item_form extends moodleform {
+ function definition() {
+ $mform =& $this->_form;
+
+ // visible elements
+ $mform->addElement('text', 'itemname', get_string('itemname', 'grades'));
+
+ //TODO: add other elements
+
+ // hidden params
+ $mform->addElement('hidden', 'id', 0);
+ $mform->setType('id', PARAM_INT);
+
+ $mform->addElement('hidden', 'courseid', 0);
+ $mform->setType('courseid', PARAM_INT);
+
+ $mform->addElement('hidden', 'itemtype', 0);
+ $mform->setType('itemtype', PARAM_ALPHA);
+
+//-------------------------------------------------------------------------------
+ // buttons
+ $this->add_action_buttons();
+ }
+}
\ No newline at end of file
+++ /dev/null
-<?php //$Id$
-
-require_once $CFG->libdir.'/formslib.php';
-
-class edit_item_form extends moodleform {
- function definition() {
- $mform =& $this->_form;
-
- // visible elements
- $mform->addElement('text', 'itemname', get_string('itemname', 'grades'));
-
- //TODO: add other elements
-
- // hidden params
- $mform->addElement('hidden', 'id', 0);
- $mform->setType('id', PARAM_INT);
-
- $mform->addElement('hidden', 'courseid', 0);
- $mform->setType('courseid', PARAM_INT);
-
- $mform->addElement('hidden', 'itemtype', 0);
- $mform->setType('itemtype', PARAM_ALPHA);
-
-//-------------------------------------------------------------------------------
- // buttons
- $this->add_action_buttons();
- }
-}
-?>
\ No newline at end of file
case 'hide':
// TODO Implement calendar for selection of a date to hide element until
- if (!$element['object']->set_hidden(1)) {
- debugging("Could not update the element's hidden state!");
- } else {
- $gtree = new grade_tree($courseid);
- }
+ $element['object']->set_hidden(1);
+ $gtree = new grade_tree($courseid);
break;
case 'show':
- if (!$element['object']->set_hidden(0)) {
- debugging("Could not update the element's hidden state!");
- } else {
- $gtree = new grade_tree($courseid);
- }
+ $element['object']->set_hidden(0);
+ $gtree = new grade_tree($courseid);
break;
case 'lock':
// TODO Implement calendar for selection of a date to lock element after
if (!$element['object']->set_locked(1)) {
debugging("Could not update the element's locked state!");
- } else {
- $gtree = new grade_tree($courseid);
}
+ $gtree = new grade_tree($courseid);
break;
case 'unlock':
if (!$element['object']->set_locked(0)) {
debugging("Could not update the element's locked state!");
- } else {
- $gtree = new grade_tree($courseid);
}
+ $gtree = new grade_tree($courseid);
break;
default:
break;
}
- if ($element['type'] == 'filler') {
- $headerhtml .= '<td class="filler'.$catlevel.'" '.$colspan.'> </td>';
+ if ($type == 'filler' or $type == 'fillerfirst' or $type == 'fillerlast') {
+ $headerhtml .= '<td class="'.$type.$catlevel.'" '.$colspan.'> </td>';
- } else if ($element['type'] == 'category') {
+ } else if ($type == 'category') {
$headerhtml .= '<td class="category'.$catlevel.'" '.$colspan.'">'.$element['object']->get_name();
// Print icons
$dimmed = 'class="dimmed_text"';
}
- $headerhtml .= '<th '.$dimmed.' class="'.$element['type'].$catlevel.'"><a href="'.$baseurl.'&sortitemid='
+ $headerhtml .= '<th '.$dimmed.' class="'.$type.$catlevel.'"><a href="'.$baseurl.'&sortitemid='
. $element['object']->id .'">'. $element['object']->get_name()
. '</a>' . $arrow;
if (isset($finalgrades[$userid][$item->id])) {
$gradeval = $finalgrades[$userid][$item->id]->finalgrade;
- $grade_grades = new grade_grades($finalgrades[$userid][$item->id], false);
- $grade_grades->feedback = $finalgrades[$userid][$item->id]->feedback;
+ $grade = new grade_grades($finalgrades[$userid][$item->id], false);
+ $grade->feedback = $finalgrades[$userid][$item->id]->feedback;
} else {
$gradeval = '-';
- $grade_grades = new grade_grades(array('userid' => $userid, 'itemid' => $item->id), false);
+ $grade = new grade_grades(array('userid' => $userid, 'itemid' => $item->id), false);
}
// if in editting mode, we need to print either a text box
}
}
+ // Do not show any icons if no grade (no record in DB to match)
+ if (!empty($grade->id)) {
+ // emulate grade element
+ $grade->courseid = $course->id;
+ $grade->grade_item = $item; // this may speedup is_hidden() and other grade_grades methods
+ $element = array ('eid'=>'g'.$grade->id, 'object'=>$grade, 'type'=>'grade');
+ $studentshtml .= grade_get_icons($element, $gtree);
+ }
+
$studentshtml .= '</td>' . "\n";
}
$studentshtml .= '</tr>';
/**
* Set the hidden status of grade_item and all grades, 0 mean visible, 1 always hidden, number means date to hide until.
* @param int $hidden new hidden status
+ * @return void
*/
function set_hidden($hidden) {
$this->hidden = $hidden;
}
$chdepths = array();
$chids = array_keys($element['children']);
+ $last_child = end($chids);
+ $first_child = reset($chids);
foreach ($chids as $chid) {
$chdepths[$chid] = grade_tree::inject_fillers($element['children'][$chid], $depth);
continue;
}
for ($i=0; $i < $maxdepth-$chd; $i++) {
+ if ($chid == $first_child) {
+ $type = 'fillerfirst';
+ } else if ($chid == $last_child) {
+ $type = 'fillerlast';
+ } else {
+ $type = 'filler';
+ }
$oldchild =& $element['children'][$chid];
- $element['children'][$chid] = array('object'=>'filler', 'type'=>'filler', 'eid'=>'', 'depth'=>$element['object']->depth,'children'=>array($oldchild));
+ $element['children'][$chid] = array('object'=>'filler', 'type'=>$type, 'eid'=>'', 'depth'=>$element['object']->depth,'children'=>array($oldchild));
}
}
* @return object element
*/
function locate_element($eid) {
+ if (strpos($eid, 'g') === 0) {
+ // it is a grade construct a new object
+ $id = (int)substr($eid, 1);
+ if (!$grade = grade_grades::fetch(array('id'=>$id))) {
+ return null;
+ }
+ //extra security check - the grade item must be in this tree
+ if (!$item_el = $this->locate_element('i'.$grade->itemid)) {
+ return null;
+ }
+ $grade->grade_item =& $item_el['object']; // this may speedup grade_grades methods!
+ return array('eid'=>'g'.$id,'object'=>$grade, 'type'=>'grade');
+ }
+
+ // it is a category or item
foreach ($this->levels as $row) {
foreach ($row as $element) {
if ($element['type'] == 'filler') {
return null;
}
- /**
- * Given an element object, returns its type (topcat, subcat or item).
- * The $element can be a straight object (fully instantiated), an array of 'object' and 'children'/'final_grades', or a stdClass element
- * as produced by grade_tree::locate_element(). This method supports all three types of inputs.
- * @param object $element
- * @return string Type
- */
- function get_element_type($element) {
- if ($element['object'] == 'filler') {
- return 'filler';
- }
-
- if (get_class($element['object']) == 'grade_category') {
- if ($element['object']->depth == 2) {
- return 'topcat';
- } else {
- return 'subcat';
- }
- }
-
- return 'item';
- }
}
/**
* For backwards compatibility with old third-party modules, this function can
* be used to import all grades from activities with legacy grading.
+ * @param int $courseid or null if all courses
*/
-function grade_grab_legacy_grades() {
+function grade_grab_legacy_grades($courseid=null) {
global $CFG;
error('No modules installed!');
}
+ if ($courseid) {
+ $course_sql = " AND cm.course=$courseid";
+ } else {
+ $course_sql = "";
+ }
+
foreach ($mods as $mod) {
if ($mod == 'NEWMODULE') { // Someone has unzipped the template, ignore it
// get all instance of the activity
$sql = "SELECT a.*, cm.idnumber as cmidnumber, m.name as modname
FROM {$CFG->prefix}$mod a, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
- WHERE m.name='$mod' AND m.id=cm.module AND cm.instance=a.id";
+ WHERE m.name='$mod' AND m.id=cm.module AND cm.instance=a.id $course_sql";
if ($modinstances = get_records_sql($sql)) {
foreach ($modinstances as $modinstance) {
$html .= '<a href="report/grader/edit_category.php?courseid='.$object->courseid.'&id='.$object->id.'">';
$html .= '<img src="'.$CFG->pixpath.'/t/edit.gif" class="iconsmall" alt="'
.$stredit.'" title="'.$stredit.'" /></a>'. "\n";
- } else {
+
+ } else if ($type == 'item' or $type == 'courseitem' or $type == 'categoryitem') {
$html .= '<a href="report/grader/edit_item.php?courseid='.$object->courseid.'&id='.$object->id.'">';
$html .= '<img src="'.$CFG->pixpath.'/t/edit.gif" class="iconsmall" alt="'
.$stredit.'" title="'.$stredit.'" /></a>'. "\n";
+
+ } else if ($type == 'grade') {
+ $html .= '<a href="report/grader/edit_grade.php?courseid='.$object->courseid.'&id='.$object->id.'">';
+ $html .= '<img src="'.$CFG->pixpath.'/t/edit.gif" class="iconsmall" alt="'
+ .$stredit.'" title="'.$stredit.'" /></a>'. "\n";
}
// Prepare Hide/Show icon state
margin:0px 20px 0px 20px;
}
+
/* new grades CSS */
#grade-report table {
border-style:solid;
}
-#grade-report th.item {
- border-width:1px 1px 1px 1px;
+#grade-report td.fillerfirst {
+ border-width:0px 0px 0px 1px;
border-style:solid;
}
-/* gradebook edit tree */
-#grade_edit_tree .movetarget {
- position: relative;
- width: 80px;
- height: 16px;
+#grade-report td.fillerlast {
+ border-width:0px 1px 0px 0px;
+ border-style:solid;
}
-#content ul#grade_edit_tree {
- width: auto;
+#grade-report th.item {
+ border-width:1px 1px 1px 1px;
+ border-style:solid;
}
-#grade_edit_tree li {
- list-style: none;
- margin-top: 8px;
+/* gradebook edit tree */
+
+#grade-report-grader-category .gradetreebox {
+ width:70%;
+ margin-left:auto;
+ margin-right:auto;
+ margin-top:10px;
+ padding-bottom:15px;
}
-#grade_edit_tree li div.moduleicon {
- margin-right: 5px;
- display: inline;
+#grade-report-grader-category .buttons {
+ margin: 20px;
+ text-align:center;
}
-#grade_edit_tree li div.select_checkbox {
- margin-right: 5px;
+#grade-report-grader-category .buttons .singlebutton {
display: inline;
+ padding: 5px;
}
-#grade_edit_tree li.insertion {
- cursor: pointer;
-}
-#grade_edit_tree .moveuparrow {
- cursor: pointer;
+#grade-report-grader-category .movetarget {
+ position: relative;
+ width: 80px;
+ height: 16px;
}
-#grade_edit_tree .movedownarrow {
- cursor: pointer;
+#grade-report-grader-category ul#grade_tree {
+ width: auto;
}
-#grade_edit_tree form.movearrow div {
- display: inline;
+#grade-report-grader-category ul#grade_tree li {
+ list-style: none;
}
-#grade_edit_tree form.movearrow {
- display: inline;
+#grade-report-grader-category ul#grade_tree li.category {
+ margin-bottom: 6px;
}
-#grade_edit_tree .selected_element {
+#grade-report-grader-category .moving {
background-color: #E8EEF7;
}
-#grade_edit_tree .icons {
- position: relative;
- display: inline;
- margin-left: 10px;
+#grade-report-grader-category .iconsmall {
+ margin-left: 4px;
}
+
/***
*** Login
***/