コード例 #1
0
 /**
  * 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);
 }
コード例 #2
0
ファイル: upgrade.php プロジェクト: evltuma/moodle
/**
 * 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;
}
コード例 #3
0
/**
 * 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);
}
コード例 #4
0
ファイル: indexTest.php プロジェクト: matlow/taxonomy
 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);
 }
コード例 #5
0
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;
}
コード例 #6
0
ファイル: helper_test.php プロジェクト: janeklb/moodle
 /**
  * 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));
 }
コード例 #7
0
ファイル: upgrade.php プロジェクト: abhilash1994/moodle
/**
 * 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;
}
コード例 #8
0
ファイル: blocklib.php プロジェクト: Burick/moodle
 /**
  * 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);
             // hacks for some contexts
             if ($parentcontext->contextlevel == CONTEXT_COURSE && $parentcontext->instanceid != SITEID) {
                 // For course context
                 // is page type pattern is mod-*, change showinsubcontext to 1
                 if ($bits[0] == 'mod' || $bi->pagetypepattern == '*') {
                     $bi->showinsubcontexts = 1;
                 } else {
                     $bi->showinsubcontexts = 0;
                 }
             } else {
                 if ($parentcontext->contextlevel == CONTEXT_USER) {
                     // for user context
                     // subpagepattern should be null
                     if ($bits[0] == 'user' or $bits[0] == 'my') {
                         // we don't need subpagepattern in usercontext
                         $bi->subpagepattern = null;
                     }
                 }
             }
             $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('blockconfiga', 'moodle', $block->get_title());
             $editpage->set_title($strheading);
             $editpage->set_heading($strheading);
             $bits = explode('-', $this->page->pagetype);
             if ($bits[0] == 'tag' && !empty($this->page->subpage)) {
                 // better navbar for tag pages
                 $editpage->navbar->add(get_string('tags'), new moodle_url('/tag/'));
                 $tag = tag_get('id', $this->page->subpage, '*');
                 // tag search page doesn't have subpageid
                 if ($tag) {
                     $editpage->navbar->add($tag->name, new moodle_url('/tag/index.php', array('id' => $tag->id)));
                 }
             }
             $editpage->navbar->add($block->get_title());
             $editpage->navbar->add(get_string('configuration'));
             echo $output->header();
             echo $output->heading($strheading, 2);
             $mform->display();
             echo $output->footer();
             exit;
         }
     }
 }
コード例 #9
0
ファイル: index.php プロジェクト: verbazend/AWFA
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');
コード例 #10
0
 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' => '*****@*****.**'));
     $context1 = context_user::instance($user1->id);
     $user2 = $this->getDataGenerator()->create_user(array('picture' => 0, 'email' => '*****@*****.**'));
     $context2 = context_user::instance($user2->id);
     $user3 = $this->getDataGenerator()->create_user(array('picture' => 1, 'deleted' => 1, 'email' => '*****@*****.**'));
     $context3 = context_user::instance($user3->id, IGNORE_MISSING);
     $this->assertEquals($user3->picture, 0);
     $this->assertNotEquals($user3->email, '*****@*****.**');
     $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->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"));
     set_config('theme', 'afterburner');
     $page = new moodle_page();
     $page->set_url('/user/profile.php');
     $page->set_context(context_system::instance());
     $renderer = $page->get_renderer('core');
     $up2 = new user_picture($user2);
     $this->assertEquals('http://www.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=http%3A%2F%2Fwww.example.com%2Fmoodle%2Ftheme%2Fafterburner%2Fpix_core%2Fu%2Ff2.png', $up2->get_url($page, $renderer)->out(false));
     // https version
     $CFG->httpswwwroot = str_replace('http:', 'https:', $CFG->wwwroot);
     $up2 = new user_picture($user2);
     $this->assertEquals('https://secure.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=https%3A%2F%2Fwww.example.com%2Fmoodle%2Ftheme%2Fafterburner%2Fpix_core%2Fu%2Ff2.png', $up2->get_url($page, $renderer)->out(false));
     // end of gravatar tests
     // test themed images
     set_config('enablegravatar', 0);
     $this->assertTrue(file_exists("{$CFG->dirroot}/theme/formal_white/config.php"));
     // use any other theme
     set_config('theme', 'formal_white');
     $CFG->httpswwwroot = $CFG->wwwroot;
     $page = new moodle_page();
     $page->set_url('/user/profile.php');
     $page->set_context(context_system::instance());
     $renderer = $page->get_renderer('core');
     $up1 = new user_picture($user1);
     $this->assertEquals($CFG->wwwroot . '/pluginfile.php/' . $context1->id . '/user/icon/formal_white/f2?rev=11', $up1->get_url($page, $renderer)->out(false));
     $up2 = new user_picture($user2);
     $this->assertEquals($CFG->wwwroot . '/theme/image.php/formal_white/core/1/u/f2', $up2->get_url($page, $renderer)->out(false));
     // test non-slashargument images
     set_config('theme', 'standard');
     $CFG->httpswwwroot = $CFG->wwwroot;
     $CFG->slasharguments = 0;
     $page = new moodle_page();
     $page->set_url('/user/profile.php');
     $page->set_context(context_system::instance());
     $renderer = $page->get_renderer('core');
     $up3 = new user_picture($user3);
     $this->assertEquals($CFG->wwwroot . '/theme/image.php?theme=standard&component=core&rev=1&image=u%2Ff2', $up3->get_url($page, $renderer)->out(false));
 }
コード例 #11
0
ファイル: blocklib.php プロジェクト: vuchannguyen/web
 /**
  * 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;
             $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('blockconfiga', 'moodle', $block->get_title());
             $editpage->set_title($strheading);
             $editpage->set_heading($strheading);
             $editpage->navbar->add($strheading);
             $output = $editpage->get_renderer('core');
             echo $output->header();
             echo $output->heading($strheading, 2);
             $mform->display();
             echo $output->footer();
             exit;
         }
     }
 }
コード例 #12
0
ファイル: lib_test.php プロジェクト: rushi963/moodle
 /**
  * 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);
 }
コード例 #13
0
ファイル: blocklib_test.php プロジェクト: Jtgadbois/Pedadida
    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);
    }
コード例 #14
0
ファイル: events_test.php プロジェクト: Keneth1212/moodle
 /**
  * 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();
     $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 course context - the module context should still be used.
     $PAGE = new moodle_page();
     $coursecontext = \context_course::instance($course->id);
     $PAGE->set_context($coursecontext);
     // 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());
 }
コード例 #15
0
ファイル: blocklib.php プロジェクト: ajv/Offline-Caching
 /**
  * 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);
             $editpage->set_heading($strheading);
             $output = $editpage->theme->get_renderer('core', $editpage);
             echo $output->header();
             echo $output->heading($strheading, 2);
             $mform->display();
             echo $output->footer();
             exit;
         }
     }
 }
コード例 #16
0
/**
 * Add the default system-context blocks. E.g. the admin tree.
 */
