Skip to content

Commit

Permalink
encapsulate post attributes in condition
Browse files Browse the repository at this point in the history
  • Loading branch information
TamaroWalter committed May 16, 2024
1 parent 5522f22 commit e51a8c2
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions classes/moodleoverflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,29 @@ public static function get_events(): array {
unset($moodleoverflowevents[$key]);
}

// Add an anonymous attribute.
if ($event->anonymoussetting == anonymous::EVERYTHING_ANONYMOUS) {
$event->anonymous = true;
} else if ($event->anonymoussetting == anonymous::QUESTION_ANONYMOUS) {
$event->anonymous = $event->postuserid == $event->discussionuserid;
} else {
$event->anonymous = false;
if ($event->eventtype == 'post') {
// Add an anonymous attribute.
if ($event->anonymoussetting == anonymous::EVERYTHING_ANONYMOUS) {
$event->anonymous = true;
} else if ($event->anonymoussetting == anonymous::QUESTION_ANONYMOUS) {
$event->anonymous = $event->postuserid == $event->discussionuserid;
} else {
$event->anonymous = false;
}

// If the post is anonymous, make the author anonymous.
if ($event->anonymous) {
$event->postuserfirstname = 'anonymous';
$event->postuserlastname = '';
$event->postuserid = -1;
}

// Add links.
$event->linktopost = new moodle_url('/mod/moodleoverflow/discussion.php',
['d' => $event->postdiscussion], 'p' . $event->postid);
$event->linktoauthor = $event->anonymous ? new moodle_url('') :
new moodle_url('/user/view.php', ['id' => $event->postuserid]);
}

// If the post is anonymous, make the author anonymous.
if ($event->anonymous) {
$event->postuserfirstname = 'anonymous';
$event->postuserlastname = '';
$event->postuserid = -1;
}

// Add links.
$event->linktopost = new moodle_url('/mod/moodleoverflow/discussion.php',
['d' => $event->postdiscussion], 'p' . $event->postid);
$event->linktoauthor = $event->anonymous ? new moodle_url('') :
new moodle_url('/user/view.php', ['id' => $event->postuserid]);
}

return $moodleoverflowevents;
Expand Down

0 comments on commit e51a8c2

Please sign in to comment.