本文整理汇总了PHP中repository::get_moodle_file方法的典型用法代码示例。如果您正苦于以下问题:PHP repository::get_moodle_file方法的具体用法?PHP repository::get_moodle_file怎么用?PHP repository::get_moodle_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类repository
的用法示例。
在下文中一共展示了repository::get_moodle_file方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: file_exception
$record->contextid = $usercontext->id;
$record->timecreated = $now;
$record->timemodified = $now;
$record->userid = $USER->id;
$record->sortorder = 0;
// Check that user has permission to access this file
if (!$repo->file_is_accessible($source)) {
throw new file_exception('storedfilecannotread');
}
// If file is already a reference, set $source = file source, $repo = file repository
// note that in this case user may not have permission to access the source file directly
// so no file_browser/file_info can be used below
if ($repo->has_moodle_files()) {
$file = repository::get_moodle_file($source);
if ($file && $file->is_external_file()) {
$source = $file->get_reference();
$repo_id = $file->get_repository_id();
$repo = repository::get_repository_by_id($repo_id, $contextid, $repooptions);
}
}
// {@link repository::build_source_field()}
$sourcefield = $repo->get_file_source_info($source);
$record->source = $repo::build_source_field($sourcefield);
if ($usefilereference) {
$reference = $repo->get_file_reference($source);
// get reference life time from repo
$record->referencelifetime = $repo->get_reference_file_lifetime($reference);
示例2: array
if ($repo->has_moodle_files()) {
$file = repository::get_moodle_file($source);
if ($file && $file->is_external_file()) {
$sourcefield = $file->get_source();
// remember the original source
$record->source = $repo::build_source_field($sourcefield);
$record->contenthash = $file->get_contenthash();
$record->filesize = $file->get_filesize();
$reference = $file->get_reference();
$repo_id = $file->get_repository_id();
$repo = repository::get_repository_by_id($repo_id, $contextid, $repooptions);
}
}
if ($usefilereference) {
if ($repo->has_moodle_files()) {
$sourcefile = repository::get_moodle_file($reference);
$record->contenthash = $sourcefile->get_contenthash();
$record->filesize = $sourcefile->get_filesize();
}
// Check if file exists.
if (repository::draftfile_exists($itemid, $saveas_path, $saveas_filename)) {
// File name being used, rename it.
$unused_filename = repository::get_unused_filename($itemid, $saveas_path, $saveas_filename);
$record->filename = $unused_filename;
// Create a file copy using unused filename.
$storedfile = $fs->create_file_from_reference($record, $repo_id, $reference);
$event = array();
$event['event'] = 'fileexists';
$event['newfile'] = new stdClass();
$event['newfile']->filepath = $saveas_path;
$event['newfile']->filename = $unused_filename;
示例3: print_error
case 'download':
// Check that user has permission to access this file
if (!$repo->file_is_accessible($fileurl)) {
print_error('storedfilecannotread');
}
$record = new stdClass();
$reference = $repo->get_file_reference($fileurl);
$sourcefield = $repo->get_file_source_info($fileurl);
$record->source = repository::build_source_field($sourcefield);
// If file is already a reference, set $fileurl = file source, $repo = file repository
// note that in this case user may not have permission to access the source file directly
// so no file_browser/file_info can be used below
if ($repo->has_moodle_files()) {
$file = repository::get_moodle_file($fileurl);
if ($file && $file->is_external_file()) {
$sourcefield = $file->get_source(); // remember the original source
$record->source = $repo::build_source_field($sourcefield);
$reference = $file->get_reference();
$repo_id = $file->get_repository_id();
$repo = repository::get_repository_by_id($repo_id, $contextid, $repooptions);
}
}
$record->filepath = $savepath;
$record->filename = $filename;
$record->component = 'user';
$record->filearea = 'draft';
$record->itemid = $itemid;
$record->license = '';