本文整理汇总了PHP中get_context_instance_by_id函数的典型用法代码示例。如果您正苦于以下问题:PHP get_context_instance_by_id函数的具体用法?PHP get_context_instance_by_id怎么用?PHP get_context_instance_by_id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_context_instance_by_id函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: retrieveFile
/**
* Retrieve a file for a user of the Moodle client calling this function
* The file is encoded in base64
* @global <type> $DB
* @global <type> $USER
* @global <type> $MNET_REMOTE_CLIENT
* @param <type> $username
* @param <type> $source
* @return <type>
*/
public function retrieveFile($username, $source)
{
global $DB, $USER, $MNET_REMOTE_CLIENT;
///check the the user is known
///he has to be previously connected to the server site in order to be in the database
//TODO: this seems weird - is it executed from cron or what? Please review
$USER = $DB->get_record('user', array('username' => $username, 'mnethostid' => $MNET_REMOTE_CLIENT->id));
if (empty($USER)) {
exit(mnet_server_fault(9016, get_string('usernotfound', 'repository_remotemoodle', $username)));
}
$file = unserialize(base64_decode($source));
$contextid = $file[0];
$filearea = $file[1];
$itemid = $file[2];
$filepath = $file[3];
$filename = $file[4];
///check that the user has read permission on this file
$browser = get_file_browser();
$fileinfo = $browser->get_file_info(get_context_instance_by_id($contextid), $filearea, $itemid, $filepath, $filename);
if (empty($fileinfo)) {
exit(mnet_server_fault(9016, get_string('usercannotaccess', 'repository_remotemoodle', $file)));
}
///retrieve the file with file API functions and return it encoded in base64
$fs = get_file_storage();
$sf = $fs->get_file($contextid, $filearea, $itemid, $filepath, $filename);
$contents = base64_encode($sf->get_content());
return array($contents, $sf->get_filename());
}
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:38,代码来源:repository.class.php
示例2: role_unassigned
public function role_unassigned($ra)
{
global $DB;
// note: do not test if plugin enabled, we want to keep removing previous roles
// prevent circular dependencies - we can not sync meta roles recursively
if ($ra->component === 'enrol_meta') {
return true;
}
// only course level roles are interesting
$parentcontext = get_context_instance_by_id($ra->contextid);
if ($parentcontext->contextlevel != CONTEXT_COURSE) {
return true;
}
// does anything want to sync with this parent?
if (!($enrols = $DB->get_records('enrol', array('customint1' => $parentcontext->instanceid, 'enrol' => 'meta'), 'id ASC'))) {
return true;
}
// note: do not check 'nosyncroleids', somebody might have just enabled it, we want to get rid of nosync roles gradually
foreach ($enrols as $enrol) {
// Is the user enrolled? We want to sync only really enrolled users
if (!$DB->record_exists('user_enrolments', array('userid' => $ra->userid, 'enrolid' => $enrol->id))) {
continue;
}
$context = get_context_instance(CONTEXT_COURSE, $enrol->courseid);
// now make sure the user does not have the role through some other enrol plugin
$params = array('contextid' => $ra->contextid, 'roleid' => $ra->roleid, 'userid' => $ra->userid);
if ($DB->record_exists_select('role_assignments', "contextid = :contextid AND roleid = :roleid AND userid = :userid AND component <> 'enrol_meta'", $params)) {
continue;
}
// unassign role, there is no other role assignment in parent course
role_unassign($ra->roleid, $ra->userid, $context->id, 'enrol_meta', $enrol->id);
}
return true;
}
开发者ID:sebastiansanio,项目名称:tallerdeprogramacion2fiuba,代码行数:34,代码来源:locallib.php
示例3: 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 = get_context_instance_by_id($birecord_or_cm->parentcontextid)) {
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);
}
开发者ID:nmicha,项目名称:moodle,代码行数:45,代码来源:lib.php
示例4: question_dataset_dependent_items_form
/**
* Add question-type specific form fields.
*
* @param MoodleQuickForm $mform the form being built.
*/
function question_dataset_dependent_items_form($submiturl, $question, $regenerate)
{
global $QTYPES, $SESSION, $CFG, $DB;
$this->regenerate = $regenerate;
$this->question = $question;
$this->qtypeobj =& $QTYPES[$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 = get_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::moodleform($submiturl);
}
开发者ID:ajv,项目名称:Offline-Caching,代码行数:39,代码来源:datasetitems_form.php
示例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 = get_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));
}
开发者ID:nigeli,项目名称:moodle,代码行数:34,代码来源:addinstance_form.php
示例6: module_specific_controls
/**
* Callback function called from question_list() function
* (which is called from showbank())
*/
function module_specific_controls($totalnumber, $recurse, $category, $cmid, $cmoptions)
{
global $QTYPES, $OUTPUT;
$out = '';
$catcontext = get_context_instance_by_id($category->contextid);
if (has_capability('moodle/question:useall', $catcontext)) {
if ($cmoptions->hasattempts) {
$disabled = 'disabled="disabled"';
} else {
$disabled = '';
}
$randomusablequestions = $QTYPES['random']->get_usable_questions_from_category($category->id, $recurse, '0');
$maxrand = count($randomusablequestions);
if ($maxrand > 0) {
for ($i = 1; $i <= min(10, $maxrand); $i++) {
$randomcount[$i] = $i;
}
for ($i = 20; $i <= min(100, $maxrand); $i += 10) {
$randomcount[$i] = $i;
}
$straddtoquiz = get_string('addtoquiz', 'quiz');
$out = '<strong><label for="menurandomcount">' . get_string('addrandomfromcategory', 'quiz') . '</label></strong><br />';
$select = html_select::make($randomcount, 'randomcount', '1', false);
$select->nothingvalue = '';
$select->disabled = $cmoptions->hasattempts;
$out .= get_string('addrandom', 'quiz', $OUTPUT->select($select));
$out .= '<input type="hidden" name="recurse" value="' . $recurse . '" />';
$out .= '<input type="hidden" name="categoryid" value="' . $category->id . '" />';
$out .= ' <input type="submit" name="addrandom" value="' . $straddtoquiz . '" ' . $disabled . ' />';
$out .= $OUTPUT->help_icon(moodle_help_icon::make('random', get_string('random', 'quiz'), 'quiz'));
}
}
return $out;
}
开发者ID:ajv,项目名称:Offline-Caching,代码行数:38,代码来源:edit.php
示例7: role_assigned
/**
* Handle a role assignment by creating an equivalent class enrolment or
* instructor assignment (if applicable).
*/
static function role_assigned($data)
{
require_once CURMAN_DIRLOCATION . '/lib/student.class.php';
require_once CURMAN_DIRLOCATION . '/lib/instructor.class.php';
global $CURMAN;
if (!($context = get_context_instance_by_id($data->contextid))) {
$context = get_context_instance($data->contextid, $data->itemid);
}
if (!empty($context) && $context->contextlevel == context_level_base::get_custom_context_level('class', 'block_curr_admin')) {
$cmuserid = cm_get_crlmuserid($data->userid);
if ($data->roleid == $CURMAN->config->enrolment_role_sync_student_role) {
// add enrolment record
$student = new student();
$student->userid = $cmuserid;
$student->classid = $context->instanceid;
// NOTE: student::add checks if the student is already
// enrolled, so we don't have to check here
$student->add();
}
if ($data->roleid == $CURMAN->config->enrolment_role_sync_instructor_role) {
// add instructor record
if (!instructor::user_is_instructor_of_class($cmuserid, $context->instanceid)) {
$instructor = new instructor();
$instructor->userid = $cmuserid;
$instructor->classid = $context->instanceid;
$instructor->add();
}
}
}
return true;
}
开发者ID:remotelearner,项目名称:elis.cm,代码行数:35,代码来源:lib.php
示例8: module_specific_controls
/**
* Callback function called from question_list() function (which is called from showbank())
*/
function module_specific_controls($totalnumber, $recurse, $category, $cmid)
{
global $QTYPES;
$out = '';
$catcontext = get_context_instance_by_id($category->contextid);
if (has_capability('moodle/question:useall', $catcontext)) {
$randomusablequestions = $QTYPES['random']->get_usable_questions_from_category($category->id, $recurse, '0');
$maxrand = count($randomusablequestions);
if ($maxrand > 0) {
for ($i = 1; $i <= min(10, $maxrand); $i++) {
$randomcount[$i] = $i;
}
for ($i = 20; $i <= min(100, $maxrand); $i += 10) {
$randomcount[$i] = $i;
}
$out .= '<br />';
$out .= get_string('addrandom', 'quiz', choose_from_menu($randomcount, 'randomcount', '1', '', '', '', true));
$out .= '<input type="hidden" name="recurse" value="' . $recurse . '" />';
$out .= '<input type="hidden" name="categoryid" value="' . $category->id . '" />';
$out .= ' <input type="submit" name="addrandom" value="' . get_string('add') . '" />';
$out .= helpbutton('random', get_string('random', 'quiz'), 'quiz', true, false, '', true);
}
}
return $out;
}
开发者ID:JackCanada,项目名称:moodle-hacks,代码行数:28,代码来源:edit.php
示例9: definition
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();
}
开发者ID:ajv,项目名称:Offline-Caching,代码行数:59,代码来源:edit_form.php
示例10: get_listing
/**
* Get file listing
*
* @param string $encodedpath
* @return mixed
*/
public function get_listing($encodedpath = '', $page = '')
{
global $CFG, $USER, $OUTPUT;
$ret = array();
$ret['dynload'] = true;
$ret['nosearch'] = true;
$ret['nologin'] = true;
$list = array();
if (!empty($encodedpath)) {
$params = unserialize(base64_decode($encodedpath));
if (is_array($params)) {
$component = is_null($params['component']) ? NULL : clean_param($params['component'], PARAM_COMPONENT);
$filearea = is_null($params['filearea']) ? NULL : clean_param($params['filearea'], PARAM_AREA);
$itemid = is_null($params['itemid']) ? NULL : clean_param($params['itemid'], PARAM_INT);
$filepath = is_null($params['filepath']) ? NULL : clean_param($params['filepath'], PARAM_PATH);
$filename = is_null($params['filename']) ? NULL : clean_param($params['filename'], PARAM_FILE);
$context = get_context_instance_by_id(clean_param($params['contextid'], PARAM_INT));
}
} else {
$itemid = null;
$filename = null;
$filearea = null;
$filepath = null;
$component = null;
if (!empty($this->context)) {
list($context, $course, $cm) = get_context_info_array($this->context->id);
if (is_object($course)) {
$context = get_context_instance(CONTEXT_COURSE, $course->id);
} else {
$context = get_system_context();
}
} else {
$context = get_system_context();
}
}
$browser = get_file_browser();
$list = array();
if ($fileinfo = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, $filename)) {
// build file tree
$element = repository_local_file::retrieve_file_info($fileinfo, $this);
$nonemptychildren = $element->get_non_empty_children();
foreach ($nonemptychildren as $child) {
$list[] = (array) $child->get_node();
}
} else {
// if file doesn't exist, build path nodes root of current context
$fileinfo = $browser->get_file_info($context, null, null, null, null, null);
}
// build path navigation
$ret['path'] = array();
$element = repository_local_file::retrieve_file_info($fileinfo, $this);
for ($level = $element; $level; $level = $level->get_parent()) {
if ($level == $element || !$level->can_skip()) {
array_unshift($ret['path'], $level->get_node_path());
}
}
$ret['list'] = array_filter($list, array($this, 'filter'));
return $ret;
}
开发者ID:nmicha,项目名称:moodle,代码行数:65,代码来源:lib.php
示例11: qtype_ddmarker_course_context_id
function qtype_ddmarker_course_context_id($catcontextid)
{
$context = get_context_instance_by_id($catcontextid);
while ($context->contextlevel != CONTEXT_COURSE) {
$context = get_context_instance_by_id(get_parent_contextid($context));
}
return $context->id;
}
开发者ID:ndunand,项目名称:moodle-qtype_ddmarker,代码行数:8,代码来源:lib.php
示例12: question_edit_form
function question_edit_form($submiturl, $question, $category, $contexts, $formeditable = true)
{
$this->question = $question;
$this->contexts = $contexts;
$this->category = $category;
$this->categorycontext = get_context_instance_by_id($category->contextid);
//course id or site id depending on question cat context
$this->coursefilesid = get_filesdir_from_context(get_context_instance_by_id($category->contextid));
parent::moodleform($submiturl, null, 'post', '', null, $formeditable);
}
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:10,代码来源:edit_question_form.php
示例13: __construct
/**
* Add question-type specific form fields.
*
* @param MoodleQuickForm $mform the form being built.
*/
public function __construct($submiturl, $question) {
global $DB;
$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 = get_context_instance_by_id($category->contextid);
parent::__construct($submiturl);
}
开发者ID:nigeldaley,项目名称:moodle,代码行数:18,代码来源:datasetdefinitions_form.php
示例14: __construct
public function __construct($submiturl, $question, $category, $contexts, $formeditable = true)
{
global $DB;
$this->question = $question;
$this->contexts = $contexts;
$record = $DB->get_record('question_categories', array('id' => $question->category), 'contextid');
$this->context = get_context_instance_by_id($record->contextid);
$this->editoroptions = array('subdirs' => 1, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'context' => $this->context);
$this->fileoptions = array('subdirs' => 1, 'maxfiles' => -1, 'maxbytes' => -1);
$this->category = $category;
$this->categorycontext = get_context_instance_by_id($category->contextid);
parent::__construct($submiturl, null, 'post', '', null, $formeditable);
}
开发者ID:sebastiansanio,项目名称:tallerdeprogramacion2fiuba,代码行数:13,代码来源:edit_question_form.php
示例15: question_dataset_dependent_definitions_form
/**
* Add question-type specific form fields.
*
* @param MoodleQuickForm $mform the form being built.
*/
function question_dataset_dependent_definitions_form($submiturl, $question)
{
global $QTYPES;
$this->question = $question;
$this->qtypeobj =& $QTYPES[$this->question->qtype];
// Validate the question category.
if (!($category = get_record('question_categories', 'id', $question->category))) {
print_error('categorydoesnotexist', 'question', $returnurl);
}
$this->category = $category;
$this->categorycontext = get_context_instance_by_id($category->contextid);
parent::moodleform($submiturl);
}
开发者ID:JackCanada,项目名称:moodle-hacks,代码行数:18,代码来源:datasetdefinitions_form.php
示例16: get_owning_quiz
/**
* If this block belongs to a quiz context, then return that quiz's id.
* Otherwise, return 0.
* @return integer the quiz id.
*/
public function get_owning_quiz()
{
if (empty($this->instance->parentcontextid)) {
return 0;
}
$parentcontext = get_context_instance_by_id($this->instance->parentcontextid);
if ($parentcontext->contextlevel != CONTEXT_MODULE) {
return 0;
}
$cm = get_coursemodule_from_id('quiz', $parentcontext->instanceid);
if (!$cm) {
return 0;
}
return $cm->instance;
}
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:20,代码来源:block_quiz_results.php
示例17: 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
* @todo MDL-36050 improve capability check on stick blocks, so we can check user capability before sending images.
*/
function block_html_pluginfile($course, $birecord_or_cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
global $DB, $CFG;
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);
}
}
// At this point there is no way to check SYSTEM or USER context, so ignoring it.
}
}
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 = get_context_instance_by_id($birecord_or_cm->parentcontextid)) {
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);
}
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:64,代码来源:lib.php
示例18: _setup_plugin
private function _setup_plugin($comment)
{
global $DB;
$this->context = get_context_instance_by_id($comment->contextid);
if ($this->context->contextlevel == CONTEXT_BLOCK) {
if ($block = $DB->get_record('block_instances', array('id' => $this->context->instanceid))) {
$this->plugintype = 'block';
$this->pluginname = $block->blockname;
}
}
if ($this->context->contextlevel == CONTEXT_MODULE) {
$this->plugintype = 'mod';
$this->cm = get_coursemodule_from_id('', $this->context->instanceid);
$this->_setup_course($this->cm->course);
$this->modinfo = get_fast_modinfo($this->course);
$this->pluginname = $this->modinfo->cms[$this->cm->id]->modname;
}
}
开发者ID:ajv,项目名称:Offline-Caching,代码行数:18,代码来源:lib.php
示例19: module_specific_controls
/**
* Callback function called from question_list() function (which is called from showbank())
*/
function module_specific_controls($totalnumber, $recurse, $category, $cmid)
{
$catcontext = get_context_instance_by_id($category->contextid);
if (has_capability('moodle/question:useall', $catcontext)) {
for ($i = 1; $i <= min(10, $totalnumber); $i++) {
$randomcount[$i] = $i;
}
for ($i = 20; $i <= min(100, $totalnumber); $i += 10) {
$randomcount[$i] = $i;
}
$out = '<br />';
$out .= get_string('addrandom', 'quiz', choose_from_menu($randomcount, 'randomcount', '1', '', '', '', true));
$out .= '<input type="hidden" name="recurse" value="' . $recurse . '" />';
$out .= "<input type=\"hidden\" name=\"categoryid\" value=\"{$category->id}\" />";
$out .= ' <input type="submit" name="addrandom" value="' . get_string('add') . '" />';
$out .= helpbutton('random', get_string('random', 'quiz'), 'quiz', true, false, '', true);
} else {
$out = '';
}
return $out;
}
开发者ID:r007,项目名称:PMoodle,代码行数:24,代码来源:edit.php
示例20: module_specific_controls
/**
* Callback function called from question_list() function
* (which is called from showbank())
*/
function module_specific_controls($totalnumber, $recurse, $category, $cmid, $cmoptions) {
global $OUTPUT;
$out = '';
$catcontext = get_context_instance_by_id($category->contextid);
if (has_capability('moodle/question:useall', $catcontext)) {
if ($cmoptions->hasattempts) {
$disabled = ' disabled="disabled"';
} else {
$disabled = '';
}
$randomusablequestions =
question_bank::get_qtype('random')->get_available_questions_from_category(
$category->id, $recurse);
$maxrand = count($randomusablequestions);
if ($maxrand > 0) {
for ($i = 1; $i <= min(10, $maxrand); $i++) {
$randomcount[$i] = $i;
}
for ($i = 20; $i <= min(100, $maxrand); $i += 10) {
$randomcount[$i] = $i;
}
} else {
$randomcount[0] = 0;
$disabled = ' disabled="disabled"';
}
$out = '<strong><label for="menurandomcount">'.get_string('addrandomfromcategory', 'quiz').
'</label></strong><br />';
$attributes = array();
$attributes['disabled'] = $disabled ? 'disabled' : null;
$select = html_writer::select($randomcount, 'randomcount', '1', null, $attributes);
$out .= get_string('addrandom', 'quiz', $select);
$out .= '<input type="hidden" name="recurse" value="'.$recurse.'" />';
$out .= '<input type="hidden" name="categoryid" value="' . $category->id . '" />';
$out .= ' <input type="submit" name="addrandom" value="'.
get_string('addtoquiz', 'quiz').'"' . $disabled . ' />';
$out .= $OUTPUT->help_icon('addarandomquestion', 'quiz');
}
return $out;
}
开发者ID:nigeli,项目名称:moodle,代码行数:44,代码来源:edit.php
注:本文中的get_context_instance_by_id函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论