Please review my code, what am i doing wrong ?

Started by wtfwtf, February 04, 2019, 10:54:34 AM

Previous topic - Next topic

wtfwtf

for some reason i am always getting true for the bottom statement

Post.php

$useractivity = $user_info['posts'];
$regy = time() - $user_settings['date_registered'];
$loggy= $user_settings['total_time_logged_in'];
$activityRank = false;

$stopPoints = array(40,130,300,1000,2000,6000,12000);

if (!in_array($useractivity, $stopPoints))
{
$activityRank = true;
}
else
{
switch($useractivity) {
    case 40:
if ($regy  >= (168 * 3600))
$activityRank = true;
break;
    case 130:
if ($regy  >= (720 * 3600))
$activityRank = true;
break;
    case 300:
if ($regy  >= (2160 * 3600))
$activityRank = true;
break;
case 1000:
if ($regy  >= (4320 * 3600))
$activityRank = true;
break;
case 2000:
if ($regy  >= (6480 * 3600))
$activityRank = true;
break;
case 6000:
if ($regy  >= (8640 * 3600))
$activityRank = true;
break;
case 12000:
if ($regy  >= (12960 * 3600))
$activityRank = true;
break;
}
}


then
'update_post_count' => !$user_info['is_guest'] && !isset($_REQUEST['msg']) && $board_info['posts_count'] && $activityRank && $minLenght,

Shambles

You're setting $activityRank = true in a large number of cases because of the !in_array($useractivity, $stopPoints) test.


wtfwtf

Quote from: Shambles on February 04, 2019, 12:05:29 PM
You're setting $activityRank = true in a large number of cases because of the !in_array($useractivity, $stopPoints) test.

it is intentional,
however, i am always getting true, even in the cases that should not be


Shambles

Quote from: wtfwtf on February 04, 2019, 12:13:43 PM
Quote from: Shambles on February 04, 2019, 12:05:29 PM
You're setting $activityRank = true in a large number of cases because of the !in_array($useractivity, $stopPoints) test.

it is intentional,
however, i am always getting true, even in the cases that should not be

The way I see it, is you're checking if a member's post count is exactly equal to one of 40,130,300,1000,2000,6000 or 12000 then doing further time-based tests to then set your $activityRank to true. If anything other than one of those exact numbers (ie, every other case) then set it true anyway.

if (!in_array($useractivity, $stopPoints))
{
$activityRank = true;
}

Aleksi "Lex" Kilpinen

I'm not sure where you are using this, and I have to admit this is not my best expertise at all - but are you sure you are actually getting values with $user_settings['date_registered'] ?

I don't think $user_settings is a global, and registration date is not loaded into $user_info either. You may need to fetch that data specifically if you need it.
Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

How you can help SMF

wtfwtf

Quote from: Shambles on February 04, 2019, 02:11:15 PM
Quote from: wtfwtf on February 04, 2019, 12:13:43 PM
Quote from: Shambles on February 04, 2019, 12:05:29 PM
You're setting $activityRank = true in a large number of cases because of the !in_array($useractivity, $stopPoints) test.

it is intentional,
however, i am always getting true, even in the cases that should not be

The way I see it, is you're checking if a member's post count is exactly equal to one of 40,130,300,1000,2000,6000 or 12000 then doing further time-based tests to then set your $activityRank to true. If anything other than one of those exact numbers (ie, every other case) then set it true anyway.

if (!in_array($useractivity, $stopPoints))
{
$activityRank = true;
}


that's correct

wtfwtf

Quote from: Aleksi "Lex" Kilpinen on February 04, 2019, 02:44:50 PM
I'm not sure where you are using this, and I have to admit this is not my best expertise at all - but are you sure you are actually getting values with $user_settings['date_registered'] ?

I don't think $user_settings is a global, and registration date is not loaded into $user_info either. You may need to fetch that data specifically if you need it.
took care of all these,
on echo everything behaving as it should
however the update keeps getting true for some reason

tinoest

If you can echo and all values are correct then manually go through and work out which check is setting it to true. I would expect in most instances it to be true unless they are a recent member.

wtfwtf

the code works fine, the only issue is  $activityRank is not being seen as false in the update function
everything else works as it should i think

vbgamer45

Probably this part


$stopPoints = array(40,130,300,1000,2000,6000,12000);

if (!in_array($useractivity, $stopPoints))
{
$activityRank = true;
}


Does that users post not equal any of those values 40,130,300,1000,2000,6000,12000
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

live627

Perhaps it may be best if you explain what you want to accomplish.

wtfwtf

Quote from: live627 on February 04, 2019, 05:41:34 PM
Perhaps it may be best if you explain what you want to accomplish.

if post count any of the values 40,130,300,1000,2000,6000 or 12000, i am triggering a switch case for each condition
then in this switch other condition tested and if met  the variable $activityRank is set to  true;

update_post_count is Boolean, thus in theory when i send it $activityRank it should be false if $activityRank is false.
that's not happening,



wtfwtf

Quote from: vbgamer45 on February 04, 2019, 05:25:26 PM
Probably this part


$stopPoints = array(40,130,300,1000,2000,6000,12000);

if (!in_array($useractivity, $stopPoints))
{
$activityRank = true;
}


Does that users post not equal any of those values 40,130,300,1000,2000,6000,12000

this is ok, i don't want to concern myself with other values,
just focusing on these

live627

I completely overlooked the update part. What is $minLenght and how is it defined?

wtfwtf

Quote from: live627 on February 04, 2019, 06:09:18 PM
I completely overlooked the update part. What is $minLenght and how is it defined?

that's for something else, it works fine

the issue is
how the false is not being reflected for $activityRank in the update part

live627


wtfwtf


live627

The plot thickens.

How  is $activityRank shared? Could you post your entire function? Are both functions in the same file?

wtfwtf

Quote from: live627 on February 04, 2019, 10:32:58 PM
The plot thickens.

How  is $activityRank shared? Could you post your entire function? Are both functions in the same file?

above -1st post is the entire code, didn't do anything else

Advertisement: