本文整理汇总了PHP中stored_file::get_sortorder方法的典型用法代码示例。如果您正苦于以下问题:PHP stored_file::get_sortorder方法的具体用法?PHP stored_file::get_sortorder怎么用?PHP stored_file::get_sortorder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stored_file
的用法示例。
在下文中一共展示了stored_file::get_sortorder方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: file_overwrite_existing_draftfile
/**
* Overwrite an existing file in a draft area.
*
* @param stored_file $newfile the new file with the new content and meta-data
* @param stored_file $existingfile the file that will be overwritten
* @throws moodle_exception
* @since Moodle 3.2
*/
function file_overwrite_existing_draftfile(stored_file $newfile, stored_file $existingfile)
{
if ($existingfile->get_component() != 'user' or $existingfile->get_filearea() != 'draft') {
throw new coding_exception('The file to overwrite is not in a draft area.');
}
$fs = get_file_storage();
// Remember original file source field.
$source = @unserialize($existingfile->get_source());
// Remember the original sortorder.
$sortorder = $existingfile->get_sortorder();
if ($newfile->is_external_file()) {
// New file is a reference. Check that existing file does not have any other files referencing to it
if (isset($source->original) && $fs->search_references_count($source->original)) {
throw new moodle_exception('errordoublereference', 'repository');
}
}
// Delete existing file to release filename.
$newfilerecord = array('contextid' => $existingfile->get_contextid(), 'component' => 'user', 'filearea' => 'draft', 'itemid' => $existingfile->get_itemid(), 'timemodified' => time());
$existingfile->delete();
// Create new file.
$newfile = $fs->create_file_from_storedfile($newfilerecord, $newfile);
// Preserve original file location (stored in source field) for handling references.
if (isset($source->original)) {
if (!($newfilesource = @unserialize($newfile->get_source()))) {
$newfilesource = new stdClass();
}
$newfilesource->original = $source->original;
$newfile->set_source(serialize($newfilesource));
}
$newfile->set_sortorder($sortorder);
}