Skip to content

Commit f380956

Browse files
integration with best answer mod
Signed-off-by: Diego Andrés <diegoandres_cortes@outlook.com>
1 parent 6314a17 commit f380956

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Topic Solved mod provides a very basic functionality to mark topics as solved.
1414
- Solve own topics
1515
- Select boards where it applies
1616
- Color the solved topics in messageindex
17+
- Integration with [Best Answer](https://github.com/SychO9/smf-best-answer)
1718

1819
### Localization
1920
- ![English](https://www.simplemachines.org/site_images/lang/english.gif) English

Sources/Class-TopicSolved.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public static function hooks()
4040

4141
// Settings
4242
add_integration_function('integrate_general_mod_settings', __CLASS__ . '::settings#', false, $sourcedir . '/Class-TopicSolved.php');
43+
44+
// Best Answer
45+
add_integration_function('integrate_sycho_best_answer', __CLASS__ . '::best_answer#', false, $sourcedir . '/Class-TopicSolved.php');
4346
}
4447

4548
/**
@@ -285,4 +288,42 @@ public function permissions(&$permissionGroups, &$permissionList, &$leftPermissi
285288
{
286289
$permissionList['board']['solve_topics'] = [true, 'topic', 'moderate'];
287290
}
291+
292+
/**
293+
* Best Answer
294+
*
295+
* Mark the topic as solved after the best answer is chosen
296+
*
297+
* @return void
298+
*/
299+
public function best_answer($id_msg) : void
300+
{
301+
global $smcFunc, $modSettings, $board;
302+
303+
// Can we solve in this board?
304+
if (!in_array($board, explode(',', $modSettings['TopicSolved_boards_can_solve'])))
305+
return;
306+
307+
// Find the topic from this msg
308+
$request = $smcFunc['db_query']('', '
309+
SELECT m.id_topic
310+
FROM {db_prefix}messages AS m
311+
WHERE m.id_msg = {int:id_msg}',
312+
[
313+
'id_msg' => $id_msg,
314+
]
315+
);
316+
$topic = $smcFunc['db_fetch_assoc']($request);
317+
$smcFunc['db_free_result']($request);
318+
319+
// Mark the topic as solved
320+
$smcFunc['db_query']('', '
321+
UPDATE {db_prefix}topics AS t
322+
SET is_solved = 1
323+
WHERE t.id_topic = {int:topic}',
324+
[
325+
'topic' => $topic['id_topic'],
326+
]
327+
);
328+
}
288329
}

readme/readme.english.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
[/li]
2121
[li][size=0.9em]Select boards where it applies[/size][/li]
2222
[li][size=0.9em]Color the solved topics in messageindex[/size][/li]
23+
[li][size=0.9em]Integration with [url="https://custom.simplemachines.org/index.php?mod=4274"]Best Answer[/url][/size][/li]
2324
[/list]
2425

2526
[size=3][color=#358234]Localization[/color][/size]

0 commit comments

Comments
 (0)