• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

PHP get_file_storage函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中get_file_storage函数的典型用法代码示例。如果您正苦于以下问题:PHP get_file_storage函数的具体用法?PHP get_file_storage怎么用?PHP get_file_storage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_file_storage函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: assignfeedback_editpdf_pluginfile

/**
 * Serves assignment feedback and other files.
 *
 * @param mixed $course course or id of the course
 * @param mixed $cm course module or id of the course module
 * @param context $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - just send the file
 */
function assignfeedback_editpdf_pluginfile($course, $cm, context $context, $filearea, $args, $forcedownload)
{
    global $USER, $DB, $CFG;
    if ($context->contextlevel == CONTEXT_MODULE) {
        require_login($course, false, $cm);
        $itemid = (int) array_shift($args);
        if (!($assign = $DB->get_record('assign', array('id' => $cm->instance)))) {
            return false;
        }
        $record = $DB->get_record('assign_grades', array('id' => $itemid), 'userid,assignment', MUST_EXIST);
        $userid = $record->userid;
        if ($assign->id != $record->assignment) {
            return false;
        }
        // Check is users feedback or has grading permission.
        if ($USER->id != $userid and !has_capability('mod/assign:grade', $context)) {
            return false;
        }
        $relativepath = implode('/', $args);
        $fullpath = "/{$context->id}/assignfeedback_editpdf/{$filearea}/{$itemid}/{$relativepath}";
        $fs = get_file_storage();
        if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
            return false;
        }
        // Download MUST be forced - security!
        send_stored_file($file, 0, 0, true);
        // Check if we want to retrieve the stamps.
    }
}
开发者ID:pzhu2004,项目名称:moodle,代码行数:40,代码来源:lib.php


示例2: __construct

 /**
  * Constructs a file picker object.
  *
  * The following are possible options for the filepicker:
  *    - accepted_types  (*)
  *    - return_types    (FILE_INTERNAL)
  *    - env             (filepicker)
  *    - client_id       (uniqid)
  *    - itemid          (0)
  *    - maxbytes        (-1)
  *    - maxfiles        (1)
  *    - buttonname      (false)
  *
  * @param stdClass $options An object containing options for the file picker.
  */
 public function __construct(stdClass $options)
 {
     global $CFG, $USER, $PAGE;
     require_once $CFG->dirroot . '/repository/lib.php';
     $defaults = array('accepted_types' => '*', 'return_types' => FILE_INTERNAL, 'env' => 'filepicker', 'client_id' => uniqid(), 'itemid' => 0, 'maxbytes' => -1, 'maxfiles' => 1, 'buttonname' => false);
     foreach ($defaults as $key => $value) {
         if (empty($options->{$key})) {
             $options->{$key} = $value;
         }
     }
     $options->currentfile = '';
     if (!empty($options->itemid)) {
         $fs = get_file_storage();
         $usercontext = context_user::instance($USER->id);
         if (empty($options->filename)) {
             if ($files = $fs->get_area_files($usercontext->id, 'user', 'draft', $options->itemid, 'id DESC', false)) {
                 $file = reset($files);
             }
         } else {
             $file = $fs->get_file($usercontext->id, 'user', 'draft', $options->itemid, $options->filepath, $options->filename);
         }
         if (!empty($file)) {
             $options->currentfile = html_writer::link(moodle_url::make_draftfile_url($file->get_itemid(), $file->get_filepath(), $file->get_filename()), $file->get_filename());
         }
     }
     // initilise options, getting files in root path
     $this->options = initialise_filepicker($options);
     // copying other options
     foreach ($options as $name => $value) {
         if (!isset($this->options->{$name})) {
             $this->options->{$name} = $value;
         }
     }
 }
开发者ID:jtibbetts,项目名称:moodle,代码行数:49,代码来源:outputcomponents.php


示例3: block_xp_pluginfile

/**
 * File serving.
 *
 * @param stdClass $course The course object.
 * @param stdClass $bi Block instance record.
 * @param context $context The context object.
 * @param string $filearea The file area.
 * @param array $args List of arguments.
 * @param bool $forcedownload Whether or not to force the download of the file.
 * @param array $options Array of options.
 * @return void|false
 */
