当前位置: 首页>>代码示例>>PHP>>正文


PHP get_roles_used_in_context函数代码示例

本文整理汇总了PHP中get_roles_used_in_context函数的典型用法代码示例。如果您正苦于以下问题:PHP get_roles_used_in_context函数的具体用法?PHP get_roles_used_in_context怎么用?PHP get_roles_used_in_context使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_roles_used_in_context函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: definition

 protected function definition()
 {
     global $CFG, $DB;
     $collection = $this->_customdata['collection'];
     $context = $this->_customdata['context'];
     $mform = $this->_form;
     // Text search box.
     $mform->addElement('text', 'search', get_string('search'));
     $mform->setType('search', PARAM_TEXT);
     $options = array(\mod_mediagallery\base::TYPE_ALL => get_string('typeall', 'mediagallery'), \mod_mediagallery\base::TYPE_IMAGE => get_string('typeimage', 'mediagallery'), \mod_mediagallery\base::TYPE_VIDEO => get_string('typevideo', 'mediagallery'), \mod_mediagallery\base::TYPE_AUDIO => get_string('typeaudio', 'mediagallery'));
     $mform->addElement('select', 'type', get_string('mediatype', 'mediagallery'), $options);
     // Role select dropdown includes all roles, but using course-specific
     // names if applied. The reason for not restricting to roles that can
     // be assigned at course level is that upper-level roles display in the
     // enrolments table so it makes sense to let users filter by them.
     $rolenames = role_fix_names(get_profile_roles($context), $context, ROLENAME_ALIAS, true);
     if (!empty($CFG->showenrolledusersrolesonly)) {
         $rolenames = role_fix_names(get_roles_used_in_context($context));
     }
     $mform->addElement('select', 'role', get_string('role'), array(0 => get_string('all')) + $rolenames);
     // Filter by group.
     $allgroups = groups_get_all_groups($collection->course);
     $groupsmenu[0] = get_string('allparticipants');
     foreach ($allgroups as $gid => $unused) {
         $groupsmenu[$gid] = $allgroups[$gid]->name;
     }
     if (count($groupsmenu) > 1) {
         $mform->addElement('select', 'group', get_string('group'), $groupsmenu);
     }
     // Submit button does not use add_action_buttons because that adds
     // another fieldset which causes the CSS style to break in an unfixable
     // way due to fieldset quirks.
     $group = array();
     $group[] = $mform->createElement('submit', 'submitbutton', get_string('filter'));
     $group[] = $mform->createElement('submit', 'resetbutton', get_string('reset'));
     $group[] = $mform->createElement('submit', 'exportbutton', get_string('exportascsv', 'mediagallery'));
     $mform->addGroup($group, 'buttons', '', ' ', false);
     $mform->addElement('hidden', 'id', $context->instanceid);
     $mform->setType('id', PARAM_INT);
     $mform->addElement('hidden', 'action', 'search');
     $mform->setType('action', PARAM_ALPHA);
 }
开发者ID:eSrem,项目名称:moodle-mod_mediagallery,代码行数:42,代码来源:search.php

示例2: _wwassignment_get_course_students

/**
* @desc Finds all of the users in the course
* @param $courseid   -- the course id
* @return record containing user information ( username, userid)
*/
function _wwassignment_get_course_students($courseid)
{
    debugLog("Begin get_course_students({$courseid} )");
    debugLog("courseID is " . print_r($courseid, true));
    $context = get_context_instance(CONTEXT_COURSE, $courseid);
    debugLog("context is " . print_r($context, true));
    $users = array();
    $roles_used_in_context = get_roles_used_in_context($context);
    //debugLog("roles used ". print_r($roles_used_in_context, true));
    foreach ($roles_used_in_context as $role) {
        $roleid = $role->id;
        debugLog("roleid should be 5 for a student {$roleid}");
        //debugLog(get_role_users($roleid, $context, true) );
        if ($new_users = get_role_users($roleid, $context, true)) {
            $users = array_merge($users, $new_users);
            //FIXME a user could be liseted twice
        }
        debugLog("display users " . print_r($users, true));
    }
    debugLog("display users in course--on");
    debugLog("users again" . print_r($users, true));
    debugLog("End get_course_students({$courseid} )");
    return $users;
}
开发者ID:bjornbe,项目名称:wwassignment,代码行数:29,代码来源:locallib.php

