PDA

View Full Version : I'm looking to change the query in NEWS.PHP so only select certain user groups....


KW802
10-01-2004, 01:52 PM
What I'm looking at doing is changing the query in NEWS.PHP so that it only pulls threads for posters who belong to certain usergroups. This way I wouldn't have to create a seperate forum for items that I want to appear on the portal page versus forums that everybody else is allowed to post in.

My first inclination was to create a new variable ($portal_user_groups = '6,9') and then change the query to include "AND user.usergroupid IN($portal_user_groups)" but I'm stumped on the user.membergroupids field since that itself could contain muliple values. How would I go about checking to see any of the values in $portal_user_groups are in user.membergroupids?

Thoughts? Is there an easier way of doing this? Am I destined to never learn the tricks of PHP? :D


Thanks,
Kevin

Artayick
10-01-2004, 02:44 PM
Ok recap here. You want to keep one news forum but depending on the usergroup to have the portal only pull certain posts that you make for each user group?

If so I don't think you can sperate posts by user group... not without some serious modding.. While youcould make subforums and set them to each user group in order to get it to show up. Other then that.. hmmmm

Our Sponsors
 

KW802
10-01-2004, 02:58 PM
Ok recap here. You want to keep one news forum but depending on the usergroup to have the portal only pull certain posts that you make for each user group?

If so I don't think you can sperate posts by user group... not without some serious modding.. While youcould make subforums and set them to each user group in order to get it to show up. Other then that.. hmmmm
The recap is correct. :) One forum that everybody can post into but only threads from people in certain usergroups would show up on the portal.

To clarify, think of creating a new user group called "Can Post Portal News" and that new group gets assigned an ID of 10. Now when the query in NEWS.PHP is executed to pull from the forums specified in the the ACP I'm looking at pulling only the threads of users who belong to either groups 6 (the default ID for administrators) or 9 (the new group) regardless of whether "6" or "10" is their primary user group or is one of their secondary groups.

I know I can do it through changing the WHERE condition of the query and I can handle the code for checking the users primary user group but because the member group field could contain multiple values that's the part that threw me off. I'm thinking it should only be a one or two line change to the query but I'm stuck on "How do see if any values from array X match any of the values in array Y?".

hani
10-02-2004, 04:01 AM
Hi
What I did is I started a news forum, where certain groups can start a thread, all others can reply.
Since replys dont show in portal, then you dont have to worry.

I hope this helps

Hani

Our Sponsors
 

KW802
10-02-2004, 11:04 AM
I am so close yet still so far..... :o

By changing the query to always do a left join on the user table (instead of just being in the if statement) that gives me access to the user.usergroupid and user.membergroupids fields in the where clause. I've got the user.usergroupid condition working but I'm still stuck on the user.membergroupids field. For some reason it does not like me working with arrays within the where clause.

Back to experimenting.....

KW802
10-04-2004, 07:38 PM
Well, I'm stuck. :(

For the life of my I just can't figure out how to get it to work with the user.membergroupids field because every time I try to insert a command that deals with an array into the where clause I get an error.

The code below works for the primary group though. :o

Thoughts?

$portal_user_groups = "6,9";
$getnews = $DB_site->query("
SELECT " . iif($vba_options['portal_news_showrating'], 'IF(votenum >= ' . $vboptions['showvotes'] . ', votenum, 0) AS votenum, IF(votenum >= ' . $vboptions['showvotes'] . ' AND votenum != 0, votetotal / votenum, 0) AS voteavg,') . "
thread.threadid, thread.title, replycount, postusername, postuserid, thread.dateline AS postdateline, thread.lastposter, thread.lastpost, IF(views<=replycount, replycount+1, views) AS views, forumid, post.postid, pagetext, allowsmilie
" . iif ($vba_options['portal_news_showsignature'], ', showsignature, usertextfield.signature') . "
" . iif ($vba_options['portal_news_showicon'] , ',thread.iconid AS threadiconid, iconpath AS threadiconpath') . "
" . iif ($vba_options['portal_news_showavatar'] , ', avatarpath, NOT ISNULL(avatardata) AS hascustom, customavatar.dateline AS avatardateline, avatarrevision') . "
" . iif ($vba_options['portal_news_showsubscribed'] AND $bbuserinfo['userid'] , ', NOT ISNULL(subscribethread.subscribethreadid) AS subscribed ') . "
" . iif ($vba_options['portal_news_showattachments'], ', attachment.filename, attachment.filesize, attachment.visible, attachmentid, counter, thumbnail, LENGTH(thumbnail) AS thumbnailsize') . "
FROM " . TABLE_PREFIX . "thread AS thread
LEFT JOIN " . TABLE_PREFIX . "post AS post ON (post.postid = thread.firstpostid)
" . iif ($vba_options['portal_news_showicon'] , 'LEFT JOIN ' . TABLE_PREFIX . 'icon USING (iconid)') . "
" . iif ($vba_options['portal_news_showattachments'] , 'LEFT JOIN ' . TABLE_PREFIX . 'attachment AS attachment ON (post.postid = attachment.postid)') . "
LEFT JOIN " . TABLE_PREFIX . "user AS user ON (user.userid = post.userid)
" . iif ($vba_options['portal_news_showsignature'], 'LEFT JOIN ' . TABLE_PREFIX . 'usertextfield AS usertextfield ON (post.userid = usertextfield.userid)') . "
" . iif ($vba_options['portal_news_showavatar'] , '
LEFT JOIN ' . TABLE_PREFIX . 'avatar as avatar ON (avatar.avatarid = user.avatarid)
LEFT JOIN ' . TABLE_PREFIX . 'customavatar as customavatar ON (customavatar.userid = user.userid)
') . "
" . iif ($vba_options['portal_news_showsubscribed'] AND $bbuserinfo['userid'] , ' LEFT JOIN ' . TABLE_PREFIX . 'subscribethread AS subscribethread ON (subscribethread.threadid = thread.threadid AND subscribethread.userid = \'' . $bbuserinfo['userid'] . '\')') . "
$deljoin
WHERE forumid IN($vba_options[portal_news_forumid]) AND user.usergroupid IN($portal_user_groups) AND thread.visible = 1 AND thread.open != 10 $notdeleted
GROUP BY post.postid
ORDER BY " . iif($vboptions['stickynewsthreads'], 'sticky DESC,') . " postdateline DESC" . iif($vboptions['shownewsattach'], ', attachmentid') . "
$newslimit");