How to get forum_id from topic_id?

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
pierredu
Registered User
Posts: 1256
Joined: Thu Nov 01, 2012 8:04 am
Location: Paris (France)

How to get forum_id from topic_id?

Post by pierredu »

In one of my extensions, permission is given to use some bbcode only if the user is moderator of the forum.
When creating a topic, there is a f parameter on the command line.
When creating an answer or editing a message, there is only a t parameter.

It is not difficult to get the forum_id from the topic_id with a SQL query, but I'm quite sure that there is already a function in the core phpBB code, but I couldn't fond it.

Thanks in advance.
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53411
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: How to get forum_id from topic_id?

Post by Brf »

Near the top of viewtopic, it is getting forum_id by reading the topics table. If there were a function dedicated to that it would probably use that instead:

Code: Select all

		$sql = 'SELECT forum_id
			FROM ' . TOPICS_TABLE . "
			WHERE topic_id = $topic_id";
		$result = $db->sql_query($sql);
		$forum_id = (int) $db->sql_fetchfield('forum_id');
		$db->sql_freeresult($result);

		if (!$forum_id)
		{
			trigger_error('NO_TOPIC');
		}
User avatar
pierredu
Registered User
Posts: 1256
Joined: Thu Nov 01, 2012 8:04 am
Location: Paris (France)

Re: How to get forum_id from topic_id?

Post by pierredu »

Thanks for the pointer.
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: How to get forum_id from topic_id?

Post by 3Di »

pierredu wrote: Thu Oct 21, 2021 8:46 am In one of my extensions, permission is given to use some bbcode only if the user is moderator of the forum.
When creating a topic, there is a f parameter on the command line.
When creating an answer or editing a message, there is only a t parameter.
I tend to avoid extra queries if possible, a link to that part of code?
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
User avatar
pierredu
Registered User
Posts: 1256
Joined: Thu Nov 01, 2012 8:04 am
Location: Paris (France)

Re: How to get forum_id from topic_id?

Post by pierredu »

User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: How to get forum_id from topic_id?

Post by 3Di »

pierredu wrote: Fri Oct 22, 2021 6:14 am https://github.com/pierrdu/lmdi_hidebbc ... stener.php
lines 56 & ss.
Exact link https://github.com/pierrdu/lmdi_hidebbc ... er.php#L56

Are you still using request_var ?

Anyway, I will take a look at this later on.
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: How to get forum_id from topic_id?

Post by 3Di »

pierredu wrote: Thu Oct 21, 2021 8:46 am In one of my extensions, permission is given to use some bbcode only if the user is moderator of the forum.
When creating a topic, there is a f parameter on the command line.
When creating an answer or editing a message, there is only a t parameter.
The first thing that comes to mind when looking at the event you're using is that you could be using custom forum permissions instead of the query. The second is that there are more effective methods using the s9e utilities for this. The latter would require a substantial rewrite of the code.
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
User avatar
pierredu
Registered User
Posts: 1256
Joined: Thu Nov 01, 2012 8:04 am
Location: Paris (France)

Re: How to get forum_id from topic_id?

Post by pierredu »

Thanks for your remarks.
Post Reply

Return to “Extension Writers Discussion”