本文整理汇总了PHP中repository::get_type_by_id方法的典型用法代码示例。如果您正苦于以下问题:PHP repository::get_type_by_id方法的具体用法?PHP repository::get_type_by_id怎么用?PHP repository::get_type_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类repository
的用法示例。
在下文中一共展示了repository::get_type_by_id方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: is_visible
/**
* Return is the instance is visible
* (is the type visible ? is the context enable ?)
*
* @return bool
*/
public function is_visible()
{
$type = repository::get_type_by_id($this->options['typeid']);
$instanceoptions = repository::static_function($type->get_typename(), 'get_instance_option_names');
if ($type->get_visible()) {
//if the instance is unique so it's visible, otherwise check if the instance has a enabled context
if (empty($instanceoptions) || $type->get_contextvisibility(context::instance_by_id($this->instance->contextid))) {
return true;
}
}
return false;
}
示例2: admin_externalpage_setup
}
}
admin_externalpage_setup($pagename, '', null, new moodle_url('/admin/repositoryinstances.php'));
require_capability('moodle/site:config', $context);
$baseurl = new moodle_url("/{$CFG->admin}/repositoryinstance.php", array('sesskey' => sesskey()));
$parenturl = new moodle_url("/{$CFG->admin}/repository.php", array('sesskey' => sesskey(), 'action' => 'edit'));
if ($new) {
$parenturl->param('repos', $new);
} else {
$parenturl->param('repos', $type);
}
$return = true;
if (!empty($edit) || !empty($new)) {
if (!empty($edit)) {
$instance = repository::get_instance($edit);
$instancetype = repository::get_type_by_id($instance->options['typeid']);
$classname = 'repository_' . $instancetype->get_typename();
$configs = $instance->get_instance_option_names();
$plugin = $instancetype->get_typename();
$typeid = $instance->options['typeid'];
} else {
$plugin = $new;
$typeid = null;
$instance = null;
}
// display the edit form for this instance
$mform = new repository_instance_form('', array('plugin' => $plugin, 'typeid' => $typeid, 'instance' => $instance, 'contextid' => $context->id));
// end setup, begin output
if ($mform->is_cancelled()) {
redirect($parenturl);
exit;
示例3: print_error
if (!($course = $DB->get_record('course', array('id' => $usercourseid)))) {
print_error('invalidcourseid');
}
$currenttab = 'repositories';
include $CFG->dirroot . '/user/tabs.php';
}
print_heading($pagename);
$return = true;
if (!empty($edit) || !empty($new)) {
if (!empty($edit)) {
$instance = repository::get_instance($edit);
//if you try to edit an instance set as readonly, display an error message
if ($instance->readonly) {
throw new repository_exception('readonlyinstance', 'repository');
}
$instancetype = repository::get_type_by_id($instance->typeid);
$classname = 'repository_' . $instancetype->get_typename();
$configs = $instance->get_instance_option_names();
$plugin = $instancetype->get_typename();
$typeid = $instance->typeid;
} else {
$plugin = $new;
$typeid = $new;
$instance = null;
}
/// Create edit form for this instance
$mform = new repository_instance_form('', array('plugin' => $plugin, 'typeid' => $typeid, 'instance' => $instance, 'contextid' => $contextid));
/// Process the form data if any, or display
if ($mform->is_cancelled()) {
redirect($baseurl);
exit;
示例4: get_real_path
/**
* get_real_path
*
* @param object $file
* @param object $hotpot (optional, default=null)
* @return string
*/
public static function get_real_path($file, $hotpot = null)
{
global $CFG, $PAGE;
// sanity check
if (empty($file)) {
return '';
}
// set default path (= cached file in filedir)
$hash = $file->get_contenthash();
$path = $CFG->dataroot . '/filedir/' . $hash[0] . $hash[1] . '/' . $hash[2] . $hash[3] . '/' . $hash;
if (!method_exists($file, 'get_repository_id')) {
return $path;
// Moodle <= 2.2
}
if (!($repositoryid = $file->get_repository_id())) {
return $path;
// shoudn't happen !!
}
if (!($repository = repository::get_repository_by_id($repositoryid, $PAGE->context))) {
return $path;
// shouldn't happen
}
// get repository $type
switch (true) {
case isset($repository->options['type']):
$type = $repository->options['type'];
break;
case isset($repository->instance->typeid):
$type = repository::get_type_by_id($repository->instance->typeid);
$type = $type->get_typename();
break;
default:
$type = '';
// shouldn't happen !!
}
// get path according to repository $type
switch ($type) {
case 'filesystem':
if (method_exists($repository, 'get_rootpath')) {
$path = $repository->get_rootpath() . '/' . $file->get_reference();
} else {
if (isset($repository->root_path)) {
$path = $repository->root_path . '/' . $file->get_reference();
}
}
break;
case 'user':
case 'coursefiles':
// use the the default $path
break;
}
return $path;
}
示例5: hotpot_pluginfile_externalfile
/**
* Gets main file in a file area
*
* if the main file is a link from an external repository
* look for the target file in the main file's repository
* Note: this functionality only exists in Moodle 2.3+
*
* @param stdclass $context
* @param string $component 'mod_hotpot'
* @param string $filearea 'sourcefile', 'entrytext' or 'exittext'
* @param string $filepath despite the name, this is a dir path with leading and trailing "/"
* @param string $filename
* @param array $file_record
* @return stdclass if external file found, false otherwise
*/
function hotpot_pluginfile_externalfile($context, $component, $filearea, $filepath, $filename, $file_record)
{
// get file storage
$fs = get_file_storage();
// get main file for this $component/$filearea
// typically this will be the HotPot quiz file
$mainfile = hotpot_pluginfile_mainfile($context, $component, $filearea);
// get repository - cautiously :-)
if (!$mainfile) {
return false;
// no main file - shouldn't happen !!
}
if (!method_exists($mainfile, 'get_repository_id')) {
return false;
// no file linking in Moodle 2.0 - 2.2
}
if (!($repositoryid = $mainfile->get_repository_id())) {
return false;
// $mainfile is not from an external repository
}
if (!($repository = repository::get_repository_by_id($repositoryid, $context))) {
return false;
// $repository is not accessible in this context - shouldn't happen !!
}
// get repository type
switch (true) {
case isset($repository->options['type']):
$type = $repository->options['type'];
break;
case isset($repository->instance->typeid):
$type = repository::get_type_by_id($repository->instance->typeid);
$type = $type->get_typename();
break;
default:
$type = '';
// shouldn't happen !!
}
// set paths (within repository) to required file
// how we do this depends on the repository $typename
// "filesystem" path is in plain text, others are encoded
$mainreference = $mainfile->get_reference();
switch ($type) {
case 'filesystem':
$maindirname = dirname($mainreference);
$encodepath = false;
break;
case 'user':
case 'coursefiles':
$params = file_storage::unpack_reference($mainreference, true);
$maindirname = $params['filepath'];
$encodepath = true;
break;
default:
echo 'unknown repository type in hotpot_pluginfile_externalfile(): ' . $type;
die;
}
// remove leading and trailing "/" from dir names
$maindirname = trim($maindirname, '/');
$dirname = trim($filepath, '/');
// assume path to target dir is same as path to main dir
$path = explode('/', $maindirname);
// traverse back up folder hierarchy if necessary
$count = count(explode('/', $dirname));
array_splice($path, -$count);
// reconstruct expected dir path for source file
if ($dirname) {
$path[] = $dirname;
}
$source = $path;
$source[] = $filename;
$source = implode('/', $source);
$path = implode('/', $path);
// filepaths in the repository to search for the file
$paths = array();
// add to the list of possible paths
$paths[$path] = $source;
if ($dirname) {
$paths[$dirname] = $dirname . '/' . $filename;
}
if ($maindirname) {
$paths[$maindirname] = $maindirname . '/' . $filename;
}
if ($maindirname && $dirname) {
$paths[$maindirname . '/' . $dirname] = $maindirname . '/' . $dirname . '/' . $filename;
$paths[$dirname . '/' . $maindirname] = $dirname . '/' . $maindirname . '/' . $filename;
//.........这里部分代码省略.........
示例6: xmldb_hotpot_locate_externalfile
function xmldb_hotpot_locate_externalfile($contextid, $component, $filearea, $itemid, $filepath, $filename)
{
global $CFG, $DB;
if (!class_exists('repository')) {
return false;
// Moodle <= 2.2 has no repositories
}
static $repositories = null;
if ($repositories === null) {
$exclude_types = array('recent', 'upload', 'user', 'areafiles');
$repositories = repository::get_instances();
foreach (array_keys($repositories) as $id) {
if (method_exists($repositories[$id], 'get_typename')) {
$type = $repositories[$id]->get_typename();
} else {
$type = $repositories[$id]->options['type'];
}
if (in_array($type, $exclude_types)) {
unset($repositories[$id]);
}
}
// ensure upgraderunning is set
if (empty($CFG->upgraderunning)) {
$CFG->upgraderunning = null;
}
}
// get file storage
$fs = get_file_storage();
// the following types repository use encoded params
$encoded_types = array('user', 'areafiles', 'coursefiles');
foreach ($repositories as $id => $repository) {
// "filesystem" path is in plain text, others are encoded
if (method_exists($repositories[$id], 'get_typename')) {
$type = $repositories[$id]->get_typename();
} else {
$type = $repositories[$id]->options['type'];
}
$encodepath = in_array($type, $encoded_types);
// save $root_path, because it may get messed up by
// $repository->get_listing($path), if $path is non-existant
if (method_exists($repository, 'get_rootpath')) {
$root_path = $repository->get_rootpath();
} else {
if (isset($repository->root_path)) {
$root_path = $repository->root_path;
} else {
$root_path = false;
}
}
// get repository type
switch (true) {
case isset($repository->options['type']):
$type = $repository->options['type'];
break;
case isset($repository->instance->typeid):
$type = repository::get_type_by_id($repository->instance->typeid);
$type = $type->get_typename();
break;
default:
$type = '';
// shouldn't happen !!
}
$path = $filepath;
$source = trim($filepath . $filename, '/');
// setup $params for path encoding, if necessary
$params = array();
if ($encodepath) {
$listing = $repository->get_listing();
switch (true) {
case isset($listing['list'][0]['source']):
$param = 'source';
break;
// file
// file
case isset($listing['list'][0]['path']):
$param = 'path';
break;
// dir
// dir
default:
return false;
// shouldn't happen !!
}
$params = file_storage::unpack_reference($listing['list'][0][$param], true);
$params['filepath'] = '/' . $path . ($path == '' ? '' : '/');
$params['filename'] = '.';
// "." signifies a directory
$path = file_storage::pack_reference($params);
}
// reset $repository->root_path (filesystem repository only)
if ($root_path) {
$repository->root_path = $root_path;
}
// unset upgraderunning because it can cause get_listing() to fail
$upgraderunning = $CFG->upgraderunning;
$CFG->upgraderunning = null;
// Note: we use "@" to suppress warnings in case $path does not exist
$listing = @$repository->get_listing($path);
// restore upgraderunning flag
$CFG->upgraderunning = $upgraderunning;
//.........这里部分代码省略.........