function block_xp_pluginfile($course, $bi, $context, $filearea, $args, $forcedownload, array $options = array())
{
    global $CFG;
    if ($CFG->block_xp_context == CONTEXT_SYSTEM && $context->contextlevel !== CONTEXT_SYSTEM) {
        return false;
    } else {
        if ($CFG->block_xp_context != CONTEXT_SYSTEM && $context->contextlevel !== CONTEXT_COURSE) {
            return false;
        }
    }
    $fs = get_file_storage();
    $file = null;
    if ($filearea == 'badges') {
        // For performance reason, and very low risk, we do not restrict the access to the level badges
        // to the participant of the course, nor do we check if they have the required level, etc...
        $itemid = array_shift($args);
        $filename = array_shift($args);
        $filepath = '/';
        $file = $fs->get_file($context->id, 'block_xp', $filearea, $itemid, $filepath, $filename . '.png');
        if (!$file) {
            $file = $fs->get_file($context->id, 'block_xp', $filearea, $itemid, $filepath, $filename . '.jpg');
        }
    }
    if (!$file) {
        return false;
    }
    send_stored_file($file);
}
开发者ID:antoniorodrigues,项目名称:redes-digitais,代码行数:40,代码来源:lib.php


示例4: dataformview_tabular_pluginfile

/**
 * Serves the dataformview_tabular template files.
 *
 * @param object $course
 * @param object $cm
 * @param object $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - justsend the file
 */
function dataformview_tabular_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload)
{
    if (!in_array($filearea, dataformview_tabular_tabular::get_file_areas())) {
        return false;
    }
    if ($context->contextlevel == CONTEXT_MODULE) {
        require_course_login($course, true, $cm);
        $viewid = (int) array_shift($args);
        $dataformid = $cm->instance;
        // Confirm user access.
        $params = array('dataformid' => $dataformid, 'viewid' => $viewid);
        if (!mod_dataform\access\view_access::validate($params)) {
            return false;
        }
        $relativepath = implode('/', $args);
        $fullpath = "/{$context->id}/dataformview_tabular/{$filearea}/{$viewid}/{$relativepath}";
        $fs = get_file_storage();
        if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
            return false;
        }
        // Finally send the file.
        send_stored_file($file, 0, 0, true);
        // Download MUST be forced - security!
    }
    return false;
}
开发者ID:parksandwildlife,项目名称:learning,代码行数:37,代码来源:lib.php


示例5: assignsubmission_onlinepoodll_pluginfile

/**
 * Serves assignment submissions and other files.
 *
 * @param mixed $course course or id of the course
 * @param mixed $cm course module or id of the course module
 * @param context $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - just send the file
 */
function assignsubmission_onlinepoodll_pluginfile($course, $cm, context $context, $filearea, $args, $forcedownload)
{
    global $USER, $DB;
    if ($context->contextlevel != CONTEXT_MODULE) {
        return false;
    }
    require_login($course, false, $cm);
    $itemid = (int) array_shift($args);
    //back image is a special case
    if (!($itemid == 0 && ($filearea = "onlinepoodll_backimage"))) {
        $record = $DB->get_record('assign_submission', array('id' => $itemid), 'userid, assignment', MUST_EXIST);
        $userid = $record->userid;
        if (!($assign = $DB->get_record('assign', array('id' => $cm->instance)))) {
            return false;
        }
        if ($assign->id != $record->assignment) {
            return false;
        }
        // check is users submission or has grading permission
        if ($USER->id != $userid and !has_capability('mod/assign:grade', $context)) {
            return false;
        }
    }
    $relativepath = implode('/', $args);
    $fullpath = "/{$context->id}/assignsubmission_onlinepoodll/{$filearea}/{$itemid}/{$relativepath}";
    $fs = get_file_storage();
    if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
        return false;
    }
    send_stored_file($file, 0, 0, true);
    // download MUST be forced - security!
}
开发者ID:laiello,项目名称:poodll.poodll23,代码行数:43,代码来源:lib.php


示例6: printFile

 private function printFile($arg)
 {
     global $CFG;
     $id = trim($arg);
     if (strlen($id) == 40) {
         //this is file hash
         $hash = $id;
     } else {
         $fs = get_file_storage();
         $file = $fs->get_file_by_id($id);
         if (!$file) {
             echo "File '{$id}' not found\n";
             return;
         }
         $hash = $file->get_contenthash();
     }
     if (isset($CFG->filedir)) {
         $filedir = $CFG->filedir;
     } else {
         $filedir = $CFG->dataroot . '/filedir';
     }
     $l1 = $hash[0] . $hash[1];
     $l2 = $hash[2] . $hash[3];
     if ($this->expandedOptions['relative']) {
         echo "filedir/{$l1}/{$l2}/{$hash}\n";
     } else {
         echo "{$filedir}/{$l1}/{$l2}/{$hash}\n";
     }
 }
