@@ -72,19 +72,12 @@ public static function get_events(): array {
72
72
73
73
if ($ event ->eventtype == 'post ' ) {
74
74
// Add an anonymous attribute.
75
- if ($ event ->anonymoussetting == anonymous::EVERYTHING_ANONYMOUS ) {
76
- $ event ->anonymous = true ;
77
- } else if ($ event ->anonymoussetting == anonymous::QUESTION_ANONYMOUS ) {
78
- $ event ->anonymous = $ event ->postuserid == $ event ->discussionuserid ;
79
- } else {
80
- $ event ->anonymous = false ;
81
- }
75
+ $ event ->anonymous = self ::is_post_anonymous ($ event );
82
76
83
77
// If the post is anonymous, make the author anonymous.
84
78
if ($ event ->anonymous ) {
85
79
$ event ->postuserfirstname = 'anonymous ' ;
86
80
$ event ->postuserlastname = '' ;
87
- $ event ->postuserid = -1 ;
88
81
}
89
82
90
83
// Add links.
@@ -94,7 +87,6 @@ public static function get_events(): array {
94
87
new moodle_url ('/user/view.php ' , ['id ' => $ event ->postuserid ]);
95
88
}
96
89
}
97
-
98
90
return $ moodleoverflowevents ;
99
91
}
100
92
@@ -129,7 +121,8 @@ private static function get_moodleoverflowposts_from_db($courses, $timestart): a
129
121
posts.parent AS postparentid,
130
122
posts.userid AS postuserid,
131
123
posts.created AS timestart,
132
- posts.message AS postmessage
124
+ posts.message AS content,
125
+ posts.messageformat AS postmessageformat
133
126
FROM {moodleoverflow_posts} posts
134
127
JOIN {moodleoverflow_discussions} discuss ON discuss.id = posts.discussion
135
128
JOIN {moodleoverflow} module ON module.id = discuss.moodleoverflow
@@ -160,8 +153,9 @@ private static function get_other_events_from_db($courses, $timestart, $timeend)
160
153
$ params = ['timestart ' => $ timestart , 'timeduration ' => $ timestart ,
161
154
'timeend ' => $ timeend , 'courses ' => $ courses , ] + $ inparamscourses ;
162
155
// Set the sql statement.
163
- $ sql = "SELECT e.id, e.name, mo.name AS instancename, e.courseid, cm.id AS coursemoduleid, cm.availability AS availability,
164
- e.groupid, e.userid, e.modulename, e.instance, e.eventtype, e.timestart, e.timemodified, e.visible
156
+ $ sql = "SELECT e.id, e.name AS content, mo.name AS instancename, e.courseid, cm.id AS coursemoduleid,
157
+ cm.availability AS availability, e.groupid, e.userid, e.modulename, e.instance, e.eventtype, e.timestart,
158
+ e.timemodified, e.visible
165
159
FROM {event} e
166
160
JOIN {modules} m ON e.modulename = m.name
167
161
JOIN {course_modules} cm ON (cm.course = e.courseid AND cm.module = m.id AND cm.instance = e.instance)
@@ -179,4 +173,17 @@ private static function get_other_events_from_db($courses, $timestart, $timeend)
179
173
return $ DB ->get_records_sql ($ sql , $ params );
180
174
}
181
175
176
+ /**
177
+ * Helper function to check if a post is anonymous. Helps to reduce the cyclomatic complexity.
178
+ * @param $event
179
+ * @return bool
180
+ */
181
+ private static function is_post_anonymous ($ event ) {
182
+ if ($ event ->anonymoussetting == anonymous::EVERYTHING_ANONYMOUS ) {
183
+ return true ;
184
+ } else if ($ event ->anonymoussetting == anonymous::QUESTION_ANONYMOUS ) {
185
+ return $ event ->postuserid == $ event ->discussionuserid ;
186
+ }
187
+ return false ;
188
+ }
182
189
}
0 commit comments