Beispiel #1
0
            $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;
}