开发者ID:dariogs,项目名称:moosh,代码行数:29,代码来源:FilePath.php


示例7: copyFromBlock

 function copyFromBlock(GcrMdlBlockCourseProfile $parent_block, GcrMdlCourse $course)
 {
     $obj = $parent_block->getObject();
     // If the instructor set on the parent block also has a teaching role
     // on this course, copy that instructorid. Otherwise, set it to the
     // default instructor of this course.
     $instructorid = 0;
     $courseid = $course->getObject()->id;
     $course_context_id = $course->getContext()->id;
     $instructor = $parent_block->getApp()->getUserById($obj->instructorid);
     if ($instructor && $course->isInstructor($instructor)) {
         $instructorid = $obj->instructorid;
     } else {
         $instructor = $course->getInstructor();
         if ($instructor) {
             $instructorid = $instructor->getObject()->id;
         } else {
             return false;
         }
     }
     $fs = get_file_storage();
     $existing_file = $fs->get_file($course_context_id, 'block_course_profile', 'courseicon', 0, '/', $courseid);
     if ($existing_file) {
         $existing_file->delete();
     }
     $file = $fs->get_file($parent_block->getContext()->id, 'block_course_profile', 'courseicon', 0, '/', $obj->courseid);
     $file_record = array('contextid' => $course_context_id, 'component' => 'block_course_profile', 'filearea' => 'courseicon', 'itemid' => 0, 'filepath' => '/', 'filename' => $courseid, 'userid' => $instructorid);
     $fs->create_file_from_storedfile($file_record, $file);
     $data = array('courseid' => $courseid, 'instructorid' => $instructorid, 'courseicon' => $obj->courseicon);
     $course->getApp()->upsertIntoMdlTable('block_course_profile', $data, array('courseid' => $courseid));
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:31,代码来源:block_course_profile.php


示例8: test_import_chapters_events

 public function test_import_chapters_events()
 {
     $course = $this->getDataGenerator()->create_course();
     $book = $this->getDataGenerator()->create_module('book', array('course' => $course->id));
     $context = context_module::instance($book->cmid);
     $record = new stdClass();
     $record->contextid = $context->id;
     $record->component = 'phpunit';
     $record->filearea = 'test';
     $record->itemid = 0;
     $record->filepath = '/';
     $record->filename = 'chapters.zip';
     $fs = get_file_storage();
     $file = $fs->create_file_from_pathname($record, __DIR__ . '/fixtures/chapters.zip');
     // Importing the chapters.
     $sink = $this->redirectEvents();
     toolbook_importhtml_import_chapters($file, 2, $book, $context, false);
     $events = $sink->get_events();
     // Checking the results.
     $this->assertCount(5, $events);
     foreach ($events as $event) {
         $this->assertInstanceOf('\\mod_book\\event\\chapter_created', $event);
         $this->assertEquals($context, $event->get_context());
         $chapter = $event->get_record_snapshot('book_chapters', $event->objectid);
         $this->assertNotEmpty($chapter);
         $this->assertEventContextNotUsed($event);
     }
 }
开发者ID:evltuma,项目名称:moodle,代码行数:28,代码来源:locallib_test.php


示例9: 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


示例10: useredit_update_picture

/**
 * Updates the provided users profile picture based upon the expected fields
 * returned from the edit or edit_advanced forms.
 *
 * @global moodle_database $DB
 * @param stdClass $usernew An object that contains some information about the user being updated
 * @param moodleform $userform The form that was submitted to edit the form
 * @return bool True if the user was updated, false if it stayed the same.
 */
function useredit_update_picture(stdClass $usernew, moodleform $userform) {
    global $CFG, $DB;
    require_once("$CFG->libdir/gdlib.php");

    $context = get_context_instance(CONTEXT_USER, $usernew->id, MUST_EXIST);
    // This will hold the value to set to the user's picture field at the end of
    // this function
    $picturetouse = null;
    if (!empty($usernew->deletepicture)) {
        // The user has chosen to delete the selected users picture
        $fs = get_file_storage();
        $fs->delete_area_files($context->id, 'user', 'icon'); // drop all areas
        $picturetouse = 0;
    } else if ($iconfile = $userform->save_temp_file('imagefile')) {
        // There is a new image that has been uploaded
        // Process the new image and set the user to make use of it.
        // NOTE: This may be overridden by Gravatar
        if (process_new_icon($context, 'user', 'icon', 0, $iconfile)) {
            $picturetouse = 1;
        }
        // Delete the file that has now been processed
        @unlink($iconfile);
    }

    // If we have a picture to set we can now do so. Note this will still be NULL
    // unless the user has changed their picture or caused a change by selecting
    // to delete their picture or use gravatar
    if (!is_null($picturetouse)) {
        $DB->set_field('user', 'picture', $picturetouse, array('id' => $usernew->id));
        return true;
    }

    return false;
}
开发者ID:nigeldaley,项目名称:moodle,代码行数:43,代码来源:editlib.php


示例11: assignsubmission_onenote_pluginfile

/**
 * Serves assignment submissions and other files.
 *
 * @param mixed $course course or id of the course
 * @param mixed $cm course module or id of the course module
 * @param context $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - just send the file
 */
function assignsubmission_onenote_pluginfile($course, $cm, context $context, $filearea, $args, $forcedownload)
{
    global $DB, $CFG;
    if ($context->contextlevel != CONTEXT_MODULE) {
        return false;
    }
    require_login($course, false, $cm);
    $itemid = (int) array_shift($args);
    $record = $DB->get_record('assign_submission', array('id' => $itemid), 'userid, assignment, groupid', MUST_EXIST);
    $userid = $record->userid;
    $groupid = $record->groupid;
    require_once $CFG->dirroot . '/mod/assign/locallib.php';
    $assign = new assign($context, $cm, $course);
    if ($assign->get_instance()->id != $record->assignment) {
        return false;
    }
    if ($assign->get_instance()->teamsubmission && !$assign->can_view_group_submission($groupid)) {
        return false;
    }
    if (!$assign->get_instance()->teamsubmission && !$assign->can_view_submission($userid)) {
        return false;
    }
    $relativepath = implode('/', $args);
    $fullpath = "/{$context->id}/assignsubmission_onenote/{$filearea}/{$itemid}/{$relativepath}";
    $fs = get_file_storage();
    if (!($file = $fs->get_file_by_hash(sha1($fullpath))) || $file->is_directory()) {
        return false;
    }
    // Download MUST be forced - security!
    send_stored_file($file, 0, 0, true);
}
开发者ID:eugeneventer,项目名称:o365-moodle,代码行数:42,代码来源:lib.php


示例12: local_filemanager_pluginfile

function local_filemanager_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
    global $DB;
    if ($context->contextlevel != CONTEXT_SYSTEM) {
        return false;
    }
    require_login();
    if ($filearea != 'attachment') {
        return false;
    }
    $itemid = (int) array_shift($args);
    if ($itemid != 0) {
        return false;
    }
    $fs = get_file_storage();
    $filename = array_pop($args);
    if (empty($args)) {
        $filepath = '/';
    } else {
        $filepath = '/' . implode('/', $args) . '/';
    }
    $file = $fs->get_file($context->id, 'local_filemanager', $filearea, $itemid, $filepath, $filename);
    if (!$file) {
        return false;
    }
    // finally send the file
    send_stored_file($file, 0, 0, true, $options);
    // download MUST be forced - security!
}
开发者ID:sharkadder,项目名称:filemanager-1,代码行数:29,代码来源:lib.php


