SOLVED - Schedule - Email - EVAL Problem

nclaypool

Member
Hello All,

I've been smashing my head against my desk trying to troubleshoot my code in a scheduled email task. All it has to do is check the value of one element, then in a rather large IF statement test a series of five or six dates to see if they're within a specific time frame from today. Here's my code as it exists now:

PHP:
// Map row data to shortened variables
$center = "{staff_certifications___center_raw}";
$cpr = date('m/d/Y', "{staff_certifications___cpr}");
$fa = date('m/d/Y', "{staff_certifications___first_aid}");
$tb = date('m/d/Y', "{staff_certifications___tb}");
$cda = date('m/d/Y', "{staff_certifications___cda}");
$can = date('m/d/Y', "{staff_certifications___child_abuse_neglect}");
$ss = date('m/d/Y', "{staff_certifications___safe_sleep}");

// Checks conditions to see if name should be included on email
if ($center == '2')
{
if (strtotime($cda) > strtotime('-90 day') || strtotime($cpr) > strtotime('-30 day') || strtotime($fa) > strtotime('-30 day') || strtotime($tb) >  strtotime('-30 day') || strtotime($can) > strtotime('-30 day') || strtotime($ss) > strtotime('-30 day'))
  {
    return true;
  }
  else
  {
    return false;
  }
}
else
{
  return false;
}

I only recently added the "date" function to the variables at the beginning as I wondered if the way my dates are stored in the DB with dashes was messing up the strtotime function. With the "date" functions added I always get zero records regardless if any fall within the time frames specified. If I remove the "date" functions (I only have one record currently) I always get the one record returned, even if none of the dates fall within the specified time frame.

Since it doesn't spit out any diagnostic information I'm having a hell of a time figuring out what's going on. Are the dates not getting assigned to the variables properly??? If anyone can give my code a gander and see if I'm missing something glaring that would be great. Or if there's a way I can get more info from Fabrik on why the code isn't resulting in the expected results.

Thank you in advance!
 
Use var_dump() and exit to get feedback, like ...

Code:
var_dump($fa,$tb,$cda,$can,$ss);exit;

... after you've assigned all the variables. Then use the "run" button, and it should dump the variable values out.

-- hugh
 
Use var_dump() and exit to get feedback, like ...

Code:
var_dump($fa,$tb,$cda,$can,$ss);exit;

... after you've assigned all the variables. Then use the "run" button, and it should dump the variable values out.

-- hugh

That's what I needed, by seeing what was being spit out via vardump I determined a few things.
  1. I wasn't using RAW and dates were being output how I set them up with dashes, PHP was interpreting these as European dates thus my comparisons would fail.
  2. I needed my IF statement to utilize a LESS THAN comparison instead of GREATER THAN as I needed to know which dates were within 30 or 90 days from now.
  3. My 30/90 day strtotime functions were wrong, I was going backwards in time 30 or 90 days with a "-30 day", instead I needed to go into the future so instead they're "30 day"
Thanks hugh for pointing out how the vardumps, allowed me to troubleshoot and fix my own code.

For anybody's future reference here's my functional code.

PHP:
// Map row data to shortened variables
$center = "{staff_certifications___center_raw}";
$cpr = strtotime("{staff_certifications___cpr_raw}");
$fa = strtotime("{staff_certifications___first_aid_raw}");
$tb = strtotime("{staff_certifications___tb_raw}");
$cda = strtotime("{staff_certifications___cda_raw}");
$can = strtotime("{staff_certifications___child_abuse_neglect_raw}");
$ss = strtotime("{staff_certifications___safe_sleep_raw}");

$days30 = strtotime('30 day');
$days90 = strtotime('90 day');

// var_dump($center,$cda,$cpr,$fa,$tb,$can,$ss,$days30,$days90);
// exit;

// Checks conditions to see if name should be included on email
if ($center == '2')
{
if ($cda < $days90 || $cpr < $days30 || $fa < $days30 || $tb < $days30 || $can < $days30 || $ss < $days30)
  {
    return true;
  }
  else
  {
    return false;
  }
}
else
{
  return false;
}
 
We are in need of some funding.
More details.

Thank you.

Staff online

Members online

Back
Top