$app->post("/user/timezones/activated", $save_timezone_activations); $save_user_timezone_attachments = function (Request $request, Response $response) { $parser = new RequestParser($request); $data = $parser->getData(); $errors = array(); if (empty($data['user_id'])) { $errors[] = "User id should not be empty"; } $user_id = $data['user_id']; $attach = array(); if (!empty($data['attach'])) { $attach = $data['attach']; } $detach = array(); if (!empty($data['detach'])) { $detach = $data['detach']; } if (empty($attach) && empty($detach)) { $errors[] = "Both attach and detach were empty. You must supply one or the other"; } if (!empty($errors)) { $new_response = $response->withStatus(400); $r = array("errors" => $errors); $new_response->getBody()->write(json_encode($r)); return $new_response; } $r = array("attach" => TimezoneRepository::createMultipleTimezoneUserRelationships($user_id, $attach), "detach" => TimezoneRepository::deleteTimezoneUserRelationship($user_id, $detach)); $response->getBody()->write(json_encode($r)); return $r; }; $app->post("/user/timezones/attached", $save_user_timezone_attachments);
} else { $tz_collection = TimezoneRepository::getTimezonesByUserId( $user_id ); } */ $tz_collection = array("all" => array(), "attached" => TimezoneRepository::getTimezonesByUserId($user_id)); if ($session->getUser()->hasPrivilege(Privilege::MANAGE_ALL_TIMEZONES)) { $tz_collection['all'] = TimezoneRepository::getAllTimezones(); } $response->getBody()->write(json_encode($tz_collection)); return $response; }; $app->get("/timezone/list", $get_timezones); $delete_timezone = function (Request $request, Response $response) { $parser = new RequestParser($request); $data = $parser->getData(); if (empty($data['id'])) { $new_response = $response->withStatus(400); $new_response->getBody()->write("Missing timezone id"); return $new_response; } $affected = TimezoneRepository::markTimezoneAsDeleted($data['id']); if ($affected < 1) { $new_response = $response->withStatus(404); $new_response->getBody()->write("Invalid timezone id"); return $new_response; } $response->getBody()->write("Successfully deleted timezone with id " . $data['id']); return $response; }; $app->post("/timezone/delete", $delete_timezone);