示例3: test_get_roles_used_in_context

 /**
  * Test used role query.
  */
 public function test_get_roles_used_in_context()
 {
     global $DB;
     $this->resetAfterTest();
     $systemcontext = context_system::instance();
     $teacherrole = $DB->get_record('role', array('shortname' => 'editingteacher'), '*', MUST_EXIST);
     $course = $this->getDataGenerator()->create_course();
     $coursecontext = context_course::instance($course->id);
     $otherid = create_role('Other role', 'other', 'Some other role', '');
     $teacherrename = (object) array('roleid' => $teacherrole->id, 'name' => 'Učitel', 'contextid' => $coursecontext->id);
     $DB->insert_record('role_names', $teacherrename);
     $otherrename = (object) array('roleid' => $otherid, 'name' => 'Ostatní', 'contextid' => $coursecontext->id);
     $DB->insert_record('role_names', $otherrename);
     $user1 = $this->getDataGenerator()->create_user();
     role_assign($teacherrole->id, $user1->id, $coursecontext->id);
     $roles = get_roles_used_in_context($coursecontext);
     $this->assertCount(1, $roles);
     $role = reset($roles);
     $roleid = key($roles);
     $this->assertEquals($roleid, $role->id);
     $this->assertEquals($teacherrole->id, $role->id);
     $this->assertSame($teacherrole->name, $role->name);
     $this->assertSame($teacherrole->shortname, $role->shortname);
     $this->assertEquals($teacherrole->sortorder, $role->sortorder);
     $this->assertSame($teacherrename->name, $role->coursealias);
     $user2 = $this->getDataGenerator()->create_user();
     role_assign($teacherrole->id, $user2->id, $systemcontext->id);
     role_assign($otherid, $user2->id, $systemcontext->id);
     $roles = get_roles_used_in_context($systemcontext);
     $this->assertCount(2, $roles);
 }
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:34,代码来源:accesslib_test.php

示例4: groups_get_potential_members

/**
 * Gets potential group members for grouping
 * @param int $courseid The id of the course
 * @param int $roleid The role to select users from
 * @param string $orderby The colum to sort users by
 * @return array An array of the users
 */
function groups_get_potential_members($courseid, $roleid = null, $orderby = 'lastname,firstname')
{
    global $CFG;
    $context = get_context_instance(CONTEXT_COURSE, $courseid);
    $sitecontext = get_context_instance(CONTEXT_SYSTEM);
    $rolenames = array();
    $avoidroles = array();
    if ($roles = get_roles_used_in_context($context, true)) {
        $canviewroles = get_roles_with_capability('moodle/course:view', CAP_ALLOW, $context);
        $doanythingroles = get_roles_with_capability('moodle/site:doanything', CAP_ALLOW, $sitecontext);
        foreach ($roles as $role) {
            if (!isset($canviewroles[$role->id])) {
                // Avoid this role (eg course creator)
                $avoidroles[] = $role->id;
                unset($roles[$role->id]);
                continue;
            }
            if (isset($doanythingroles[$role->id])) {
                // Avoid this role (ie admin)
                $avoidroles[] = $role->id;
                unset($roles[$role->id]);
                continue;
            }
            $rolenames[$role->id] = strip_tags(role_get_name($role, $context));
            // Used in menus etc later on
        }
    }
    $select = 'SELECT u.id, u.username, u.firstname, u.lastname, u.idnumber ';
    $from = "FROM {$CFG->prefix}user u INNER JOIN\n               {$CFG->prefix}role_assignments r on u.id=r.userid ";
    if ($avoidroles) {
        $adminroles = 'AND r.roleid NOT IN (';
        $adminroles .= implode(',', $avoidroles);
        $adminroles .= ')';
    } else {
        $adminroles = '';
    }
    // we are looking for all users with this role assigned in this context or higher
    if ($usercontexts = get_parent_contexts($context)) {
        $listofcontexts = '(' . implode(',', $usercontexts) . ')';
    } else {
        $listofcontexts = '(' . $sitecontext->id . ')';
        // must be site
    }
    if ($roleid) {
        $selectrole = " AND r.roleid = {$roleid} ";
    } else {
        $selectrole = " ";
    }
    $where = "WHERE (r.contextid = {$context->id} OR r.contextid in {$listofcontexts})\n                     AND u.deleted = 0 {$selectrole}\n                     AND u.username != 'guest'\n                     {$adminroles} ";
    $order = "ORDER BY {$orderby} ";
    return get_records_sql($select . $from . $where . $order);
}
开发者ID:nadavkav,项目名称:MoodleTAO,代码行数:59,代码来源:lib.php

示例5: array

