Skip to content

Commit 1080666

Browse files
authored
Merge pull request #97 from learnweb/fix/allow-anonymous-setting
Add functioning admin switch for allowing anonymous forums.
2 parents f001a53 + eaaa47f commit 1080666

File tree

5 files changed

+82
-6
lines changed

5 files changed

+82
-6
lines changed

lang/en/moodleoverflow.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,9 @@
412412
$string['anonymous:everything'] = 'Questioners and answerers (Irreversible!)';
413413
$string['anonym_you'] = 'Anonymous (You)';
414414
$string['allowanonymous'] = 'Allow anonymous';
415-
$string['allowanonymous_desc'] = 'Allow teachers to put moodleoverflow forums into anonymous question or full anonymous mode';
415+
$string['allowanonymous_desc'] = 'Allow teachers to put moodleoverflow forums into anonymous question or full anonymous mode. Once enabled, anonymous forums will stay anonymous, even when this setting is disabled. If you really want to, you can reset anonymity in all forums <a href="{$a}">here</a>.';
416416
$string['questioner'] = 'Questioner';
417417
$string['answerer'] = 'Answerer #{$a}';
418418
$string['desc:only_questions'] = 'The name of questioners will not be displayed in their question and comments.';
419419
$string['desc:anonymous'] = 'No names will be displayed.';
420+
$string['resetanonymous_warning'] = 'Are you sure? If you are in production, <b>this is most certainly a bad decision</b> because your students and teachers posted their questions and answers, believing they would remain anonymous. <br><br><b>{$a->fullanoncount}</b> forums are currently fully anonymized, and in <b>{$a->questionanoncount}</b> additional forums the questioners are anonymized.<br><br><b>In all these forums, the real names of posters will be displayed again, even in already existing posts!</b>There is no way of reverting those changes!</b>';

mod_form.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,11 @@ public function definition() {
8282
$possiblesettings[anonymous::NOT_ANONYMOUS] = get_string('no');
8383
}
8484

85-
$mform->addElement('select', 'anonymous', get_string('anonymous', 'moodleoverflow'), $possiblesettings);
86-
$mform->addHelpButton('anonymous', 'anonymous', 'moodleoverflow');
87-
$mform->setDefault('anonymous', anonymous::NOT_ANONYMOUS);
85+
if (get_config('moodleoverflow', 'allowanonymous') == '1') {
86+
$mform->addElement('select', 'anonymous', get_string('anonymous', 'moodleoverflow'), $possiblesettings);
87+
$mform->addHelpButton('anonymous', 'anonymous', 'moodleoverflow');
88+
$mform->setDefault('anonymous', anonymous::NOT_ANONYMOUS);
89+
}
8890

8991
// Attachments.
9092
$mform->addElement('header', 'attachmentshdr', get_string('attachments', 'moodleoverflow'));
@@ -220,7 +222,7 @@ public function definition() {
220222
* @param array $data data from the form.
221223
*/
222224
public function data_postprocessing($data) {
223-
if ($data->anonymous != anonymous::NOT_ANONYMOUS) {
225+
if (isset($data->anonymous) && $data->anonymous != anonymous::NOT_ANONYMOUS) {
224226
$data->coursewidereputation = false;
225227
}
226228
}

resetanonymous.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
* Resets all forums anonymity level, if the admin really wants to.
19+
*
20+
* @package mod_moodleoverflow
21+
* @copyright 2022 Justus Dieckmann WWU
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
25+
use mod_moodleoverflow\anonymous;
26+
27+
require_once('../../config.php');
28+
29+
global $DB, $PAGE, $OUTPUT;
30+
31+
$PAGE->set_url('/mod/moodleoverflow/resetanonymous.php');
32+
$PAGE->set_context(context_system::instance());
33+
34+
require_admin();
35+
36+
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
37+
38+
$returnurl = new moodle_url('/admin/settings.php?section=modsettingmoodleoverflow');
39+
40+
if ($confirmed !== 1) {
41+
$a = new stdClass();
42+
$a->fullanoncount = $DB->count_records('moodleoverflow',
43+
['anonymous' => anonymous::EVERYTHING_ANONYMOUS]);
44+
$a->questionanoncount = $DB->count_records('moodleoverflow',
45+
['anonymous' => anonymous::QUESTION_ANONYMOUS]);
46+
echo $OUTPUT->header();
47+
echo html_writer::div(
48+
$OUTPUT->confirm(get_string('resetanonymous_warning', 'moodleoverflow', $a),
49+
new moodle_url($PAGE->url, ['confirmed' => true, 'sesskey' => sesskey()]), $returnurl),
50+
'mod_moodleoverflow-hack-primary-to-danger-btn'
51+
);
52+
echo $OUTPUT->footer();
53+
die();
54+
}
55+
56+
require_sesskey();
57+
58+
$DB->execute('UPDATE {moodleoverflow} SET anonymous = ?', [anonymous::NOT_ANONYMOUS]);
59+
60+
redirect($returnurl);

settings.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,11 @@
7777
$settings->add(new admin_setting_configselect('moodleoverflow/cleanreadtime', get_string('cleanreadtime', 'moodleoverflow'),
7878
get_string('configcleanreadtime', 'moodleoverflow'), 2, $options));
7979

80+
$url = new moodle_url('/mod/moodleoverflow/resetanonymous.php');
81+
8082
$settings->add(new admin_setting_configcheckbox('moodleoverflow/allowanonymous',
8183
get_string('allowanonymous', 'moodleoverflow'),
82-
get_string('allowanonymous_desc', 'moodleoverflow'),
84+
get_string('allowanonymous_desc', 'moodleoverflow', $url->out(false)),
8385
1
8486
));
8587

styles.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,17 @@ span.unread {
520520
text-align: right;
521521
}
522522

523+
.mod_moodleoverflow-hack-primary-to-danger-btn .btn-primary {
524+
background-color: #a90000;
525+
border-color: #a90000;
526+
}
527+
528+
.mod_moodleoverflow-hack-primary-to-danger-btn .btn-primary:hover,
529+
.mod_moodleoverflow-hack-primary-to-danger-btn .btn-primary:focus {
530+
background-color: #900000;
531+
border-color: #900000;
532+
}
533+
523534
@media (max-width: 600px) {
524535
.hide-600 {
525536
display: none;

0 commit comments

Comments
 (0)