public static function unitTest() { $response = ''; $response .= "<br/>starting Data Point tests <br/>"; $response .= 'Testing updateUserDataPoint: '; DataPoint::updateUserDataPoint(TEST_USER_ID, DataPoint::$BLOOD_PRESSURE, '121/50'); $value = DataPoint::getValueForDataPoint(DataPoint::$BLOOD_PRESSURE, TEST_USER_ID); if ($value == '121/50') { $response .= 'Passed'; } else { $response .= 'Failed'; } $response .= '<br/>'; $response .= 'Testing getHistoryListForDataPoint: '; $dataPointList = DataPoint::getHistoryListForDataPointAsArray(DataPoint::$BLOOD_PRESSURE, TEST_USER_ID); if (sizeof($dataPointList) > 0) { $response .= 'Passed'; } else { $response .= 'Failed'; } $response .= '<br/>'; $response .= 'Testing deleteDataPointHistory: '; DataPoint::deleteDataPointHistory(TEST_USER_ID, DataPoint::$BLOOD_PRESSURE); $dataPointList = DataPoint::getHistoryListForDataPointAsArray(DataPoint::$BLOOD_PRESSURE, TEST_USER_ID); if (sizeof($dataPointList) == 0) { $response .= 'Passed'; } else { $response .= 'Failed'; } $response .= '<br/>'; return $response; }
$provider_response = postRequest(AUTH_SERVER . '/emails/send-email/kick_tracker-admin_alert', $provider_data); if (!isset($response->status) || $response->status != 'success' || (!isset($provider_response->status) || $provider_response->status != 'success')) { Log::user("Error sending irregular kick count email"); exit; } // once email is sent, update the last time a kick email was sent User::updateKickEmailTime($userId); } if ($curNumKicks >= 10) { Log::user("Silently updating last sent email time so avoid getting a forgotten kick tracker email"); User::updateKickEmailTime($userId); } boldError("Success"); echo json_encode(array('status' => 'success', 'numKicks' => $curNumKicks, 'timesBeenEmailed' => $timesBeenEmailed)); } } elseif ($_SERVER['REQUEST_METHOD'] == 'GET') { // get a date time for two hours ago $twoHoursAgo = new DateTime(); $twoHoursAgo->sub(new DateInterval("PT2H")); // get the most recent reset time, though it's stored as a string $lastResetTime = DataPoint::getValueForDataPoint(DataPoint::$BABY_KICK_RESET, $userId); // so convert it back to a DateTime so you can compare it $lastResetTime = DateTime::createFromFormat(DATABASE_DATETIME_FORMAT, $lastResetTime); // if the reset time is less than two hours ago, compare kicks to reset time if ($lastResetTime > $twoHoursAgo) { $numKicks = DataPoint::getNumDataPointsWithinReset(DataPoint::$BABY_KICK, $userId); } else { $numKicks = DataPoint::getNumDataPointsWithinTwoHours(DataPoint::$BABY_KICK, $userId); } echo (string) $numKicks; }