本文整理汇总了PHP中context::instance_by_id方法的典型用法代码示例。如果您正苦于以下问题:PHP context::instance_by_id方法的具体用法?PHP context::instance_by_id怎么用?PHP context::instance_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类context
的用法示例。
在下文中一共展示了context::instance_by_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例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: __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);
}
示例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: 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));
}
示例6: __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);
}
示例7: 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)));
}
}
}
示例8: 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;
}
示例9: 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;
}
示例10: 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;
}
示例11: 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;
}
示例12: get_description
/**
* Returns a string describing the rule.
*
* @return string
*/
public function get_description()
{
$context = context::instance_by_id($this->value, IGNORE_MISSING);
$contextname = get_string('errorunknownmodule', 'block_xp');
if ($context) {
$contextname = $context->get_context_name();
}
return get_string('rulecmdesc', 'block_xp', (object) array('contextname' => $contextname));
}
示例13: tool_capability_calculate_role_data
/**
* Calculates capability data organised by context for the given roles.
*
* @param string $capability The capability to get data for.
* @param array $roles An array of roles to get data for.
* @return context[] An array of contexts.
*/
function tool_capability_calculate_role_data($capability, array $roles)
{
global $DB;
$systemcontext = context_system::instance();
$roleids = array_keys($roles);
// Work out the bits needed for the SQL WHERE clauses.
$params = array($capability);
list($sqlroletest, $roleparams) = $DB->get_in_or_equal($roleids);
$params = array_merge($params, $roleparams);
$sqlroletest = 'AND roleid ' . $sqlroletest;
// Get all the role_capabilities rows for this capability - that is, all
// role definitions, and all role overrides.
$sql = 'SELECT id, roleid, contextid, permission
FROM {role_capabilities}
WHERE capability = ? ' . $sqlroletest;
$rolecaps = $DB->get_records_sql($sql, $params);
// In order to display a nice tree of contexts, we need to get all the
// ancestors of all the contexts in the query we just did.
$sql = 'SELECT DISTINCT con.path, 1
FROM {context} con
JOIN {role_capabilities} rc ON rc.contextid = con.id
WHERE capability = ? ' . $sqlroletest;
$relevantpaths = $DB->get_records_sql_menu($sql, $params);
$requiredcontexts = array($systemcontext->id);
foreach ($relevantpaths as $path => $notused) {
$requiredcontexts = array_merge($requiredcontexts, explode('/', trim($path, '/')));
}
$requiredcontexts = array_unique($requiredcontexts);
// Now load those contexts.
list($sqlcontexttest, $contextparams) = $DB->get_in_or_equal($requiredcontexts);
$contexts = get_sorted_contexts('ctx.id ' . $sqlcontexttest, $contextparams);
// Prepare some empty arrays to hold the data we are about to compute.
foreach ($contexts as $conid => $con) {
$contexts[$conid]->children = array();
$contexts[$conid]->rolecapabilities = array();
}
// Put the contexts into a tree structure.
foreach ($contexts as $conid => $con) {
$context = context::instance_by_id($conid);
$parentcontext = $context->get_parent_context();
if ($parentcontext) {
$contexts[$parentcontext->id]->children[] = $conid;
}
}
// Put the role capabilities into the context tree.
foreach ($rolecaps as $rolecap) {
$contexts[$rolecap->contextid]->rolecapabilities[$rolecap->roleid] = $rolecap->permission;
}
// Fill in any missing rolecaps for the system context.
foreach ($roleids as $roleid) {
if (!isset($contexts[$systemcontext->id]->rolecapabilities[$roleid])) {
$contexts[$systemcontext->id]->rolecapabilities[$roleid] = CAP_INHERIT;
}
}
return $contexts;
}
示例14: col_name
/**
* Generate the name column.
*
* @param \stdClass $tool event data.
* @return string
*/
public function col_name($tool)
{
if (empty($tool->name)) {
$toolcontext = \context::instance_by_id($tool->contextid);
$name = $toolcontext->get_context_name();
} else {
$name = $tool->name;
}
return $this->get_display_text($tool, $name);
}
示例15: block_informationspot_pluginfile
/**
* Form for editing Information Spot block instances.
*
* @copyright 2014 Roberto Pinna
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package block_informationspot
* @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_informationspot_pluginfile($course, $birecord_or_cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
global $DB, $CFG, $USER;
if ($context->contextlevel != CONTEXT_BLOCK) {
send_file_not_found();
}
// If block is in course context, then check if user has capability to access course.
if ($context->get_course_context(false)) {
require_course_login($course);
} else {
if ($CFG->forcelogin) {
require_login();
} else {
// Get parent context and see if user have proper permission.
$parentcontext = $context->get_parent_context();
if ($parentcontext->contextlevel === CONTEXT_COURSECAT) {
// Check if category is visible and user can view this category.
$category = $DB->get_record('course_categories', array('id' => $parentcontext->instanceid), '*', MUST_EXIST);
if (!$category->visible) {
require_capability('moodle/category:viewhiddencategories', $parentcontext);
}
} else {
if ($parentcontext->contextlevel === CONTEXT_USER && $parentcontext->instanceid != $USER->id) {
// The block is in the context of a user, it is only visible to the user who it belongs to.
send_file_not_found();
}
}
// At this point there is no way to check SYSTEM context, so ignoring it.
}
}
if ($filearea != 'image') {
send_file_not_found();
}
$fs = get_file_storage();
$imageid = array_shift($args);
$filename = array_pop($args);
$filepath = $args ? '/' . implode('/', $args) . '/' : '/';
if (!($file = $fs->get_file($context->id, 'block_informationspot', $filearea, $imageid, $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;
}
// NOTE: it woudl be nice to have file revisions here, for now rely on standard file lifetime,
// do not lower it because the files are dispalyed very often.
\core\session\manager::write_close();
send_stored_file($file, null, 0, $forcedownload, $options);
}