Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/lesson/import_form.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00027 defined('MOODLE_INTERNAL') || die();
00028 
00034 class lesson_import_form extends moodleform {
00035 
00036     public function definition() {
00037 
00038         $mform = $this->_form;
00039 
00040         $mform->addElement('hidden', 'id');
00041         $mform->setType('id', PARAM_INT);
00042 
00043         $mform->addElement('hidden', 'pageid');
00044         $mform->setType('pageid', PARAM_INT);
00045 
00046         $mform->addElement('select', 'format', get_string('fileformat', 'lesson'), $this->_customdata['formats']);
00047         $mform->setDefault('format', 'gift');
00048         $mform->setType('format', 'text');
00049         $mform->addRule('format', null, 'required');
00050 
00051         //Using filemanager as filepicker
00052         $mform->addElement('filepicker', 'questionfile', get_string('upload'));
00053         $mform->addRule('questionfile', null, 'required', null, 'client');
00054 
00055         $this->add_action_buttons(null, get_string("import"));
00056     }
00057 
00064     protected function validate_uploaded_file($data, $errors) {
00065         global $CFG;
00066 
00067         if (empty($data['questionfile'])) {
00068             $errors['questionfile'] = get_string('required');
00069             return $errors;
00070         }
00071 
00072         $files = $this->get_draft_files('questionfile');
00073         if (count($files) < 1) {
00074             $errors['questionfile'] = get_string('required');
00075             return $errors;
00076         }
00077 
00078         $formatfile = $CFG->dirroot.'/question/format/'.$data['format'].'/format.php';
00079         if (!is_readable($formatfile)) {
00080             throw new moodle_exception('formatnotfound', 'lesson', '', $data['format']);
00081         }
00082 
00083         require_once($formatfile);
00084 
00085         $classname = 'qformat_' . $data['format'];
00086         $qformat = new $classname();
00087 
00088         return $errors;
00089     }
00090 
00091     public function validation($data, $files) {
00092         $errors = parent::validation($data, $files);
00093         $errors = $this->validate_uploaded_file($data, $errors);
00094         return $errors;
00095     }
00096 }
 All Data Structures Namespaces Files Functions Variables Enumerations