Merge branch 'MDL-43197-26-2nd' of git://github.com/FMCorz/moodle into MOODLE_26_STABLE

This commit is contained in:
Marina Glancy 2014-08-19 13:26:19 +08:00
commit f09f95fefa
3 changed files with 58 additions and 8 deletions

View file

@ -79,6 +79,9 @@ $anyreport = has_capability('moodle/user:viewuseractivitiesreport', $personalco
$modes = array(); $modes = array();
// Used for grade reports, it represents whether we should be viewing the report as ourselves, or as the targetted user.
$viewasuser = false;
if (has_capability('moodle/grade:viewall', $coursecontext)) { if (has_capability('moodle/grade:viewall', $coursecontext)) {
//ok - can view all course grades //ok - can view all course grades
$modes[] = 'grade'; $modes[] = 'grade';
@ -90,10 +93,12 @@ if (has_capability('moodle/grade:viewall', $coursecontext)) {
} else if ($course->showgrades and has_capability('moodle/grade:viewall', $personalcontext)) { } else if ($course->showgrades and has_capability('moodle/grade:viewall', $personalcontext)) {
// ok - can view grades of this user - parent most probably // ok - can view grades of this user - parent most probably
$modes[] = 'grade'; $modes[] = 'grade';
$viewasuser = true;
} else if ($course->showgrades and $anyreport) { } else if ($course->showgrades and $anyreport) {
// ok - can view grades of this user - parent most probably // ok - can view grades of this user - parent most probably
$modes[] = 'grade'; $modes[] = 'grade';
$viewasuser = true;
} }
if (empty($modes)) { if (empty($modes)) {
@ -126,7 +131,7 @@ switch ($mode) {
$functionname = 'grade_report_'.$CFG->grade_profilereport.'_profilereport'; $functionname = 'grade_report_'.$CFG->grade_profilereport.'_profilereport';
if (function_exists($functionname)) { if (function_exists($functionname)) {
$functionname($course, $user); $functionname($course, $user, $viewasuser);
} }
break; break;

View file

@ -1,6 +1,14 @@
This files describes API changes in /grade/report/*, This files describes API changes in /grade/report/*,
information provided here is intended especially for developers. information provided here is intended especially for developers.
=== 2.6.5, 2.7.2 ===
* The callback function grade_report_*_profilereport now takes one more parameter $viewasuser. This parameter
is set to true when the report must be viewed as the user whose grades are being displayed. For instance,
when a mentor/parent is viewing the report, they should see the same grades, not more, not less. When the
setting is set to false (default), the capability checks, visibility and access levels are using the
currently logged in user.
=== 2.6 === === 2.6 ===
* grade_report_grader::get_toggles_html() and grade_report_grader::print_toggle() * grade_report_grader::get_toggles_html() and grade_report_grader::print_toggle()
can not be used any more can not be used any more

View file

@ -151,14 +151,34 @@ class grade_report_user extends grade_report {
public $baseurl; public $baseurl;
public $pbarurl; public $pbarurl;
/**
* The modinfo object to be used.
*
* @var course_modinfo
*/
protected $modinfo = null;
/**
* View as user.
*
* When this is set to true, the visibility checks, and capability checks will be
* applied to the user whose grades are being displayed. This is very useful when
* a mentor/parent is viewing the report of their mentee because they need to have
* access to the same information, but not more, not less.
*
* @var boolean
*/
protected $viewasuser = false;
/** /**
* Constructor. Sets local copies of user preferences and initialises grade_tree. * Constructor. Sets local copies of user preferences and initialises grade_tree.
* @param int $courseid * @param int $courseid
* @param object $gpr grade plugin return tracking object * @param object $gpr grade plugin return tracking object
* @param string $context * @param string $context
* @param int $userid The id of the user * @param int $userid The id of the user
* @param bool $viewasuser Set this to true when the current user is a mentor/parent of the targetted user.
*/ */
public function __construct($courseid, $gpr, $context, $userid) { public function __construct($courseid, $gpr, $context, $userid, $viewasuser = null) {
global $DB, $CFG; global $DB, $CFG;
parent::__construct($courseid, $gpr, $context); parent::__construct($courseid, $gpr, $context);
@ -174,6 +194,8 @@ class grade_report_user extends grade_report {
$this->showlettergrade = grade_get_setting($this->courseid, 'report_user_showlettergrade', !empty($CFG->grade_report_user_showlettergrade)); $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)); $this->showaverage = grade_get_setting($this->courseid, 'report_user_showaverage', !empty($CFG->grade_report_user_showaverage));
$this->viewasuser = $viewasuser;
// The default grade decimals is 2 // The default grade decimals is 2
$defaultdecimals = 2; $defaultdecimals = 2;
if (property_exists($CFG, 'grade_decimalpoints')) { if (property_exists($CFG, 'grade_decimalpoints')) {
@ -203,11 +225,19 @@ class grade_report_user extends grade_report {
$this->tabledata = array(); $this->tabledata = array();
$this->canviewhidden = has_capability('moodle/grade:viewhidden', context_course::instance($this->courseid)); // Get the user (for full name).
// get the user (for full name)
$this->user = $DB->get_record('user', array('id' => $userid)); $this->user = $DB->get_record('user', array('id' => $userid));
// What user are we viewing this as?
$coursecontext = context_course::instance($this->courseid);
if ($viewasuser) {
$this->modinfo = new course_modinfo($this->course, $this->user->id);
$this->canviewhidden = has_capability('moodle/grade:viewhidden', $coursecontext, $this->user->id);
} else {
$this->modinfo = $this->gtree->modinfo;
$this->canviewhidden = has_capability('moodle/grade:viewhidden', $coursecontext);
}
// base url for sorting by first/last name // base url for sorting by first/last name
$this->baseurl = $CFG->wwwroot.'/grade/report?id='.$courseid.'&userid='.$userid; $this->baseurl = $CFG->wwwroot.'/grade/report?id='.$courseid.'&userid='.$userid;
$this->pbarurl = $this->baseurl; $this->pbarurl = $this->baseurl;
@ -363,7 +393,7 @@ class grade_report_user extends grade_report {
// The grade object can be marked visible but still be hidden if... // 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. // 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. // 2) the student cannot see the activity due to conditional access and its set to be hidden entirely.
$instances = $this->gtree->modinfo->get_instances_of($grade_object->itemmodule); $instances = $this->modinfo->get_instances_of($grade_object->itemmodule);
if (!empty($instances[$grade_object->iteminstance])) { if (!empty($instances[$grade_object->iteminstance])) {
$cm = $instances[$grade_object->iteminstance]; $cm = $instances[$grade_object->iteminstance];
if (!$cm->uservisible) { if (!$cm->uservisible) {
@ -904,7 +934,14 @@ function grade_report_user_settings_definition(&$mform) {
$mform->addHelpButton('report_user_showtotalsifcontainhidden', 'hidetotalifhiddenitems', 'grades'); $mform->addHelpButton('report_user_showtotalsifcontainhidden', 'hidetotalifhiddenitems', 'grades');
} }
function grade_report_user_profilereport($course, $user) { /**
* Profile report callback.
*
* @param object $course The course.
* @param object $user The user.
* @param boolean $viewasuser True when we are viewing this as the targetted user sees it.
*/
function grade_report_user_profilereport($course, $user, $viewasuser = false) {
global $OUTPUT; global $OUTPUT;
if (!empty($course->showgrades)) { if (!empty($course->showgrades)) {
@ -916,7 +953,7 @@ function grade_report_user_profilereport($course, $user) {
/// return tracking object /// return tracking object
$gpr = new grade_plugin_return(array('type'=>'report', 'plugin'=>'user', 'courseid'=>$course->id, 'userid'=>$user->id)); $gpr = new grade_plugin_return(array('type'=>'report', 'plugin'=>'user', 'courseid'=>$course->id, 'userid'=>$user->id));
// Create a report instance // Create a report instance
$report = new grade_report_user($course->id, $gpr, $context, $user->id); $report = new grade_report_user($course->id, $gpr, $context, $user->id, $viewasuser);
// print the page // print the page
echo '<div class="grade-report-user">'; // css fix to share styles with real report page echo '<div class="grade-report-user">'; // css fix to share styles with real report page