TinyPortal

Development => Feedback => Topic started by: deniz on April 19, 2006, 06:15:36 PM

Title: block permission according to message count.
Post by: deniz on April 19, 2006, 06:15:36 PM
in block permission there is no group whic according to message count.

i need a block which comes in view to specific user group.

for example if user has 0 message block seems just this gorup.  etc.
Title: Re: block permission according to message count.
Post by: anunlike on April 19, 2006, 06:42:34 PM
Good idea. I can think of some specific uses for this.
Title: Re: block permission according to message count.
Post by: Sineksekiz on October 28, 2008, 09:53:58 AM
I may be shouldn't resurrect an old topic like this but deniz has put it exactly the way I wanted to.

Is there anyway to set block permisions by member groups according to message count? I did not try the TP 1.6 Beta, does it has this option or could you tell me in which file I need to modify to do this?

Thank you...
Title: Re: block permission according to message count.
Post by: Ken. on October 28, 2008, 11:32:15 AM
In your block edit screen you should see "Choose your membergroups that will able to see this block."
Title: Re: block permission according to message count.
Post by: Sineksekiz on October 28, 2008, 12:40:42 PM
Hi Ken.

I know where would you want me to look at. But  there is only normal member groups. I can't see membergorups according to message count there...

If this helps I am using SMF 1.1.6, Midnight Theme and TP 0.9.8 ....

Thank you.
Title: Re: block permission according to message count.
Post by: IchBin on October 28, 2008, 01:14:22 PM
Post based groups are not part of the TP permissions. There's no option to do this type of thing without coding the block to have the custom option.
Title: Re: block permission according to message count.
Post by: Sineksekiz on October 28, 2008, 06:18:54 PM
Hi IchBinâ,,¢

Please let me know where can I tweak these settings? Or is there a mod for this? If you give me a headstart about where should I start I would want to give it a go.

Thank you.
Title: Re: block permission according to message count.
Post by: IchBin on October 28, 2008, 06:34:33 PM
Its not a setting you can tweak. I was referring to writing some code in the block to check for post count or something.

if ($user_info['post_count'] < 100)

echo ' Display something for users with less than 100 posts';


That is just an example of what I mean. I'm not sure ATM if anything exists in the $user_info array that has the users post count in it. Eating lunch, so I'll check later.
Title: Re: block permission according to message count.
Post by: Ianedres on October 29, 2008, 01:05:25 AM
Unless I missed it, I don't see a post count within the $context array; probably only loaded while checking stats, as it does show in the member summary page in the profile.

Wrote a brief SQL query to count the number of posts for ID_MEMBER, but this did not correlate to the summary page...

Can investigate further, but if all you want to do is to check against NO messages (versus an exact count) then a query might be the best bet and quickest adaption...
Title: Re: block permission according to message count.
Post by: Sineksekiz on October 29, 2008, 05:58:04 AM
How does SMF manages this. Can't we use same query? I'm always scared of this query business since if I wouldn't do proply it would slow down the site...

Can we copy or re-arange SMFs hadling method? So I would be able to use same user groups and if I would change any of them I wouldn't have to change the code as well....
Title: Re: block permission according to message count.
Post by: Ianedres on October 29, 2008, 08:44:09 AM
This will add 1 query to your page, and retrieve the current number of posts stored in the members table. (i.e. whatever SMF reports in stats)...

Obviously, you will need to exclude it from guests in permissions when making the php block or article; did not code for that since TP can handle that.

global $db_prefix, $context;

