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 |
/**
|
|
|
19 |
* Completion Progress block configuration form definition
|
|
|
20 |
*
|
|
|
21 |
* @package block_completion_progress
|
|
|
22 |
* @copyright 2016 Michael de Raadt
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
defined('MOODLE_INTERNAL') || die;
|
|
|
27 |
|
|
|
28 |
use block_completion_progress\completion_progress;
|
|
|
29 |
use block_completion_progress\defaults;
|
|
|
30 |
|
|
|
31 |
require_once($CFG->dirroot.'/blocks/completion_progress/block_completion_progress.php');
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* Completion Progress block config form class
|
|
|
35 |
*
|
|
|
36 |
* @copyright 2016 Michael de Raadt
|
|
|
37 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
38 |
*/
|
|
|
39 |
class block_completion_progress_edit_form extends block_edit_form {
|
|
|
40 |
/**
|
|
|
41 |
* Settings specific to this block.
|
|
|
42 |
*
|
|
|
43 |
* @param moodleform $mform
|
|
|
44 |
*/
|
|
|
45 |
protected function specific_definition($mform) {
|
|
|
46 |
global $COURSE, $OUTPUT;
|
|
|
47 |
$progress = (new completion_progress($COURSE))->for_block_instance($this->block->instance, false);
|
|
|
48 |
$activities = $progress->get_activities(completion_progress::ORDERBY_COURSE);
|
|
|
49 |
|
|
|
50 |
// The My home version is not configurable.
|
|
|
51 |
if (block_completion_progress::on_site_page()) {
|
|
|
52 |
return;
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
// Start block specific section in config form.
|
|
|
56 |
$mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
|
|
|
57 |
|
|
|
58 |
// Control order of items in Progress Bar.
|
|
|
59 |
$expectedbystring = get_string('completionexpected', 'completion');
|
|
|
60 |
$options = array(
|
|
|
61 |
completion_progress::ORDERBY_TIME => get_string('config_orderby_due_time',
|
|
|
62 |
'block_completion_progress', $expectedbystring),
|
|
|
63 |
completion_progress::ORDERBY_COURSE => get_string('config_orderby_course_order',
|
|
|
64 |
'block_completion_progress'),
|
|
|
65 |
);
|
|
|
66 |
$label = get_string('config_orderby', 'block_completion_progress');
|
|
|
67 |
$mform->addElement('select', 'config_orderby', $label, $options);
|
|
|
68 |
$mform->setDefault('config_orderby', defaults::ORDERBY);
|
|
|
69 |
$mform->addHelpButton('config_orderby', 'how_ordering_works', 'block_completion_progress');
|
|
|
70 |
|
|
|
71 |
// Check if all elements have an expect completion by time set.
|
|
|
72 |
$allwithexpected = true;
|
|
|
73 |
foreach ($activities as $activity) {
|
|
|
74 |
if ($activity->expected == 0) {
|
|
|
75 |
$allwithexpected = false;
|
|
|
76 |
break;
|
|
|
77 |
}
|
|
|
78 |
}
|
|
|
79 |
if (!$allwithexpected) {
|
|
|
80 |
$warningstring = get_string('not_all_expected_set', 'block_completion_progress', $expectedbystring);
|
|
|
81 |
$expectedwarning = html_writer::tag('div', $warningstring, array('class' => 'warning'));
|
|
|
82 |
$mform->addElement('static', $expectedwarning, '', $expectedwarning);
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
// Control how long bars wrap/scroll.
|
|
|
86 |
$options = array(
|
|
|
87 |
'squeeze' => get_string('config_squeeze', 'block_completion_progress'),
|
|
|
88 |
'scroll' => get_string('config_scroll', 'block_completion_progress'),
|
|
|
89 |
'wrap' => get_string('config_wrap', 'block_completion_progress'),
|
|
|
90 |
);
|
|
|
91 |
$label = get_string('config_longbars', 'block_completion_progress');
|
|
|
92 |
$mform->addElement('select', 'config_longbars', $label, $options);
|
|
|
93 |
$defaultlongbars = get_config('block_completion_progress', 'defaultlongbars') ?: defaults::LONGBARS;
|
|
|
94 |
$mform->setDefault('config_longbars', $defaultlongbars);
|
|
|
95 |
$mform->addHelpButton('config_longbars', 'how_longbars_works', 'block_completion_progress');
|
|
|
96 |
|
|
|
97 |
// Allow icons to be turned on/off on the block.
|
|
|
98 |
if (get_config('block_completion_progress', 'forceiconsinbar') !== "1") {
|
|
|
99 |
$mform->addElement('selectyesno', 'config_progressBarIcons',
|
|
|
100 |
get_string('config_icons', 'block_completion_progress').' '.
|
|
|
101 |
$OUTPUT->pix_icon('tick', '', 'block_completion_progress', array('class' => 'iconOnConfig')).
|
|
|
102 |
$OUTPUT->pix_icon('cross', '', 'block_completion_progress', array('class' => 'iconOnConfig')));
|
|
|
103 |
$mform->setDefault('config_progressBarIcons', defaults::PROGRESSBARICONS);
|
|
|
104 |
$mform->addHelpButton('config_progressBarIcons', 'why_use_icons', 'block_completion_progress');
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
// Allow progress percentage to be turned on for students.
|
|
|
108 |
$mform->addElement('selectyesno', 'config_showpercentage',
|
|
|
109 |
get_string('config_percentage', 'block_completion_progress'));
|
|
|
110 |
$mform->setDefault('config_showpercentage', defaults::SHOWPERCENTAGE);
|
|
|
111 |
$mform->addHelpButton('config_showpercentage', 'why_show_precentage', 'block_completion_progress');
|
|
|
112 |
|
|
|
113 |
// Allow the block to be visible to a single group or grouping.
|
|
|
114 |
$groups = groups_get_all_groups($COURSE->id);
|
|
|
115 |
$groupings = groups_get_all_groupings($COURSE->id);
|
|
|
116 |
if (!empty($groups) || !empty($groupings)) {
|
|
|
117 |
$options = array();
|
|
|
118 |
$options['0'] = get_string('allparticipants');
|
|
|
119 |
foreach ($groups as $group) {
|
|
|
120 |
$options['group-' . $group->id] = format_string($group->name);
|
|
|
121 |
}
|
|
|
122 |
foreach ($groupings as $grouping) {
|
|
|
123 |
$options['grouping-' . $grouping->id] = format_string($grouping->name);
|
|
|
124 |
}
|
|
|
125 |
$label = get_string('config_group', 'block_completion_progress');
|
|
|
126 |
$mform->addElement('select', 'config_group', $label, $options);
|
|
|
127 |
$mform->setDefault('config_group', '0');
|
|
|
128 |
$mform->addHelpButton('config_group', 'how_group_works', 'block_completion_progress');
|
|
|
129 |
$mform->setAdvanced('config_group', true);
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
// Set block instance title.
|
|
|
133 |
$mform->addElement('text', 'config_progressTitle',
|
|
|
134 |
get_string('config_title', 'block_completion_progress'));
|
|
|
135 |
$mform->setDefault('config_progressTitle', '');
|
|
|
136 |
$mform->setType('config_progressTitle', PARAM_TEXT);
|
|
|
137 |
$mform->addHelpButton('config_progressTitle', 'why_set_the_title', 'block_completion_progress');
|
|
|
138 |
$mform->setAdvanced('config_progressTitle', true);
|
|
|
139 |
|
|
|
140 |
// Control which activities are included in the bar.
|
|
|
141 |
$options = array(
|
|
|
142 |
'activitycompletion' => get_string('config_activitycompletion', 'block_completion_progress'),
|
|
|
143 |
'selectedactivities' => get_string('config_selectedactivities', 'block_completion_progress'),
|
|
|
144 |
);
|
|
|
145 |
$label = get_string('config_activitiesincluded', 'block_completion_progress');
|
|
|
146 |
$mform->addElement('select', 'config_activitiesincluded', $label, $options);
|
|
|
147 |
$mform->setDefault('config_activitiesincluded', defaults::ACTIVITIESINCLUDED);
|
|
|
148 |
$mform->addHelpButton('config_activitiesincluded', 'how_activitiesincluded_works', 'block_completion_progress');
|
|
|
149 |
$mform->setAdvanced('config_activitiesincluded', true);
|
|
|
150 |
|
|
|
151 |
// Check that there are activities to monitor.
|
|
|
152 |
if (empty($activities)) {
|
|
|
153 |
$warningstring = get_string('no_activities_config_message', 'block_completion_progress');
|
|
|
154 |
$activitieswarning = html_writer::tag('div', $warningstring, array('class' => 'warning'));
|
|
|
155 |
$mform->addElement('static', '', '', $activitieswarning);
|
|
|
156 |
} else {
|
|
|
157 |
$options = array();
|
|
|
158 |
foreach ($activities as $activity) {
|
|
|
159 |
$options[$activity->type.'-'.$activity->instance] = format_string($activity->name);
|
|
|
160 |
}
|
|
|
161 |
$label = get_string('config_selectactivities', 'block_completion_progress');
|
|
|
162 |
$mform->addElement('select', 'config_selectactivities', $label, $options);
|
|
|
163 |
$mform->getElement('config_selectactivities')->setMultiple(true);
|
|
|
164 |
$mform->getElement('config_selectactivities')->setSize(count($activities));
|
|
|
165 |
$mform->setAdvanced('config_selectactivities', true);
|
|
|
166 |
$mform->disabledif('config_selectactivities', 'config_activitiesincluded', 'neq', 'selectedactivities');
|
|
|
167 |
$mform->addHelpButton('config_selectactivities', 'how_selectactivities_works', 'block_completion_progress');
|
|
|
168 |
}
|
|
|
169 |
}
|
|
|
170 |
}
|