Skip to content

Commit c4b4ff8

Browse files
author
Laur0r
authored
Merge pull request #92 from justusdieckmann/feature/anon-overhaul
Anonymous Feature overhaul
2 parents 152d5ef + d17754a commit c4b4ff8

File tree

15 files changed

+120
-53
lines changed

15 files changed

+120
-53
lines changed

amd/build/functions.min.js

Lines changed: 10 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/build/functions.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/src/functions.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
* Ajax functions for moodleoverflow
1818
*
1919
* @module mod/moodleoverflow
20-
* @package
2120
* @copyright 2017 Tamara Gunkel
2221
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2322
*/

classes/anonymous.php

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ class anonymous {
4949
/**
5050
* Checks if post is anonymous.
5151
*
52-
* @param object $post moodleoverflow post object
52+
* @param object $discussion moodleoverflow discussion
5353
* @param object $moodleoverflow
5454
* @param int $postinguserid user id of posting user
5555
*
5656
* @return bool true if user is not logged in, everything is marked anonymous
5757
* and if the question is anonymous and there are no answers yet, else false
5858
*/
59-
public static function is_post_anonymous($post, $moodleoverflow, $postinguserid): bool {
59+
public static function is_post_anonymous($discussion, $moodleoverflow, $postinguserid): bool {
6060
if ($postinguserid == 0) {
6161
return true;
6262
}
@@ -66,10 +66,47 @@ public static function is_post_anonymous($post, $moodleoverflow, $postinguserid)
6666
}
6767

6868
if ($moodleoverflow->anonymous == self::QUESTION_ANONYMOUS) {
69-
return $post->parent == 0;
69+
return $discussion->userid == $postinguserid;
7070
}
7171

7272
return false;
7373
}
7474

75+
/**
76+
* Returns a usermapping for the Moodleoverflow, where each anonymized userid is replaced by an int, to form the
77+
* new name, e.g. Answerer #4.
78+
*
79+
* @param \stdClass $moodleoverflow
80+
* @param int $discussionid
81+
*/
82+
public static function get_userid_mapping($moodleoverflow, $discussionid) {
83+
global $DB;
84+
if ($moodleoverflow->anonymous == self::NOT_ANONYMOUS) {
85+
return [];
86+
}
87+
if ($moodleoverflow->anonymous == self::QUESTION_ANONYMOUS) {
88+
return [
89+
$DB->get_field('moodleoverflow_posts', 'userid',
90+
['parent' => 0, 'discussion' => $discussionid]) => get_string('questioner', 'mod_moodleoverflow')
91+
];
92+
}
93+
94+
$userids = $DB->get_records_sql(
95+
'SELECT userid ' .
96+
'FROM mdl_moodleoverflow_posts ' .
97+
'WHERE discussion = :discussion' .
98+
'GROUP BY userid ' .
99+
'ORDER BY MIN(created) ASC;', ['discussion' => $discussionid]);
100+
101+
$mapping = [];
102+
$questioner = array_shift($userids);
103+
$mapping[$questioner->userid] = get_string('questioner', 'moodleoverflow');
104+
$i = 1;
105+
foreach ($userids as $user) {
106+
$mapping[$user->userid] = get_string('answerer', 'moodleoverflow', $i);
107+
$i++;
108+
}
109+
return $mapping;
110+
}
111+
75112
}

