本文整理汇总了PHP中context类的典型用法代码示例。如果您正苦于以下问题:PHP context类的具体用法?PHP context怎么用?PHP context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: core_role_get_potential_user_selector
/**
* Get the potential assignees selector for a given context.
*
* If this context is a course context, or inside a course context (module or
* some blocks) then return a core_role_potential_assignees_below_course object. Otherwise
* return a core_role_potential_assignees_course_and_above.
*
* @param context $context a context.
* @param string $name passed to user selector constructor.
* @param array $options to user selector constructor.
* @return user_selector_base an appropriate user selector.
*/
function core_role_get_potential_user_selector(context $context, $name, $options)
{
$blockinsidecourse = false;
if ($context->contextlevel == CONTEXT_BLOCK) {
$parentcontext = $context->get_parent_context();
$blockinsidecourse = in_array($parentcontext->contextlevel, array(CONTEXT_MODULE, CONTEXT_COURSE));
}
if (($context->contextlevel == CONTEXT_MODULE || $blockinsidecourse) && !is_inside_frontpage($context)) {
$potentialuserselector = new core_role_potential_assignees_below_course('addselect', $options);
} else {
$potentialuserselector = new core_role_potential_assignees_course_and_above('addselect', $options);
}
return $potentialuserselector;
}
示例2: definition
function definition()
{
global $CFG, $DB;
$mform = $this->_form;
list($instance, $plugin, $course) = $this->_customdata;
$coursecontext = context_course::instance($course->id);
$enrol = enrol_get_plugin('cohort');
$groups = array(0 => get_string('none'));
foreach (groups_get_all_groups($course->id) as $group) {
$groups[$group->id] = format_string($group->name, true, array('context' => $coursecontext));
}
$mform->addElement('header', 'general', get_string('pluginname', 'enrol_cohort'));
$mform->addElement('text', 'name', get_string('custominstancename', 'enrol'));
$mform->setType('name', PARAM_TEXT);
$options = array(ENROL_INSTANCE_ENABLED => get_string('yes'), ENROL_INSTANCE_DISABLED => get_string('no'));
$mform->addElement('select', 'status', get_string('status', 'enrol_cohort'), $options);
if ($instance->id) {
if ($cohort = $DB->get_record('cohort', array('id' => $instance->customint1))) {
$cohorts = array($instance->customint1 => format_string($cohort->name, true, array('context' => context::instance_by_id($cohort->contextid))));
} else {
$cohorts = array($instance->customint1 => get_string('error'));
}
$mform->addElement('select', 'customint1', get_string('cohort', 'cohort'), $cohorts);
$mform->setConstant('customint1', $instance->customint1);
$mform->hardFreeze('customint1', $instance->customint1);
} else {
$cohorts = array('' => get_string('choosedots'));
$allcohorts = cohort_get_available_cohorts($coursecontext, 0, 0, 0);
foreach ($allcohorts as $c) {
$cohorts[$c->id] = format_string($c->name);
}
$mform->addElement('select', 'customint1', get_string('cohort', 'cohort'), $cohorts);
$mform->addRule('customint1', get_string('required'), 'required', null, 'client');
}
$roles = get_assignable_roles($coursecontext);
$roles[0] = get_string('none');
$roles = array_reverse($roles, true);
// Descending default sortorder.
$mform->addElement('select', 'roleid', get_string('assignrole', 'enrol_cohort'), $roles);
$mform->setDefault('roleid', $enrol->get_config('roleid'));
if ($instance->id and !isset($roles[$instance->roleid])) {
if ($role = $DB->get_record('role', array('id' => $instance->roleid))) {
$roles = role_fix_names($roles, $coursecontext, ROLENAME_ALIAS, true);
$roles[$instance->roleid] = role_get_name($role, $coursecontext);
} else {
$roles[$instance->roleid] = get_string('error');
}
}
$mform->addElement('select', 'customint2', get_string('addgroup', 'enrol_cohort'), $groups);
$mform->addElement('hidden', 'courseid', null);
$mform->setType('courseid', PARAM_INT);
$mform->addElement('hidden', 'id', null);
$mform->setType('id', PARAM_INT);
if ($instance->id) {
$this->add_action_buttons(true);
} else {
$this->add_action_buttons(true, get_string('addinstance', 'enrol'));
}
$this->set_data($instance);
}
示例3: get_instance_name
/**
* Returns localised name of enrol instance.
*
* @param stdClass $instance (null is accepted too)
* @return string
*/
public function get_instance_name($instance)
{
global $DB;
if (empty($instance)) {
$enrol = $this->get_name();
return get_string('pluginname', 'enrol_' . $enrol);
} else {
if (empty($instance->name)) {
$enrol = $this->get_name();
$cohort = $DB->get_record('cohort', array('id' => $instance->customint1));
if (!$cohort) {
return get_string('pluginname', 'enrol_' . $enrol);
}
$cohortname = format_string($cohort->name, true, array('context' => context::instance_by_id($cohort->contextid)));
if ($role = $DB->get_record('role', array('id' => $instance->roleid))) {
$role = role_get_name($role, context_course::instance($instance->courseid, IGNORE_MISSING));
return get_string('pluginname', 'enrol_' . $enrol) . ' (' . $cohortname . ' - ' . $role . ')';
} else {
return get_string('pluginname', 'enrol_' . $enrol) . ' (' . $cohortname . ')';
}
} else {
return format_string($instance->name, true, array('context' => context_course::instance($instance->courseid)));
}
}
}
示例4: block_html_pluginfile
/**
* Form for editing HTML block instances.
*
* @copyright 2010 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package block_html
* @category files
* @param stdClass $course course object
* @param stdClass $birecord_or_cm block instance record
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @param array $options additional options affecting the file serving
* @return bool
*/
function block_html_pluginfile($course, $birecord_or_cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
global $SCRIPT;
if ($context->contextlevel != CONTEXT_BLOCK) {
send_file_not_found();
}
require_course_login($course);
if ($filearea !== 'content') {
send_file_not_found();
}
$fs = get_file_storage();
$filename = array_pop($args);
$filepath = $args ? '/' . implode('/', $args) . '/' : '/';
if (!($file = $fs->get_file($context->id, 'block_html', 'content', 0, $filepath, $filename)) or $file->is_directory()) {
send_file_not_found();
}
if ($parentcontext = context::instance_by_id($birecord_or_cm->parentcontextid, IGNORE_MISSING)) {
if ($parentcontext->contextlevel == CONTEXT_USER) {
// force download on all personal pages including /my/
//because we do not have reliable way to find out from where this is used
$forcedownload = true;
}
} else {
// weird, there should be parent context, better force dowload then
$forcedownload = true;
}
session_get_instance()->write_close();
send_stored_file($file, 60 * 60, 0, $forcedownload, $options);
}
示例5: defaultData
/**
* Retrieve the data from the url and make the base initialization
*
* @return void
*/
protected function defaultData()
{
$context = Context::getInstance();
$this->setData('extension', context::getInstance()->getExtensionName());
$this->setData('module', $context->getModuleName());
$this->setData('action', $context->getActionName());
if ($this->hasRequestParameter('uri')) {
// @todo stop using session to manage uri/classUri
$this->setSessionAttribute('uri', $this->getRequestParameter('uri'));
// inform the client of new classUri
$this->setData('uri', $this->getRequestParameter('uri'));
}
if ($this->hasRequestParameter('classUri')) {
// @todo stop using session to manage uri/classUri
$this->setSessionAttribute('classUri', $this->getRequestParameter('classUri'));
if (!$this->hasRequestParameter('uri')) {
$this->removeSessionAttribute('uri');
}
// inform the client of new classUri
$this->setData('uri', $this->getRequestParameter('classUri'));
}
if ($this->getRequestParameter('message')) {
$this->setData('message', $this->getRequestParameter('message'));
}
if ($this->getRequestParameter('errorMessage')) {
$this->setData('errorMessage', $this->getRequestParameter('errorMessage'));
}
$this->setData('client_timeout', $this->getClientTimeout());
$this->setData('client_config_url', $this->getClientConfigUrl());
}
示例6: procCashpayDoIt
/**
* @brief pay
*/
function procCashpayDoIt()
{
$oEpayController = getController('epay');
$vars = Context::getRequestVars();
$output = $oEpayController->beforePayment($vars);
if (!$output->toBool()) {
return $output;
}
$obj = new stdClass();
$obj->bank_name = $this->module_info->bank_name;
$obj->account_number = $this->module_info->account_number;
$obj->account_holder = $this->module_info->account_holder;
$output = new Object();
$output->add('transaction_srl', Context::get('transaction_srl'));
$output->add('state', '1');
// not completed
$output->add('payment_method', 'BT');
$output->add('payment_amount', Context::get('price'));
$output->add('result_code', '0');
$output->add('result_message', 'success');
$output->add('pg_tid', $this->keygen());
$output->add('vact_bankname', $obj->bank_name);
$output->add('vact_num', $obj->account_number);
$output->add('vact_name', $obj->account_holder);
$output->add('vact_inputname', context::get('depositor_name'));
// afterPayment will call an after trigger
$output = $oEpayController->afterPayment($output);
if (!$output->toBool()) {
return $output;
}
$return_url = $output->get('return_url');
if ($return_url) {
$this->setRedirectUrl($return_url);
}
}
示例7: __construct
public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array()) {
global $SESSION, $CFG, $DB, $PAGE;
if (!is_numeric($repositoryid)) {
// ELIS-8550: were constructing these with repositoryid = 'elisfiles'
$sql = 'SELECT MIN(ri.id)
FROM {repository} r
JOIN {repository_instances} ri
ON r.id = ri.typeid
WHERE r.type = ?';
$repositoryid = $DB->get_field_sql($sql, array($repositoryid));
}
parent::__construct($repositoryid, $context, $options);
require_once dirname(__FILE__). '/ELIS_files_factory.class.php';
if (is_object($context)) {
$this->context = $context;
} else {
$this->context = context::instance_by_id($context);
}
/// ELIS files class
$this->elis_files = repository_factory::factory();
$this->config = get_config('elisfiles');
$this->current_node = null;
// jQuery files required for file picker - just for this repository
$PAGE->requires->js('/repository/elisfiles/js/jquery-1.6.2.min.js');
$PAGE->requires->js('/repository/elisfiles/js/jquery-ui-1.8.16.custom.min.js');
$PAGE->requires->js('/repository/elisfiles/js/fileuploader.js');
$PAGE->requires->js('/repository/elisfiles/lib/HTML_TreeMenu-1.2.0/TreeMenu.js', true);
}
示例8: __construct
/**
* Add question-type specific form fields.
*
* @param MoodleQuickForm $mform the form being built.
*/
public function __construct($submiturl, $question, $regenerate)
{
global $SESSION, $CFG, $DB;
$this->regenerate = $regenerate;
$this->question = $question;
$this->qtypeobj = question_bank::get_qtype($this->question->qtype);
// Validate the question category.
if (!($category = $DB->get_record('question_categories', array('id' => $question->category)))) {
print_error('categorydoesnotexist', 'question', $returnurl);
}
$this->category = $category;
$this->categorycontext = context::instance_by_id($category->contextid);
// Get the dataset defintions for this question.
if (empty($question->id)) {
$this->datasetdefs = $this->qtypeobj->get_dataset_definitions($question->id, $SESSION->calculated->definitionform->dataset);
} else {
if (empty($question->options)) {
$this->get_question_options($question);
}
$this->datasetdefs = $this->qtypeobj->get_dataset_definitions($question->id, array());
}
foreach ($this->datasetdefs as $datasetdef) {
// Get maxnumber.
if ($this->maxnumber == -1 || $datasetdef->itemcount < $this->maxnumber) {
$this->maxnumber = $datasetdef->itemcount;
}
}
foreach ($this->datasetdefs as $defid => $datasetdef) {
if (isset($datasetdef->id)) {
$this->datasetdefs[$defid]->items = $this->qtypeobj->get_database_dataset_items($datasetdef->id);
}
}
parent::__construct($submiturl);
}
示例9: get_owning_activity
/**
* If this block belongs to a activity context, then return that activity's id.
* Otherwise, return 0.
* @return stdclass the activity record.
*/
public function get_owning_activity()
{
global $DB;
// Set some defaults.
$result = new stdClass();
$result->id = 0;
if (empty($this->instance->parentcontextid)) {
return $result;
}
$parentcontext = context::instance_by_id($this->instance->parentcontextid);
if ($parentcontext->contextlevel != CONTEXT_MODULE) {
return $result;
}
$cm = get_coursemodule_from_id($this->page->cm->modname, $parentcontext->instanceid);
if (!$cm) {
return $result;
}
// Get the grade_items id.
$rec = $DB->get_record('grade_items', array('iteminstance' => $cm->instance, 'itemmodule' => $this->page->cm->modname));
if (!$rec) {
return $result;
}
// See if it is a gradable activity.
if ($rec->gradetype != GRADE_TYPE_VALUE && $rec->gradetype != GRADE_TYPE_SCALE) {
return $result;
}
return $rec;
}
示例10: getInstance
/**
* @return context
*/
public static function getInstance()
{
if (self::$instance == null) {
self::$instance = new context();
}
return self::$instance;
}
示例11: specific_definition
protected function specific_definition($mform)
{
global $CFG;
// Fields for editing HTML block title and contents.
$mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
$mform->addElement('text', 'config_title', get_string('configtitle', 'block_tags'));
$mform->setType('config_title', PARAM_TEXT);
$mform->setDefault('config_title', get_string('pluginname', 'block_tags'));
$this->add_collection_selector($mform);
$numberoftags = array();
for ($i = 1; $i <= 200; $i++) {
$numberoftags[$i] = $i;
}
$mform->addElement('select', 'config_numberoftags', get_string('numberoftags', 'blog'), $numberoftags);
$mform->setDefault('config_numberoftags', 80);
$defaults = array('official' => get_string('officialonly', 'block_tags'), '' => get_string('anytype', 'block_tags'));
$mform->addElement('select', 'config_tagtype', get_string('defaultdisplay', 'block_tags'), $defaults);
$mform->setDefault('config_tagtype', '');
$defaults = array(0 => context_system::instance()->get_context_name());
$parentcontext = context::instance_by_id($this->block->instance->parentcontextid);
if ($parentcontext->contextlevel > CONTEXT_COURSE) {
$coursecontext = $parentcontext->get_course_context();
$defaults[$coursecontext->id] = $coursecontext->get_context_name();
}
if ($parentcontext->contextlevel != CONTEXT_SYSTEM) {
$defaults[$parentcontext->id] = $parentcontext->get_context_name();
}
$mform->addElement('select', 'config_ctx', get_string('taggeditemscontext', 'block_tags'), $defaults);
$mform->addHelpButton('config_ctx', 'taggeditemscontext', 'block_tags');
$mform->setDefault('config_ctx', 0);
$mform->addElement('advcheckbox', 'config_rec', get_string('recursivecontext', 'block_tags'));
$mform->addHelpButton('config_rec', 'recursivecontext', 'block_tags');
$mform->setDefault('config_rec', 1);
}
示例12: definition
function definition()
{
global $CFG, $DB;
$mform = $this->_form;
$course = $this->_customdata;
$coursecontext = context_course::instance($course->id);
$enrol = enrol_get_plugin('cohort');
$cohorts = array('' => get_string('choosedots'));
list($sqlparents, $params) = $DB->get_in_or_equal(get_parent_contexts($coursecontext));
$sql = "SELECT id, name, contextid\n FROM {cohort}\n WHERE contextid {$sqlparents}\n ORDER BY name ASC";
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $c) {
$context = context::instance_by_id($c->contextid);
if (!has_capability('moodle/cohort:view', $context)) {
continue;
}
$cohorts[$c->id] = format_string($c->name);
}
$rs->close();
$roles = get_assignable_roles($coursecontext);
$roles[0] = get_string('none');
$roles = array_reverse($roles, true);
// descending default sortorder
$mform->addElement('header', 'general', get_string('pluginname', 'enrol_cohort'));
$mform->addElement('select', 'cohortid', get_string('cohort', 'cohort'), $cohorts);
$mform->addRule('cohortid', get_string('required'), 'required', null, 'client');
$mform->addElement('select', 'roleid', get_string('role'), $roles);
$mform->addRule('roleid', get_string('required'), 'required', null, 'client');
$mform->setDefault('roleid', $enrol->get_config('roleid'));
$mform->addElement('hidden', 'id', null);
$mform->setType('id', PARAM_INT);
$this->add_action_buttons(true, get_string('addinstance', 'enrol'));
$this->set_data(array('id' => $course->id));
}
示例13: qtype_ddmarker_course_context_id
function qtype_ddmarker_course_context_id($catcontextid)
{
$context = context::instance_by_id($catcontextid);
while ($context->contextlevel != CONTEXT_COURSE) {
$context = $context->get_parent_context();
}
return $context->id;
}
示例14: handle_ajax
/**
* Retrieves ajax parameters for content and update or delete
* user data depending on params.
*
* @throws \coding_exception
*/
public static function handle_ajax()
{
global $DB;
// Query String Parameters.
$content_id = required_param('content_id', PARAM_INT);
$data_id = required_param('data_type', PARAM_RAW);
$sub_content_id = required_param('sub_content_id', PARAM_INT);
// Form Data.
$data = optional_param('data', null, PARAM_RAW);
$pre_load = optional_param('preload', null, PARAM_INT);
$invalidate = optional_param('invalidate', null, PARAM_INT);
if ($content_id === null || $data_id === null || $sub_content_id === null) {
\H5PCore::ajaxError(get_string('missingparameters', 'hvp'));
exit;
// Missing parameters.
}
// Saving data
if ($data !== NULL && $pre_load !== NULL && $invalidate !== NULL) {
// Validate token
if (!\H5PCore::validToken('contentuserdata', required_param('token', PARAM_RAW))) {
\H5PCore::ajaxError(get_string('invalidtoken', 'hvp'));
exit;
}
// Use context id if supplied
$context_id = optional_param('contextId', null, PARAM_INT);
if ($context_id) {
$context = \context::instance_by_id($context_id);
} else {
// Otherwise try to find it from content id
$context = \context_course::instance($DB->get_field('hvp', 'course', array('id' => $content_id)));
}
// Check permissions
if (!has_capability('mod/hvp:savecontentuserdata', $context)) {
\H5PCore::ajaxError(get_string('nopermissiontosavecontentuserdata', 'hvp'));
http_response_code(403);
exit;
}
if ($data === '0') {
// Delete user data.
self::delete_user_data($content_id, $sub_content_id, $data_id);
} else {
// Save user data.
self::save_user_data($content_id, $sub_content_id, $data_id, $pre_load, $invalidate, $data);
}
\H5PCore::ajaxSuccess();
} else {
// Fetch user data
$user_data = self::get_user_data($content_id, $sub_content_id, $data_id);
if ($user_data === false) {
// Did not find data, return nothing
\H5PCore::ajaxSuccess();
} else {
// Found data, return encoded data
\H5PCore::ajaxSuccess($user_data->data);
}
}
exit;
}
示例15: getLibraries
/**
* Decides which content types the editor should have.
*
* Two usecases:
* 1. No input, will list all the available content types.
* 2. Libraries supported are specified, load additional data and verify
* that the content types are available. Used by e.g. the Presentation Tool
* Editor that already knows which content types are supported in its
* slides.
*
* @param array $libraries List of library names + version to load info for
* @return array List of all libraries loaded
*/
public function getLibraries($libraries = null)
{
global $DB;
$context_id = required_param('contextId', PARAM_RAW);
$super_user = has_capability('mod/hvp:userestrictedlibraries', \context::instance_by_id($context_id));
if ($libraries !== null) {
// Get details for the specified libraries only.
$librarieswithdetails = array();
foreach ($libraries as $library) {
// Look for library
$details = $DB->get_record_sql("SELECT title,\n runnable,\n restricted,\n tutorial_url\n FROM {hvp_libraries}\n WHERE machine_name = ?\n AND major_version = ?\n AND minor_version = ?\n AND semantics IS NOT NULL\n ", array($library->name, $library->majorVersion, $library->minorVersion));
if ($details) {
// Library found, add details to list
$library->tutorialUrl = $details->tutorial_url;
$library->title = $details->title;
$library->runnable = $details->runnable;
$library->restricted = $super_user ? false : ($details->restricted === '1' ? true : false);
$librarieswithdetails[] = $library;
}
}
// Done, return list with library details
return $librarieswithdetails;
}
// Load all libraries
$libraries = array();
$librariesresult = $DB->get_records_sql("SELECT id,\n machine_name AS name,\n title,\n major_version,\n minor_version,\n tutorial_url,\n restricted\n FROM {hvp_libraries}\n WHERE runnable = 1\n AND semantics IS NOT NULL\n ORDER BY title");
foreach ($librariesresult as $library) {
// Remove unique index
unset($library->id);
// Convert snakes to camels
$library->majorVersion = (int) $library->major_version;
unset($library->major_version);
$library->minorVersion = (int) $library->minor_version;
unset($library->minor_version);
if (!empty($library->tutorial_url)) {
$library->tutorialUrl = $library->tutorial_url;
}
unset($library->tutorial_url);
// Make sure we only display the newest version of a library.
foreach ($libraries as $key => $existinglibrary) {
if ($library->name === $existinglibrary->name) {
// Found library with same name, check versions
if ($library->majorVersion === $existinglibrary->majorVersion && $library->minorVersion > $existinglibrary->minorVersion || $library->majorVersion > $existinglibrary->majorVersion) {
// This is a newer version
$existinglibrary->isOld = true;
} else {
// This is an older version
$library->isOld = true;
}
}
}
// Check to see if content type should be restricted
$library->restricted = $super_user ? false : ($library->restricted === '1' ? true : false);
// Add new library
$libraries[] = $library;
}
return $libraries;
}