Commit 061e6b28 authored by sam marshall's avatar sam marshall
Browse files

MDL-44725 Availability: Replace groupmembersonly - upgrade, core (1)

* Upgrades existing data so that the groupmembersonly option is
  replaced with equivalent data for the new availability API.
* Removes the database field and admin setting used for
  groupmembersonly.
* Changes core modinfo library to remove/deprecate groupmembersonly
  data and functions.
* Changes other core library files to remove groupmembersonly
  references.

Includes deprecation of several functions, listed in lib/upgrade.txt.
parent 5474b8bf
......@@ -11,7 +11,6 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
//TODO: Re-enable cc-import once re-implemented in 2.0.x
//$temp->add(new admin_setting_configcheckbox('enableimsccimport', new lang_string('enable_cc_import', 'imscc'), new lang_string('enable_cc_import_description', 'imscc'), 0));
$temp->add(new admin_setting_configcheckbox('enablesafebrowserintegration', new lang_string('enablesafebrowserintegration', 'admin'), new lang_string('configenablesafebrowserintegration', 'admin'), 0));
$temp->add(new admin_setting_configcheckbox('enablegroupmembersonly', new lang_string('enablegroupmembersonly', 'admin'), new lang_string('configenablegroupmembersonly', 'admin'), 0));
$temp->add(new admin_setting_configcheckbox('dndallowtextandlinks', new lang_string('dndallowtextandlinks', 'admin'), new lang_string('configdndallowtextandlinks', 'admin'), 0));
// The CSS optimiser setting. When changed we need to reset the theme caches in order to ensure they are regenerated through the optimiser.
......
......@@ -996,7 +996,6 @@ function get_array_of_activities($courseid) {
// name - the name of the instance
// visible - is the instance visible or not
// groupingid - grouping id
// groupmembersonly - is this instance visible to group members only
// extra - contains extra string to include in any link
global $CFG, $DB;
if(!empty($CFG->enableavailability)) {
......@@ -1048,7 +1047,6 @@ function get_array_of_activities($courseid) {
$mod[$seq]->visibleold = $rawmods[$seq]->visibleold;
$mod[$seq]->groupmode = $rawmods[$seq]->groupmode;
$mod[$seq]->groupingid = $rawmods[$seq]->groupingid;
$mod[$seq]->groupmembersonly = $rawmods[$seq]->groupmembersonly;
$mod[$seq]->indent = $rawmods[$seq]->indent;
$mod[$seq]->completion = $rawmods[$seq]->completion;
$mod[$seq]->extra = "";
......@@ -1127,13 +1125,12 @@ function get_array_of_activities($courseid) {
$mod[$seq]->name = $DB->get_field($rawmods[$seq]->modname, "name", array("id"=>$rawmods[$seq]->instance));
}
// Minimise the database size by unsetting default options when they are
// 'empty'. This list corresponds to code in the cm_info constructor.
foreach (array('idnumber', 'groupmode', 'groupingid', 'groupmembersonly',
'indent', 'completion', 'extra', 'extraclasses', 'iconurl', 'onclick', 'content',
'icon', 'iconcomponent', 'customdata', 'availability',
'completionview', 'completionexpected', 'score', 'showdescription')
as $property) {
// Minimise the database size by unsetting default options when they are
// 'empty'. This list corresponds to code in the cm_info constructor.
foreach (array('idnumber', 'groupmode', 'groupingid',
'indent', 'completion', 'extra', 'extraclasses', 'iconurl', 'onclick', 'content',
'icon', 'iconcomponent', 'customdata', 'availability', 'completionview',
'completionexpected', 'score', 'showdescription') as $property) {
if (property_exists($mod[$seq], $property) &&
empty($mod[$seq]->{$property})) {
unset($mod[$seq]->{$property});
......
......@@ -201,7 +201,6 @@ class core_course_courselib_testcase extends advanced_testcase {
$moduleinfo->section = 1; // This is the section number in the course. Not the section id in the database.
$moduleinfo->course = $course->id;
$moduleinfo->groupingid = $grouping->id;
$moduleinfo->groupmembersonly = 0;
$moduleinfo->visible = true;
// Sometimes optional generic values for some modules.
......@@ -276,7 +275,6 @@ class core_course_courselib_testcase extends advanced_testcase {
$this->assertEquals($moduleinfo->section, $section->section);
$this->assertEquals($moduleinfo->course, $dbcm->course);
$this->assertEquals($moduleinfo->groupingid, $dbcm->groupingid);
$this->assertEquals($moduleinfo->groupmembersonly, $dbcm->groupmembersonly);
$this->assertEquals($moduleinfo->visible, $dbcm->visible);
$this->assertEquals($moduleinfo->completion, $dbcm->completion);
$this->assertEquals($moduleinfo->completionview, $dbcm->completionview);
......@@ -438,7 +436,6 @@ class core_course_courselib_testcase extends advanced_testcase {
$moduleinfo->modulename = $modulename;
$moduleinfo->course = $course->id;
$moduleinfo->groupingid = $grouping->id;
$moduleinfo->groupmembersonly = 0;
$moduleinfo->visible = true;
// Sometimes optional generic values for some modules.
......@@ -509,7 +506,6 @@ class core_course_courselib_testcase extends advanced_testcase {
$this->assertEquals($moduleinfo->modulename, $dbcm->modname);
$this->assertEquals($moduleinfo->course, $dbcm->course);
$this->assertEquals($moduleinfo->groupingid, $dbcm->groupingid);
$this->assertEquals($moduleinfo->groupmembersonly, $dbcm->groupmembersonly);
$this->assertEquals($moduleinfo->visible, $dbcm->visible);
$this->assertEquals($moduleinfo->completion, $dbcm->completion);
$this->assertEquals($moduleinfo->completionview, $dbcm->completionview);
......
......@@ -203,7 +203,6 @@ $string['configemailchangeconfirmation'] = 'Require an email confirmation step w
$string['configenablecalendarexport'] = 'Enable exporting or subscribing to calendars.';
$string['configenablecomments'] = 'Enable comments';
$string['configenablecourserequests'] = 'This will allow any user to request a course be created.';
$string['configenablegroupmembersonly'] = 'If enabled, access to activities can be restricted to group members only. This may result in an increased server load. In addition, gradebook categories must be set up in a certain way to ensure that activities are hidden from non-group members.';
$string['configenablemobilewebservice'] = 'Enable mobile service for the official Moodle app or other app requesting it. For more information, read the {$a}';
$string['configenablerssfeeds'] = 'If enabled, RSS feeds are generated by various features across the site, such as blogs, forums, database activities and glossaries. Note that RSS feeds also need to be enabled for the particular activity modules.';
$string['configenablerssfeedsdisabled'] = 'It is not available because RSS feeds are disabled in all the Site. To enable them, go to the Variables settings under Admin Configuration.';
......@@ -472,7 +471,6 @@ $string['enabled'] = 'Enabled';
$string['enabledevicedetection'] = 'Enable device detection';
$string['enablegravatar'] = 'Enable Gravatar';
$string['enablegravatar_help'] = 'When enabled Moodle will attempt to fetch a user profile picture from Gravatar if the user has not uploaded an image.';
$string['enablegroupmembersonly'] = 'Enable group members only';
$string['enablemobilewebservice'] = 'Enable web services for mobile devices';
$string['enablerecordcache'] = 'Enable record cache';
$string['enablerssfeeds'] = 'Enable RSS feeds';
......
......@@ -1442,7 +1442,7 @@ function get_coursemodules_in_course($modulename, $courseid, $extrafields='') {
* in the course. Returns an empty array on any errors.
*
* The returned objects includle the columns cw.section, cm.visible,
* cm.groupmode and cm.groupingid, cm.groupmembersonly, and are indexed by cm.id.
* cm.groupmode, and cm.groupingid, and are indexed by cm.id.
*
* @global object
* @global object
......@@ -1470,7 +1470,7 @@ function get_all_instances_in_courses($modulename, $courses, $userid=NULL, $incl
$params['modulename'] = $modulename;
if (!$rawmods = $DB->get_records_sql("SELECT cm.id AS coursemodule, m.*, cw.section, cm.visible AS visible,
cm.groupmode, cm.groupingid, cm.groupmembersonly
cm.groupmode, cm.groupingid
FROM {course_modules} cm, {course_sections} cw, {modules} md,
{".$modulename."} m
WHERE cm.course $coursessql AND
......@@ -1515,7 +1515,7 @@ function get_all_instances_in_courses($modulename, $courses, $userid=NULL, $incl
* in the course. Returns an empty array on any errors.
*
* The returned objects includle the columns cw.section, cm.visible,
* cm.groupmode and cm.groupingid, cm.groupmembersonly, and are indexed by cm.id.
* cm.groupmode, and cm.groupingid, and are indexed by cm.id.
*
* Simply calls {@link all_instances_in_courses()} with a single provided course
*
......@@ -1536,7 +1536,7 @@ function get_all_instances_in_course($modulename, $course, $userid=NULL, $includ
*
* Given a valid module object with info about the id and course,
* and the module's type (eg "forum") returns whether the object
* is visible or not, groupmembersonly visibility not tested
* is visible or not according to the 'eye' icon only.
*
* NOTE: This does NOT take into account visibility to a particular user.
* To get visibility access for a specific user, use get_fast_modinfo, get a
......@@ -1554,7 +1554,7 @@ function instance_is_visible($moduletype, $module) {
if (!empty($module->id)) {
$params = array('courseid'=>$module->course, 'moduletype'=>$moduletype, 'moduleid'=>$module->id);
if ($records = $DB->get_records_sql("SELECT cm.instance, cm.visible, cm.groupingid, cm.id, cm.groupmembersonly, cm.course
if ($records = $DB->get_records_sql("SELECT cm.instance, cm.visible, cm.groupingid, cm.id, cm.course
FROM {course_modules} cm, {modules} m
WHERE cm.course = :courseid AND
cm.module = m.id AND
......
......@@ -293,7 +293,6 @@
<FIELD NAME="visibleold" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
<FIELD NAME="groupmode" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="groupingid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="groupmembersonly" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="only members of any group are allowed to access the activity"/>
<FIELD NAME="completion" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Whether the completion-tracking facilities are enabled for this activity. 0 = not enabled (database default) 1 = manual tracking, user can tick this activity off (UI default for most activity types) 2 = automatic tracking, system should mark completion according to rules specified in course_moduleS_completion"/>
<FIELD NAME="completiongradeitemnumber" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="Grade-item number used to track automatic completion, if applicable."/>
<FIELD NAME="completionview" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Controls whether a page view is part of the automatic completion requirements for this activity. 0 = view not required 1 = view required"/>
......
......@@ -3743,5 +3743,52 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2014082900.01);
}
if ($oldversion < 2014082900.02) {
// Replace groupmembersonly usage with new availability system.
$transaction = $DB->start_delegated_transaction();
if ($CFG->enablegroupmembersonly) {
// If it isn't already enabled, we need to enable availability.
if (!$CFG->enableavailability) {
set_config('enableavailability', 1);
}
// Count all course-modules with groupmembersonly set (for progress
// bar).
$total = $DB->count_records('course_modules', array('groupmembersonly' => 1));
$pbar = new progress_bar('upgradegroupmembersonly', 500, true);
// Get all these course-modules, one at a time.
$rs = $DB->get_recordset('course_modules', array('groupmembersonly' => 1),
'course, id');
$i = 0;
foreach ($rs as $cm) {
// Calculate and set new availability value.
$availability = upgrade_group_members_only($cm->groupingid, $cm->availability);
$DB->set_field('course_modules', 'availability', $availability,
array('id' => $cm->id));
// Update progress.
$i++;
$pbar->update($i, $total, "Upgrading groupmembersonly settings - $i/$total.");
}
$rs->close();
}
// Define field groupmembersonly to be dropped from course_modules.
$table = new xmldb_table('course_modules');
$field = new xmldb_field('groupmembersonly');
// Conditionally launch drop field groupmembersonly.
if ($dbman->field_exists($table, $field)) {
$dbman->drop_field($table, $field);
}
// Unset old config variable.
unset_config('enablegroupmembersonly');
$transaction->allow_commit();
upgrade_main_savepoint(true, 2014082900.02);
}
return true;
}
......@@ -457,6 +457,60 @@ function upgrade_availability_item($groupmembersonly, $groupingid,
}
}
/**
* Using data for a single course-module that has groupmembersonly enabled,
* returns the new availability value that incorporates the correct
* groupmembersonly option.
*
* Included as a function so that it can be shared between upgrade and restore,
* and unit-tested.
*
* @param int $groupingid Grouping id for the course-module (0 if none)
* @param string $availability Availability JSON data for the module (null if none)
* @return string New value for availability for the module
*/
function upgrade_group_members_only($groupingid, $availability) {
// Work out the new JSON object representing this option.
if ($groupingid) {
// Require specific grouping.
$condition = (object)array('type' => 'grouping', 'id' => (int)$groupingid);
} else {
// No grouping specified, so require membership of any group.
$condition = (object)array('type' => 'group');
}
if (is_null($availability)) {
// If there are no conditions using the new API then just set it.
$tree = (object)array('op' => '&', 'c' => array($condition), 'showc' => array(false));
} else {
// There are existing conditions.
$tree = json_decode($availability);
switch ($tree->op) {
case '&' :
// For & conditions we can just add this one.
$tree->c[] = $condition;
$tree->showc[] = false;
break;
case '!|' :
// For 'not or' conditions we can add this one
// but negated.
$tree->c[] = (object)array('op' => '!&', 'c' => array($condition));
$tree->showc[] = false;
break;
default:
// For the other two (OR and NOT AND) we have to add
// an extra level to the tree.
$tree = (object)array('op' => '&', 'c' => array($tree, $condition),
'showc' => array($tree->show, false));
// Inner trees do not have a show option, so remove it.
unset($tree->c[0]->show);
break;
}
}
return json_encode($tree);
}
/**
* Updates the mime-types for files that exist in the database, based on their
* file extension.
......
......@@ -956,6 +956,53 @@ function get_current_group($courseid, $full = false) {
}
}
/**
* Filter a user list and return only the users that can see the course module based on
* groups/permissions etc. It is assumed that the users are pre-filtered to those who are enrolled in the course.
*
* @category group
* @param stdClass|cm_info $cm The course module
* @param array $users An array of users, indexed by userid
* @return array A filtered list of users that can see the module, indexed by userid.
* @deprecated Since Moodle 2.8
*/
function groups_filter_users_by_course_module_visible($cm, $users) {
debugging('groups_filter_users_by_course_module_visible() is deprecated. ' .
'Replace with a call to \core_availability\info_module::filter_user_list(), ' .
'which does basically the same thing but includes other restrictions such ' .
'as profile restrictions.', DEBUG_DEVELOPER);
if (empty($users)) {
return $users;
}
// Since this function allows stdclass, let's play it safe and ensure we
// do have a cm_info.
if (!($cm instanceof cm_info)) {
$modinfo = get_fast_modinfo($cm->course);
$cm = $modinfo->get_cm($cm->id);
}
$info = new \core_availability\info_module($cm);
return $info->filter_user_list($users);
}
/**
* Determine if a course module is currently visible to a user
*
* Deprecated (it was never very useful as it only took into account the
* groupmembersonly option and no other way of hiding activities). Always
* returns true.
*
* @category group
* @param stdClass|cm_info $cm The course module
* @param int $userid The user to check against the group.
* @return bool True
* @deprecated Since Moodle 2.8
*/
function groups_course_module_visible($cm, $userid=null) {
debugging('groups_course_module_visible() is deprecated and always returns ' .
'true; use $cm->uservisible to decide whether the current user can ' .
'access an activity.', DEBUG_DEVELOPER);
return true;
}
/**
* Inndicates fatal error. This function was originally printing the
......
......@@ -848,108 +848,6 @@ function groups_get_activity_allowed_groups($cm,$userid=0) {
}
}
/**
* Filter a user list and return only the users that can see the course module based on
* groups/permissions etc. It is assumed that the users are pre-filtered to those who are enrolled in the course.
*
* @category group
* @param stdClass $cm The course module
* @param array $users An array of users, indexed by userid
* @return array A filtered list of users that can see the module, indexed by userid.
*/
function groups_filter_users_by_course_module_visible($cm, $users) {
global $CFG, $DB;
if (empty($users)) {
return $users;
}
if (empty($CFG->enablegroupmembersonly)) {
return $users;
}
if (empty($cm->groupmembersonly)) {
return $users;
}
list($usql, $uparams) = $DB->get_in_or_equal(array_keys($users), SQL_PARAMS_NAMED, 'userid', true);
// Group membership sub-query.
if ($cm->groupingid) {
// Find out if member of any group in selected activity grouping.
$igsql = "SELECT gm.userid
FROM {groups_members} gm
LEFT JOIN {groupings_groups} gg
ON gm.groupid = gg.groupid
WHERE gm.userid $usql AND gg.groupingid = :groupingid";
$igparams = array_merge($uparams, array('groupingid' => $cm->groupingid));
} else {
// No grouping used - check all groups in course.
$igsql = "SELECT gm.userid
FROM {groups_members} gm
LEFT JOIN {groups} g
ON gm.groupid = g.id
WHERE gm.userid $usql AND g.courseid = :courseid";
$igparams = array_merge($uparams, array('courseid' => $cm->course));
}
$context = context_module::instance($cm->id);
// Get the list of users in a valid group.
$usersingroup = $DB->get_records_sql($igsql, $igparams);
if (!$usersingroup) {
$usersingroup = array();
} else {
$usersingroup = array_keys($usersingroup);
}
// Get the list of users who can access all groups.
list($accessallgroupssql, $accessallgroupsparams) = get_enrolled_sql($context, 'moodle/site:accessallgroups');
$userswithaccessallgroups = $DB->get_records_sql($accessallgroupssql, $accessallgroupsparams);
if (!$userswithaccessallgroups) {
$userswithaccessallgroups = array();
} else {
$userswithaccessallgroups = array_keys($userswithaccessallgroups);
}
// Explaining this array mangling:
// $users is an array of $user[$userid] => stdClass etc
// $userswithaccessallgroups is an array of $userswithaccessallgroups[random int] = $userid
// $usersingroup is an array of $usersingroup[random int] = $userid
// so - the inner array_merge combines the values of the 2 arrays disregarding the keys (because they are ints)
// this is then flipped so the values become the keys (and the values are now nonsense)
// this is then intersected with the users array only by looking at the keys - this
// returns only the users from the original array that had a value in one of the two $usersxxx lists.
return array_intersect_key($users, array_flip(array_merge($userswithaccessallgroups, $usersingroup)));
}
/**
* Determine if a course module is currently visible to a user
*
* $USER If $userid is null, use the global object.
*
* @category group
* @param stdClass|cm_info $cm The course module
* @param int $userid The user to check against the group.
* @return bool True if the user can view the course module, false otherwise.
*/
function groups_course_module_visible($cm, $userid=null) {
global $CFG, $USER;
if (empty($userid)) {
$userid = $USER->id;
}
if (empty($CFG->enablegroupmembersonly)) {
return true;
}
if (empty($cm->groupmembersonly)) {
return true;
}
if (has_capability('moodle/site:accessallgroups', context_module::instance($cm->id), $userid) or groups_has_membership($cm, $userid)) {
return true;
}
return false;
}
/**
* Determine if a given group is visible to user or not in a given context.
*
......
......@@ -704,9 +704,6 @@ class course_modinfo {
* @property-read int $groupmode Group mode (one of the constants NOGROUPS, SEPARATEGROUPS, or VISIBLEGROUPS) - from
* course_modules table. Use {@link cm_info::$effectivegroupmode} to find the actual group mode that may be forced by course.
* @property-read int $groupingid Grouping ID (0 = all groupings)
* @property-read int $groupmembersonly Group members only (if set to 1, only members of a suitable group see this link on the
* course page; 0 = everyone sees it even if they don't belong to a suitable group) - from
* course_modules table
* @property-read bool $coursegroupmodeforce Indicates whether the course containing the module has forced the groupmode
* This means that cm_info::$groupmode should be ignored and cm_info::$coursegroupmode be used instead
* @property-read int $coursegroupmode Group mode (one of the constants NOGROUPS, SEPARATEGROUPS, or VISIBLEGROUPS) - from
......@@ -864,14 +861,6 @@ class cm_info implements IteratorAggregate {
*/
private $groupingid;
/**
* Group members only (if set to 1, only members of a suitable group see this link on the
* course page; 0 = everyone sees it even if they don't belong to a suitable group) - from
* course_modules table
* @var int
*/
private $groupmembersonly;
/**
* Indent level on course page (0 = no indent) - from course_modules table
* @var int
......@@ -1093,7 +1082,7 @@ class cm_info implements IteratorAggregate {
'effectivegroupmode' => 'get_effective_groupmode',
'extra' => false,
'groupingid' => false,
'groupmembersonly' => false,
'groupmembersonly' => 'get_deprecated_group_members_only',
'groupmode' => false,
'icon' => false,
'iconcomponent' => false,
......@@ -1520,7 +1509,7 @@ class cm_info implements IteratorAggregate {
// Standard fields from table course_modules.
static $cmfields = array('id', 'course', 'module', 'instance', 'section', 'idnumber', 'added',
'score', 'indent', 'visible', 'visibleold', 'groupmode', 'groupingid', 'groupmembersonly',
'score', 'indent', 'visible', 'visibleold', 'groupmode', 'groupingid',
'completion', 'completiongradeitemnumber', 'completionview', 'completionexpected',
'showdescription', 'availability');
foreach ($cmfields as $key) {
......@@ -1699,7 +1688,6 @@ class cm_info implements IteratorAggregate {
$this->sectionnum = $mod->section; // Note weirdness with name here
$this->groupmode = isset($mod->groupmode) ? $mod->groupmode : 0;
$this->groupingid = isset($mod->groupingid) ? $mod->groupingid : 0;
$this->groupmembersonly = isset($mod->groupmembersonly) ? $mod->groupmembersonly : 0;
$this->indent = isset($mod->indent) ? $mod->indent : 0;
$this->extra = isset($mod->extra) ? $mod->extra : '';
$this->extraclasses = isset($mod->extraclasses) ? $mod->extraclasses : '';
......@@ -1871,9 +1859,25 @@ class cm_info implements IteratorAggregate {
return 0;
}
/**
* Getter method for $availablefrom and $availableuntil. Just returns zero
* as these are no longer supported.
*
* @return int Zero
* @deprecated Since Moodle 2.8
*/
private function get_deprecated_group_members_only() {
debugging('$cm->groupmembersonly has been deprecated and always returns zero. ' .
'If used to restrict a list of enrolled users to only those who can ' .
'access the module, consider \core_availability\info_module::filter_user_list.',
DEBUG_DEVELOPER);
return 0;
}
/**
* Getter method for property $availableinfo, ensures that dynamic data is retrieved
* @return type
*
* @return string Available info (HTML)
*/
private function get_available_info() {
$this->obtain_dynamic_data();
......@@ -1885,7 +1889,6 @@ class cm_info implements IteratorAggregate {
*
* If the activity is unavailable, additional checks are required to determine if its hidden or greyed out
*
* @see is_user_access_restricted_by_group()
* @see is_user_access_restricted_by_conditional_access()
* @return void
*/
......@@ -1905,8 +1908,7 @@ class cm_info implements IteratorAggregate {
}
// Check group membership.
if ($this->is_user_access_restricted_by_group() ||
$this->is_user_access_restricted_by_capability()) {
if ($this->is_user_access_restricted_by_capability()) {
$this->uservisible = false;
// Ensure activity is completely hidden from the user.
......@@ -1915,27 +1917,19 @@ class cm_info implements IteratorAggregate {
}
/**
* Checks whether the module's group settings restrict the current user's access
* Checks whether the module's group settings restrict the current user's
* access. This function is not necessary now that all access restrictions
* are handled by the availability API. You can use $cm->uservisible to
* find out if the current user can access an activity, or $cm->availableinfo
* to get information about why not.
*
* @return bool True if the user access is restricted
* @return bool False
* @deprecated Since Moodle 2.8
*/
public function is_user_access_restricted_by_group() {
global $CFG;
if (!empty($CFG->enablegroupmembersonly) and !empty($this->groupmembersonly)) {
$userid = $this->modinfo->get_user_id();
if ($userid == -1) {
return null;
}
if (!has_capability('moodle/site:accessallgroups', $this->get_context(), $userid)) {
// If the activity has 'group members only' and you don't have accessallgroups...
$groups = $this->modinfo->get_groups($this->groupingid);
if (empty($groups)) {
// ...and you don't belong to a group, then set it so you can't see/access it
return true;
}
}
}
debugging('cm_info::is_user_access_restricted_by_group() ' .
'is deprecated and always returns false; use $cm->uservisible ' .
'to decide whether the current user can access an activity', DEBUG_DEVELOPER);
return false;
}
......@@ -1976,7 +1970,7 @@ class cm_info implements IteratorAggregate {
global $CFG;
debugging('cm_info::is_user_access_restricted_by_conditional_access() ' .
'is deprecated; this function is not needed (use $cm->uservisible ' .
'and $cm->availableinfo) to decide whether it should be available ' .
'and $cm->availableinfo to decide whether it should be available ' .
'or appear)', DEBUG_DEVELOPER);
if (empty($CFG->enableavailability)) {
......
......@@ -414,7 +414,10 @@ define('FEATURE_IDNUMBER', 'idnumber');
define('FEATURE_GROUPS', 'groups');
/** True if module supports groupings */
define('FEATURE_GROUPINGS', 'groupings');
/** True if module supports groupmembersonly */
/**
* True if module supports groupmembersonly (which no longer exists)
* @deprecated Since Moodle 2.8
*/
define('FEATURE_GROUPMEMBERSONLY', 'groupmembersonly');
/** Type of module */
......@@ -3134,7 +3137,7 @@ function require_login($courseorid = null, $autologinguest = true, $cm = null, $
}
}
// Check visibility of activity to current user; includes visible flag, groupmembersonly, conditional availability, etc.
// Check visibility of activity to current user; includes visible flag, conditional availability, etc.
if ($cm && !$cm->uservisible) {
if ($preventredirect) {
throw new require_login_exception('Activity is hidden');
......
......@@ -174,7 +174,7 @@ abstract class testing_module_generator extends component_generator_base {
// argument $options is being deprecated.
// List excludes fields: instance (does not exist yet), course, module and idnumber (set above)
$easymergefields = array('section', 'added', 'score', 'indent',
'visible', 'visibleold', 'groupmode', 'groupingid', 'groupmembersonly',
'visible', 'visibleold', 'groupmode', 'groupingid',
'completion', 'completiongradeitemnumber', 'completionview', 'completionexpected',
'availability', 'showdescription');
foreach ($easymergefields as $key) {
......@@ -190,7 +190,6 @@ abstract class testing_module_generator extends component_generator_base {
'cmidnumber' => '',
'groupmode' => 0,
'groupingid' => 0,
'groupmembersonly' => 0,
'availability' => null,
'completion' => 0,
'completionview' => 0,
......
......@@ -131,7 +131,6 @@ class core_test_generator_testcase extends advanced_testcase {
// Enable advanced functionality.
$CFG->enablecompletion = 1;
$CFG->enableavailability = 1;
$CFG->enablegroupmembersonly = 1;
$CFG->enableoutcomes = 1;
require_once($CFG->libdir.'/gradelib.php');
require_once($CFG->libdir.'/completionlib.php');
......@@ -163,8 +162,6 @@ class core_test_generator_testcase extends advanced_testcase {
'groupmode' => SEPARATEGROUPS, // Note: will be reset to 0 if course groupmodeforce is set.
// Module supports FEATURE_GROUPINGS or module supports FEATURE_GROUPMEMBERSONLY:
'groupingid' => $grouping->id,
// Module supports FEATURE_GROUPMEMBERSONLY: