title = $_GET["title"]; } if (isset($_GET["description"])) { $activity->description = $_GET["description"]; } if (isset($_GET["duration"])) { $activity->expectedDuration = (int)$_GET["duration"]; } if (isset($_GET["available"])) { $activity->available = filter_var($_GET["available"], FILTER_VALIDATE_BOOLEAN); } if (isset($_GET["working"])) { $activity->working = filter_var($_GET["working"], FILTER_VALIDATE_BOOLEAN); } if (isset($_GET["template"])) { $activity->template = $_GET["template"]; } } function handleTemplate(Activity $activity) { // Load and find template try { $templates = loadTemplates(); } catch (Exception $e) { respondAndDie($e->getMessage()); } $template = $templates->findValidTemplate($activity); if ($template == null) { // No applicable template found return; } // Apply template $template->applyTo($activity); // Overwrite parameters if template was specified on activity if ($activity->template != "") { loadGivenParameters($activity); } } // If no secret key is provided, respond with the current activity global $SECRET_KEY; if (!isset($_GET["secret"]) || $_GET["secret"] != $SECRET_KEY) { // Respond with the current activity try { $activity = loadActivity(); } catch (Exception $e) { respondAndDie($e->getMessage()); } handleTemplate($activity); if ($activity->title == "Sleeping") { $activity->streak = getStreakEntries("sleep"); } respondWithJson($activity->getPublicData()); } // Update activity $activity = new Activity(); loadGivenParameters($activity); storeActivity($activity); // Handle sleep streak $startingHour = (int) date("H"); $startingMinute = (int) date("i"); if ($activity->title == "Sleeping" && $startingHour > 15 && ($startingHour < 22 || ($startingHour == 22 && $startingMinute <= 5))) { markTodayAsSuccess("sleep"); } respondAndDie("Activity updated");