本文整理汇总了PHP中moodle_page::get_renderer方法的典型用法代码示例。如果您正苦于以下问题:PHP moodle_page::get_renderer方法的具体用法?PHP moodle_page::get_renderer怎么用?PHP moodle_page::get_renderer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类moodle_page
的用法示例。
在下文中一共展示了moodle_page::get_renderer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_format_renderer
/**
* @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);
}
示例2: test_update_user_profile_image
/**
* Test the update user profile image function.
*/
public function test_update_user_profile_image()
{
global $DB, $CFG;
// Set the profile image.
\enrol_lti\helper::update_user_profile_image($this->user1->id, $this->getExternalTestFileUrl('/test.jpg'));
// Get the new user record.
$this->user1 = $DB->get_record('user', array('id' => $this->user1->id));
// Set the page details.
$page = new moodle_page();
$page->set_url('/user/profile.php');
$page->set_context(context_system::instance());
$renderer = $page->get_renderer('core');
$usercontext = context_user::instance($this->user1->id);
// Get the user's profile picture and make sure it is correct.
$userpicture = new user_picture($this->user1);
$this->assertSame($CFG->wwwroot . '/pluginfile.php/' . $usercontext->id . '/user/icon/clean/f2?rev=' . $this->user1->picture, $userpicture->get_url($page, $renderer)->out(false));
}
示例3: __construct
/**
* 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);
}
示例4: get_renderer
/**
* 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());
}
示例5: __construct
/**
* 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);
}
示例6: __construct
/**
* 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);
}
示例7: get_renderer
/**
* @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));
}
示例8: get_url
/**
* 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, $DB;
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;
}
// Is the user a member of staff
// need the next two lines to obtain some fields which are not present by default in the $user variable
$ID = $this->user->id;
$user = $DB->get_record('user', array('id' => "{$ID}"));
if (strpos(strtolower($user->phone2), 'staff') !== false) {
return $defaulturl;
// It is a member of staff; we return the default URL
}
if (empty($user->idnumber)) {
return $defaulturl;
// University ID is empty; we return the default URL
}
if ($this->user->picture == 0) {
// Normalise the size variable to acceptable bounds
if ($size < 1 || $size > 512) {
$size = 35;
}
// Find the best default image URL we can (MDL-35669)
$absoluteimagepath = $page->theme->resolve_image_location('u/' . $filename, 'core');
if (strpos($absoluteimagepath, $CFG->dirroot) === 0) {
$gravatardefault = $CFG->wwwroot . substr($absoluteimagepath, strlen($CFG->dirroot));
//.........这里部分代码省略.........
示例9: get_url
/**
* 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.
//.........这里部分代码省略.........
示例10: get_renderer
public function get_renderer(moodle_page $page)
{
return $page->get_renderer('qtype_multichoice', 'multi');
}
示例11: get_format_renderer
/**
* @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)
{
return $page->get_renderer('qtype_poodllrecording', 'format_' . $this->responseformat);
// return $page->get_renderer('qtype_poodllrecording', 'format_video');
}
示例12: fullname
?>
<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);
?>
</span>
示例13: get_renderer
/**
* Return the proper renderer for this class
*
* @param moodle_page $page
* @return renderer_base
*/
public function get_renderer(moodle_page $page)
{
return $page->get_renderer('qtype_omerointeractive', 'multi');
}
示例14: get_url
/**
* 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 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');
}
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 $renderer->pix_url('u/f1');
}
// 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 >= 50) {
$filename = 'f1';
$size = (int) $this->size;
} else {
$filename = 'f2';
$size = (int) $this->size;
}
}
}
if ($this->user->picture == 1) {
// The user has uploaded their own profile pic. In this case we will
// check that a profile pic file does actually exist
$fs = get_file_storage();
$context = get_context_instance(CONTEXT_USER, $this->user->id);
if (!$fs->file_exists($context->id, 'user', 'icon', 0, '/', $filename . '/.png')) {
if (!$fs->file_exists($context->id, 'user', 'icon', 0, '/', $filename . '/.jpg')) {
return $renderer->pix_url('u/' . $filename);
}
}
$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 . '/';
}
return moodle_url::make_pluginfile_url($context->id, 'user', 'icon', NULL, $path, $filename);
} else {
if ($this->user->picture == 2) {
// This is just VERY basic support for gravatar to give the actual
// implementor a headstart in what to do.
if ($size < 1 || $size > 500) {
$size = 35;
}
$md5 = md5(strtolower(trim($this->user->email)));
$default = urlencode($this->pix_url('u/' . $filename)->out(false));
return "http://www.gravatar.com/avatar/{$md5}?s={$size}&d={$default}";
}
}
return $renderer->pix_url('u/' . $filename);
}
示例15: process_url_edit
/**
* Handle showing/processing the submission from the block editing form.
* @return boolean true if the form was submitted and the new config saved. Does not
* return if the editing form was displayed. False otherwise.
*/
public function process_url_edit()
{
global $CFG, $DB, $PAGE, $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);
//.........这里部分代码省略.........