示例13: copy_file_moodle2backup

 /**
  * Copy one file from moodle storage to backup storage
  */
 public static function copy_file_moodle2backup($backupid, $filerecorid)
 {
     global $DB;
     // Normalise param
     if (!is_object($filerecorid)) {
         $filerecorid = $DB->get_record('files', array('id' => $filerecorid));
     }
     // Directory, nothing to do
     if ($filerecorid->filename === '.') {
         return;
     }
     $fs = get_file_storage();
     $file = $fs->get_file_instance($filerecorid);
     // If the file is external file, skip copying.
     if ($file->is_external_file()) {
         return;
     }
     // Calculate source and target paths (use same subdirs strategy for both)
     $targetfilepath = self::get_backup_storage_base_dir($backupid) . '/' . self::get_backup_content_file_location($filerecorid->contenthash);
     // Create target dir if necessary
     if (!file_exists(dirname($targetfilepath))) {
         if (!check_dir_exists(dirname($targetfilepath), true, true)) {
             throw new backup_helper_exception('cannot_create_directory', dirname($targetfilepath));
         }
     }
     // And copy the file (if doesn't exist already)
     if (!file_exists($targetfilepath)) {
         $file->copy_content_to($targetfilepath);
     }
 }
开发者ID:JP-Git,项目名称:moodle,代码行数:33,代码来源:backup_file_manager.class.php


