Advertisement:

Author Topic: Please review my code, what am i doing wrong ?  (Read 930 times)

Offline wtfwtf

  • Semi-Newbie
  • *
  • Posts: 94
Please review my code, what am i doing wrong ?
« on: February 04, 2019, 10:54:34 AM »
for some reason i am always getting true for the bottom statement

Post.php

Code: [Select]
$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
Code: [Select]
'update_post_count' => !$user_info['is_guest'] && !isset($_REQUEST['msg']) && $board_info['posts_count'] && $activityRank && $minLenght,

Offline Shambles

  • SMF Hero
  • ******
  • Posts: 5,120
  • Gender: Male
    • i30 Owners Club
Re: Please review my code, what am i doing wrong ?
« Reply #1 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.


Offline wtfwtf

  • Semi-Newbie
  • *
  • Posts: 94
Re: Please review my code, what am i doing wrong ?
« Reply #2 on: February 04, 2019, 12:13:43 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

Offline wtfwtf

  • Semi-Newbie
  • *
  • Posts: 94
Re: Please review my code, what am i doing wrong ?
« Reply #3 on: February 04, 2019, 12:47:18 PM »
@Arantor you there ?

Offline Shambles

  • SMF Hero
  • ******
  • Posts: 5,120
  • Gender: Male
    • i30 Owners Club
Re: Please review my code, what am i doing wrong ?
« Reply #4 on: February 04, 2019, 02:11:15 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.

Code: [Select]
if (!in_array($useractivity, $stopPoints))
{
$activityRank = true;
}

Offline Aleksi "Lex" Kilpinen

  • A Peculiar Finn
  • Lead Support Specialist
  • SMF Super Hero
  • *
  • Posts: 18,188
  • Gender: Male
  • Don't worry, I'm n00b friendly
    • Aleksi.Kilpinen on Facebook
    • LexArma on GitHub
    • aleksi-kilpinen on LinkedIn
    • There's No Place Like 127.0.0.1
Re: Please review my code, what am i doing wrong ?
« Reply #5 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.
A Finnish Support Specialist
 Happily running multiple SMF 2.0 installations.

How you can help SMF

"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

Offline wtfwtf

  • Semi-Newbie
  • *
  • Posts: 94
Re: Please review my code, what am i doing wrong ?
« Reply #6 on: February 04, 2019, 03:57:26 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.

Code: [Select]
if (!in_array($useractivity, $stopPoints))
{
$activityRank = true;
}

that's correct

Offline wtfwtf

  • Semi-Newbie
  • *
  • Posts: 94
Re: Please review my code, what am i doing wrong ?
« Reply #7 on: February 04, 2019, 03:59:42 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

Offline tinoest

  • Development Contributor
  • Jr. Member
  • *
  • Posts: 246
Re: Please review my code, what am i doing wrong ?
« Reply #8 on: February 04, 2019, 04:33:50 PM »
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.

Offline wtfwtf

  • Semi-Newbie
  • *
  • Posts: 94
Re: Please review my code, what am i doing wrong ?
« Reply #9 on: February 04, 2019, 05:12:29 PM »
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

Offline vbgamer45

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 21,232
    • smfhacks on Facebook
    • VBGAMER45 on GitHub
    • @createaforum on Twitter
    • SMF For Free
Re: Please review my code, what am i doing wrong ?
« Reply #10 on: February 04, 2019, 05:25:26 PM »
Probably this part
Code: [Select]

$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

Offline live627

  • On Hiatus
  • SMF Hero
  • *
  • Posts: 5,620
  • Gender: Male
    • live627 on Facebook
    • live627 on GitHub
    • live627 on LinkedIn
    • @live627 on Twitter
    • livemods
Re: Please review my code, what am i doing wrong ?
« Reply #11 on: February 04, 2019, 05:41:34 PM »
Perhaps it may be best if you explain what you want to accomplish.
Try not to become a man of success, but rather try to become a man of value.
- Albert Einstein

Offline wtfwtf

  • Semi-Newbie
  • *
  • Posts: 94
Re: Please review my code, what am i doing wrong ?
« Reply #12 on: February 04, 2019, 05:56:32 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,



Offline wtfwtf

  • Semi-Newbie
  • *
  • Posts: 94
Re: Please review my code, what am i doing wrong ?
« Reply #13 on: February 04, 2019, 05:58:32 PM »
Probably this part
Code: [Select]

$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

Offline live627

  • On Hiatus
  • SMF Hero
  • *
  • Posts: 5,620
  • Gender: Male
    • live627 on Facebook
    • live627 on GitHub
    • live627 on LinkedIn
    • @live627 on Twitter
    • livemods
Re: Please review my code, what am i doing wrong ?
« Reply #14 on: February 04, 2019, 06:09:18 PM »
I completely overlooked the update part. What is $minLenght and how is it defined?
Try not to become a man of success, but rather try to become a man of value.
- Albert Einstein

Offline wtfwtf

  • Semi-Newbie
  • *
  • Posts: 94
Re: Please review my code, what am i doing wrong ?
« Reply #15 on: February 04, 2019, 06:43:33 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

Offline live627

  • On Hiatus
  • SMF Hero
  • *
  • Posts: 5,620
  • Gender: Male
    • live627 on Facebook
    • live627 on GitHub
    • live627 on LinkedIn
    • @live627 on Twitter
    • livemods
Re: Please review my code, what am i doing wrong ?
« Reply #16 on: February 04, 2019, 07:32:06 PM »
Are both code snippets in the same function?
Try not to become a man of success, but rather try to become a man of value.
- Albert Einstein

Offline wtfwtf

  • Semi-Newbie
  • *
  • Posts: 94
Re: Please review my code, what am i doing wrong ?
« Reply #17 on: February 04, 2019, 08:38:06 PM »
Are both code snippets in the same function?
no,
2 separate functions ,

Offline live627

  • On Hiatus
  • SMF Hero
  • *
  • Posts: 5,620
  • Gender: Male
    • live627 on Facebook
    • live627 on GitHub
    • live627 on LinkedIn
    • @live627 on Twitter
    • livemods
Re: Please review my code, what am i doing wrong ?
« Reply #18 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?
Try not to become a man of success, but rather try to become a man of value.
- Albert Einstein

Offline wtfwtf

  • Semi-Newbie
  • *
  • Posts: 94
Re: Please review my code, what am i doing wrong ?
« Reply #19 on: February 05, 2019, 04:46:44 AM »
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