/** * Test custom userset theme assignment. */ public function test_customusersetthemectx() { $this->load_csv_data(); // ELIS user with the associated moodle user. $user = new user(103); $muser = $user->get_moodleuser(); // Userset with a custom theme. $userset = new userset(1); $userset->field__elis_userset_theme = 'formal_white'; $userset->field__elis_userset_themepriority = 1; $userset->save(); // Assign the user to the user set. $usersetassign = new clusterassignment(); $usersetassign->userid = $user->id; $usersetassign->clusterid = $userset->id; $usersetassign->save(); // Pretend to be that user. $this->setUser($muser->id); // Initialize page. $page = new moodle_page(); $page->initialise_theme_and_output(); // Assert we have our theme. $this->assertEquals('formal_white', $page->theme->name); $this->setUser(null); }
/** * 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; }
/** * 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); }
/** * @param moodle_page the page we are outputting to. * @return qtype_poodllrecording_format_renderer_base the response-format-specific renderer. */ public function get_format_renderer(moodle_page $page) { //Nadav reported a possible problem here, I can't reproduce it, but hope this fixes it. //https://github.com/justinhunt/moodle-qtype_poodllrecording/issues/1 if ($this->responseformat == 'editor') { $this->responseformat = 'picture'; } return $page->get_renderer('qtype_poodllrecording', 'format_' . $this->responseformat); }
/** * 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); }
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); }
/** * Allows course format to execute code on moodle_page::set_course() * * If user is on course view page and there is no scorm module added to the course * and the user has 'moodle/course:update' capability, redirect to create module * form. This function is executed before the output starts * * @param moodle_page $page instance of page calling set_course */ public function page_set_course(moodle_page $page) { global $PAGE; if ($PAGE == $page && $page->has_set_url() && $page->url->compare(new moodle_url('/course/view.php'), URL_MATCH_BASE)) { $modinfo = get_fast_modinfo($this->courseid); if (empty($modinfo->instances['scorm']) && has_capability('moodle/course:update', context_course::instance($this->courseid))) { // Redirect to create a new activity $url = new moodle_url('/course/modedit.php', array('course' => $this->courseid, 'section' => 0, 'add' => 'scorm')); redirect($url); } } }
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; }
function definition() { $mform =& $this->_form; // First show fields specific to this type of block. $this->specific_definition($mform); // Then show the fields about where this block appears. $mform->addElement('header', 'whereheader', get_string('wherethisblockappears', 'block')); // If the current weight of the block is out-of-range, add that option in. $blockweight = $this->block->instance->weight; $weightoptions = array(); if ($blockweight < -block_manager::MAX_WEIGHT) { $weightoptions[$blockweight] = $blockweight; } for ($i = -block_manager::MAX_WEIGHT; $i <= block_manager::MAX_WEIGHT; $i++) { $weightoptions[$i] = $i; } if ($blockweight > block_manager::MAX_WEIGHT) { $weightoptions[$blockweight] = $blockweight; } $first = reset($weightoptions); $weightoptions[$first] = get_string('bracketfirst', 'block', $first); $last = end($weightoptions); $weightoptions[$last] = get_string('bracketlast', 'block', $last); $regionoptions = $this->page->theme->get_all_block_regions(); $parentcontext = get_context_instance_by_id($this->block->instance->parentcontextid); $mform->addElement('static', 'contextname', get_string('thisblockbelongsto', 'block'), print_context_name($parentcontext)); $mform->addElement('selectyesno', 'bui_showinsubcontexts', get_string('appearsinsubcontexts', 'block')); $pagetypeoptions = matching_page_type_patterns($this->page->pagetype); $pagetypeoptions = array_combine($pagetypeoptions, $pagetypeoptions); $mform->addElement('select', 'bui_pagetypepattern', get_string('pagetypes', 'block'), $pagetypeoptions); if ($this->page->subpage) { $subpageoptions = array('%@NULL@%' => get_string('anypagematchingtheabove', 'block'), $this->page->subpage => get_string('thisspecificpage', 'block', $this->page->subpage)); $mform->addElement('select', 'bui_subpagepattern', get_string('subpages', 'block'), $subpageoptions); } $defaultregionoptions = $regionoptions; $defaultregion = $this->block->instance->defaultregion; if (!array_key_exists($defaultregion, $defaultregionoptions)) { $defaultregionoptions[$defaultregion] = $defaultregion; } $mform->addElement('select', 'bui_defaultregion', get_string('defaultregion', 'block'), $defaultregionoptions); $mform->addElement('select', 'bui_defaultweight', get_string('defaultweight', 'block'), $weightoptions); // Where this block is positioned on this page. $mform->addElement('header', 'whereheader', get_string('onthispage', 'block')); $mform->addElement('selectyesno', 'bui_visible', get_string('visible', 'block')); $blockregion = $this->block->instance->region; if (!array_key_exists($blockregion, $regionoptions)) { $regionoptions[$blockregion] = $blockregion; } $mform->addElement('select', 'bui_region', get_string('region', 'block'), $regionoptions); $mform->addElement('select', 'bui_weight', get_string('weight', 'block'), $weightoptions); $pagefields = array('bui_visible', 'bui_region', 'bui_weight'); if (!$this->block->user_can_edit()) { $mform->hardFreezeAllVisibleExcept($pagefields); } if (!$this->page->user_can_edit_blocks()) { $mform->hardFreeze($pagefields); } $this->add_action_buttons(); }
/** * 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)); }
/** * Constructor * * The constructor takes two arguments. The first is the page that the renderer * has been created to assist with, and the second is the target. * The target is an additional identifier that can be used to load different * renderers for different options. * * In order to create and initialize the appropriate arrays for resources, activities, assignments and icons, * we must update the declared constructor of the parent class, and since we can't just update it, we declare it again * adding the appropriate commands that suit our purpose. * * @param moodle_page $page the page we are doing output for. * @param string $target one of rendering target constants * @see core:renderer::__construct() */ public function __construct(moodle_page $page, $target) { // Find and update course modules ids. global $DB; $this->chatmoduleid = $DB->get_field_sql('SELECT id FROM {modules} WHERE name="chat"', null); $this->forummoduleid = $DB->get_field_sql('SELECT id FROM {modules} WHERE name="forum"', null); $this->oldassignmoduleid = $DB->get_field_sql('SELECT id FROM {modules} WHERE name="assignment"', null); $this->newassignmoduleid = $DB->get_field_sql('SELECT id FROM {modules} WHERE name="assign"', null); $this->labelmoduleid = $DB->get_field_sql('SELECT id FROM {modules} WHERE name="label"', null); // Use the Label module id, to exclude it from course resources. $this->output = $page->get_renderer('core', null, $target); parent::__construct($page, $target); // These are needed for the enriched rubric renderer construction. $this->resources = $this->get_modules_array('resources', $this->moduleicon); $this->assignments = $this->get_modules_array('assignments', $this->moduleicon); $this->activities = $this->get_modules_array('activities', $this->moduleicon); }
/** * 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; }
/** * Return a block_contents object representing the full contents of this block. * * This internally calls ->get_content(), and then adds the editing controls etc. * * You probably should not override this method, but instead override * {@link html_attributes()}, {@link formatted_contents()} or {@link get_content()}, * {@link hide_header()}, {@link (get_edit_controls)}, etc. * * @return block_contents a representation of the block, for rendering. * @since Moodle 2.0. */ public function get_content_for_output($output) { global $CFG; $bc = new block_contents($this->html_attributes()); $bc->attributes['data-block'] = $this->name(); $bc->blockinstanceid = $this->instance->id; $bc->blockpositionid = $this->instance->blockpositionid; if ($this->instance->visible) { $bc->content = $this->formatted_contents($output); if (!empty($this->content->footer)) { $bc->footer = $this->content->footer; } } else { $bc->add_class('invisible'); } if (!$this->hide_header()) { $bc->title = $this->title; } if (empty($bc->title)) { $bc->arialabel = new lang_string('pluginname', get_class($this)); $this->arialabel = $bc->arialabel; } if ($this->page->user_is_editing()) { $bc->controls = $this->page->blocks->edit_controls($this); } else { // we must not use is_empty on hidden blocks if ($this->is_empty() && !$bc->controls) { return null; } } if (empty($CFG->allowuserblockhiding) || empty($bc->content) && empty($bc->footer) || !$this->instance_can_be_collapsed()) { $bc->collapsible = block_contents::NOT_HIDEABLE; } else { if (get_user_preferences('block' . $bc->blockinstanceid . 'hidden', false)) { $bc->collapsible = block_contents::HIDDEN; } else { $bc->collapsible = block_contents::VISIBLE; } } if ($this->instance_can_be_docked() && !$this->hide_header()) { $bc->dockable = true; } $bc->annotation = ''; // TODO MDL-19398 need to work out what to say here. return $bc; }
/** * Return a block_contents oject representing the full contents of this block. * * This internally calls ->get_content(), and then adds the editing controls etc. * * You probably should not override this method, but instead override * {@link html_attributes()}, {@link formatted_contents()} or {@link get_content()}, * {@link hide_header()}, {@link (get_edit_controls)}, etc. * * @return block_contents a represntation of the block, for rendering. * @since Moodle 2.0. */ public function get_content_for_output($output) { global $CFG; $bc = new block_contents(); $bc->blockinstanceid = $this->instance->id; $bc->blockpositionid = $this->instance->blockpositionid; if ($this->instance->visible) { $bc->content = $this->formatted_contents($output); if (!empty($this->content->footer)) { $bc->footer = $this->content->footer; } } else { $bc->add_class('invisible'); } $attributes = $this->html_attributes(); if (isset($attributes['id'])) { $bc->id = $attributes['id']; unset($attributes['id']); } if (isset($attributes['class'])) { $bc->set_classes($attributes['class']); unset($attributes['class']); } $bc->attributes = $attributes; if (!$this->hide_header()) { $bc->title = $this->title; } if ($this->page->user_is_editing()) { $bc->controls = $this->page->blocks->edit_controls($this); } if ($this->is_empty() && !$bc->controls) { return null; } if (empty($CFG->allowuserblockhiding) || empty($bc->content) && empty($bc->footer)) { $bc->collapsible = block_contents::NOT_HIDEABLE; } else { if (get_user_preferences('block' . $bc->blockinstanceid . 'hidden', false)) { $bc->collapsible = block_contents::HIDDEN; } else { $bc->collapsible = block_contents::VISIBLE; } } $bc->annotation = ''; // TODO MDL-19398 need to work out what to say here. return $bc; }
/** * @param moodle_page $page the page to render for. * @return qbehaviour_renderer get the appropriate renderer to use for this model. */ public function get_renderer(moodle_page $page) { return $page->get_renderer(get_class($this)); }
public function get_renderer(moodle_page $page) { return $page->get_renderer('qtype_multichoice', 'multi'); }
/** * Initialise with the bits of JavaScript that every Moodle page should have. * * @param moodle_page $page * @param core_renderer $renderer */ protected function init_requirements_data(moodle_page $page, core_renderer $renderer) { global $CFG; // JavaScript should always work with $CFG->httpswwwroot rather than $CFG->wwwroot. // Otherwise, in some situations, users will get warnings about insecure content // on secure pages from their web browser. $this->M_cfg = array('wwwroot' => $CFG->httpswwwroot, 'sesskey' => sesskey(), 'loadingicon' => $renderer->pix_url('i/loading_small', 'moodle')->out(false), 'themerev' => theme_get_revision(), 'slasharguments' => (int) (!empty($CFG->slasharguments)), 'theme' => $page->theme->name, 'jsrev' => (empty($CFG->cachejs) or empty($CFG->jsrev)) ? -1 : $CFG->jsrev, 'svgicons' => $page->theme->use_svg_icons()); if (debugging('', DEBUG_DEVELOPER)) { $this->M_cfg['developerdebug'] = true; } if (defined('BEHAT_SITE_RUNNING')) { $this->M_cfg['behatsiterunning'] = true; } // Accessibility stuff. $this->skip_link_to('maincontent', get_string('tocontent', 'access')); // Add strings used on many pages. $this->string_for_js('confirmation', 'admin'); $this->string_for_js('cancel', 'moodle'); $this->string_for_js('yes', 'moodle'); // Alter links in top frame to break out of frames. if ($page->pagelayout === 'frametop') { $this->js_init_call('M.util.init_frametop'); } // Include block drag/drop if editing is on if ($page->user_is_editing()) { $params = array('courseid' => $page->course->id, 'pagetype' => $page->pagetype, 'pagelayout' => $page->pagelayout, 'subpage' => $page->subpage, 'regions' => $page->blocks->get_regions(), 'contextid' => $page->context->id); if (!empty($page->cm->id)) { $params['cmid'] = $page->cm->id; } $page->requires->yui_module('moodle-core-blocks', 'M.core_blocks.init_dragdrop', array($params), null, true); } }
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();
/** * Allows course format to execute code on moodle_page::set_course() * * This function is executed before the output starts. * * If everything is configured correctly, user is redirected from the * default course view page to the activity view page. * * "Section 1" is the administrative page to manage orphaned activities * * If user is on course view page and there is no module added to the course * and the user has 'moodle/course:manageactivities' capability, redirect to create module * form. * * @param moodle_page $page instance of page calling set_course */ public function page_set_course(moodle_page $page) { global $PAGE; $page->add_body_class('format-' . $this->get_format()); if ($PAGE == $page && $page->has_set_url() && $page->url->compare(new moodle_url('/course/view.php'), URL_MATCH_BASE)) { $edit = optional_param('edit', -1, PARAM_BOOL); if (($edit == 0 || $edit == 1) && confirm_sesskey()) { // This is a request to turn editing mode on or off, do not redirect here, /course/view.php will do redirection. return; } $cm = $this->get_activity(); $cursection = optional_param('section', null, PARAM_INT); if (!empty($cursection) && has_capability('moodle/course:viewhiddensections', context_course::instance($this->courseid))) { // Display orphaned activities (course view page, section 1). return; } if (!$this->get_activitytype()) { if (has_capability('moodle/course:update', context_course::instance($this->courseid))) { // Teacher is redirected to edit course page. $url = new moodle_url('/course/edit.php', array('id' => $this->courseid)); redirect($url, get_string('erroractivitytype', 'format_singleactivity')); } else { // Student sees an empty course page. return; } } if ($cm === null) { if ($this->can_add_activity()) { // This is a user who has capability to create an activity. if ($this->activity_has_subtypes()) { // Activity that requires subtype can not be added automatically. if (optional_param('addactivity', 0, PARAM_INT)) { return; } else { $url = new moodle_url('/course/view.php', array('id' => $this->courseid, 'addactivity' => 1)); redirect($url); } } // Redirect to the add activity form. $url = new moodle_url('/course/mod.php', array('id' => $this->courseid, 'section' => 0, 'sesskey' => sesskey(), 'add' => $this->get_activitytype())); redirect($url); } else { // Student views an empty course page. return; } } else { if (!$cm->uservisible || !$cm->get_url()) { // Activity is set but not visible to current user or does not have url. // Display course page (either empty or with availability restriction info). return; } else { // Everything is set up and accessible, redirect to the activity page! redirect($cm->get_url()); } } } }
public function test_qualified_me() { global $PAGE, $FULLME, $CFG; $this->resetAfterTest(); $PAGE = new moodle_page(); $FULLME = $CFG->wwwroot . '/course/view.php?id=1&xx=yy'; $this->assertSame($FULLME, qualified_me()); $PAGE->set_url('/course/view.php', array('id' => 1)); $this->assertSame($CFG->wwwroot . '/course/view.php?id=1', qualified_me()); }
/** * 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_move() { global $CFG, $DB, $PAGE; $blockid = optional_param('bui_moveid', null, PARAM_INT); if (!$blockid) { return false; } require_sesskey(); $block = $this->find_instance($blockid); if (!$this->page->user_can_edit_blocks()) { throw new moodle_exception('nopermissions', '', $this->page->url->out(), get_string('editblock')); } $newregion = optional_param('bui_newregion', '', PARAM_ALPHANUMEXT); $newweight = optional_param('bui_newweight', null, PARAM_FLOAT); if (!$newregion || is_null($newweight)) { // Don't have a valid target position yet, must be just starting the move. $this->movingblock = $blockid; $this->page->ensure_param_not_in_url('bui_moveid'); return false; } if (!$this->is_known_region($newregion)) { throw new moodle_exception('unknownblockregion', '', $this->page->url, $newregion); } // Move this block. This may involve moving other nearby blocks. $blocks = $this->birecordsbyregion[$newregion]; $maxweight = self::MAX_WEIGHT; $minweight = -self::MAX_WEIGHT; // Initialise the used weights and spareweights array with the default values $spareweights = array(); $usedweights = array(); for ($i = $minweight; $i <= $maxweight; $i++) { $spareweights[$i] = $i; $usedweights[$i] = array(); } // Check each block and sort out where we have used weights foreach ($blocks as $bi) { if ($bi->weight > $maxweight) { // If this statement is true then the blocks weight is more than the // current maximum. To ensure that we can get the best block position // we will initialise elements within the usedweights and spareweights // arrays between the blocks weight (which will then be the new max) and // the current max $parseweight = $bi->weight; while (!array_key_exists($parseweight, $usedweights)) { $usedweights[$parseweight] = array(); $spareweights[$parseweight] = $parseweight; $parseweight--; } $maxweight = $bi->weight; } else { if ($bi->weight < $minweight) { // As above except this time the blocks weight is LESS than the // the current minimum, so we will initialise the array from the // blocks weight (new minimum) to the current minimum $parseweight = $bi->weight; while (!array_key_exists($parseweight, $usedweights)) { $usedweights[$parseweight] = array(); $spareweights[$parseweight] = $parseweight; $parseweight++; } $minweight = $bi->weight; } } if ($bi->id != $block->instance->id) { unset($spareweights[$bi->weight]); $usedweights[$bi->weight][] = $bi->id; } } // First we find the nearest gap in the list of weights. $bestdistance = max(abs($newweight - self::MAX_WEIGHT), abs($newweight + self::MAX_WEIGHT)) + 1; $bestgap = null; foreach ($spareweights as $spareweight) { if (abs($newweight - $spareweight) < $bestdistance) { $bestdistance = abs($newweight - $spareweight); $bestgap = $spareweight; } } // If there is no gap, we have to go outside -self::MAX_WEIGHT .. self::MAX_WEIGHT. if (is_null($bestgap)) { $bestgap = self::MAX_WEIGHT + 1; while (!empty($usedweights[$bestgap])) { $bestgap++; } } // Now we know the gap we are aiming for, so move all the blocks along. if ($bestgap < $newweight) { $newweight = floor($newweight); for ($weight = $bestgap + 1; $weight <= $newweight; $weight++) { foreach ($usedweights[$weight] as $biid) { $this->reposition_block($biid, $newregion, $weight - 1); } } $this->reposition_block($block->instance->id, $newregion, $newweight); } else { $newweight = ceil($newweight); for ($weight = $bestgap - 1; $weight >= $newweight; $weight--) { if (array_key_exists($weight, $usedweights)) { foreach ($usedweights[$weight] as $biid) { $this->reposition_block($biid, $newregion, $weight + 1); } } } $this->reposition_block($block->instance->id, $newregion, $newweight); } $this->page->ensure_param_not_in_url('bui_moveid'); $this->page->ensure_param_not_in_url('bui_newregion'); $this->page->ensure_param_not_in_url('bui_newweight'); return true; }
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)); }
/** * Returns the rubric plugin renderer * * @param moodle_page $page the target page * @return gradingform_rubric_renderer */ public function get_renderer(moodle_page $page) { return $page->get_renderer('gradingform_' . $this->get_method_name()); }
/** * Works out the URL for the users picture. * * This method is recommended as it avoids costly redirects of user pictures * if requests are made for non-existent files etc. * * @param moodle_page $page * @param renderer_base $renderer * @return moodle_url */ public function get_url(moodle_page $page, renderer_base $renderer = null) { global $CFG; if (is_null($renderer)) { $renderer = $page->get_renderer('core'); } // Sort out the filename and size. Size is only required for the gravatar // implementation presently. if (empty($this->size)) { $filename = 'f2'; $size = 35; } else { if ($this->size === true or $this->size == 1) { $filename = 'f1'; $size = 100; } else { if ($this->size > 100) { $filename = 'f3'; $size = (int) $this->size; } else { if ($this->size >= 50) { $filename = 'f1'; $size = (int) $this->size; } else { $filename = 'f2'; $size = (int) $this->size; } } } } $defaulturl = $renderer->pix_url('u/' . $filename); // default image if ((!empty($CFG->forcelogin) and !isloggedin()) || !empty($CFG->forceloginforprofileimage) && (!isloggedin() || isguestuser())) { // Protect images if login required and not logged in; // also if login is required for profile images and is not logged in or guest // do not use require_login() because it is expensive and not suitable here anyway. return $defaulturl; } // First try to detect deleted users - but do not read from database for performance reasons! if (!empty($this->user->deleted) or strpos($this->user->email, '@') === false) { // All deleted users should have email replaced by md5 hash, // all active users are expected to have valid email. return $defaulturl; } // Did the user upload a picture? if ($this->user->picture > 0) { if (!empty($this->user->contextid)) { $contextid = $this->user->contextid; } else { $context = context_user::instance($this->user->id, IGNORE_MISSING); if (!$context) { // This must be an incorrectly deleted user, all other users have context. return $defaulturl; } $contextid = $context->id; } $path = '/'; if (clean_param($page->theme->name, PARAM_THEME) == $page->theme->name) { // We append the theme name to the file path if we have it so that // in the circumstance that the profile picture is not available // when the user actually requests it they still get the profile // picture for the correct theme. $path .= $page->theme->name . '/'; } // Set the image URL to the URL for the uploaded file and return. $url = moodle_url::make_pluginfile_url($contextid, 'user', 'icon', NULL, $path, $filename); $url->param('rev', $this->user->picture); return $url; } if ($this->user->picture == 0 and !empty($CFG->enablegravatar)) { // Normalise the size variable to acceptable bounds if ($size < 1 || $size > 512) { $size = 35; } // Hash the users email address $md5 = md5(strtolower(trim($this->user->email))); // Build a gravatar URL with what we know. // Find the best default image URL we can (MDL-35669) if (empty($CFG->gravatardefaulturl)) { $absoluteimagepath = $page->theme->resolve_image_location('u/' . $filename, 'core'); if (strpos($absoluteimagepath, $CFG->dirroot) === 0) { $gravatardefault = $CFG->wwwroot . substr($absoluteimagepath, strlen($CFG->dirroot)); } else { $gravatardefault = $CFG->wwwroot . '/pix/u/' . $filename . '.png'; } } else { $gravatardefault = $CFG->gravatardefaulturl; } // If the currently requested page is https then we'll return an // https gravatar page. if (is_https()) { $gravatardefault = str_replace($CFG->wwwroot, $CFG->httpswwwroot, $gravatardefault); // Replace by secure url. return new moodle_url("https://secure.gravatar.com/avatar/{$md5}", array('s' => $size, 'd' => $gravatardefault)); } else { return new moodle_url("http://www.gravatar.com/avatar/{$md5}", array('s' => $size, 'd' => $gravatardefault)); } } return $defaulturl; }
/** * This function loads all of the front page settings into the settings navigation. * This function is called when the user is on the front page, or $COURSE==$SITE * @return navigation_node */ protected function load_front_page_settings($forceopen = false) { global $SITE, $CFG; $course = clone $SITE; $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context $frontpage = $this->add(get_string('frontpagesettings'), null, self::TYPE_SETTING, null, 'frontpage'); if ($forceopen) { $frontpage->force_open(); } $frontpage->id = 'frontpagesettings'; if (has_capability('moodle/course:update', $coursecontext)) { // Add the turn on/off settings $url = new moodle_url('/course/view.php', array('id' => $course->id, 'sesskey' => sesskey())); if ($this->page->user_is_editing()) { $url->param('edit', 'off'); $editstring = get_string('turneditingoff'); } else { $url->param('edit', 'on'); $editstring = get_string('turneditingon'); } $frontpage->add($editstring, $url, self::TYPE_SETTING, null, null, new pix_icon('i/edit', '')); // Add the course settings link $url = new moodle_url('/admin/settings.php', array('section' => 'frontpagesettings')); $frontpage->add(get_string('editsettings'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/settings', '')); } // add enrol nodes enrol_add_course_navigation($frontpage, $course); // Manage filters if (has_capability('moodle/filter:manage', $coursecontext) && count(filter_get_available_in_context($coursecontext)) > 0) { $url = new moodle_url('/filter/manage.php', array('contextid' => $coursecontext->id)); $frontpage->add(get_string('filters', 'admin'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/filter', '')); } // Backup this course if (has_capability('moodle/backup:backupcourse', $coursecontext)) { $url = new moodle_url('/backup/backup.php', array('id' => $course->id)); $frontpage->add(get_string('backup'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/backup', '')); } // Restore to this course if (has_capability('moodle/restore:restorecourse', $coursecontext)) { $url = new moodle_url('/backup/restorefile.php', array('contextid' => $coursecontext->id)); $frontpage->add(get_string('restore'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/restore', '')); } // Manage questions $questioncaps = array('moodle/question:add', 'moodle/question:editmine', 'moodle/question:editall', 'moodle/question:viewmine', 'moodle/question:viewall', 'moodle/question:movemine', 'moodle/question:moveall'); if (has_any_capability($questioncaps, $this->context)) { $questionlink = $CFG->wwwroot . '/question/edit.php'; } else { if (has_capability('moodle/question:managecategory', $this->context)) { $questionlink = $CFG->wwwroot . '/question/category.php'; } } if (isset($questionlink)) { $url = new moodle_url($questionlink, array('courseid' => $course->id)); $frontpage->add(get_string('questions', 'quiz'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/questions', '')); } // Manage files if ($course->legacyfiles == 2 and has_capability('moodle/course:managefiles', $this->context)) { //hiden in new installs $url = new moodle_url('/files/index.php', array('contextid' => $coursecontext->id, 'itemid' => 0, 'component' => 'course', 'filearea' => 'legacy')); $frontpage->add(get_string('sitelegacyfiles'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/files', '')); } return $frontpage; }
function definition() { $mform =& $this->_form; // First show fields specific to this type of block. $this->specific_definition($mform); // Then show the fields about where this block appears. $mform->addElement('header', 'whereheader', get_string('wherethisblockappears', 'block')); // If the current weight of the block is out-of-range, add that option in. $blockweight = $this->block->instance->weight; $weightoptions = array(); if ($blockweight < -block_manager::MAX_WEIGHT) { $weightoptions[$blockweight] = $blockweight; } for ($i = -block_manager::MAX_WEIGHT; $i <= block_manager::MAX_WEIGHT; $i++) { $weightoptions[$i] = $i; } if ($blockweight > block_manager::MAX_WEIGHT) { $weightoptions[$blockweight] = $blockweight; } $first = reset($weightoptions); $weightoptions[$first] = get_string('bracketfirst', 'block', $first); $last = end($weightoptions); $weightoptions[$last] = get_string('bracketlast', 'block', $last); $regionoptions = $this->page->theme->get_all_block_regions(); foreach ($this->page->blocks->get_regions() as $region) { // Make sure to add all custom regions of this particular page too. if (!isset($regionoptions[$region])) { $regionoptions[$region] = $region; } } $parentcontext = context::instance_by_id($this->block->instance->parentcontextid); $mform->addElement('hidden', 'bui_parentcontextid', $parentcontext->id); $mform->setType('bui_parentcontextid', PARAM_INT); $mform->addElement('static', 'bui_homecontext', get_string('createdat', 'block'), $parentcontext->get_context_name()); $mform->addHelpButton('bui_homecontext', 'createdat', 'block'); // For pre-calculated (fixed) pagetype lists $pagetypelist = array(); // parse pagetype patterns $bits = explode('-', $this->page->pagetype); // First of all, check if we are editing blocks @ front-page or no and // make some dark magic if so (MDL-30340) because each page context // implies one (and only one) harcoded page-type that will be set later // when processing the form data at {@link block_manager::process_url_edit()} // There are some conditions to check related to contexts $ctxconditions = $this->page->context->contextlevel == CONTEXT_COURSE && $this->page->context->instanceid == get_site()->id; // And also some pagetype conditions $pageconditions = isset($bits[0]) && isset($bits[1]) && $bits[0] == 'site' && $bits[1] == 'index'; // So now we can be 100% sure if edition is happening at frontpage $editingatfrontpage = $ctxconditions && $pageconditions; // Let the form to know about that, can be useful later $mform->addElement('hidden', 'bui_editingatfrontpage', (int) $editingatfrontpage); $mform->setType('bui_editingatfrontpage', PARAM_INT); // Front page, show the page-contexts element and set $pagetypelist to 'any page' (*) // as unique option. Processign the form will do any change if needed if ($editingatfrontpage) { $contextoptions = array(); $contextoptions[BUI_CONTEXTS_FRONTPAGE_ONLY] = get_string('showonfrontpageonly', 'block'); $contextoptions[BUI_CONTEXTS_FRONTPAGE_SUBS] = get_string('showonfrontpageandsubs', 'block'); $contextoptions[BUI_CONTEXTS_ENTIRE_SITE] = get_string('showonentiresite', 'block'); $mform->addElement('select', 'bui_contexts', get_string('contexts', 'block'), $contextoptions); $mform->addHelpButton('bui_contexts', 'contexts', 'block'); $pagetypelist['*'] = '*'; // This is not going to be shown ever, it's an unique option // Any other system context block, hide the page-contexts element, // it's always system-wide BUI_CONTEXTS_ENTIRE_SITE } else { if ($parentcontext->contextlevel == CONTEXT_SYSTEM) { $mform->addElement('hidden', 'bui_contexts', BUI_CONTEXTS_ENTIRE_SITE); } else { if ($parentcontext->contextlevel == CONTEXT_COURSE) { // 0 means display on current context only, not child contexts // but if course managers select mod-* as pagetype patterns, block system will overwrite this option // to 1 (display on current context and child contexts) $mform->addElement('hidden', 'bui_contexts', BUI_CONTEXTS_CURRENT); } else { if ($parentcontext->contextlevel == CONTEXT_MODULE or $parentcontext->contextlevel == CONTEXT_USER) { // module context doesn't have child contexts, so display in current context only $mform->addElement('hidden', 'bui_contexts', BUI_CONTEXTS_CURRENT); } else { $parentcontextname = $parentcontext->get_context_name(); $contextoptions[BUI_CONTEXTS_CURRENT] = get_string('showoncontextonly', 'block', $parentcontextname); $contextoptions[BUI_CONTEXTS_CURRENT_SUBS] = get_string('showoncontextandsubs', 'block', $parentcontextname); $mform->addElement('select', 'bui_contexts', get_string('contexts', 'block'), $contextoptions); } } } } $mform->setType('bui_contexts', PARAM_INT); // Generate pagetype patterns by callbacks if necessary (has not been set specifically) if (empty($pagetypelist)) { $pagetypelist = generate_page_type_patterns($this->page->pagetype, $parentcontext, $this->page->context); $displaypagetypewarning = false; if (!array_key_exists($this->block->instance->pagetypepattern, $pagetypelist)) { // Pushing block's existing page type pattern $pagetypestringname = 'page-' . str_replace('*', 'x', $this->block->instance->pagetypepattern); if (get_string_manager()->string_exists($pagetypestringname, 'pagetype')) { $pagetypelist[$this->block->instance->pagetypepattern] = get_string($pagetypestringname, 'pagetype'); } else { //as a last resort we could put the page type pattern in the select box //however this causes mod-data-view to be added if the only option available is mod-data-* // so we are just showing a warning to users about their prev setting being reset $displaypagetypewarning = true; } } } // hide page type pattern select box if there is only one choice if (count($pagetypelist) > 1) { if ($displaypagetypewarning) { $mform->addElement('static', 'pagetypewarning', '', get_string('pagetypewarning', 'block')); } $mform->addElement('select', 'bui_pagetypepattern', get_string('restrictpagetypes', 'block'), $pagetypelist); } else { $values = array_keys($pagetypelist); $value = array_pop($values); $mform->addElement('hidden', 'bui_pagetypepattern', $value); $mform->setType('bui_pagetypepattern', PARAM_RAW); // Now we are really hiding a lot (both page-contexts and page-type-patterns), // specially in some systemcontext pages having only one option (my/user...) // so, until it's decided if we are going to add the 'bring-back' pattern to // all those pages or no (see MDL-30574), we are going to show the unique // element statically // TODO: Revisit this once MDL-30574 has been decided and implemented, although // perhaps it's not bad to always show this statically when only one pattern is // available. if (!$editingatfrontpage) { // Try to beautify it $strvalue = $value; $strkey = 'page-' . str_replace('*', 'x', $strvalue); if (get_string_manager()->string_exists($strkey, 'pagetype')) { $strvalue = get_string($strkey, 'pagetype'); } // Show as static (hidden has been set already) $mform->addElement('static', 'bui_staticpagetypepattern', get_string('restrictpagetypes', 'block'), $strvalue); } } if ($this->page->subpage) { if ($parentcontext->contextlevel == CONTEXT_USER) { $mform->addElement('hidden', 'bui_subpagepattern', '%@NULL@%'); $mform->setType('bui_subpagepattern', PARAM_RAW); } else { $subpageoptions = array('%@NULL@%' => get_string('anypagematchingtheabove', 'block'), $this->page->subpage => get_string('thisspecificpage', 'block', $this->page->subpage)); $mform->addElement('select', 'bui_subpagepattern', get_string('subpages', 'block'), $subpageoptions); } } $defaultregionoptions = $regionoptions; $defaultregion = $this->block->instance->defaultregion; if (!array_key_exists($defaultregion, $defaultregionoptions)) { $defaultregionoptions[$defaultregion] = $defaultregion; } $mform->addElement('select', 'bui_defaultregion', get_string('defaultregion', 'block'), $defaultregionoptions); $mform->addHelpButton('bui_defaultregion', 'defaultregion', 'block'); $mform->addElement('select', 'bui_defaultweight', get_string('defaultweight', 'block'), $weightoptions); $mform->addHelpButton('bui_defaultweight', 'defaultweight', 'block'); // Where this block is positioned on this page. $mform->addElement('header', 'onthispage', get_string('onthispage', 'block')); $mform->addElement('selectyesno', 'bui_visible', get_string('visible', 'block')); $blockregion = $this->block->instance->region; if (!array_key_exists($blockregion, $regionoptions)) { $regionoptions[$blockregion] = $blockregion; } $mform->addElement('select', 'bui_region', get_string('region', 'block'), $regionoptions); $mform->addElement('select', 'bui_weight', get_string('weight', 'block'), $weightoptions); $pagefields = array('bui_visible', 'bui_region', 'bui_weight'); if (!$this->block->user_can_edit()) { $mform->hardFreezeAllVisibleExcept($pagefields); } if (!$this->page->user_can_edit_blocks()) { $mform->hardFreeze($pagefields); } $this->add_action_buttons(); }
/** * @param moodle_page the page we are outputting to. * @return qtype_essay_format_renderer_base the response-format-specific renderer. */ public function get_format_renderer(moodle_page $page) { return $page->get_renderer('qtype_essay', 'format_' . $this->responseformat); }
/** * Constructor method, calls the parent constructor * * @param moodle_page $page * @param string $target one of rendering target constants */ public function __construct(moodle_page $page, $target) { $this->output = $page->get_renderer('core', null, $target); parent::__construct($page, $target); }
/** * Returns instance of page renderer used by this plugin * * @param moodle_page $page * @return renderer_base */ public function get_renderer(moodle_page $page) { return $page->get_renderer('format_' . $this->get_format()); }
/** * Constructor method, calls the parent constructor * * @param moodle_page $page * @param string $target one of rendering target constants */ public function __construct(moodle_page $page, $target) { if (empty($target) && $page->pagelayout === 'maintenance') { // If the page is using the maintenance layout then we're going to force the target to maintenance. // This way we'll get a special maintenance renderer that is designed to block access to API's that are likely // unavailable for this page layout. $target = RENDERER_TARGET_MAINTENANCE; } $this->output = $page->get_renderer('core', null, $target); parent::__construct($page, $target); }