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


PHP moodle_page::set_context方法代码示例

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


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

示例1: get_block_manager

 /**
  * Returns the block manager for a given course.
  */
 private function get_block_manager($course)
 {
     $page = new \moodle_page();
     $page->set_context(\context_course::instance($course->id));
     $page->set_pagetype('course-view-*');
     return new \block_manager($page);
 }
开发者ID:unikent,项目名称:moodle-tool_cat,代码行数:10,代码来源:block_region.php

示例2: xmldb_block_calendar_month_upgrade

/**
 * Upgrade the calendar_month block
 * @param int $oldversion
 * @param object $block
 */
function xmldb_block_calendar_month_upgrade($oldversion, $block)
{
    global $DB;
    if ($oldversion < 2014062600) {
        // Add this block the default blocks on /my.
        $blockname = 'calendar_month';
        // Do not try to add the block if we cannot find the default my_pages entry.
        // Private => 1 refers to MY_PAGE_PRIVATE.
        if ($systempage = $DB->get_record('my_pages', array('userid' => null, 'private' => 1))) {
            $page = new moodle_page();
            $page->set_context(context_system::instance());
            // Check to see if this block is already on the default /my page.
            $criteria = array('blockname' => $blockname, 'parentcontextid' => $page->context->id, 'pagetypepattern' => 'my-index', 'subpagepattern' => $systempage->id);
            if (!$DB->record_exists('block_instances', $criteria)) {
                // Add the block to the default /my.
                $page->blocks->add_region(BLOCK_POS_RIGHT);
                $page->blocks->add_block($blockname, BLOCK_POS_RIGHT, 0, false, 'my-index', $systempage->id);
            }
        }
        upgrade_block_savepoint(true, 2014062600, $blockname);
    }
    // Moodle v2.8.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.9.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v3.0.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v3.1.0 release upgrade line.
    // Put any upgrade step following this.
    return true;
}
开发者ID:evltuma,项目名称:moodle,代码行数:36,代码来源:upgrade.php

示例3: xmldb_block_eexcess_install

/**
 * Adds eexcess block on eexcess user settings pages.
 */
function xmldb_block_eexcess_install()
{
    $page = new moodle_page();
    $page->set_context(context_system::instance());
    $page->blocks->add_region(BLOCK_POS_LEFT);
    $page->blocks->add_block('eexcess', BLOCK_POS_LEFT, 0, false, 'blocks-eexcess-eexcess_citation', null);
    $page->blocks->add_block('eexcess', BLOCK_POS_LEFT, 0, false, 'blocks-eexcess-eexcess_interests', null);
    $page->blocks->add_block('eexcess', BLOCK_POS_LEFT, 0, false, 'blocks-eexcess-eexcess_image_license', null);
}
开发者ID:EEXCESS,项目名称:moodle-block_eexcess,代码行数:12,代码来源:install.php

示例4: testDisplayIndex

 function testDisplayIndex()
 {
     global $USER;
     $this->resetAfterTest(true);
     $PAGE = new moodle_page();
     $PAGE->set_context(context_system::instance());
     $this->setAdminUser();
     $USER->editing = 1;
     $out = "";
     $this->assertContains("something", $out);
 }
开发者ID:matlow,项目名称:taxonomy,代码行数:11,代码来源:indexTest.php

示例5: xmldb_local_iomad_dashboard_install

function xmldb_local_iomad_dashboard_install()
{
    global $SITE;
    // Add some default blocks to the dashboard
    // yes, I know this isn't really what this is for!!
    $systemcontext = context_system::instance();
    $page = new moodle_page();
    $page->set_context($systemcontext);
    $page->set_pagetype('local-iomad-dashboard-index');
    $page->set_pagelayout('mydashboard');
    $page->blocks->add_region('content');
    $defaultblocks = array('side_pre' => array('course_list'), 'content' => array('iomad_company_admin', 'iomad_reports'), 'side_post' => array('news_items'));
    $page->blocks->add_blocks($defaultblocks);
    return true;
}
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:15,代码来源:install.php

示例6: test_update_user_profile_image

 /**
  * Test the update user profile image function.
  */
 public function test_update_user_profile_image()
 {
     global $DB, $CFG;
     // Set the profile image.
     \enrol_lti\helper::update_user_profile_image($this->user1->id, $this->getExternalTestFileUrl('/test.jpg'));
     // Get the new user record.
     $this->user1 = $DB->get_record('user', array('id' => $this->user1->id));
     // Set the page details.
     $page = new moodle_page();
     $page->set_url('/user/profile.php');
     $page->set_context(context_system::instance());
     $renderer = $page->get_renderer('core');
     $usercontext = context_user::instance($this->user1->id);
     // Get the user's profile picture and make sure it is correct.
     $userpicture = new user_picture($this->user1);
     $this->assertSame($CFG->wwwroot . '/pluginfile.php/' . $usercontext->id . '/user/icon/clean/f2?rev=' . $this->user1->picture, $userpicture->get_url($page, $renderer)->out(false));
 }
开发者ID:janeklb,项目名称:moodle,代码行数:20,代码来源:helper_test.php

示例7: xmldb_block_badges_upgrade

/**
 * Upgrade the badges block
 * @param int $oldversion
 * @param object $block
 */
function xmldb_block_badges_upgrade($oldversion, $block)
{
    global $DB;
    if ($oldversion < 2014062600) {
        // Add this block the default blocks on /my.
        $blockname = 'badges';
        $page = new moodle_page();
        $page->set_context(context_system::instance());
        // Check to see if this block is already on the default /my page.
        $criteria = array('blockname' => $blockname, 'parentcontextid' => $page->context->id, 'pagetypepattern' => 'my-index');
        if (!$DB->record_exists('block_instances', $criteria)) {
            // Add the block to the default /my.
            $page->blocks->add_region(BLOCK_POS_RIGHT);
            $page->blocks->add_block($blockname, BLOCK_POS_RIGHT, 0, false, 'my-index');
        }
        upgrade_block_savepoint(true, 2014062600, $blockname);
    }
    return true;
}
开发者ID:abhilash1994,项目名称:moodle,代码行数:24,代码来源:upgrade.php

示例8: process_url_edit

 /**
  * Handle showing/processing the submission from the block editing form.
  * @return boolean true if the form was submitted and the new config saved. Does not
  *      return if the editing form was displayed. False otherwise.
  */
 public function process_url_edit()
 {
     global $CFG, $DB, $PAGE, $OUTPUT;
     $blockid = optional_param('bui_editid', null, PARAM_INT);
     if (!$blockid) {
         return false;
     }
     require_sesskey();
     require_once $CFG->dirroot . '/blocks/edit_form.php';
     $block = $this->find_instance($blockid);
     if (!$block->user_can_edit() && !$this->page->user_can_edit_blocks()) {
         throw new moodle_exception('nopermissions', '', $this->page->url->out(), get_string('editblock'));
     }
     $editpage = new moodle_page();
     $editpage->set_pagelayout('admin');
     $editpage->set_course($this->page->course);
     //$editpage->set_context($block->context);
     $editpage->set_context($this->page->context);
     if ($this->page->cm) {
         $editpage->set_cm($this->page->cm);
     }
     $editurlbase = str_replace($CFG->wwwroot . '/', '/', $this->page->url->out_omit_querystring());
     $editurlparams = $this->page->url->params();
     $editurlparams['bui_editid'] = $blockid;
     $editpage->set_url($editurlbase, $editurlparams);
     $editpage->set_block_actions_done();
     // At this point we are either going to redirect, or display the form, so
     // overwrite global $PAGE ready for this. (Formslib refers to it.)
     $PAGE = $editpage;
     //some functions like MoodleQuickForm::addHelpButton use $OUTPUT so we need to replace that to
     $output = $editpage->get_renderer('core');
     $OUTPUT = $output;
     $formfile = $CFG->dirroot . '/blocks/' . $block->name() . '/edit_form.php';
     if (is_readable($formfile)) {
         require_once $formfile;
         $classname = 'block_' . $block->name() . '_edit_form';
         if (!class_exists($classname)) {
             $classname = 'block_edit_form';
         }
     } else {
         $classname = 'block_edit_form';
     }
     $mform = new $classname($editpage->url, $block, $this->page);
     $mform->set_data($block->instance);
     if ($mform->is_cancelled()) {
         redirect($this->page->url);
     } else {
         if ($data = $mform->get_data()) {
             $bi = new stdClass();
             $bi->id = $block->instance->id;
             // This may get overwritten by the special case handling below.
             $bi->pagetypepattern = $data->bui_pagetypepattern;
             $bi->showinsubcontexts = (bool) $data->bui_contexts;
             if (empty($data->bui_subpagepattern) || $data->bui_subpagepattern == '%@NULL@%') {
                 $bi->subpagepattern = null;
             } else {
                 $bi->subpagepattern = $data->bui_subpagepattern;
             }
             $systemcontext = context_system::instance();
             $frontpagecontext = context_course::instance(SITEID);
             $parentcontext = context::instance_by_id($data->bui_parentcontextid);
             // Updating stickiness and contexts.  See MDL-21375 for details.
             if (has_capability('moodle/site:manageblocks', $parentcontext)) {
                 // Check permissions in destination
                 // Explicitly set the default context
                 $bi->parentcontextid = $parentcontext->id;
                 if ($data->bui_editingatfrontpage) {
                     // The block is being edited on the front page
                     // The interface here is a special case because the pagetype pattern is
                     // totally derived from the context menu.  Here are the excpetions.   MDL-30340
                     switch ($data->bui_contexts) {
                         case BUI_CONTEXTS_ENTIRE_SITE:
                             // The user wants to show the block across the entire site
                             $bi->parentcontextid = $systemcontext->id;
                             $bi->showinsubcontexts = true;
                             $bi->pagetypepattern = '*';
                             break;
                         case BUI_CONTEXTS_FRONTPAGE_SUBS:
                             // The user wants the block shown on the front page and all subcontexts
                             $bi->parentcontextid = $frontpagecontext->id;
                             $bi->showinsubcontexts = true;
                             $bi->pagetypepattern = '*';
                             break;
                         case BUI_CONTEXTS_FRONTPAGE_ONLY:
                             // The user want to show the front page on the frontpage only
                             $bi->parentcontextid = $frontpagecontext->id;
                             $bi->showinsubcontexts = false;
                             $bi->pagetypepattern = 'site-index';
                             // This is the only relevant page type anyway but we'll set it explicitly just
                             // in case the front page grows site-index-* subpages of its own later
                             break;
                     }
                 }
             }
             $bits = explode('-', $bi->pagetypepattern);
//.........这里部分代码省略.........
开发者ID:Burick,项目名称:moodle,代码行数:101,代码来源:blocklib.php

示例9: if

unset($SESSION->theme);

if ($reset and confirm_sesskey()) {
    theme_reset_all_caches();

} else if ($choose && $device && !$unsettheme && confirm_sesskey()) {
    // Load the theme to make sure it is valid.
    $theme = theme_config::load($choose);
    // Get the config argument for the chosen device.
    $themename = get_device_cfg_var_name($device);
    set_config($themename, $theme->name);

    // Create a new page for the display of the themes readme.
    // This ensures that the readme page is shown using the new theme.
    $confirmpage = new moodle_page();
    $confirmpage->set_context($PAGE->context);
    $confirmpage->set_url($PAGE->url);
    $confirmpage->set_pagelayout($PAGE->pagelayout);
    $confirmpage->set_pagetype($PAGE->pagetype);
    $confirmpage->set_title($PAGE->title);
    $confirmpage->set_heading($PAGE->heading);

    // Get the core renderer for the new theme.
    $output = $confirmpage->get_renderer('core');

    echo $output->header();
    echo $output->heading(get_string('themesaved'));
    echo $output->box_start();
    echo format_text(get_string('choosereadme', 'theme_'.$theme->name), FORMAT_MOODLE);
    echo $output->box_end();
    echo $output->continue_button($CFG->wwwroot . '/theme/index.php');
开发者ID:verbazend,项目名称:AWFA,代码行数:31,代码来源:index.php

示例10: test_get_url

 public function test_get_url()
 {
     global $DB, $CFG;
     $this->resetAfterTest();
     // Force SVG on so that we have predictable URL's.
     $CFG->svgicons = true;
     // verify new install contains expected defaults
     $this->assertEquals('standard', $CFG->theme);
     $this->assertEquals(1, $CFG->slasharguments);
     $this->assertEquals(1, $CFG->themerev);
     $this->assertEquals(0, $CFG->themedesignermode);
     $this->assertEquals('http://www.example.com/moodle', $CFG->wwwroot);
     $this->assertEquals($CFG->wwwroot, $CFG->httpswwwroot);
     $this->assertEquals(0, $CFG->enablegravatar);
     $this->assertEquals('mm', $CFG->gravatardefaulturl);
     // create some users
     $page = new moodle_page();
     $page->set_url('/user/profile.php');
     $page->set_context(context_system::instance());
     $renderer = $page->get_renderer('core');
     $user1 = $this->getDataGenerator()->create_user(array('picture' => 11, 'email' => 'user1@example.com'));
     $context1 = context_user::instance($user1->id);
     $user2 = $this->getDataGenerator()->create_user(array('picture' => 0, 'email' => 'user2@example.com'));
     $context2 = context_user::instance($user2->id);
     $user3 = $this->getDataGenerator()->create_user(array('picture' => 1, 'deleted' => 1, 'email' => 'user3@example.com'));
     $context3 = context_user::instance($user3->id, IGNORE_MISSING);
     $this->assertEquals($user3->picture, 0);
     $this->assertNotEquals($user3->email, 'user3@example.com');
     $this->assertFalse($context3);
     // try legacy picture == 1
     $user1->picture = 1;
     $up1 = new user_picture($user1);
     $this->assertEquals($CFG->wwwroot . '/pluginfile.php/' . $context1->id . '/user/icon/standard/f2?rev=1', $up1->get_url($page, $renderer)->out(false));
     $user1->picture = 11;
     // try valid user with picture when user context is not cached - 1 query expected
     context_helper::reset_caches();
     $reads = $DB->perf_get_reads();
     $up1 = new user_picture($user1);
     $this->assertEquals($reads, $DB->perf_get_reads());
     $this->assertEquals($CFG->wwwroot . '/pluginfile.php/' . $context1->id . '/user/icon/standard/f2?rev=11', $up1->get_url($page, $renderer)->out(false));
     $this->assertEquals($reads + 1, $DB->perf_get_reads());
     // try valid user with contextid hint - no queries expected
     $user1->contextid = $context1->id;
     context_helper::reset_caches();
     $reads = $DB->perf_get_reads();
     $up1 = new user_picture($user1);
     $this->assertEquals($reads, $DB->perf_get_reads());
     $this->assertEquals($CFG->wwwroot . '/pluginfile.php/' . $context1->id . '/user/icon/standard/f2?rev=11', $up1->get_url($page, $renderer)->out(false));
     $this->assertEquals($reads, $DB->perf_get_reads());
     // try valid user without image - no queries expected
     context_helper::reset_caches();
     $reads = $DB->perf_get_reads();
     $up2 = new user_picture($user2);
     $this->assertEquals($reads, $DB->perf_get_reads());
     $this->assertEquals($CFG->wwwroot . '/theme/image.php/standard/core/1/u/f2', $up2->get_url($page, $renderer)->out(false));
     $this->assertEquals($reads, $DB->perf_get_reads());
     // try guessing of deleted users - no queries expected
     unset($user3->deleted);
     context_helper::reset_caches();
     $reads = $DB->perf_get_reads();
     $up3 = new user_picture($user3);
     $this->assertEquals($reads, $DB->perf_get_reads());
     $this->assertEquals($CFG->wwwroot . '/theme/image.php/standard/core/1/u/f2', $up3->get_url($page, $renderer)->out(false));
     $this->assertEquals($reads, $DB->perf_get_reads());
     // try incorrectly deleted users (with valid email and pciture flag) - some DB reads expected
     $user3->email = 'user3@example.com';
     $user3->picture = 1;
     $reads = $DB->perf_get_reads();
     $up3 = new user_picture($user3);
     $this->assertEquals($reads, $DB->perf_get_reads());
     $this->assertEquals($CFG->wwwroot . '/theme/image.php/standard/core/1/u/f2', $up3->get_url($page, $renderer)->out(false));
     $this->assertTrue($reads < $DB->perf_get_reads());
     // test gravatar
     set_config('enablegravatar', 1);
     // deleted user can not have gravatar
     $user3->email = 'deleted';
     $user3->picture = 0;
     $up3 = new user_picture($user3);
     $this->assertEquals($CFG->wwwroot . '/theme/image.php/standard/core/1/u/f2', $up3->get_url($page, $renderer)->out(false));
     // verify defaults to misteryman (mm)
     $up2 = new user_picture($user2);
     $this->assertEquals('http://www.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=mm', $up2->get_url($page, $renderer)->out(false));
     // without gravatardefaulturl, verify we pick own file
     set_config('gravatardefaulturl', '');
     $up2 = new user_picture($user2);
     $this->assertEquals('http://www.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=http%3A%2F%2Fwww.example.com%2Fmoodle%2Fpix%2Fu%2Ff2.png', $up2->get_url($page, $renderer)->out(false));
     // uploaded image takes precedence before gravatar
     $up1 = new user_picture($user1);
     $this->assertEquals($CFG->wwwroot . '/pluginfile.php/' . $context1->id . '/user/icon/standard/f2?rev=11', $up1->get_url($page, $renderer)->out(false));
     // https version
     $CFG->httpswwwroot = str_replace('http:', 'https:', $CFG->wwwroot);
     $up1 = new user_picture($user1);
     $this->assertEquals($CFG->httpswwwroot . '/pluginfile.php/' . $context1->id . '/user/icon/standard/f2?rev=11', $up1->get_url($page, $renderer)->out(false));
     $up3 = new user_picture($user3);
     $this->assertEquals($CFG->httpswwwroot . '/theme/image.php/standard/core/1/u/f2', $up3->get_url($page, $renderer)->out(false));
     $up2 = new user_picture($user2);
     $this->assertEquals('https://secure.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=https%3A%2F%2Fwww.example.com%2Fmoodle%2Fpix%2Fu%2Ff2.png', $up2->get_url($page, $renderer)->out(false));
     // now test gravatar with one theme having own images (afterburner)
     $CFG->httpswwwroot = $CFG->wwwroot;
     $this->assertTrue(file_exists("{$CFG->dirroot}/theme/afterburner/config.php"));
//.........这里部分代码省略.........
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:101,代码来源:outputcomponents_test.php

示例11: process_url_edit

 /**
  * Handle showing/processing the submission from the block editing form.
  * @return boolean true if the form was submitted and the new config saved. Does not
  *      return if the editing form was displayed. False otherwise.
  */
 public function process_url_edit()
 {
     global $CFG, $DB, $PAGE;
     $blockid = optional_param('bui_editid', null, PARAM_INTEGER);
     if (!$blockid) {
         return false;
     }
     require_sesskey();
     require_once $CFG->dirroot . '/blocks/edit_form.php';
     $block = $this->find_instance($blockid);
     if (!$block->user_can_edit() && !$this->page->user_can_edit_blocks()) {
         throw new moodle_exception('nopermissions', '', $this->page->url->out(), get_string('editblock'));
     }
     $editpage = new moodle_page();
     $editpage->set_pagelayout('admin');
     $editpage->set_course($this->page->course);
     $editpage->set_context($block->context);
     if ($this->page->cm) {
         $editpage->set_cm($this->page->cm);
     }
     $editurlbase = str_replace($CFG->wwwroot . '/', '/', $this->page->url->out_omit_querystring());
     $editurlparams = $this->page->url->params();
     $editurlparams['bui_editid'] = $blockid;
     $editpage->set_url($editurlbase, $editurlparams);
     $editpage->set_block_actions_done();
     // At this point we are either going to redirect, or display the form, so
     // overwrite global $PAGE ready for this. (Formslib refers to it.)
     $PAGE = $editpage;
     $formfile = $CFG->dirroot . '/blocks/' . $block->name() . '/edit_form.php';
     if (is_readable($formfile)) {
         require_once $formfile;
         $classname = 'block_' . $block->name() . '_edit_form';
         if (!class_exists($classname)) {
             $classname = 'block_edit_form';
         }
     } else {
         $classname = 'block_edit_form';
     }
     $mform = new $classname($editpage->url, $block, $this->page);
     $mform->set_data($block->instance);
     if ($mform->is_cancelled()) {
         redirect($this->page->url);
     } else {
         if ($data = $mform->get_data()) {
             $bi = new stdClass();
             $bi->id = $block->instance->id;
             $bi->pagetypepattern = $data->bui_pagetypepattern;
             if (empty($data->bui_subpagepattern) || $data->bui_subpagepattern == '%@NULL@%') {
                 $bi->subpagepattern = null;
             } else {
                 $bi->subpagepattern = $data->bui_subpagepattern;
             }
             $parentcontext = get_context_instance_by_id($data->bui_parentcontextid);
             $systemcontext = get_context_instance(CONTEXT_SYSTEM);
             // Updating stickiness and contexts.  See MDL-21375 for details.
             if (has_capability('moodle/site:manageblocks', $parentcontext)) {
                 // Check permissions in destination
                 // Explicitly set the context
                 $bi->parentcontextid = $parentcontext->id;
                 // If the context type is > 0 then we'll explicitly set the block as sticky, otherwise not
                 $bi->showinsubcontexts = (int) (!empty($data->bui_contexts));
                 // If the block wants to be system-wide, then explicitly set that
                 if ($data->bui_contexts == 2) {
                     // Only possible on a frontpage or system page
                     $bi->parentcontextid = $systemcontext->id;
                 } else {
                     // The block doesn't want to be system-wide, so let's ensure that
                     if ($parentcontext->id == $systemcontext->id) {
                         // We need to move it to the front page
                         $frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID);
                         $bi->parentcontextid = $frontpagecontext->id;
                         $bi->pagetypepattern = '*';
                         // Just in case
                     }
                 }
             }
             $bi->defaultregion = $data->bui_defaultregion;
             $bi->defaultweight = $data->bui_defaultweight;
             $DB->update_record('block_instances', $bi);
             if (!empty($block->config)) {
                 $config = clone $block->config;
             } else {
                 $config = new stdClass();
             }
             foreach ($data as $configfield => $value) {
                 if (strpos($configfield, 'config_') !== 0) {
                     continue;
                 }
                 $field = substr($configfield, 7);
                 $config->{$field} = $value;
             }
             $block->instance_config_save($config);
             $bp = new stdClass();
             $bp->visible = $data->bui_visible;
             $bp->region = $data->bui_region;
//.........这里部分代码省略.........
开发者ID:vuchannguyen,项目名称:web,代码行数:101,代码来源:blocklib.php

示例12: test_forum_get_context

 /**
  * Test that context fetching returns the appropriate context.
  */
 public function test_forum_get_context()
 {
     global $DB, $PAGE;
     $this->resetAfterTest();
     // Setup test data.
     $course = $this->getDataGenerator()->create_course();
     $coursecontext = \context_course::instance($course->id);
     $options = array('course' => $course->id, 'forcesubscribe' => FORUM_CHOOSESUBSCRIBE);
     $forum = $this->getDataGenerator()->create_module('forum', $options);
     $forumcm = get_coursemodule_from_instance('forum', $forum->id);
     $forumcontext = \context_module::instance($forumcm->id);
     // First check that specifying the context results in the correct context being returned.
     // Do this before we set up the page object and we should return from the coursemodule record.
     // There should be no DB queries here because the context type was correct.
     $startcount = $DB->perf_get_reads();
     $result = forum_get_context($forum->id, $forumcontext);
     $aftercount = $DB->perf_get_reads();
     $this->assertEquals($forumcontext, $result);
     $this->assertEquals(0, $aftercount - $startcount);
     // And a context which is not the correct type.
     // This tests will result in a DB query to fetch the course_module.
     $startcount = $DB->perf_get_reads();
     $result = forum_get_context($forum->id, $coursecontext);
     $aftercount = $DB->perf_get_reads();
     $this->assertEquals($forumcontext, $result);
     $this->assertEquals(1, $aftercount - $startcount);
     // Now do not specify a context at all.
     // This tests will result in a DB query to fetch the course_module.
     $startcount = $DB->perf_get_reads();
     $result = forum_get_context($forum->id);
     $aftercount = $DB->perf_get_reads();
     $this->assertEquals($forumcontext, $result);
     $this->assertEquals(1, $aftercount - $startcount);
     // Set up the default page event to use the forum.
     $PAGE = new moodle_page();
     $PAGE->set_context($forumcontext);
     $PAGE->set_cm($forumcm, $course, $forum);
     // Now specify a context which is not a context_module.
     // There should be no DB queries here because we use the PAGE.
     $startcount = $DB->perf_get_reads();
     $result = forum_get_context($forum->id, $coursecontext);
     $aftercount = $DB->perf_get_reads();
     $this->assertEquals($forumcontext, $result);
     $this->assertEquals(0, $aftercount - $startcount);
     // Now do not specify a context at all.
     // There should be no DB queries here because we use the PAGE.
     $startcount = $DB->perf_get_reads();
     $result = forum_get_context($forum->id);
     $aftercount = $DB->perf_get_reads();
     $this->assertEquals($forumcontext, $result);
     $this->assertEquals(0, $aftercount - $startcount);
     // Now specify the page context of the course instead..
     $PAGE = new moodle_page();
     $PAGE->set_context($coursecontext);
     // Now specify a context which is not a context_module.
     // This tests will result in a DB query to fetch the course_module.
     $startcount = $DB->perf_get_reads();
     $result = forum_get_context($forum->id, $coursecontext);
     $aftercount = $DB->perf_get_reads();
     $this->assertEquals($forumcontext, $result);
     $this->assertEquals(1, $aftercount - $startcount);
     // Now do not specify a context at all.
     // This tests will result in a DB query to fetch the course_module.
     $startcount = $DB->perf_get_reads();
     $result = forum_get_context($forum->id);
     $aftercount = $DB->perf_get_reads();
     $this->assertEquals($forumcontext, $result);
     $this->assertEquals(1, $aftercount - $startcount);
 }
开发者ID:rushi963,项目名称:moodle,代码行数:72,代码来源:lib_test.php

示例13: get_a_page_and_block_manager

    protected function get_a_page_and_block_manager($regions, $context, $pagetype, $subpage = '') {
        $page = new moodle_page;
        $page->set_context($context);
        $page->set_pagetype($pagetype);
        $page->set_subpage($subpage);

        $blockmanager = new testable_block_manager($page);
        $blockmanager->add_regions($regions);
        $blockmanager->set_default_region($regions[0]);

        return array($page, $blockmanager);
    }
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:12,代码来源:blocklib_test.php

示例14: test_forum_subscription_page_context_valid

 /**
  * Test that the correct context is used in the events when subscribing
  * users.
  */
 public function test_forum_subscription_page_context_valid()
 {
     global $CFG, $PAGE;
     require_once $CFG->dirroot . '/mod/forum/lib.php';
     // Setup test data.
     $course = $this->getDataGenerator()->create_course();
     $user = $this->getDataGenerator()->create_user();
     $this->getDataGenerator()->enrol_user($user->id, $course->id);
     $options = array('course' => $course->id, 'forcesubscribe' => FORUM_CHOOSESUBSCRIBE);
     $forum = $this->getDataGenerator()->create_module('forum', $options);
     $quiz = $this->getDataGenerator()->create_module('quiz', $options);
     // Add a discussion.
     $record = array();
     $record['course'] = $course->id;
     $record['forum'] = $forum->id;
     $record['userid'] = $user->id;
     $discussion = $this->getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
     // Add a post.
     $record = array();
     $record['discussion'] = $discussion->id;
     $record['userid'] = $user->id;
     $post = $this->getDataGenerator()->get_plugin_generator('mod_forum')->create_post($record);
     // Set up the default page event to use this forum.
     $PAGE = new moodle_page();
     $cm = get_coursemodule_from_instance('forum', $discussion->forum);
     $context = \context_module::instance($cm->id);
     $PAGE->set_context($context);
     $PAGE->set_cm($cm, $course, $forum);
     // Trigger and capturing the event.
     $sink = $this->redirectEvents();
     // Trigger the event by subscribing the user to the forum.
     \mod_forum\subscriptions::subscribe_user($user->id, $forum);
     $events = $sink->get_events();
     $sink->clear();
     $this->assertCount(1, $events);
     $event = reset($events);
     // Checking that the event contains the expected values.
     $this->assertInstanceOf('\\mod_forum\\event\\subscription_created', $event);
     $this->assertEquals($context, $event->get_context());
     // Trigger the event by unsubscribing the user to the forum.
     \mod_forum\subscriptions::unsubscribe_user($user->id, $forum);
     $events = $sink->get_events();
     $sink->clear();
     $this->assertCount(1, $events);
     $event = reset($events);
     // Checking that the event contains the expected values.
     $this->assertInstanceOf('\\mod_forum\\event\\subscription_deleted', $event);
     $this->assertEquals($context, $event->get_context());
     // Trigger the event by subscribing the user to the discussion.
     \mod_forum\subscriptions::subscribe_user_to_discussion($user->id, $discussion);
     $events = $sink->get_events();
     $sink->clear();
     $this->assertCount(1, $events);
     $event = reset($events);
     // Checking that the event contains the expected values.
     $this->assertInstanceOf('\\mod_forum\\event\\discussion_subscription_created', $event);
     $this->assertEquals($context, $event->get_context());
     // Trigger the event by unsubscribing the user from the discussion.
     \mod_forum\subscriptions::unsubscribe_user_from_discussion($user->id, $discussion);
     $events = $sink->get_events();
     $sink->clear();
     $this->assertCount(1, $events);
     $event = reset($events);
     // Checking that the event contains the expected values.
     $this->assertInstanceOf('\\mod_forum\\event\\discussion_subscription_deleted', $event);
     $this->assertEquals($context, $event->get_context());
     // Now try with the context for a different module (quiz).
     $PAGE = new moodle_page();
     $cm = get_coursemodule_from_instance('quiz', $quiz->id);
     $quizcontext = \context_module::instance($cm->id);
     $PAGE->set_context($quizcontext);
     $PAGE->set_cm($cm, $course, $quiz);
     // Trigger and capturing the event.
     $sink = $this->redirectEvents();
     // Trigger the event by subscribing the user to the forum.
     \mod_forum\subscriptions::subscribe_user($user->id, $forum);
     $events = $sink->get_events();
     $sink->clear();
     $this->assertCount(1, $events);
     $event = reset($events);
     // Checking that the event contains the expected values.
     $this->assertInstanceOf('\\mod_forum\\event\\subscription_created', $event);
     $this->assertEquals($context, $event->get_context());
     // Trigger the event by unsubscribing the user to the forum.
     \mod_forum\subscriptions::unsubscribe_user($user->id, $forum);
     $events = $sink->get_events();
     $sink->clear();
     $this->assertCount(1, $events);
     $event = reset($events);
     // Checking that the event contains the expected values.
     $this->assertInstanceOf('\\mod_forum\\event\\subscription_deleted', $event);
     $this->assertEquals($context, $event->get_context());
     // Trigger the event by subscribing the user to the discussion.
     \mod_forum\subscriptions::subscribe_user_to_discussion($user->id, $discussion);
     $events = $sink->get_events();
     $sink->clear();
//.........这里部分代码省略.........
开发者ID:Keneth1212,项目名称:moodle,代码行数:101,代码来源:events_test.php

示例15: process_url_edit

 /**
  * Handle showing/processing the submission from the block editing form.
  * @return boolean true if the form was submitted and the new config saved. Does not
  *      return if the editing form was displayed. False otherwise.
  */
 public function process_url_edit()
 {
     global $CFG, $DB, $PAGE;
     $blockid = optional_param('bui_editid', null, PARAM_INTEGER);
     if (!$blockid) {
         return false;
     }
     confirm_sesskey();
     require_once $CFG->dirroot . '/blocks/edit_form.php';
     $block = $this->find_instance($blockid);
     if (!$block->user_can_edit() && !$this->page->user_can_edit_blocks()) {
         throw new moodle_exception('nopermissions', '', $this->page->url->out(), get_string('editblock'));
     }
     $editpage = new moodle_page();
     $editpage->set_generaltype('form');
     $editpage->set_course($this->page->course);
     $editpage->set_context($block->context);
     $editurlbase = str_replace($CFG->wwwroot . '/', '', $this->page->url->out(true));
     $editurlparams = $this->page->url->params();
     $editurlparams['bui_editid'] = $blockid;
     $editpage->set_url($editurlbase, $editurlparams);
     $editpage->_block_actions_done = true;
     // At this point we are either going to redirect, or display the form, so
     // overwrite global $PAGE ready for this. (Formslib refers to it.)
     $PAGE = $editpage;
     $formfile = $CFG->dirroot . '/blocks/' . $block->name() . '/edit_form.php';
     if (is_readable($formfile)) {
         require_once $formfile;
         $classname = 'block_' . $block->name() . '_edit_form';
     } else {
         $classname = 'block_edit_form';
     }
     $mform = new $classname($editpage->url, $block, $this->page);
     $mform->set_data($block->instance);
     if ($mform->is_cancelled()) {
         redirect($this->page->url);
     } else {
         if ($data = $mform->get_data()) {
             $bi = new stdClass();
             $bi->id = $block->instance->id;
             $bi->showinsubcontexts = $data->bui_showinsubcontexts;
             $bi->pagetypepattern = $data->bui_pagetypepattern;
             if (empty($data->bui_subpagepattern) || $data->bui_subpagepattern == '%@NULL@%') {
                 $bi->subpagepattern = null;
             } else {
                 $bi->subpagepattern = $data->bui_subpagepattern;
             }
             $bi->defaultregion = $data->bui_defaultregion;
             $bi->defaultweight = $data->bui_defaultweight;
             $DB->update_record('block_instances', $bi);
             if (!empty($block->config)) {
                 $config = clone $block->config;
             } else {
                 $config = new stdClass();
             }
             foreach ($data as $configfield => $value) {
                 if (strpos($configfield, 'config_') !== 0) {
                     continue;
                 }
                 $field = substr($configfield, 7);
                 $config->{$field} = $value;
             }
             $block->instance_config_save($config);
             $bp = new stdClass();
             $bp->visible = $data->bui_visible;
             $bp->region = $data->bui_region;
             $bp->weight = $data->bui_weight;
             $needbprecord = !$data->bui_visible || $data->bui_region != $data->bui_defaultregion || $data->bui_weight != $data->bui_defaultweight;
             if ($block->instance->blockpositionid && !$needbprecord) {
                 $DB->delete_records('block_positions', array('id' => $block->instance->blockpositionid));
             } else {
                 if ($block->instance->blockpositionid && $needbprecord) {
                     $bp->id = $block->instance->blockpositionid;
                     $DB->update_record('block_positions', $bp);
                 } else {
                     if ($needbprecord) {
                         $bp->blockinstanceid = $block->instance->id;
                         $bp->contextid = $this->page->context->id;
                         $bp->pagetype = $this->page->pagetype;
                         if ($this->page->subpage) {
                             $bp->subpage = $this->page->subpage;
                         } else {
                             $bp->subpage = '';
                         }
                         $DB->insert_record('block_positions', $bp);
                     }
                 }
             }
             redirect($this->page->url);
         } else {
             $strheading = get_string('editinga', $block->name());
             if (strpos($strheading, '[[') === 0) {
                 $strheading = get_string('blockconfiga', 'moodle', $block->get_title());
             }
             $editpage->set_title($strheading);
//.........这里部分代码省略.........
开发者ID:ajv,项目名称:Offline-Caching,代码行数:101,代码来源:blocklib.php


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