• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP get_parent_contexts函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: __construct

 public function __construct($stringidentifier, $link, $contextids)
 {
     global $DB;
     $this->records = array();
     foreach ($contextids as $contextid) {
         if (!isset($this->records[$contextid])) {
             $this->records[$contextid] = get_context_instance_by_id($contextid, MUST_EXIST);
         }
         $parents = get_parent_contexts($this->records[$contextid]);
         foreach ($parents as $parentcontextid) {
             if (!isset($this->records[$parentcontextid])) {
                 $this->records[$parentcontextid] = get_context_instance_by_id($parentcontextid, MUST_EXIST);
             }
         }
     }
     $this->make_list_item_instances_from_records($stringidentifier, $link);
 }
开发者ID:ndunand,项目名称:moodle-qtype_ddmarker,代码行数:17,代码来源:questionlists.php


示例17: test_everything_in_accesslib


//.........这里部分代码省略.........
         $this->assertFalse(empty($name));
         $this->assertTrue($context->get_url() instanceof moodle_url);
         $caps = $context->get_capabilities();
         $this->assertTrue(is_array($caps));
         foreach ($caps as $cap) {
             $cap = (array) $cap;
             $this->assertIdentical(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->assertIdentical($frontpagecontext->get_course_context(true), $frontpagecontext);
     $this->assertIdentical($frontpagepagecontext->get_course_context(true), $frontpagecontext);
     $this->assertIdentical($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->assertIdentical($usercontext->get_parent_context(), $systemcontext);
     $this->assertIdentical($usercontext->get_parent_contexts(), array($systemcontext->id => $systemcontext));
     $this->assertIdentical($usercontext->get_parent_contexts(true), array($usercontext->id => $usercontext, $systemcontext->id => $systemcontext));
     $this->assertIdentical($systemcontext->get_parent_contexts(), array());
     $this->assertIdentical($systemcontext->get_parent_contexts(true), array($systemcontext->id => $systemcontext));
     $this->assertIdentical($systemcontext->get_parent_context_ids(), array());
     $this->assertIdentical($systemcontext->get_parent_context_ids(true), array($systemcontext->id));
     $this->assertIdentical($frontpagecontext->get_parent_context(), $systemcontext);
     $this->assertIdentical($frontpagecontext->get_parent_contexts(), array($systemcontext->id => $systemcontext));
     $this->assertIdentical($frontpagecontext->get_parent_contexts(true), array($frontpagecontext->id => $frontpagecontext, $systemcontext->id => $systemcontext));
     $this->assertIdentical($frontpagecontext->get_parent_context_ids(), array($systemcontext->id));
     $this->assertEqual($frontpagecontext->get_parent_context_ids(true), array($frontpagecontext->id, $systemcontext->id));
     $this->assertIdentical($systemcontext->get_parent_context(), false);
     $frontpagecontext = context_course::instance($SITE->id);
     $parent = $systemcontext;
     foreach ($testcategories as $catid) {
         $catcontext = context_coursecat::instance($catid);
         $this->assertIdentical($catcontext->get_parent_context(), $parent);
         $parent = $catcontext;
     }
     $this->assertIdentical($frontpagepagecontext->get_parent_context(), $frontpagecontext);
     $this->assertIdentical($frontpageblockcontext->get_parent_context(), $frontpagecontext);
     $this->assertIdentical($frontpagepageblockcontext->get_parent_context(), $frontpagepagecontext);
     // ====== $context->get_child_contexts() ================================
     $children = $systemcontext->get_child_contexts();
     $this->assertEqual(count($children) + 1, $DB->count_records('context'));
     $context = context_coursecat::instance($testcategories[3]);
     $children = $context->get_child_contexts();
     $countcats = 0;
     $countcourses = 0;
     $countblocks = 0;
     foreach ($children as $child) {
         if ($child->contextlevel == CONTEXT_COURSECAT) {
             $countcats++;
开发者ID:rolandovanegas,项目名称:moodle,代码行数:67,代码来源:fulltestaccesslib.php


示例18: enrol_cohort_search_cohorts

/**
 * Gets cohorts the user is able to view.
 *
 * @global moodle_database $DB
 * @param course_enrolment_manager $manager
 * @param int $offset limit output from
 * @param int $limit items to output per load
 * @param string $search search string
 * @return array    Array(more => bool, offset => int, cohorts => array)
 */
function enrol_cohort_search_cohorts(course_enrolment_manager $manager, $offset = 0, $limit = 25, $search = '')
{
    global $DB;
    $context = $manager->get_context();
    $cohorts = array();
    $instances = $manager->get_enrolment_instances();
    $enrolled = array();
    foreach ($instances as $instance) {
        if ($instance->enrol == 'cohort') {
            $enrolled[] = $instance->customint1;
        }
    }
    list($sqlparents, $params) = $DB->get_in_or_equal(get_parent_contexts($context));
    // Add some additional sensible conditions
    $tests = array('contextid ' . $sqlparents);
    // Modify the quesry to perform the search if requred
    if (!empty($search)) {
        $conditions = array('name', 'idnumber', 'description');
        $searchparam = '%' . $search . '%';
        foreach ($conditions as $key => $condition) {
            $conditions[$key] = $DB->sql_like($condition, "?", false);
            $params[] = $searchparam;
        }
        $tests[] = '(' . implode(' OR ', $conditions) . ')';
    }
    $wherecondition = implode(' AND ', $tests);
    $fields = 'SELECT id, name, contextid, description';
    $countfields = 'SELECT COUNT(1)';
    $sql = " FROM {cohort}\n             WHERE {$wherecondition}";
    $order = ' ORDER BY name ASC';
    $rs = $DB->get_recordset_sql($fields . $sql . $order, $params, $offset);
    // Produce the output respecting parameters
    foreach ($rs as $c) {
        // Track offset
        $offset++;
        // Check capabilities
        $context = get_context_instance_by_id($c->contextid);
        if (!has_capability('moodle/cohort:view', $context)) {
            continue;
        }
        if ($limit === 0) {
            // we have reached the required number of items and know that there are more, exit now
            $offset--;
            break;
        }
        $cohorts[$c->id] = array('cohortid' => $c->id, 'name' => shorten_text(format_string($c->name), 35), 'users' => $DB->count_records('cohort_members', array('cohortid' => $c->id)), 'enrolled' => in_array($c->id, $enrolled));
        // Count items
        $limit--;
    }
    $rs->close();
    return array('more' => !(bool) $limit, 'offset' => $offset, 'cohorts' => $cohorts);
}
开发者ID:rolandovanegas,项目名称:moodle,代码行数:62,代码来源:locallib.php


示例19: get_cohorts

 /**
  * Gets all the cohorts the user is able to view.
  *
  * @global moodle_database $DB
  * @return array
  */
 public function get_cohorts() {
     global $DB;
     $context = $this->get_context();
     $cohorts = array();
     $instances = $this->get_enrolment_instances();
     $enrolled = array();
     foreach ($instances as $instance) {
         if ($instance->enrol == 'cohort') {
             $enrolled[] = $instance->customint1;
         }
     }
     list($sqlparents, $params) = $DB->get_in_or_equal(get_parent_contexts($context));
     $sql = "SELECT id, name, contextid
               FROM {cohort}
              WHERE contextid $sqlparents
           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] = array(
             'cohortid'=>$c->id,
             'name'=>format_string($c->name),
             'users'=>$DB->count_records('cohort_members', array('cohortid'=>$c->id)),
             'enrolled'=>in_array($c->id, $enrolled)
         );
     }
     $rs->close();
     return $cohorts;
 }
开发者ID:nuckey,项目名称:moodle,代码行数:38,代码来源:locallib.php


示例20: get_course_users

该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP get_parent_grade函数代码示例发布时间:2022-05-15
下一篇:
PHP get_parent_contextid函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap