Forums authorized to view

Discussion forum for MOD Writers regarding MOD Development.
User avatar
mix1
Registered User
Posts: 209
Joined: Thu Oct 14, 2004 8:55 am
Location: England

Forums authorized to view

Post by mix1 »

Hi all i am trying to basically grab a few topics from a database as long as the user who is logged in is allow to see the forum which used to able to be done by the "auth_view" field in the forums table, which isn't there anymore, any ideas?

User avatar
poyntesm
Registered User
Posts: 1671
Joined: Tue Jan 18, 2005 11:19 am
Location: Dublin, Ireland
Contact:

Re: Forums authorized to view

Post by poyntesm »

These are what you want... they will return the forum ids a user has the permissions for. f_list is to see forum. f_read is to actual read forum and the other two are obvious.

Code: Select all

$auth->acl_getf('f_list');
$auth->acl_getf('f_read');
$auth->acl_getf('f_post');
$auth->acl_getf('f_reply');

User avatar
mix1
Registered User
Posts: 209
Joined: Thu Oct 14, 2004 8:55 am
Location: England

Re: Forums authorized to view

Post by mix1 »

Ah ha, thank you very much, your awesome!

User avatar
mix1
Registered User
Posts: 209
Joined: Thu Oct 14, 2004 8:55 am
Location: England

Re: Forums authorized to view

Post by mix1 »

Another question, i wish to make a query where it selects the forum ID's of the forums the logged in user is allowed to view, any ideas?

User avatar
poyntesm
Registered User
Posts: 1671
Joined: Tue Jan 18, 2005 11:19 am
Location: Dublin, Ireland
Contact:

Re: Forums authorized to view

Post by poyntesm »

You do not need a query to get forum IDs...I gave it to you already ;)

Code: Select all

$auth->acl_getf('f_read');

Zottel
Registered User
Posts: 3
Joined: Fri Aug 19, 2005 2:31 am

Re: Forums authorized to view

Post by Zottel »

That's nearly what i was searching for as well :)

But how can I grab a list of forums a specific role/group has access to, not the current user. For example, grabing a list of forums all non logged in users have f_read-access to. How could this be done?

User avatar
mix1
Registered User
Posts: 209
Joined: Thu Oct 14, 2004 8:55 am
Location: England

Re: Forums authorized to view

Post by mix1 »

Well all what you gave me echos out "Array" how do i get the query to accept the ID's from that array to use?

User avatar
poyntesm
Registered User
Posts: 1671
Joined: Tue Jan 18, 2005 11:19 am
Location: Dublin, Ireland
Contact:

Re: Forums authorized to view

Post by poyntesm »

You would use something like below, you get the IDs (in an array) and then good idea to unique them and then you can ammend the query and build it using the sql_in_set function.

Code: Select all

$forum_ary = $auth->acl_getf('f_read', true);
$forum_ary = array_unique(array_keys($forum_ary));

if (sizeof($forum_ary))
{
	$sql .= ' AND ' . $db->sql_in_set('forum_id', $forum_ary, true);
}

User avatar
mix1
Registered User
Posts: 209
Joined: Thu Oct 14, 2004 8:55 am
Location: England

Re: Forums authorized to view

Post by mix1 »

Right i have this:

Code: Select all

// sql statement to fetch active topics of public forums

$sql = "SELECT DISTINCT t.topic_title, t.topic_last_post_id, p.post_time, f.forum_name 

  FROM " . TOPICS_TABLE . " AS t, " . POSTS_TABLE . " AS p, " . FORUMS_TABLE . " AS f 

  WHERE 

    t.forum_id = f.forum_id 

      AND p.topic_id = t.topic_id 

      AND p.post_id = t.topic_last_post_id

  ORDER BY p.post_time DESC LIMIT " . TOPIC_COUNT;

$forum_ary = $auth->acl_getf('f_read', true);
$forum_ary = array_unique(array_keys($forum_ary));

if (sizeof($forum_ary))
{
   $sql .= ' AND ' . $db->sql_in_set('forum_id', $forum_ary, true);
}
But it doesn't find anything?

User avatar
A_Jelly_Doughnut
Former Team Member
Posts: 34457
Joined: Sat Jan 18, 2003 1:26 am
Location: Where the Rivers Run
Contact:

Re: Forums authorized to view

Post by A_Jelly_Doughnut »

You have a contradiction in the $db->sql_in_set call (that's what the third argument is called). This means you're fetching from all forums except those where the user has f_read permission. I'm guessing you're testing with an admin account with rights in all forums, so there are no forums left to select from.

Try removing the true from sql_in_set()
A Donut's Blog
"Bach's Prelude (Cello Suite No. 1) is driving Indiana country roads in Autumn" - Ann Kish

User avatar
mix1
Registered User
Posts: 209
Joined: Thu Oct 14, 2004 8:55 am
Location: England

Re: Forums authorized to view

Post by mix1 »

Still says there is nothing with the true statement removed?

I removed the parts to do with the authorized forums and it still says there is nothing, so here is the full code for anyone to see if they can see a problem.

Code: Select all

// sql statement to fetch active topics of public forums

$sql = "SELECT DISTINCT t.topic_title, t.topic_last_post_id, p.post_time, f.forum_name 

  FROM " . TOPICS_TABLE . " AS t, " . POSTS_TABLE . " AS p, " . FORUMS_TABLE . " AS f 

  WHERE 

    t.forum_id = f.forum_id 

      AND p.topic_id = t.topic_id 

      AND p.post_id = t.topic_last_post_id

  ORDER BY p.post_time DESC LIMIT " . TOPIC_COUNT;

$forum_ary = $auth->acl_getf('f_read', true);
$forum_ary = array_unique(array_keys($forum_ary));

if (sizeof($forum_ary))
{
   $sql .= ' AND ' . $db->sql_in_set('forum_id', $forum_ary);
}


$nt_result = $db->sql_query($sql);



if(!$nt_result)

{

    die("Failed obtaining list of active topics".mysql_error());

}

else

{

    $nt_data = $db->sql_fetchrowset($af_result);

}

    

if ( count($nt_data) == 0 )

{

    die("No topics found".mysql_error());

}
The error it is giving me is the end part "No Topics Found".
Last edited by mix1 on Mon Jul 02, 2007 11:01 am, edited 1 time in total.

User avatar
poyntesm
Registered User
Posts: 1671
Joined: Tue Jan 18, 2005 11:19 am
Location: Dublin, Ireland
Contact:

Re: Forums authorized to view

Post by poyntesm »

A_Jelly_Doughnut ... Do'h was typing without thinking!!

Show us where you are getting and displaying the data. Maybe you have a mistake in the display.

joebert
Registered User
Posts: 224
Joined: Mon Jan 24, 2005 5:50 am
Location: Kenneth City, FL USA
Name: Joe

Re: Forums authorized to view

Post by joebert »

I don't believe I've ever seen a query where an AND conditional was appended after an ORDER BY & LIMIT.

phpbb3 has a prefered method of adding LIMIT clauses.
Here's the SQL section of coding guidelines.
http://area51.phpbb.com/docs/coding-guidelines.html#sql
Here's the LIMIT method
sql_query_limit():

We do not add limit statements to the sql query, but instead use $db->sql_query_limit(). You basically pass the query, the total number of lines to retrieve and the offset.

Note: Since Oracle handles limits differently and because of how we implemented this handling you need to take special care if you use sql_query_limit with an sql query retrieving data from more than one table.

Make sure when using something like "SELECT x.*, y.jars" that there is not a column named jars in x; make sure that there is no overlap between an implicit column and the explicit columns.
The auth check & definition of $forum_ary should definately come before $sql is defined, if sizeof returns elements then define $sql & do the query.

I'm not familiar with phpbb3 column relations yet, so I'm not going to attempt to give you a correct query.

skinmaster
Registered User
Posts: 32
Joined: Tue Feb 17, 2004 7:46 am

Re: Forums authorized to view

Post by skinmaster »

poyntesm wrote:These are what you want... they will return the forum ids a user has the permissions for. f_list is to see forum. f_read is to actual read forum and the other two are obvious.

Code: Select all

$auth->acl_getf('f_list');
$auth->acl_getf('f_read');
$auth->acl_getf('f_post');
$auth->acl_getf('f_reply');
How is this serialized in the database? I want to do something similar and display a top 10 active threads across forums the current user has access to, but, for my site performance is king, so I was intending to write a stored procedure (MS SQL) so the query plan can be cached and optimised etc.

User avatar
A_Jelly_Doughnut
Former Team Member
Posts: 34457
Joined: Sat Jan 18, 2003 1:26 am
Location: Where the Rivers Run
Contact:

Re: Forums authorized to view

Post by A_Jelly_Doughnut »

There is a table, phpbb_acl_options, which is joined with phpbb_acl_groups or phpbb_acl_users to determine what permissions a user has.

These results are cached for each user in the phpbb_users table.

HTH you skinmaster :)
A Donut's Blog
"Bach's Prelude (Cello Suite No. 1) is driving Indiana country roads in Autumn" - Ann Kish

Locked

Return to “[3.0.x] MOD Writers Discussion”