コード例 #1
0
ファイル: groupinglib.php プロジェクト: veritech/pare-project
/**
 * Gets the users for the course who are not in any group of a grouping.
 * @param int $courseid The id of the course
 * @param int $groupingid The id of the grouping
 * @param int $groupid Excludes members of a particular group
 * @return array An array of the userids of the users not in any group of 
 * the grouping or false if an error occurred. 
 */
function groups_get_users_not_in_any_group_in_grouping($courseid, $groupingid, $groupid = false)
{
    $users = get_course_users($courseid);
    $userids = groups_users_to_userids($users);
    $nongroupmembers = array();
    if (!$userids) {
        return $nongroupmembers;
    }
    foreach ($userids as $userid) {
        if (!groups_is_member_of_some_group_in_grouping($userid, $groupingid)) {
            // If a group has been specified don't include members of that group
            if ($groupid and !groups_is_member($userid, $groupid)) {
                array_push($nongroupmembers, $userid);
            } else {
                ///array_push($nongroupmembers, $userid);
            }
        }
    }
    return $nongroupmembers;
}
コード例 #2
0
ファイル: modulelib.php プロジェクト: veritech/pare-project
/**
 * Indicates if a specified user has a particular type of permission for a 
 * particular group for this module instance.
 * @uses $USER      
 * @param int $cmid The id of the module instance. This is necessary because the 
 * same group can be used in different module instances with different 
 * permission setups. 
 * @param int $groupid The id of the group
 * @param int $permissiontype The permission type - see note on permission types 
 * above
 * @userid int $userid The id of the user, defaults to the current user
 * @return boolean True if the user has the specified permission type, false 
 * otherwise or if an error occurred. 
 */
function groups_m_has_permission($cm, $groupid, $permissiontype, $userid = null)
{
    if (!$userid) {
        global $USER;
        $userid = $USER->id;
    }
    $groupingid = groups_get_grouping_for_coursemodule($cm);
    if (!$groupingid || !is_object($cm) || !isset($cm->course)) {
        return false;
    }
    $courseid = $cm->course;
    $isstudent = isstudent($courseid, $userid);
    $isteacher = isteacher($courseid, $userid);
    $groupmember = groups_is_member($groupid, $userid);
    $memberofsomegroup = groups_is_member_of_some_group_in_grouping($userid, $groupingid);
    $groupingsettings = groups_get_grouping_settings($groupingid);
    $viewowngroup = $groupingsettings->viewowngroup;
    $viewallgroupsmembers = $groupingsettings->viewallgroupmembers;
    $viewallgroupsactivities = $groupingsettings->viewallgroupsactivities;
    $teachersgroupsmark = $groupingsettings->teachersgroupsmark;
    $teachersgroupsview = $groupingsettings->teachersgroupsview;
    $teachersgroupmark = $groupingsettings->teachersgroupmark;
    $teachersgroupview = $groupingsettings->teachersgroupview;
    $teachersoverride = $groupingsettings->teachersoverride;
    $permission = false;
    switch ($permissiontype) {
        case 'view':
            if ($isstudent and $groupmember or $isteacher and $groupmember or $isstudent and $viewallgroupsactivities or $isteacher and !$teachersgroupview or $isteacher and !$memberofsomegroup and $teachersoverride) {
                $permission = true;
            }
            break;
        case 'studentcontribute':
            if ($isstudent and $groupmember or $isteacher and $groupmember or $isteacher and !$memberofsomegroup and $teachersoverride) {
                $permission = true;
            }
            break;
        case 'teachermark':
            if ($isteacher and $groupmember or $isteacher and !$teachersgroupmark or $isteacher and !$memberofsomegroup and $teachersoverride) {
                $permission = true;
            }
            break;
        case 'viewmembers':
            if ($isstudent and $groupmember and $viewowngroup or $isstudent and $viewallgroupsmembers or $isteacher and $groupmember or $isteacher and !$teachersgroupview or $isteacher and !$memberofsomegroup and $teachersoverride or $isteacheredit) {
                $permission = true;
            }
            break;
    }
    return $permission;
}