Commit 01199ea9 authored by vyshane's avatar vyshane
Browse files

Updated to use new Roles System. Plus some fixes.

parent 920b93d1
......@@ -718,7 +718,10 @@ class block_nuke extends block_base {
$oldvals['admin'] = $GLOBALS['admin'];
}
// isteacher() will eventually be deprecated and blocks
// should define their own capabilities.
$GLOBALS['admin'] = isteacher($this->course->id);
@include($dir.$file);
foreach($oldvals as $key => $val) {
......@@ -739,4 +742,4 @@ class block_nuke extends block_base {
}
}
?>
?>
\ No newline at end of file
<?PHP //$Id$
/**
* This block needs to be reworked.
* The new roles system does away with the concepts of rigid student and
* teacher roles.
*/
class block_online_users extends block_base {
function init() {
$this->title = get_string('blockname','block_online_users');
......@@ -22,15 +27,20 @@ class block_online_users extends block_base {
if (empty($this->instance)) {
return $this->content;
}
$timetoshowusers = 300; //Seconds default
if (isset($CFG->block_online_users_timetosee)) {
$timetoshowusers = $CFG->block_online_users_timetosee * 60;
}
$timefrom = time()-$timetoshowusers;
// Get context so we can check capabilities.
$context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
//Calculate if we are in separate groups
$isseparategroups = ($COURSE->groupmode == SEPARATEGROUPS && $COURSE->groupmodeforce && !isteacheredit($COURSE->id));
$isseparategroups = ($COURSE->groupmode == SEPARATEGROUPS
&& $COURSE->groupmodeforce
&& !has_capability('moodle/site:accessallgroups', $context));
//Get the user current group
$currentgroup = $isseparategroups ? get_current_group($COURSE->id) : NULL;
......@@ -85,7 +95,9 @@ class block_online_users extends block_base {
{$CFG->prefix}user_teachers s
$groupmembers
WHERE u.id = s.userid $courseselect $groupselect $timeselect ";
// Now that we have the Roles System, how will we handle what
// used to be hidden teachers?
if (!isteacher($COURSE->id)) {
// Hide hidden teachers from students.
$findteacherssql .= 'AND s.authority > 0 ';
......@@ -131,4 +143,4 @@ class block_online_users extends block_base {
}
}
?>
?>
\ No newline at end of file
......@@ -14,15 +14,17 @@ class block_participants extends block_list {
if (empty($this->instance->pageid)) {
return '';
}
$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
// only 2 possible contexts, site or course
if ($this->instance->pageid == SITEID) { // site context
$context = get_context_instance(CONTEXT_SYSTEM, SITEID);
$currentcontext = $sitecontext;
} else { // course context
$context = get_context_instance(CONTEXT_COURSE, $this->instance->pageid);
$currentcontext = get_context_instance(CONTEXT_COURSE, $this->instance->pageid);
}
if (!has_capability('moodle/course:viewparticipants', $context)) {
if (!has_capability('moodle/course:viewparticipants', $currentcontext)) {
$this->context = '';
return $this->content;
}
......@@ -45,13 +47,14 @@ class block_participants extends block_list {
$this->instance->pageid = SITEID;
}
// $CFG->showsiteparticipantslist == 1 <-- this is deprecated.
if ($this->instance->pageid != SITEID ||
$CFG->showsiteparticipantslist > 1 ||
($CFG->showsiteparticipantslist == 1 && isteacherinanycourse()) ||
isteacher(SITEID)) {
has_capability('moodle/course:viewparticipants', $sitecontext)) {
$this->content->items[] = '<a title="'.get_string('listofallpeople').'" href="'.
$CFG->wwwroot.'/user/index.php?contextid='.$context->id.'">'.get_string('participants').'</a>';
$CFG->wwwroot.'/user/index.php?contextid='.$currentcontext->id.'">'.get_string('participants').'</a>';
$this->content->icons[] = '<img src="'.$CFG->pixpath.'/i/users.gif" height="16" width="16" alt="" />';
}
......@@ -66,4 +69,4 @@ class block_participants extends block_list {
}
?>
?>
\ No newline at end of file
......@@ -51,6 +51,9 @@ class block_quiz_results extends block_base {
$courseid = $this->config->courseid;
}
$context = get_context_instance(CONTEXT_COURSE, $courseid);
if(empty($quizid)) {
$this->content->text = get_string('error_emptyquizid', 'block_quiz_results');
return $this->content;
......@@ -101,7 +104,7 @@ class block_quiz_results extends block_base {
// The actual groupmode for the quiz is now known to be $groupmode
}
if(isteacheredit($courseid) && $groupmode == SEPARATEGROUPS) {
if(has_capability('moodle/site:accessallgroups', $context) && $groupmode == SEPARATEGROUPS) {
// We 'll make an exception in this case
$groupmode = VISIBLEGROUPS;
}
......
......@@ -27,6 +27,7 @@ class block_social_activities extends block_list {
}
$course = get_record('course', 'id', $this->instance->pageid);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
// To make our day, we start with an ugly hack
global $sections, $mods, $modnames;
......@@ -36,8 +37,8 @@ class block_social_activities extends block_list {
$groupbuttons = $course->groupmode;
$groupbuttonslink = (!$course->groupmodeforce);
$isteacher = isteacher($this->instance->pageid);
$isediting = isediting($this->instance->pageid);
$viewhiddenactivities = has_capability('moodle/course:viewhiddenactivities', $context);
$manageactivities = has_capability('moodle/course:manageactivities', $context);
$ismoving = ismoving($this->instance->pageid);
if ($ismoving) {
$strmovehere = get_string('movehere');
......@@ -61,7 +62,7 @@ class block_social_activities extends block_list {
continue;
}
$mod = $mods[$modnumber];
if ($isediting && !$ismoving) {
if ($manageactivities && !$ismoving) {
if ($groupbuttons) {
if (! $mod->groupmodelink = $groupbuttonslink) {
$mod->groupmode = $course->groupmode;
......@@ -74,7 +75,7 @@ class block_social_activities extends block_list {
} else {
$editbuttons = '';
}
if ($mod->visible || $isteacher) {
if ($mod->visible || $viewhiddenactivities) {
if ($ismoving) {
if ($mod->id == $USER->activitycopy) {
continue;
......@@ -115,7 +116,7 @@ class block_social_activities extends block_list {
$this->content->icons[] = '';
}
if ($isediting && $modnames) {
if ($manageactivities && $modnames) {
$this->content->footer = print_section_add_menus($course, 0, $modnames, true, true);
} else {
$this->content->footer = '';
......@@ -125,4 +126,4 @@ class block_social_activities extends block_list {
}
}
?>
?>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment