forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefine.class.php
41 lines (29 loc) · 1.36 KB
/
define.class.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
<?php
class profile_define_menu extends profile_define_base {
function define_form_specific($form) {
/// Param 1 for menu type contains the options
$form->addElement('textarea', 'param1', get_string('profilemenuoptions', 'admin'), array('rows' => 6, 'cols' => 40));
$form->setType('param1', PARAM_TEXT);
/// Default data
$form->addElement('text', 'defaultdata', get_string('profiledefaultdata', 'admin'), 'size="50"');
$form->setType('defaultdata', PARAM_TEXT);
}
function define_validate_specific($data, $files) {
$err = array();
$data->param1 = str_replace("\r", '', $data->param1);
/// Check that we have at least 2 options
if (($options = explode("\n", $data->param1)) === false) {
$err['param1'] = get_string('profilemenunooptions', 'admin');
} elseif (count($options) < 2) {
$err['param1'] = get_string('profilemenutoofewoptions', 'admin');
/// Check the default data exists in the options
} elseif (!empty($data->defaultdata) and !in_array($data->defaultdata, $options)) {
$err['defaultdata'] = get_string('profilemenudefaultnotinoptions', 'admin');
}
return $err;
}
function define_save_preprocess($data) {
$data->param1 = str_replace("\r", '', $data->param1);
return $data;
}
}