本文整理汇总了PHP中file_save_draft_area_files函数的典型用法代码示例。如果您正苦于以下问题:PHP file_save_draft_area_files函数的具体用法?PHP file_save_draft_area_files怎么用?PHP file_save_draft_area_files使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了file_save_draft_area_files函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: set_data
function set_data($defaults)
{
if (empty($entry->id)) {
$entry = new stdClass();
$entry->id = null;
}
$draftitemid = file_get_submitted_draft_itemid('config_attachments');
file_prepare_draft_area($draftitemid, $this->block->context->id, 'block_slider', 'content', 0, array('subdirs' => true));
$entry->attachments = $draftitemid;
parent::set_data($defaults);
if ($data = parent::get_data()) {
file_save_draft_area_files($data->config_attachments, $this->block->context->id, 'block_slider', 'content', 0, array('subdirs' => true));
}
}
示例2: instance_config_save
/**
* Serialize and store config data
*/
function instance_config_save($data, $nolongerused = false)
{
global $DB;
$config = clone $data;
// Move embedded files into a proper filearea and adjust HTML links to match
$config->text = file_save_draft_area_files($data->text['itemid'], $this->context->id, 'block_html', 'content', 0, array('subdirs' => true), $data->text['text']);
$config->format = $data->text['format'];
parent::instance_config_save($config, $nolongerused);
}
示例3: 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, $filemanageroptions = array()) {
global $CFG, $DB;
require_once("$CFG->libdir/gdlib.php");
$context = context_user::instance($usernew->id, MUST_EXIST);
$user = $DB->get_record('user', array('id'=>$usernew->id), 'id, picture', MUST_EXIST);
$newpicture = $user->picture;
// Get file_storage to process files.
$fs = get_file_storage();
if (!empty($usernew->deletepicture)) {
// The user has chosen to delete the selected users picture
$fs->delete_area_files($context->id, 'user', 'icon'); // drop all images in area
$newpicture = 0;
} else {
// Save newly uploaded file, this will avoid context mismatch for newly created users.
file_save_draft_area_files($usernew->imagefile, $context->id, 'user', 'newicon', 0, $filemanageroptions);
if (($iconfiles = $fs->get_area_files($context->id, 'user', 'newicon')) && count($iconfiles) == 2) {
// Get file which was uploaded in draft area
foreach ($iconfiles as $file) {
if (!$file->is_directory()) {
break;
}
}
// Copy file to temporary location and the send it for processing icon
if ($iconfile = $file->copy_content_to_temp()) {
// There is a new image that has been uploaded
// Process the new image and set the user to make use of it.
// NOTE: Uploaded images always take over Gravatar
$newpicture = (int)process_new_icon($context, 'user', 'icon', 0, $iconfile);
// Delete temporary file
@unlink($iconfile);
// Remove uploaded file.
$fs->delete_area_files($context->id, 'user', 'newicon');
} else {
// Something went wrong while creating temp file.
// Remove uploaded file.
$fs->delete_area_files($context->id, 'user', 'newicon');
return false;
}
}
}
if ($newpicture != $user->picture) {
$DB->set_field('user', 'picture', $newpicture, array('id' => $user->id));
return true;
} else {
return false;
}
}
示例4: slideshow_update_instance
function slideshow_update_instance($data, $mform)
{
global $CFG, $DB;
$cmid = $data->coursemodule;
$draftitemid = $data->location;
$data->timemodified = time();
$data->id = $data->instance;
$DB->update_record("slideshow", $data);
$context = get_context_instance(CONTEXT_MODULE, $cmid);
if ($draftitemid = file_get_submitted_draft_itemid('location')) {
file_save_draft_area_files($draftitemid, $context->id, 'mod_slideshow', 'content', 0, array('subdirs' => true));
}
return true;
}
示例5: store_annotation_document
function store_annotation_document($data)
{
global $DB, $CFG;
$fs = get_file_storage();
$cmid = $data->coursemodule;
$draftitemid = $data->files;
$context = context_module::instance($cmid);
if ($draftitemid) {
$messagetext = file_save_draft_area_files($draftitemid, $context->id, 'mod_annotation', 'content', 0, array('subdirs' => true));
}
$files = $fs->get_area_files($context->id, 'mod_annotation', 'content', 0, 'sortorder', false);
if (count($files) == 1) {
// Only one file attached, set it as main file automatically.
$file = reset($files);
file_set_sortorder($context->id, 'mod_annotation', 'content', 0, $file->get_filepath(), $file->get_filename(), 1);
}
// Find out the file location by getting the content hash.
$table = "files";
$results = $DB->get_records($table, array('itemid' => $draftitemid));
foreach ($results as $result) {
$userid = $result->userid;
$timecreated = $result->timecreated;
$contenthash = $result->contenthash;
break;
// Bad way of doing it, TODO.
}
// Insert a reference into mdl_annotation_document.
$table = 'annotation_document';
$record = new stdClass();
$record->id = 0;
// DB will auto increment it.
$record->userid = $userid;
$record->group_id = 0;
$record->time_created = $timecreated;
$record->documenttype = $data->type;
$record->location = $contenthash;
$record->lang = "";
// Lang column no longer used, highlightjs automatically detects language.
$record->cmid = $cmid;
$record->groupannotation = $data->groupannotation;
if (isset($record->groupannotationsvisible)) {
$record->groupannotationsvisible = $data->groupannotationsvisible;
} else {
$record->groupannotationsvisible = 0;
}
$record->allowfrom = $data->allowfrom;
$record->allowuntil = $data->allowuntil;
$insertid = $DB->insert_record('annotation_document', $record, false);
}
示例6: saveSimulationFilesToDraft
/**
* Saves the simulation file into the draft area
* @return boolean
*/
public function saveSimulationFilesToDraft($CFG, $context, $draftitemid_applet)
{
$result = false;
$this->maxbytes = get_max_upload_file_size($CFG->maxbytes);
//Obtains the folder number to store the file
while (file_exists($this->folderpath . $this->incremental)) {
$this->incremental++;
}
//Saves the file in draft area
if ($draftitemid_applet) {
file_save_draft_area_files($draftitemid_applet, $context->id, 'atto_ejsapp', 'jarfiles', $this->incremental, array('subdirs' => 0, 'maxbytes' => $this->maxbytes, 'maxfiles' => 1, 'accepted_types' => array('application/java-archive', 'application/zip')));
$result = true;
}
return $result;
}
示例7: pdfparts_set_mainfile
/**
* Saves the file from pdfparts record somewhere on the server.
* @param object $data
*/
function pdfparts_set_mainfile($data)
{
global $DB;
$fs = get_file_storage();
$cmid = $data->coursemodule;
$draftitemid = $data->files;
$context = context_module::instance($cmid);
if ($draftitemid) {
file_save_draft_area_files($draftitemid, $context->id, 'mod_pdfparts', 'content', 0, array('subdirs' => true));
}
$files = $fs->get_area_files($context->id, 'mod_pdfparts', 'content', 0, 'sortorder', false);
if (count($files) == 1) {
// only one file attached, set it as main file automatically
$file = reset($files);
file_set_sortorder($context->id, 'mod_pdfparts', 'content', 0, $file->get_filepath(), $file->get_filename(), 1);
}
}
示例8: setInitilizationFile
public function setInitilizationFile($CFG, $DB, $context, $fromform, $incremental, $maxbytes, $folderpath)
{
$this->setSimulationFilePath("");
file_save_draft_area_files($fromform->recordingfile, $context->id, 'atto_ejsapp', 'recordingfiles', $incremental, array('subdirs' => 0, 'maxbytes' => $maxbytes, 'maxfiles' => 1, 'accepted_types' => '.rec'));
$fs = get_file_storage();
if ($files = $fs->get_area_files($context->id, 'atto_ejsapp', 'recordingfiles', $incremental, 'sortorder', false)) {
foreach ($files as $file) {
$fileurl = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());
$this->setSimulationFilePath($fileurl);
}
}
/*$file_records = $DB->get_records('files', array('contextid'=>$context->id, 'component'=>'atto_ejsapp', 'filearea'=>'recordingfiles', 'itemid'=>$incremental), 'filesize DESC');
$file_record = reset($file_records);
if($file_record) {
$fs = get_file_storage();
$file_state = $fs->get_file_by_id($file_record->id);
$file_state->copy_content_to($folderpath . "simfiles/".$file_record->filename);
$this->setSimulationFilePath($CFG->wwwroot . '/lib/editor/atto/plugins/ejsapp/jarfiles/' . $incremental . "/simfiles/".$file_record->filename);
}*/
}
示例9: dataform_add_instance
/**
* Adds an instance of a dataform
*
* @global object
* @param object $data
* @return $int
*/
function dataform_add_instance($data)
{
global $CFG, $DB, $COURSE;
$data->timemodified = time();
if (empty($data->grade)) {
$data->grade = 0;
$data->gradeitems = null;
}
// Max entries.
if (!isset($data->maxentries) or $data->maxentries < -1) {
$data->maxentries = -1;
}
if ($CFG->dataform_maxentries == 0) {
$data->maxentries = 0;
} else {
if ($CFG->dataform_maxentries > 0 and ($data->maxentries > $CFG->dataform_maxentries or $data->maxentries < 0)) {
$data->maxentries = $CFG->dataform_maxentries;
}
}
if (!($data->id = $DB->insert_record('dataform', $data))) {
return false;
}
// Activity icon.
if (!empty($data->activityicon)) {
// We need to use context now, so we need to make sure all needed info is already in db.
$DB->set_field('course_modules', 'instance', $data->id, array('id' => $data->coursemodule));
$context = context_module::instance($data->coursemodule);
$options = array('subdirs' => 0, 'maxbytes' => $COURSE->maxbytes, 'maxfiles' => 1, 'accepted_types' => array('image'));
file_save_draft_area_files($data->activityicon, $context->id, 'mod_dataform', 'activityicon', 0, $options);
}
// Calendar.
\mod_dataform\helper\calendar_event::update_event_timeavailable($data);
\mod_dataform\helper\calendar_event::update_event_timedue($data);
// Grading.
if ($data->grade) {
$grademan = \mod_dataform_grade_manager::instance($data->id);
$itemparams = $grademan->get_grade_item_params_from_data($data);
$grademan->update_grade_item(0, $itemparams);
}
return $data->id;
}
示例10: save_question_options
public function save_question_options($formdata)
{
global $DB;
$context = $formdata->context;
$options = $DB->get_record('qtype_poodllrecording_opts', array('questionid' => $formdata->id));
if (!$options) {
$options = new stdClass();
$options->questionid = $formdata->id;
$options->id = $DB->insert_record('qtype_poodllrecording_opts', $options);
}
//"import_or_save_files" won't work, because it expects output from an editor which is an array with member itemid
//the filemanager doesn't produce this, so need to use file save draft area directly
//$options->backimage = $this->import_or_save_files($formdata->backimage,
// $context, 'qtype_poodllrecording', 'backimage', $formdata->id);
if (isset($formdata->backimage)) {
file_save_draft_area_files($formdata->backimage, $context->id, 'qtype_poodllrecording', 'backimage', $formdata->id, array('subdirs' => 0, 'maxbytes' => 0, 'maxfiles' => 1));
//save the itemid of the backimage filearea
$options->backimage = $formdata->backimage;
} else {
$options->backimage = null;
}
//save the selected board size
if (isset($formdata->boardsize)) {
$options->boardsize = $formdata->boardsize;
} else {
$options->boardsize = "320x320";
}
//if we have a recording time limit
if (isset($formdata->timelimit)) {
$options->timelimit = $formdata->timelimit;
} else {
$options->timelimit = 0;
}
$options->responseformat = $formdata->responseformat;
$options->graderinfo = $this->import_or_save_files($formdata->graderinfo, $context, 'qtype_poodllrecording', 'graderinfo', $formdata->id);
$options->graderinfoformat = $formdata->graderinfo['format'];
$DB->update_record('qtype_poodllrecording_opts', $options);
}
示例11: apply
public function apply($discussion, $all, $selected, $formdata)
{
global $CFG;
$filecontext = $discussion->get_context();
$forum = $discussion;
if (!isset($formdata->mailnow)) {
$formdata->mailnow = false;
}
foreach ($selected as $postid) {
// Call the lock for selected discussions.
$discussion = mod_forumng_discussion::get_from_id($postid, $formdata->clone);
if (!$discussion->is_deleted() && !$discussion->is_locked()) {
$newpostid = $discussion->lock($formdata->subject, $formdata->message['text'], $formdata->message['format'], $formdata->attachments, $formdata->mailnow, '', '', $formdata->asmoderator);
// Save attachments.
file_save_draft_area_files($formdata->attachments, $filecontext->id, 'mod_forumng', 'attachment', $newpostid, null);
$newtext = file_save_draft_area_files($formdata->message['itemid'], $filecontext->id, 'mod_forumng', 'message', $newpostid, null, $formdata->message['text']);
if ($newtext !== $formdata->message['text']) {
mod_forumng_post::update_message_for_files($newpostid, $newtext);
}
}
}
// Redirect to the Main page.
redirect('../../view.php?' . $forum->get_link_params(mod_forumng::PARAM_PLAIN));
}
示例12: file_postupdate_standard_filemanager
/**
* Saves files modified by File manager formslib element
*
* @todo MDL-31073 review this function
* @category files
* @param stdClass $data $database entry field
* @param string $field name of data field
* @param array $options various options
* @param stdClass $context context - must already exist
* @param string $component
* @param string $filearea file area name
* @param int $itemid must already exist, usually means data is in db
* @return stdClass modified data obejct
*/
function file_postupdate_standard_filemanager($data, $field, array $options, $context, $component, $filearea, $itemid)
{
$options = (array) $options;
if (!isset($options['subdirs'])) {
$options['subdirs'] = false;
}
if (!isset($options['maxfiles'])) {
$options['maxfiles'] = -1;
// unlimited
}
if (!isset($options['maxbytes'])) {
$options['maxbytes'] = 0;
// unlimited
}
if (empty($data->{$field . '_filemanager'})) {
$data->{$field} = '';
} else {
file_save_draft_area_files($data->{$field . '_filemanager'}, $context->id, $component, $filearea, $itemid, $options);
$fs = get_file_storage();
if ($fs->get_area_files($context->id, $component, $filearea, $itemid)) {
$data->{$field} = '1';
// TODO: this is an ugly hack (skodak)
} else {
$data->{$field} = '';
}
}
return $data;
}
示例13: turnitintool_dofileupload_post_29
/**
* Upload file for submission
*
* @param object $cm the course module object
* @return array result and message
*/
function turnitintool_dofileupload_post_29($cm, $turnitintool, $userid, $post)
{
global $USER, $CFG;
$param_do = optional_param('do', null, PARAM_CLEAN);
$checksubmission = turnitintool_checkforsubmission($cm, $turnitintool, $post['submissionpart'], $userid);
if (isset($checksubmission->id) and $turnitintool->reportgenspeed == 0) {
// Kill the script here as we do not want double errors
// We only get here if there are no other errors
turnitintool_print_error('alreadysubmitted', 'turnitintool', NULL, NULL, __FILE__, __LINE__);
exit;
}
$resubmission = false;
if (isset($checksubmission->id) and $turnitintool->reportgenspeed > 0) {
$resubmission = true;
}
if ($resubmission and $checksubmission->dtdue < time()) {
turnitintool_print_error('alreadysubmitted', 'turnitintool', NULL, NULL, __FILE__, __LINE__);
exit;
}
$submitobject = new stdClass();
$submitobject->userid = $userid;
$submitobject->turnitintoolid = $turnitintool->id;
$submitobject->submission_part = $post['submissionpart'];
$submitobject->submission_type = $post['submissiontype'];
$submitobject->submission_queued = null;
$submitobject->submission_attempts = 0;
$submitobject->submission_gmimaged = 0;
$submitobject->submission_status = null;
$submitobject->submission_modified = time();
$submitobject->submission_objectid = !isset($checksubmission->submission_objectid) ? null : $checksubmission->submission_objectid;
if (!isset($checksubmission->submission_unanon) or $checksubmission->submission_unanon) {
// If non anon resubmission or new submission set the title as what was entered in the form
$submitobject->submission_title = $post['submissiontitle'];
if (!$turnitintool->anon) {
// If not anon assignment and this is a non anon resubmission or a new submission set the unanon flag to true (1)
$submitobject->submission_unanon = 1;
}
}
if (!$resubmission) {
// Prevent duplication in issues where the TII servers may be inaccessible.
if (!($check_existing = turnitintool_get_records_select('turnitintool_submissions', 'userid=' . $submitobject->userid . ' AND turnitintoolid=' . $submitobject->turnitintoolid . ' AND submission_part=' . $submitobject->submission_part))) {
if (!($submitobject->id = turnitintool_insert_record('turnitintool_submissions', $submitobject))) {
turnitintool_print_error('submissioninserterror', 'turnitintool', NULL, NULL, __FILE__, __LINE__);
exit;
}
}
} else {
$submitobject->id = $checksubmission->id;
$submitobject->submission_score = null;
$submitobject->submission_grade = null;
if (!turnitintool_update_record('turnitintool_submissions', $submitobject)) {
turnitintool_print_error('submissionupdateerror', 'turnitintool', NULL, NULL, __FILE__, __LINE__);
exit;
} else {
$submitobject->id = $checksubmission->id;
}
}
$return = array();
$context = context_module::instance($cm->id);
// Get draft item id and save the files in the draft area.
$draftitemid = file_get_submitted_draft_itemid('submissionfile');
$uploadoptions = array('maxbytes' => $turnitintool->maxfilesize, 'subdirs' => false, 'maxfiles' => 1, 'accepted_types' => '*');
file_prepare_draft_area($draftitemid, $context->id, 'mod_turnitintool', 'submissions', $submitobject->id, $uploadoptions);
file_save_draft_area_files($draftitemid, $context->id, 'mod_turnitintool', 'submissions', $submitobject->id, $uploadoptions);
$fs = get_file_storage();
$files = $fs->get_area_files($context->id, 'mod_turnitintool', 'submissions', $submitobject->id, "timecreated", false);
// This should only return 1 result.
if (count($files) == 0) {
$notice['result'] = false;
$_SESSION["notice"]["message"] = get_string('submissionfileerror', 'turnitintool');
$_SESSION["notice"]["type"] = "error";
turnitintool_delete_records('turnitintool_submissions', 'id', $submitobject->id);
return $notice;
} else {
$notice['result'] = true;
}
if (has_capability('mod/turnitintool:grade', turnitintool_get_context('MODULE', $cm->id)) and !$turnitintool->autosubmission) {
turnitintool_redirect($CFG->wwwroot . '/mod/turnitintool/view.php?id=' . $cm->id . '&do=allsubmissions');
exit;
} else {
if (!$turnitintool->autosubmission) {
turnitintool_redirect($CFG->wwwroot . '/mod/turnitintool/view.php?id=' . $cm->id . '&do=' . $param_do);
exit;
}
}
$notice["subid"] = $submitobject->id;
return $notice;
}
示例14: form_update
/**
* Create and update question data from the forms.
*/
public function form_update($formdata, $questionnaire)
{
global $DB;
$this->form_preprocess_data($formdata);
if (!empty($formdata->qid)) {
// Update existing question.
// Handle any attachments in the content.
$formdata->itemid = $formdata->content['itemid'];
$formdata->format = $formdata->content['format'];
$formdata->content = $formdata->content['text'];
$formdata->content = file_save_draft_area_files($formdata->itemid, $questionnaire->context->id, 'mod_questionnaire', 'question', $formdata->qid, array('subdirs' => true), $formdata->content);
$fields = array('name', 'type_id', 'length', 'precise', 'required', 'content', 'dependquestion', 'dependchoice');
$questionrecord = new \stdClass();
$questionrecord->id = $formdata->qid;
foreach ($fields as $f) {
if (isset($formdata->{$f})) {
$questionrecord->{$f} = trim($formdata->{$f});
}
}
$result = $this->update($questionrecord, false);
if (questionnaire_has_dependencies($questionnaire->questions)) {
questionnaire_check_page_breaks($questionnaire);
}
} else {
// Create new question:
// Need to update any image content after the question is created, so create then update the content.
$formdata->survey_id = $formdata->sid;
$fields = array('survey_id', 'name', 'type_id', 'length', 'precise', 'required', 'position', 'dependquestion', 'dependchoice');
$questionrecord = new \stdClass();
foreach ($fields as $f) {
if (isset($formdata->{$f})) {
$questionrecord->{$f} = trim($formdata->{$f});
}
}
$questionrecord->content = '';
$this->add($questionrecord);
// Handle any attachments in the content.
$formdata->itemid = $formdata->content['itemid'];
$formdata->format = $formdata->content['format'];
$formdata->content = $formdata->content['text'];
$content = file_save_draft_area_files($formdata->itemid, $questionnaire->context->id, 'mod_questionnaire', 'question', $this->qid, array('subdirs' => true), $formdata->content);
$result = $DB->set_field('questionnaire_question', 'content', $content, array('id' => $this->qid));
}
if ($this->has_choices()) {
// Now handle any choice updates.
$cidx = 0;
if (isset($this->choices) && !isset($formdata->makecopy)) {
$oldcount = count($this->choices);
$echoice = reset($this->choices);
$ekey = key($this->choices);
} else {
$oldcount = 0;
}
$newchoices = explode("\n", $formdata->allchoices);
$nidx = 0;
$newcount = count($newchoices);
while ($nidx < $newcount && $cidx < $oldcount) {
if ($newchoices[$nidx] != $echoice->content) {
$choicerecord = new \stdClass();
$choicerecord->id = $ekey;
$choicerecord->question_id = $this->qid;
$choicerecord->content = trim($newchoices[$nidx]);
$r = preg_match_all("/^(\\d{1,2})(=.*)\$/", $newchoices[$nidx], $matches);
// This choice has been attributed a "score value" OR this is a rate question type.
if ($r) {
$newscore = $matches[1][0];
$choicerecord->value = $newscore;
} else {
// No score value for this choice.
$choicerecord->value = null;
}
$this->update_choice($choicerecord);
}
$nidx++;
$echoice = next($this->choices);
$ekey = key($this->choices);
$cidx++;
}
while ($nidx < $newcount) {
// New choices...
$choicerecord = new \stdClass();
$choicerecord->question_id = $this->qid;
$choicerecord->content = trim($newchoices[$nidx]);
$r = preg_match_all("/^(\\d{1,2})(=.*)\$/", $choicerecord->content, $matches);
// This choice has been attributed a "score value" OR this is a rate question type.
if ($r) {
$choicerecord->value = $matches[1][0];
}
$this->add_choice($choicerecord);
$nidx++;
}
while ($cidx < $oldcount) {
end($this->choices);
$ekey = key($this->choices);
$this->delete_choice($ekey);
$cidx++;
}
//.........这里部分代码省略.........
示例15: scorm_dndupload_handle
/**
* Handle a file that has been uploaded
* @param object $uploadinfo details of the file / content that has been uploaded
* @return int instance id of the newly created mod
*/
function scorm_dndupload_handle($uploadinfo) {
$context = context_module::instance($uploadinfo->coursemodule);
file_save_draft_area_files($uploadinfo->draftitemid, $context->id, 'mod_scorm', 'package', 0);
$fs = get_file_storage();
$files = $fs->get_area_files($context->id, 'mod_scorm', 'package', 0, 'sortorder, itemid, filepath, filename', false);
$file = reset($files);
// Validate the file, make sure it's a valid SCORM package!
$errors = scorm_validate_package($file);
if (!empty($errors)) {
return false;
}
// Create a default scorm object to pass to scorm_add_instance()!
$scorm = get_config('scorm');
$scorm->course = $uploadinfo->course->id;
$scorm->coursemodule = $uploadinfo->coursemodule;
$scorm->cmidnumber = '';
$scorm->name = $uploadinfo->displayname;
$scorm->scormtype = SCORM_TYPE_LOCAL;
$scorm->reference = $file->get_filename();
$scorm->intro = '';
$scorm->width = $scorm->framewidth;
$scorm->height = $scorm->frameheight;
return scorm_add_instance($scorm, null);
}