MDL-10286 Implementing the view feedback page. Added links to the user, module and...
[moodle-pu.git] / lib / gradelib.php
blob01a33cd5caf4537c17544547658fb5aa33def569
1 <?php // $Id$
3 ///////////////////////////////////////////////////////////////////////////
4 // //
5 // NOTICE OF COPYRIGHT //
6 // //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
9 // //
10 // Copyright (C) 2001-2003 Martin Dougiamas http://dougiamas.com //
11 // //
12 // This program is free software; you can redistribute it and/or modify //
13 // it under the terms of the GNU General Public License as published by //
14 // the Free Software Foundation; either version 2 of the License, or //
15 // (at your option) any later version. //
16 // //
17 // This program is distributed in the hope that it will be useful, //
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20 // GNU General Public License for more details: //
21 // //
22 // http://www.gnu.org/copyleft/gpl.html //
23 // //
24 ///////////////////////////////////////////////////////////////////////////
26 /**
27 * Library of functions for gradebook
29 * @author Moodle HQ developers
30 * @version $Id$
31 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
32 * @package moodlecore
35 define('GRADE_AGGREGATE_MEAN_ALL', 0);
36 define('GRADE_AGGREGATE_MEDIAN', 1);
37 define('GRADE_AGGREGATE_MEAN_GRADED', 2);
38 define('GRADE_AGGREGATE_MIN', 3);
39 define('GRADE_AGGREGATE_MAX', 4);
40 define('GRADE_AGGREGATE_MODE', 5);
42 define('GRADE_CHILDTYPE_ITEM', 0);
43 define('GRADE_CHILDTYPE_CAT', 1);
45 define('GRADE_ITEM', 0); // Used to compare class names with CHILDTYPE values
46 define('GRADE_CATEGORY', 1); // Used to compare class names with CHILDTYPE values
48 define('GRADE_CATEGORY_CONTRACTED', 0); // The state of a category header in the grader report
49 define('GRADE_CATEGORY_EXPANDED', 1); // The state of a category header in the grader report
51 define('GRADE_TYPE_NONE', 0);
52 define('GRADE_TYPE_VALUE', 1);
53 define('GRADE_TYPE_SCALE', 2);
54 define('GRADE_TYPE_TEXT', 3);
56 define('GRADE_UPDATE_OK', 0);
57 define('GRADE_UPDATE_FAILED', 1);
58 define('GRADE_UPDATE_MULTIPLE', 2);
59 define('GRADE_UPDATE_ITEM_DELETED', 3);
60 define('GRADE_UPDATE_ITEM_LOCKED', 4);
62 // Set up constants for report preferences
63 define('GRADER_REPORT_AGGREGATION_POSITION_LEFT', 0);
64 define('GRADER_REPORT_AGGREGATION_POSITION_RIGHT', 1);
65 define('GRADER_REPORT_AGGREGATION_VIEW_FULL', 0);
66 define('GRADER_REPORT_AGGREGATION_VIEW_COMPACT', 1);
67 define('GRADER_REPORT_GRADE_DISPLAY_TYPE_RAW', 0);
68 define('GRADER_REPORT_GRADE_DISPLAY_TYPE_PERCENTAGE', 1);
69 define('GRADER_REPORT_FEEDBACK_FORMAT_TEXT', 0);
70 define('GRADER_REPORT_FEEDBACK_FORMAT_HTML', 1);
73 require_once($CFG->libdir . '/grade/grade_category.php');
74 require_once($CFG->libdir . '/grade/grade_item.php');
75 require_once($CFG->libdir . '/grade/grade_grades.php');
76 require_once($CFG->libdir . '/grade/grade_scale.php');
77 require_once($CFG->libdir . '/grade/grade_outcome.php');
78 require_once($CFG->libdir . '/grade/grade_history.php');
79 require_once($CFG->libdir . '/grade/grade_grades_text.php');
80 require_once($CFG->libdir . '/grade/grade_tree.php');
82 /***** PUBLIC GRADE API *****/
84 /**
85 * Submit new or update grade; update/create grade_item definition. Grade must have userid specified,
86 * rawgrade and feedback with format are optional. rawgrade NULL means 'Not graded', missing property
87 * or key means do not change existing.
89 * Only following grade item properties can be changed 'itemname', 'idnumber', 'gradetype', 'grademax',
90 * 'grademin', 'scaleid', 'multfactor', 'plusfactor', 'deleted'.
92 * @param string $source source of the grade such as 'mod/assignment', often used to prevent infinite loops when processing grade_updated events
93 * @param int $courseid id of course
94 * @param string $itemtype type of grade item - mod, block, gradecategory, calculated
95 * @param string $itemmodule more specific then $itemtype - assignment, forum, etc.; maybe NULL for some item types
96 * @param int $iteminstance instance it of graded subject
97 * @param int $itemnumber most probably 0, modules can use other numbers when having more than one grades for each user
98 * @param mixed $grades grade (object, array) or several grades (arrays of arrays or objects), NULL if updating rgade_item definition only\
99 * @param mixed $itemdetails object or array describing the grading item, NULL if no change
101 function grade_update($source, $courseid, $itemtype, $itemmodule, $iteminstance, $itemnumber, $grades=NULL, $itemdetails=NULL) {
103 // only following grade_item properties can be changed in this function
104 $allowed = array('itemname', 'idnumber', 'gradetype', 'grademax', 'grademin', 'scaleid', 'multfactor', 'plusfactor', 'deleted');
106 // grade item identification
107 $params = compact('courseid', 'itemtype', 'itemmodule', 'iteminstance', 'itemnumber');
109 if (is_null($courseid) or is_null($itemtype)) {
110 debugging('Missing courseid or itemtype');
111 return GRADE_UPDATE_FAILED;
114 if (!$grade_items = grade_item::fetch_all($params)) {
115 // create a new one
116 $grade_item = false;
118 } else if (count($grade_items) == 1){
119 $grade_item = reset($grade_items);
120 unset($grade_items); //release memory
122 } else {
123 debugging('Found more than one grade item');
124 return GRADE_UPDATE_MULTIPLE;
127 /// Create or update the grade_item if needed
128 if (!$grade_item) {
129 if ($itemdetails) {
130 $itemdetails = (array)$itemdetails;
132 // grademin and grademax ignored when scale specified
133 if (array_key_exists('scaleid', $itemdetails)) {
134 if ($itemdetails['scaleid']) {
135 unset($itemdetails['grademin']);
136 unset($itemdetails['grademax']);
140 foreach ($itemdetails as $k=>$v) {
141 if (!in_array($k, $allowed)) {
142 // ignore it
143 continue;
145 if ($k == 'gradetype' and $v == GRADE_TYPE_NONE) {
146 // no grade item needed!
147 return GRADE_UPDATE_OK;
149 $params[$k] = $v;
152 $grade_item = new grade_item($params);
153 $grade_item->insert();
155 } else {
156 if ($grade_item->is_locked()) {
157 debugging('Grading item is locked!');
158 return GRADE_UPDATE_ITEM_LOCKED;
161 if ($itemdetails) {
162 $itemdetails = (array)$itemdetails;
163 $update = false;
164 foreach ($itemdetails as $k=>$v) {
165 if (!in_array($k, $allowed)) {
166 // ignore it
167 continue;
169 if ($grade_item->{$k} != $v) {
170 $grade_item->{$k} = $v;
171 $update = true;
174 if ($update) {
175 $grade_item->update();
180 /// Some extra checks
181 // do we use grading?
182 if ($grade_item->gradetype == GRADE_TYPE_NONE) {
183 return GRADE_UPDATE_OK;
186 // no grade submitted
187 if (empty($grades)) {
188 return GRADE_UPDATE_OK;
191 // no grading in deleted items
192 if ($grade_item->deleted) {
193 debugging('Grade item was already deleted!');
194 return GRADE_UPDATE_ITEM_DELETED;
197 /// Finally start processing of grades
198 if (is_object($grades)) {
199 $grades = array($grades);
200 } else {
201 if (array_key_exists('userid', $grades)) {
202 $grades = array($grades);
206 $failed = false;
207 foreach ($grades as $grade) {
208 $grade = (array)$grade;
209 if (empty($grade['userid'])) {
210 $failed = true;
211 debugging('Invalid userid in grade submitted');
212 continue;
213 } else {
214 $userid = $grade['userid'];
217 $rawgrade = false;
218 $feedback = false;
219 $feedbackformat = FORMAT_MOODLE;
221 if (array_key_exists('rawgrade', $grade)) {
222 $rawgrade = $grade['rawgrade'];
225 if (array_key_exists('feedback', $grade)) {
226 $feedback = $grade['feedback'];
229 if (array_key_exists('feedbackformat', $grade)) {
230 $feedbackformat = $grade['feedbackformat'];
233 // update or insert the grade
234 if (!$grade_item->update_raw_grade($userid, $rawgrade, $source, null, $feedback, $feedbackformat)) {
235 $failed = true;
239 if (!$failed) {
240 return GRADE_UPDATE_OK;
241 } else {
242 return GRADE_UPDATE_FAILED;
248 * Tells a module whether a grade (or grade_item if $userid is not given) is currently locked or not.
249 * This is a combination of the actual settings in the grade tables and a check on moodle/course:editgradeswhenlocked.
250 * If it's locked to the current use then the module can print a nice message or prevent editing in the module.
251 * If no $userid is given, the method will always return the grade_item's locked state.
252 * If a $userid is given, the method will first check the grade_item's locked state (the column). If it is locked,
253 * the method will return true no matter the locked state of the specific grade being checked. If unlocked, it will
254 * return the locked state of the specific grade.
256 * @param int $courseid id of course
257 * @param string $itemtype 'mod', 'blocks', 'import', 'calculated' etc
258 * @param string $itemmodule 'forum, 'quiz', 'csv' etc
259 * @param int $iteminstance id of the item module
260 * @param int $itemnumber most probably 0, modules can use other numbers when having more than one grades for each user
261 * @param int $userid ID of the graded user
262 * @return boolean Whether the grade is locked or not
264 function grade_is_locked($courseid, $itemtype, $itemmodule, $iteminstance, $itemnumber, $userid=NULL) {
266 if (!$grade_items = grade_item::fetch_all(compact('courseid', 'itemtype', 'itemmodule', 'iteminstance', 'itemnumber'))) {
267 return false;
269 } else if (count($grade_items) == 1){
270 $grade_item = reset($grade_items);
271 return $grade_item->is_locked($userid);
273 } else {
274 debugging('Found more than one grade item');
275 foreach ($grade_items as $grade_item) {
276 if ($grade_item->is_locked($userid)) {
277 return true;
280 return false;
284 /***** END OF PUBLIC API *****/
288 * Updates all final grades in course.
290 * @param int $courseid
291 * @param boolean $regradeall force regrading of all items
293 * @return boolean true if ok, array of errors if problems found
295 function grade_update_final_grades($courseid, $regradeall=false) {
297 if ($regradeall) {
298 set_field('grade_items', 'needsupdate', 1, 'courseid', $courseid);
301 if (!$grade_items = grade_item::fetch_all(array('courseid'=>$courseid))) {
302 return true;
305 if (!$regradeall) {
306 $needsupdate = false;
307 $calculated = false;
308 foreach ($grade_items as $gid=>$gitem) {
309 $grade_item =& $grade_items[$gid];
310 if ($grade_item->needsupdate) {
311 $needsupdate = true;
313 if ($grade_item->is_calculated()) {
314 $calculated = true;
318 if (!$needsupdate) {
319 // no update needed
320 return true;
322 } else if ($calculated) {
323 // flag all calculated grade items with needsupdate
324 // we want to make sure all are ok, this can be improved later with proper dependency calculation
325 foreach ($grade_items as $gid=>$gitem) {
326 $grade_item =& $grade_items[$gid];
327 if (!$grade_item->is_calculated()) {
328 continue;
330 $grade_item->update_from_db(); // make sure we have current data, it might have been updated in this loop already
331 if (!$grade_item->needsupdate) {
332 //force recalculation and forced update of all parents
333 $grade_item->force_regrading();
337 // again make sure all date is up-to-date - the needsupdate flag might have changed
338 foreach ($grade_items as $gid=>$gitem) {
339 $grade_item =& $grade_items[$gid];
340 $grade_item->update_from_db();
341 unset($grade_item->category);
347 $errors = array();
349 // now the hard way with calculated grade_items or categories
350 $finalitems = array();
351 $finalids = array();
352 while (count($grade_items) > 0) {
353 $count = 0;
354 foreach ($grade_items as $gid=>$gitem) {
355 $grade_item =& $grade_items[$gid];
356 if (!$grade_item->needsupdate) {
357 $finalitems[$gid] = $grade_item;
358 $finalids[] = $gid;
359 unset($grade_items[$gid]);
360 continue;
363 //do we have all data for finalizing of this item?
364 $depends_on = $grade_item->depends_on();
366 $doupdate = true;
367 foreach ($depends_on as $did) {
368 if (!in_array($did, $finalids)) {
369 $doupdate = false;
373 //oki - let's update, calculate or aggregate :-)
374 if ($doupdate) {
375 $result = $grade_item->update_final_grades();
376 if ($result !== true) {
377 $errors = array_merge($errors, $result);
378 } else {
379 $finalitems[$gid] = $grade_item;
380 $finalids[] = $gid;
381 unset($grade_items[$gid]);
386 if ($count == 0) {
387 foreach($grade_items as $grade_item) {
388 $errors[] = 'Probably circular reference or broken calculation formula in grade_item id:'.$grade_item->id; // TODO: localize
390 break;
394 if (count($errors) == 0) {
395 return true;
396 } else {
397 return $errors;
402 * For backwards compatibility with old third-party modules, this function can
403 * be used to import all grades from activities with legacy grading.
404 * @param int $courseid or null if all courses
406 function grade_grab_legacy_grades($courseid=null) {
408 global $CFG;
410 if (!$mods = get_list_of_plugins('mod') ) {
411 error('No modules installed!');
414 if ($courseid) {
415 $course_sql = " AND cm.course=$courseid";
416 } else {
417 $course_sql = "";
420 foreach ($mods as $mod) {
422 if ($mod == 'NEWMODULE') { // Someone has unzipped the template, ignore it
423 continue;
426 if (!$module = get_record('modules', 'name', $mod)) {
427 //not installed
428 continue;
431 if (!$module->visible) {
432 //disabled module
433 continue;
436 $fullmod = $CFG->dirroot.'/mod/'.$mod;
438 // include the module lib once
439 if (file_exists($fullmod.'/lib.php')) {
440 include_once($fullmod.'/lib.php');
441 // look for modname_grades() function - old gradebook pulling function
442 // if present sync the grades with new grading system
443 $gradefunc = $mod.'_grades';
444 if (function_exists($gradefunc)) {
446 // get all instance of the activity
447 $sql = "SELECT a.*, cm.idnumber as cmidnumber, m.name as modname
448 FROM {$CFG->prefix}$mod a, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
449 WHERE m.name='$mod' AND m.id=cm.module AND cm.instance=a.id $course_sql";
451 if ($modinstances = get_records_sql($sql)) {
452 foreach ($modinstances as $modinstance) {
453 grade_update_mod_grades($modinstance);
462 * For testing purposes mainly, reloads grades from all non legacy modules into gradebook.
464 function grade_grab_grades() {
466 global $CFG;
468 if (!$mods = get_list_of_plugins('mod') ) {
469 error('No modules installed!');
472 foreach ($mods as $mod) {
474 if ($mod == 'NEWMODULE') { // Someone has unzipped the template, ignore it
475 continue;
478 if (!$module = get_record('modules', 'name', $mod)) {
479 //not installed
480 continue;
483 if (!$module->visible) {
484 //disabled module
485 continue;
488 $fullmod = $CFG->dirroot.'/mod/'.$mod;
490 // include the module lib once
491 if (file_exists($fullmod.'/lib.php')) {
492 include_once($fullmod.'/lib.php');
493 // look for modname_grades() function - old gradebook pulling function
494 // if present sync the grades with new grading system
495 $gradefunc = $mod.'_update_grades';
496 if (function_exists($gradefunc)) {
497 $gradefunc();
504 * Force full update of module grades in central gradebook - works for both legacy and converted activities.
505 * @param object $modinstance object with extra cmidnumber and modname property
506 * @return boolean success
508 function grade_update_mod_grades($modinstance) {
509 global $CFG;
511 $fullmod = $CFG->dirroot.'/mod/'.$modinstance->modname;
512 if (!file_exists($fullmod.'/lib.php')) {
513 debugging('missing lib.php file in module');
514 return false;
516 include_once($fullmod.'/lib.php');
518 // does it use legacy grading?
519 $gradefunc = $modinstance->modname.'_grades';
520 $updategradesfunc = $modinstance->modname.'_update_grades';
521 $updateitemfunc = $modinstance->modname.'_grade_item_update';
523 if (function_exists($gradefunc)) {
524 if ($oldgrades = $gradefunc($modinstance->id)) {
526 $grademax = $oldgrades->maxgrade;
527 $scaleid = NULL;
528 if (!is_numeric($grademax)) {
529 // scale name is provided as a string, try to find it
530 if (!$scale = get_record('scale', 'name', $grademax)) {
531 debugging('Incorrect scale name! name:'.$grademax);
532 return false;
534 $scaleid = $scale->id;
537 if (!$grade_item = grade_get_legacy_grade_item($modinstance, $grademax, $scaleid)) {
538 debugging('Can not get/create legacy grade item!');
539 return false;
542 $grades = array();
543 foreach ($oldgrades->grades as $userid=>$usergrade) {
544 $grade = new object();
545 $grade->userid = $userid;
547 if ($usergrade == '-') {
548 // no grade
549 $grade->rawgrade = null;
551 } else if ($scaleid) {
552 // scale in use, words used
553 $gradescale = explode(",", $scale->scale);
554 $grade->rawgrade = array_search($usergrade, $gradescale) + 1;
556 } else {
557 // good old numeric value
558 $grade->rawgrade = $usergrade;
560 $grades[] = $grade;
563 grade_update('legacygrab', $grade_item->courseid, $grade_item->itemtype, $grade_item->itemmodule,
564 $grade_item->iteminstance, $grade_item->itemnumber, $grades);
567 } else if (function_exists($updategradesfunc) and function_exists($updateitemfunc)) {
568 //new grading supported, force updating of grades
569 $updateitemfunc($modinstance);
570 $updategradesfunc($modinstance);
572 } else {
573 // mudule does not support grading
576 return true;
580 * Get and update/create grade item for legacy modules.
582 function grade_get_legacy_grade_item($modinstance, $grademax, $scaleid) {
584 // does it already exist?
585 if ($grade_items = grade_grades::fetch_all(array('courseid'=>$modinstance->course, 'itemtype'=>'mod', 'itemmodule'=>$modinstance->modname, 'iteminstance'=>$modinstance->id, 'itemnumber'=>0))) {
586 if (count($grade_items) > 1) {
587 debugging('Multiple legacy grade_items found.');
588 return false;
591 $grade_item = reset($grade_items);
593 if (is_null($grademax) and is_null($scaleid)) {
594 $grade_item->gradetype = GRADE_TYPE_NONE;
596 } else if ($scaleid) {
597 $grade_item->gradetype = GRADE_TYPE_SCALE;
598 $grade_item->scaleid = $scaleid;
599 $grade_item->grademin = 1;
601 } else {
602 $grade_item->gradetype = GRADE_TYPE_VALUE;
603 $grade_item->grademax = $grademax;
604 $grade_item->grademin = 0;
607 $grade_item->itemname = $modinstance->name;
608 $grade_item->idnumber = $modinstance->cmidnumber;
610 $grade_item->update();
612 return $grade_item;
615 // create new one
616 $params = array('courseid' =>$modinstance->course,
617 'itemtype' =>'mod',
618 'itemmodule' =>$modinstance->modname,
619 'iteminstance'=>$modinstance->id,
620 'itemnumber' =>0,
621 'itemname' =>$modinstance->name,
622 'idnumber' =>$modinstance->cmidnumber);
624 if (is_null($grademax) and is_null($scaleid)) {
625 $params['gradetype'] = GRADE_TYPE_NONE;
627 } else if ($scaleid) {
628 $params['gradetype'] = GRADE_TYPE_SCALE;
629 $params['scaleid'] = $scaleid;
630 $grade_item->grademin = 1;
631 } else {
632 $params['gradetype'] = GRADE_TYPE_VALUE;
633 $params['grademax'] = $grademax;
634 $params['grademin'] = 0;
637 $grade_item = new grade_item($params);
638 $grade_item->insert();
640 return $grade_item;
644 * This function is used to migrade old date and settings from old gradebook into new grading system.
646 * TODO:
647 * - category weight not used - we would have to create extra top course grade calculated category
648 * - exta_credit item flag not used - does not fit all our aggregation types, could be used in SUM only
650 function grade_oldgradebook_upgrade($courseid) {
651 global $CFG;
653 $categories = array();
654 if ($oldcats = get_records('grade_category', 'courseid', $courseid)) {
655 foreach ($oldcats as $oldcat) {
656 $newcat = new grade_category(array('courseid'=>$courseid, 'fullname'=>$oldcat->name));
657 $newcat->droplow = $oldcat->drop_x_lowest;
658 $newcat->aggregation = GRADE_AGGREGATE_MEAN_GRADED;
660 if (empty($newcat->id)) {
661 $newcat->insert();
662 } else {
663 $newcat->update();
666 $categories[$oldcat->id] = $newcat;
668 $catitem = $newcat->get_grade_item();
669 $catitem->gradetype = GRADE_TYPE_VALUE;
670 $catitem->plusfactor = $oldcat->bonus_points;
671 $catitem->hidden = $oldcat->hidden;
672 $catitem->update();
676 // get all grade items with mod details
677 $sql = "SELECT gi.*, cm.idnumber as cmidnumber, m.name as modname
678 FROM {$CFG->prefix}grade_item gi, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
679 WHERE gi.courseid=$courseid AND m.id=gi.modid AND cm.instance=gi.cminstance
680 ORDER BY gi.sortorder ASC";
682 if ($olditems = get_records_sql($sql)) {
683 foreach ($olditems as $olditem) {
684 $newitem = new grade_item(array('courseid'=>$olditem->courseid, 'itemtype'=>'mod', 'itemmodule'=>$olditem->modname, 'iteminstance'=>$olditem->cminstance, 'itemnumber'=>0));
685 if (!empty($olditem->category)) {
686 // we do this low level stuff to get some speedup during upgrade
687 $newitem->set_parent($categories[$olditem->category]->id);
689 $newitem->gradetype = GRADE_TYPE_NONE;
690 $newitem->multfactor = $olditem->scale_grade;
691 if (empty($newitem->id)) {
692 $newitem->insert();
693 } else {
694 $newitem->update();
701 * Given a grade_category, grade_item or grade_grade, this function
702 * figures out the state of the object and builds then returns a div
703 * with the icons needed for the grader report.
705 * @param object $object
706 * @param object $tree (A complete grade_tree object)
707 * @return string HTML
709 function grade_get_icons($element, $tree) {
710 global $CFG;
711 global $USER;
713 // Load language strings
714 $straddfeedback = get_string("addfeedback", 'grades');
715 $stredit = get_string("edit");
716 $streditfeedback = get_string("editfeedback", 'grades');
717 $strfeedback = get_string("feedback");
718 $strmove = get_string("move");
719 $strmoveup = get_string("moveup");
720 $strmovedown = get_string("movedown");
721 $strmovehere = get_string("movehere");
722 $strcancel = get_string("cancel");
723 $stredit = get_string("edit");
724 $strdelete = get_string("delete");
725 $strhide = get_string("hide");
726 $strshow = get_string("show");
727 $strlock = get_string("lock", 'grades');
728 $strswitch_minus = get_string("contract", 'grades');
729 $strswitch_plus = get_string("expand", 'grades');
730 $strunlock = get_string("unlock", 'grades');
732 // Prepare container div
733 $html = '<div class="grade_icons">';
735 // Prepare reference variables
736 $eid = $element['eid'];
737 $object = $element['object'];
738 $type = $element['type'];
740 // Load user preferences
741 $aggregationview = get_user_preferences('grade_report_aggregationview', $CFG->grade_report_aggregationview);
743 // Icons shown when edit mode is on
744 if ($USER->gradeediting) {
745 // Edit icon (except for grade_grades)
746 if ($type == 'category') {
747 $html .= '<a href="report/grader/edit_category.php?courseid='.$object->courseid.'&amp;id='.$object->id.'">';
748 $html .= '<img src="'.$CFG->pixpath.'/t/edit.gif" class="iconsmall" alt="'
749 .$stredit.'" title="'.$stredit.'" /></a>'. "\n";
751 } else if ($type == 'item' or $type == 'courseitem' or $type == 'categoryitem') {
752 $html .= '<a href="report/grader/edit_item.php?courseid='.$object->courseid.'&amp;id='.$object->id.'">';
753 $html .= '<img src="'.$CFG->pixpath.'/t/edit.gif" class="iconsmall" alt="'
754 .$stredit.'" title="'.$stredit.'" /></a>'. "\n";
756 } else if ($type == 'grade') {
757 $html .= '<a href="report/grader/edit_grade.php?courseid='.$object->courseid.'&amp;id='.$object->id.'">';
758 $html .= '<img src="'.$CFG->pixpath.'/t/edit.gif" class="iconsmall" alt="'
759 .$stredit.'" title="'.$stredit.'" /></a>'. "\n";
762 // Prepare Hide/Show icon state
763 $hide_show = 'hide';
764 if ($object->is_hidden()) {
765 $hide_show = 'show';
768 // Setup object identifier and show feedback icon if applicable
769 if ($type != 'category' and $USER->gradefeedback) {
770 // Display Edit/Add feedback icon
771 if (empty($object->feedback)) {
772 $html .= '<a href="report/grader/edit_feedback.php?id=' . $object->id
773 . "&amp;action=add&amp;courseid=$object->courseid\">\n";
774 $html .= '<img src="'.$CFG->pixpath.'/t/feedback_add.gif" class="iconsmall" alt="'.$straddfeedback.'" '
775 . 'title="'.$straddfeedback.'" /></a>'. "\n";
776 } else {
777 $html .= '<a href="report/grader/edit_feedback.php?id=' . $object->id
778 . "&amp;action=edit&amp;courseid=$object->courseid\">\n";
779 $html .= '<img src="'.$CFG->pixpath.'/t/feedback.gif" class="iconsmall" alt="'.$streditfeedback.'" '
780 . 'title="'.$streditfeedback.'" onmouseover="return overlib(\''.$object->feedback.'\', CAPTION, \''
781 . $strfeedback.'\');" onmouseout="return nd();" /></a>'. "\n";
785 // Display Hide/Show icon
786 $html .= '<a href="report.php?report=grader&amp;target='.$eid
787 . "&amp;action=$hide_show$tree->commonvars\">\n";
788 $html .= '<img src="'.$CFG->pixpath.'/t/'.$hide_show.'.gif" class="iconsmall" alt="'
789 .${'str' . $hide_show}.'" title="'.${'str' . $hide_show}.'" /></a>'. "\n";
791 // Prepare lock/unlock string
792 $lock_unlock = 'lock';
793 if ($object->is_locked()) {
794 $lock_unlock = 'unlock';
797 // Print lock/unlock icon
798 $html .= '<a href="report.php?report=grader&amp;target='.$eid
799 . "&amp;action=$lock_unlock$tree->commonvars\">\n";
800 $html .= '<img src="'.$CFG->pixpath.'/t/'.$lock_unlock.'.gif" class="iconsmall" alt="'
801 .${'str' . $lock_unlock}.'" title="'.${'str' . $lock_unlock}.'" /></a>'. "\n";
803 // If object is a category, display expand/contract icon
804 if (get_class($object) == 'grade_category' && $aggregationview == GRADER_REPORT_AGGREGATION_VIEW_COMPACT) {
805 $expand_contract = 'switch_minus'; // Default: expanded
807 $state = get_user_preferences('grade_category_' . $object->id, GRADE_CATEGORY_EXPANDED);
809 if ($state == GRADE_CATEGORY_CONTRACTED) {
810 $expand_contract = 'switch_plus';
813 $html .= '<a href="report.php?report=grader&amp;target=' . $eid
814 . "&amp;action=$expand_contract$tree->commonvars\">\n";
815 $html .= '<img src="'.$CFG->pixpath.'/t/'.$expand_contract.'.gif" class="iconsmall" alt="'
816 .${'str' . $expand_contract}.'" title="'.${'str' . $expand_contract}.'" /></a>'. "\n";
818 } else {
819 if ($USER->gradefeedback) {
820 // Display view feedback icon
821 if (!empty($object->feedback)) {
822 $html .= '<a href="report/grader/edit_feedback.php?id=' . $object->id
823 . "&amp;action=view&amp;courseid=$object->courseid\">\n";
824 $html .= '<img onmouseover="return overlib(\''.$object->feedback.'\', CAPTION, \''
825 . $strfeedback.'\');" onmouseout="return nd();" '
826 . 'src="'.$CFG->pixpath.'/t/feedback.gif" class="iconsmall" alt="" /></a>'. "\n";
831 return $html . '</div>';