2021-12-28 21:22:32 +00:00
< ? php
namespace api ;
use PDO ;
require_once " ./config.php " ;
/**
* Project Data Class
* Define all functions which either get , update , create or delete timeline data
*/
class projectData
{
2022-10-09 02:40:06 +01:00
/**
* Get all project data
* @ return array - Array of all project data or error message
*/
2022-07-29 20:00:36 +01:00
function getProjectData () : array
2021-12-28 21:22:32 +00:00
{
$conn = dbConn ();
2023-01-17 01:56:03 +00:00
$stmt = $conn -> prepare ( " SELECT title, isMainProject, information, imgLocation, projectLink, gitLink FROM projects order by date LIMIT 4; " );
2021-12-28 21:22:32 +00:00
$stmt -> execute ();
// set the resulting array to associative
$result = $stmt -> fetchAll ( PDO :: FETCH_ASSOC );
if ( $result )
{
return $result ;
}
2022-07-29 20:00:36 +01:00
return array ( " errorMessage " => " Error, project data not found " );
2021-12-28 21:22:32 +00:00
}
2022-11-11 14:04:43 +00:00
function updateProjectData ( string $title , string $isMainProject , string $information , string $projectLink , string $githubLink , string $id ) : bool
{
$conn = dbConn ();
$stmt = $conn -> prepare ( " UPDATE projects SET title = :title, isMainProject = :isMainProject, information = :information, projectLink = :projectLink, githubLink = :githubLink WHERE ID = :id " );
$stmt -> bindParam ( " :title " , $title );
$stmt -> bindParam ( " :isMainProject " , $isMainProject );
$stmt -> bindParam ( " :information " , $information );
$stmt -> bindParam ( " :projectLink " , $projectLink );
$stmt -> bindParam ( " :githubLink " , $githubLink );
$stmt -> bindParam ( " :id " , $id );
$stmt -> execute ();
if ( $stmt -> rowCount () > 0 )
{
return true ;
}
return false ;
}
function deleteProjectData ( int $id ) : bool
{
$conn = dbConn ();
$stmt = $conn -> prepare ( " DELETE FROM projects WHERE ID = :id " );
$stmt -> bindParam ( " :id " , $id );
$stmt -> execute ();
if ( $stmt -> rowCount () > 0 )
{
return true ;
}
return false ;
}
function addProjectData ( string $title , string $isMainProject , string $information , string $projectLink , string $githubLink ) : bool
{
$conn = dbConn ();
$stmt = $conn -> prepare ( " INSERT INTO projects (title, isMainProject, information, projectLink, githubLink) VALUES (:title, :isMainProject, :information, :projectLink, :githubLink) " );
$stmt -> bindParam ( " :title " , $title );
$stmt -> bindParam ( " :isMainProject " , $isMainProject );
$stmt -> bindParam ( " :information " , $information );
$stmt -> bindParam ( " :projectLink " , $projectLink );
$stmt -> bindParam ( " :githubLink " , $githubLink );
$stmt -> execute ();
if ( $stmt -> rowCount () > 0 )
{
return true ;
}
return false ;
}
2022-07-29 20:00:36 +01:00
}