本文整理匯總了PHP中course_modinfo::get_groups方法的典型用法代碼示例。如果您正苦於以下問題:PHP course_modinfo::get_groups方法的具體用法?PHP course_modinfo::get_groups怎麽用?PHP course_modinfo::get_groups使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類course_modinfo
的用法示例。
在下文中一共展示了course_modinfo::get_groups方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: update_user_visible
/**
* Works out whether activity is visible *for current user* - if this is false, they
* aren't allowed to access it.
* @return void
*/
private function update_user_visible()
{
global $CFG;
$modcontext = get_context_instance(CONTEXT_MODULE, $this->id);
$userid = $this->modinfo->get_user_id();
$this->uservisible = true;
if ((!$this->visible or !$this->available) and !has_capability('moodle/course:viewhiddenactivities', $modcontext, $userid)) {
// If the activity is hidden or unavailable, and you don't have viewhiddenactivities,
// set it so that user can't see or access it
$this->uservisible = false;
} else {
if (!empty($CFG->enablegroupmembersonly) and !empty($this->groupmembersonly) and !has_capability('moodle/site:accessallgroups', $modcontext, $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
$this->uservisible = false;
}
}
}
}
示例2: is_user_access_restricted_by_group
/**
* Checks whether the module's group settings restrict the current user's access
*
* @return bool True if the user access is restricted
*/
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;
}
}
}
return false;
}
示例3: update_user_visible
/**
* Works out whether activity is visible *for current user* - if this is false, they
* aren't allowed to access it.
* @return void
*/
private function update_user_visible()
{
global $CFG;
$modcontext = get_context_instance(CONTEXT_MODULE, $this->id);
$userid = $this->modinfo->get_user_id();
$this->uservisible = true;
// Check visibility/availability conditions.
if ((!$this->visible or !$this->available) and !has_capability('moodle/course:viewhiddenactivities', $modcontext, $userid)) {
// If the activity is hidden or unavailable, and you don't have viewhiddenactivities,
// set it so that user can't see or access it.
$this->uservisible = false;
}
// Check group membership. The grouping option makes the activity
// completely invisible as it does not apply to the user at all.
if (!empty($CFG->enablegroupmembersonly) and !empty($this->groupmembersonly) and !has_capability('moodle/site:accessallgroups', $modcontext, $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
$this->uservisible = false;
// Ensure activity is completely hidden from user.
$this->showavailability = 0;
}
}
}