本文整理汇总了PHP中get_context_info_array函数的典型用法代码示例。如果您正苦于以下问题:PHP get_context_info_array函数的具体用法?PHP get_context_info_array怎么用?PHP get_context_info_array使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_context_info_array函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_content
function get_content()
{
global $CFG, $PAGE;
if (!$CFG->usecomments) {
$this->content->text = '';
if ($this->page->user_is_editing()) {
$this->content->text = get_string('disabledcomments');
}
return $this->content;
}
if ($this->content !== NULL) {
return $this->content;
}
if (empty($this->instance)) {
return null;
}
$this->content->footer = '';
$this->content->text = '';
list($context, $course, $cm) = get_context_info_array($PAGE->context->id);
$args = new stdClass();
$args->context = $PAGE->context;
$args->course = $course;
$args->area = 'page_comments';
$args->itemid = 0;
// set 'env' to tell moodle tweak ui for this block
$args->env = 'block_comments';
$args->component = 'block_comments';
$args->linktext = get_string('showcomments');
$comment = new comment($args);
$comment->set_view_permission(true);
$this->content = new stdClass();
$this->content->text = $comment->output(true);
$this->content->footer = '';
return $this->content;
}
示例2: ga_trackurl
/**
* Local Redirect
*
* This local plugin that adds a 'friendly url' version of Google analytics
* to Moodle
*
* @package local
* @subpackage local_googleanalytics
* @copyright 2013 Bas Brands, www.basbrands.nl
* @author Bas Brands and Gavin Henrick.
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
function ga_trackurl() {
global $CFG, $DB, $PAGE, $COURSE, $OUTPUT;
$pageinfo = get_context_info_array($PAGE->context->id);
$trackurl = array();
if ($COURSE->id == 1) {
return '';
}
// Adds course category name.
if (isset($pageinfo[1]->category)) {
if ($category = $DB->get_record('course_categories', array('id'=>$pageinfo[1]->category))) {
$trackurl[] = urlencode($category->name);
}
}
// Adds course full name.
if (isset($pageinfo[1]->fullname)) {
$trackurl[] = urlencode($pageinfo[1]->fullname);
}
// Adds activity name.
if (isset($pageinfo[2]->name)) {
$trackurl[] = urlencode($pageinfo[2]->name);
}
return implode('/', $trackurl);
}
示例3: analytics_trackurl
/**
* Analytics
*
* This module provides extensive analytics on a platform of choice
* Currently support Google Analytics and Piwik
*
* @package local_analytics
* @copyright David Bezemer <info@davidbezemer.nl>, www.davidbezemer.nl
* @author David Bezemer <info@davidbezemer.nl>, Bas Brands <bmbrands@gmail.com>, Gavin Henrick <gavin@lts.ie>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
function analytics_trackurl()
{
global $DB, $PAGE;
$pageinfo = get_context_info_array($PAGE->context->id);
$trackurl = "'/";
// Adds course category name.
if (isset($pageinfo[1]->category)) {
if ($category = $DB->get_record('course_categories', array('id' => $pageinfo[1]->category))) {
$cats = explode("/", $category->path);
foreach (array_filter($cats) as $cat) {
if ($categorydepth = $DB->get_record("course_categories", array("id" => $cat))) {
$trackurl .= urlencode($categorydepth->name) . '/';
}
}
}
}
// Adds course full name.
if (isset($pageinfo[1]->fullname)) {
if (isset($pageinfo[2]->name)) {
$trackurl .= urlencode($pageinfo[1]->fullname) . '/';
} else {
if ($PAGE->user_is_editing()) {
$trackurl .= urlencode($pageinfo[1]->fullname) . '/' . get_string('edit');
} else {
$trackurl .= urlencode($pageinfo[1]->fullname) . '/' . get_string('view');
}
}
}
// Adds activity name.
if (isset($pageinfo[2]->name)) {
$trackurl .= urlencode($pageinfo[2]->modname) . '/' . urlencode($pageinfo[2]->name);
}
$trackurl .= "'";
return $trackurl;
}
示例4: 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;
}
示例5: question_pluginfile_joomdle
function question_pluginfile_joomdle($course, $context, $component, $filearea, $args, $forcedownload)
{
global $DB, $CFG;
list($context, $course, $cm) = get_context_info_array($context->id);
$qubaid = (int) array_shift($args);
$filename = array_shift($args);
$module = $DB->get_field('question_usages', 'component', array('id' => $qubaid));
return question_preview_question_pluginfile_joomdle($course, $context, $component, $filearea, $qubaid, $slot, $filename, $forcedownload);
}
示例6: qformat_xhtml_questiontext_preview_pluginfile
/**
* Serve question files when they are displayed in this export format.
*
* @param context $previewcontext the quiz context
* @param int $questionid the question id.
* @param context $filecontext the file (question) context
* @param string $filecomponent the component the file belongs to.
* @param string $filearea the file area.
* @param array $args remaining file args.
* @param bool $forcedownload.
* @param array $options additional options affecting the file serving.
*/
function qformat_xhtml_questiontext_preview_pluginfile($context, $questionid,
$args, $forcedownload, array $options = array()) {
global $CFG;
list($context, $course, $cm) = get_context_info_array($context->id);
require_login($course, false, $cm);
question_require_capability_on($questionid, 'view');
question_send_questiontext_file($questionid, $args, $forcedownload, $options);
}
示例7: offlinequiz_statistics_questiontext_preview_pluginfile
/**
* Serve questiontext files in the question text when they are displayed in this report.
*
* @package mod_offlinequiz
* @category files
* @param stdClass $context the context
* @param int $questionid the question id
* @param array $args remaining file args
* @param bool $forcedownload
* @param array $options additional options affecting the file serving
*/
function offlinequiz_statistics_questiontext_preview_pluginfile($context, $questionid, $args, $forcedownload, array $options = array())
{
global $CFG;
require_once $CFG->dirroot . '/mod/offlinequiz/locallib.php';
list($context, $course, $cm) = get_context_info_array($context->id);
require_login($course, false, $cm);
// Assume only trusted people can see this report. There is no real way to
// validate questionid, becuase of the complexity of random quetsions.
require_capability('offlinequiz/statistics:view', $context);
question_send_questiontext_file($questionid, $args, $forcedownload, $options);
}
示例8: qformat_xhtml_question_preview_pluginfile
/**
* Serve question files when they are displayed in this export format.
*
* @param context $previewcontext the quiz context
* @param int $questionid the question id.
* @param context $filecontext the file (question) context
* @param string $filecomponent the component the file belongs to.
* @param string $filearea the file area.
* @param array $args remaining file args.
* @param bool $forcedownload.
* @param array $options additional options affecting the file serving.
*/
function qformat_xhtml_question_preview_pluginfile($previewcontext, $questionid, $filecontext, $filecomponent, $filearea, $args, $forcedownload, $options = array())
{
global $CFG;
list($context, $course, $cm) = get_context_info_array($previewcontext->id);
require_login($course, false, $cm);
question_require_capability_on($questionid, 'view');
$fs = get_file_storage();
$relativepath = implode('/', $args);
$fullpath = "/{$filecontext->id}/{$filecomponent}/{$filearea}/{$relativepath}";
if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
send_file_not_found();
}
send_stored_file($file, 0, 0, $forcedownload, $options);
}
示例9: quiz_statistics_question_preview_pluginfile
/**
* Serve questiontext files in the question text when they are displayed in this report.
*
* @package quiz_statistics
* @category files
* @param context $previewcontext the quiz context
* @param int $questionid the question id.
* @param context $filecontext the file (question) context
* @param string $filecomponent the component the file belongs to.
* @param string $filearea the file area.
* @param array $args remaining file args.
* @param bool $forcedownload.
* @param array $options additional options affecting the file serving.
*/
function quiz_statistics_question_preview_pluginfile($previewcontext, $questionid, $filecontext, $filecomponent, $filearea, $args, $forcedownload, $options = array())
{
global $CFG;
require_once $CFG->dirroot . '/mod/quiz/locallib.php';
list($context, $course, $cm) = get_context_info_array($previewcontext->id);
require_login($course, false, $cm);
// Assume only trusted people can see this report. There is no real way to
// validate questionid, becuase of the complexity of random quetsions.
require_capability('quiz/statistics:view', $context);
$fs = get_file_storage();
$relativepath = implode('/', $args);
$fullpath = "/{$filecontext->id}/{$filecomponent}/{$filearea}/{$relativepath}";
if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
send_file_not_found();
}
send_stored_file($file, 0, 0, $forcedownload, $options);
}
示例10: __construct
public function __construct($context, $itemid, $filearea = 'submission')
{
global $USER, $CFG;
require_once $CFG->libdir . '/portfoliolib.php';
$this->context = $context;
list($context, $course, $cm) = get_context_info_array($context->id);
$this->cm = $cm;
$this->course = $course;
$fs = get_file_storage();
$this->dir = $fs->get_area_tree($this->context->id, 'mod_assignment', $filearea, $itemid);
$files = $fs->get_area_files($this->context->id, 'mod_assignment', $filearea, $itemid, "timemodified", false);
if (count($files) >= 1 && has_capability('mod/assignment:exportownsubmission', $this->context)) {
$button = new portfolio_add_button();
$button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id), '/mod/assignment/locallib.php');
$button->reset_formats();
$this->portfolioform = $button->to_html();
}
$this->preprocess($this->dir, $filearea);
}
示例11: get_content
function get_content()
{
global $CFG, $PAGE;
if ($this->content !== NULL) {
return $this->content;
}
if (!$CFG->usecomments) {
$this->content = new stdClass();
$this->content->text = '';
if ($this->page->user_is_editing()) {
$this->content->text = get_string('disabledcomments');
}
return $this->content;
}
$this->content = new stdClass();
$this->content->footer = '';
$this->content->text = '';
if (empty($this->instance)) {
return $this->content;
}
list($context, $course, $cm) = get_context_info_array($PAGE->context->id);
$args = new stdClass();
$args->context = $PAGE->context;
$args->course = $course;
$args->area = 'page_comments';
$args->itemid = 0;
$args->component = 'block_comments';
$args->linktext = get_string('showcomments');
$args->notoggle = true;
$args->autostart = true;
$args->displaycancel = false;
$comment = new comment($args);
$comment->set_view_permission(true);
$comment->set_fullwidth();
$this->content = new stdClass();
$this->content->text = $comment->output(true);
$this->content->footer = '';
return $this->content;
}
示例12: get_grading_manager
// get manager by id
$manager = get_grading_manager($areaid);
} else {
// get manager by context and component
if (is_null($contextid) or is_null($component) or is_null($area)) {
throw new coding_exception('The caller script must identify the gradable area.');
}
$context = context::instance_by_id($contextid, MUST_EXIST);
$manager = get_grading_manager($context, $component, $area);
}
if ($manager->get_context()->contextlevel < CONTEXT_COURSE) {
throw new coding_exception('Unsupported gradable area context level');
}
// get the currently active method
$method = $manager->get_active_method();
list($context, $course, $cm) = get_context_info_array($manager->get_context()->id);
require_login($course, true, $cm);
require_capability('moodle/grade:managegradingforms', $context);
if (!empty($returnurl)) {
$returnurl = new moodle_url($returnurl);
} else {
$returnurl = null;
}
$PAGE->set_url($manager->get_management_url($returnurl));
navigation_node::override_active_url($manager->get_management_url());
$PAGE->set_title(get_string('gradingmanagement', 'core_grading'));
$PAGE->set_heading(get_string('gradingmanagement', 'core_grading'));
$output = $PAGE->get_renderer('core_grading');
// process the eventual change of the active grading method
if (!empty($setmethod)) {
require_sesskey();
示例13: initialise_filepicker
/**
* Generate all options needed by filepicker
*
* @param array $args including following keys
* context
* accepted_types
* return_types
*
* @return array the list of repository instances, including meta infomation, containing the following keys
* externallink
* repositories
* accepted_types
*/
function initialise_filepicker($args)
{
global $CFG, $USER, $PAGE, $OUTPUT;
static $templatesinitialized = array();
require_once $CFG->libdir . '/licenselib.php';
$return = new stdClass();
$licenses = array();
if (!empty($CFG->licenses)) {
$array = explode(',', $CFG->licenses);
foreach ($array as $license) {
$l = new stdClass();
$l->shortname = $license;
$l->fullname = get_string($license, 'license');
$licenses[] = $l;
}
}
if (!empty($CFG->sitedefaultlicense)) {
$return->defaultlicense = $CFG->sitedefaultlicense;
}
$return->licenses = $licenses;
$return->author = fullname($USER);
if (empty($args->context)) {
$context = $PAGE->context;
} else {
$context = $args->context;
}
$disable_types = array();
if (!empty($args->disable_types)) {
$disable_types = $args->disable_types;
}
$user_context = context_user::instance($USER->id);
list($context, $course, $cm) = get_context_info_array($context->id);
$contexts = array($user_context, context_system::instance());
if (!empty($course)) {
// adding course context
$contexts[] = context_course::instance($course->id);
}
$externallink = (int) get_config(null, 'repositoryallowexternallinks');
$repositories = repository::get_instances(array('context' => $contexts, 'currentcontext' => $context, 'accepted_types' => $args->accepted_types, 'return_types' => $args->return_types, 'disable_types' => $disable_types));
$return->repositories = array();
if (empty($externallink)) {
$return->externallink = false;
} else {
$return->externallink = true;
}
$return->userprefs = array();
$return->userprefs['recentrepository'] = get_user_preferences('filepicker_recentrepository', '');
$return->userprefs['recentlicense'] = get_user_preferences('filepicker_recentlicense', '');
$return->userprefs['recentviewmode'] = get_user_preferences('filepicker_recentviewmode', '');
user_preference_allow_ajax_update('filepicker_recentrepository', PARAM_INT);
user_preference_allow_ajax_update('filepicker_recentlicense', PARAM_SAFEDIR);
user_preference_allow_ajax_update('filepicker_recentviewmode', PARAM_INT);
// provided by form element
$return->accepted_types = file_get_typegroup('extension', $args->accepted_types);
$return->return_types = $args->return_types;
$templates = array();
foreach ($repositories as $repository) {
$meta = $repository->get_meta();
// Please note that the array keys for repositories are used within
// JavaScript a lot, the key NEEDS to be the repository id.
$return->repositories[$repository->id] = $meta;
// Register custom repository template if it has one
if (method_exists($repository, 'get_upload_template') && !array_key_exists('uploadform_' . $meta->type, $templatesinitialized)) {
$templates['uploadform_' . $meta->type] = $repository->get_upload_template();
$templatesinitialized['uploadform_' . $meta->type] = true;
}
}
if (!array_key_exists('core', $templatesinitialized)) {
// we need to send each filepicker template to the browser just once
$fprenderer = $PAGE->get_renderer('core', 'files');
$templates = array_merge($templates, $fprenderer->filepicker_js_templates());
$templatesinitialized['core'] = true;
}
if (sizeof($templates)) {
$PAGE->requires->js_init_call('M.core_filepicker.set_templates', array($templates), true);
}
return $return;
}
示例14: course_page_type_list
/**
* Return a list of page types
* @param string $pagetype current page type
* @param stdClass $parentcontext Block's parent context
* @param stdClass $currentcontext Current context of block
*/
function course_page_type_list($pagetype, $parentcontext, $currentcontext)
{
// if above course context ,display all course fomats
list($currentcontext, $course, $cm) = get_context_info_array($currentcontext->id);
if ($course->id == SITEID) {
return array('*' => get_string('page-x', 'pagetype'));
} else {
return array('*' => get_string('page-x', 'pagetype'), 'course-*' => get_string('page-course-x', 'pagetype'), 'course-view-*' => get_string('page-course-view-x', 'pagetype'));
}
}
示例15: data_print_template
//.........这里部分代码省略.........
$moreurl .= '&filter=1';
}
$patterns[]='##more##';
$replacement[] = '<a href="' . $moreurl . '"><img src="' . $OUTPUT->pix_url('i/search') . '" class="iconsmall" alt="' . get_string('more', 'data') . '" title="' . get_string('more', 'data') . '" /></a>';
$patterns[]='##moreurl##';
$replacement[] = $moreurl;
$patterns[]='##user##';
$replacement[] = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$record->userid.
'&course='.$data->course.'">'.fullname($record).'</a>';
$patterns[]='##export##';
if (!empty($CFG->enableportfolios) && ($template == 'singletemplate' || $template == 'listtemplate')
&& ((has_capability('mod/data:exportentry', $context)
|| (data_isowner($record->id) && has_capability('mod/data:exportownentry', $context))))) {
require_once($CFG->libdir . '/portfoliolib.php');
$button = new portfolio_add_button();
$button->set_callback_options('data_portfolio_caller', array('id' => $cm->id, 'recordid' => $record->id), '/mod/data/locallib.php');
list($formats, $files) = data_portfolio_caller::formats($fields, $record);
$button->set_formats($formats);
$replacement[] = $button->to_html(PORTFOLIO_ADD_ICON_LINK);
} else {
$replacement[] = '';
}
$patterns[] = '##timeadded##';
$replacement[] = userdate($record->timecreated);
$patterns[] = '##timemodified##';
$replacement [] = userdate($record->timemodified);
$patterns[]='##approve##';
if (has_capability('mod/data:approve', $context) && ($data->approval) && (!$record->approved)){
$replacement[] = '<span class="approve"><a href="'.$CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&approve='.$record->id.'&sesskey='.sesskey().'"><img src="'.$OUTPUT->pix_url('i/approve') . '" class="icon" alt="'.get_string('approve').'" /></a></span>';
} else {
$replacement[] = '';
}
$patterns[]='##comments##';
if (($template == 'listtemplate') && ($data->comments)) {
if (!empty($CFG->usecomments)) {
require_once($CFG->dirroot . '/comment/lib.php');
list($context, $course, $cm) = get_context_info_array($context->id);
$cmt = new stdClass();
$cmt->context = $context;
$cmt->course = $course;
$cmt->cm = $cm;
$cmt->area = 'database_entry';
$cmt->itemid = $record->id;
$cmt->showcount = true;
$cmt->component = 'mod_data';
$comment = new comment($cmt);
$replacement[] = $comment->output(true);
}
} else {
$replacement[] = '';
}
// actual replacement of the tags
$newtext = str_ireplace($patterns, $replacement, $data->{$template});
// no more html formatting and filtering - see MDL-6635
if ($return) {
return $newtext;
} else {
echo $newtext;
// hack alert - return is always false in singletemplate anyway ;-)
/**********************************
* Printing Ratings Form *
*********************************/
if ($template == 'singletemplate') { //prints ratings options
data_print_ratings($data, $record);
}
/**********************************
* Printing Comments Form *
*********************************/
if (($template == 'singletemplate') && ($data->comments)) {
if (!empty($CFG->usecomments)) {
require_once($CFG->dirroot . '/comment/lib.php');
list($context, $course, $cm) = get_context_info_array($context->id);
$cmt = new stdClass();
$cmt->context = $context;
$cmt->course = $course;
$cmt->cm = $cm;
$cmt->area = 'database_entry';
$cmt->itemid = $record->id;
$cmt->showcount = true;
$cmt->component = 'mod_data';
$comment = new comment($cmt);
$comment->output(false);
}
}
}
}
}