@@ -94,7 +94,7 @@ public function user_can_solve_post($solved, $topic_data)
94
94
95
95
if (($ topic_data [$ forum_permission [$ solved ]] == topicsolved::TOPIC_SOLVED_MOD ||
96
96
$ topic_data [$ forum_permission [$ solved ]] == topicsolved::TOPIC_SOLVED_YES ) &&
97
- $ this ->auth ->acl_get ('m_ ' ))
97
+ $ this ->auth ->acl_get ('m_ ' , $ topic_data [ ' forum_id ' ] ))
98
98
{
99
99
return true ;
100
100
}
@@ -140,26 +140,15 @@ public function get_topic_data($post_id)
140
140
}
141
141
142
142
/**
143
- * Mark topic as solved with the given post .
143
+ * Update topic with the given data .
144
144
*
145
- * Post will only be locked if marking as solved, not when unsolving. This
146
- * method does not do any validation. Data should be validated first.
147
- *
148
- * @param int $topic_id Topic to be marked.
149
- * @param int $post_id Solved post or 0 for unsolved topic.
150
- * @param bool $lock Lock the topic after marking as solved.
145
+ * @param int $topic_id Topic to update.
146
+ * @param int $data Topic data to update.
151
147
*
152
148
* @return mixed true if successful
153
149
*/
154
- public function update_topic_solved ($ topic_id , $ post_id , $ lock = false )
150
+ public function update_topic ($ topic_id , $ data )
155
151
{
156
- $ data = array ('topic_solved ' => $ post_id );
157
-
158
- if ($ lock )
159
- {
160
- $ data ['topic_status ' ] = ITEM_LOCKED ;
161
- }
162
-
163
152
$ update_sql = $ this ->db ->sql_build_array ('UPDATE ' , $ data );
164
153
$ result = $ this ->db ->sql_query ('
165
154
UPDATE ' . TOPICS_TABLE . '
@@ -170,6 +159,73 @@ public function update_topic_solved($topic_id, $post_id, $lock = false)
170
159
return $ result ;
171
160
}
172
161
162
+ /**
163
+ * Marks a topic as solved.
164
+ *
165
+ * @param array $topic_data Topic to be marked as solved.
166
+ * @param int $post_id Post to mark as the solution.
167
+ */
168
+ public function mark_solved ($ topic_data , $ post_id )
169
+ {
170
+ // Database column values to set.
171
+ $ column_data = array ('topic_solved ' => $ post_id );
172
+
173
+ if ($ topic_data ['forum_lock_solved ' ] &&
174
+ $ this ->user_can_lock_post ($ topic_data ['forum_id ' ]))
175
+ {
176
+ $ column_data ['topic_status ' ] = ITEM_LOCKED ;
177
+ }
178
+
179
+ $ this ->update_topic ($ topic_data ['topic_id ' ], $ column_data );
180
+ }
181
+
182
+ /**
183
+ * Marks a topic as unsolved.
184
+ *
185
+ * @param array $topic_data Topic to be marked as unsolved.
186
+ */
187
+ public function mark_unsolved ($ topic_data )
188
+ {
189
+ // Database column values to set.
190
+ $ column_data = array ('topic_solved ' => 0 );
191
+
192
+ if ($ topic_data ['forum_lock_solved ' ] &&
193
+ $ this ->auth ->acl_get ('m_lock ' , $ topic_data ['forum_id ' ]))
194
+ {
195
+ $ column_data ['topic_status ' ] = ITEM_UNLOCKED ;
196
+ }
197
+
198
+ $ this ->update_topic ($ topic_data ['topic_id ' ], $ column_data );
199
+ }
200
+
201
+ /**
202
+ * Checks if the currently logged in user has permission to lock a post.
203
+ *
204
+ * Regular users won't have permission to solve any topics other than their
205
+ * own, and moderator permissions are forum based, so we only need to know
206
+ * the forum, not the post.
207
+ *
208
+ * @param int $forum_id Forum to check permissions on.
209
+ *
210
+ * @return bool true if user has permission to lock a post.
211
+ */
212
+ public function user_can_lock_post ($ forum_id )
213
+ {
214
+ // Check if user is moderator with appropriate lock permission
215
+ if ($ this ->auth ->acl_get ('m_lock ' , $ forum_id ))
216
+ {
217
+ return true ;
218
+ }
219
+
220
+ // Check if user has "lock own posts" permission
221
+ if ($ this ->auth ->acl_get ('f_user_lock ' , $ forum_id ))
222
+ {
223
+ return true ;
224
+ }
225
+
226
+ return false ;
227
+ }
228
+
173
229
/**
174
230
* Generate markup for the given solved indicator image.
175
231
*
0 commit comments