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

PHP file_save_draft_area_files函数代码示例

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

本文整理汇总了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函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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));
     }
 }
开发者ID:shinriyadi,项目名称:moodle,代码行数:14,代码来源:edit_form.php


示例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);
 }
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:12,代码来源:block_html.php


示例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;
    }
}
开发者ID:JP-Git,项目名称:moodle,代码行数:60,代码来源:editlib.php


示例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;
}
开发者ID:noparadise,项目名称:moodle-mod_slideshow,代码行数:14,代码来源:lib.php


示例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);
}
开发者ID:jamiemcg,项目名称:moodle-collaborative-annotation,代码行数:49,代码来源:locallib.php


示例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;
 }
开发者ID:UNEDLabs,项目名称:moodle-atto_ejsapp,代码行数:19,代码来源:atto_ejss_simulation.php


示例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);
    }
}
开发者ID:lex-programmer,项目名称:moodle-mod_pdfparts,代码行数:21,代码来源:locallib.php


示例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);
       }*/
 }
开发者ID:UNEDLabs,项目名称:moodle-atto_ejsapp,代码行数:20,代码来源:SimulationRecordingFile.php


示例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;
}
开发者ID:parksandwildlife,项目名称:learning,代码行数:48,代码来源:lib.php


示例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);
 }
开发者ID:OctaveBabel,项目名称:moodle-itop,代码行数:38,代码来源:questiontype.php


示例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));
 }
开发者ID:ULCC-QMUL,项目名称:moodle-mod_forumng,代码行数:24,代码来源:lockall.php


示例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;
}
开发者ID:IFPBMoodle,项目名称:moodle,代码行数:42,代码来源:filelib.php


示例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;
}
开发者ID:ccle,项目名称:moodle-mod_turnitintool,代码行数:94,代码来源:lib.php


示例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++;
         }
//.........这里部分代码省略.........
开发者ID:remotelearner,项目名称:moodle-mod_questionnaire,代码行数:101,代码来源:base.php


示例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);
}
开发者ID:ruddj,项目名称:moodle,代码行数:32,代码来源:lib.php


