]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-19002 new simplified file api file limits; docs are still not finished
authorskodak <skodak>
Wed, 29 Apr 2009 07:52:35 +0000 (07:52 +0000)
committerskodak <skodak>
Wed, 29 Apr 2009 07:52:35 +0000 (07:52 +0000)
lib/filelib.php
mod/glossary/edit.php
mod/glossary/edit_form.php

index d06deadc2b696cae9fb298180b561a06d64a91ec..f4acc0f13f51c4987651b5ba72c2c3757f500aff 100644 (file)
@@ -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');
     }
 
index ac8c73b3df694892ea50650e0b38ea5574256fa2..22b4c80c720ec07e9a30ebe65f8f24d1e61f2143 100644 (file)
@@ -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){
index 4be22c591498f660d3c5fba12a6ef4acd4dde0e9..2ede126b138b901fec1d1864a54041957d58b578 100644 (file)
@@ -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) {