$query = db_query("
SELECT posts FROM {$db_prefix}members
WHERE ID_MEMBER = {$context['user']['id']}
", __FILE__, __LINE__);

list($num_posts) = ($query = mysql_fetch_row($query));

if($num_posts < 1)
{
echo 'Display message for members with less than 1 post.';
}
else
{
echo 'Display message for members with 1 or more posts.';
}
Title: Re: block permission according to message count.
Post by: Sineksekiz on October 29, 2008, 10:25:00 AM
Sorry I couldn't quite get which file to add this. Is it gonna go in to Themes/default/TPortalBlocks.template.php or Source/TPortalAdmin.php.

Thank you.
Title: Re: block permission according to message count.
Post by: IchBin on October 29, 2008, 02:29:41 PM
Ianedres, actually if you look at the $user_info array in includes $user_info['posts']. You could then check the that count just like I specified earlier in this topic.
Title: Re: block permission according to message count.
Post by: Ianedres on October 29, 2008, 08:06:53 PM
Well, a big 'duh' for me. I got stuck on the $context array and did not use, as you suggested, $user_info...

Definitely would make more sense to use the $user_info, if nothing else, to save a query and code as well.

$myFoo took a big hit on that one...
Title: Re: block permission according to message count.
Post by: Sineksekiz on October 29, 2008, 08:53:22 PM
Are you still speaking English? : D

:tries to come between to professionals
Title: Re: block permission according to message count.
Post by: G6Cad on October 29, 2008, 09:02:01 PM
They are just fooing eatch other again, it will be good in th next post they make   ;D
Title: Re: block permission according to message count.
Post by: IchBin on October 29, 2008, 09:02:37 PM
global $user_info;
if ($user_info['posts'] < 100)
echo 'this for users with a post count less than 100';


This is the basics of what it would look like. This isn't something that you can put into TP to make blocks work  like you are wanting. In fact, Bloc has said in the past that he never had plans to add post count groups into TP. The code above is just something that you can add in a custom block to only display things to a user with a specified post count.
Title: Re: block permission according to message count.
Post by: Sineksekiz on October 29, 2008, 11:10:50 PM
Oh I get it. No I didn't. Oh yeah here it is again. So if I understand you correctly If I open a phpblock and insert this code in the begining of it and change the count like however I like it should work.

Please tell me that I got it. Even if you had to lie tell me please....

Like:


global $user_info;
if ($user_info['posts'] < 100)
echo 'For user less then 100 count';
else
echo 'For user has more';


right?

By the way what does Bloc has against to this kind of member groups?
Title: Re: block permission according to message count.
Post by: IchBin on October 30, 2008, 12:32:20 AM
That looks right to me. And I'm not lying either. lol I'm not sure why Bloc did that. Probably because of what is involved to add that to all of the TP features.
Title: Re: block permission according to message count.
Post by: Sineksekiz on October 30, 2008, 02:02:47 AM
This works just great.

Thank you guys. You managed to save my stinky hide again. : D
Title: Re: block permission according to message count.
Post by: bloc on October 30, 2008, 01:51:07 PM
It was before 0.9 even I mentioned that..the intial reason was that it was so easy to set access wrong when based on post count. And TP did use its own handling of membergroups in certain sections. complicating things. That has now changed, all is based on what you set in "permissions" screen of SMF. Maybe is time to upgrade that part too.
Title: Re: block permission according to message count.
Post by: Sineksekiz on October 31, 2008, 01:56:33 AM
Quote from: Bloc on October 30, 2008, 01:51:07 PM
It was before 0.9 even I mentioned that..the intial reason was that it was so easy to set access wrong when based on post count. And TP did use its own handling of membergroups in certain sections. complicating things. That has now changed, all is based on what you set in "permissions" screen of SMF. Maybe is time to upgrade that part too.

I agree. I apperaciate IchBinâ,,¢  and  lanedreses helps however including them we all know this is not the proper way. But actually this code has got its benefits as well. You can target members less and more then certain amount of posts in a single block.

Put the Content A in to if and content B in to else statement so if a member has less then 100 post it will see the content A otherwise Content B. Downside of it is even considering its simplicity most of the people would get confused because of PHP coding. We can't expect everybody to know how to use an if else statment.

So we get this feature in the next beta? : DDD
Title: Re: block permission according to message count.
Post by: Sineksekiz on November 01, 2008, 12:35:29 AM
Hi

I think I spoke too soon before completely check it. This does not work. Does not matter however I change the equation It shows nothing to anybody. I belive variable posts or the way we call it does not exists. Since I have tried to do everything with the equation (><=) I think we are looking for wrong variable or we are looking for it before we call it.

If you had another look that would be great. By the way my theme is midnight and I am using smf 1.1.6 and TP 0.98...

Thank you.
Title: Re: block permission according to message count.
Post by: IchBin on November 01, 2008, 01:03:24 AM
Did you check the permissions on the block to allow other membergroups? The code works fine for me.
Title: Re: block permission according to message count.
Post by: Sineksekiz on November 01, 2008, 09:40:34 AM
Quote from: IchBinâ,,¢ on November 01, 2008, 01:03:24 AM
Did you check the permissions on the block to allow other membergroups? The code works fine for me.

Yeah I did. Still no go. Could it be the themes fault or my TP version? It is allowed to see by all member groups, not collapsable, frames are used and tried showin <100 and >100 and tried with 2 types of user account.

I know I am doing something wrong.

Yet again my system is SMF 1.1.6, TP v0.9.8, Midnight (by Crip)...

Thank you...
Title: Re: block permission according to message count.
Post by: Ianedres on November 01, 2008, 12:19:21 PM
The code you posted (in your reply here (http://www.tinyportal.net/index.php/topic,4464.msg213923.html#msg213923)) should have brackets for the if/else clause:
global $user_info;
if ($user_info['posts'] < 100)
{ echo 'For user less then 100 count'; }
else
{ echo 'For user has more'; }
Title: Re: block permission according to message count.
Post by: Sineksekiz on November 01, 2008, 06:21:20 PM
Quote from: Ianedres on November 01, 2008, 12:19:21 PM
The code you posted (in your reply here (http://www.tinyportal.net/index.php/topic,4464.msg213923.html#msg213923)) should have brackets for the if/else clause:
global $user_info;
if ($user_info['posts'] < 100)
{ echo 'For user less then 100 count'; }
else
{ echo 'For user has more'; }


I've already tried brackets... I think the problem is $user_info or $user_info['posts'] because it doesn't show if or else statments. It is just a blank block. Nothing in it....
Title: Re: block permission according to message count.
Post by: IchBin on November 01, 2008, 08:59:11 PM
Put this in your block and tell me if your see the [posts] element of the array.

global $user_info;
echo '<pre>',print_r($user_info),'</pre>';


Brackets aren't necessary unless you plan to put more than one executed line inside the if or else statement.
Title: Re: block permission according to message count.
Post by: Sineksekiz on November 02, 2008, 03:20:21 AM
I have done that and it worked great... Then I realised that all the details printed without " ' " sighn so I wonder if it would work if I would write [posts] instead of ['posts'] and it worked too.

So if


global $user_info;
if ($user_info['posts'] < 100)
{ echo 'For user less then 100 count'; }
else
{ echo 'For user has more'; }


try


global $user_info;
if ($user_info[posts] < 100)
{ echo 'For user less then 100 count'; }
else
{ echo 'For user has more'; }


it should work.

Thanks IchBinâ,,¢. This time you accidentally saved me. : DDD
Title: Re: block permission according to message count.
Post by: IchBin on November 02, 2008, 03:56:29 AM
$user_info[posts] should not work. Without the single quotes php will treat it like a number instead of a string.
Title: Re: block permission according to message count.
Post by: Sineksekiz on November 02, 2008, 04:00:58 AM
Well it does work. : D May be it is because of my php version. I run my own server and it is 5.1.4 (I could not upgrade it 5.2.5 because it also uses Fedora Core 6 soit is not supported by yum.)
Title: Re: block permission according to message count.
Post by: IchBin on November 02, 2008, 04:04:35 AM
Well with crap like that happening then you'll likely run into other problems. lol Good luck with that. :)
Title: Re: block permission according to message count.
Post by: Ianedres on November 02, 2008, 08:20:51 AM
I've seen code that uses no single quotes around the array key; to me, and for what it is worth, it is a form of laziness to not use the proper syntactic structure of the code language you are writing with. If nothing else, it will lead to errors or slight changes between installations (as we provide code to many different servers types here on TP)...

Also, when I write if/else loops, I specify the brackets from the initial writing of the loop- I actually type {} and separate the two with a line between, whether I intend to use one line or five; I write the code and test. That way, if I add lines to the loop, I already have the brackets set and I can error-check the code much easier if needed.

Just a bit of forward-thinking for my purposes. Shortcuts may save you ten keystrokes or so, but writing with the future in mind can really help develop your code with boilerplate. I recently was able to convert several CSV scripts to SQL simply by changing the way the variables were set in the loops- already set in brackets and the variables properly specified in arrays.
Title: Re: block permission according to message count.
Post by: Sineksekiz on November 02, 2008, 01:19:07 PM
Quote from: IchBin™ on November 02, 2008, 04:04:35 AM
Well with crap like that happening then you'll likely run into other problems. lol Good luck with that. :)

I always have a problem with my server. But it teaches me alot. : D Hell I am always in trouble in life. May be the being in trouble is my natural state of beign. It never gets dull. Never ever. : DDDD

Quote from: Ianedres on November 02, 2008, 08:20:51 AM
I've seen code that uses no single quotes around the array key; to me, and for what it is worth, it is a form of laziness to not use the proper syntactic structure of the code language you are writing with. If nothing else, it will lead to errors or slight changes between installations (as we provide code to many different servers types here on TP)...

Also, when I write if/else loops, I specify the brackets from the initial writing of the loop- I actually type {} and separate the two with a line between, whether I intend to use one line or five; I write the code and test. That way, if I add lines to the loop, I already have the brackets set and I can error-check the code much easier if needed.

Just a bit of forward-thinking for my purposes. Shortcuts may save you ten keystrokes or so, but writing with the future in mind can really help develop your code with boilerplate. I recently was able to convert several CSV scripts to SQL simply by changing the way the variables were set in the loops- already set in brackets and the variables properly specified in arrays.

Oh don't get me wrong please. This is not the way I am. This is the way it is. : D I do some C++ coding and some PHP and HTML desighn I even am careful how many crachter a tab will containg ( I do standard 8 )... My coding is generally so clean. Because it mostly is so simple. : D But I don't know why this happens like this but it happens anyways...

One of these days I will re format my server and install everything over again with nice PHP 5.2.5 and Mysql 5.2 then I think everything should be normal. : )

Thank you guys.