Skip to content

Commit bc2d091

Browse files
committed
improve settings elements
1 parent 346fe3b commit bc2d091

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

Diff for: db/upgrade.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ function xmldb_moodleoverflow_upgrade($oldversion) {
314314
if (!$dbman->field_exists($table, $field)) {
315315
$dbman->add_field($table, $field);
316316
}
317-
upgrade_mod_savepoint(true, 2024061700, 'moodleoverflow');
317+
upgrade_mod_savepoint(true, 2025031200, 'moodleoverflow');
318318
}
319319

320320
return true;

Diff for: lang/en/moodleoverflow.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -172,18 +172,21 @@
172172
$string['invalidpostid'] = 'Invalid post ID - {$a}';
173173
$string['invalidratingid'] = 'The submitted rating is neither an upvote nor a downvote.';
174174
$string['jump_to_next_post_needing_review'] = 'Jump to next post needing to be reviewed.';
175-
$string['la_endtime'] = 'End time students can answer';
175+
$string['la_endtime'] = 'Time at which students can no longer answer';
176176
$string['la_endtime_help'] = 'Students can not answer to qustions after the set up date';
177-
$string['la_starttime'] = 'Start time students can answer';
177+
$string['la_endtime_ruleerror'] = 'End time must be in the future';
178+
$string['la_sequence_error'] = 'The end time must be after the start time';
179+
$string['la_starttime'] = 'Time at which students can start to answer';
178180
$string['la_starttime_help'] = 'Students can not answer to questions until the set up date';
181+
$string['la_starttime_ruleerror'] = 'Start time must be in the future';
179182
$string['lastpost'] = 'Last post';
180183
$string['limitedanswer_helpicon_teacher'] = 'This can be changed in the settings of the Moodleoverflow.';
181184
$string['limitedanswer_info_endtime'] = 'Posts can not be answered after {$a->limitedanswerdate}.';
182185
$string['limitedanswer_info_start'] = 'This Moodleoverflow is in a limited answer mode.';
183186
$string['limitedanswer_info_starttime'] = 'Posts can not be answered until {$a->limitedanswerdate}.';
184187
$string['limitedanswerheading'] = 'Limited Answer Mode';
185188
$string['limitedanswerwarning_answers'] = 'There are already answered posts in this Moodleoverflow.';
186-
$string['limitedanswerwarning_conclusion'] = 'Activating or changing limited answer mode might confuse users.';
189+
$string['limitedanswerwarning_conclusion'] = 'You can only set a time until students are able to answer';
187190
$string['mailindexlink'] = 'Change your forum preferences: {$a}';
188191
$string['manydiscussions'] = 'Discussions per page';
189192
$string['markallread'] = 'Mark all posts in this discussion as read';

Diff for: mod_form.php

+41-4
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,10 @@ public function definition() {
232232
// Limited answer options.
233233
$mform->addElement('header', 'limitedanswerheading', get_string('limitedanswerheading', 'moodleoverflow'));
234234

235+
$answersfound = false;
235236
if (!empty($this->current->id)) {
236237

237238
$limiteddate = $DB->get_record('moodleoverflow', ['id' => $this->current->id], 'la_starttime, la_endtime');
238-
239239
// Check if limitedanswermode was already set up and place a warning in case the starttime has already expired ...
240240
// ... or the endtime has already expired.
241241

@@ -247,23 +247,32 @@ public function definition() {
247247
AND discuss.moodleoverflow = ' . $this->current->id . ';';
248248
$answerpostscount = $DB->get_records_sql($sql);
249249
$answerpostscount = $answerpostscount[array_key_first($answerpostscount)]->answerposts;
250-
251-
if ($answerpostscount > 0) {
250+
$answersfound = $answerpostscount > 0;
251+
if ($answersfound) {
252252
$warningstring = get_string('limitedanswerwarning_answers', 'moodleoverflow');
253253
$warningstring .= '<br>' . get_string('limitedanswerwarning_conclusion', 'moodleoverflow');
254254
$htmlwarning = html_writer::div($warningstring, 'alert alert-warning', ['role' => 'alert']);
255255
$mform->addElement('html', $htmlwarning);
256256
}
257257
}
258258

259-
// Limited answer settings.
259+
// Limited answer setting elements..
260+
$mform->addElement('hidden', 'la_answersfound', $answersfound);
261+
$mform->setType('la_answersfound', PARAM_BOOL);
260262
$mform->addElement('date_time_selector', 'la_starttime', get_string('la_starttime', 'moodleoverflow'),
261263
['optional' => true]);
264+
//$mform->setType('la_starttime', PARAM_INT);
262265
$mform->addHelpButton('la_starttime', 'la_starttime', 'moodleoverflow');
266+
$mform->disabledIf('la_starttime', 'la_answersfound', 'eq', true);
267+
263268
$mform->addElement('date_time_selector', 'la_endtime', get_string('la_endtime', 'moodleoverflow'),
264269
['optional' => true]);
270+
//$mform->setType('la_endtime', PARAM_INT);
265271
$mform->addHelpButton('la_endtime', 'la_endtime', 'moodleoverflow');
266272

273+
$mform->addElement('hidden', 'la_error');
274+
$mform->setType('la_error', PARAM_TEXT);
275+
267276
// Add standard elements, common to all modules.
268277
$this->standard_coursemodule_elements();
269278

@@ -284,4 +293,32 @@ public function data_postprocessing($data) {
284293
$data->coursewidereputation = false;
285294
}
286295
}
296+
297+
public function validation($data, $files) {
298+
$errors = parent::validation($data, $files);
299+
300+
// Validate that the limited answer settings.
301+
$currenttime = time();
302+
$isstarttime = !empty($data['la_starttime']);
303+
$isendtime = !empty($data['la_endtime']);
304+
305+
if ($isstarttime && $data['la_starttime'] < $currenttime) {
306+
$errors['la_starttime'] = get_string('la_starttime_ruleerror', 'moodleoverflow');
307+
}
308+
if ($isendtime) {
309+
if ($data['la_endtime'] < $currenttime) {
310+
$errors['la_endtime'] = get_string('la_endtime_ruleerror', 'moodleoverflow');
311+
}
312+
313+
if ($isstarttime && $data['la_endtime'] <= $data['la_starttime']) {
314+
if (isset($errors['la_endtime'])) {
315+
$errors['la_endtime'] .= '<br>' . get_string('la_sequence_error', 'moodleoverflow');
316+
} else {
317+
$errors['la_endtime'] = get_string('la_sequence_error', 'moodleoverflow');
318+
}
319+
}
320+
}
321+
322+
return $errors;
323+
}
287324
}

0 commit comments

Comments
 (0)