From: nicolasconnault Date: Fri, 28 Aug 2009 05:29:05 +0000 (+0000) Subject: MDL-19797 Upgraded most output code in grader report X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=319770d74719c34efce001a9ea0330334d15eb46;p=moodle.git MDL-19797 Upgraded most output code in grader report --- diff --git a/grade/report/grader/functions.js b/grade/report/grader/functions.js index 6498690f31..8b0e2adfd6 100755 --- a/grade/report/grader/functions.js +++ b/grade/report/grader/functions.js @@ -13,6 +13,10 @@ function set_row(idx) { } } +function yui_set_row(e) { + set_row(this.parentNode.rowIndex); +} + /** highlight/unset the column of a table **/ function set_col(idx) { var table = document.getElementById('user-grades'); diff --git a/grade/report/grader/index.php b/grade/report/grader/index.php index 09ef890dc5..2eab35fa45 100644 --- a/grade/report/grader/index.php +++ b/grade/report/grader/index.php @@ -180,22 +180,14 @@ $reporthtml .= $report->get_endhtml(); $reporthtml .= ''; // print submit button -if ($USER->gradeediting[$course->id] and !$report->get_pref('enableajax')) { - echo '
'; - echo '
'; - echo ''; - echo ''; - echo ''; -} - -echo $reporthtml; - -// print submit button -if ($USER->gradeediting[$course->id] && ($report->get_pref('showquickfeedback') - || - $report->get_pref('quickgrading')) && !$report->get_pref('enableajax')) { - echo '
'; - echo '
'; +if ($USER->gradeediting[$course->id] && ($report->get_pref('showquickfeedback') || $report->get_pref('quickgrading')) && !$report->get_pref('enableajax')) { + $form = new html_form(); + $form->url = new moodle_url('index.php', array('id' => $courseid, 'report' => 'grader')); + $form->button->text = get_string('update'); + $form->button->add_class('submit'); + echo $OUTPUT->form($form, $reporthtml); +} else { + echo $reporthtml; } // prints paging bar at bottom for large pages @@ -203,7 +195,7 @@ if (!empty($studentsperpage) && $studentsperpage >= 20) { echo $OUTPUT->paging_bar(moodle_paging_bar::make($numusers, $report->page, $studentsperpage, $report->pbarurl)); } -echo '
tooltip panel
'; +echo $OUTPUT->container('tooltip panel', '', 'hiddentooltiproot'); // Print AJAX code if ($report->get_pref('enableajax')) { require_once 'ajax.php'; diff --git a/grade/report/grader/lib.php b/grade/report/grader/lib.php index 87afb84ba9..8ba9745bcc 100644 --- a/grade/report/grader/lib.php +++ b/grade/report/grader/lib.php @@ -63,9 +63,9 @@ class grade_report_grader extends grade_report { /** * The bound params for $userselect - * @var array $userselect_params + * @var array $userselectparams */ - public $userselect_params = array(); + public $userselectparams = array(); /** * List of collapsed categories from user preference @@ -84,7 +84,7 @@ class grade_report_grader extends grade_report { * */ public $canviewhidden; - var $preferences_page=false; + var $preferencespage=false; /** * Constructor. Sets local copies of user preferences and initialises grade_tree. @@ -125,17 +125,15 @@ class grade_report_grader extends grade_report { $this->sortitemid = $sortitemid; // base url for sorting by first/last name - $studentsperpage = $this->get_pref('studentsperpage'); - $perpage = ''; - $curpage = ''; + $this->baseurl = new moodle_url('index.php', array('id' => $this->courseid)); + + $studentsperpage = $this->get_pref('studentsperpage'); if (!empty($studentsperpage)) { - $perpage = '&perpage='.$studentsperpage; - $curpage = '&page='.$this->page; + $this->baseurl->params(array('perpage' => $studentsperpage, 'page' => $this->page)); } - $this->baseurl = 'index.php?id='.$this->courseid. $perpage.$curpage.'&'; - $this->pbarurl = 'index.php?id='.$this->courseid.$perpage.'&'; + $this->pbarurl = new moodle_url('index.php', array('id' => $this->courseid, 'perpage' => $studentsperpage)); $this->setup_groups(); @@ -174,9 +172,9 @@ class grade_report_grader extends grade_report { // skip, not a grade nor feedback if (strpos($varname, 'grade') === 0) { - $data_type = 'grade'; + $datatype = 'grade'; } else if (strpos($varname, 'feedback') === 0) { - $data_type = 'feedback'; + $datatype = 'feedback'; } else { continue; } @@ -192,15 +190,15 @@ class grade_report_grader extends grade_report { continue; } - if (!$grade_item = grade_item::fetch(array('id'=>$itemid, 'courseid'=>$this->courseid))) { // we must verify course id here! + if (!$gradeitem = grade_item::fetch(array('id'=>$itemid, 'courseid'=>$this->courseid))) { // we must verify course id here! print_error('invalidgradeitmeid'); } // Pre-process grade - if ($data_type == 'grade') { + if ($datatype == 'grade') { $feedback = false; $feedbackformat = false; - if ($grade_item->gradetype == GRADE_TYPE_SCALE) { + if ($gradeitem->gradetype == GRADE_TYPE_SCALE) { if ($postedvalue == -1) { // -1 means no grade $finalgrade = null; } else { @@ -215,7 +213,7 @@ class grade_report_grader extends grade_report { if (is_null($finalgrade)) { // ok } else { - $bounded = $grade_item->bounded_grade($finalgrade); + $bounded = $gradeitem->bounded_grade($finalgrade); if ($bounded > $finalgrade) { $errorstr = 'lessthanmin'; } else if ($bounded < $finalgrade) { @@ -226,11 +224,11 @@ class grade_report_grader extends grade_report { $user = $DB->get_record('user', array('id' => $userid), 'id, firstname, lastname'); $gradestr = new object(); $gradestr->username = fullname($user); - $gradestr->itemname = $grade_item->get_name(); + $gradestr->itemname = $gradeitem->get_name(); $warnings[] = get_string($errorstr, 'grades', $gradestr); } - } else if ($data_type == 'feedback') { + } else if ($datatype == 'feedback') { $finalgrade = false; $trimmed = trim($postedvalue); if (empty($trimmed)) { @@ -258,7 +256,7 @@ class grade_report_grader extends grade_report { } } - $grade_item->update_final_grade($userid, $finalgrade, 'gradebook', $feedback, FORMAT_MOODLE); + $gradeitem->update_final_grade($userid, $finalgrade, 'gradebook', $feedback, FORMAT_MOODLE); } return $warnings; @@ -328,10 +326,10 @@ class grade_report_grader extends grade_report { public function load_users() { global $CFG, $DB; - list($usql, $gbr_params) = $DB->get_in_or_equal(explode(',', $this->gradebookroles), SQL_PARAMS_NAMED, 'grbr0'); + list($usql, $gbrparams) = $DB->get_in_or_equal(explode(',', $this->gradebookroles), SQL_PARAMS_NAMED, 'grbr0'); if (is_numeric($this->sortitemid)) { - $params = array_merge(array('gitemid'=>$this->sortitemid), $gbr_params, $this->groupwheresql_params); + $params = array_merge(array('gitemid'=>$this->sortitemid), $gbrparams, $this->groupwheresql_params); // the MAX() magic is required in order to please PG $sort = "MAX(g.finalgrade) $this->sortorder"; @@ -357,7 +355,7 @@ class grade_report_grader extends grade_report { $sort = "u.idnumber $this->sortorder"; break; } - $params = array_merge($gbr_params, $this->groupwheresql_params); + $params = array_merge($gbrparams, $this->groupwheresql_params); $sql = "SELECT DISTINCT u.id, u.firstname, u.lastname, u.imagealt, u.picture, u.idnumber FROM {user} u JOIN {role_assignments} ra ON u.id = ra.userid @@ -427,37 +425,37 @@ class grade_report_grader extends grade_report { * @return string HTML code */ public function get_toggles_html() { - global $CFG, $USER, $COURSE; + global $CFG, $USER, $COURSE, $OUTPUT; - $html = '
'; + $html = ''; if ($USER->gradeediting[$this->courseid]) { if (has_capability('moodle/grade:manage', $this->context) or has_capability('moodle/grade:hide', $this->context)) { - $html .= $this->print_toggle('eyecons', true); + $html .= $this->print_toggle('eyecons'); } if (has_capability('moodle/grade:manage', $this->context) or has_capability('moodle/grade:lock', $this->context) or has_capability('moodle/grade:unlock', $this->context)) { - $html .= $this->print_toggle('locks', true); + $html .= $this->print_toggle('locks'); } if (has_capability('moodle/grade:manage', $this->context)) { - $html .= $this->print_toggle('quickfeedback', true); + $html .= $this->print_toggle('quickfeedback'); } if (has_capability('moodle/grade:manage', $this->context)) { - $html .= $this->print_toggle('calculations', true); + $html .= $this->print_toggle('calculations'); } } if ($this->canviewhidden) { - $html .= $this->print_toggle('averages', true); + $html .= $this->print_toggle('averages'); } - $html .= $this->print_toggle('ranges', true); + $html .= $this->print_toggle('ranges'); if (!empty($CFG->enableoutcomes)) { - $html .= $this->print_toggle('nooutcomes', true); + $html .= $this->print_toggle('nooutcomes'); } - $html .= '
'; - return $html; + + return $OUTPUT->container($html, 'grade-report-toggles'); } /** @@ -466,54 +464,53 @@ class grade_report_grader extends grade_report { * @param bool $return Whether to return the HTML string rather than printing it * @return void */ - public function print_toggle($type, $return=false) { + public function print_toggle($type) { global $CFG, $OUTPUT; - $icons = array('eyecons' => 't/hide.gif', - 'calculations' => 't/calc.gif', - 'locks' => 't/lock.gif', - 'averages' => 't/mean.gif', - 'quickfeedback' => 't/feedback.gif', - 'nooutcomes' => 't/outcomes.gif'); + $icons = array('eyecons' => 't/hide', + 'calculations' => 't/calc', + 'locks' => 't/lock', + 'averages' => 't/mean', + 'quickfeedback' => 't/feedback', + 'nooutcomes' => 't/outcomes'); - $pref_name = 'grade_report_show' . $type; + $prefname = 'grade_report_show' . $type; - if (array_key_exists($pref_name, $CFG)) { - $show_pref = get_user_preferences($pref_name, $CFG->$pref_name); + if (array_key_exists($prefname, $CFG)) { + $showpref = get_user_preferences($prefname, $CFG->$prefname); } else { - $show_pref = get_user_preferences($pref_name); + $showpref = get_user_preferences($prefname); } $strshow = $this->get_lang_string('show' . $type, 'grades'); $strhide = $this->get_lang_string('hide' . $type, 'grades'); - $show_hide = 'show'; - $toggle_action = 1; + $showhide = 'show'; + $toggleaction = 1; - if ($show_pref) { - $show_hide = 'hide'; - $toggle_action = 0; + if ($showpref) { + $showhide = 'hide'; + $toggleaction = 0; } if (array_key_exists($type, $icons)) { - $image_name = $icons[$type]; + $imagename = $icons[$type]; } else { - $image_name = "t/$type.gif"; + $imagename = "t/$type.gif"; } - $string = ${'str' . $show_hide}; + $string = ${'str' . $showhide}; - $img = ''
-                      .$string.''. "\n"; + $toggleicon = new moodle_action_icon(); + $toggleicon->image->src = $OUTPUT->old_icon_url($imagename); + $toggleicon->image->add_class('iconsmall'); + $toggleicon->alt = $string; + $toggleicon->title = $string; + $toggleicon->link->url = $this->baseurl->out(false, array('toggle' => $toggleaction, 'toggle_type' => $type), false); - $retval = '
' . $img . '" - . $string . '
'; + $retval = $OUTPUT->container($OUTPUT->action_icon($toggleicon, 'gradertoggle')); - if ($return) { - return $retval; - } else { - echo $retval; - } + return $retval; } /** @@ -521,7 +518,7 @@ class grade_report_grader extends grade_report { * @return string $headerhtml */ public function get_headerhtml() { - global $CFG, $USER; + global $CFG, $USER, $OUTPUT; $this->rowcount = 0; $fixedstudents = $this->is_fixed_students(); @@ -560,7 +557,7 @@ class grade_report_grader extends grade_report { $numrows = count($this->gtree->get_levels()); - $columns_to_unset = array(); + $columnstounset = array(); foreach ($this->gtree->get_levels() as $key=>$row) { $columncount = 0; @@ -574,9 +571,12 @@ class grade_report_grader extends grade_report { } else { $headerhtml .= ''; if ($key == $numrows - 1) { - $headerhtml .= '' - . $strfirstname . ' ' - . $firstarrow. '/ ' . $strlastname . ''. $lastarrow .''; + $sortfirstname = html_link::make(clone($this->baseurl), $strfirstname); + $sortfirstname->url->param('sortitemid', 'firstname'); + $sortlastname = html_link::make(clone($this->baseurl), $strlastname); + $sortlastname->url->param('sortitemid', 'lastname'); + $headerhtml .= '' . $OUTPUT->link($sortfirstname) + . $firstarrow. '/ ' . $OUTPUT->link($sortlastname) . $lastarrow .''; if ($showuseridnumber) { if ('idnumber' == $this->sortitemid) { if ($this->sortorder == 'ASC') { @@ -587,8 +587,9 @@ class grade_report_grader extends grade_report { } else { $idnumberarrow = ''; } - $headerhtml .= '' - . get_string('idnumber') . ' ' . $idnumberarrow . ''; + $sortidnumber = html_link::make(clone($this->baseurl), get_string('idnumber')); + $sortidnumber->url->param('sortitemid', 'idnumber'); + $headerhtml .= '' . $OUTPUT->link($sortidnumber) . $idnumberarrow . ''; } } else { $colspan=''; @@ -606,9 +607,9 @@ class grade_report_grader extends grade_report { foreach ($row as $columnkey => $element) { - $sort_link = ''; + $sortlink = clone($this->baseurl); if (isset($element['object']->id)) { - $sort_link = $this->baseurl.'&sortitemid=' . $element['object']->id; + $sortlink->param('sortitemid', $element['object']->id); } $eid = $element['eid']; @@ -656,12 +657,12 @@ class grade_report_grader extends grade_report { if ($element['object']->id == $this->sortitemid) { if ($this->sortorder == 'ASC') { - $arrow = $this->get_sort_arrow('up', $sort_link); + $arrow = $this->get_sort_arrow('up', $sortlink); } else { - $arrow = $this->get_sort_arrow('down', $sort_link); + $arrow = $this->get_sort_arrow('down', $sortlink); } } else { - $arrow = $this->get_sort_arrow('move', $sort_link); + $arrow = $this->get_sort_arrow('move', $sortlink); } $hidden = ''; @@ -699,27 +700,27 @@ class grade_report_grader extends grade_report { $fixedstudents = $this->is_fixed_students(); // Preload scale objects for items with a scaleid - $scales_list = array(); + $scaleslist = array(); $tabindices = array(); foreach ($this->gtree->get_items() as $item) { if (!empty($item->scaleid)) { - $scales_list[] = $item->scaleid; + $scaleslist[] = $item->scaleid; } $tabindices[$item->id]['grade'] = $gradetabindex; $tabindices[$item->id]['feedback'] = $gradetabindex + $numusers; $gradetabindex += $numusers * 2; } - $scales_array = array(); + $scalesarray = array(); - if (!empty($scales_list)) { - $scales_array = $DB->get_records_list('scale', 'id', $scales_list); + if (!empty($scaleslist)) { + $scalesarray = $DB->get_records_list('scale', 'id', $scaleslist); } - $row_classes = array(' even ', ' odd '); + $rowclasses = array(' even ', ' odd '); - $row_classes = array(' even ', ' odd '); + $rowclasses = array(' even ', ' odd '); foreach ($this->users as $userid => $user) { @@ -727,26 +728,26 @@ class grade_report_grader extends grade_report { $altered = array(); $unknown = array(); } else { - $hiding_affected = grade_grade::get_hiding_affected($this->grades[$userid], $this->gtree->get_items()); - $altered = $hiding_affected['altered']; - $unknown = $hiding_affected['unknown']; - unset($hiding_affected); + $hidingaffected = grade_grade::get_hiding_affected($this->grades[$userid], $this->gtree->get_items()); + $altered = $hidingaffected['altered']; + $unknown = $hidingaffected['unknown']; + unset($hidingaffected); } $columncount = 0; if ($fixedstudents) { - $studentshtml .= ''; + $studentshtml .= ''; } else { // Student name and link - $user_pic = null; + $userpic = null; if ($showuserimage) { - $user_pic = '
' . $OUTPUT->user_picture(moodle_user_picture::make($user, $this->courseid)) . '
'; + $userpic = $OUTPUT->container($OUTPUT->user_picture(moodle_user_picture::make($user, $this->courseid)), 'userpic'); } - $studentshtml .= '' - .''.$user_pic - .'' - .fullname($user).''; + $userlink = html_link::make(new moodle_url($CFG->wwwroot.'/user/view.php', array('id' => $user->id, 'course' => $this->course->id)), fullname($user)); + $studentshtml .= '' + .''.$userpic + .$OUTPUT->link($userlink).''; if ($showuseridnumber) { $studentshtml .= ''. @@ -775,7 +776,8 @@ class grade_report_grader extends grade_report { if (!$this->canviewhidden and $grade->is_hidden()) { if (!empty($CFG->grade_hiddenasdate) and $grade->get_datesubmitted() and !$item->is_category_item() and !$item->is_course_item()) { // the problem here is that we do not have the time when grade value was modified, 'timemodified' is general modification date for grade_grades records - $studentshtml .= ''.userdate($grade->get_datesubmitted(),get_string('strftimedatetimeshort')).''; + $studentshtml .= '' + . $OUTPUT->span(userdate($grade->get_datesubmitted(),get_string('strftimedatetimeshort')), 'datesubmitted') . ''; } else { $studentshtml .= '-'; } @@ -801,20 +803,17 @@ class grade_report_grader extends grade_report { // $cellclasses .= ' excluded'; } - $grade_title = '
'.fullname($user).'
'; - $grade_title .= '
'.$item->get_name(true).'
'; + $gradetitle = $OUTPUT->container(fullname($user), 'fullname'); + $gradetitle .= $OUTPUT->container($item->get_name(true), 'itemname'); if (!empty($grade->feedback) && !$USER->gradeediting[$this->courseid]) { - $grade_title .= '
' - .wordwrap(trim(format_string($grade->feedback, $grade->feedbackformat)), 34, '
') . '
'; - } else { - + $gradetitle .= $OUTPUT->container(wordwrap(trim(format_string($grade->feedback, $grade->feedbackformat)), 34, '
'), 'feedback'); } - $studentshtml .= ''; + $studentshtml .= ''; if ($grade->is_excluded()) { - $studentshtml .= ''.get_string('excluded', 'grades') . ' '; + $studentshtml .= $OUTPUT->span(get_string('excluded', 'grades'), 'excludedfloater'); } // Do not show any icons if no grade (no record in DB to match) @@ -838,12 +837,12 @@ class grade_report_grader extends grade_report { // or a drop down (for scales) // grades in item of type grade category or course are not directly editable if ($item->needsupdate) { - $studentshtml .= ''.get_string('error').''; + $studentshtml .= $OUTPUT->span(get_string('error'), "gradingerror$hidden"); } else if ($USER->gradeediting[$this->courseid]) { - if ($item->scaleid && !empty($scales_array[$item->scaleid])) { - $scale = $scales_array[$item->scaleid]; + if ($item->scaleid && !empty($scalesarray[$item->scaleid])) { + $scale = $scalesarray[$item->scaleid]; $gradeval = (int)$gradeval; // scales use only integers $scales = explode(",", $scale->scale); // reindex because scale is off 1 @@ -875,10 +874,10 @@ class grade_report_grader extends grade_report { // invalid grade if gradeval < 1 if ($gradeval < 1) { - $studentshtml .= '-'; + $studentshtml .= $OUTPUT->span('-', "gradevalue$hidden$gradepass"); } else { $gradeval = $grade->grade_item->bounded_grade($gradeval); //just in case somebody changes scale - $studentshtml .= ''.$scales[$gradeval-1].''; + $studentshtml .= $OUTPUT->span($scales[$gradeval-1], "gradevalue$hidden$gradepass"); } } else { // no such scale, throw error? @@ -889,10 +888,10 @@ class grade_report_grader extends grade_report { $value = format_float($gradeval, $decimalpoints); $studentshtml .= ''; $studentshtml .= ''; } else { - $studentshtml .= ''.format_float($gradeval, $decimalpoints).''; + $studentshtml .= $OUTPUT->span(format_float($gradeval, $decimalpoints), "gradevalue$hidden$gradepass"); } } @@ -913,10 +912,9 @@ class grade_report_grader extends grade_report { // If feedback present, surround grade with feedback tooltip: Open span here if ($item->needsupdate) { - $studentshtml .= ''.get_string('error').''; - + $studentshtml .= $OUTPUT->span(get_string('error'), "gradingerror$hidden$gradepass"); } else { - $studentshtml .= ''.grade_format_gradevalue($gradeval, $item, true, $gradedisplaytype, null).''; + $studentshtml .= $OUTPUT->span(grade_format_gradevalue($gradeval, $item, true, $gradedisplaytype, null), "gradevalue$hidden$gradepass"); } } @@ -965,92 +963,155 @@ class grade_report_grader extends grade_report { } if ($fixedstudents) { - $studentshtml .= '
- - '; + $fixedcolumntable = new html_table(); + $fixedcolumntable->id = 'fixed_column'; + $fixedcolumntable->add_class('fixed_grades_column'); + $fixedcolumntable->bodyclasses = array('leftbody'); - $colspan = ''; + $colspan = null; if ($showuseridnumber) { - $colspan = 'colspan="2"'; + $colspan = 2; } $levels = count($this->gtree->levels) - 1; - for ($i = 0; $i < $levels; $i++) { - $studentshtml .= ' - - - - '; + $fillercell = new html_table_cell(); + $fillercell->add_classes(array('fixedcolumn', 'cell', 'c0', 'topleft')); + $fillercell->text = ' '; + $fillercell->colspan = $colspan; + $fixedcolumntable->data[] = html_table_row::make(array($fillercell)); } - $studentshtml .= ''; + $sortfirstname = html_link::make(clone($this->baseurl), $strfirstname); + $sortfirstname->url->param('sortitemid', 'firstname'); + $sortlastname = html_link::make(clone($this->baseurl), $strlastname); + $sortlastname->url->param('sortitemid', 'lastname'); + + $headerrow = new html_table_row(); + $headerrow->add_class('heading'); + + $studentheader = new html_table_cell(); + $studentheader->add_classes(array('header', 'c0')); + $studentheader->scope = 'col'; + $studentheader->header = true; + $studentheader->id = 'studentheader'; + $studentheader->text = $OUTPUT->link($sortfirstname) . $firstarrow. '/ ' . $OUTPUT->link($sortlastname) . $lastarrow; + + $headerrow->cells[] = $studentheader; if ($showuseridnumber) { + $sortidnumberlink = html_link::make(clone($this->baseurl), get_string('idnumber')); + $sortidnumberlink->url->param('sortitemid', 'idnumber'); + + $idnumberheader = new html_table_cell(); + $idnumberheader->add_classes(array('header', 'c0', 'useridnumber')); + $idnumberheader->scope = 'col'; + $idnumberheader->header = true; + $idnumberheader->text = $OUTPUT->link($sortidnumberlink); + if ('idnumber' == $this->sortitemid) { if ($this->sortorder == 'ASC') { - $idnumberarrow = print_arrow('up', $strsortasc, true); + $idnumberheader->text .= print_arrow('up', $strsortasc, true); } else { - $idnumberarrow = print_arrow('down', $strsortdesc, true); + $idnumberheader->text .= print_arrow('down', $strsortdesc, true); } - } else { - $idnumberarrow = ''; } - $studentshtml .= ''; + $headerrow->cells[] = $idnumberheader; } - $studentshtml .= ''; + $fixedcolumntable->data[] = $headerrow; if ($USER->gradeediting[$this->courseid]) { - $studentshtml .= ''; + $controlsrow = new html_table_row(); + $controlsrow->add_class('controls'); + $controlscell = new html_table_cell(); + $controlscell->add_classes(array('header', 'c0', 'controls')); + $controlscell->colspan = $colspan; + $controlscell->text = $this->get_lang_string('controls','grades'); + + $controlsrow->cells[] = $controlscell; + $fixedcolumntable->data[] = $controlsrow; } - $row_classes = array(' even ', ' odd '); + $rowclasses = array('even', 'odd'); foreach ($this->users as $userid => $user) { + $userrow = new html_table_row(); + $userrow->add_classes(array('r'.$this->rowcount++, $rowclasses[$this->rowcount % 2])); + + $usercell = new html_table_cell(); + $usercell->add_classes(array('c0', 'user')); + $usercell->header = true; + $usercell->scope = 'row'; + $usercell->add_action('click', 'yui_set_row'); - $user_pic = null; if ($showuserimage) { - $user_pic = '
' . $OUTPUT->user_picture(moodle_user_picture::make($user, $this->courseid)) . "
\n"; + $usercell->text = $OUTPUT->container($OUTPUT->user_picture(moodle_user_picture::make($user, $this->courseid)), 'userpic'); } - $studentshtml .= '' - .'\n"; + $usercell->text .= $OUTPUT->link(html_link::make(new moodle_url($CFG->wwwroot.'/user/view.php', array('id' => $user->id, 'course' => $this->course->id)), fullname($user))); + $userrow->cells[] = $usercell; if ($showuseridnumber) { - $studentshtml .= '\n"; + $idnumbercell = new html_table_cell(); + $idnumbercell->add_classes(array('header', 'c0', 'useridnumber')); + $idnumbercell->header = true; + $idnumbercell->scope = 'row'; + $idnumbercell->add_action('click', 'yui_set_row'); + $userrow->cells[] = $idnumbercell; } - $studentshtml .= "\n"; + $fixedcolumntable->data[] = $userrow; } if ($this->get_pref('showranges')) { - $studentshtml .= '' . ''; + $rangerow = new html_table_row(); + $rangerow->add_classes(array('range', 'r'.$this->rowcount++)); + $rangecell = new html_table_cell(); + $rangecell->add_classes(array('header', 'c0', 'range')); + $rangecell->colspan = $colspan; + $rangecell->header = true; + $rangecell->scope = 'row'; + $rangecell->text = $this->get_lang_string('range','grades'); + $rangerow->cells[] = $rangecell; + $fixedcolumntable->data[] = $rangerow; } // Averages heading - $straverage_group = get_string('groupavg', 'grades'); + $straveragegroup = get_string('groupavg', 'grades'); $straverage = get_string('overallaverage', 'grades'); $showaverages = $this->get_pref('showaverages'); - $showaverages_group = $this->currentgroup && $showaverages; - - if ($showaverages_group) { - $studentshtml .= ''; + $showaveragesgroup = $this->currentgroup && $showaverages; + + if ($showaveragesgroup) { + $groupavgrow = new html_table_row(); + $groupavgrow->add_classes(array('groupavg', 'r'.$this->rowcount++)); + $groupavgcell = new html_table_cell(); + $groupavgcell->add_classes(array('header', 'c0', 'range')); + $groupavgcell->colspan = $colspan; + $groupavgcell->header = true; + $groupavgcell->scope = 'row'; + $groupavgcell->text = $straveragegroup; + $groupavgrow->cells[] = $groupavgcell; + $fixedcolumntable->data[] = $groupavgrow; } if ($showaverages) { - $studentshtml .= ''; + $avgrow = new html_table_row(); + $avgrow->add_classes(array('avg', 'r'.$this->rowcount++)); + $avgcell = new html_table_cell(); + $avgcell->add_classes(array('header', 'c0', 'range')); + $avgcell->colspan = $colspan; + $avgcell->header = true; + $avgcell->scope = 'row'; + $avgcell->text = $straverage; + $avgrow->cells[] = $avgcell; + $fixedcolumntable->data[] = $avgrow; } - $studentshtml .= ' -
' - . $strfirstname . ' ' - . $firstarrow. '/ ' . $strlastname . ''. $lastarrow .'' - . get_string('idnumber') . ' ' . $idnumberarrow . '
'.$this->get_lang_string('controls','grades').'
'.$user_pic - .'' - .fullname($user)."'. $user->idnumber."
'.$this->get_lang_string('range','grades').'
'.$straverage_group.'
'.$straverage.'
-
+ $studentshtml .= $OUTPUT->container($OUTPUT->table($fixedcolumntable), 'left_scroller'); + $studentshtml .= '
'; @@ -1105,14 +1166,14 @@ class grade_report_grader extends grade_report { $showaverages = $this->currentgroup && $this->get_pref('showaverages'); $groupsql = $this->groupsql; $groupwheresql = $this->groupwheresql; - $groupwheresql_params = $this->groupwheresql_params; + $groupwheresqlparams = $this->groupwheresql_params; $avgcssclass = 'groupavg'; } else { $straverage = get_string('overallaverage', 'grades'); $showaverages = $this->get_pref('showaverages'); $groupsql = ""; $groupwheresql = ""; - $groupwheresql_params = array(); + $groupwheresqlparams = array(); } if ($shownumberofgrades) { @@ -1121,10 +1182,10 @@ class grade_report_grader extends grade_report { $totalcount = $this->get_numusers($grouponly); - list($usql, $roles_params) = $DB->get_in_or_equal(explode(',', $this->gradebookroles), SQL_PARAMS_NAMED, 'grbr0'); + list($usql, $rolesparams) = $DB->get_in_or_equal(explode(',', $this->gradebookroles), SQL_PARAMS_NAMED, 'grbr0'); if ($showaverages) { - $params = array_merge(array('courseid'=>$this->courseid), $roles_params, $groupwheresql_params); + $params = array_merge(array('courseid'=>$this->courseid), $rolesparams, $groupwheresqlparams); // find sums of all grade items in course $SQL = "SELECT g.itemid, SUM(g.finalgrade) AS sum @@ -1139,10 +1200,10 @@ class grade_report_grader extends grade_report { AND g.finalgrade IS NOT NULL $groupwheresql GROUP BY g.itemid"; - $sum_array = array(); + $sumarray = array(); if ($sums = $DB->get_records_sql($SQL, $params)) { foreach ($sums as $itemid => $csum) { - $sum_array[$itemid] = $csum->sum; + $sumarray[$itemid] = $csum->sum; } } @@ -1151,7 +1212,7 @@ class grade_report_grader extends grade_report { // MDL-10875 Empty grades must be evaluated as grademin, NOT always 0 // This query returns a count of ungraded grades (NULL finalgrade OR no matching record in grade_grades table) - $params = array_merge(array('courseid'=>$this->courseid), $roles_params, $groupwheresql_params); + $params = array_merge(array('courseid'=>$this->courseid), $rolesparams, $groupwheresqlparams); $SQL = "SELECT gi.id, COUNT(u.id) AS count FROM {grade_items} gi CROSS JOIN {user} u @@ -1165,7 +1226,7 @@ class grade_report_grader extends grade_report { $groupwheresql GROUP BY gi.id"; - $ungraded_counts = $DB->get_records_sql($SQL, $params); + $ungradedcounts = $DB->get_records_sql($SQL, $params); $fixedstudents = $this->is_fixed_students(); if (!$fixedstudents) { @@ -1184,21 +1245,21 @@ class grade_report_grader extends grade_report { continue; } - if (!isset($sum_array[$item->id])) { - $sum_array[$item->id] = 0; + if (!isset($sumarray[$item->id])) { + $sumarray[$item->id] = 0; } - if (empty($ungraded_counts[$itemid])) { - $ungraded_count = 0; + if (empty($ungradedcounts[$itemid])) { + $ungradedcount = 0; } else { - $ungraded_count = $ungraded_counts[$itemid]->count; + $ungradedcount = $ungradedcounts[$itemid]->count; } if ($meanselection == GRADE_REPORT_MEAN_GRADED) { - $mean_count = $totalcount - $ungraded_count; + $meancount = $totalcount - $ungradedcount; } else { // Bump up the sum by the number of ungraded items * grademin - $sum_array[$item->id] += $ungraded_count * $item->grademin; - $mean_count = $totalcount; + $sumarray[$item->id] += $ungradedcount * $item->grademin; + $meancount = $totalcount; } $decimalpoints = $item->get_decimals(); @@ -1222,16 +1283,16 @@ class grade_report_grader extends grade_report { $decimalpoints = $averagesdecimalpoints; } - if (!isset($sum_array[$item->id]) || $mean_count == 0) { + if (!isset($sumarray[$item->id]) || $meancount == 0) { $avghtml .= ''; } else { - $sum = $sum_array[$item->id]; - $avgradeval = $sum/$mean_count; + $sum = $sumarray[$item->id]; + $avgradeval = $sum/$meancount; $gradehtml = grade_format_gradevalue($avgradeval, $item, true, $displaytype, $decimalpoints); $numberofgrades = ''; if ($shownumberofgrades) { - $numberofgrades = " ($mean_count)"; + $numberofgrades = " ($meancount)"; } $avghtml .= ''; @@ -1275,9 +1336,9 @@ class grade_report_grader extends grade_report { $hidden = ' hidden '; } - $formatted_range = $item->get_formatted_range($rangesdisplaytype, $rangesdecimalpoints); + $formattedrange = $item->get_formatted_range($rangesdisplaytype, $rangesdecimalpoints); - $rangehtml .= ''; + $rangehtml .= ''; } $rangehtml .= ''; @@ -1333,39 +1394,39 @@ class grade_report_grader extends grade_report { * @return string HTML */ protected function get_icons($element) { - global $CFG, $USER; + global $CFG, $USER, $OUTPUT; if (!$USER->gradeediting[$this->courseid]) { return '
'; } // Init all icons - $edit_icon = ''; + $editicon = ''; if ($element['type'] != 'categoryitem' && $element['type'] != 'courseitem') { - $edit_icon = $this->gtree->get_edit_icon($element, $this->gpr); + $editicon = $this->gtree->get_edit_icon($element, $this->gpr); } - $edit_calculation_icon = ''; - $show_hide_icon = ''; - $lock_unlock_icon = ''; + $editcalculationicon = ''; + $showhideicon = ''; + $lockunlockicon = ''; if (has_capability('moodle/grade:manage', $this->context)) { if ($this->get_pref('showcalculations')) { - $edit_calculation_icon = $this->gtree->get_calculation_icon($element, $this->gpr); + $editcalculationicon = $this->gtree->get_calculation_icon($element, $this->gpr); } if ($this->get_pref('showeyecons')) { - $show_hide_icon = $this->gtree->get_hiding_icon($element, $this->gpr); + $showhideicon = $this->gtree->get_hiding_icon($element, $this->gpr); } if ($this->get_pref('showlocks')) { - $lock_unlock_icon = $this->gtree->get_locking_icon($element, $this->gpr); + $lockunlockicon = $this->gtree->get_locking_icon($element, $this->gpr); } } - return '
'.$edit_icon.$edit_calculation_icon.$show_hide_icon.$lock_unlock_icon.'
'; + return $OUTPUT->container($editicon.$editcalculationicon.$showhideicon.$lockunlockicon, 'grade_icons'); } /** @@ -1376,26 +1437,32 @@ class grade_report_grader extends grade_report { protected function get_collapsing_icon($element) { global $OUTPUT; - $contract_expand_icon = ''; + $icon = ''; // If object is a category, display expand/contract icon if ($element['type'] == 'category') { // Load language strings - $strswitch_minus = $this->get_lang_string('aggregatesonly', 'grades'); - $strswitch_plus = $this->get_lang_string('gradesonly', 'grades'); - $strswitch_whole = $this->get_lang_string('fullmode', 'grades'); + $strswitchminus = $this->get_lang_string('aggregatesonly', 'grades'); + $strswitchplus = $this->get_lang_string('gradesonly', 'grades'); + $strswitchwhole = $this->get_lang_string('fullmode', 'grades'); - $expand_contract = 'switch_minus'; // Default: expanded + $contractexpandicon = new moodle_action_icon(); + $contractexpandicon->link->url = new moodle_url($this->gpr->get_return_url(null, array('target'=>$element['eid'], 'action'=>'switch_minus', 'sesskey'=>sesskey()))); + $contractexpandicon->image->add_class('iconsmall'); + $contractexpandicon->image->src = $OUTPUT->old_icon_url('t/switch_minus'); + $contractexpandicon->image->alt = $strswitchminus; if (in_array($element['object']->id, $this->collapsed['aggregatesonly'])) { - $expand_contract = 'switch_plus'; + $contractexpandicon->image->src = $OUTPUT->old_icon_url('t/switch_plus'); + $contractexpandicon->image->alt = $strswitchplus; + $contractexpandicon->link->url->param('action', 'switch_plus'); } elseif (in_array($element['object']->id, $this->collapsed['gradesonly'])) { - $expand_contract = 'switch_whole'; + $contractexpandicon->image->src = $OUTPUT->old_icon_url('t/switch_whole'); + $contractexpandicon->image->alt = $strswitchwhole; + $contractexpandicon->link->url->param('action', 'switch_whole'); } - $url = $this->gpr->get_return_url(null, array('target'=>$element['eid'], 'action'=>$expand_contract, 'sesskey'=>sesskey())); - $contract_expand_icon = ''
-                                    .${'str'.$expand_contract}.''; + $icon = $OUTPUT->action_icon($contractexpandicon); } - return $contract_expand_icon; + return $icon; } /** diff --git a/grade/report/grader/styles.php b/grade/report/grader/styles.php index 5502e6d375..464959525c 100644 --- a/grade/report/grader/styles.php +++ b/grade/report/grader/styles.php @@ -323,12 +323,16 @@ vertical-align:middle; padding:0; } -.grade-report-grader td input { +.grade-report-grader td input.text { border:1px solid #666; margin-left:10px; margin-right:10px; } +.grade-report-grader td input.submit { +margin: 10px 10px 0px 10px; +} + .grade-report-grader table#quick_edit td.fullname { border-left:none; padding-left:5px; diff --git a/grade/report/lib.php b/grade/report/lib.php index 001ac15895..1f6aa5dfe1 100755 --- a/grade/report/lib.php +++ b/grade/report/lib.php @@ -316,15 +316,18 @@ abstract class grade_report { /** * Returns an arrow icon inside an tag, for the purpose of sorting a column. * @param string $direction - * @param string $sort_link + * @param moodle_url $sort_link * @param string HTML */ - protected function get_sort_arrow($direction='move', $sort_link=null) { + protected function get_sort_arrow($direction='move', $sortlink=null) { + global $OUTPUT; $matrix = array('up' => 'desc', 'down' => 'asc', 'move' => 'desc'); $strsort = $this->get_lang_string('sort' . $matrix[$direction]); $arrow = print_arrow($direction, $strsort, true); - $html = '' . $arrow . ''; + $link = html_link::make($sortlink, $arrow); + $link->title = $strsort; + $html = $OUTPUT->link($link); return $html; } } diff --git a/lang/en_utf8/grades.php b/lang/en_utf8/grades.php index 43ee02e25d..a417b0bfd5 100644 --- a/lang/en_utf8/grades.php +++ b/lang/en_utf8/grades.php @@ -475,6 +475,7 @@ $string['savepreferences'] = 'Save preferences'; $string['scaledpct'] = 'Scaled %%'; $string['scaleidhelp'] = 'When using the scale grade type, a scale can be selected. The scale for an activity-based grade item is selected on the update activity page.'; $string['scalestandardhelp'] = 'A standard scale is one that is available site-wide, for all courses.'; +$string['scaleconfirmdelete'] = 'Are you sure you wish to delete the scale \"$a\"?'; $string['seeallcoursegrades'] = 'See all course grades'; $string['selectdestination'] = 'Select destination of $a'; $string['selectalloroneuser'] = 'Select all or one user'; diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index d3acbf4b33..cdb7132811 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -1052,6 +1052,19 @@ class html_table extends labelled_html_component { * @var bool true causes the contents of the heading cells to be rotated 90 degrees. */ public $rotateheaders = false; + /** + * @var array $headclasses Array of CSS classes to apply to the table's thead. + */ + public $headclasses = array(); + /** + * @var array $bodyclasses Array of CSS classes to apply to the table's tbody. + */ + public $bodyclasses = array(); + /** + * @var array $footclasses Array of CSS classes to apply to the table's tfoot. + */ + public $footclasses = array(); + /** * @see moodle_html_component::prepare() @@ -1416,12 +1429,8 @@ class html_form extends moodle_html_component { * @return void */ public function __construct() { - static $yes; $this->button = new html_button(); - if (!isset($yes)) { - $yes = get_string('yes'); - $this->button->text = $yes; - } + $this->button->text = get_string('yes'); } /** diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 7144e744a3..51b78f0eee 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -1554,10 +1554,18 @@ class moodle_core_renderer extends moodle_renderer_base { /** * Prints an inline span element with optional text contents. * - * @param html_span $span A html_span object + * @param mixed $span A html_span object or some string content to wrap in a span + * @param mixed $classes A space-separated list or an array of classes. Only used if $span is a string * @return string A HTML fragment */ - public function span($span) { + public function span($span, $classes='') { + if (!($span instanceof html_span)) { + $text = $span; + $span = new html_span(); + $span->contents = $text; + $span->add_classes($classes); + } + $span = clone($span); $span->prepare(); $this->prepare_event_handlers($span); @@ -2028,7 +2036,7 @@ class moodle_core_renderer extends moodle_renderer_base { if (!empty($table->head)) { $countcols = count($table->head); - $output .= $this->output_start_tag('thead', array()) . "\n"; + $output .= $this->output_start_tag('thead', $table->headclasses) . "\n"; $output .= $this->output_start_tag('tr', array()) . "\n"; $keys = array_keys($table->head); $lastkey = end($keys); @@ -2077,7 +2085,7 @@ class moodle_core_renderer extends moodle_renderer_base { $oddeven = 1; $keys = array_keys($table->data); $lastrowkey = end($keys); - $output .= $this->output_start_tag('tbody', array()) . "\n"; + $output .= $this->output_start_tag('tbody', $table->bodyclasses) . "\n"; foreach ($table->data as $key => $row) { if (($row === 'hr') && ($countcols)) {
-'.$gradehtml.$numberofgrades.''. $formatted_range .''. $formattedrange .'