From: skodak Date: Wed, 29 Apr 2009 07:52:35 +0000 (+0000) Subject: MDL-19002 new simplified file api file limits; docs are still not finished X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=85db95e7084fe78d119b07717cb84230a2c802af;p=moodle.git MDL-19002 new simplified file api file limits; docs are still not finished --- diff --git a/lib/filelib.php b/lib/filelib.php index d06deadc2b..f4acc0f13f 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -154,7 +154,7 @@ function file_prepare_standard_editor($data, $field, array $options, $context=nu $draftid_editor = file_get_submitted_draft_itemid($field); $currenttext = file_prepare_draft_area($draftid_editor, $contextid, $filearea, $data->id, $options['subdirs'], $data->{$field}, $options['forcehttps']); - $data->{'editor_'.$field} = array('text'=>$currenttext, 'format'=>$data->{$field.'format'}, 'itemid'=>$draftid_editor); + $data->{$field.'_editor'} = array('text'=>$currenttext, 'format'=>$data->{$field.'format'}, 'itemid'=>$draftid_editor); return $data; } @@ -181,7 +181,7 @@ function file_postupdate_standard_editor($data, $field, array $options, $context $options['subdirs'] = false; } if (!isset($options['maxfiles'])) { - $options['maxfiles'] = -1; // unlimited + $options['maxfiles'] = 0; // no files by default } if (!isset($options['maxbytes'])) { $options['maxbytes'] = 0; // unlimited @@ -193,7 +193,7 @@ function file_postupdate_standard_editor($data, $field, array $options, $context $data->definitiontrust = 0; } - $editor = $data->{'editor_'.$field}; + $editor = $data->{$field.'_editor'}; $data->{$field} = file_save_draft_area_files($editor['itemid'], $context->id, $filearea, $itemid, $options, $editor['text'], $options['forcehttps']); $data->{$field.'format'} = $editor['format']; @@ -223,9 +223,9 @@ function file_prepare_standard_filemanager($data, $field, array $options, $conte $contextid = $context->id; } - $draftid_editor = file_get_submitted_draft_itemid('filemanager_'.$field); + $draftid_editor = file_get_submitted_draft_itemid($field.'_filemanager'); file_prepare_draft_area($draftid_editor, $contextid, $filearea, $data->id, $options['subdirs']); - $data->{'filemanager_'.$field} = $draftid_editor; + $data->{$field.'_filemanager'} = $draftid_editor; return $data; } @@ -252,11 +252,11 @@ function file_postupdate_standard_filemanager($data, $field, array $options, $co $options['maxbytes'] = 0; // unlimited } - if (empty($data->{'filemanager_'.$field})) { + if (empty($data->{$field.'_filemanager'})) { $data->$field = ''; } else { - file_save_draft_area_files($data->{'filemanager_'.$field}, $context->id, $filearea, $data->id, $options); + file_save_draft_area_files($data->{$field.'_filemanager'}, $context->id, $filearea, $data->id, $options); $fs = get_file_storage(); if ($fs->get_area_files($context->id, $filearea, $itemid)) { @@ -277,7 +277,7 @@ function file_get_unused_draft_itemid() { global $DB, $USER; if (isguestuser() or !isloggedin()) { - // guests and not-logged-in users can not be allowed to upload anything! + // guests and not-logged-in users can not be allowed to upload anything!!!!!! print_error('noguest'); } diff --git a/mod/glossary/edit.php b/mod/glossary/edit.php index ac8c73b3df..22b4c80c72 100644 --- a/mod/glossary/edit.php +++ b/mod/glossary/edit.php @@ -27,8 +27,6 @@ if (!$glossary = $DB->get_record('glossary', array('id'=>$cm->instance))) { print_error('invalidid', 'glossary'); } -$mform = new mod_glossary_entry_form(null, compact('cm', 'glossary')); - if ($id) { // if entry is specified if (!$entry = $DB->get_record('glossary_entries', array('id'=>$id, 'glossaryid'=>$glossary->id))) { print_error('invalidentry'); @@ -69,9 +67,9 @@ $entry = file_prepare_standard_filemanager($entry, 'attachment', $attachmentopti $entry->cmid = $cm->id; -// set form initial data -$mform->set_data($entry); - +// create form and set initial data +$mform = new mod_glossary_entry_form(null, array('current'=>$entry, 'cm'=>$cm, 'glossary'=>$glossary, + 'definitionoptions'=>$definitionoptions, 'attachmentoptions'=>$attachmentoptions)); if ($mform->is_cancelled()){ if ($id){ diff --git a/mod/glossary/edit_form.php b/mod/glossary/edit_form.php index 4be22c5914..2ede126b13 100644 --- a/mod/glossary/edit_form.php +++ b/mod/glossary/edit_form.php @@ -6,9 +6,13 @@ class mod_glossary_entry_form extends moodleform { function definition() { global $CFG, $DB; - $mform = $this->_form; - $glossary = $this->_customdata['glossary']; - $cm = $this->_customdata['cm']; + $mform = $this->_form; + + $currententry = $this->_customdata['current']; + $glossary = $this->_customdata['glossary']; + $cm = $this->_customdata['cm']; + $definitionoptions = $this->_customdata['definitionoptions']; + $attachmentoptions = $this->_customdata['attachmentoptions']; //------------------------------------------------------------------------------- $mform->addElement('header', 'general', get_string('general', 'form')); @@ -17,10 +21,9 @@ class mod_glossary_entry_form extends moodleform { $mform->setType('concept', PARAM_TEXT); $mform->addRule('concept', null, 'required', null, 'client'); - $mform->addElement('editor', 'editor_definition', get_string('definition', 'glossary'), array('maxfiles' => EDITOR_UNLIMITED_FILES)); - $mform->setType('editor_definition', PARAM_RAW); - $mform->addRule('editor_definition', get_string('required'), 'required', null, 'client'); - $mform->setHelpButton('editor_definition', array('reading', 'writing', 'questions', 'richtext2'), false, 'editorhelpbutton'); + $mform->addElement('editor', 'definition_editor', get_string('definition', 'glossary'), $definitionoptions); + $mform->setType('definition_editor', PARAM_RAW); + $mform->addRule('definition_editor', get_string('required'), 'required', null, 'client'); if ($categories = $DB->get_records_menu('glossary_categories', array('glossaryid'=>$glossary->id), 'name ASC', 'id, name')){ $categories = array(0 => get_string('notcategorised', 'glossary')) + $categories; @@ -33,14 +36,8 @@ class mod_glossary_entry_form extends moodleform { $mform->setType('aliases', PARAM_TEXT); $mform->setHelpButton('aliases', array('aliases2', strip_tags(get_string('aliases', 'glossary')), 'glossary')); - $mform->addElement('filemanager', 'filemanager_attachment', get_string('attachment', 'glossary'), - array('subdirs'=>0, -// 'maxbytes'=>$glossary->maxbytes, -// 'maxfiles'=>-1, - 'filetypes'=>'*', - 'returnvalue'=>'ref_id' - )); - $mform->setHelpButton('filemanager_attachment', array('attachment2', get_string('attachment', 'glossary'), 'glossary')); + $mform->addElement('filemanager', 'attachment_filemanager', get_string('attachment', 'glossary'), $attachmentoptions); + $mform->setHelpButton('attachment_filemanager', array('attachment2', get_string('attachment', 'glossary'), 'glossary')); if (!$glossary->usedynalink) { $mform->addElement('hidden', 'usedynalink', $CFG->glossary_linkentries); @@ -71,6 +68,9 @@ class mod_glossary_entry_form extends moodleform { //------------------------------------------------------------------------------- $this->add_action_buttons(); + +//------------------------------------------------------------------------------- + $this->set_data($currententry); } function validation($data, $files) {