public static function checkAndAssignKickCampaignToUser($userId) { Log::user("checkAndAssignKickCampaignToUser"); $currentWeek = OBCampaign::getCurrentWeek($userId); Log::user("current week is {$currentWeek}"); $lala = Campaign::doesUserHaveCampaign($userId, Campaign::$_KICK_TRACKER_CAMPAIGN); Log::user("does this person already have this campaign? {$lala}"); $conditional = OBCampaign::getCurrentWeek($userId) >= 28 && !Campaign::doesUserHaveCampaign($userId, Campaign::$_KICK_TRACKER_CAMPAIGN); $currentUser = User::findById($userId); $hasLocation = $currentUser->location; boldError("the conditional is: {$conditional}"); if (OBCampaign::getCurrentWeek($userId) >= 28 && $hasLocation) { Campaign::assignCampaignToUser(Campaign::$_KICK_TRACKER_CAMPAIGN, $userId); Action::assignActionItem($userId, KickCampaign::$_KICK_TRACKER_ACTION_ID); boldError("ASSIGNED KICK CAMPAIGN"); } }
// send an email to the user $response = postRequest(AUTH_SERVER . '/emails/send-email/kick_tracker-inactive', $data); // send an email to the user's group's admin $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);