Moved all current routes to individual folders which use a class system and inherit from an interface. Moved rest of the files for a better structure and for readability. Each editable cms should have its own folder with a routes class file and data class file

Signed-off-by: rodude123 <rodude123@gmail.com>
This commit is contained in:
2023-06-08 15:10:27 +01:00
parent fb75dd2255
commit a3eb4678f9
26 changed files with 1189 additions and 931 deletions
+97
View File
@@ -0,0 +1,97 @@
<?php
namespace api\blog;
use PDO;
require_once __DIR__ . "/../utils/config.php";
/**
* Blog Data Class
* Define all functions which either get, update, create or delete posts
*/
class blogData
{
/**
* Get all blog posts
* @return array - Array of all blog posts or error message
*/
function getBlogPosts(): array
{
$conn = dbConn();
$stmt = $conn->prepare("SELECT ID, title, dateCreated, dateModified, body, tags FROM blog ORDER BY dateCreated DESC;");
$stmt->execute();
// set the resulting array to associative
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
if ($result)
{
return $result;
}
return array("errorMessage" => "Error, blog data not found");
}
/**
* Get a blog post with the given ID
* @param string $ID - ID of the blog post to get
* @return array - Array of all blog posts or error message
*/
function getBlogPost(string $ID): array
{
$conn = dbConn();
$stmt = $conn->prepare("SELECT ID, title, dateCreated, dateModified, featured, headerImg, body, tags FROM blog WHERE ID = :ID;");
$stmt->bindParam(":ID", $ID);
$stmt->execute();
// set the resulting array to associative
$result = $stmt->fetch(PDO::FETCH_ASSOC);
if ($result)
{
return $result;
}
return array("errorMessage" => "Error, blog post could not found");
}
/**
* Get the latest blog post
* @return array - Array of the latest blog post or error message
*/
function getLatestBlogPost(): array
{
$conn = dbConn();
$stmt = $conn->prepare("SELECT ID, title, dateCreated, dateModified, featured, headerImg, body, tags FROM blog ORDER BY dateCreated DESC LIMIT 1;");
$stmt->execute();
// set the resulting array to associative
$result = $stmt->fetch(PDO::FETCH_ASSOC);
if ($result)
{
return $result;
}
return array("errorMessage" => "Error, blog post could not found");
}
/**
* Get featured blog post
* @return array - Array of the featured blog post or error message
*/
function getFeaturedBlogPost(): array
{
$conn = dbConn();
$stmt = $conn->prepare("SELECT ID, title, dateCreated, dateModified, featured, headerImg, body, tags FROM blog WHERE featured = 1;");
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
if ($result)
{
return $result;
}
return array("errorMessage" => "Error, blog post could not found");
}
}
+20
View File
@@ -0,0 +1,20 @@
<?php
namespace api\blog;
use Slim\App;
class blogRoutes implements \api\utils\routesInterface
{
private blogData $blogData;
public function __construct(App $app)
{
$this->blogData = new blogData();
$this->createRoutes($app);
}
public function createRoutes(App $app): void
{
// TODO: Implement createRoutes() method.
}
}