2009-07-07 02:26:36 +00:00
< ? php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
2007-10-10 06:34:20 +00:00
2007-07-16 04:09:00 +00:00
/**
2012-01-06 11:52:46 +07:00
* Definition of the grade_user_report class is defined
*
* @ package gradereport_user
* @ copyright 2007 Nicolas Connault
* @ license http :// www . gnu . org / copyleft / gpl . html GNU GPL v3 or later
2007-07-16 04:09:00 +00:00
*/
require_once ( $CFG -> dirroot . '/grade/report/lib.php' );
require_once ( $CFG -> libdir . '/tablelib.php' );
2010-01-08 07:48:37 +00:00
//showhiddenitems values
define ( " GRADE_REPORT_USER_HIDE_HIDDEN " , 0 );
define ( " GRADE_REPORT_USER_HIDE_UNTIL " , 1 );
define ( " GRADE_REPORT_USER_SHOW_HIDDEN " , 2 );
2007-07-16 04:09:00 +00:00
/**
* Class providing an API for the user report building and displaying .
* @ uses grade_report
2012-01-06 11:52:46 +07:00
* @ package gradereport_user
2007-07-16 04:09:00 +00:00
*/
class grade_report_user extends grade_report {
/**
* The user .
* @ var object $user
*/
2008-06-03 16:10:57 +00:00
public $user ;
2007-07-16 04:09:00 +00:00
/**
* A flexitable to hold the data .
* @ var object $table
*/
2008-06-03 16:10:57 +00:00
public $table ;
2007-07-16 04:09:00 +00:00
2011-01-18 16:24:41 +08:00
/**
* An array of table headers
* @ var array
*/
public $tableheaders = array ();
/**
* An array of table columns
* @ var array
*/
public $tablecolumns = array ();
/**
* An array containing rows of data for the table .
* @ var type
*/
public $tabledata = array ();
/**
* The grade tree structure
* @ var grade_tree
*/
public $gtree ;
2009-04-16 07:16:44 +00:00
2007-10-08 23:09:10 +00:00
/**
* Flat structure similar to grade tree
*/
2008-06-03 16:10:57 +00:00
public $gseq ;
2007-10-08 23:09:10 +00:00
2007-10-27 15:33:43 +00:00
/**
* show student ranks
*/
2008-06-03 16:10:57 +00:00
public $showrank ;
2007-10-27 15:33:43 +00:00
2008-10-08 11:06:05 +00:00
/**
* show grade percentages
*/
public $showpercentage ;
2009-02-25 07:56:11 +00:00
/**
* Show range
*/
2011-01-18 16:24:41 +08:00
public $showrange = true ;
2009-02-25 07:56:11 +00:00
2011-01-18 16:24:41 +08:00
/**
* Show grades in the report , default true
* @ var bool
*/
public $showgrade = true ;
2009-02-25 07:56:11 +00:00
2011-01-18 16:24:41 +08:00
/**
* Decimal points to use for values in the report , default 2
* @ var int
*/
public $decimals = 2 ;
2009-02-25 07:56:11 +00:00
2011-01-18 16:24:41 +08:00
/**
* The number of decimal places to round range to , default 0
* @ var int
*/
public $rangedecimals = 0 ;
2009-02-25 07:56:11 +00:00
2011-01-18 16:24:41 +08:00
/**
* Show grade feedback in the report , default true
* @ var bool
*/
public $showfeedback = true ;
/**
* Show grade weighting in the report , default false
* @ var bool
*/
public $showweight = false ;
/**
* Show letter grades in the report , default false
* @ var bool
*/
public $showlettergrade = false ;
/**
* Show average grades in the report , default false .
* @ var false
*/
public $showaverage = false ;
public $maxdepth ;
public $evenodd ;
public $canviewhidden ;
public $switch ;
2009-02-25 07:56:11 +00:00
2007-10-27 15:33:43 +00:00
/**
* Show hidden items even when user does not have required cap
*/
2008-06-03 16:10:57 +00:00
public $showhiddenitems ;
2011-01-18 16:24:41 +08:00
public $showtotalsifcontainhidden ;
public $baseurl ;
public $pbarurl ;
2007-10-27 15:33:43 +00:00
2007-07-16 04:09:00 +00:00
/**
* Constructor . Sets local copies of user preferences and initialises grade_tree .
* @ param int $courseid
2007-07-17 06:09:03 +00:00
* @ param object $gpr grade plugin return tracking object
2007-07-16 04:09:00 +00:00
* @ param string $context
* @ param int $userid The id of the user
*/
2008-06-03 16:10:57 +00:00
public function __construct ( $courseid , $gpr , $context , $userid ) {
2011-01-18 16:24:41 +08:00
global $DB , $CFG ;
2008-06-03 16:10:57 +00:00
parent :: __construct ( $courseid , $gpr , $context );
2007-07-16 04:09:00 +00:00
2007-10-30 21:25:50 +00:00
$this -> showrank = grade_get_setting ( $this -> courseid , 'report_user_showrank' , $CFG -> grade_report_user_showrank );
2008-10-08 11:06:05 +00:00
$this -> showpercentage = grade_get_setting ( $this -> courseid , 'report_user_showpercentage' , $CFG -> grade_report_user_showpercentage );
2007-10-30 21:25:50 +00:00
$this -> showhiddenitems = grade_get_setting ( $this -> courseid , 'report_user_showhiddenitems' , $CFG -> grade_report_user_showhiddenitems );
2010-02-08 06:27:04 +00:00
$this -> showtotalsifcontainhidden = grade_get_setting ( $this -> courseid , 'report_user_showtotalsifcontainhidden' , $CFG -> grade_report_user_showtotalsifcontainhidden );
2009-04-16 07:16:44 +00:00
2011-01-18 16:24:41 +08:00
$this -> showgrade = grade_get_setting ( $this -> courseid , 'report_user_showgrade' , ! empty ( $CFG -> grade_report_user_showgrade ));
$this -> showrange = grade_get_setting ( $this -> courseid , 'report_user_showrange' , ! empty ( $CFG -> grade_report_user_showrange ));
$this -> showfeedback = grade_get_setting ( $this -> courseid , 'report_user_showfeedback' , ! empty ( $CFG -> grade_report_user_showfeedback ));
$this -> showweight = grade_get_setting ( $this -> courseid , 'report_user_showweight' , ! empty ( $CFG -> grade_report_user_showweight ));
$this -> showlettergrade = grade_get_setting ( $this -> courseid , 'report_user_showlettergrade' , ! empty ( $CFG -> grade_report_user_showlettergrade ));
$this -> showaverage = grade_get_setting ( $this -> courseid , 'report_user_showaverage' , ! empty ( $CFG -> grade_report_user_showaverage ));
// The default grade decimals is 2
$defaultdecimals = 2 ;
if ( property_exists ( $CFG , 'grade_decimalpoints' )) {
$defaultdecimals = $CFG -> grade_decimalpoints ;
}
$this -> decimals = grade_get_setting ( $this -> courseid , 'decimalpoints' , $defaultdecimals );
// The default range decimals is 0
$defaultrangedecimals = 0 ;
if ( property_exists ( $CFG , 'grade_report_user_rangedecimals' )) {
$defaultrangedecimals = $CFG -> grade_report_user_rangedecimals ;
}
$this -> rangedecimals = grade_get_setting ( $this -> courseid , 'report_user_rangedecimals' , $defaultrangedecimals );
2009-02-25 07:56:11 +00:00
$this -> switch = grade_get_setting ( $this -> courseid , 'aggregationposition' , $CFG -> grade_aggregationposition );
// Grab the grade_tree for this course
2010-09-17 19:05:23 +00:00
$this -> gtree = new grade_tree ( $this -> courseid , false , $this -> switch , null , ! $CFG -> enableoutcomes );
2007-10-27 15:33:43 +00:00
2009-02-25 07:56:11 +00:00
// Determine the number of rows and indentation
$this -> maxdepth = 1 ;
$this -> inject_rowspans ( $this -> gtree -> top_element );
$this -> maxdepth ++ ; // Need to account for the lead column that spans all children
for ( $i = 1 ; $i <= $this -> maxdepth ; $i ++ ) {
$this -> evenodd [ $i ] = 0 ;
}
$this -> tabledata = array ();
2007-10-08 23:09:10 +00:00
2012-07-24 14:04:40 +08:00
$this -> canviewhidden = has_capability ( 'moodle/grade:viewhidden' , context_course :: instance ( $this -> courseid ));
2007-07-25 19:57:47 +00:00
2007-07-16 04:09:00 +00:00
// get the user (for full name)
2008-06-03 16:10:57 +00:00
$this -> user = $DB -> get_record ( 'user' , array ( 'id' => $userid ));
2007-07-16 04:09:00 +00:00
// base url for sorting by first/last name
$this -> baseurl = $CFG -> wwwroot . '/grade/report?id=' . $courseid . '&userid=' . $userid ;
2007-07-20 09:34:35 +00:00
$this -> pbarurl = $this -> baseurl ;
2007-07-16 04:09:00 +00:00
2007-10-28 12:51:16 +00:00
// no groups on this report - rank is from all course users
2007-07-20 09:34:35 +00:00
$this -> setup_table ();
2011-01-18 16:24:41 +08:00
//optionally calculate grade item averages
$this -> calculate_averages ();
2007-07-16 04:09:00 +00:00
}
2009-02-25 07:56:11 +00:00
function inject_rowspans ( & $element ) {
if ( $element [ 'depth' ] > $this -> maxdepth ) {
$this -> maxdepth = $element [ 'depth' ];
}
if ( empty ( $element [ 'children' ])) {
return 1 ;
}
$count = 1 ;
foreach ( $element [ 'children' ] as $key => $child ) {
$count += $this -> inject_rowspans ( $element [ 'children' ][ $key ]);
}
$element [ 'rowspan' ] = $count ;
return $count ;
}
2007-07-16 04:09:00 +00:00
/**
* Prepares the headers and attributes of the flexitable .
*/
2008-06-03 16:10:57 +00:00
public function setup_table () {
2007-07-16 04:09:00 +00:00
/*
2011-01-18 16:24:41 +08:00
* Table has 1 - 8 columns
*| All columns except for itemname / description are optional
2007-10-28 12:51:16 +00:00
*/
2007-07-16 04:09:00 +00:00
// setting up table headers
2011-01-18 16:24:41 +08:00
$this -> tablecolumns = array ( 'itemname' );
$this -> tableheaders = array ( $this -> get_lang_string ( 'gradeitem' , 'grades' ));
if ( $this -> showweight ) {
$this -> tablecolumns [] = 'weight' ;
$this -> tableheaders [] = $this -> get_lang_string ( 'weightuc' , 'grades' );
}
if ( $this -> showgrade ) {
$this -> tablecolumns [] = 'grade' ;
$this -> tableheaders [] = $this -> get_lang_string ( 'grade' , 'grades' );
}
2008-10-08 11:06:05 +00:00
2009-02-25 07:56:11 +00:00
if ( $this -> showrange ) {
$this -> tablecolumns [] = 'range' ;
$this -> tableheaders [] = $this -> get_lang_string ( 'range' , 'grades' );
}
2008-10-08 11:06:05 +00:00
if ( $this -> showpercentage ) {
2009-02-25 07:56:11 +00:00
$this -> tablecolumns [] = 'percentage' ;
$this -> tableheaders [] = $this -> get_lang_string ( 'percentage' , 'grades' );
2008-10-08 11:06:05 +00:00
}
2011-01-18 16:24:41 +08:00
if ( $this -> showlettergrade ) {
$this -> tablecolumns [] = 'lettergrade' ;
$this -> tableheaders [] = $this -> get_lang_string ( 'lettergrade' , 'grades' );
}
2007-10-27 15:33:43 +00:00
if ( $this -> showrank ) {
2009-02-25 07:56:11 +00:00
$this -> tablecolumns [] = 'rank' ;
$this -> tableheaders [] = $this -> get_lang_string ( 'rank' , 'grades' );
2007-10-21 12:56:19 +00:00
}
2007-07-16 04:09:00 +00:00
2011-01-18 16:24:41 +08:00
if ( $this -> showaverage ) {
$this -> tablecolumns [] = 'average' ;
$this -> tableheaders [] = $this -> get_lang_string ( 'average' , 'grades' );
}
2007-07-16 04:09:00 +00:00
2011-01-18 16:24:41 +08:00
if ( $this -> showfeedback ) {
$this -> tablecolumns [] = 'feedback' ;
$this -> tableheaders [] = $this -> get_lang_string ( 'feedback' , 'grades' );
}
2009-02-25 07:56:11 +00:00
}
2007-07-16 04:09:00 +00:00
2009-02-25 07:56:11 +00:00
function fill_table () {
//print "<pre>";
//print_r($this->gtree->top_element);
$this -> fill_table_recursive ( $this -> gtree -> top_element );
//print_r($this->tabledata);
//print "</pre>";
return true ;
2007-07-16 04:09:00 +00:00
}
2009-02-25 07:56:11 +00:00
private function fill_table_recursive ( & $element ) {
2011-01-18 16:24:41 +08:00
global $DB , $CFG ;
2007-07-16 04:09:00 +00:00
2009-02-25 07:56:11 +00:00
$type = $element [ 'type' ];
$depth = $element [ 'depth' ];
$grade_object = $element [ 'object' ];
$eid = $grade_object -> id ;
2011-11-08 14:09:50 +08:00
$element [ 'userid' ] = $this -> user -> id ;
2009-02-25 07:56:11 +00:00
$fullname = $this -> gtree -> get_element_header ( $element , true , true , true );
$data = array ();
$hidden = '' ;
$excluded = '' ;
$class = '' ;
2012-03-04 12:21:03 +07:00
$classfeedback = '' ;
2007-07-16 04:09:00 +00:00
2010-01-08 07:48:37 +00:00
// If this is a hidden grade category, hide it completely from the user
2009-04-30 08:40:22 +00:00
if ( $type == 'category' && $grade_object -> is_hidden () && ! $this -> canviewhidden && (
2010-01-08 07:48:37 +00:00
$this -> showhiddenitems == GRADE_REPORT_USER_HIDE_HIDDEN ||
( $this -> showhiddenitems == GRADE_REPORT_USER_HIDE_UNTIL && ! $grade_object -> is_hiddenuntil ()))) {
2009-04-16 07:16:44 +00:00
return false ;
}
2007-10-17 09:45:14 +00:00
2009-02-25 07:56:11 +00:00
if ( $type == 'category' ) {
$this -> evenodd [ $depth ] = (( $this -> evenodd [ $depth ] + 1 ) % 2 );
2007-10-17 20:38:52 +00:00
}
2009-02-25 07:56:11 +00:00
$alter = ( $this -> evenodd [ $depth ] == 0 ) ? 'even' : 'odd' ;
2007-10-17 09:45:14 +00:00
2009-02-25 07:56:11 +00:00
/// Process those items that have scores associated
if ( $type == 'item' or $type == 'categoryitem' or $type == 'courseitem' ) {
if ( ! $grade_grade = grade_grade :: fetch ( array ( 'itemid' => $grade_object -> id , 'userid' => $this -> user -> id ))) {
$grade_grade = new grade_grade ();
$grade_grade -> userid = $this -> user -> id ;
$grade_grade -> itemid = $grade_object -> id ;
2007-10-19 08:51:52 +00:00
}
2007-10-17 09:45:14 +00:00
2009-02-25 07:56:11 +00:00
$grade_grade -> load_grade_item ();
2007-07-16 04:09:00 +00:00
2009-02-25 07:56:11 +00:00
/// Hidden Items
if ( $grade_grade -> grade_item -> is_hidden ()) {
$hidden = ' hidden' ;
2007-11-01 08:25:05 +00:00
}
2012-09-18 13:41:11 +08:00
$hide = false ;
2010-01-08 07:48:37 +00:00
// If this is a hidden grade item, hide it completely from the user.
2009-04-16 07:16:44 +00:00
if ( $grade_grade -> is_hidden () && ! $this -> canviewhidden && (
2010-01-08 07:48:37 +00:00
$this -> showhiddenitems == GRADE_REPORT_USER_HIDE_HIDDEN ||
( $this -> showhiddenitems == GRADE_REPORT_USER_HIDE_UNTIL && ! $grade_grade -> is_hiddenuntil ()))) {
2012-09-18 13:41:11 +08:00
$hide = true ;
} else if ( ! empty ( $grade_object -> itemmodule ) && ! empty ( $grade_object -> iteminstance )) {
2012-10-09 11:22:54 +08:00
// The grade object can be marked visible but still be hidden if...
// 1) "enablegroupmembersonly" is on and the activity is assigned to a grouping the user is not in.
// 2) the student cannot see the activity due to conditional access and its set to be hidden entirely.
2012-09-18 13:41:11 +08:00
$instances = $this -> gtree -> modinfo -> get_instances_of ( $grade_object -> itemmodule );
if ( ! empty ( $instances [ $grade_object -> iteminstance ])) {
$cm = $instances [ $grade_object -> iteminstance ];
2012-10-09 11:22:54 +08:00
if ( ! $cm -> uservisible ) {
// Further checks are required to determine whether the activity is entirely hidden or just greyed out.
if ( $cm -> is_user_access_restricted_by_group () || $cm -> is_user_access_restricted_by_conditional_access ()) {
$hide = true ;
}
2012-04-08 11:10:44 +07:00
}
}
2012-09-18 13:41:11 +08:00
}
if ( ! $hide ) {
2010-02-12 03:39:40 +00:00
/// Excluded Item
if ( $grade_grade -> is_excluded ()) {
$fullname .= ' [' . get_string ( 'excluded' , 'grades' ) . ']' ;
$excluded = ' excluded' ;
}
2009-04-16 07:16:44 +00:00
2010-02-12 03:39:40 +00:00
/// Other class information
$class = " $hidden $excluded " ;
if ( $this -> switch ) { // alter style based on whether aggregation is first or last
$class .= ( $type == 'categoryitem' or $type == 'courseitem' ) ? " " . $alter . " d $depth baggt b2b " : " item b1b " ;
} else {
$class .= ( $type == 'categoryitem' or $type == 'courseitem' ) ? " " . $alter . " d $depth baggb " : " item b1b " ;
}
2007-07-16 04:09:00 +00:00
2010-02-12 03:39:40 +00:00
/// Name
$data [ 'itemname' ][ 'content' ] = $fullname ;
$data [ 'itemname' ][ 'class' ] = $class ;
$data [ 'itemname' ][ 'colspan' ] = ( $this -> maxdepth - $depth );
2007-10-08 23:09:10 +00:00
2010-02-12 03:39:40 +00:00
/// Actual Grade
$gradeval = $grade_grade -> finalgrade ;
2011-01-18 16:24:41 +08:00
2012-03-04 12:21:03 +07:00
if ( $this -> showfeedback ) {
// Copy $class before appending itemcenter as feedback should not be centered
$classfeedback = $class ;
}
2011-01-18 16:24:41 +08:00
$class .= " itemcenter " ;
if ( $this -> showweight ) {
$data [ 'weight' ][ 'class' ] = $class ;
$data [ 'weight' ][ 'content' ] = '-' ;
// has a weight assigned, might be extra credit
if ( $grade_object -> aggregationcoef > 0 && $type <> 'courseitem' ) {
$data [ 'weight' ][ 'content' ] = number_format ( $grade_object -> aggregationcoef , 2 ) . '%' ;
}
2008-10-08 11:06:05 +00:00
}
2007-10-17 09:45:14 +00:00
2011-01-18 16:24:41 +08:00
if ( $this -> showgrade ) {
if ( $grade_grade -> grade_item -> needsupdate ) {
$data [ 'grade' ][ 'class' ] = $class . ' gradingerror' ;
$data [ 'grade' ][ 'content' ] = get_string ( 'error' );
} else if ( ! empty ( $CFG -> grade_hiddenasdate ) and $grade_grade -> get_datesubmitted () and ! $this -> canviewhidden and $grade_grade -> is_hidden ()
and ! $grade_grade -> grade_item -> is_category_item () and ! $grade_grade -> grade_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
$class .= ' datesubmitted' ;
$data [ 'grade' ][ 'class' ] = $class ;
$data [ 'grade' ][ 'content' ] = get_string ( 'submittedon' , 'grades' , userdate ( $grade_grade -> get_datesubmitted (), get_string ( 'strftimedatetimeshort' )));
} elseif ( $grade_grade -> is_hidden ()) {
$data [ 'grade' ][ 'class' ] = $class . ' hidden' ;
$data [ 'grade' ][ 'content' ] = '-' ;
} else {
$data [ 'grade' ][ 'class' ] = $class ;
$gradeval = $this -> blank_hidden_total ( $this -> courseid , $grade_grade -> grade_item , $gradeval );
$data [ 'grade' ][ 'content' ] = grade_format_gradevalue ( $gradeval , $grade_grade -> grade_item , true );
}
}
// Range
if ( $this -> showrange ) {
$data [ 'range' ][ 'class' ] = $class ;
$data [ 'range' ][ 'content' ] = $grade_grade -> grade_item -> get_formatted_range ( GRADE_DISPLAY_TYPE_REAL , $this -> rangedecimals );
}
// Percentage
2010-02-12 03:39:40 +00:00
if ( $this -> showpercentage ) {
if ( $grade_grade -> grade_item -> needsupdate ) {
$data [ 'percentage' ][ 'class' ] = $class . ' gradingerror' ;
$data [ 'percentage' ][ 'content' ] = get_string ( 'error' );
2011-01-18 16:24:41 +08:00
} else if ( $grade_grade -> is_hidden ()) {
$data [ 'percentage' ][ 'class' ] = $class . ' hidden' ;
$data [ 'percentage' ][ 'content' ] = '-' ;
2010-02-12 03:39:40 +00:00
} else {
$data [ 'percentage' ][ 'class' ] = $class ;
$data [ 'percentage' ][ 'content' ] = grade_format_gradevalue ( $gradeval , $grade_grade -> grade_item , true , GRADE_DISPLAY_TYPE_PERCENTAGE );
}
}
2011-01-18 16:24:41 +08:00
// Lettergrade
if ( $this -> showlettergrade ) {
if ( $grade_grade -> grade_item -> needsupdate ) {
$data [ 'lettergrade' ][ 'class' ] = $class . ' gradingerror' ;
$data [ 'lettergrade' ][ 'content' ] = get_string ( 'error' );
} else if ( $grade_grade -> is_hidden ()) {
$data [ 'lettergrade' ][ 'class' ] = $class . ' hidden' ;
if ( ! $this -> canviewhidden ) {
$data [ 'lettergrade' ][ 'content' ] = '-' ;
} else {
$data [ 'lettergrade' ][ 'content' ] = grade_format_gradevalue ( $gradeval , $grade_grade -> grade_item , true , GRADE_DISPLAY_TYPE_LETTER );
}
} else {
$data [ 'lettergrade' ][ 'class' ] = $class ;
$data [ 'lettergrade' ][ 'content' ] = grade_format_gradevalue ( $gradeval , $grade_grade -> grade_item , true , GRADE_DISPLAY_TYPE_LETTER );
}
}
// Rank
2010-02-12 03:39:40 +00:00
if ( $this -> showrank ) {
if ( $grade_grade -> grade_item -> needsupdate ) {
$data [ 'rank' ][ 'class' ] = $class . ' gradingerror' ;
$data [ 'rank' ][ 'content' ] = get_string ( 'error' );
} elseif ( $grade_grade -> is_hidden ()) {
$data [ 'rank' ][ 'class' ] = $class . ' hidden' ;
$data [ 'rank' ][ 'content' ] = '-' ;
} else if ( is_null ( $gradeval )) {
// no grade, no rank
$data [ 'rank' ][ 'class' ] = $class ;
2009-04-16 07:16:44 +00:00
$data [ 'rank' ][ 'content' ] = '-' ;
2007-10-27 15:33:43 +00:00
2010-02-12 03:39:40 +00:00
} else {
/// find the number of users with a higher grade
$sql = " SELECT COUNT(DISTINCT(userid))
FROM { grade_grades }
WHERE finalgrade > ?
2011-01-18 16:24:41 +08:00
AND itemid = ?
AND hidden = 0 " ;
2010-02-12 03:39:40 +00:00
$rank = $DB -> count_records_sql ( $sql , array ( $grade_grade -> finalgrade , $grade_grade -> grade_item -> id )) + 1 ;
$data [ 'rank' ][ 'class' ] = $class ;
$data [ 'rank' ][ 'content' ] = " $rank / " . $this -> get_numusers ( false ); // total course users
}
2007-10-21 12:56:19 +00:00
}
2007-07-16 04:09:00 +00:00
2011-01-18 16:24:41 +08:00
// Average
if ( $this -> showaverage ) {
$data [ 'average' ][ 'class' ] = $class ;
if ( ! empty ( $this -> gtree -> items [ $eid ] -> avg )) {
$data [ 'average' ][ 'content' ] = $this -> gtree -> items [ $eid ] -> avg ;
} else {
$data [ 'average' ][ 'content' ] = '-' ;
}
2010-02-12 03:39:40 +00:00
}
2007-10-17 09:45:14 +00:00
2011-01-18 16:24:41 +08:00
// Feedback
if ( $this -> showfeedback ) {
if ( $grade_grade -> overridden > 0 AND ( $type == 'categoryitem' OR $type == 'courseitem' )) {
2012-03-04 12:21:03 +07:00
$data [ 'feedback' ][ 'class' ] = $classfeedback . ' feedbacktext' ;
2011-01-18 16:24:41 +08:00
$data [ 'feedback' ][ 'content' ] = get_string ( 'overridden' , 'grades' ) . ': ' . format_text ( $grade_grade -> feedback , $grade_grade -> feedbackformat );
} else if ( empty ( $grade_grade -> feedback ) or ( ! $this -> canviewhidden and $grade_grade -> is_hidden ())) {
2012-03-04 12:21:03 +07:00
$data [ 'feedback' ][ 'class' ] = $classfeedback . ' feedbacktext' ;
2011-01-18 16:24:41 +08:00
$data [ 'feedback' ][ 'content' ] = ' ' ;
} else {
2012-03-04 12:21:03 +07:00
$data [ 'feedback' ][ 'class' ] = $classfeedback . ' feedbacktext' ;
2011-01-18 16:24:41 +08:00
$data [ 'feedback' ][ 'content' ] = format_text ( $grade_grade -> feedback , $grade_grade -> feedbackformat );
}
2010-02-12 03:39:40 +00:00
}
2009-02-25 07:56:11 +00:00
}
2007-07-16 04:09:00 +00:00
}
2007-10-08 23:09:10 +00:00
2009-02-25 07:56:11 +00:00
/// Category
if ( $type == 'category' ) {
$data [ 'leader' ][ 'class' ] = $class . ' ' . $alter . " d $depth b1t b2b b1l " ;
$data [ 'leader' ][ 'rowspan' ] = $element [ 'rowspan' ];
if ( $this -> switch ) { // alter style based on whether aggregation is first or last
$data [ 'itemname' ][ 'class' ] = $class . ' ' . $alter . " d $depth b1b b1t " ;
} else {
$data [ 'itemname' ][ 'class' ] = $class . ' ' . $alter . " d $depth b2t " ;
}
$data [ 'itemname' ][ 'colspan' ] = ( $this -> maxdepth - $depth + count ( $this -> tablecolumns ) - 1 );
$data [ 'itemname' ][ 'content' ] = $fullname ;
}
/// Add this row to the overall system
$this -> tabledata [] = $data ;
/// Recursively iterate through all child elements
if ( isset ( $element [ 'children' ])) {
foreach ( $element [ 'children' ] as $key => $child ) {
$this -> fill_table_recursive ( $element [ 'children' ][ $key ]);
}
}
2007-07-16 04:09:00 +00:00
}
/**
* Prints or returns the HTML from the flexitable .
* @ param bool $return Whether or not to return the data instead of printing it directly .
* @ return string
*/
2008-06-03 16:10:57 +00:00
public function print_table ( $return = false ) {
2009-02-25 07:56:11 +00:00
$maxspan = $this -> maxdepth ;
/// Build table structure
$html = "
2009-04-23 20:20:41 +00:00
< table cellspacing = '0' cellpadding = '0' class = 'boxaligncenter generaltable user-grade' >
2009-02-25 07:56:11 +00:00
< thead >
< tr >
< th class = \ " header \" colspan=' $maxspan '> " . $this -> tableheaders [ 0 ] . " </th> \n " ;
for ( $i = 1 ; $i < count ( $this -> tableheaders ); $i ++ ) {
$html .= " <th class= \" header \" > " . $this -> tableheaders [ $i ] . " </th> \n " ;
}
$html .= "
</ tr >
</ thead >
< tbody > \n " ;
/// Print out the table data
for ( $i = 0 ; $i < count ( $this -> tabledata ); $i ++ ) {
$html .= " <tr> \n " ;
if ( isset ( $this -> tabledata [ $i ][ 'leader' ])) {
$rowspan = $this -> tabledata [ $i ][ 'leader' ][ 'rowspan' ];
$class = $this -> tabledata [ $i ][ 'leader' ][ 'class' ];
$html .= " <td class=' $class ' rowspan=' $rowspan '></td> \n " ;
}
for ( $j = 0 ; $j < count ( $this -> tablecolumns ); $j ++ ) {
$name = $this -> tablecolumns [ $j ];
$class = ( isset ( $this -> tabledata [ $i ][ $name ][ 'class' ])) ? $this -> tabledata [ $i ][ $name ][ 'class' ] : '' ;
$colspan = ( isset ( $this -> tabledata [ $i ][ $name ][ 'colspan' ])) ? " colspan=' " . $this -> tabledata [ $i ][ $name ][ 'colspan' ] . " ' " : '' ;
$content = ( isset ( $this -> tabledata [ $i ][ $name ][ 'content' ])) ? $this -> tabledata [ $i ][ $name ][ 'content' ] : null ;
if ( isset ( $content )) {
$html .= " <td class=' $class ' $colspan > $content </td> \n " ;
}
}
$html .= " </tr> \n " ;
}
$html .= " </tbody></table> " ;
2007-07-16 04:09:00 +00:00
if ( $return ) {
return $html ;
} else {
echo $html ;
}
}
/**
* Processes the data sent by the form ( grades and feedbacks ) .
* @ var array $data
* @ return bool Success or Failure ( array of errors ) .
*/
2009-04-16 07:16:44 +00:00
function process_data ( $data ) {
2008-06-03 16:10:57 +00:00
}
2009-04-16 07:16:44 +00:00
function process_action ( $target , $action ) {
2007-07-16 04:09:00 +00:00
}
2011-01-18 16:24:41 +08:00
/**
* Builds the grade item averages .
*
*/
function calculate_averages () {
global $USER , $DB ;
if ( $this -> showaverage ) {
// this settings are actually grader report settings (not user report)
// however we're using them as having two separate but identical settings the
// user would have to keep in sync would be annoying
$averagesdisplaytype = $this -> get_pref ( 'averagesdisplaytype' );
$averagesdecimalpoints = $this -> get_pref ( 'averagesdecimalpoints' );
$meanselection = $this -> get_pref ( 'meanselection' );
$shownumberofgrades = $this -> get_pref ( 'shownumberofgrades' );
$avghtml = '' ;
$avgcssclass = 'avg' ;
$straverage = get_string ( 'overallaverage' , 'grades' );
$groupsql = $this -> groupsql ;
$groupwheresql = $this -> groupwheresql ;
//$groupwheresqlparams = ;
if ( $shownumberofgrades ) {
$straverage .= ' (' . get_string ( 'submissions' , 'grades' ) . ') ' ;
}
$totalcount = $this -> get_numusers ( false );
//limit to users with a gradeable role ie students
list ( $gradebookrolessql , $gradebookrolesparams ) = $DB -> get_in_or_equal ( explode ( ',' , $this -> gradebookroles ), SQL_PARAMS_NAMED , 'grbr0' );
//limit to users with an active enrolment
list ( $enrolledsql , $enrolledparams ) = get_enrolled_sql ( $this -> context );
$params = array_merge ( $this -> groupwheresql_params , $gradebookrolesparams , $enrolledparams );
$params [ 'courseid' ] = $this -> courseid ;
// find sums of all grade items in course
$sql = " SELECT gg.itemid, SUM(gg.finalgrade) AS sum
FROM { grade_items } gi
2011-04-04 11:27:09 +02:00
JOIN { grade_grades } gg ON gg . itemid = gi . id
JOIN { user } u ON u . id = gg . userid
JOIN ( $enrolledsql ) je ON je . id = gg . userid
JOIN (
SELECT DISTINCT ra . userid
FROM { role_assignments } ra
WHERE ra . roleid $gradebookrolessql
AND ra . contextid " . get_related_contexts_string( $this->context ) . "
) rainner ON rainner . userid = u . id
2011-01-18 16:24:41 +08:00
$groupsql
WHERE gi . courseid = : courseid
2011-04-04 11:27:09 +02:00
AND u . deleted = 0
AND gg . finalgrade IS NOT NULL
AND gg . hidden = 0
$groupwheresql
2011-01-18 16:24:41 +08:00
GROUP BY gg . itemid " ;
$sum_array = array ();
2011-01-30 13:43:06 +01:00
$sums = $DB -> get_recordset_sql ( $sql , $params );
foreach ( $sums as $itemid => $csum ) {
$sum_array [ $itemid ] = $csum -> sum ;
2011-01-18 16:24:41 +08:00
}
2011-01-30 13:43:06 +01:00
$sums -> close ();
2011-01-18 16:24:41 +08:00
$columncount = 0 ;
// 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)
// No join condition when joining grade_items and user to get a grade item row for every user
// Then left join with grade_grades and look for rows with null final grade (which includes grade items with no grade_grade)
$sql = " SELECT gi.id, COUNT(u.id) AS count
FROM { grade_items } gi
2011-11-10 11:42:21 +08:00
JOIN { user } u ON u . deleted = 0
2011-04-04 11:27:09 +02:00
JOIN ( $enrolledsql ) je ON je . id = u . id
JOIN (
SELECT DISTINCT ra . userid
FROM { role_assignments } ra
WHERE ra . roleid $gradebookrolessql
AND ra . contextid " . get_related_contexts_string( $this->context ) . "
) rainner ON rainner . userid = u . id
2011-01-18 17:17:14 +08:00
LEFT JOIN { grade_grades } gg
2011-11-10 11:42:21 +08:00
ON ( gg . itemid = gi . id AND gg . userid = u . id AND gg . finalgrade IS NOT NULL AND gg . hidden = 0 )
2011-01-18 16:24:41 +08:00
$groupsql
2011-04-04 11:27:09 +02:00
WHERE gi . courseid = : courseid
AND gg . finalgrade IS NULL
$groupwheresql
GROUP BY gi . id " ;
2011-01-18 16:24:41 +08:00
$ungraded_counts = $DB -> get_records_sql ( $sql , $params );
foreach ( $this -> gtree -> items as $itemid => $unused ) {
if ( ! empty ( $this -> gtree -> items [ $itemid ] -> avg )) {
continue ;
}
$item = $this -> gtree -> items [ $itemid ];
if ( $item -> needsupdate ) {
$avghtml .= '<td class="cell c' . $columncount ++. '"><span class="gradingerror">' . get_string ( 'error' ) . '</span></td>' ;
continue ;
}
if ( empty ( $sum_array [ $item -> id ])) {
$sum_array [ $item -> id ] = 0 ;
}
if ( empty ( $ungraded_counts [ $itemid ])) {
$ungraded_count = 0 ;
} else {
$ungraded_count = $ungraded_counts [ $itemid ] -> count ;
}
//do they want the averages to include all grade items
if ( $meanselection == GRADE_REPORT_MEAN_GRADED ) {
$mean_count = $totalcount - $ungraded_count ;
} else { // Bump up the sum by the number of ungraded items * grademin
$sum_array [ $item -> id ] += ( $ungraded_count * $item -> grademin );
$mean_count = $totalcount ;
}
$decimalpoints = $item -> get_decimals ();
// Determine which display type to use for this average
if ( ! empty ( $USER -> gradeediting ) && $USER -> gradeediting [ $this -> courseid ]) {
$displaytype = GRADE_DISPLAY_TYPE_REAL ;
} else if ( $averagesdisplaytype == GRADE_REPORT_PREFERENCE_INHERIT ) { // no ==0 here, please resave the report and user preferences
$displaytype = $item -> get_displaytype ();
} else {
$displaytype = $averagesdisplaytype ;
}
// Override grade_item setting if a display preference (not inherit) was set for the averages
if ( $averagesdecimalpoints == GRADE_REPORT_PREFERENCE_INHERIT ) {
$decimalpoints = $item -> get_decimals ();
} else {
$decimalpoints = $averagesdecimalpoints ;
}
if ( empty ( $sum_array [ $item -> id ]) || $mean_count == 0 ) {
$this -> gtree -> items [ $itemid ] -> avg = '-' ;
} else {
$sum = $sum_array [ $item -> id ];
$avgradeval = $sum / $mean_count ;
$gradehtml = grade_format_gradevalue ( $avgradeval , $item , true , $displaytype , $decimalpoints );
$numberofgrades = '' ;
if ( $shownumberofgrades ) {
$numberofgrades = " ( $mean_count ) " ;
}
$this -> gtree -> items [ $itemid ] -> avg = $gradehtml . $numberofgrades ;
}
}
}
}
2007-10-27 15:33:43 +00:00
}
function grade_report_user_settings_definition ( & $mform ) {
global $CFG ;
$options = array ( - 1 => get_string ( 'default' , 'grades' ),
0 => get_string ( 'hide' ),
1 => get_string ( 'show' ));
2007-10-27 20:37:22 +00:00
if ( empty ( $CFG -> grade_report_user_showrank )) {
2007-10-27 15:33:43 +00:00
$options [ - 1 ] = get_string ( 'defaultprev' , 'grades' , $options [ 0 ]);
} else {
$options [ - 1 ] = get_string ( 'defaultprev' , 'grades' , $options [ 1 ]);
}
$mform -> addElement ( 'select' , 'report_user_showrank' , get_string ( 'showrank' , 'grades' ), $options );
2010-06-25 17:19:34 +00:00
$mform -> addHelpButton ( 'report_user_showrank' , 'showrank' , 'grades' );
2007-10-27 15:33:43 +00:00
2008-10-08 11:06:05 +00:00
if ( empty ( $CFG -> grade_report_user_showpercentage )) {
2008-10-13 08:44:10 +00:00
$options [ - 1 ] = get_string ( 'defaultprev' , 'grades' , $options [ 0 ]);
2009-02-25 07:56:11 +00:00
} else {
$options [ - 1 ] = get_string ( 'defaultprev' , 'grades' , $options [ 1 ]);
2008-10-08 11:06:05 +00:00
}
$mform -> addElement ( 'select' , 'report_user_showpercentage' , get_string ( 'showpercentage' , 'grades' ), $options );
2010-06-21 08:39:27 +00:00
$mform -> addHelpButton ( 'report_user_showpercentage' , 'showpercentage' , 'grades' );
2008-10-08 11:06:05 +00:00
2011-01-18 16:24:41 +08:00
if ( empty ( $CFG -> grade_report_user_showgrade )) {
$options [ - 1 ] = get_string ( 'defaultprev' , 'grades' , $options [ 0 ]);
} else {
$options [ - 1 ] = get_string ( 'defaultprev' , 'grades' , $options [ 1 ]);
}
$mform -> addElement ( 'select' , 'report_user_showgrade' , get_string ( 'showgrade' , 'grades' ), $options );
if ( empty ( $CFG -> grade_report_user_showfeedback )) {
$options [ - 1 ] = get_string ( 'defaultprev' , 'grades' , $options [ 0 ]);
} else {
$options [ - 1 ] = get_string ( 'defaultprev' , 'grades' , $options [ 1 ]);
}
$mform -> addElement ( 'select' , 'report_user_showfeedback' , get_string ( 'showfeedback' , 'grades' ), $options );
if ( empty ( $CFG -> grade_report_user_showweight )) {
$options [ - 1 ] = get_string ( 'defaultprev' , 'grades' , $options [ 0 ]);
} else {
$options [ - 1 ] = get_string ( 'defaultprev' , 'grades' , $options [ 1 ]);
}
$mform -> addElement ( 'select' , 'report_user_showweight' , get_string ( 'showweight' , 'grades' ), $options );
if ( empty ( $CFG -> grade_report_user_showaverage )) {
$options [ - 1 ] = get_string ( 'defaultprev' , 'grades' , $options [ 0 ]);
} else {
$options [ - 1 ] = get_string ( 'defaultprev' , 'grades' , $options [ 1 ]);
}
$mform -> addElement ( 'select' , 'report_user_showaverage' , get_string ( 'showaverage' , 'grades' ), $options );
$mform -> addHelpButton ( 'report_user_showaverage' , 'showaverage' , 'grades' );
if ( empty ( $CFG -> grade_report_user_showlettergrade )) {
$options [ - 1 ] = get_string ( 'defaultprev' , 'grades' , $options [ 0 ]);
} else {
$options [ - 1 ] = get_string ( 'defaultprev' , 'grades' , $options [ 1 ]);
}
$mform -> addElement ( 'select' , 'report_user_showlettergrade' , get_string ( 'showlettergrade' , 'grades' ), $options );
if ( empty ( $CFG -> grade_report_user_showrange )) {
$options [ - 1 ] = get_string ( 'defaultprev' , 'grades' , $options [ 0 ]);
} else {
$options [ - 1 ] = get_string ( 'defaultprev' , 'grades' , $options [ 1 ]);
}
$mform -> addElement ( 'select' , 'report_user_showrange' , get_string ( 'showrange' , 'grades' ), $options );
$options = array ( 0 => 0 , 1 => 1 , 2 => 2 , 3 => 3 , 4 => 4 , 5 => 5 );
if ( ! empty ( $CFG -> grade_report_user_rangedecimals )) {
$options [ - 1 ] = $options [ $CFG -> grade_report_user_rangedecimals ];
}
$mform -> addElement ( 'select' , 'report_user_rangedecimals' , get_string ( 'rangedecimals' , 'grades' ), $options );
2007-10-27 15:33:43 +00:00
$options = array ( - 1 => get_string ( 'default' , 'grades' ),
2009-05-07 07:38:02 +00:00
0 => get_string ( 'shownohidden' , 'grades' ),
2007-10-30 21:25:50 +00:00
1 => get_string ( 'showhiddenuntilonly' , 'grades' ),
2009-05-07 07:38:02 +00:00
2 => get_string ( 'showallhidden' , 'grades' ));
2007-10-27 15:33:43 +00:00
2007-10-27 20:37:22 +00:00
if ( empty ( $CFG -> grade_report_user_showhiddenitems )) {
2007-10-27 15:33:43 +00:00
$options [ - 1 ] = get_string ( 'defaultprev' , 'grades' , $options [ 0 ]);
} else {
2009-05-07 07:38:02 +00:00
$options [ - 1 ] = get_string ( 'defaultprev' , 'grades' , $options [ $CFG -> grade_report_user_showhiddenitems ]);
2007-10-27 15:33:43 +00:00
}
$mform -> addElement ( 'select' , 'report_user_showhiddenitems' , get_string ( 'showhiddenitems' , 'grades' ), $options );
2010-06-21 06:57:46 +00:00
$mform -> addHelpButton ( 'report_user_showhiddenitems' , 'showhiddenitems' , 'grades' );
2010-02-08 06:27:04 +00:00
//showtotalsifcontainhidden
$options = array ( - 1 => get_string ( 'default' , 'grades' ),
GRADE_REPORT_HIDE_TOTAL_IF_CONTAINS_HIDDEN => get_string ( 'hide' ),
GRADE_REPORT_SHOW_TOTAL_IF_CONTAINS_HIDDEN => get_string ( 'hidetotalshowexhiddenitems' , 'grades' ),
GRADE_REPORT_SHOW_REAL_TOTAL_IF_CONTAINS_HIDDEN => get_string ( 'hidetotalshowinchiddenitems' , 'grades' ) );
if ( empty ( $CFG -> grade_report_user_showtotalsifcontainhidden )) {
$options [ - 1 ] = get_string ( 'defaultprev' , 'grades' , $options [ 0 ]);
} else {
$options [ - 1 ] = get_string ( 'defaultprev' , 'grades' , $options [ $CFG -> grade_report_user_showtotalsifcontainhidden ]);
}
$mform -> addElement ( 'select' , 'report_user_showtotalsifcontainhidden' , get_string ( 'hidetotalifhiddenitems' , 'grades' ), $options );
2010-06-07 09:56:33 +00:00
$mform -> addHelpButton ( 'report_user_showtotalsifcontainhidden' , 'hidetotalifhiddenitems' , 'grades' );
2007-10-28 17:15:00 +00:00
}
function grade_report_user_profilereport ( $course , $user ) {
2009-09-04 03:12:01 +00:00
global $OUTPUT ;
2007-10-28 17:15:00 +00:00
if ( ! empty ( $course -> showgrades )) {
2012-07-24 14:04:40 +08:00
$context = context_course :: instance ( $course -> id );
2007-10-28 17:15:00 +00:00
//first make sure we have proper final grades - this must be done before constructing of the grade tree
grade_regrade_final_grades ( $course -> id );
/// return tracking object
$gpr = new grade_plugin_return ( array ( 'type' => 'report' , 'plugin' => 'user' , 'courseid' => $course -> id , 'userid' => $user -> id ));
// Create a report instance
$report = new grade_report_user ( $course -> id , $gpr , $context , $user -> id );
2007-07-16 04:09:00 +00:00
2007-10-28 17:15:00 +00:00
// print the page
echo '<div class="grade-report-user">' ; // css fix to share styles with real report page
MDL-23071 standardising gradebook plugin names
AMOS BEGIN
MOV [modulename,gradeimport_csv],[pluginname,gradeimport_csv]
MOV [modulename,gradeimport_xml],[pluginname,gradeimport_xml]
MOV [modulename,gradeexport_ods],[pluginname,gradeexport_ods]
MOV [modulename,gradeexport_txt],[pluginname,gradeexport_txt]
MOV [modulename,gradeexport_xls],[pluginname,gradeexport_xls]
MOV [modulename,gradeexport_xml],[pluginname,gradeexport_xml]
MOV [modulename,gradereport_grader],[pluginname,gradereport_grader]
MOV [modulename,gradereport_outcomes],[pluginname,gradereport_outcomes]
MOV [modulename,gradereport_overview],[pluginname,gradereport_overview]
MOV [modulename,gradereport_user],[pluginname,gradereport_user]
AMOS END
2010-07-04 13:08:11 +00:00
echo $OUTPUT -> heading ( get_string ( 'pluginname' , 'gradereport_user' ) . ' - ' . fullname ( $report -> user ));
2007-10-28 17:15:00 +00:00
if ( $report -> fill_table ()) {
echo $report -> print_table ( true );
}
echo '</div>' ;
}
2007-07-16 04:09:00 +00:00
}
2007-10-28 17:15:00 +00:00
2009-11-01 12:11:29 +00:00