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
12 changes: 10 additions & 2 deletions amd/build/functions.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion amd/build/functions.min.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion amd/src/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* Ajax functions for moodleoverflow
*
* @module mod/moodleoverflow
* @package
* @copyright 2017 Tamara Gunkel
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
Expand Down
43 changes: 40 additions & 3 deletions classes/anonymous.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ class anonymous {
/**
* Checks if post is anonymous.
*
* @param object $post moodleoverflow post object
* @param object $discussion moodleoverflow discussion
* @param object $moodleoverflow
* @param int $postinguserid user id of posting user
*
* @return bool true if user is not logged in, everything is marked anonymous
* and if the question is anonymous and there are no answers yet, else false
*/
public static function is_post_anonymous($post, $moodleoverflow, $postinguserid): bool {
public static function is_post_anonymous($discussion, $moodleoverflow, $postinguserid): bool {
if ($postinguserid == 0) {
return true;
}
Expand All @@ -66,10 +66,47 @@ public static function is_post_anonymous($post, $moodleoverflow, $postinguserid)
}

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

return false;
}

/**
* Returns a usermapping for the Moodleoverflow, where each anonymized userid is replaced by an int, to form the
* new name, e.g. Answerer #4.
*
* @param \stdClass $moodleoverflow
* @param int $discussionid
*/
public static function get_userid_mapping($moodleoverflow, $discussionid) {
global $DB;
if ($moodleoverflow->anonymous == self::NOT_ANONYMOUS) {
return [];
}
if ($moodleoverflow->anonymous == self::QUESTION_ANONYMOUS) {
return [
$DB->get_field('moodleoverflow_posts', 'userid',
['parent' => 0, 'discussion' => $discussionid]) => get_string('questioner', 'mod_moodleoverflow')
];
}

$userids = $DB->get_records_sql(
'SELECT userid ' .
'FROM mdl_moodleoverflow_posts ' .
'WHERE discussion = :discussion' .
'GROUP BY userid ' .
'ORDER BY MIN(created) ASC;', ['discussion' => $discussionid]);

$mapping = [];
$questioner = array_shift($userids);
$mapping[$questioner->userid] = get_string('questioner', 'moodleoverflow');
$i = 1;
foreach ($userids as $user) {
$mapping[$user->userid] = get_string('answerer', 'moodleoverflow', $i);
$i++;
}
return $mapping;
}

}
8 changes: 4 additions & 4 deletions classes/output/moodleoverflow_email.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public function get_discussionname() {
* @return string
*/
public function get_author_fullname() {
if (anonymous::is_post_anonymous($this->post, $this->moodleoverflow, $this->author->id)) {
if (anonymous::is_post_anonymous($this->discussion, $this->moodleoverflow, $this->author->id)) {
return get_string('privacy:anonym_user_name', 'mod_moodleoverflow');
} else {
return fullname($this->author, $this->viewfullnames);
Expand Down Expand Up @@ -519,7 +519,7 @@ public function get_moodleoverflowviewlink() {
* @return string
*/
public function get_authorlink() {
if (anonymous::is_post_anonymous($this->post, $this->moodleoverflow, $this->author->id)) {
if (anonymous::is_post_anonymous($this->discussion, $this->moodleoverflow, $this->author->id)) {
return null;
}

Expand All @@ -540,7 +540,7 @@ public function get_authorlink() {
*/
public function get_author_picture() {
global $OUTPUT;
if (anonymous::is_post_anonymous($this->post, $this->moodleoverflow, $this->author->id)) {
if (anonymous::is_post_anonymous($this->discussion, $this->moodleoverflow, $this->author->id)) {
return '';
}

Expand All @@ -553,7 +553,7 @@ public function get_author_picture() {
* @return string
*/
public function get_group_picture() {
if (anonymous::is_post_anonymous($this->post, $this->moodleoverflow, $this->author->id)) {
if (anonymous::is_post_anonymous($this->discussion, $this->moodleoverflow, $this->author->id)) {
return '';
}

Expand Down
2 changes: 1 addition & 1 deletion externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static function record_vote($discussionid, $postid, $ratingid, $sesskey)
$ownerrating = \mod_moodleoverflow\ratings::moodleoverflow_get_reputation($moodleoverflow->id, $postownerid);
$raterrating = \mod_moodleoverflow\ratings::moodleoverflow_get_reputation($moodleoverflow->id, $USER->id);

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

$params['postrating'] = $rating->upvotes - $rating->downvotes;
Expand Down
11 changes: 9 additions & 2 deletions lang/en/moodleoverflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,15 @@
$string['gradesupdated'] = 'Grades updated';
$string['taskupdategrades'] = 'Moodleoverflow maintenance job to update grades';

// Anonymous Feature
$string['anonymous'] = 'Anonymous';
$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.';
$string['anonymous:only_questions'] = 'Only questions (Irreversible!)';
$string['anonymous:everything'] = 'Questions and answers (Irreversible!)';
$string['anonymous:only_questions'] = 'Only questioners (Irreversible!)';
$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['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.';
2 changes: 1 addition & 1 deletion lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ function moodleoverflow_send_mails() {
continue;
}

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