Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lang/en/moodleoverflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,9 @@
$string['anonymous:everything'] = 'Questioners and answerers (Irreversible!)';
$string['anonym_you'] = 'Anonymous (You)';
$string['allowanonymous'] = 'Allow anonymous';
$string['allowanonymous_desc'] = 'Allow teachers to put moodleoverflow forums into anonymous question or full anonymous mode';
$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>.';
$string['questioner'] = 'Questioner';
$string['answerer'] = 'Answerer #{$a}';
$string['desc:only_questions'] = 'The name of questioners will not be displayed in their question and comments.';
$string['desc:anonymous'] = 'No names will be displayed.';
$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>';
10 changes: 6 additions & 4 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ public function definition() {
$possiblesettings[anonymous::NOT_ANONYMOUS] = get_string('no');
}

$mform->addElement('select', 'anonymous', get_string('anonymous', 'moodleoverflow'), $possiblesettings);
$mform->addHelpButton('anonymous', 'anonymous', 'moodleoverflow');
$mform->setDefault('anonymous', anonymous::NOT_ANONYMOUS);
if (get_config('moodleoverflow', 'allowanonymous') == '1') {
$mform->addElement('select', 'anonymous', get_string('anonymous', 'moodleoverflow'), $possiblesettings);
$mform->addHelpButton('anonymous', 'anonymous', 'moodleoverflow');
$mform->setDefault('anonymous', anonymous::NOT_ANONYMOUS);
}

// Attachments.
$mform->addElement('header', 'attachmentshdr', get_string('attachments', 'moodleoverflow'));
Expand Down Expand Up @@ -220,7 +222,7 @@ public function definition() {
* @param array $data data from the form.
*/
public function data_postprocessing($data) {
if ($data->anonymous != anonymous::NOT_ANONYMOUS) {
if (isset($data->anonymous) && $data->anonymous != anonymous::NOT_ANONYMOUS) {
$data->coursewidereputation = false;
}
}
Expand Down
60 changes: 60 additions & 0 deletions resetanonymous.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?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/>.

/**
* Resets all forums anonymity level, if the admin really wants to.
*
* @package mod_moodleoverflow
* @copyright 2022 Justus Dieckmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use mod_moodleoverflow\anonymous;

require_once('../../config.php');

global $DB, $PAGE, $OUTPUT;

$PAGE->set_url('/mod/moodleoverflow/resetanonymous.php');
$PAGE->set_context(context_system::instance());

require_admin();

$confirmed = optional_param('confirmed', false, PARAM_BOOL);

$returnurl = new moodle_url('/admin/settings.php?section=modsettingmoodleoverflow');

if ($confirmed !== 1) {
$a = new stdClass();
$a->fullanoncount = $DB->count_records('moodleoverflow',
['anonymous' => anonymous::EVERYTHING_ANONYMOUS]);
$a->questionanoncount = $DB->count_records('moodleoverflow',
['anonymous' => anonymous::QUESTION_ANONYMOUS]);
echo $OUTPUT->header();
echo html_writer::div(
$OUTPUT->confirm(get_string('resetanonymous_warning', 'moodleoverflow', $a),
new moodle_url($PAGE->url, ['confirmed' => true, 'sesskey' => sesskey()]), $returnurl),
'mod_moodleoverflow-hack-primary-to-danger-btn'
);
echo $OUTPUT->footer();
die();
}

require_sesskey();

$DB->execute('UPDATE {moodleoverflow} SET anonymous = ?', [anonymous::NOT_ANONYMOUS]);

redirect($returnurl);
4 changes: 3 additions & 1 deletion settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@
$settings->add(new admin_setting_configselect('moodleoverflow/cleanreadtime', get_string('cleanreadtime', 'moodleoverflow'),
get_string('configcleanreadtime', 'moodleoverflow'), 2, $options));

$url = new moodle_url('/mod/moodleoverflow/resetanonymous.php');

$settings->add(new admin_setting_configcheckbox('moodleoverflow/allowanonymous',
get_string('allowanonymous', 'moodleoverflow'),
get_string('allowanonymous_desc', 'moodleoverflow'),
get_string('allowanonymous_desc', 'moodleoverflow', $url->out(false)),
1
));

Expand Down
11 changes: 11 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,17 @@ span.unread {
text-align: right;
}

.mod_moodleoverflow-hack-primary-to-danger-btn .btn-primary {
background-color: #a90000;
border-color: #a90000;
}

.mod_moodleoverflow-hack-primary-to-danger-btn .btn-primary:hover,
.mod_moodleoverflow-hack-primary-to-danger-btn .btn-primary:focus {
background-color: #900000;
border-color: #900000;
}

@media (max-width: 600px) {
.hide-600 {
display: none;
Expand Down