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


PHP get_parent_contexts函数代码示例

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


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

示例1: definition

 function definition()
 {
     global $CFG, $DB;
     $mform = $this->_form;
     $course = $this->_customdata;
     $coursecontext = context_course::instance($course->id);
     $enrol = enrol_get_plugin('cohort');
     $cohorts = array('' => get_string('choosedots'));
     list($sqlparents, $params) = $DB->get_in_or_equal(get_parent_contexts($coursecontext));
     $sql = "SELECT id, name, contextid\n                  FROM {cohort}\n                 WHERE contextid {$sqlparents}\n              ORDER BY name ASC";
     $rs = $DB->get_recordset_sql($sql, $params);
     foreach ($rs as $c) {
         $context = get_context_instance_by_id($c->contextid);
         if (!has_capability('moodle/cohort:view', $context)) {
             continue;
         }
         $cohorts[$c->id] = format_string($c->name);
     }
     $rs->close();
     $roles = get_assignable_roles($coursecontext);
     $roles[0] = get_string('none');
     $roles = array_reverse($roles, true);
     // descending default sortorder
     $mform->addElement('header', 'general', get_string('pluginname', 'enrol_cohort'));
     $mform->addElement('select', 'cohortid', get_string('cohort', 'cohort'), $cohorts);
     $mform->addRule('cohortid', get_string('required'), 'required', null, 'client');
     $mform->addElement('select', 'roleid', get_string('role'), $roles);
     $mform->addRule('roleid', get_string('required'), 'required', null, 'client');
     $mform->setDefault('roleid', $enrol->get_config('roleid'));
     $mform->addElement('hidden', 'id', null);
     $mform->setType('id', PARAM_INT);
     $this->add_action_buttons(true, get_string('addinstance', 'enrol'));
     $this->set_data(array('id' => $course->id));
 }
开发者ID:nigeli,项目名称:moodle,代码行数:34,代码来源:addinstance_form.php

