Skip to content

Commit

Permalink
integration with best answer mod
Browse files Browse the repository at this point in the history
Signed-off-by: Diego Andrés <diegoandres_cortes@outlook.com>
  • Loading branch information
DiegoAndresCortes committed Jul 8, 2022
1 parent 6314a17 commit f380956
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Topic Solved mod provides a very basic functionality to mark topics as solved.
- Solve own topics
- Select boards where it applies
- Color the solved topics in messageindex
- Integration with [Best Answer](https://github.com/SychO9/smf-best-answer)

### Localization
- ![English](https://www.simplemachines.org/site_images/lang/english.gif) English
Expand Down
41 changes: 41 additions & 0 deletions Sources/Class-TopicSolved.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public static function hooks()

// Settings
add_integration_function('integrate_general_mod_settings', __CLASS__ . '::settings#', false, $sourcedir . '/Class-TopicSolved.php');

// Best Answer
add_integration_function('integrate_sycho_best_answer', __CLASS__ . '::best_answer#', false, $sourcedir . '/Class-TopicSolved.php');
}

/**
Expand Down Expand Up @@ -285,4 +288,42 @@ public function permissions(&$permissionGroups, &$permissionList, &$leftPermissi
{
$permissionList['board']['solve_topics'] = [true, 'topic', 'moderate'];
}

/**
* Best Answer
*
* Mark the topic as solved after the best answer is chosen
*
* @return void
*/
public function best_answer($id_msg) : void
{
global $smcFunc, $modSettings, $board;

// Can we solve in this board?
if (!in_array($board, explode(',', $modSettings['TopicSolved_boards_can_solve'])))
return;

// Find the topic from this msg
$request = $smcFunc['db_query']('', '
SELECT m.id_topic
FROM {db_prefix}messages AS m
WHERE m.id_msg = {int:id_msg}',
[
'id_msg' => $id_msg,
]
);
$topic = $smcFunc['db_fetch_assoc']($request);
$smcFunc['db_free_result']($request);

// Mark the topic as solved
$smcFunc['db_query']('', '
UPDATE {db_prefix}topics AS t
SET is_solved = 1
WHERE t.id_topic = {int:topic}',
[
'topic' => $topic['id_topic'],
]
);
}
}
1 change: 1 addition & 0 deletions readme/readme.english.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
[/li]
[li][size=0.9em]Select boards where it applies[/size][/li]
[li][size=0.9em]Color the solved topics in messageindex[/size][/li]
[li][size=0.9em]Integration with [url="https://custom.simplemachines.org/index.php?mod=4274"]Best Answer[/url][/size][/li]
[/list]

[size=3][color=#358234]Localization[/color][/size]
Expand Down

0 comments on commit f380956

Please sign in to comment.