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
 * Form.
19
 *
20
 * @package    tool_lpmigrate
21
 * @copyright  2016 Frédéric Massart - FMCorz.net
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace tool_lpmigrate\form;
26
defined('MOODLE_INTERNAL') || die();
27
 
28
require_once($CFG->libdir . '/formslib.php');
29
\MoodleQuickForm::registerElementType('framework_autocomplete',
30
    $CFG->dirroot . '/admin/tool/lp/classes/form/framework_autocomplete.php',
31
    '\\tool_lp\\form\\framework_autocomplete');
32
 
33
/**
34
 * Form class.
35
 *
36
 * @package    tool_lpmigrate
37
 * @copyright  2016 Frédéric Massart - FMCorz.net
38
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39
 */
40
class migrate_framework extends \moodleform {
41
 
42
    /** @var context The page context. */
43
    protected $pagecontext;
44
 
45
    /**
46
     * Constructor.
47
     * @param \context $context The page context.
48
     */
49
    public function __construct(\context $context) {
50
        $this->pagecontext = $context;
51
        parent::__construct();
52
    }
53
 
54
    protected function definition() {
55
        $mform = $this->_form;
56
 
57
        $mform->addElement('header', 'hdrcourses', get_string('frameworks', 'tool_lpmigrate'));
58
 
59
        $mform->addElement('framework_autocomplete', 'from', get_string('migratefrom', 'tool_lpmigrate'), array(
60
            'contextid' => $this->pagecontext->id,
61
            'onlyvisible' => '0',
62
        ), 1, 2, 3);
63
        $mform->addRule('from', get_string('required'), 'required', null);
64
        $mform->addHelpButton('from', 'migratefrom', 'tool_lpmigrate');
65
 
66
        $mform->addElement('framework_autocomplete', 'to', get_string('migrateto', 'tool_lpmigrate'), array(
67
            'contextid' => $this->pagecontext->id,
68
            'onlyvisible' => '1',      // We cannot add competencies from hidden frameworks, so it must be visible.
69
        ), 1, 2, 3);
70
        $mform->addRule('to', get_string('required'), 'required', null);
71
        $mform->addHelpButton('to', 'migrateto', 'tool_lpmigrate');
72
 
73
        $mform->addElement('header', 'hdrcourses', get_string('courses'));
74
        $mform->addElement('course', 'allowedcourses', get_string('limittothese', 'tool_lpmigrate'),
75
            array('showhidden' => true, 'multiple' => true));
76
        $mform->addHelpButton('allowedcourses', 'allowedcourses', 'tool_lpmigrate');
77
        $mform->addElement('course', 'disallowedcourses', get_string('excludethese', 'tool_lpmigrate'),
78
            array('showhidden' => true, 'multiple' => true));
79
        $mform->addHelpButton('disallowedcourses', 'disallowedcourses', 'tool_lpmigrate');
80
        $mform->addElement('date_time_selector', 'coursestartdate', get_string('startdatefrom', 'tool_lpmigrate'),
81
            array('optional' => true));
82
        $mform->addHelpButton('coursestartdate', 'coursestartdate', 'tool_lpmigrate');
83
 
84
        $this->add_action_buttons(true, get_string('performmigration', 'tool_lpmigrate'));
85
    }
86
 
87
    public function validation($data, $files) {
88
        $errors = array();
89
 
90
        if ($data['from'] == $data['to']) {
91
            $errors['to'] = get_string('errorcannotmigratetosameframework', 'tool_lpmigrate');
92
 
93
        } else if (!empty($data['from']) && !empty($data['to'])) {
94
            $mapper = new \tool_lpmigrate\framework_mapper($data['from'], $data['to']);
95
            $mapper->automap();
96
            if (!$mapper->has_mappings()) {
97
                $errors['to'] = 'Could not map to any competency in this framework.';
98
            }
99
        }
100
 
101
        return $errors;
102
    }
103
 
104
}