2021-08-22 10:44:49 +01:00
|
|
|
<?php
|
|
|
|
////////////////// Index file //////////////
|
|
|
|
/// Creates base routes and runs ///
|
|
|
|
/// respective functions ///
|
|
|
|
////////////////////////////////////////////
|
2021-08-31 18:50:08 +01:00
|
|
|
//require “routes.php”;
|
|
|
|
require "../vendor/autoload.php";
|
2021-09-28 11:29:26 +01:00
|
|
|
include "timelineData.php";
|
|
|
|
include "projectData.php";
|
2021-12-28 21:20:00 +00:00
|
|
|
use api\projectData;
|
|
|
|
use api\timelineData;
|
|
|
|
use Psr\Http\Message\ResponseInterface as Response;
|
|
|
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
|
|
|
use Slim\Factory\AppFactory;
|
2021-08-22 10:44:49 +01:00
|
|
|
|
|
|
|
// Start slim
|
|
|
|
$app = AppFactory::create();
|
|
|
|
// create middleware
|
|
|
|
$app->addRoutingMiddleware();
|
|
|
|
|
2021-08-31 18:50:08 +01:00
|
|
|
// for error checking
|
|
|
|
$errorMiddleware = $app->addErrorMiddleware(true, true, true);
|
2021-08-22 10:44:49 +01:00
|
|
|
|
2021-08-31 18:50:08 +01:00
|
|
|
$app->setBasePath("/api");
|
|
|
|
|
2021-12-28 21:20:00 +00:00
|
|
|
$timelineData = new timelineData();
|
|
|
|
$projectData = new projectData();
|
2021-08-31 18:50:08 +01:00
|
|
|
|
|
|
|
$app->get("/timelineData/{timeline}", function (Request $request, Response $response, array $args)
|
2021-08-22 10:44:49 +01:00
|
|
|
{
|
2021-08-31 18:50:08 +01:00
|
|
|
global $timelineData;
|
|
|
|
$json = $result = "";
|
2021-12-28 21:20:00 +00:00
|
|
|
|
|
|
|
//check if route is available if it is get the data
|
2021-08-31 18:50:08 +01:00
|
|
|
//otherwise return an error
|
|
|
|
if($args["timeline"] == "edu")
|
|
|
|
{
|
|
|
|
$result = $timelineData->getEduData();
|
|
|
|
}
|
|
|
|
else if($args["timeline"] == "work")
|
|
|
|
{
|
|
|
|
$result = $timelineData->getWorkData();
|
|
|
|
}
|
2021-12-28 21:20:00 +00:00
|
|
|
else
|
2021-08-31 18:50:08 +01:00
|
|
|
{
|
|
|
|
$result = array(array("errorMessage" => "Error, timeline data not found"));
|
|
|
|
}
|
2021-12-28 21:20:00 +00:00
|
|
|
|
2021-08-31 18:50:08 +01:00
|
|
|
$json = json_encode($result);
|
2021-08-22 10:44:49 +01:00
|
|
|
|
2021-08-31 18:50:08 +01:00
|
|
|
$response->getBody()->write($json);
|
2021-12-30 16:08:47 +00:00
|
|
|
return $response;
|
|
|
|
// //if it is an error give a 403 code since it can't find the data
|
|
|
|
// if(array_key_exists("errorMessage", $result[-1]))
|
|
|
|
// {
|
|
|
|
// $response = $response->withStatus(403);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// //use content type json to indicate json data on frontend.
|
|
|
|
// return $response->withHeader("Content-Type", "application/json");
|
2021-12-28 21:20:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$app->get('/projectData', function (Request $request, Response $response)
|
|
|
|
{
|
|
|
|
global $projectData;
|
|
|
|
|
|
|
|
$result= $projectData->getProjectData();
|
|
|
|
|
|
|
|
$json = json_encode($result);
|
|
|
|
|
|
|
|
$response->getBody()->write($json);
|
|
|
|
|
2021-12-30 16:08:47 +00:00
|
|
|
if(array_key_exists("errorMessage", $result[-1]))
|
2021-12-28 21:20:00 +00:00
|
|
|
{
|
|
|
|
$response = $response->withStatus(403);
|
|
|
|
}
|
|
|
|
|
2021-08-31 18:50:08 +01:00
|
|
|
//use content type json to indicate json data on frontend.
|
|
|
|
return $response->withHeader("Content-Type", "application/json");
|
2021-08-22 10:44:49 +01:00
|
|
|
});
|
2021-08-31 18:50:08 +01:00
|
|
|
|
|
|
|
$app->run();
|