示例2: test_get_parent_contexts

 function test_get_parent_contexts()
 {
     $context = get_context_instance(CONTEXT_SYSTEM);
     $this->assertEqual(get_parent_contexts($context), array());
     $context = new stdClass();
     $context->path = '/1/25';
     $this->assertEqual(get_parent_contexts($context), array(1));
     $context = new stdClass();
     $context->path = '/1/123/234/345/456';
     $this->assertEqual(get_parent_contexts($context), array(345, 234, 123, 1));
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:11,代码来源:testaccesslib.php

示例3: can_add_new_instances

 /**
  * Given a courseid this function returns true if the user is able to enrol or configure cohorts
  * AND there are cohorts that the user can view.
  *
  * @param int $courseid
  * @return bool
  */
 protected function can_add_new_instances($courseid)
 {
     global $DB;
     $coursecontext = get_context_instance(CONTEXT_COURSE, $courseid);
     if (!has_capability('moodle/course:enrolconfig', $coursecontext) or !has_capability('enrol/cohort:config', $coursecontext)) {
         return false;
     }
     list($sqlparents, $params) = $DB->get_in_or_equal(get_parent_contexts($coursecontext));
     $sql = "SELECT id, contextid\n                  FROM {cohort}\n                 WHERE contextid {$sqlparents}\n              ORDER BY name ASC";
     $cohorts = $DB->get_records_sql($sql, $params);
     foreach ($cohorts as $c) {
         $context = get_context_instance_by_id($c->contextid);
         if (has_capability('moodle/cohort:view', $context)) {
             return true;
         }
     }
     return false;
 }
开发者ID:nmicha,项目名称:moodle,代码行数:25,代码来源:lib.php

示例4: get_newinstance_link

 /**
  * Returns link to page which may be used to add new instance of enrolment plugin in course.
  * @param int $courseid
  * @return moodle_url page url
  */
 public function get_newinstance_link($courseid)
 {
     global $DB;
     $coursecontext = get_context_instance(CONTEXT_COURSE, $courseid);
     if (!has_capability('moodle/course:enrolconfig', $coursecontext) or !has_capability('enrol/cohort:config', $coursecontext)) {
         return NULL;
     }
     list($sqlparents, $params) = $DB->get_in_or_equal(get_parent_contexts($coursecontext));
     $sql = "SELECT id, contextid\n                  FROM {cohort}\n                 WHERE contextid {$sqlparents}\n              ORDER BY name ASC";
     $cohorts = $DB->get_records_sql($sql, $params);
     $found = false;
     foreach ($cohorts as $c) {
         $context = get_context_instance_by_id($c->contextid);
         if (has_capability('moodle/cohort:view', $context)) {
             $found = true;
             break;
         }
     }
     if (!$found) {
         return NULL;
     }
     // multiple instances supported - multiple parent courses linked
     return new moodle_url('/enrol/cohort/addinstance.php', array('id' => $courseid));
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:29,代码来源:lib.php

示例5: role_unassigned

 public function role_unassigned($ra)
 {
     global $DB;
     if (!enrol_is_enabled('category')) {
         return true;
     }
     // only category level roles are interesting
     $parentcontext = get_context_instance_by_id($ra->contextid);
     if ($parentcontext->contextlevel != CONTEXT_COURSECAT) {
         return true;
     }
     // now this is going to be a bit slow, take all enrolments in child courses and verify each separately
     $syscontext = get_context_instance(CONTEXT_SYSTEM);
     if (!($roles = get_roles_with_capability('enrol/category:synchronised', CAP_ALLOW, $syscontext))) {
         return true;
     }
     $plugin = enrol_get_plugin('category');
     $sql = "SELECT e.*\n                  FROM {course} c\n                  JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :courselevel AND ctx.path LIKE :match)\n                  JOIN {enrol} e ON (e.courseid = c.id AND e.enrol = 'category')\n                  JOIN {user_enrolments} ue ON (ue.enrolid = e.id AND ue.userid = :userid)";
     $params = array('courselevel' => CONTEXT_COURSE, 'match' => $parentcontext->path . '/%', 'userid' => $ra->userid);
     $rs = $DB->get_recordset_sql($sql, $params);
     list($roleids, $params) = $DB->get_in_or_equal(array_keys($roles), SQL_PARAMS_NAMED, 'r');
     $params['userid'] = $ra->userid;
     foreach ($rs as $instance) {
         $coursecontext = get_context_instance(CONTEXT_COURSE, $instance->courseid);
         $contextids = get_parent_contexts($coursecontext);
         array_pop($contextids);
         // remove system context, we are interested in categories only
         list($contextids, $contextparams) = $DB->get_in_or_equal($contextids, SQL_PARAMS_NAMED, 'c');
         $params = array_merge($params, $contextparams);
         $sql = "SELECT ra.id\n                      FROM {role_assignments} ra\n                     WHERE ra.userid = :userid AND ra.contextid {$contextids} AND ra.roleid {$roleids}";
         if (!$DB->record_exists_sql($sql, $params)) {
             // user does not have any interesting role in any parent context, let's unenrol
             $plugin->unenrol_user($instance, $ra->userid);
         }
     }
     $rs->close();
     return true;
 }
开发者ID:raymondAntonio,项目名称:moodle,代码行数:38,代码来源:locallib.php

示例6: count_role_users

/**
 * Counts all the users assigned this role in this context or higher
 * @param int roleid
 * @param int contextid
 * @param bool parent if true, get list of users assigned in higher context too
 * @return array()
 */
function count_role_users($roleid, $context, $parent = false)
{
    global $CFG;
    if ($parent) {
        if ($contexts = get_parent_contexts($context)) {
            $parentcontexts = ' OR r.contextid IN (' . implode(',', $contexts) . ')';
        } else {
            $parentcontexts = '';
        }
    } else {
        $parentcontexts = '';
    }
    $SQL = "SELECT count(*)\n            FROM {$CFG->prefix}role_assignments r\n            WHERE (r.contextid = {$context->id} {$parentcontexts})\n            AND r.roleid = {$roleid}";
    return count_records_sql($SQL);
}
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:22,代码来源:accesslib.php

示例7: role_fix_names

/**
 * Prepare list of roles for display, apply aliases and format text
 * @param array $roleoptions array roleid => rolename or roleid => roleobject
 * @param object $context a context
 * @return array of context-specific role names, or role objexts with a ->localname field added.
 */
function role_fix_names($roleoptions, $context, $rolenamedisplay = ROLENAME_ALIAS)
{
    global $DB;
    // Make sure we are working with an array roleid => name. Normally we
    // want to use the unlocalised name if the localised one is not present.
    $newnames = array();
    foreach ($roleoptions as $rid => $roleorname) {
        if ($rolenamedisplay != ROLENAME_ALIAS_RAW) {
            if (is_object($roleorname)) {
                $newnames[$rid] = $roleorname->name;
            } else {
                $newnames[$rid] = $roleorname;
            }
        } else {
            $newnames[$rid] = '';
        }
    }
    // If necessary, get the localised names.
    if ($rolenamedisplay != ROLENAME_ORIGINAL && !empty($context->id)) {
        // Make sure we have a course context.
        if ($context->contextlevel == CONTEXT_MODULE || $context->contextlevel == CONTEXT_BLOCK) {
            // find the parent course context
            if ($parentcontextid = array_shift(get_parent_contexts($context))) {
                $context = get_context_instance_by_id($parentcontextid);
            }
        }
        // The get the relevant renames, and use them.
        $aliasnames = $DB->get_records('role_names', array('contextid' => $context->id));
        foreach ($aliasnames as $alias) {
            if (isset($newnames[$alias->roleid])) {
                if ($rolenamedisplay == ROLENAME_ALIAS || $rolenamedisplay == ROLENAME_ALIAS_RAW) {
                    $newnames[$alias->roleid] = $alias->name;
                } else {
                    if ($rolenamedisplay == ROLENAME_BOTH) {
                        $newnames[$alias->roleid] = $alias->name . ' (' . $roleoptions[$alias->roleid] . ')';
                    }
                }
            }
        }
    }
    // Finally, apply format_string and put the result in the right place.
    foreach ($roleoptions as $rid => $roleorname) {
        if ($rolenamedisplay != ROLENAME_ALIAS_RAW) {
            $newnames[$rid] = strip_tags(format_string($newnames[$rid]));
        }
        if (is_object($roleorname)) {
            $roleoptions[$rid]->localname = $newnames[$rid];
        } else {
            $roleoptions[$rid] = $newnames[$rid];
        }
    }
    return $roleoptions;
}
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:59,代码来源:accesslib.php

示例8: grade_get_letters

/**
 * Returns grade letters array used in context
 * @param object $context object or null for defaults
 * @return array of grade_boundary=>letter_string
 */
function grade_get_letters($context = null)
{
    if (empty($context)) {
        //default grading letters
        return array('93' => 'A', '90' => 'A-', '87' => 'B+', '83' => 'B', '80' => 'B-', '77' => 'C+', '73' => 'C', '70' => 'C-', '67' => 'D+', '60' => 'D', '0' => 'F');
    }
    static $cache = array();
    if (array_key_exists($context->id, $cache)) {
        return $cache[$context->id];
    }
    if (count($cache) > 100) {
        $cache = array();
        // cache size limit
    }
    $letters = array();
    $contexts = get_parent_contexts($context);
    array_unshift($contexts, $context->id);
    foreach ($contexts as $ctxid) {
        if ($records = get_records('grade_letters', 'contextid', $ctxid, 'lowerboundary DESC')) {
            foreach ($records as $record) {
                $letters[$record->lowerboundary] = $record->letter;
            }
        }
        if (!empty($letters)) {
            $cache[$context->id] = $letters;
            return $letters;
        }
    }
    $letters = grade_get_letters(null);
    $cache[$context->id] = $letters;
    return $letters;
}
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:37,代码来源:gradelib.php

示例9: admin_externalpage_print_header

        admin_externalpage_print_header();
        $currenttab = 'override';
        include_once 'tabs.php';
    } else {
        $currenttab = 'override';
        include_once 'tabs.php';
    }
}
print_heading_with_help(get_string('overridepermissionsin', 'role', print_context_name($context)), 'overrides');
if ($roleid) {
    /// prints a form to swap roles
    echo '<div class="selector">';
    $overridableroles = array('0' => get_string('listallroles', 'role') . '...') + $overridableroles;
    popup_form("{$CFG->wwwroot}/{$CFG->admin}/roles/override.php?userid={$userid}&amp;courseid={$courseid}&amp;contextid={$contextid}&amp;roleid=", $overridableroles, 'switchrole', $roleid, '', '', '', false, 'self', $strroletooverride);
    echo '</div>';
    $parentcontexts = get_parent_contexts($context);
    if (!empty($parentcontexts)) {
        $parentcontext = array_shift($parentcontexts);
        $parentcontext = get_context_instance_by_id($parentcontext);
    } else {
        $parentcontext = $context;
        // site level in override??
    }
    $r_caps = role_context_capabilities($roleid, $parentcontext);
    $localoverrides = get_records_select('role_capabilities', "roleid = {$roleid} AND contextid = {$context->id}", '', 'capability, permission, id');
    $lang = str_replace('_utf8', '', current_language());
    if (!empty($capabilities)) {
        // Print the capabilities overrideable in this context
        print_simple_box_start('center');
        include 'override.html';
        print_simple_box_end();
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:31,代码来源:override.php

示例10: test_everything_in_accesslib


//.........这里部分代码省略.........
                $cap = (array)$cap;
                $this->assertSame(array_keys($cap), array('id', 'name', 'captype', 'contextlevel', 'component', 'riskbitmask'));
            }
        }
        unset($testcontexts);

        // ===== $context->get_course_context() =========================================

        $this->assertFalse($systemcontext->get_course_context(false));
        try {
            $systemcontext->get_course_context();
            $this->fail('exception expected');
        } catch (Exception $e) {
            $this->assertTrue(true);
        }
        $context = context_coursecat::instance($testcategories[0]);
        $this->assertFalse($context->get_course_context(false));
        try {
            $context->get_course_context();
            $this->fail('exception expected');
        } catch (Exception $e) {
            $this->assertTrue(true);
        }
        $this->assertSame($frontpagecontext->get_course_context(true), $frontpagecontext);
        $this->assertSame($frontpagepagecontext->get_course_context(true), $frontpagecontext);
        $this->assertSame($frontpagepageblockcontext->get_course_context(true), $frontpagecontext);


        // ======= $context->get_parent_context(), $context->get_parent_contexts(), $context->get_parent_context_ids() =======

        $userid = reset($testusers);
        $usercontext = context_user::instance($userid);
        $this->assertSame($usercontext->get_parent_context(), $systemcontext);
        $this->assertSame($usercontext->get_parent_contexts(), array($systemcontext->id=>$systemcontext));
        $this->assertSame($usercontext->get_parent_contexts(true), array($usercontext->id=>$usercontext, $systemcontext->id=>$systemcontext));

        $this->assertSame($systemcontext->get_parent_contexts(), array());
        $this->assertSame($systemcontext->get_parent_contexts(true), array($systemcontext->id=>$systemcontext));
        $this->assertSame($systemcontext->get_parent_context_ids(), array());
        $this->assertSame($systemcontext->get_parent_context_ids(true), array($systemcontext->id));

        $this->assertSame($frontpagecontext->get_parent_context(), $systemcontext);
        $this->assertSame($frontpagecontext->get_parent_contexts(), array($systemcontext->id=>$systemcontext));
        $this->assertSame($frontpagecontext->get_parent_contexts(true), array($frontpagecontext->id=>$frontpagecontext, $systemcontext->id=>$systemcontext));
        $this->assertSame($frontpagecontext->get_parent_context_ids(), array($systemcontext->id));
        $this->assertEquals($frontpagecontext->get_parent_context_ids(true), array($frontpagecontext->id, $systemcontext->id));

        $this->assertSame($systemcontext->get_parent_context(), false);
        $frontpagecontext = context_course::instance($SITE->id);
        $parent = $systemcontext;
        foreach ($testcategories as $catid) {
            $catcontext = context_coursecat::instance($catid);
            $this->assertSame($catcontext->get_parent_context(), $parent);
            $parent = $catcontext;
        }
        $this->assertSame($frontpagepagecontext->get_parent_context(), $frontpagecontext);
        $this->assertSame($frontpageblockcontext->get_parent_context(), $frontpagecontext);
        $this->assertSame($frontpagepageblockcontext->get_parent_context(), $frontpagepagecontext);


        // ====== $context->get_child_contexts() ================================

        $CFG->debug = 0;
        $children = $systemcontext->get_child_contexts();
        $CFG->debug = DEBUG_DEVELOPER;
        $this->assertEquals(count($children)+1, $DB->count_records('context'));
