forked from totara/facetoface-2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
customfield_form.php
62 lines (46 loc) · 2.63 KB
/
customfield_form.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
require_once "$CFG->dirroot/lib/formslib.php";
require_once "$CFG->dirroot/mod/facetoface/lib.php";
class mod_facetoface_customfield_form extends moodleform {
function definition()
{
$mform =& $this->_form;
$mform->addElement('header', 'general', get_string('general', 'form'));
$mform->addElement('hidden', 'id', $this->_customdata['id']);
$mform->addElement('text', 'name', get_string('name'), 'maxlength="255" size="50"');
$mform->addRule('name', null, 'required', null, 'client');
$mform->setType('name', PARAM_MULTILANG);
$mform->addElement('text', 'shortname', get_string('shortname'), 'maxlength="255" size="25"');
$mform->addRule('shortname', null, 'required', null, 'client');
$mform->setType('shortname', PARAM_ALPHANUM);
$options = array(CUSTOMFIELD_TYPE_TEXT => get_string('field:text', 'facetoface'),
CUSTOMFIELD_TYPE_SELECT => get_string('field:select', 'facetoface'),
CUSTOMFIELD_TYPE_MULTISELECT => get_string('field:multiselect', 'facetoface'),
);
$mform->addElement('select', 'type', get_string('setting:type', 'facetoface'), $options);
$mform->addRule('type', null, 'required', null, 'client');
$mform->setDefault('type', 0);
$mform->addElement('text', 'defaultvalue', get_string('setting:defaultvalue', 'facetoface'), 'maxlength="255" size="30"');
$mform->setType('defaultvalue', PARAM_MULTILANG);
$mform->addElement('textarea', 'possiblevalues', get_string('setting:possiblevalues', 'facetoface'), 'rows="5" cols="30"');
$mform->setType('possiblevalues', PARAM_MULTILANG);
$mform->disabledIf('possiblevalues', 'type', 'eq', 0);
$mform->addElement('checkbox', 'required', get_string('required'));
$mform->setDefault('required', false);
$mform->addElement('checkbox', 'isfilter', get_string('setting:isfilter', 'facetoface'));
$mform->setDefault('isfilter', false);
$mform->addElement('checkbox', 'showinsummary', get_string('setting:showinsummary', 'facetoface'));
$mform->setDefault('showinsummary', true);
$this->add_action_buttons();
}
function validation($data, $files) {
global $DB;
$errors = array();
$where = "id <> ? AND shortname = ?";
$params = array($data['id'], $data['shortname']);
if ($DB->record_exists_select('facetoface_session_field', $where, $params)) {
$errors['shortname']= get_string('error:shortnametaken', 'facetoface');
}
return $errors;
}
}