"Recent forum topics" block query

Events happening in the community are now at Drupal community events on www.drupal.org.
Posted by kiryoku on December 11, 2007 at 10:34pm

Hi...

I would like to re-create the "Recent forum topics" block on a non-Drupal page.
Because of this I took a look into the .module file in order to locate and copy the query that would output the latest active topics.
However, I'm stuck as I'm not too familiar with mysql yet....

I found the code below, but I don't really understand why it does the left join on the group_id and others...
Anyone who knows how the $sql command should look like and could wrap it up for me?

$query = "SELECT $tt.topic_id, $tt.topic_title, $tt.topic_last_post_id "
."FROM $tt "
."LEFT JOIN $ag ON $tt.forum_id = $ag.forum_id "
."LEFT JOIN $ar ON $ag.auth_role_id = $ar.role_id "
."LEFT JOIN $tg ON $ag.group_id = $tg.group_id "
."WHERE $tg.group_name = '$gid' AND $ar.role_name IN ('ROLE_FORUM_POLLS', 'ROLE_FORUM_STANDARD', 'ROLE_FORUM_READONLY') "
. $ignore_query
." ORDER BY $tt.topic_last_post_id DESC LIMIT {$phpbbcfg['block0_count']};";

Thanks a lot and have a nice Christmas!
(phpbb is going gold in 1 hour and 18 minutes!)

Comments

Should be able to reuse directly

Posted by arkepp on December 12, 2007 at 1:09am

Hi,

the whole thing is pretty convoluted to accomodate for people who are upgrading their phpBB installations. Basically you don't want to display topics from forums that are not public for regular user.

The problem is that there is no static permission number or anything that says "regular users have read access to this forum". So you have to go through this entire spiel, find out the ACL roles that would permit you to read a given forum, then ensure the users group is in the appropriate ACL group.

You should be able to use the query above directly, provided you also provide the correct values for $tt, $tf... and all those.

That said, on my own sites I have hardcoded this to a list of forums for performance reasons:

$query =
"SELECT $tt.topic_id, $tt.topic_title, $tt.topic_last_post_id, $tf.forum_name, $tt.topic_last_poster_name "
."FROM $tt "
."LEFT JOIN $tf ON $tt.forum_id = $tf.forum_id "
."WHERE "
." $tt.forum_id NOT IN({$user_ignores 144,219,138)"
." ORDER BY $tt.topic_last_post_id DESC LIMIT {$phpbbcfg['block0_count']};";
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");

$user_ignores is a filter set by the user (hardcoded for anonymous), 144, 219, 138 are forum ids I never want to show up on the recent topic list.

HI, i would like to extract

Posted by alexic on December 24, 2007 at 7:39pm

HI,

i would like to extract from this query the forum name and the author name too. Can you help me?

I tried this:

$query = "SELECT $tt.topic_id, $tt.topic_title, $tt.topic_last_post_id,<b> phpbb_forums.forum_name </b>" // MODIFICATA
."FROM $tt "
."LEFT JOIN $ag ON $tt.forum_id = $ag.forum_id "
<b> ."LEFT JOIN phpbb_forums ON $tt.forum_id = phpbb_forums.forum_id"</b>
."LEFT JOIN $ar ON $ag.auth_role_id = $ar.role_id "

."LEFT JOIN $tg ON $ag.group_id = $tg.group_id "
."WHERE $tg.group_name = '$gid' AND $ar.role_name IN ('ROLE_FORUM_POLLS', 'ROLE_FORUM_STANDARD', 'ROLE_FORUM_READONLY') "
. $ignore_query
." ORDER BY $tt.topic_last_post_id DESC LIMIT {$phpbbcfg['block0_count']};";
//echo $query;

but i'm not good with sql :)

Thanks and merry christmas

phpbb

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

AltStyle によって変換されたページ (->オリジナル) /