开发者ID:numbas,项目名称:moodle,代码行数:67,代码来源:accesslib_test.php

示例11: get_other_users

 /**
  * Gets and array of other users.
  *
  * Other users are users who have been assigned roles or inherited roles
  * within this course but who have not been enrolled in the course
  *
  * @global moodle_database $DB
  * @param string $sort
  * @param string $direction
  * @param int $page
  * @param int $perpage
  * @return array
  */
 public function get_other_users($sort, $direction = 'ASC', $page = 0, $perpage = 25)
 {
     global $DB;
     if ($direction !== 'ASC') {
         $direction = 'DESC';
     }
     $key = md5("{$sort}-{$direction}-{$page}-{$perpage}");
     if (!array_key_exists($key, $this->otherusers)) {
         list($ctxcondition, $params) = $DB->get_in_or_equal(get_parent_contexts($this->context, true), SQL_PARAMS_NAMED, 'ctx');
         $params['courseid'] = $this->course->id;
         $params['cid'] = $this->course->id;
         $sql = "SELECT ra.id as raid, ra.contextid, ra.component, ctx.contextlevel, ra.roleid, u.*, ue.lastseen\n                    FROM {role_assignments} ra\n                    JOIN {user} u ON u.id = ra.userid\n                    JOIN {context} ctx ON ra.contextid = ctx.id\n               LEFT JOIN (\n                       SELECT ue.id, ue.userid, ul.timeaccess AS lastseen\n                         FROM {user_enrolments} ue\n                    LEFT JOIN {enrol} e ON e.id=ue.enrolid\n                    LEFT JOIN {user_lastaccess} ul ON (ul.courseid = e.courseid AND ul.userid = ue.userid)\n                        WHERE e.courseid = :courseid\n                       ) ue ON ue.userid=u.id\n                   WHERE ctx.id {$ctxcondition} AND\n                         ue.id IS NULL\n                ORDER BY u.{$sort} {$direction}, ctx.depth DESC";
         $this->otherusers[$key] = $DB->get_records_sql($sql, $params, $page * $perpage, $perpage);
     }
     return $this->otherusers[$key];
 }
