$locationid, 'act' => $action )); } private static function calcNextwake($action, $openingTimes) { //TODO: Calculate nextWake based on openingTimes. Needs action to know if openTimes or closingTimes are used. return 0; } private static function upsert($locationid, $action, $nextwake, $options) { $schedule = Database::queryFirst("SELECT locationid, action FROM `scheduler` WHERE locationid = :lid AND action = :act", array( 'lid' => $locationid, 'act' => $action )); if ($schedule === false) { Database::exec("INSERT INTO `scheduler` (locationid, action, nextwake, options) VALUES (:lid, :act, :next, :opt)", array( 'lid' => $locationid, 'act' => $action, 'next' => $nextwake, 'opt' => $options )); } else { Database::exec("UPDATE `scheduler` SET nextwake = :next, options = :opt WHERE locationid = :lid AND action = :act", array( 'next' => $nextwake, 'opt' => $options, 'lid' => $locationid, 'act' => $action )); } return true; } }