-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_form.php
69 lines (53 loc) · 2.19 KB
/
edit_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
63
64
65
66
<?php
class block_progress_edit_form extends block_edit_form {
protected function specific_definition($mform) {
require_once($base_url.'/srv/www/htdocs/config.php');
// Adds Block settings section
$mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
// Adds block name field.
$mform->addElement('text', 'config_title', get_string('blocktitletext', 'block_progress'));
$mform->setDefault('config_title', 'default value');
$mform->setType('config_title', PARAM_MULTILANG);
//Adds footer field
$options = array('no'=>'No', 'yes'=>'Yes',);
$mform->addElement('select', 'config_footer', get_string('showpoints', 'block_progress'), $options, $attributes);
$mform->setType('config_footer', PARAM_MULTILANG);
//Adds summary mode field
$options = array('teacher'=>get_string('teacher', 'block_progress'), 'tutor'=>get_string('tutor', 'block_progress'),);
$mform->addElement('select', 'config_mode', get_string('summarymode', 'block_progress'), $options, $attributes);
$mform->setType('config_mode', PARAM_MULTILANG);
//Adds default group field.
global $DB;
global $course;
$groups = $DB->get_records_sql('SELECT `name`,`id` FROM {groups} WHERE courseid = '.$course->id.'');
//Converts object array to string array
function objectToArray($d) {
if (is_object($d)) {
// Gets the properties of the given object
// with get_object_vars function
$d = get_object_vars($d);
}
if (is_array($d)) {
/*
* Return array converted to object
* Using __FUNCTION__ (Magic constant)
* for recursive call
*/
return array_map(__FUNCTION__, $d);
}
else {
// Return array
return $d;
}
}
//Converts object array to string array
$groups = objectToArray($groups);
//Builds group select list from $groups array.
foreach ($groups as $key => $row) {
$groupselect[$row['id']] = $row['name'];
}
$groupselect['0']="All";
ksort($groupselect);
$mform->addElement('select', 'config_group', get_string('defaultgroup', 'block_progress'), $groupselect);
}
}