开发者ID:Burick,项目名称:moodle,代码行数:29,代码来源:locallib.php

示例12: dirname

<?php

require dirname(__FILE__) . '/../../config.php';
// Get parameters.
$userid = required_param('user', PARAM_INTEGER);
// We use 0 here to mean not-logged-in.
$contextid = required_param('contextid', PARAM_INTEGER);
$capability = required_param('capability', PARAM_CAPABILITY);
// Get the context and its parents.
$context = get_context_instance_by_id($contextid);
if (!$context) {
    print_error('unknowncontext');
}
$contextids = get_parent_contexts($context);
array_unshift($contextids, $context->id);
$contexts = array();
$number = count($contextids);
foreach ($contextids as $contextid) {
    $contexts[$contextid] = get_context_instance_by_id($contextid);
    $contexts[$contextid]->name = print_context_name($contexts[$contextid], true, true);
    $contexts[$contextid]->number = $number--;
}
// Validate the user id.
if ($userid) {
    $user = get_record('user', 'id', $userid);
    if (!$user) {
        print_error('nosuchuser');
    }
} else {
    $frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID);
    if (!empty($CFG->forcelogin) || $context->contextlevel >= CONTEXT_COURSE && !in_array($frontpagecontext->id, $contextids)) {
开发者ID:nadavkav,项目名称:MoodleTAO,代码行数:31,代码来源:explainhascapabiltiy.php

示例13: role_fix_names

/**
 * Prepare list of roles for display, apply aliases and format text
 * @param array $roleoptions array roleid=>rolename
 * @param object $context
 * @return array of role names
 */
function role_fix_names($roleoptions, $context, $rolenamedisplay = ROLENAME_ALIAS)
{
    if ($rolenamedisplay != ROLENAME_ORIGINAL && !empty($context->id)) {
        if ($context->contextlevel == CONTEXT_MODULE || $context->contextlevel == CONTEXT_BLOCK) {
            // find the parent course context
            if ($parentcontextid = array_shift(get_parent_contexts($context))) {
                $context = get_context_instance_by_id($parentcontextid);
            }
        }
        if ($aliasnames = get_records('role_names', 'contextid', $context->id)) {
            if ($rolenamedisplay == ROLENAME_ALIAS) {
                foreach ($aliasnames as $alias) {
                    if (isset($roleoptions[$alias->roleid])) {
                        $roleoptions[$alias->roleid] = format_string($alias->name);
                    }
                }
            } else {
                if ($rolenamedisplay == ROLENAME_BOTH) {
                    foreach ($aliasnames as $alias) {
                        if (isset($roleoptions[$alias->roleid])) {
                            $roleoptions[$alias->roleid] = format_string($alias->name) . ' (' . format_string($roleoptions[$alias->roleid]) . ')';
                        }
                    }
                }
            }
        }
    }
    foreach ($roleoptions as $rid => $name) {
        $roleoptions[$rid] = strip_tags(format_string($name));
    }
    return $roleoptions;
}
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:38,代码来源:accesslib.php

示例14: validate_context

 /**
  * Makes sure user may execute functions in this context.
  * @param object $context
  * @return void
  */
 protected static function validate_context($context)
 {
     global $CFG;
     if (empty($context)) {
         throw new invalid_parameter_exception('Context does not exist');
     }
     if (empty(self::$contextrestriction)) {
         self::$contextrestriction = get_context_instance(CONTEXT_SYSTEM);
     }
     $rcontext = self::$contextrestriction;
     if ($rcontext->contextlevel == $context->contextlevel) {
         if ($rcontext->id != $context->id) {
             throw new restricted_context_exception();
         }
     } else {
         if ($rcontext->contextlevel > $context->contextlevel) {
             throw new restricted_context_exception();
         } else {
             $parents = get_parent_contexts($context);
             if (!in_array($rcontext->id, $parents)) {
                 throw new restricted_context_exception();
             }
         }
     }
     if ($context->contextlevel >= CONTEXT_COURSE) {
         list($context, $course, $cm) = get_context_info_array($context->id);
         require_login($course, false, $cm, false, true);
     }
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:34,代码来源:externallib.php

示例15: 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


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