From 8a954a15715091be50eb92bdbc98b623fb017752 Mon Sep 17 00:00:00 2001 From: Shamim Rezaie Date: Fri, 20 Jan 2017 20:07:11 +1100 Subject: [PATCH] MDL-55915 mod_assign: let fullname() know if user has viewfullnames cap Instruct fullname() to format names on the assignment grading page with alternativefullnameformat when user has moodle/site:viewfullnames capability. --- mod/assign/gradingtable.php | 6 ++++-- mod/assign/locallib.php | 32 +++++++++++++++++++------------- mod/assign/renderable.php | 7 ++++++- mod/assign/renderer.php | 2 +- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/mod/assign/gradingtable.php b/mod/assign/gradingtable.php index ade35cfdc73..47d4afca2ac 100644 --- a/mod/assign/gradingtable.php +++ b/mod/assign/gradingtable.php @@ -567,8 +567,9 @@ class assign_grading_table extends table_sql implements renderable { list($sort, $params) = users_order_by_sql(); $markers = get_users_by_capability($this->assignment->get_context(), 'mod/assign:grade', '', $sort); $markerlist[0] = get_string('choosemarker', 'assign'); + $viewfullnames = has_capability('moodle/site:viewfullnames', $this->assignment->get_context()); foreach ($markers as $marker) { - $markerlist[$marker->id] = fullname($marker); + $markerlist[$marker->id] = fullname($marker, $viewfullnames); } } if (empty($markerlist)) { @@ -577,7 +578,8 @@ class assign_grading_table extends table_sql implements renderable { } if ($this->is_downloading()) { if (isset($markers[$row->allocatedmarker])) { - return fullname($markers[$row->allocatedmarker]); + return fullname($markers[$row->allocatedmarker], + has_capability('moodle/site:viewfullnames', $this->assignment->get_context())); } else { return ''; } diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index 8d54db84225..9e6eb40428a 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -3271,7 +3271,7 @@ class assign { $extensionduedate = $flags->extensionduedate; } $showedit = $this->submissions_open($userid) && ($this->is_any_submission_plugin_enabled()); - $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_course_context()); + $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_context()); $usergroups = $this->get_all_groups($user->id); $submissionstatus = new assign_submission_status_compact($instance->allowsubmissionsfromdate, @@ -3433,7 +3433,7 @@ class assign { $user = $DB->get_record('user', array('id' => $userid)); if ($user) { - $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_course_context()); + $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_context()); $usersummary = new assign_user_summary($user, $this->get_course()->id, $viewfullnames, @@ -3468,7 +3468,7 @@ class assign { $extensionduedate = $flags->extensionduedate; } $showedit = $this->submissions_open($userid) && ($this->is_any_submission_plugin_enabled()); - $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_course_context()); + $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_context()); $usergroups = $this->get_all_groups($user->id); $submissionstatus = new assign_submission_status($instance->allowsubmissionsfromdate, @@ -3694,8 +3694,9 @@ class assign { $markers = get_users_by_capability($this->context, 'mod/assign:grade', '', $sort); $markingallocationoptions[''] = get_string('filternone', 'assign'); $markingallocationoptions[ASSIGN_MARKER_FILTER_NO_MARKER] = get_string('markerfilternomarker', 'assign'); + $viewfullnames = has_capability('moodle/site:viewfullnames', $this->context); foreach ($markers as $marker) { - $markingallocationoptions[$marker->id] = fullname($marker); + $markingallocationoptions[$marker->id] = fullname($marker, $viewfullnames); } } @@ -3939,12 +3940,13 @@ class assign { $uniqueid = $user->recordid; } if ($hasviewblind) { - return get_string('participant', 'assign') . ' ' . $uniqueid . ' (' . fullname($user) . ')'; + return get_string('participant', 'assign') . ' ' . $uniqueid . ' (' . + fullname($user, has_capability('moodle/site:viewfullnames', $this->get_context())) . ')'; } else { return get_string('participant', 'assign') . ' ' . $uniqueid; } } else { - return fullname($user); + return fullname($user, has_capability('moodle/site:viewfullnames', $this->get_context())); } } @@ -4207,6 +4209,7 @@ class assign { $usercount = 0; $extrauserfields = get_extra_user_fields($this->get_context()); + $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_context()); foreach ($userlist as $userid) { if ($usercount >= 5) { $usershtml .= get_string('moreusers', 'assign', count($userlist) - 5); @@ -4216,8 +4219,7 @@ class assign { $usershtml .= $this->get_renderer()->render(new assign_user_summary($user, $this->get_course()->id, - has_capability('moodle/site:viewfullnames', - $this->get_course_context()), + $viewfullnames, $this->is_blind_marking(), $this->get_uniqueid_for_user($user->id), $extrauserfields, @@ -4271,6 +4273,7 @@ class assign { $usercount = 0; $extrauserfields = get_extra_user_fields($this->get_context()); + $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_context()); foreach ($userlist as $userid) { if ($usercount >= 5) { $usershtml .= get_string('moreusers', 'assign', count($userlist) - 5); @@ -4280,8 +4283,7 @@ class assign { $usershtml .= $this->get_renderer()->render(new assign_user_summary($user, $this->get_course()->id, - has_capability('moodle/site:viewfullnames', - $this->get_course_context()), + $viewfullnames, $this->is_blind_marking(), $this->get_uniqueid_for_user($user->id), $extrauserfields, @@ -4428,7 +4430,7 @@ class assign { if ($flags) { $extensionduedate = $flags->extensionduedate; } - $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_course_context()); + $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_context()); $gradingstatus = $this->get_grading_status($user->id); $usergroups = $this->get_all_groups($user->id); @@ -4540,6 +4542,8 @@ class assign { } } + $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_context()); + $feedbackstatus = new assign_feedback_status($gradefordisplay, $gradeddate, $grader, @@ -4547,7 +4551,8 @@ class assign { $grade, $this->get_course_module()->id, $this->get_return_action(), - $this->get_return_params()); + $this->get_return_params(), + $viewfullnames); return $feedbackstatus; } return; @@ -6775,8 +6780,9 @@ class assign { list($sort, $params) = users_order_by_sql(); $markers = get_users_by_capability($this->context, 'mod/assign:grade', '', $sort); $markerlist = array('' => get_string('choosemarker', 'assign')); + $viewfullnames = has_capability('moodle/site:viewfullnames', $this->context); foreach ($markers as $marker) { - $markerlist[$marker->id] = fullname($marker); + $markerlist[$marker->id] = fullname($marker, $viewfullnames); } $mform->addElement('select', 'allocatedmarker', get_string('allocatedmarker', 'assign'), $markerlist); $mform->addHelpButton('allocatedmarker', 'allocatedmarker', 'assign'); diff --git a/mod/assign/renderable.php b/mod/assign/renderable.php index 4d8b73c1cfe..6ee0e490ce7 100644 --- a/mod/assign/renderable.php +++ b/mod/assign/renderable.php @@ -287,6 +287,8 @@ class assign_feedback_status implements renderable { public $returnaction = ''; /** @var array returnparams */ public $returnparams = array(); + /** @var bool canviewfullnames */ + public $canviewfullnames = false; /** * Constructor @@ -298,6 +300,7 @@ class assign_feedback_status implements renderable { * @param int $coursemoduleid * @param string $returnaction The action required to return to this page * @param array $returnparams The list of params required to return to this page + * @param bool $canviewfullnames */ public function __construct($gradefordisplay, $gradeddate, @@ -306,7 +309,8 @@ class assign_feedback_status implements renderable { $grade, $coursemoduleid, $returnaction, - $returnparams) { + $returnparams, + $canviewfullnames) { $this->gradefordisplay = $gradefordisplay; $this->gradeddate = $gradeddate; $this->grader = $grader; @@ -315,6 +319,7 @@ class assign_feedback_status implements renderable { $this->coursemoduleid = $coursemoduleid; $this->returnaction = $returnaction; $this->returnparams = $returnparams; + $this->canviewfullnames = $canviewfullnames; } } diff --git a/mod/assign/renderer.php b/mod/assign/renderer.php index 665a0d3c002..0dae5e0cc91 100644 --- a/mod/assign/renderer.php +++ b/mod/assign/renderer.php @@ -389,7 +389,7 @@ class mod_assign_renderer extends plugin_renderer_base { $cell1 = new html_table_cell(get_string('gradedby', 'assign')); $userdescription = $this->output->user_picture($status->grader) . $this->output->spacer(array('width'=>30)) . - fullname($status->grader); + fullname($status->grader, $status->canviewfullnames); $cell2 = new html_table_cell($userdescription); $row->cells = array($cell1, $cell2); $t->data[] = $row;