From: toyomoyo Date: Fri, 17 Nov 2006 08:57:50 +0000 (+0000) Subject: fix for MDL-7595, adding coursemanager config variable to determine what roles are... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=d42c64ba14f8b96a8cfecb3604dc7e2c48fdef67;p=moodle.git fix for MDL-7595, adding coursemanager config variable to determine what roles are displayed on course description page --- diff --git a/admin/settings/appearance.php b/admin/settings/appearance.php index 789241c936..ae14f00ed7 100644 --- a/admin/settings/appearance.php +++ b/admin/settings/appearance.php @@ -123,6 +123,10 @@ $temp = new admin_settingpage('gradebook', get_string('gradebook', 'admin')); $temp->add(new admin_setting_special_gradebookroles()); $ADMIN->add('appearance', $temp); +// new CFG variable for coursemanager (what roles to display) +$temp = new admin_settingpage('coursemanager', get_string('coursemanager', 'admin')); +$temp->add(new admin_setting_special_coursemanager()); +$ADMIN->add('appearance', $temp); $ADMIN->add('appearance', new admin_externalpage('stickyblocks', get_string('stickyblocks', 'admin'), "$CFG->wwwroot/$CFG->admin/stickyblocks.php")); diff --git a/course/lib.php b/course/lib.php index b01f15e973..3869afa98d 100644 --- a/course/lib.php +++ b/course/lib.php @@ -1549,25 +1549,27 @@ function print_course($course, $width="100%") { $linkcss.' href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'. $course->fullname.'
'; - if ($teachers = get_users_by_capability($context, 'moodle/course:update', - 'u.*, ul.timeaccess as lastaccess', - 'r.sortorder ASC', '','','','', false, true)) { - $namesarray = array(); - foreach ($teachers as $teacher) { - if ($roles = get_user_roles($context, $teacher->id, true, 'r.sortorder ASC', true)) { - $role = array_shift($roles); // First one - $fullname = fullname($teacher, has_capability('moodle/site:viewfullnames', $context)); - $namesarray[] = format_string($role->name).': wwwroot.'/user/view.php?id='. $teacher->id.'&course='.SITEID.'">'.$fullname.''; + } } } - if ($namesarray) { + + if (!empty($namesarray)) { echo ""; } } - + require_once("$CFG->dirroot/enrol/enrol.class.php"); $enrol = enrolment_factory::factory($course->enrol); echo $enrol->get_access_icons($course); diff --git a/lang/en_utf8/admin.php b/lang/en_utf8/admin.php index 771de24157..44884d05c8 100644 --- a/lang/en_utf8/admin.php +++ b/lang/en_utf8/admin.php @@ -57,6 +57,7 @@ $string['configclamactlikevirus'] = 'Treat files like viruses'; $string['configclamdonothing'] = 'Treat files as OK'; $string['configclamfailureonupload'] = 'If you have configured clam to scan uploaded files, but it is configured incorrectly or fails to run for some unknown reason, how should it behave? If you choose \'Treat files like viruses\', they\'ll be moved into the quarantine area, or deleted. If you choose \'Treat files as OK\', the files will be moved to the desination directory like normal. Either way, admins will be alerted that clam has failed. If you choose \'Treat files like viruses\' and for some reason clam fails to run (usually because you have entered an invalid pathtoclam), ALL files that are uploaded will be moved to the given quarantine area, or deleted. Be careful with this setting.'; $string['configcountry'] = 'If you set a country here, then this country will be selected by default on new user accounts. To force users to choose a country, just leave this unset.'; +$string['configcoursemanager'] = 'This setting allows you to control who appears on the course description. Users need to have at least one of these roles in a course to be shown on the course description for that course.'; $string['configcoursesperpage'] = 'Enter the number of courses to be display per page in a course listing.'; $string['configdbsessions'] = 'If enabled, this setting will use the database to store information about current sessions. This is especially useful for large/busy sites or sites built on cluster of servers. For most sites this should probably be left disabled so that the server disk is used instead. Note that changing this setting now will log out all current users (including you). If you are using MySQL please make sure that \'max_allowed_packet\' in my.cnf (or my.ini) is at least 4M.'; $string['configdebug'] = 'If you turn this on, then PHP\'s error_reporting will be increased so that more warnings are printed. This is only useful for developers.'; @@ -179,6 +180,7 @@ $string['configzip'] = 'Indicate the location of your zip program (Unix only, op $string['confirmation'] = 'Confirmation'; $string['confirminstall'] = 'You are about to install language pack ($a), are you sure?'; $string['country'] = 'Default country'; +$string['coursemanager'] = 'Course managers'; $string['coursemgmt'] = 'Add/edit courses'; $string['courseoverview'] = 'Course overview'; $string['courserequests'] = 'Course Requests'; diff --git a/lib/accesslib.php b/lib/accesslib.php index 3dba6c35fb..944b5bcc83 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -2767,7 +2767,7 @@ function get_roles_used_in_context($context, $view = false) { // filter for roles with all hidden assignments // no need to return when only pulling roles for reviewing // e.g. participants page. - $hiddensql = ($view && has_capability('moodle/role:viewhiddenassigns', $context))? '':' AND ra.hidden = 0 '; + $hiddensql = ($view && !has_capability('moodle/role:viewhiddenassigns', $context))? ' AND ra.hidden = 0 ':''; $contextlist = get_related_contexts_string($context); $sql = "SELECT DISTINCT r.id, @@ -2888,7 +2888,7 @@ function get_user_roles($context, $userid=0, $checkparentcontexts=true, $order=' $userid = $USER->id; } // set up hidden sql - $hiddensql = ($view && has_capability('moodle/role:viewhiddenassigns', $context))? '':' AND ra.hidden = 0 '; + $hiddensql = ($view && !has_capability('moodle/role:viewhiddenassigns', $context))? ' AND ra.hidden = 0 ':''; if ($checkparentcontexts && ($parents = get_parent_contexts($context))) { $contexts = ' ra.contextid IN ('.implode(',' , $parents).','.$context->id.')'; @@ -3058,7 +3058,7 @@ function get_users_by_capability($context, $capability, $fields='', $sort='', $sortby = $sort ? " ORDER BY $sort " : ''; /// Set up hidden sql - $hiddensql = ($view && has_capability('moodle/role:viewhiddenassigns', $context))? '':' AND ra.hidden = 0 '; + $hiddensql = ($view && !has_capability('moodle/role:viewhiddenassigns', $context))? ' AND ra.hidden = 0 ':''; /// If context is a course, then construct sql for ul if ($context->contextlevel == CONTEXT_COURSE) { @@ -3122,7 +3122,7 @@ function get_users_by_capability($context, $capability, $fields='', $sort='', * @param bool parent if true, get list of users assigned in higher context too * @return array() */ -function get_role_users($roleid, $context, $parent=false, $fields='', $sort='u.lastname ASC') { +function get_role_users($roleid, $context, $parent=false, $fields='', $sort='u.lastname ASC', $view=false) { global $CFG; if (empty($fields)) { @@ -3132,6 +3132,8 @@ function get_role_users($roleid, $context, $parent=false, $fields='', $sort='u.l 'u.emailstop, u.lang, u.timezone'; } + // whether this assignment is hidden + $hiddensql = ($view && !has_capability('moodle/role:viewhiddenassigns', $context))? ' AND r.hidden = 0 ':''; if ($parent) { if ($contexts = get_parent_contexts($context)) { $parentcontexts = ' OR r.contextid IN ('.implode(',', $contexts).')'; @@ -3153,6 +3155,7 @@ function get_role_users($roleid, $context, $parent=false, $fields='', $sort='u.l {$CFG->prefix}user u WHERE (r.contextid = $context->id $parentcontexts) AND u.id = r.userid $roleselect + $hiddensql ORDER BY $sort "; // join now so that we can just use fullname() later diff --git a/lib/adminlib.php b/lib/adminlib.php index 1766f8e861..0cf3b9fed6 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -2376,6 +2376,79 @@ class admin_setting_special_gradebookroles extends admin_setting { } +/* + * this is used in config->appearance->coursemanager + * (which roles to show on course decription page) + */ +class admin_setting_special_coursemanager extends admin_setting { + + function admin_setting_special_coursemanager() { + $name = 'coursemanager'; + $visiblename = get_string('coursemanager', 'admin'); + $description = get_string('configcoursemanager', 'admin'); + $default = array(3=>'1'); // The teahcer role in a default install + parent::admin_setting($name, $visiblename, $description, $default); + } + + function get_setting() { + + global $CFG; + if (!empty($CFG->{$this->name})) { + $result = explode(',', $CFG->{$this->name}); + foreach ($result as $roleid) { + $array[$roleid] = 1; + } + return $array; + } else { + return null; + } + } + + function write_setting($data) { + + if (!empty($data)) { + $str = ''; + foreach ($data as $key => $value) { + if ($value) { + $str .= $key.','; + } + } + return set_config($this->name, rtrim($str, ","))?'':get_string('errorsetting', 'admin') . $this->visiblename . '
'; + } else { + return set_config($this->name, '')?'':get_string('errorsetting', 'admin') . $this->visiblename . '
'; + } + } + + function output_html() { + + if ($this->get_setting() === NULL) { + $currentsetting = $this->defaultsetting; + } else { + $currentsetting = $this->get_setting(); + } + // from to process which roles to display + if ($roles = get_records('role')) { + $return = '
'; + $first = true; + foreach ($roles as $roleid=>$role) { + if (is_array($currentsetting) && in_array($roleid, array_keys($currentsetting))) { + $checked = 'checked="checked"'; + } else { + $checked = ''; + } + if ($first) { + $first = false; + } else { + $return .= '
'; + } + $return .= ' '.$role->name; + } + $return .= '
'; + } + return format_admin_setting($this->name, $this->visiblename, $return, $this->description); + } +} + class admin_setting_special_perfdebug extends admin_setting_configcheckbox { function admin_setting_special_perfdebug() { @@ -2386,6 +2459,7 @@ class admin_setting_special_perfdebug extends admin_setting_configcheckbox { } function write_setting($data) { + if ($data == '1') { return (set_config($this->name,15) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); } else { @@ -2394,6 +2468,7 @@ class admin_setting_special_perfdebug extends admin_setting_configcheckbox { } function output_html() { + if ($this->get_setting() === NULL) { $currentsetting = $this->defaultsetting; } else {