classes/output/moodleoverflow_email.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ public function get_discussionname() {
357357
* @return string
358358
*/
359359
public function get_author_fullname() {
360-
if (anonymous::is_post_anonymous($this->post, $this->moodleoverflow, $this->author->id)) {
360+
if (anonymous::is_post_anonymous($this->discussion, $this->moodleoverflow, $this->author->id)) {
361361
return get_string('privacy:anonym_user_name', 'mod_moodleoverflow');
362362
} else {
363363
return fullname($this->author, $this->viewfullnames);
@@ -519,7 +519,7 @@ public function get_moodleoverflowviewlink() {
519519
* @return string
520520
*/
521521
public function get_authorlink() {
522-
if (anonymous::is_post_anonymous($this->post, $this->moodleoverflow, $this->author->id)) {
522+
if (anonymous::is_post_anonymous($this->discussion, $this->moodleoverflow, $this->author->id)) {
523523
return null;
524524
}
525525

@@ -540,7 +540,7 @@ public function get_authorlink() {
540540
*/
541541
public function get_author_picture() {
542542
global $OUTPUT;
543-
if (anonymous::is_post_anonymous($this->post, $this->moodleoverflow, $this->author->id)) {
543+
if (anonymous::is_post_anonymous($this->discussion, $this->moodleoverflow, $this->author->id)) {
544544
return '';
545545
}
546546

@@ -553,7 +553,7 @@ public function get_author_picture() {
553553
* @return string
554554
*/
555555
public function get_group_picture() {
556-
if (anonymous::is_post_anonymous($this->post, $this->moodleoverflow, $this->author->id)) {
556+
if (anonymous::is_post_anonymous($this->discussion, $this->moodleoverflow, $this->author->id)) {
557557
return '';
558558
}
559559

externallib.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public static function record_vote($discussionid, $postid, $ratingid, $sesskey)
128128
$ownerrating = \mod_moodleoverflow\ratings::moodleoverflow_get_reputation($moodleoverflow->id, $postownerid);
129129
$raterrating = \mod_moodleoverflow\ratings::moodleoverflow_get_reputation($moodleoverflow->id, $USER->id);
130130

131-
$cannotseeowner = \mod_moodleoverflow\anonymous::is_post_anonymous($post, $moodleoverflow, $USER->id) &&
131+
$cannotseeowner = \mod_moodleoverflow\anonymous::is_post_anonymous($discussion, $moodleoverflow, $USER->id) &&
132132
$USER->id != $postownerid;
133133

134134
$params['postrating'] = $rating->upvotes - $rating->downvotes;

lang/en/moodleoverflow.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,15 @@
405405
$string['gradesupdated'] = 'Grades updated';
406406
$string['taskupdategrades'] = 'Moodleoverflow maintenance job to update grades';
407407

408+
// Anonymous Feature
408409
$string['anonymous'] = 'Anonymous';
409410
$string['anonymous_help'] = 'This will hide username from all question (and answers).<br>WARNING: Once the questions (and answers) are anonymized, this cannot be reversed.<br>The setting can only be changed to a higher degree of anonymity.';
410-
$string['anonymous:only_questions'] = 'Only questions (Irreversible!)';
411-
$string['anonymous:everything'] = 'Questions and answers (Irreversible!)';
411+
$string['anonymous:only_questions'] = 'Only questioners (Irreversible!)';
412+
$string['anonymous:everything'] = 'Questioners and answerers (Irreversible!)';
412413
$string['anonym_you'] = 'Anonymous (You)';
414+
$string['allowanonymous'] = 'Allow anonymous';
415+
$string['allowanonymous_desc'] = 'Allow teachers to put moodleoverflow forums into anonymous question or full anonymous mode';
416+
$string['questioner'] = 'Questioner';
417+
$string['answerer'] = 'Answerer #{$a}';
418+
$string['desc:only_questions'] = 'The name of questioners will not be displayed in their question and comments.';
419+
$string['desc:anonymous'] = 'No names will be displayed.';

lib.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ function moodleoverflow_send_mails() {
780780
continue;
781781
}
782782

783-
if (\mod_moodleoverflow\anonymous::is_post_anonymous($post, $moodleoverflow, $post->userid)) {
783+
if (\mod_moodleoverflow\anonymous::is_post_anonymous($discussion, $moodleoverflow, $post->userid)) {
784784
$userfrom = \core_user::get_noreply_user();
785785
} else {
786786
// Check whether the sending user is cached already.

0 commit comments

Comments
 (0)