-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathedit_form.php
169 lines (153 loc) · 8.55 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Completion Progress block configuration form definition
*
* @package block_completion_progress
* @copyright 2016 Michael de Raadt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
use block_completion_progress\completion_progress;
use block_completion_progress\defaults;
require_once($CFG->dirroot.'/blocks/completion_progress/block_completion_progress.php');
/**
* Completion Progress block config form class
*
* @copyright 2016 Michael de Raadt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_completion_progress_edit_form extends block_edit_form {
/**
* Settings specific to this block.
*
* @param moodleform $mform
*/
protected function specific_definition($mform) {
global $COURSE, $OUTPUT;
$progress = (new completion_progress($COURSE))->for_block_instance($this->block->instance, false);
$activities = $progress->get_activities(completion_progress::ORDERBY_COURSE);
// The My home version is not configurable.
if (block_completion_progress::on_site_page()) {
return;
}
// Start block specific section in config form.
$mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
// Control order of items in Progress Bar.
$expectedbystring = get_string('completionexpected', 'completion');
$options = [
completion_progress::ORDERBY_TIME => get_string('config_orderby_due_time',
'block_completion_progress', $expectedbystring),
completion_progress::ORDERBY_COURSE => get_string('config_orderby_course_order',
'block_completion_progress'),
];
$label = get_string('config_orderby', 'block_completion_progress');
$mform->addElement('select', 'config_orderby', $label, $options);
$mform->setDefault('config_orderby', defaults::ORDERBY);
$mform->addHelpButton('config_orderby', 'how_ordering_works', 'block_completion_progress');
// Check if all elements have an expect completion by time set.
$allwithexpected = true;
foreach ($activities as $activity) {
if ($activity->expected == 0) {
$allwithexpected = false;
break;
}
}
if (!$allwithexpected) {
$warningstring = get_string('not_all_expected_set', 'block_completion_progress', $expectedbystring);
$expectedwarning = html_writer::tag('div', $warningstring, ['class' => 'warning']);
$mform->addElement('static', $expectedwarning, '', $expectedwarning);
}
// Control how long bars wrap/scroll.
$options = [
'squeeze' => get_string('config_squeeze', 'block_completion_progress'),
'scroll' => get_string('config_scroll', 'block_completion_progress'),
'wrap' => get_string('config_wrap', 'block_completion_progress'),
];
$label = get_string('config_longbars', 'block_completion_progress');
$mform->addElement('select', 'config_longbars', $label, $options);
$defaultlongbars = get_config('block_completion_progress', 'defaultlongbars') ?: defaults::LONGBARS;
$mform->setDefault('config_longbars', $defaultlongbars);
$mform->addHelpButton('config_longbars', 'how_longbars_works', 'block_completion_progress');
// Allow icons to be turned on/off on the block.
if (get_config('block_completion_progress', 'forceiconsinbar') !== "1") {
$mform->addElement('selectyesno', 'config_progressBarIcons',
get_string('config_icons', 'block_completion_progress').' '.
$OUTPUT->pix_icon('tick', '', 'block_completion_progress', ['class' => 'iconOnConfig']).
$OUTPUT->pix_icon('cross', '', 'block_completion_progress', ['class' => 'iconOnConfig']));
$mform->setDefault('config_progressBarIcons', defaults::PROGRESSBARICONS);
$mform->addHelpButton('config_progressBarIcons', 'why_use_icons', 'block_completion_progress');
}
// Allow progress percentage to be turned on for students.
$mform->addElement('selectyesno', 'config_showpercentage',
get_string('config_percentage', 'block_completion_progress'));
$mform->setDefault('config_showpercentage', defaults::SHOWPERCENTAGE);
$mform->addHelpButton('config_showpercentage', 'why_show_precentage', 'block_completion_progress');
// Allow the block to be visible to a single group or grouping.
$groups = groups_get_all_groups($COURSE->id);
$groupings = groups_get_all_groupings($COURSE->id);
if (!empty($groups) || !empty($groupings)) {
$options = [];
$options['0'] = get_string('allparticipants');
foreach ($groups as $group) {
$options['group-' . $group->id] = format_string($group->name);
}
foreach ($groupings as $grouping) {
$options['grouping-' . $grouping->id] = format_string($grouping->name);
}
$label = get_string('config_group', 'block_completion_progress');
$mform->addElement('select', 'config_group', $label, $options);
$mform->setDefault('config_group', '0');
$mform->addHelpButton('config_group', 'how_group_works', 'block_completion_progress');
$mform->setAdvanced('config_group', true);
}
// Set block instance title.
$mform->addElement('text', 'config_progressTitle',
get_string('config_title', 'block_completion_progress'));
$mform->setDefault('config_progressTitle', '');
$mform->setType('config_progressTitle', PARAM_TEXT);
$mform->addHelpButton('config_progressTitle', 'why_set_the_title', 'block_completion_progress');
$mform->setAdvanced('config_progressTitle', true);
// Control which activities are included in the bar.
$options = [
'activitycompletion' => get_string('config_activitycompletion', 'block_completion_progress'),
'selectedactivities' => get_string('config_selectedactivities', 'block_completion_progress'),
];
$label = get_string('config_activitiesincluded', 'block_completion_progress');
$mform->addElement('select', 'config_activitiesincluded', $label, $options);
$mform->setDefault('config_activitiesincluded', defaults::ACTIVITIESINCLUDED);
$mform->addHelpButton('config_activitiesincluded', 'how_activitiesincluded_works', 'block_completion_progress');
$mform->setAdvanced('config_activitiesincluded', true);
// Check that there are activities to monitor.
if (empty($activities)) {
$warningstring = get_string('no_activities_config_message', 'block_completion_progress');
$activitieswarning = html_writer::tag('div', $warningstring, ['class' => 'warning']);
$mform->addElement('static', '', '', $activitieswarning);
} else {
$options = [];
foreach ($activities as $activity) {
$options[$activity->type.'-'.$activity->instance] = format_string($activity->name);
}
$label = get_string('config_selectactivities', 'block_completion_progress');
$mform->addElement('select', 'config_selectactivities', $label, $options);
$mform->getElement('config_selectactivities')->setMultiple(true);
$mform->getElement('config_selectactivities')->setSize(count($activities));
$mform->setAdvanced('config_selectactivities', true);
$mform->disabledif('config_selectactivities', 'config_activitiesincluded', 'neq', 'selectedactivities');
$mform->addHelpButton('config_selectactivities', 'how_selectactivities_works', 'block_completion_progress');
}
}
}