示例14: __construct

 public function __construct()
 {
     global $USER;
     $this->context = get_context_instance(CONTEXT_USER, $USER->id);
     $fs = get_file_storage();
     $this->dir = $fs->get_area_tree($this->context->id, 'user', 'private', 0);
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:7,代码来源:renderer.php


示例15: __construct

 public function __construct($context)
 {
     global $USER;
     $this->context = $context;
     $fs = get_file_storage();
     $this->dir = $fs->get_area_tree($this->context->id, 'user', 'csvenrol', 0);
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:7,代码来源:renderer.php


示例16: block_jmail_pluginfile

/**
 * Serves the message attachments. Implements needed access control ;-)
 *
 * @param object $course
 * @param object $cm
 * @param object $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - justsend the file
 */
function block_jmail_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload)
{
    global $SCRIPT;
    if ($context->contextlevel != CONTEXT_BLOCK) {
        //send_file_not_found();
    }
    require_course_login($course);
    $coursecontext = block_jmail_get_context(CONTEXT_COURSE, $course->id, MUST_EXIST);
    // The mailbox constructor does the permission validation
    if (!($mailbox = new block_jmail_mailbox($course, $coursecontext, $context))) {
        return;
    }
    $messageid = (int) array_shift($args);
    $message = block_jmail_message::get_from_id($messageid);
    // We check if we are the senders or the receivers
    if (!$message) {
        send_file_not_found();
    }
    $pendingaprobal = !$message->approved and has_capability('block/jmail:approvemessages', $context);
    if (!$message->is_mine() and !$pendingaprobal) {
        send_file_not_found();
    }
    $fs = get_file_storage();
    $relativepath = implode('/', $args);
    $fullpath = "/{$context->id}/block_jmail/{$filearea}/{$messageid}/{$relativepath}";
    if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
        send_file_not_found();
    }
    $forcedownload = true;
    send_stored_file($file, 60 * 60, 0, $forcedownload);
}
开发者ID:borrown,项目名称:moodle-block_jmail,代码行数:42,代码来源:lib.php


示例17: assignment_delete_instance

/**
 * Deletes an assignment instance
 *
 * @param $id
 */
function assignment_delete_instance($id)
{
    global $CFG, $DB;
    if (!($assignment = $DB->get_record('assignment', array('id' => $id)))) {
        return false;
    }
    $result = true;
    // Now get rid of all files
    $fs = get_file_storage();
    if ($cm = get_coursemodule_from_instance('assignment', $assignment->id)) {
        $context = context_module::instance($cm->id);
        $fs->delete_area_files($context->id);
    }
    if (!$DB->delete_records('assignment_submissions', array('assignment' => $assignment->id))) {
        $result = false;
    }
    if (!$DB->delete_records('event', array('modulename' => 'assignment', 'instance' => $assignment->id))) {
        $result = false;
    }
    if (!$DB->delete_records('assignment', array('id' => $assignment->id))) {
        $result = false;
    }
    grade_update('mod/assignment', $assignment->course, 'mod', 'assignment', $assignment->id, 0, NULL, array('deleted' => 1));
    return $result;
}
开发者ID:evltuma,项目名称:moodle,代码行数:30,代码来源:lib.php


示例18: seplfeedback_file_pluginfile

/**
 * Serves seplment feedback and other files.
 *
 * @param mixed $course course or id of the course
 * @param mixed $cm course module or id of the course module
 * @param context $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - just send the file
 */
function seplfeedback_file_pluginfile($course, $cm, context $context, $filearea, $args, $forcedownload)
{
    global $USER, $DB;
    if ($context->contextlevel != CONTEXT_MODULE) {
        return false;
    }
    require_login($course, false, $cm);
    $itemid = (int) array_shift($args);
    $record = $DB->get_record('sepl_grades', array('id' => $itemid), 'userid,seplment', MUST_EXIST);
    $userid = $record->userid;
    if (!($sepl = $DB->get_record('sepl', array('id' => $cm->instance)))) {
        return false;
    }
    if ($sepl->id != $record->seplment) {
        return false;
    }
    // Check is users feedback or has grading permission.
    if ($USER->id != $userid and !has_capability('mod/sepl:grade', $context)) {
        return false;
    }
    $relativepath = implode('/', $args);
    $fullpath = "/{$context->id}/seplfeedback_file/{$filearea}/{$itemid}/{$relativepath}";
    $fs = get_file_storage();
    if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
        return false;
    }
    // Download MUST be forced - security!
    send_stored_file($file, 0, 0, true);
}
开发者ID:krzpassrl,项目名称:SRL_Moodle_Baseline,代码行数:40,代码来源:lib.php


