Skip to content

Commit ef356f4

Browse files
Code cleanup; Make NOT_ANONYMOUS default; Fix externallib anonymous check; Remove reputation display completely when anonymous
1 parent fc799fe commit ef356f4

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

externallib.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,19 @@ public static function record_vote($discussionid, $postid, $ratingid, $sesskey)
121121
print_error('ratingfailed', 'moodleoverflow');
122122
}
123123

124-
$postownerid = moodleoverflow_get_post_full($params['postid'])->userid;
124+
$post = moodleoverflow_get_post_full($params['postid']);
125+
$postownerid = $post->userid;
125126
$rating = \mod_moodleoverflow\ratings::moodleoverflow_get_ratings_by_discussion($discussion->id,
126127
$params['postid']);
127128
$ownerrating = \mod_moodleoverflow\ratings::moodleoverflow_get_reputation($moodleoverflow->id, $postownerid);
128129
$raterrating = \mod_moodleoverflow\ratings::moodleoverflow_get_reputation($moodleoverflow->id, $USER->id);
129130

130-
$canseeowner = $moodleoverflow->anonymous && $USER->id != $postownerid;
131+
$cannotseeowner = \mod_moodleoverflow\anonymous::is_post_anonymous($post, $moodleoverflow, $USER->id) && $USER->id != $postownerid;
131132

132133
$params['postrating'] = $rating->upvotes - $rating->downvotes;
133-
$params['ownerreputation'] = $canseeowner ? null : $ownerrating;
134+
$params['ownerreputation'] = $cannotseeowner ? null : $ownerrating;
134135
$params['raterreputation'] = $raterrating;
135-
$params['ownerid'] = $canseeowner ? null : $postownerid;
136+
$params['ownerid'] = $cannotseeowner ? null : $postownerid;
136137

137138
$transaction->allow_commit();
138139

locallib.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,23 +1289,17 @@ function moodleoverflow_print_post($post, $discussion, $moodleoverflow, $cm, $co
12891289
}
12901290

12911291
// The rating of the user.
1292-
if (anonymous::is_post_anonymous($post, $moodleoverflow, $post->userid) && $post->userid !== $USER->id) {
1293-
$postuserrating = '--';
1292+
if (anonymous::is_post_anonymous($post, $moodleoverflow, $post->userid)) {
1293+
$postuserrating = null;
12941294
} else {
12951295
$postuserrating = \mod_moodleoverflow\ratings::moodleoverflow_get_reputation($moodleoverflow->id, $postinguser->id);
12961296
}
12971297

12981298
// The name of the user and the date modified.
1299-
$by = new stdClass();
1300-
$by->date = userdate($post->modified);
1301-
$by->name = $postinguser->profilelink ?
1302-
html_writer::link($postinguser->profilelink, $postinguser->fullname)
1303-
: $postinguser->fullname;
1304-
$by->rating = "<img class='icon iconsmall' src='" .
1305-
$OUTPUT->image_url('star', 'moodleoverflow') . "'><span>" . $postuserrating . '</span>';
1306-
$mustachedata->bytext = get_string('bynameondate', 'moodleoverflow', $by);
1307-
$mustachedata->bydate = $by->date;
1308-
$mustachedata->byname = $by->name;
1299+
$mustachedata->bydate = userdate($post->modified);
1300+
$mustachedata->byname = $postinguser->profilelink ?
1301+
html_writer::link($postinguser->profilelink, $postinguser->fullname)
1302+
: $postinguser->fullname;
13091303
$mustachedata->byrating = $postuserrating;
13101304

13111305
// Set options for the post.

mod_form.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public function definition() {
8484

8585
$mform->addElement('select', 'anonymous', get_string('anonymous', 'moodleoverflow'), $possiblesettings);
8686
$mform->addHelpButton('anonymous', 'anonymous', 'moodleoverflow');
87+
$mform->setDefault('anonymous', anonymous::NOT_ANONYMOUS);
8788

8889
// Attachments.
8990
$mform->addElement('header', 'attachmentshdr', get_string('attachments', 'moodleoverflow'));

templates/answer.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
{{{ picture }}}
7575
</div>
7676
<div class="user-details">
77-
{{{ byname }}} ({{#pix}}star, moodleoverflow, {{#str}}reputation, moodleoverflow{{/str}}{{/pix}}<span>{{ byrating }}</span>)
77+
{{{ byname }}} {{#byrating}}({{#pix}}star, moodleoverflow, {{#str}}reputation, moodleoverflow{{/str}}{{/pix}}<span>{{ byrating }}</span>){{/byrating}}
7878
<div class="-flair">
7979
<div class="user-action-time">
8080
{{ bydate }}

templates/question.mustache

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@
5959

6060
{{! The author and date. }}
6161
<div class="author" role="heading" aria-level="2">
62-
{{{ bytext }}}
62+
<span class="user-details">
63+
by {{{ byname }}}
64+
{{#byrating}}({{#pix}}star, moodleoverflow, {{#str}}reputation, moodleoverflow{{/str}}{{/pix}}<span>{{ byrating }}</span>){{/byrating}} -
65+
{{ bydate }}
66+
</span>
6367
</div>
6468

6569
{{^isfirstpost}}

0 commit comments

Comments
 (0)