Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * This file contains the form for importing a framework from a file.
19
 *
20
 * @package   tool_lpimportcsv
21
 * @copyright 2015 Damyon Wiese
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace tool_lpimportcsv\form;
26
 
27
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
28
 
29
use moodleform;
30
use core_competency\api;
31
use core_text;
32
use csv_import_reader;
33
 
34
require_once($CFG->libdir.'/formslib.php');
35
 
36
/**
37
 * Import Competency framework form.
38
 *
39
 * @package   tool_lpimportcsv
40
 * @copyright 2015 Damyon Wiese
41
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
42
 */
43
class import extends moodleform {
44
 
45
    /**
46
     * Define the form - called by parent constructor
47
     */
48
    public function definition() {
49
        global $CFG;
50
        require_once($CFG->libdir . '/csvlib.class.php');
51
 
52
        $mform = $this->_form;
53
        $element = $mform->createElement('filepicker', 'importfile', get_string('importfile', 'tool_lpimportcsv'));
54
        $mform->addElement($element);
55
        $mform->addHelpButton('importfile', 'importfile', 'tool_lpimportcsv');
56
        $mform->addRule('importfile', null, 'required');
57
        $mform->addElement('hidden', 'confirm', 0);
58
        $mform->setType('confirm', PARAM_BOOL);
59
 
60
        $choices = csv_import_reader::get_delimiter_list();
61
        $mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'tool_lpimportcsv'), $choices);
62
        if (array_key_exists('cfg', $choices)) {
63
            $mform->setDefault('delimiter_name', 'cfg');
64
        } else if (get_string('listsep', 'langconfig') == ';') {
65
            $mform->setDefault('delimiter_name', 'semicolon');
66
        } else {
67
            $mform->setDefault('delimiter_name', 'comma');
68
        }
69
 
70
        $choices = core_text::get_encodings();
71
        $mform->addElement('select', 'encoding', get_string('encoding', 'tool_lpimportcsv'), $choices);
72
        $mform->setDefault('encoding', 'UTF-8');
73
 
74
        $this->add_action_buttons(false, get_string('import', 'tool_lpimportcsv'));
75
    }
76
 
77
    /**
78
     * Display an error on the import form.
79
     * @param string $msg
80
     */
81
    public function set_import_error($msg) {
82
        $mform = $this->_form;
83
 
84
        $mform->setElementError('importfile', $msg);
85
    }
86
 
87
}