mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-29501 Gradebook should not show links to activities that aren't available to user
This commit is contained in:
parent
6731a04d93
commit
73ca5f01c5
@ -1002,6 +1002,14 @@ class grade_structure {
|
|||||||
|
|
||||||
public $courseid;
|
public $courseid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to modinfo for current course (for performance, to save
|
||||||
|
* retrieving it from courseid every time). Not actually set except for
|
||||||
|
* the grade_tree type.
|
||||||
|
* @var course_modinfo
|
||||||
|
*/
|
||||||
|
public $modinfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 1D array of grade items only
|
* 1D array of grade items only
|
||||||
*/
|
*/
|
||||||
@ -1104,8 +1112,6 @@ class grade_structure {
|
|||||||
* @return string header
|
* @return string header
|
||||||
*/
|
*/
|
||||||
public function get_element_header(&$element, $withlink=false, $icon=true, $spacerifnone=false) {
|
public function get_element_header(&$element, $withlink=false, $icon=true, $spacerifnone=false) {
|
||||||
global $CFG;
|
|
||||||
|
|
||||||
$header = '';
|
$header = '';
|
||||||
|
|
||||||
if ($icon) {
|
if ($icon) {
|
||||||
@ -1119,31 +1125,54 @@ class grade_structure {
|
|||||||
return $header;
|
return $header;
|
||||||
}
|
}
|
||||||
|
|
||||||
$itemtype = $element['object']->itemtype;
|
if ($withlink) {
|
||||||
$itemmodule = $element['object']->itemmodule;
|
$url = $this->get_activity_link($element);
|
||||||
$iteminstance = $element['object']->iteminstance;
|
if ($url) {
|
||||||
|
|
||||||
if ($withlink and $itemtype=='mod' and $iteminstance and $itemmodule) {
|
|
||||||
if ($cm = get_coursemodule_from_instance($itemmodule, $iteminstance, $this->courseid)) {
|
|
||||||
|
|
||||||
$a = new stdClass();
|
$a = new stdClass();
|
||||||
$a->name = get_string('modulename', $element['object']->itemmodule);
|
$a->name = get_string('modulename', $element['object']->itemmodule);
|
||||||
$title = get_string('linktoactivity', 'grades', $a);
|
$title = get_string('linktoactivity', 'grades', $a);
|
||||||
$dir = $CFG->dirroot.'/mod/'.$itemmodule;
|
|
||||||
|
|
||||||
if (file_exists($dir.'/grade.php')) {
|
$header = html_writer::link($url, $header, array('title' => $title));
|
||||||
$url = $CFG->wwwroot.'/mod/'.$itemmodule.'/grade.php?id='.$cm->id;
|
|
||||||
} else {
|
|
||||||
$url = $CFG->wwwroot.'/mod/'.$itemmodule.'/view.php?id='.$cm->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
$header = '<a href="'.$url.'" title="'.s($title).'">'.$header.'</a>';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $header;
|
return $header;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function get_activity_link($element) {
|
||||||
|
global $CFG;
|
||||||
|
|
||||||
|
$itemtype = $element['object']->itemtype;
|
||||||
|
$itemmodule = $element['object']->itemmodule;
|
||||||
|
$iteminstance = $element['object']->iteminstance;
|
||||||
|
|
||||||
|
// Links only for module items that have valid instance, module and are
|
||||||
|
// called from grade_tree with valid modinfo
|
||||||
|
if ($itemtype != 'mod' || !$iteminstance || !$itemmodule || !$this->modinfo) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get $cm efficiently and with visibility information using modinfo
|
||||||
|
$instances = $this->modinfo->get_instances();
|
||||||
|
if (empty($instances[$itemmodule][$iteminstance])) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$cm = $instances[$itemmodule][$iteminstance];
|
||||||
|
|
||||||
|
// Do not add link if activity is not visible to the current user
|
||||||
|
if (!$cm->uservisible) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If module has grade.php, link to that, otherwise view.php
|
||||||
|
$dir = $CFG->dirroot . '/mod/' . $itemmodule;
|
||||||
|
if (file_exists($dir.'/grade.php')) {
|
||||||
|
return new moodle_url('/mod/' . $itemmodule . '/grade.php', array('id' => $cm->id));
|
||||||
|
} else {
|
||||||
|
return new moodle_url('/mod/' . $itemmodule . '/view.php', array('id' => $cm->id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the grade eid - the grade may not exist yet.
|
* Returns the grade eid - the grade may not exist yet.
|
||||||
*
|
*
|
||||||
@ -1600,12 +1629,19 @@ class grade_tree extends grade_structure {
|
|||||||
*/
|
*/
|
||||||
public function grade_tree($courseid, $fillers=true, $category_grade_last=false,
|
public function grade_tree($courseid, $fillers=true, $category_grade_last=false,
|
||||||
$collapsed=null, $nooutcomes=false) {
|
$collapsed=null, $nooutcomes=false) {
|
||||||
global $USER, $CFG;
|
global $USER, $CFG, $COURSE, $DB;
|
||||||
|
|
||||||
$this->courseid = $courseid;
|
$this->courseid = $courseid;
|
||||||
$this->levels = array();
|
$this->levels = array();
|
||||||
$this->context = get_context_instance(CONTEXT_COURSE, $courseid);
|
$this->context = get_context_instance(CONTEXT_COURSE, $courseid);
|
||||||
|
|
||||||
|
if (!empty($COURSE->id) && $COURSE->id == $this->courseid) {
|
||||||
|
$course = $COURSE;
|
||||||
|
} else {
|
||||||
|
$course = $DB->get_record('course', array('id' => $this->courseid));
|
||||||
|
}
|
||||||
|
$this->modinfo = get_fast_modinfo($course);
|
||||||
|
|
||||||
// get course grade tree
|
// get course grade tree
|
||||||
$this->top_element = grade_category::fetch_course_tree($courseid, true);
|
$this->top_element = grade_category::fetch_course_tree($courseid, true);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user