示例19: open

 /**
  * Open the file
  *
  * @param int $mode One of RLIP_FILE_READ or RLIP_FILE_WRITE, specifying
  *                  the mode in which the file should be opened
  */
 function open($mode)
 {
     global $CFG;
     $fs = get_file_storage();
     if ($mode == RLIP_FILE_WRITE) {
         if ($this->sendtobrowser) {
             // must buffer output in case of errors
             $this->tempfile = tempnam(sys_get_temp_dir(), basename($this->filename));
             $this->filepointer = fopen($this->tempfile, 'w');
         } else {
             //we are only writing to files on the file-system
             $this->filepointer = fopen($this->filename, 'w');
         }
     } else {
         if ($this->filename != '') {
             //read from the file system
             $this->filepointer = fopen($this->filename, 'r');
         } else {
             //read from a Moodle file
             $file = $fs->get_file_by_id($this->fileid);
             $this->filepointer = $file->get_content_file_handle();
         }
     }
     $this->first = true;
     $this->header = NULL;
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:32,代码来源:csv.class.php


示例20: save_question_options

 public function save_question_options($question)
 {
     global $DB;
     $result = new stdClass();
     $context = $question->context;
     // Fetch old answer ids so that we can reuse them.
     $oldanswers = $DB->get_records('question_answers', array('question' => $question->id), 'id ASC');
     // Save the true answer - update an existing answer if possible.
     $answer = array_shift($oldanswers);
     if (!$answer) {
         $answer = new stdClass();
         $answer->question = $question->id;
         $answer->answer = '';
         $answer->feedback = '';
         $answer->id = $DB->insert_record('question_answers', $answer);
     }
     $answer->answer = get_string('true', 'qtype_truefalse');
     $answer->fraction = $question->correctanswer;
     $answer->feedback = $this->import_or_save_files($question->feedbacktrue, $context, 'question', 'answerfeedback', $answer->id);
     $answer->feedbackformat = $question->feedbacktrue['format'];
     $DB->update_record('question_answers', $answer);
     $trueid = $answer->id;
     // Save the false answer - update an existing answer if possible.
     $answer = array_shift($oldanswers);
     if (!$answer) {
         $answer = new stdClass();
         $answer->question = $question->id;
         $answer->answer = '';
         $answer->feedback = '';
         $answer->id = $DB->insert_record('question_answers', $answer);
     }
     $answer->answer = get_string('false', 'qtype_truefalse');
     $answer->fraction = 1 - (int) $question->correctanswer;
     $answer->feedback = $this->import_or_save_files($question->feedbackfalse, $context, 'question', 'answerfeedback', $answer->id);
     $answer->feedbackformat = $question->feedbackfalse['format'];
     $DB->update_record('question_answers', $answer);
     $falseid = $answer->id;
     // Delete any left over old answer records.
     $fs = get_file_storage();
     foreach ($oldanswers as $oldanswer) {
         $fs->delete_area_files($context->id, 'question', 'answerfeedback', $oldanswer->id);
         $DB->delete_records('question_answers', array('id' => $oldanswer->id));
     }
     // Save question options in question_truefalse table.
     if ($options = $DB->get_record('question_truefalse', array('question' => $question->id))) {
         // No need to do anything, since the answer IDs won't have changed
         // But we'll do it anyway, just for robustness.
         $options->trueanswer = $trueid;
         $options->falseanswer = $falseid;
         $DB->update_record('question_truefalse', $options);
     } else {
         $options = new stdClass();
         $options->question = $question->id;
         $options->trueanswer = $trueid;
         $options->falseanswer = $falseid;
         $DB->insert_record('question_truefalse', $options);
     }
     $this->save_hints($question);
     return true;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:60,代码来源:questiontype.php



注:本文中的get_file_storage函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP get_file_suffix函数代码示例发布时间:2022-05-15
下一篇:
PHP get_file_size函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap