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


PHP context_helper::get_level_name方法代码示例

本文整理汇总了PHP中context_helper::get_level_name方法的典型用法代码示例。如果您正苦于以下问题:PHP context_helper::get_level_name方法的具体用法?PHP context_helper::get_level_name怎么用?PHP context_helper::get_level_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在context_helper的用法示例。


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

示例1: get_capabitity_optgroups

 protected function get_capabitity_optgroups()
 {
     if (!empty($this->_optGroups)) {
         // I have absolutely no idea why this is necessary, but it does seem to be.
         // Bloody formslib. Somehow it is calling the constructor twice.
         return array();
     }
     $optgroups = array();
     $capabilities = context_system::instance()->get_capabilities();
     $contextlevel = 0;
     $component = '';
     $currentgroup = array();
     $currentgroupname = '';
     foreach ($capabilities as $capability) {
         // Start a new optgroup if the componentname or context level has changed.
         if (component_level_changed($capability, $component, $contextlevel)) {
             if ($currentgroup) {
                 $optgroups[$currentgroupname] = $currentgroup;
             }
             $currentgroup = array();
             $currentgroupname = context_helper::get_level_name($capability->contextlevel) . ': ' . get_component_string($capability->component, $capability->contextlevel);
         }
         $contextlevel = $capability->contextlevel;
         $component = $capability->component;
         $a = new stdClass();
         $a->name = get_capability_string($capability->name);
         $a->capabilityname = $capability->name;
         $currentgroup[$capability->name] = get_string('capabilityandname', 'tool_editrolesbycap', $a);
     }
     // Remeber to add the currently open optgroup.
     if ($currentgroup) {
         $optgroups[$currentgroupname] = $currentgroup;
     }
     return $optgroups;
 }
开发者ID:Keneth1212,项目名称:moodle,代码行数:35,代码来源:capabilityformfield.php

示例2: __construct

 public function __construct($context, $roleid)
 {
     $this->roleid = $roleid;
     parent::__construct($context, 'defineroletable', $roleid);
     $this->displaypermissions = $this->allpermissions;
     $this->strperms[$this->allpermissions[CAP_INHERIT]] = get_string('notset', 'core_role');
     $this->allcontextlevels = array();
     $levels = context_helper::get_all_levels();
     foreach ($levels as $level => $classname) {
         $this->allcontextlevels[$level] = context_helper::get_level_name($level);
     }
 }
开发者ID:Gavinthisisit,项目名称:Moodle,代码行数:12,代码来源:define_role_table_advanced.php

示例3: get_contextlevel_name

/**
 * Returns context level name
 * @deprecated since 2.2
 * @param integer $contextlevel $context->context level. One of the CONTEXT_... constants.
 * @return string the name for this type of context.
 */
function get_contextlevel_name($contextlevel)
{
    return context_helper::get_level_name($contextlevel);
}
开发者ID:rolandovanegas,项目名称:moodle,代码行数:10,代码来源:accesslib.php

示例4: get_context

    /**
     * Gets the internal context id from the context reference.
     *
     * The context reference changes depending on the context
     * level, it can be the system, a user, a category, a course or
     * a module.
     *
     * @throws Exception
     * @param string $levelname The context level string introduced by the test writer
     * @param string $contextref The context reference introduced by the test writer
     * @return context
     */
    protected function get_context($levelname, $contextref) {
        global $DB;

        // Getting context levels and names (we will be using the English ones as it is the test site language).
        $contextlevels = context_helper::get_all_levels();
        $contextnames = array();
        foreach ($contextlevels as $level => $classname) {
            $contextnames[context_helper::get_level_name($level)] = $level;
        }

        if (empty($contextnames[$levelname])) {
            throw new Exception('The specified "' . $levelname . '" context level does not exist');
        }
        $contextlevel = $contextnames[$levelname];

        // Return it, we don't need to look for other internal ids.
        if ($contextlevel == CONTEXT_SYSTEM) {
            return context_system::instance();
        }

        switch ($contextlevel) {

            case CONTEXT_USER:
                $instanceid = $DB->get_field('user', 'id', array('username' => $contextref));
                break;

            case CONTEXT_COURSECAT:
                $instanceid = $DB->get_field('course_categories', 'id', array('idnumber' => $contextref));
                break;

            case CONTEXT_COURSE:
                $instanceid = $DB->get_field('course', 'id', array('shortname' => $contextref));
                break;

            case CONTEXT_MODULE:
                $instanceid = $DB->get_field('course_modules', 'id', array('idnumber' => $contextref));
                break;

            default:
                break;
        }

        $contextclass = $contextlevels[$contextlevel];
        if (!$context = $contextclass::instance($instanceid, IGNORE_MISSING)) {
            throw new Exception('The specified "' . $contextref . '" context reference does not exist');
        }

        return $context;
    }
开发者ID:nagyistoce,项目名称:moodle,代码行数:61,代码来源:behat_data_generators.php

示例5: get_contextlevel_name

/**
 * Returns context level name
 *
 * @deprecated since 2.2
 * @see context_helper::get_level_name()
 * @param integer $contextlevel $context->context level. One of the CONTEXT_... constants.
 * @return string the name for this type of context.
 */
function get_contextlevel_name($contextlevel)
{
    debugging('get_contextlevel_name() is deprecated, please use context_helper::get_level_name() instead.', DEBUG_DEVELOPER);
    return context_helper::get_level_name($contextlevel);
}
开发者ID:Hirenvaghasiya,项目名称:moodle,代码行数:13,代码来源:deprecatedlib.php

示例6: test_everything_in_accesslib


//.........这里部分代码省略.........
                $manualenrol->add_default_instance($DB->get_record('course', array('id'=>$course->id)));

                // Add block to each course
                $bi = $generator->create_block('online_users', array('parentcontextid'=>$coursecontext->id));
                $testblocks[] = $bi->id;

                // Add a resource to each course
                $page = $generator->create_module('page', array('course'=>$course->id));
                $testpages[] = $page->id;
                $modcontext = context_module::instance($page->cmid);

                // Add block to each module
                $bi = $generator->create_block('online_users', array('parentcontextid'=>$modcontext->id));
                $testblocks[] = $bi->id;
            }
        }

        // Make sure all contexts were created properly
        $count = 1; //system
        $count += $DB->count_records('user', array('deleted'=>0));
        $count += $DB->count_records('course_categories');
        $count += $DB->count_records('course');
        $count += $DB->count_records('course_modules');
        $count += $DB->count_records('block_instances');
        $this->assertEquals($DB->count_records('context'), $count);
        $this->assertEquals($DB->count_records('context', array('depth'=>0)), 0);
        $this->assertEquals($DB->count_records('context', array('path'=>NULL)), 0);


        // ====== context_helper::get_level_name() ================================

        $levels = context_helper::get_all_levels();
        foreach ($levels as $level=>$classname) {
            $name = context_helper::get_level_name($level);
            $this->assertFalse(empty($name));
        }


        // ======= context::instance_by_id(), context_xxx::instance();

        $context = context::instance_by_id($frontpagecontext->id);
        $this->assertSame($context->contextlevel, CONTEXT_COURSE);
        $this->assertFalse(context::instance_by_id(-1, IGNORE_MISSING));
        try {
            context::instance_by_id(-1);
            $this->fail('exception expected');
        } catch (Exception $e) {
            $this->assertTrue(true);
        }
        $this->assertTrue(context_system::instance() instanceof context_system);
        $this->assertTrue(context_coursecat::instance($testcategories[0]) instanceof context_coursecat);
        $this->assertTrue(context_course::instance($testcourses[0]) instanceof context_course);
        $this->assertTrue(context_module::instance($testpages[0]) instanceof context_module);
        $this->assertTrue(context_block::instance($testblocks[0]) instanceof context_block);

        $this->assertFalse(context_coursecat::instance(-1, IGNORE_MISSING));
        $this->assertFalse(context_course::instance(-1, IGNORE_MISSING));
        $this->assertFalse(context_module::instance(-1, IGNORE_MISSING));
        $this->assertFalse(context_block::instance(-1, IGNORE_MISSING));
        try {
            context_coursecat::instance(-1);
            $this->fail('exception expected');
        } catch (Exception $e) {
            $this->assertTrue(true);
        }
        try {
开发者ID:numbas,项目名称:moodle,代码行数:67,代码来源:accesslib_test.php

示例7: this_con_group_name

 protected function this_con_group_name($search, $numusers)
 {
     if ($this->context->contextlevel == CONTEXT_SYSTEM) {
         // Special case in the System context.
         if ($search) {
             return get_string('extusersmatching', 'core_role', $search);
         } else {
             return get_string('extusers', 'core_role');
         }
     }
     $contexttype = context_helper::get_level_name($this->context->contextlevel);
     if ($search) {
         $a = new stdClass();
         $a->search = $search;
         $a->contexttype = $contexttype;
         if ($numusers) {
             return get_string('usersinthisxmatching', 'core_role', $a);
         } else {
             return get_string('noneinthisxmatching', 'core_role', $a);
         }
     } else {
         if ($numusers) {
             return get_string('usersinthisx', 'core_role', $contexttype);
         } else {
             return get_string('noneinthisx', 'core_role', $contexttype);
         }
     }
 }
开发者ID:pzhu2004,项目名称:moodle,代码行数:28,代码来源:existing_role_holders.php

示例8: COUNT

echo $OUTPUT->heading(get_string('pluginname', 'tool_unsuproles'));
$sql = "SELECT r.id AS roleid, c.contextlevel, r.sortorder, COUNT(ra.id) AS racount\n          FROM {role} r\n          JOIN {role_assignments} ra ON ra.roleid = r.id\n          JOIN {context} c ON c.id = ra.contextid\n     LEFT JOIN {role_context_levels} rcl ON (rcl.roleid = r.id AND rcl.contextlevel = c.contextlevel)\n         WHERE rcl.id IS NULL\n      GROUP BY r.id, c.contextlevel, r.sortorder\n      ORDER BY c.contextlevel ASC, r.sortorder ASC";
//print the overview table
$problems = array();
$rs = $DB->get_recordset_sql($sql);
foreach ($rs as $problem) {
    $problems[] = $problem;
}
$rs->close();
if (!$problems) {
    echo $OUTPUT->notification(get_string('noprolbems', 'tool_unsuproles'), 'notifysuccess');
} else {
    $roles = get_all_roles();
    $data = array();
    foreach ($problems as $problem) {
        $levelname = context_helper::get_level_name($problem->contextlevel);
        $rolename = role_get_name($roles[$problem->roleid]);
        //TODO: show list of users if count low
        $count = $problem->racount;
        $edit = array();
        $aurl = new moodle_url('/admin/roles/define.php', array('roleid' => $problem->roleid, 'action' => 'edit'));
        $edit[] = html_writer::link($aurl, html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/edit'), 'alt' => get_string('edit'), 'class' => 'smallicon')));
        $aurl = new moodle_url($PAGE->url, array('roleid' => $problem->roleid, 'contextlevel' => $problem->contextlevel, 'action' => 'delete'));
        $edit[] = html_writer::link($aurl, html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/delete'), 'alt' => get_string('delete'), 'class' => 'smallicon')));
        $data[] = array($levelname, $rolename, $count, implode(' ', $edit));
    }
    $table = new html_table();
    $table->head = array(get_string('contextlevel', 'tool_unsuproles'), get_string('role'), get_string('count', 'tool_unsuproles'), get_string('edit'));
    $table->size = array('40%', '40%', '10%', '10%');
    $table->align = array('left', 'left', 'center', 'center');
    $table->width = '90%';
开发者ID:alanaipe2015,项目名称:moodle,代码行数:31,代码来源:index.php

示例9: test_everything_in_accesslib


//.........这里部分代码省略.........
             $bi->parentcontextid = $coursecontext->id;
             $biid = $DB->insert_record('block_instances', $bi);
             context_block::instance($biid);
             $testblocks[] = $biid;
             // Add a resource to each course
             $page->course = $courseid;
             $pageid = $DB->insert_record('page', $page);
             $testpages[] = $pageid;
             $cm->course = $courseid;
             $cm->instance = $pageid;
             $cm->id = $DB->insert_record('course_modules', $cm);
             $modcontext = context_module::instance($cm->id);
             // Add block to each module
             $bi->parentcontextid = $modcontext->id;
             $biid = $DB->insert_record('block_instances', $bi);
             context_block::instance($biid);
             $testblocks[] = $biid;
         }
     }
     // Make sure all contexts were created properly
     $count = 1;
     //system
     $count += $DB->count_records('user', array('deleted' => 0));
     $count += $DB->count_records('course_categories');
     $count += $DB->count_records('course');
     $count += $DB->count_records('course_modules');
     $count += $DB->count_records('block_instances');
     $this->assertEqual($DB->count_records('context'), $count);
     $this->assertEqual($DB->count_records('context', array('depth' => 0)), 0);
     $this->assertEqual($DB->count_records('context', array('path' => NULL)), 0);
     // ====== context_helper::get_level_name() ================================
     $levels = context_helper::get_all_levels();
     foreach ($levels as $level => $classname) {
         $name = context_helper::get_level_name($level);
         $this->assertFalse(empty($name));
     }
     // ======= context::instance_by_id(), context_xxx::instance();
     $context = context::instance_by_id($frontpagecontext->id);
     $this->assertidentical($context->contextlevel, CONTEXT_COURSE);
     $this->assertFalse(context::instance_by_id(-1, IGNORE_MISSING));
     try {
         context::instance_by_id(-1);
         $this->fail('exception expected');
     } catch (Exception $e) {
         $this->assertTrue(true);
     }
     $this->assertTrue(context_system::instance() instanceof context_system);
     $this->assertTrue(context_coursecat::instance($testcategories[0]) instanceof context_coursecat);
     $this->assertTrue(context_course::instance($testcourses[0]) instanceof context_course);
     $this->assertTrue(context_module::instance($testpages[0]) instanceof context_module);
     $this->assertTrue(context_block::instance($testblocks[0]) instanceof context_block);
     $this->assertFalse(context_coursecat::instance(-1, IGNORE_MISSING));
     $this->assertFalse(context_course::instance(-1, IGNORE_MISSING));
     $this->assertFalse(context_module::instance(-1, IGNORE_MISSING));
     $this->assertFalse(context_block::instance(-1, IGNORE_MISSING));
     try {
         context_coursecat::instance(-1);
         $this->fail('exception expected');
     } catch (Exception $e) {
         $this->assertTrue(true);
     }
     try {
         context_course::instance(-1);
         $this->fail('exception expected');
     } catch (Exception $e) {
         $this->assertTrue(true);
开发者ID:rolandovanegas,项目名称:moodle,代码行数:67,代码来源:fulltestaccesslib.php


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