本文整理汇总了PHP中context_block::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP context_block::instance方法的具体用法?PHP context_block::instance怎么用?PHP context_block::instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类context_block
的用法示例。
在下文中一共展示了context_block::instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor - instantiates one object of this class
*/
public function __construct($name, $blockid, $moduleid = null, $plan = null)
{
global $DB;
// Check blockid exists
if (!($block = $DB->get_record('block_instances', array('id' => $blockid)))) {
throw new backup_task_exception('block_task_block_instance_not_found', $blockid);
}
$this->blockid = $blockid;
$this->blockname = $block->blockname;
$this->contextid = context_block::instance($this->blockid)->id;
$this->moduleid = $moduleid;
$this->modulename = null;
$this->parentcontextid = null;
// If moduleid passed, check exists, supports moodle2 format and save info
// Check moduleid exists
if (!empty($moduleid)) {
if (!($coursemodule = get_coursemodule_from_id(false, $moduleid))) {
throw new backup_task_exception('block_task_coursemodule_not_found', $moduleid);
}
// Check activity supports this moodle2 backup format
if (!plugin_supports('mod', $coursemodule->modname, FEATURE_BACKUP_MOODLE2)) {
throw new backup_task_exception('block_task_activity_lacks_moodle2_backup_support', $coursemodule->modname);
}
$this->moduleid = $moduleid;
$this->modulename = $coursemodule->modname;
$this->parentcontextid = context_module::instance($this->moduleid)->id;
}
parent::__construct($name, $plan);
}
示例2: get_content
/**
* Used to generate the content for the block.
* @return string
*/
public function get_content()
{
global $DB, $OUTPUT;
if ($this->content !== null) {
return $this->content;
}
$this->content = new stdClass();
$this->content->items = array();
$this->content->icons = array();
$this->content->footer = '';
$rs = $DB->get_records('block_links', array('defaultshow' => BLOCK_LINKS_SHOWLINK), 'linktext');
if (!is_array($rs)) {
$rs = array();
}
$link = new stdClass();
foreach ($rs as $link) {
if (block_links_check_permissions($link)) {
// Does the user have permission, or is it viewable to all?
$this->add_link($link);
}
}
if (empty($this->instance->pinned)) {
$context = context_block::instance($this->instance->id);
} else {
$context = context_system::instance();
// Pinned blocks do not have own context.
}
if (has_capability('moodle/site:manageblocks', $context) && has_capability('block/links:managelinks', $context)) {
$link->url = new moodle_url('/blocks/links/config_global_action.php');
$link->linktext = html_writer::tag('span', get_string('managelinks', 'block_links'), array('class' => 'links-bold'));
$this->content->items[] = html_writer::tag('a', $link->linktext, array('href' => $link->url));
$this->content->icons[] = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('web', 'block_links'), 'class' => 'icon'));
}
return $this->content;
}
示例3: xmldb_block_nurs_navigation_upgrade
/**
* This is the upgrade script for the project.
*
* @package block_nurs_navigation
* @category block
* @copyright 2012 Craig Jamieson
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
function xmldb_block_nurs_navigation_upgrade($oldversion = 0)
{
global $DB;
$dbman = $DB->get_manager();
$result = true;
// June 17, 2013 version changed the way that contexts are stored in the files table.
if ($oldversion < 2013061706) {
$query = "SELECT * FROM {nurs_navigation} WHERE courseid <> 1";
$records = $DB->get_records_sql($query);
$fs = get_file_storage();
foreach ($records as $record) {
$coursecontext = context_course::instance($record->courseid);
// Explicit check here since sometimes there are old nurs_navigation records that point to deleted courses.
if (isset($coursecontext->id)) {
$params = array($coursecontext->id, 'nurs_navigation');
$query = "SELECT * FROM {block_instances} WHERE parentcontextid = ? AND blockname = ?";
$block = $DB->get_record_sql($query, $params, IGNORE_MULTIPLE);
$blockcontext = context_block::instance($block->id);
// This can return multiple records because of how the multiple file terminator works.
$filerecords = $DB->get_records('files', array('contextid' => $coursecontext->id, 'itemid' => $record->fileid));
foreach ($filerecords as $filerecord) {
$filerecord->contextid = $blockcontext->id;
// Path hash must be updated as well with a context change.
$filerecord->pathnamehash = $fs->get_pathname_hash($filerecord->contextid, BNN_BLOCK_SAVE_COMPONENT, BNN_BLOCK_SAVE_AREA, $filerecord->itemid, $filerecord->filepath, $filerecord->filename);
$DB->update_record('files', $filerecord);
}
}
}
}
// Create the second table.
if ($oldversion < 2012110200) {
// Define table nurs_navigation_settings to be created.
$table = new xmldb_table('nurs_navigation_settings');
// Adding fields to table nurs_navigation_settings.
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('courseid', XMLDB_TYPE_INTEGER, '20', null, XMLDB_NOTNULL, null, null);
$table->add_field('sectionname', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null);
$table->add_field('disableicon', XMLDB_TYPE_INTEGER, '20', null, XMLDB_NOTNULL, null, null);
$table->add_field('customlabel', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
// Adding keys to table nurs_navigation_settings.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
// Conditionally launch create table for nurs_navigation_settings.
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
// Define field disableicon to be dropped from nurs_navigation.
$table = new xmldb_table('nurs_navigation');
$field = new xmldb_field('disableicon');
// Conditionally launch drop field courseid.
if ($dbman->field_exists($table, $field)) {
$dbman->drop_field($table, $field);
}
// Update savepoint.
upgrade_block_savepoint(true, 2012110200, 'nurs_navigation');
}
return $result;
}
示例4: create_instance
/**
* Create new block instance
* @param array|stdClass $record
* @param array $options
* @return stdClass activity record with extra cmid field
*/
public function create_instance($record = null, $options = null)
{
global $DB;
$this->instancecount++;
$record = (object) (array) $record;
$options = (array) $options;
$record = $this->prepare_record($record);
$id = $DB->insert_record('block_instances', $record);
context_block::instance($id);
$instance = $DB->get_record('block_instances', array('id' => $id), '*', MUST_EXIST);
return $instance;
}
示例5: create_instance
/**
* Create new block instance
* @param array|stdClass $record
* @param array $options
* @return stdClass activity record with extra cmid field
*/
public function create_instance($record = null, array $options = null)
{
global $DB, $CFG;
require_once "{$CFG->dirroot}/mod/page/locallib.php";
$this->instancecount++;
$record = (object) (array) $record;
$options = (array) $options;
$record = $this->prepare_record($record);
$id = $DB->insert_record('block_instances', $record);
context_block::instance($id);
$instance = $DB->get_record('block_instances', array('id' => $id), '*', MUST_EXIST);
return $instance;
}
示例6: create_instance
/**
* Create new block instance
* @param array|stdClass $record
* @param array $config Instance configurations
* @return stdClass instance record
*/
public function create_instance($record = null, array $config = null)
{
global $DB, $CFG;
require_once "{$CFG->dirroot}/mod/page/locallib.php";
$this->instancecount++;
$record = (object) (array) $record;
$config = (object) (array) $config;
$record = $this->prepare_record($record);
if (!isset($config->sped_version)) {
$config->sped_version = 0;
}
$record->configdata = base64_encode(serialize($config));
$id = $DB->insert_record('block_instances', $record);
$context = context_block::instance($id);
$instance = $DB->get_record('block_instances', array('id' => $id), '*', MUST_EXIST);
return $instance;
}
示例7: get_content
/**
* @see block_base::get_content()
*/
public function get_content()
{
global $CFG, $PAGE, $USER, $COURSE, $OUTPUT;
if ($this->content !== null) {
return $this->content;
}
// Display admin or user page depending capability.
$context = context_block::instance($this->instance->id);
$this->content = new stdClass();
if (has_capability('moodle/course:managegroups', $context)) {
$this->content->text = '<a href="' . $CFG->wwwroot . '/blocks/upload_group/index.php?id=' . $COURSE->id . '">Upload groups</a>';
} else {
$this->content->text = '';
}
$this->content->footer = '';
return $this->content;
}
示例8: __construct
/**
* @throws coding_exception
*/
public function __construct()
{
global $PAGE, $COURSE;
// Page path blacklist for admin menu.
$adminblockblacklist = ['/user/profile.php'];
if (in_array(local::current_url_path(), $adminblockblacklist)) {
return;
}
// Admin users always see the admin menu with the exception of blacklisted pages.
// The admin menu shows up for other users if they are a teacher in the current course.
if (!is_siteadmin()) {
// We don't want students to see the admin menu ever.
// Editing teachers are identified as people who can manage activities and non editing teachers as those who
// can view the gradebook. As editing teachers are almost certain to also be able to view the gradebook, the
// grader:view capability is checked first.
$caps = ['gradereport/grader:view', 'moodle/course:manageactivities'];
$canmanageacts = has_any_capability($caps, $PAGE->context);
$isstudent = !$canmanageacts && !is_role_switched($COURSE->id);
if ($isstudent) {
return;
}
}
if (!$PAGE->blocks->is_block_present('settings')) {
// Throw error if on front page or course page.
// (There are pages that don't have a settings block so we shouldn't throw an error on those pages).
if (strpos($PAGE->pagetype, 'course-view') === 0 || $PAGE->pagetype === 'site-index') {
debugging('Settings block was not found on this page', DEBUG_DEVELOPER);
}
return;
}
// Core Moodle API appears to be missing a 'get block by name' function.
// Cycle through all regions and block instances until we find settings.
foreach ($PAGE->blocks->get_regions() as $region) {
foreach ($PAGE->blocks->get_blocks_for_region($region) as $block) {
if (isset($block->instance) && $block->instance->blockname == 'settings') {
$this->instanceid = $block->instance->id;
break 2;
}
}
}
if (!has_capability('moodle/block:view', \context_block::instance($this->instanceid))) {
return;
}
$this->output = true;
}
示例9: block_jmail_get_context
/**
* Returns the jmail context
*
* @param int $context The context
* @param int $id The context id
* @param int $flags The flags to be used
* @return stdClass An object instance
*/
function block_jmail_get_context($context, $id = null, $flags = null)
{
if ($context == CONTEXT_SYSTEM) {
if (class_exists('context_system')) {
return context_system::instance();
} else {
return get_context_instance(CONTEXT_SYSTEM);
}
} else {
if ($context == CONTEXT_COURSE) {
if (class_exists('context_course')) {
return context_course::instance($id, $flags);
} else {
return get_context_instance($context, $id, $flags);
}
} else {
if ($context == CONTEXT_COURSECAT) {
if (class_exists('context_coursecat')) {
return context_coursecat::instance($id, $flags);
} else {
return get_context_instance($context, $id, $flags);
}
} else {
if ($context == CONTEXT_BLOCK) {
if (class_exists('context_block')) {
return context_block::instance($id, $flags);
} else {
return get_context_instance($context, $id, $flags);
}
} else {
if ($context == CONTEXT_USER) {
if (class_exists('context_user')) {
return context_user::instance($id, $flags);
} else {
return get_context_instance($context, $id, $flags);
}
}
}
}
}
}
}
示例10: my_copy_page
function my_copy_page($userid, $private = MY_PAGE_PRIVATE, $pagetype = 'my-index')
{
global $DB;
if ($customised = $DB->get_record('my_pages', array('userid' => $userid, 'private' => $private))) {
return $customised;
// We're done!
}
// Get the system default page
if (!($systempage = $DB->get_record('my_pages', array('userid' => null, 'private' => $private)))) {
return false;
// error
}
// Clone the basic system page record
$page = clone $systempage;
unset($page->id);
$page->userid = $userid;
$page->id = $DB->insert_record('my_pages', $page);
// Clone ALL the associated blocks as well
$systemcontext = context_system::instance();
$usercontext = context_user::instance($userid);
$blockinstances = $DB->get_records('block_instances', array('parentcontextid' => $systemcontext->id, 'pagetypepattern' => $pagetype, 'subpagepattern' => $systempage->id));
foreach ($blockinstances as $instance) {
$originalid = $instance->id;
unset($instance->id);
$instance->parentcontextid = $usercontext->id;
$instance->subpagepattern = $page->id;
$instance->id = $DB->insert_record('block_instances', $instance);
$blockcontext = context_block::instance($instance->id);
// Just creates the context record
$block = block_instance($instance->blockname, $instance);
if (!$block->instance_copy($originalid)) {
debugging("Unable to copy block-specific data for original block instance: {$originalid}\n to new block instance: {$instance->id}", DEBUG_DEVELOPER);
}
}
// FIXME: block position overrides should be merged in with block instance
//$blockpositions = $DB->get_records('block_positions', array('subpage' => $page->name));
//foreach($blockpositions as $positions) {
// $positions->subpage = $page->name;
// $DB->insert_record('block_positions', $tc);
//}
return $page;
}
示例11: get_content
/**
* Return the block content.
* @uses $CFG
* @return string The block content.
*/
public function get_content()
{
global $CFG;
// Checking content cached
if ($this->content !== NULL) {
return $this->content;
}
// Creating new content
$this->content = new stdClass();
$this->content->footer = '';
// Getting context
$context = context_block::instance($this->instance->id);
// Setting content depending on capabilities
if (isloggedin()) {
if (has_capability('local/vmoodle:managevmoodles', $context)) {
$this->content->footer = '<a href="' . $CFG->wwwroot . '/local/vmoodle/view.php">' . get_string('administrate', 'block_vmoodle') . '</a><br/>';
$this->content->text = $this->_print_status();
} else {
$this->content->text = get_string('notallowed', 'block_vmoodle');
}
}
// Returning content
return $this->content;
}
示例12: block_progress_get_block_context
/**
* Gets the block context, allowing for old and new Moodle instances.
*
* @param int $block The block ID
* @return stdClass The context object
*/
function block_progress_get_block_context($blockid)
{
if (class_exists('context_block')) {
return context_block::instance($blockid);
} else {
return get_context_instance(CONTEXT_BLOCK, $blockid);
}
}
示例13: required_param
require_once $CFG->dirroot . '/blocks/moodletxt/dao/MoodletxtMoodleUserDAO.php';
require_once $CFG->dirroot . '/blocks/moodletxt/dao/TxttoolsSentMessageDAO.php';
require_once $CFG->dirroot . '/blocks/moodletxt/dao/MoodletxtUserStatsDAO.php';
require_once $CFG->dirroot . '/blocks/moodletxt/forms/renderers/QuickFormRendererWithSlides.php';
require_once $CFG->dirroot . '/blocks/moodletxt/forms/MoodletxtSendMessageForm.php';
require_once $CFG->dirroot . '/blocks/moodletxt/connect/MoodletxtOutboundControllerFactory.php';
$courseId = required_param('course', PARAM_INT);
$instanceId = required_param('instance', PARAM_INT);
$replyType = optional_param('replyType', '', PARAM_ALPHA);
$replyValue = optional_param('replyValue', '', PARAM_RAW_TRIMMED);
if ($replyType == 'additional' && !MoodletxtPhoneNumber::validatePhoneNumber($replyValue)) {
$replyType = '';
$replyValue = '';
}
require_login($courseId, false);
$blockcontext = context_block::instance($instanceId);
require_capability('block/moodletxt:sendmessages', $blockcontext, $USER->id);
// OK, so you're legit. Let's load DAOs and required DB data
$templateDAO = new MoodletxtTemplatesDAO();
$accountDAO = new TxttoolsAccountDAO();
$addressbookDAO = new MoodletxtAddressbookDAO();
$userDAO = new MoodletxtMoodleUserDAO();
$messageDAO = new TxttoolsSentMessageDAO();
$statsDAO = new MoodletxtUserStatsDAO();
$course = $DB->get_record('course', array('id' => $courseId));
$notifications = '';
// Set up the page for rendering
$PAGE->set_url('/blocks/moodletxt/send.php');
$PAGE->set_title(get_string('titlesend', 'block_moodletxt') . ' ' . $course->fullname);
$PAGE->set_heading(get_string('headersend', 'block_moodletxt'));
$PAGE->set_pagelayout('incourse');
示例14: dirname
* File generate_coupon_step_four.php
* Encoding UTF-8
*
* @package block_coupon
*
* @copyright Sebsoft.nl
* @author Menno de Ridder <menno@sebsoft.nl>
* @author R.J. van Dongen <rogier@sebsoft.nl>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once dirname(__FILE__) . '/../../../config.php';
require_once $CFG->dirroot . '/blocks/coupon/classes/settings.php';
use block_coupon\helper;
$id = required_param('id', PARAM_INT);
$instance = $DB->get_record('block_instances', array('id' => $id), '*', MUST_EXIST);
$context = \context_block::instance($instance->id);
$coursecontext = $context->get_course_context(false);
$course = false;
if ($coursecontext !== false) {
$course = $DB->get_record("course", array("id" => $coursecontext->instanceid));
}
if ($course === false) {
$course = get_site();
}
require_login($course, true);
$PAGE->navbar->add(get_string('page:generate_coupon_step_four.php:title', 'block_coupon'));
$url = new moodle_url('/blocks/coupon/view/generate_coupon_step_four.php', array('id' => $id));
$PAGE->set_url($url);
$PAGE->set_title(get_string('view:generate_coupon:title', 'block_coupon'));
$PAGE->set_heading(get_string('view:generate_coupon:heading', 'block_coupon'));
$PAGE->set_context($context);
示例15: required_param
$courseid = required_param('courseid', PARAM_INT);
$blockid = required_param('blockid', PARAM_INT);
// Next look for optional variables.
$occurrenceid = optional_param('occurrenceid', 0, PARAM_INT);
$mode = optional_param('mode', 'list', PARAM_ALPHANUMEXT);
// Force the browse mode ('list')
$edit = optional_param('edit', -1, PARAM_INT);
$approve = optional_param('approve', 0, PARAM_INT);
//approval recordid
$delete = optional_param('delete', 0, PARAM_INT);
//delete recordid
if (!($course = $DB->get_record('course', array('id' => $courseid)))) {
print_error('invalidcourse', 'block_referentiel', $courseid);
}
$contextcourse = context_course::instance($course->id);
$context = context_block::instance($blockid);
require_login($course);
$params = array("blockid" => $blockid, "courseid" => $courseid, "occurrenceid" => $occurrenceid);
$occurrence_object = new occurrence($params);
$currenttab = 'list';
if ($mode == 'edit') {
$currenttab = 'edit';
}
$pagetitle = get_string('occurrence', 'block_referentiel', $occurrence_object->referentiel->code_referentiel);
$PAGE->set_url('/blocks/referentiel/view.php', array('blockid' => $blockid, 'courseid' => $courseid, 'occurrenceid' => $occurrenceid, 'mode' => $mode));
$PAGE->requires->css('/mod/referentiel/referentiel.css');
$PAGE->requires->js('/mod/referentiel/functions.js');
$PAGE->set_pagelayout('standard');
$PAGE->set_heading($course->fullname);
$PAGE->set_title($pagetitle);
$PAGE->navbar->add($occurrence_object->referentiel->code_referentiel);