$alternates = $DB->get_records_menu('block_clampmail_alternate', $alt_params, '', 'id, address');
$blockname = clampmail::_s('pluginname');
$header = clampmail::_s('email');
$PAGE->set_context($context);
$PAGE->set_course($course);
$PAGE->navbar->add($blockname);
$PAGE->navbar->add($header);
$PAGE->set_title($blockname . ': ' . $header);
$PAGE->set_heading($blockname . ': ' . $header);
$PAGE->set_url('/course/view.php', array('courseid' => $courseid));
$PAGE->set_pagetype($blockname);
$PAGE->set_pagelayout('standard');
$PAGE->requires->js('/blocks/clampmail/js/jquery.js');
$PAGE->requires->js('/blocks/clampmail/js/selection.js');
// Build role arrays.
$course_roles = get_roles_used_in_context($context);
$filter_roles = $DB->get_records_select('role', sprintf('id IN (%s)', $config['roleselection']));
$roles = clampmail::filter_roles($course_roles, $filter_roles);
// Add role names.
foreach ($roles as $id => $role) {
    if (empty($role->name)) {
        $roles[$id]->name = role_get_name($role, $context);
    }
}
$allgroups = groups_get_all_groups($courseid);
$mastercap = true;
$groups = $allgroups;
if (!has_capability('moodle/site:accessallgroups', $context)) {
    $mastercap = false;
    $mygroups = groups_get_user_groups($courseid);
    $gids = implode(',', array_values($mygroups['0']));
开发者ID:sryder,项目名称:clampmail,代码行数:31,代码来源:email.php

示例6: optional_param

$praxeaction = optional_param('praxeaction', null, PARAM_ALPHAEXT);
/// extra praxe action ///
if (!is_null($praxeaction)) {
    require_once $CFG->dirroot . '/mod/praxe/praxeaction.php';
}
/// rights to all actions in this module ///
if (has_capability('mod/praxe:manageallincourse', $context) || has_capability('mod/praxe:assignselftoinspection', $context)) {
    $viewrole = 'EDITTEACHER';
    $role_title = get_string('teacher', 'praxe');
    /// rights to create or manage own record of praxe - for students ///
} else {
    if (has_capability('mod/praxe:editownrecord', $context)) {
        $viewrole = 'STUDENT';
        $role_title = get_string('student', 'praxe');
    } else {
        foreach (get_roles_used_in_context($context) as $role) {
            if (user_has_role_assignment($USER->id, $role->id, $context->id)) {
                if ($role->shortname == 'extheadmaster') {
                    $viewrole = 'HEADM';
                    $role_title = get_string('headmaster', 'praxe');
                } else {
                    if ($role->shortname == 'extteacher') {
                        $viewrole = 'EXTTEACHER';
                        $role_title = get_string('extteacher', 'praxe');
                    }
                }
                break;
            }
        }
    }
}
开发者ID:jerab,项目名称:moodle-mod-praxe,代码行数:31,代码来源:view.php

示例7: groups_get_user_groups

} else {
    $groupid = 0;
}
$usrcanjoin = false;
$usrgroups = groups_get_user_groups($cm->course, $usrobj->id);
$usrgroups = $usrgroups[0];
// Just want groups and not groupings
// If separate groups is enabled, check if the user is a part of the selected group
if (0 != $cm->groupmode) {
    if (false !== array_search($groupid, $usrgroups)) {
        $usrcanjoin = true;
    }
}
$context = get_context_instance(CONTEXT_COURSE, $cm->course);
// Make sure the user has a role in the course
$crsroles = get_roles_used_in_context($context);
if (empty($crsroles)) {
    $crsroles = array();
}
foreach ($crsroles as $roleid => $crsrole) {
    if (user_has_role_assignment($usrobj->id, $roleid, $context->id)) {
        $usrcanjoin = true;
    }
}
// user has to be in a group
if ($usrcanjoin and confirm_sesskey($sesskey)) {
    $usrprincipal = 0;
    $validuser = true;
    $groupobj = groups_get_group($groupid);
    // Get the meeting sco-id
    $param = array('instanceid' => $cm->instance, 'groupid' => $groupid);
开发者ID:rrusso,项目名称:moodle2-adobeconnect,代码行数:31,代码来源:join.php

示例8: email_choose_users_to_send

/**
 * This function show all participants of one course. Choose user/s to sent mail.
 *
 * @uses $CFG, $USER
 * @param int $courseid Course ID
 * @param int $roleid   Role ID
 * @param int $currentgroup Current group
 * @return Array Users to sending mail.
 * @todo Finish documenting this function
 */
function email_choose_users_to_send($courseid, $roleid, $currentgroup)
{
    global $CFG, $USER;
    if (!($course = get_record('course', 'id', $courseid))) {
        print_error('invalidcourseid', 'block_email_list');
    }
    // Prepare users to choose us
    if ($courseid) {
        if ($course->id == SITEID) {
            $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
            // SYSTEM context
        } else {
            $context = get_context_instance(CONTEXT_COURSE, $course->id);
            // Course context
        }
        // Security issue
        $sitecontext = get_context_instance(CONTEXT_SYSTEM);
        $frontpagectx = get_context_instance(CONTEXT_COURSE, SITEID);
        if ($context->id != $frontpagectx->id) {
            require_capability('moodle/course:viewparticipants', $context);
        } else {
            require_capability('moodle/site:viewparticipants', $sitecontext);
        }
        $rolesnames = array();
        $avoidroles = array();
        if ($roles = get_roles_used_in_context($context, true)) {
            $canviewroles = get_roles_with_capability('moodle/course:view', CAP_ALLOW, $context);
            $doanythingroles = get_roles_with_capability('moodle/site:doanything', CAP_ALLOW, $sitecontext);
            if (!$CFG->email_add_admins) {
                $adminsroles = get_roles_with_capability('moodle/legacy:admin', CAP_ALLOW, $sitecontext);
            }
            foreach ($roles as $role) {
                if (!isset($canviewroles[$role->id])) {
                    // Avoid this role (eg course creator)
                    $avoidroles[] = $role->id;
                    unset($roles[$role->id]);
                    continue;
                }
                if (isset($doanythingroles[$role->id])) {
                    // Avoid this role (ie admin)
                    $avoidroles[] = $role->id;
                    unset($roles[$role->id]);
                    continue;
                }
                if (!$CFG->email_add_admins) {
                    if (isset($adminsroles[$role->id])) {
                        // Avoid this role (ie admin)
                        $avoidroles[] = $role->id;
                        unset($roles[$role->id]);
                        continue;
                    }
                }
                // Prevent - CONTRIB-609
                if (function_exists('role_get_name')) {
                    $rolenames[$role->id] = strip_tags(role_get_name($role, $context));
                    // Used in menus etc later on
                } else {
                    $rolenames[$role->id] = strip_tags(format_string($role->name));
                    // Used in menus etc later on
                }
            }
        }
        // we are looking for all users with this role assigned in this context or higher
        if ($usercontexts = get_parent_contexts($context)) {
            $listofcontexts = '(' . implode(',', $usercontexts) . ')';
        } else {
            $listofcontexts = '(' . $sitecontext->id . ')';
            // must be site
        }
        if ($roleid) {
            $selectrole = " AND r.roleid = {$roleid} ";
        } else {
            $selectrole = " ";
        }
        if ($context->id != $frontpagectx->id) {
            $select = 'SELECT DISTINCT u.id, u.username, u.firstname, u.lastname ';
        } else {
            $select = 'SELECT u.id, u.username, u.firstname, u.lastname ';
        }
        if ($context->id != $frontpagectx->id) {
            $from = "FROM {$CFG->prefix}user u\n\t                LEFT OUTER JOIN {$CFG->prefix}context ctx\n\t                    ON (u.id=ctx.instanceid AND ctx.contextlevel = " . CONTEXT_USER . ")\n\t                JOIN {$CFG->prefix}role_assignments r\n\t                    ON u.id=r.userid\n\t                LEFT OUTER JOIN {$CFG->prefix}user_lastaccess ul\n\t                    ON (r.userid=ul.userid and ul.courseid = {$course->id}) ";
        } else {
            $from = "FROM {$CFG->prefix}user u\n\t                LEFT OUTER JOIN {$CFG->prefix}context ctx\n\t                    ON (u.id=ctx.instanceid AND ctx.contextlevel = " . CONTEXT_USER . ") ";
        }
        $hiddensql = has_capability('moodle/role:viewhiddenassigns', $context) ? '' : ' AND r.hidden = 0 ';
        // exclude users with roles we are avoiding
        if ($avoidroles) {
            $adminroles = 'AND r.roleid NOT IN (';
            $adminroles .= implode(',', $avoidroles);
            $adminroles .= ')';
//.........这里部分代码省略.........
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:101,代码来源:lib.php

示例9: get_roster

 function get_roster($onlyrole = null)
 {
     //edited below, replaced old method
     $coursecontext = context_course::instance($this->courseid);
     $allroles = get_roles_used_in_context($coursecontext);
     arsort($allroles);
     if (!$this->visible) {
         foreach ($allroles as $key => $role) {
             if ($role->shortname != 'editingteacher') {
                 unset($allroles[$key]);
             }
         }
     }
     $roles = array_keys($allroles);
     // can't used canned function as its likely to return a student role
     // when the user has both a student and a teacher role
     // so this bit will allow the lower roleid (higher value role) to overwrite the lower one
     foreach ($roles as $role) {
         $temp = get_role_users($role, $coursecontext, false, '', null, false);
         if ($temp !== false && sizeof($temp) !== 0) {
             if (isset($course->users)) {
                 $course->users = array_merge($course->users, $temp);
             } else {
                 $course = new stdclass();
                 $course->users = $temp;
             }
         }
     }
     $members = array();
     $suspended = get_suspended_userids($coursecontext);
     foreach ($course->users as $cuser) {
         if (array_key_exists($cuser->id, $suspended)) {
             /* Explanation of changes made: */
             //edited use of unset below: previous implementation wasn't working
             //because $cuser->id was a number larger than the size of
             //$course->users.
             //$course->users is an array of stdClass objects, which have their own IDs,
             //but those IDs could not be directly accessed in $course->users without callling on the $cuser object.
             //So the compiler was seeing $cuser->id as an index into the array $course->users
             //$cuser->id is normally too large to be used to index into $course->users
             //unset was not working because the index $cuser->id was out of range (larger than the size of $course->users)
             //
             ///*unset($course->users[$cuser->id]);*/
             //solution has been reimplemented below, and it should now work (hopefully)
             $deleteUser = array_search($cuser, $course->users);
             unset($course->users[$deleteUser]);
         } else {
             if ($onlyrole === null || $onlyrole == $allroles[$cuser->roleid]->shortname) {
                 $members[strtolower($cuser->email)] = $allroles[$cuser->roleid]->shortname;
             }
         }
     }
     return $members;
 }
开发者ID:bobpuffer,项目名称:moodle-repository_morsle,代码行数:54,代码来源:lib.php

示例10: report_participation_print_filter_form

/**
 * Print filter form.
 *
 * @param stdClass $course course object.
 * @param int $timefrom Time from which records should be fetched.
 * @param int $minlog Time of first record present in log store.
 * @param string $action action to be filtered.
 * @param int $roleid Role to be filtered.
 * @param int $instanceid Instance id of module.
 */
function report_participation_print_filter_form($course, $timefrom, $minlog, $action, $roleid, $instanceid)
{
    global $DB;
    $timeoptions = report_participation_get_time_options($minlog);
    $actionoptions = report_participation_get_action_options();
    // TODO: we need a new list of roles that are visible here.
    $context = context_course::instance($course->id);
    $roles = get_roles_used_in_context($context);
    $guestrole = get_guest_role();
    $roles[$guestrole->id] = $guestrole;
    $roleoptions = role_fix_names($roles, $context, ROLENAME_ALIAS, true);
    $modinfo = get_fast_modinfo($course);
    $modules = $DB->get_records_select('modules', "visible = 1", null, 'name ASC');
    $instanceoptions = array();
    foreach ($modules as $module) {
        if (empty($modinfo->instances[$module->name])) {
            continue;
        }
        $instances = array();
        foreach ($modinfo->instances[$module->name] as $cm) {
            // Skip modules such as label which do not actually have links;
            // this means there's nothing to participate in.
            if (!$cm->has_view()) {
                continue;
            }
            $instances[$cm->id] = format_string($cm->name);
        }
        if (count($instances) == 0) {
            continue;
        }
        $instanceoptions[] = array(get_string('modulenameplural', $module->name) => $instances);
    }
    echo '<form class="participationselectform" action="index.php" method="get"><div>' . "\n" . '<input type="hidden" name="id" value="' . $course->id . '" />' . "\n";
    echo '<label for="menuinstanceid">' . get_string('activitymodule') . '</label>' . "\n";
    echo html_writer::select($instanceoptions, 'instanceid', $instanceid);
    echo '<label for="menutimefrom">' . get_string('lookback') . '</label>' . "\n";
    echo html_writer::select($timeoptions, 'timefrom', $timefrom);
    echo '<label for="menuroleid">' . get_string('showonly') . '</label>' . "\n";
    echo html_writer::select($roleoptions, 'roleid', $roleid, false);
    echo '<label for="menuaction">' . get_string('showactions') . '</label>' . "\n";
    echo html_writer::select($actionoptions, 'action', $action, false);
    echo '<input type="submit" value="' . get_string('go') . '" />' . "\n</div></form>\n";
}
开发者ID:evltuma,项目名称:moodle,代码行数:53,代码来源:locallib.php

示例11: email_search_course_users

/**
 * This function returns an object of all users whithin current course who match
 * the search query.
 *  *Modified version of datalib.php's search_user() function
 *
 * @param object $course Current Course object
 * @param string $query Search query
 * @param boolean $dispadmins Flag to return course admins or not
 * @param boolean $displayunconfirmed Flag to specify to return unconfirmed users
 * @return object result set of all matching users
 * @todo Add option to remove active user from results
 */
function email_search_course_users($course, $query = '', $dispadmins = false, $dispunconfirmed = true)
{
    global $CFG, $USER;
    $LIKE = sql_ilike();
    $order = 'ORDER BY firstname, lastname, id';
    $select = 'u.deleted = \'0\'';
    if (!$dispunconfirmed) {
        $select .= ' AND u.confirmed = \'1\'';
    }
    if (!$course or $course->id == SITEID) {
        $results = get_records_sql("SELECT u.id, u.firstname, u.lastname, u.email\n                      FROM {$CFG->prefix}user u\n                      WHERE {$select}\n                          AND (u.firstname {$LIKE} '{$query}%' OR u.lastname {$LIKE} '{$query}%')\n                          AND u.username != 'guest'\n                          {$order}");
    } else {
        if ($course->id == SITEID) {
            $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
        } else {
            $context = get_context_instance(CONTEXT_COURSE, $course->id);
        }
        $contextlists = get_related_contexts_string($context);
        // Returns only group(s) members for users without the viewallgroups capability
        $groupmembers = '';
        // Separate groups
        $groupmode = groups_get_course_groupmode($course);
        if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) {
            // Returns all groups current user is assigned to in course
            if ($groups = groups_get_all_groups($course->id, $USER->id)) {
                $groupmembers = array();
                foreach ($groups as $group) {
                    $groupmembers += groups_get_members($group->id, 'u.id');
                }
                if (!empty($groupmembers)) {
                    $groupmembers = 'AND u.id IN (' . implode(',', array_keys($groupmembers)) . ')';
                } else {
                    // Nobody in their groups :(
                    return false;
                }
            } else {
                // They have no group :(
                return false;
            }
        }
        // Hides course admin roles (eg: admin && course creator) if requested (default)
        if (!$dispadmins) {
            $avoidroles = array();
            if ($roles = get_roles_used_in_context($context, true)) {
                $canviewroles = get_roles_with_capability('moodle/course:view', CAP_ALLOW, $context);
                $doanythingroles = get_roles_with_capability('moodle/site:doanything', CAP_ALLOW, $context);
                if (!$CFG->email_add_admins) {
                    $adminsroles = get_roles_with_capability('moodle/legacy:admin', CAP_ALLOW, $context);
                }
                foreach ($roles as $role) {
                    if (!isset($canviewroles[$role->id])) {
                        // Avoid this role (eg course creator)
                        $avoidroles[] = $role->id;
                        unset($roles[$role->id]);
                        continue;
                    }
                    if (isset($doanythingroles[$role->id])) {
                        // Avoid this role (ie admin)
                        $avoidroles[] = $role->id;
                        unset($roles[$role->id]);
                        continue;
                    }
                    if (!$CFG->email_add_admins) {
                        if (isset($adminsroles[$role->id])) {
                            // Avoid this role (ie admin)
                            $avoidroles[] = $role->id;
                            unset($roles[$role->id]);
                            continue;
                        }
                    }
                }
            }
            // exclude users with roles we are avoiding
            if ($avoidroles) {
                $adminroles = 'AND ra.roleid NOT IN (';
                $adminroles .= implode(',', $avoidroles);
                $adminroles .= ')';
            } else {
                $adminroles = '';
            }
        } else {
            $adminroles = '';
        }
        $results = get_records_sql("SELECT u.id, u.firstname, u.lastname, u.email\n                      FROM {$CFG->prefix}user u,\n                           {$CFG->prefix}role_assignments ra\n                      WHERE {$select} AND ra.contextid {$contextlists} AND ra.userid = u.id\n                          AND (u.firstname {$LIKE} '{$query}%' OR u.lastname {$LIKE} '{$query}%')\n                          AND (u.username != 'guest')\n                          {$adminroles} {$groupmembers} {$order}");
    }
    return $results;
}
开发者ID:henriquecrang,项目名称:e-UNI,代码行数:99,代码来源:lib.php

示例12: get_roster

 function get_roster($onlyrole = null)
 {
     //edited below, replaced old method
     $coursecontext = context_course::instance($this->courseid);
     $allroles = get_roles_used_in_context($coursecontext);
     arsort($allroles);
     if (!$this->visible) {
         foreach ($allroles as $key => $role) {
             if ($role->shortname != 'editingteacher') {
                 unset($allroles[$key]);
             }
         }
     }
     $roles = array_keys($allroles);
     // can't used canned function as its likely to return a student role
     // when the user has both a student and a teacher role
     // so this bit will allow the lower roleid (higher value role) to overwrite the lower one
     foreach ($roles as $role) {
         $temp = get_role_users($role, $coursecontext, false, '', null, false);
         if ($temp !== false && sizeof($temp) !== 0) {
             if (isset($course->users)) {
                 $course->users = array_merge($course->users, $temp);
             } else {
                 $course = new stdclass();
                 $course->users = $temp;
             }
         }
     }
     $members = array();
     $suspended = get_suspended_userids($coursecontext);
     foreach ($course->users as $cuser) {
         if (array_key_exists($cuser->id, $suspended)) {
             unset($course->users[$cuser->id]);
         } else {
             if ($onlyrole === null || $onlyrole == $allroles[$cuser->roleid]->shortname) {
                 $members[strtolower($cuser->email)] = $allroles[$cuser->roleid]->shortname;
             }
         }
     }
     return $members;
 }
开发者ID:rlorenzo,项目名称:moodle-repository_morsle,代码行数:41,代码来源:lib.php

示例13: groups_get_potential_members

/**
 * Gets potential group members for grouping
 * @param int $courseid The id of the course
 * @param int $roleid The role to select users from
 * @param string $orderby The colum to sort users by
 * @return array An array of the users
 */
function groups_get_potential_members($courseid, $roleid = null, $orderby = 'lastname,firstname')
{
    global $DB;
    $context = get_context_instance(CONTEXT_COURSE, $courseid);
    $sitecontext = get_context_instance(CONTEXT_SYSTEM);
    $rolenames = array();
    $avoidroles = array();
    if ($roles = get_roles_used_in_context($context, true)) {
        $canviewroles = get_roles_with_capability('moodle/course:view', CAP_ALLOW, $context);
        $doanythingroles = get_roles_with_capability('moodle/site:doanything', CAP_ALLOW, $sitecontext);
        foreach ($roles as $role) {
            if (!isset($canviewroles[$role->id])) {
                // Avoid this role (eg course creator)
                $avoidroles[] = $role->id;
                unset($roles[$role->id]);
                continue;
            }
            if (isset($doanythingroles[$role->id])) {
                // Avoid this role (ie admin)
                $avoidroles[] = $role->id;
                unset($roles[$role->id]);
                continue;
            }
            $rolenames[$role->id] = strip_tags(role_get_name($role, $context));
            // Used in menus etc later on
        }
    }
    if ($avoidroles) {
        list($adminroles, $params) = $DB->get_in_or_equal($avoidroles, SQL_PARAMS_NAMED, 'ar0', false);
        $adminroles = "AND r.roleid {$adminroles}";
    } else {
        $adminroles = "";
        $params = array();
    }
    // we are looking for all users with this role assigned in this context or higher
    if ($usercontexts = get_parent_contexts($context)) {
        $listofcontexts = 'IN (' . implode(',', $usercontexts) . ')';
    } else {
        $listofcontexts = '=' . $sitecontext->id . ')';
        // must be site
    }
    if ($roleid) {
        $selectrole = "AND r.roleid = :roleid";
        $params['roleid'] = $roleid;
    } else {
        $selectrole = "";
    }
    $sql = "SELECT u.id, u.username, u.firstname, u.lastname, u.idnumber\n              FROM {user} u\n              JOIN {role_assignments} r on u.id=r.userid\n             WHERE (r.contextid = :contextid OR r.contextid {$listofcontexts})\n                   AND u.deleted = 0 AND u.username != 'guest'\n                   {$selectrole} {$adminroles}\n          ORDER BY {$orderby}";
    $params['contextid'] = $context->id;
    return $DB->get_records_sql($sql, $params);
}
开发者ID:ajv,项目名称:Offline-Caching,代码行数:58,代码来源:lib.php

示例14: available_desktops

 /**
  *this function determins the desktops started and available in this course
  *TODO: this function needs performance improvements
  * @return array of moodle_urls or empty array
  */
 private function available_desktops()
 {
     global $CFG, $PAGE, $USER, $DB;
     $url = array();
     if (has_capability('mod/opendesktop:joinactive', $this->context) or has_capability('mod/opendesktop:joinpassive', $this->context)) {
         if ($roles = get_roles_used_in_context($this->context, true)) {
             $canstartusers = get_users_by_capability($this->context, 'mod/opendesktop:start', 'u.id,username,firstname,lastname');
         }
         foreach ($canstartusers as $canstartuser) {
             $sql = 'SELECT MAX(starttime) AS starttime FROM {opendesktop_sessions} WHERE userid=' . $canstartuser->id;
             $maxstarttime = $DB->get_field_sql($sql);
             $sessionmode = $DB->get_field('opendesktop_sessions', 'sessionmode', array('userid' => $canstartuser->id, 'starttime' => $maxstarttime));
             if ($USER->username != $canstartuser->username && $this->opendesktop->id == $DB->get_field('opendesktop_sessions', 'opendesktop', array('userid' => $canstartuser->id, 'starttime' => $maxstarttime))) {
                 // check if any user with the capability to start a desktop in this course has started OVD
                 $sessvaldetect = $this->session->sessionstatus($CFG->opendesktop_useprefix . $canstartuser->username);
                 // check if the opendesktop was started in the same course, if not do not display the possibility to join
                 if ($sessvaldetect['status'] == 'active' && $sessvaldetect['isregistered']) {
                     if (has_capability('mod/opendesktop:joinactive', $this->context)) {
                         $url[$canstartuser->username]['active'] = new moodle_url($PAGE->url, array('id' => $this->cm->id, 'task' => 'join', 'join' => 'active', 'sesskey' => sesskey(), 'sessionmode' => $sessionmode, 'ovduser' => $canstartuser->id));
                     }
                     if (has_capability('mod/opendesktop:joinpassive', $this->context)) {
                         $url[$canstartuser->username]['passive'] = new moodle_url($PAGE->url, array('id' => $this->cm->id, 'task' => 'join', 'join' => 'passive', 'sesskey' => sesskey(), 'sessionmode' => $sessionmode, 'ovduser' => $canstartuser->id));
                     }
                     $url[$canstartuser->username]['fullname'] = $canstartuser->firstname . ' ' . $canstartuser->lastname;
                 }
             }
         }
     }
     return $url;
 }
开发者ID:youprofit,项目名称:moodle-mod_opendesktop,代码行数:35,代码来源:locallib.php

示例15: get_string

        $timeoptions[strtotime('-' . $i . ' weeks', $now)] = get_string('numweeks', 'moodle', $i);
    }
}
// months
for ($i = 2; $i < 12; $i++) {
    if (strtotime('-' . $i . ' months', $now) >= $minlog) {
        $timeoptions[strtotime('-' . $i . ' months', $now)] = get_string('nummonths', 'moodle', $i);
    }
}
// try a year
if (strtotime('-1 year', $now) >= $minlog) {
    $timeoptions[strtotime('-1 year', $now)] = get_string('lastyear');
}
$roleoptions = array();
// TODO: we need a new list of roles that are visible here
if ($roles = get_roles_used_in_context($context)) {
    foreach ($roles as $r) {
        $roleoptions[$r->id] = $r->name;
    }
}
$guestrole = get_guest_role();
if (empty($roleoptions[$guestrole->id])) {
    $roleoptions[$guestrole->id] = $guestrole->name;
}
$roleoptions = role_fix_names($roleoptions, $context);
// print first controls.
echo '<form class="participationselectform" action="index.php" method="get"><div>' . "\n" . '<input type="hidden" name="id" value="' . $course->id . '" />' . "\n";
echo '<label for="menuinstanceid">' . get_string('activitymodule') . '</label>' . "\n";
echo html_writer::select($instanceoptions, 'instanceid', $instanceid);
echo '<label for="menutimefrom">' . get_string('lookback') . '</label>' . "\n";
echo html_writer::select($timeoptions, 'timefrom', $timefrom);
开发者ID:sebastiansanio,项目名称:tallerdeprogramacion2fiuba,代码行数:31,代码来源:index.php


注:本文中的get_roles_used_in_context函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。