示例16: update

 /**
  * Update or create an event within the database
  *
  * Pass in a object containing the event properties and this function will
  * insert it into the database and deal with any associated files
  *
  * @see add_event()
  * @see update_event()
  *
  * @param stdClass $data object of event
  * @param bool $checkcapability if moodle should check calendar managing capability or not
  * @return bool event updated
  */
 public function update($data, $checkcapability = true)
 {
     global $CFG, $DB, $USER;
     foreach ($data as $key => $value) {
         $this->properties->{$key} = $value;
     }
     $this->properties->timemodified = time();
     $usingeditor = !empty($this->properties->description) && is_array($this->properties->description);
     if (empty($this->properties->id) || $this->properties->id < 1) {
         if ($checkcapability) {
             if (!calendar_add_event_allowed($this->properties)) {
                 print_error('nopermissiontoupdatecalendar');
             }
         }
         if ($usingeditor) {
             switch ($this->properties->eventtype) {
                 case 'user':
                     $this->properties->courseid = 0;
                     $this->properties->course = 0;
                     $this->properties->groupid = 0;
                     $this->properties->userid = $USER->id;
                     break;
                 case 'site':
                     $this->properties->courseid = SITEID;
                     $this->properties->course = SITEID;
                     $this->properties->groupid = 0;
                     $this->properties->userid = $USER->id;
                     break;
                 case 'course':
                     $this->properties->groupid = 0;
                     $this->properties->userid = $USER->id;
                     break;
                 case 'group':
                     $this->properties->userid = $USER->id;
                     break;
                 default:
                     // Ewww we should NEVER get here, but just incase we do lets
                     // fail gracefully
                     $usingeditor = false;
                     break;
             }
             // If we are actually using the editor, we recalculate the context because some default values
             // were set when calculate_context() was called from the constructor.
             if ($usingeditor) {
                 $this->properties->context = $this->calculate_context($this->properties);
                 $this->editorcontext = $this->properties->context;
             }
             $editor = $this->properties->description;
             $this->properties->format = $this->properties->description['format'];
             $this->properties->description = $this->properties->description['text'];
         }
         // Insert the event into the database
         $this->properties->id = $DB->insert_record('event', $this->properties);
         if ($usingeditor) {
             $this->properties->description = file_save_draft_area_files($editor['itemid'], $this->editorcontext->id, 'calendar', 'event_description', $this->properties->id, $this->editoroptions, $editor['text'], $this->editoroptions['forcehttps']);
             $DB->set_field('event', 'description', $this->properties->description, array('id' => $this->properties->id));
         }
         // Log the event entry.
         add_to_log($this->properties->courseid, 'calendar', 'add', 'event.php?action=edit&amp;id=' . $this->properties->id, $this->properties->name);
         $repeatedids = array();
         if (!empty($this->properties->repeat)) {
             $this->properties->repeatid = $this->properties->id;
             $DB->set_field('event', 'repeatid', $this->properties->repeatid, array('id' => $this->properties->id));
             $eventcopy = clone $this->properties;
             unset($eventcopy->id);
             for ($i = 1; $i < $eventcopy->repeats; $i++) {
                 $eventcopy->timestart = $eventcopy->timestart + WEEKSECS + dst_offset_on($eventcopy->timestart) - dst_offset_on($eventcopy->timestart + WEEKSECS);
                 // Get the event id for the log record.
                 $eventcopyid = $DB->insert_record('event', $eventcopy);
                 // If the context has been set delete all associated files
                 if ($usingeditor) {
                     $fs = get_file_storage();
                     $files = $fs->get_area_files($this->editorcontext->id, 'calendar', 'event_description', $this->properties->id);
                     foreach ($files as $file) {
                         $fs->create_file_from_storedfile(array('itemid' => $eventcopyid), $file);
                     }
                 }
                 $repeatedids[] = $eventcopyid;
                 // Log the event entry.
                 add_to_log($eventcopy->courseid, 'calendar', 'add', 'event.php?action=edit&amp;id=' . $eventcopyid, $eventcopy->name);
             }
         }
         // Hook for tracking added events
         self::calendar_event_hook('add_event', array($this->properties, $repeatedids));
         return true;
     } else {
         if ($checkcapability) {
//.........这里部分代码省略.........
开发者ID:miguelangelUvirtual,项目名称:uEducon,代码行数:101,代码来源:lib.php


示例17: feedback_update_instance

/**
 * this will update a given instance
 *
 * @global object
 * @param object $feedback the object given by mod_feedback_mod_form
 * @return boolean
 */
function feedback_update_instance($feedback) {
    global $DB;

    $feedback->timemodified = time();
    $feedback->id = $feedback->instance;

    //check if openenable and/or closeenable is set and set correctly to save in db
    if (empty($feedback->openenable)) {
        $feedback->timeopen = 0;
    }
    if (empty($feedback->closeenable)) {
        $feedback->timeclose = 0;
    }
    if (empty($feedback->site_after_submit)) {
        $feedback->site_after_submit = '';
    }

    //save the feedback into the db
    $DB->update_record("feedback", $feedback);

    //create or update the new events
    feedback_set_events($feedback);

    $context = get_context_instance(CONTEXT_MODULE, $feedback->coursemodule);

    $editoroptions = feedback_get_editor_options();

    // process the custom wysiwyg editor in page_after_submit
    if ($draftitemid = $feedback->page_after_submit_editor['itemid']) {
        $feedback->page_after_submit = file_save_draft_area_files($draftitemid, $context->id,
                                                    'mod_feedback', 'page_after_submit',
                                                    0, $editoroptions,
                                                    $feedback->page_after_submit_editor['text']);

        $feedback->page_after_submitformat = $feedback->page_after_submit_editor['format'];
    }
    $DB->update_record('feedback', $feedback);

    return true;
}
开发者ID:numbas,项目名称:moodle,代码行数:47,代码来源:lib.php


示例18: write_setting

 public function write_setting($data)
 {
     global $USER;
     // Let's not deal with validation here, this is for admins only.
     $current = $this->get_setting();
     if (empty($data) && $current === null) {
         // This will be the case when applying default settings (installation).
         return $this->config_write($this->name, '') ? '' : get_string('errorsetting', 'admin');
     } else {
         if (!is_number($data)) {
             // Draft item id is expected here!
             return get_string('errorsetting', 'admin');
         }
     }
     $options = $this->get_options();
     $fs = get_file_storage();
     $component = is_null($this->plugin) ? 'core' : $this->plugin;
     $this->oldhashes = null;
     if ($current) {
         $hash = sha1('/' . $options['context']->id . '/' . $component . '/' . $this->filearea . '/' . $this->itemid . $current);
         if ($file = $fs->get_file_by_hash($hash)) {
             $this->oldhashes = $file->get_contenthash() . $file->get_pathnamehash();
         }
         unset($file);
     }
     if ($fs->file_exists($options['context']->id, $component, $this->filearea, $this->itemid, '/', '.')) {
         // Make sure the settings form was not open for more than 4 days and draft areas deleted in the meantime.
         // But we can safely ignore that if the destination area is empty, so that the user is not prompt
         // with an error because the draft area does not exist, as he did not use it.
         $usercontext = context_user::instance($USER->id);
         if (!$fs->file_exists($usercontext->id, 'user', 'draft', $data, '/', '.') && $current !== '') {
             return get_string('errorsetting', 'admin');
         }
     }
     file_save_draft_area_files($data, $options['context']->id, $component, $this->filearea, $this->itemid, $options);
     $files = $fs->get_area_files($options['context']->id, $component, $this->filearea, $this->itemid, 'sortorder,filepath,filename', false);
     $filepath = '';
     if ($files) {
         /** @var stored_file $file */
         $file = reset($files);
         $filepath = $file->get_filepath() . $file->get_filename();
     }
     return $this->config_write($this->name, $filepath) ? '' : get_string('errorsetting', 'admin');
 }
开发者ID:Alexbado,项目名称:moodle2,代码行数:44,代码来源:adminlib.php


示例19: save_answers_files

 /**
  * save editor answers files and update answer record
  *
  * @param object $context
  * @param int $maxbytes
   

鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP file_save_upload函数代码示例发布时间:2022-05-15
下一篇:
PHP file_save_data函数代码示例发布时间: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