function blocks_add_default_system_blocks()
{
    $page = new moodle_page();
    $page->set_context(get_context_instance(CONTEXT_SYSTEM));
    $page->blocks->add_blocks(array(BLOCK_POS_LEFT => array('admin_tree', 'admin_bookmarks')), 'admin-*');
}
コード例 #17
0
 /**
  * Update attendee.
  *
  * @throws \coding_exception
  */
 protected function api_update_attendee()
 {
     $sessionid = $this->collaborate->sessionid;
     if (has_capability('mod/collaborate:moderate', $this->context)) {
         $role = 'moderator';
     } else {
         if (has_capability('mod/collaborate:participate', $this->context)) {
             $role = 'participant';
         } else {
             return new \moodle_url('/mod/collaborate/view.php', ['id' => $this->cm->id]);
         }
     }
     $attendee = new HtmlAttendee($this->user->id, $role);
     $attendee->setDisplayName(\core_text::substr(fullname($this->user), 0, 80));
     $avatar = new \user_picture($this->user);
     // Note, we get the avatar url for the site instance and don't use the $PAGE object so that this function is
     // unit testable.
     $page = new \moodle_page();
     $page->set_context(\context_system::instance());
     $avatarurl = $avatar->get_url($page);
     $attendee->setAvatarUrl(new \SoapVar('<ns1:avatarUrl><![CDATA[' . $avatarurl . ']]></ns1:avatarUrl>', XSD_ANYXML));
     $satts = new UpdateHtmlSessionAttendee($sessionid, $attendee);
     $result = $this->api->UpdateHtmlSessionAttendee($satts);
     if (!$result || !method_exists($result, 'getUrl')) {
         return false;
     }
     $url = $result->getUrl();
     return $url;
 }
コード例 #18
0
ファイル: view.php プロジェクト: EduardoKrausME/mod_superchat
foreach ($students as $student) {
    ?>
                    <li id="student_<?php 
    echo $student->id;
    ?>
" data-prof="<?php 
    echo $student->roleid == 5 ? 'b' : 'a';
    ?>
" data-order="<?php 
    echo $studentNum++;
    ?>
">
                        <?php 
    $page = new moodle_page();
    $page->set_url('/user/profile.php');
    $page->set_context(context_system::instance());
    $renderer = $page->get_renderer('core');
    $up3 = new user_picture($student);
    $up3->size = 100;
    $image = $up3->get_url($page, $renderer)->out(false);
    ?>
                        <img src="<?php 
    echo $image;
    ?>
" alt="<?php 
    echo $student->firstname;
    ?>
">
                        <span class="user-name no-text"><?php 
    echo fullname($student);
    ?>